From nobody Mon Jun 30 15:00:52 2025 X-Original-To: dev-commits-src-main@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 4bW8VX4Smnz60ZKd; Mon, 30 Jun 2025 15:00:52 +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 4bW8VX2G9Fz3DRx; Mon, 30 Jun 2025 15:00:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1751295652; 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=U9UvVWh7Ie1CWSXRCFNtW4m5BoiLQyXf8/gWBOLsCAQ=; b=lELuMWFPY4CokGi/nRs+HA1yVe5PZA4Ot4EGif2q/8DVEghTaYgLN9XXqCIIfRxgfeWAZS 7Ozri7cSAtYHG0xuAaWHv+SG8BgFT71CUB3nSjToDzCVeuCEuGuYQ3vYLZmWX/YE1YagmL 1hdYpKj2lXDAIlTJxsjdwNS2hoxW2bpFfjtKyPMe4iFMEc3jCjG6jgbUNztBjIDxG1kTlj elCHutC1nUGqDklOPfqglBQSDu1+g3HKQuATgea3R4J8R0reHgMf3m6d5MbZ6Yca4uRYFZ glR2v2qBP80ET2UOvwShzYgLYTUCUKBIFMTBSOHp0QH7uV7Qzf5DoeF3AmPzgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1751295652; 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=U9UvVWh7Ie1CWSXRCFNtW4m5BoiLQyXf8/gWBOLsCAQ=; b=LyquabCwl1v6LFrWd6BOpZ+2A9cB3er0xrWpfe9A+frJjcpD42fsq/Lk580s4k+YpEP589 SemnXixZXRE7Ulva49vrGg1ykuRfrNPV3q4ap9qklcOFO88KjUL6d9jG4m0u/qDw2N7efF lc1+X29Ispj0HkrHlj68wai3OgTqEuwSOzEXWnqMvRdi/q/gy6/b+BsKSnHsOMy2u4JCVp XGWAmbwVd/NhpAhnMeC4swXkEg+vV0CWWzywzDagxYSlmj8WfBZXiNWjx6uKFUr23R0EE0 yvRUjG0EVD4pr7iyIua2fyI1k8XJHrvzUoY+dh73jeathuFb+EoXYTl9605P4g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1751295652; a=rsa-sha256; cv=none; b=qG3HkiPr79akQOJRXo0oy4z1INn/sl3zfmcVu08WXGm1igcBczIKF+4JsfTLtHRYMw+V5g PqLKkfLUwsBnZrdNbBWUkrOKERE/8RQs7TDkfWKlzW6diLOfZoMImigSdfQKW4QDU4DLez 7f/ZTpUzwmPP2TU/+VJ6EN2H2ADs4r9hsDHpUq6782+XBkppQcG5EWs25Vpk0KsXH9/h2I DbMiykYaMb5whXQo5tmEYpwgHWNBsK6FbRFWvidLtwyOxSvOf3upXZoL7iWjJL4tsZiaB/ GJCydO67KBuPZVKs+mLoSav2Gf5FgOgVlOnEWXkaVeUV7/fjkeJYqnmRQAUnlA== 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 4bW8VX1Tpgz1865; Mon, 30 Jun 2025 15:00:52 +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 55UF0qg0047543; Mon, 30 Jun 2025 15:00:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 55UF0qLU047540; Mon, 30 Jun 2025 15:00:52 GMT (envelope-from git) Date: Mon, 30 Jun 2025 15:00:52 GMT Message-Id: <202506301500.55UF0qLU047540@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: 5d9877ba8f5a - main - pfctl: Simplify host() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: 5d9877ba8f5a4f7311c9b84b973a583650d161ee Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=5d9877ba8f5a4f7311c9b84b973a583650d161ee commit 5d9877ba8f5a4f7311c9b84b973a583650d161ee Author: Kristof Provost AuthorDate: 2025-06-27 12:08:03 +0000 Commit: Kristof Provost CommitDate: 2025-06-30 15:00:27 +0000 pfctl: Simplify host() Get rid of the `cont' flag, zap obvious comments, add error label. OK benno sashan Obtained from: OpenBSD, kn , a98f6f5f17 Sponsored by: Rubicon Communications, LLC ("Netgate") --- sbin/pfctl/pfctl_parser.c | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/sbin/pfctl/pfctl_parser.c b/sbin/pfctl/pfctl_parser.c index 71731652e4af..67b63ebf8229 100644 --- a/sbin/pfctl/pfctl_parser.c +++ b/sbin/pfctl/pfctl_parser.c @@ -74,7 +74,7 @@ void print_fromto(struct pf_rule_addr *, pf_osfp_t, struct pf_rule_addr *, sa_family_t, u_int8_t, int, int); int ifa_skip_if(const char *filter, struct node_host *p); -struct node_host *host_if(const char *, int, int *); +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_dns(const char *, int, int, int); @@ -1803,7 +1803,7 @@ struct node_host * host(const char *s, int opts) { struct node_host *h = NULL; - int mask, v4mask, v6mask = 128, cont = 1; + int mask, v4mask, v6mask = 128; char *p, *ps; const char *errstr; @@ -1811,7 +1811,7 @@ host(const char *s, int opts) mask = strtonum(p+1, 0, v6mask, &errstr); if (errstr) { fprintf(stderr, "netmask is %s: %s\n", errstr, p); - return (NULL); + goto error; } if ((ps = malloc(strlen(s) - strlen(p) + 1)) == NULL) err(1, "host: malloc"); @@ -1825,34 +1825,21 @@ host(const char *s, int opts) mask = -1; } - /* IPv4 address? */ - if (cont && (h = host_v4(s, mask)) != NULL) - cont = 0; - - /* IPv6 address? */ - if (cont && (h = host_v6(ps, v6mask)) != NULL) - cont = 0; - - /* interface with this name exists? */ - /* expensive with thousands of interfaces - prioritze IPv4/6 check */ - if (cont && (h = host_if(ps, mask, &cont)) != NULL) - cont = 0; - - /* dns lookup */ - if (cont && (h = host_dns(ps, v4mask, v6mask, - (opts & PF_OPT_NODNS))) != NULL) - cont = 0; - free(ps); - - if (h == NULL || cont == 1) { + if ((h = host_v4(s, mask)) == NULL && + (h = host_v6(ps, v6mask)) == NULL && + (h = host_if(ps, mask)) == NULL && + (h = host_dns(ps, v4mask, v6mask, (opts & PF_OPT_NODNS))) == NULL) { fprintf(stderr, "no IP address found for %s\n", s); - return (NULL); + goto error; } + +error: + free(ps); return (h); } struct node_host * -host_if(const char *s, int mask, int *cont) +host_if(const char *s, int mask) { struct node_host *n, *h = NULL; char *p, *ps; @@ -1874,7 +1861,6 @@ host_if(const char *s, int mask, int *cont) return (NULL); } *p = '\0'; - *cont = 0; } if (flags & (flags - 1) & PFI_AFLAG_MODEMASK) { /* Yep! */ fprintf(stderr, "illegal combination of interface modifiers\n");