From nobody Tue Jan 14 10:37:48 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 4YXQZ46X7Kz5kVN0; Tue, 14 Jan 2025 10:37:48 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YXQZ42g65z3BsK; Tue, 14 Jan 2025 10:37:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736851068; 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=moJRPrH08WgyPN0UrMFaZcjrkj+duJWbVx2rhPxh64A=; b=LqYIGPHxYBLd0RdGrJiiPel1gEohGamcXdV1Yw5oCq25O6MRSJSq95cpGJaiexpTQR40lp fxZUGxichsdAErLDSjyv1vD4tz4X7TbDnPU3qy1kw0VfekXiV9Y2yZCpYMp288oVPpbPz9 t8qGuHuokxRHn7rg9CvjqSIKaF6GuXSCk2Q6QGwRzatkwOAvuUyR19FM8I3gbxzTGfHRYI RV48ZENVktGbRncgFYnbWoOznWoTuQazyWpweZ9Jzqinp6ebX1HiULSGTnsqApLLs1hFt/ FHaE1ltb8aXn6nqHyrmHtvyICpvYKLkJZ8b/eA9Qm3XkukZgC7KF2QyeFnfxBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736851068; 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=moJRPrH08WgyPN0UrMFaZcjrkj+duJWbVx2rhPxh64A=; b=Z9I9YCXn/NODKdE07saRinCrEAyUyoR0DiiXQ4vqsyr4Ylqj+mmUiBZWfZhL+K9j7SVFg7 ip6gPuMvH5wnM9OhivmSsFjcf0Ec6o2n+CXpZe7ASPHIt+Mlf7Xz5lLmgmAiFMXtnPCcUc 8n8j574SE9YcFADTOjRTWY3tkVVjI1uB5z1DiKJUngDb+8PrllJOCSuewoook8jzGedy6U OTOme4wXqJdNCZ/KMYxzMb4cjos6zYDE3Cd3B0yhuMIZKBkFF3ETlF47NSjdkWxZvUSj2w Dvlov14PCFvYRno1yWcnjOUU+fg9Wb1TBzPcr7KNawe0Cdv0TWNyjepAQj2A/w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736851068; a=rsa-sha256; cv=none; b=JhbA/B+q7x80N75aN8rK4zLYFOqYthVV308Nd9XFaAlfjnnuVEovbhtTSANgsn99EzkZfv SgXOkdD7TFvS/N/y+6wtTfJeTf9KuYnw1KZVA/v4NpqY4nOhCsP7F3i0TtJSSGzKwtsXVo V72Mv/aTD7lrv4dD8BBq6oYrbN9D89vEJqPILxAnHyrK0mQWsencUDDDFwuY19LC23T1uD FmiiWjnoRGRlgguFXEJq/cjqgnNuGqasMSFUYUNKV+0Tuqic7dOmZeKEYwyY2TTRhnBqBU qcF4GVLmC8eKxkdKBeb/gip74hcfWA1QUCdDibrZfHkbPpBCfqJhTFIuPZatXw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4YXQZ41xgtz1Brg; Tue, 14 Jan 2025 10:37:48 +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 50EAbmlR047834; Tue, 14 Jan 2025 10:37:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50EAbm4k047831; Tue, 14 Jan 2025 10:37:48 GMT (envelope-from git) Date: Tue, 14 Jan 2025 10:37:48 GMT Message-Id: <202501141037.50EAbm4k047831@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: f88019e8a35c - main - pf: fixup af-to regression with match rules 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: f88019e8a35c05b61b5722e4b98cd7b5cca167f7 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=f88019e8a35c05b61b5722e4b98cd7b5cca167f7 commit f88019e8a35c05b61b5722e4b98cd7b5cca167f7 Author: Kristof Provost AuthorDate: 2025-01-07 11:12:12 +0000 Commit: Kristof Provost CommitDate: 2025-01-14 08:54:17 +0000 pf: fixup af-to regression with match rules pfctl should not infer the af-to behavior from the af/naf difference. instead, we should be clear that this is an af-to rule. essentially this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so that we don't rely on ambiguous checks (like r->af != r->naf) when setting things up. positive review and comments from claudio, ok henning, sperreault Obtained from: OpenBSD, mikeb , fc302162c0 Sponsored by: Rubicon Communications, LLC ("Netgate") --- sbin/pfctl/parse.y | 36 +++++++++++++++++++++--------------- sbin/pfctl/pfctl_parser.c | 2 +- sys/netpfil/pf/pf.c | 4 ++-- sys/netpfil/pf/pf.h | 1 + 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/sbin/pfctl/parse.y b/sbin/pfctl/parse.y index 63bee3ab6a1c..3c34b0237895 100644 --- a/sbin/pfctl/parse.y +++ b/sbin/pfctl/parse.y @@ -382,7 +382,7 @@ void expand_eth_rule(struct pfctl_eth_rule *, struct node_host *, struct node_host *, const char *, const char *); void expand_rule(struct pfctl_rule *, struct node_if *, - struct node_host *, + struct redirspec *, struct redirspec *, struct node_host *, struct node_host *, struct node_proto *, struct node_os *, struct node_host *, struct node_port *, struct node_host *, struct node_port *, struct node_uid *, struct node_gid *, @@ -1079,9 +1079,8 @@ anchorrule : ANCHOR anchorname dir quick interface af proto fromto decide_address_family($8.src.host, &r.af); decide_address_family($8.dst.host, &r.af); - r.naf = r.af; - expand_rule(&r, $5, NULL, NULL, $7, $8.src_os, + expand_rule(&r, $5, NULL, NULL, NULL, NULL, $7, $8.src_os, $8.src.host, $8.src.port, $8.dst.host, $8.dst.port, $9.uid, $9.gid, $9.rcv, $9.icmpspec, pf->astack[pf->asd + 1] ? pf->alast->name : $2); @@ -1104,7 +1103,7 @@ anchorrule : ANCHOR anchorname dir quick interface af proto fromto decide_address_family($6.src.host, &r.af); decide_address_family($6.dst.host, &r.af); - expand_rule(&r, $3, NULL, NULL, $5, $6.src_os, + expand_rule(&r, $3, NULL, NULL, NULL, NULL, $5, $6.src_os, $6.src.host, $6.src.port, $6.dst.host, $6.dst.port, 0, 0, 0, 0, $2); free($2); @@ -1146,7 +1145,7 @@ anchorrule : ANCHOR anchorname dir quick interface af proto fromto r.dst.port_op = $6.dst.port->op; } - expand_rule(&r, $3, NULL, NULL, $5, $6.src_os, + expand_rule(&r, $3, NULL, NULL, NULL, NULL, $5, $6.src_os, $6.src.host, $6.src.port, $6.dst.host, $6.dst.port, 0, 0, 0, 0, $2); free($2); @@ -1469,7 +1468,7 @@ scrubrule : scrubaction dir logquick interface af proto fromto scrub_opts r.match_tag_not = $8.match_tag_not; r.rtableid = $8.rtableid; - expand_rule(&r, $4, NULL, NULL, $6, $7.src_os, + expand_rule(&r, $4, NULL, NULL, NULL, NULL, $6, $7.src_os, $7.src.host, $7.src.port, $7.dst.host, $7.dst.port, NULL, NULL, NULL, NULL, ""); } @@ -1634,7 +1633,7 @@ antispoof : ANTISPOOF logquick antispoof_ifspc af antispoof_opts { } if (h != NULL) - expand_rule(&r, j, NULL, NULL, NULL, NULL, h, + expand_rule(&r, j, NULL, NULL, NULL, NULL, NULL, NULL, h, NULL, NULL, NULL, NULL, NULL, NULL, NULL, ""); @@ -1656,7 +1655,7 @@ antispoof : ANTISPOOF logquick antispoof_ifspc af antispoof_opts { else h = ifa_lookup(i->ifname, 0); if (h != NULL) - expand_rule(&r, NULL, NULL, NULL, + expand_rule(&r, NULL, NULL, NULL, NULL, NULL, NULL, NULL, h, NULL, NULL, NULL, NULL, NULL, NULL, NULL, ""); } else @@ -2434,6 +2433,7 @@ pfrule : action dir logquick interface route af proto fromto "translation"); YYERROR; } + r.rule_flag |= PFRULE_AFTO; } r.af = $6; @@ -2721,7 +2721,6 @@ pfrule : action dir logquick interface route af proto fromto decide_address_family($8.src.host, &r.af); decide_address_family($8.dst.host, &r.af); - r.naf = r.af; if ($5.rt) { if (!r.direction) { @@ -2837,7 +2836,7 @@ pfrule : action dir logquick interface route af proto fromto YYERROR; } - expand_rule(&r, $4, $5.host, $9.nat.rdr ? $9.nat.rdr->host : NULL, + expand_rule(&r, $4, &$9.nat, &$9.rdr, $5.host, $9.nat.rdr ? $9.nat.rdr->host : NULL, $7, $8.src_os, $8.src.host, $8.src.port, $8.dst.host, $8.dst.port, $9.uid, $9.gid, $9.rcv, $9.icmpspec, ""); } @@ -4985,8 +4984,8 @@ natrule : nataction interface af proto fromto tag tagged rtable o = o->next; } - expand_rule(&r, $2, $9 == NULL ? NULL : $9->host, NULL, $4, - $5.src_os, $5.src.host, $5.src.port, $5.dst.host, + expand_rule(&r, $2, NULL, NULL, $9 == NULL ? NULL : $9->host, + NULL, $4, $5.src_os, $5.src.host, $5.src.port, $5.dst.host, $5.dst.port, 0, 0, 0, 0, ""); free($9); } @@ -5501,7 +5500,7 @@ filter_consistent(struct pfctl_rule *r, int anchor_call) "must not be used on match rules"); problems++; } - if (r->naf != r->af) { + if (r->rule_flag & PFRULE_AFTO) { yyerror("af-to is not supported on match rules"); problems++; } @@ -6139,7 +6138,8 @@ expand_eth_rule(struct pfctl_eth_rule *r, void expand_rule(struct pfctl_rule *r, - struct node_if *interfaces, struct node_host *rdr_hosts, + struct node_if *interfaces, struct redirspec *nat, + struct redirspec *rdr, struct node_host *rdr_hosts, struct node_host *nat_hosts, struct node_proto *protos, struct node_os *src_oses, struct node_host *src_hosts, struct node_port *src_ports, @@ -6179,7 +6179,13 @@ expand_rule(struct pfctl_rule *r, LOOP_THROUGH(struct node_uid, uid, uids, LOOP_THROUGH(struct node_gid, gid, gids, - r->af = af; + r->naf = r->af = af; + + if (r->rule_flag & PFRULE_AFTO) { + assert(nat != NULL); + r->naf = nat->af; + } + /* for link-local IPv6 address, interface must match up */ if ((r->af && src_host->af && r->af != src_host->af) || (r->af && dst_host->af && r->af != dst_host->af) || diff --git a/sbin/pfctl/pfctl_parser.c b/sbin/pfctl/pfctl_parser.c index 741915d41b0d..af10bdcf7e4b 100644 --- a/sbin/pfctl/pfctl_parser.c +++ b/sbin/pfctl/pfctl_parser.c @@ -1238,7 +1238,7 @@ print_rule(struct pfctl_rule *r, const char *anchor_call, int verbose, int numer #endif } if (!anchor_call[0] && ! TAILQ_EMPTY(&r->nat.list) && - r->naf != r->af) { + r->rule_flag & PFRULE_AFTO) { printf(" af-to %s from ", r->naf == AF_INET ? "inet" : "inet6"); print_pool(&r->nat, r->nat.proxy_port[0], r->nat.proxy_port[1], r->naf ? r->naf : r->af, PF_NAT); diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 335b192d454d..dd337c0aef93 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -5802,7 +5802,7 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm, pf_counter_u64_add_protected(&r->bytes[pd->dir == PF_OUT], pd->tot_len); pf_counter_u64_critical_exit(); pf_rule_to_actions(r, &pd->act); - if (r->naf) + if (r->rule_flag & PFRULE_AFTO) pd->naf = r->naf; if (pd->af != pd->naf) { if (pf_get_transaddr_af(r, pd) == -1) { @@ -5842,7 +5842,7 @@ nextrule: /* apply actions for last matching pass/block rule */ pf_rule_to_actions(r, &pd->act); - if (r->naf) + if (r->rule_flag & PFRULE_AFTO) pd->naf = r->naf; if (pd->af != pd->naf) { if (pf_get_transaddr_af(r, pd) == -1) { diff --git a/sys/netpfil/pf/pf.h b/sys/netpfil/pf/pf.h index 0d4d0a6a6f32..10431d9b77d9 100644 --- a/sys/netpfil/pf/pf.h +++ b/sys/netpfil/pf/pf.h @@ -617,6 +617,7 @@ struct pf_rule { #define PFRULE_IFBOUND 0x00010000 /* if-bound */ #define PFRULE_STATESLOPPY 0x00020000 /* sloppy state tracking */ #define PFRULE_PFLOW 0x00040000 +#define PFRULE_AFTO 0x00200000 /* af-to rule */ #ifdef _KERNEL #define PFRULE_REFS 0x0080 /* rule has references */