From nobody Thu Jul 3 12:01:07 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bXwMl4kK6z60qXS; Thu, 03 Jul 2025 12:01:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bXwMl33k7z3mcJ; Thu, 03 Jul 2025 12:01:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1751544067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kg0Kpa7dZCOJoN+eAuHRH5nCf6gdKncX6thDHR9aH1g=; b=kqbBGi7Wz6hr7NChDpROh6ewIVP+00Uq6MjSiyhItOcNfUKVTVJSXd5uSpIqqjFfxGFIXO RJn/HoAkM6Eu0sQZn+gk75hc9xiP5l/WHnT/tIGpVvwg2xXhkr3hPJdZZroOBTcYTbWH9n WQ/ktRNsq5GXQswAYnQfEFbWVz8Td9V4F6ZDUDsqlIRznGm1mPKpS/H+icH8zpqKCDoIXh NRATsHOfL7ROdp8nzqH8d/OXk2pUvf0B6LHidMiG/swmLitHkP56bQUxGrb9b1cegLwKrd aOF3urkw6XLG3Wt92/RTj+LpqJG7Af42Rh8aXF46+2BePQtl2HyXB1TiBRoImQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1751544067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kg0Kpa7dZCOJoN+eAuHRH5nCf6gdKncX6thDHR9aH1g=; b=ScZMZtx3SILBhjsS+tCrhiLU/gHNDbkvGYVYF740aPUITzOn4h2ECLFbfY8MreYIurQgrF nMfo9HNOzLp6j7to3g2WwoQcv2aC7q1NfXqp5SYMQeQyilCSiecQr7RcKlRfN+dLXSl7DY 6EC2rk0q/DiqKIo1w15KcBmND8ygq02EwzqqjHNr7xImjW/W3Aiee00a8JC3z1LxzL7QYI RZqrkWlh3ZDyW+VnzyFUkYj+qVVB+j3245lcJGyVfCD35vPy9//AVYiv9TsTWTqpQXI4s1 BWItKAgOVXy+R9Fj0pib9PVdBYFTFrklyaoz36aEG8hsOdK4Zqj58uvtIAnASg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1751544067; a=rsa-sha256; cv=none; b=N6UJvXEIcjrWJBm3gFp96DwGJx3yEdW7K0QJi8LZDoyP43/pjBNZx8bDrtQA/e2WOwx7ay fS0VXeQWMV+InUxufELXUZg+H8BM6NfTBJ2XN64aDIJh29ImK0LFdG9ddM1Ktcf4musG2m JvKrj13y50jEdqCfpD8O2mzLars7nnusWXh3NR5nqJRFhtbuVMrKijzxqQQzexfH+If0BT G+9q+N4XQfcaYXu77V8cTqpCcOYj8oefZHVhL8hm0WYJq5mNS/ktGTbgmBTj0zojd8KVDp 9qSqakVBdjgC0c2r2iMpPZ9+S9vJZJ4OHWZGtP/z4L4avV1vMJymDmKjVZJxoQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bXwMl2XbQz13rn; Thu, 03 Jul 2025 12:01:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 563C17t5051945; Thu, 3 Jul 2025 12:01:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 563C17Df051942; Thu, 3 Jul 2025 12:01:07 GMT (envelope-from git) Date: Thu, 3 Jul 2025 12:01:07 GMT Message-Id: <202507031201.563C17Df051942@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: cbca60158062 - main - pfctl: Merge host_v{4,6}() into simpler host_ip() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cbca601580626662f03933a617e88c5ff2fc329f Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=cbca601580626662f03933a617e88c5ff2fc329f commit cbca601580626662f03933a617e88c5ff2fc329f Author: Kristof Provost AuthorDate: 2025-06-27 14:57:57 +0000 Commit: Kristof Provost CommitDate: 2025-07-03 07:16:13 +0000 pfctl: Merge host_v{4,6}() into simpler host_ip() Except for networks such as "10/8" host_ip() now handles addresses in an AF-agnostic way with more duplicate code removed/merged. OK sashan (as for earlier copy_satopfaddr() diff) henning Obtained from: OpenBSD, kn , 1b6fdc2f24 Sponsored by: Rubicon Communications, LLC ("Netgate") --- sbin/pfctl/pfctl_parser.c | 71 ++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 44 deletions(-) diff --git a/sbin/pfctl/pfctl_parser.c b/sbin/pfctl/pfctl_parser.c index 244531ead280..8eb9bd1d6f5a 100644 --- a/sbin/pfctl/pfctl_parser.c +++ b/sbin/pfctl/pfctl_parser.c @@ -76,8 +76,7 @@ void print_fromto(struct pf_rule_addr *, pf_osfp_t, int ifa_skip_if(const char *filter, struct node_host *p); struct node_host *host_if(const char *, int); -struct node_host *host_v4(const char *, int); -struct node_host *host_v6(const char *, int); +struct node_host *host_ip(const char *, int); struct node_host *host_dns(const char *, int, int); const char * const tcpflags = "FSRPAUEWe"; @@ -1805,8 +1804,7 @@ host(const char *s, int opts) err(1, "host: strdup"); } - if ((h = host_v4(s, mask)) == NULL && - (h = host_v6(ps, mask)) == NULL && + if ((h = host_ip(ps, mask)) == NULL && (h = host_if(ps, mask)) == NULL && (h = host_dns(ps, mask, (opts & PF_OPT_NODNS))) == NULL) { fprintf(stderr, "no IP address found for %s\n", s); @@ -1863,57 +1861,42 @@ error: } struct node_host * -host_v4(const char *s, int mask) -{ - struct node_host *h = NULL; - struct in_addr ina; - - memset(&ina, 0, sizeof(ina)); - if (mask > -1) { - if (inet_net_pton(AF_INET, s, &ina, sizeof(ina)) == -1) - return (NULL); - } else { - if (inet_pton(AF_INET, s, &ina) != 1) - return (NULL); - } - - h = calloc(1, sizeof(struct node_host)); - if (h == NULL) - err(1, "address: calloc"); - h->ifname = NULL; - h->af = AF_INET; - h->addr.v.a.addr.addr32[0] = ina.s_addr; - set_ipmask(h, mask); - h->next = NULL; - h->tail = h; - - return (h); -} - -struct node_host * -host_v6(const char *s, int mask) +host_ip(const char *s, int mask) { struct addrinfo hints, *res; struct node_host *h = NULL; memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET6; + hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; /*dummy*/ hints.ai_flags = AI_NUMERICHOST; - if (getaddrinfo(s, "0", &hints, &res) == 0) { - h = calloc(1, sizeof(struct node_host)); + if (getaddrinfo(s, NULL, &hints, &res) == 0) { + h = calloc(1, sizeof(*h)); if (h == NULL) - err(1, "address: calloc"); - h->ifname = NULL; - h->af = AF_INET6; + err(1, "%s: calloc", __func__); + h->af = res->ai_family; copy_satopfaddr(&h->addr.v.a.addr, res->ai_addr); - h->ifindex = - ((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id; - set_ipmask(h, mask); + if (h->af == AF_INET6) + h->ifindex = + ((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id; freeaddrinfo(res); - h->next = NULL; - h->tail = h; + } else { /* ie. for 10/8 parsing */ + if (mask == -1) + return (NULL); + h = calloc(1, sizeof(*h)); + if (h == NULL) + err(1, "%s: calloc", __func__); + h->af = AF_INET; + if (inet_net_pton(AF_INET, s, &h->addr.v.a.addr.v4, + sizeof(h->addr.v.a.addr.v4)) == -1) { + free(h); + return (NULL); + } } + set_ipmask(h, mask); + h->ifname = NULL; + h->next = NULL; + h->tail = h; return (h); }