From nobody Thu Sep 19 20:21:26 2024 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 4X8n3W0wvfz5XKyC; Thu, 19 Sep 2024 20:21:27 +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 4X8n3V588nz4XD9; Thu, 19 Sep 2024 20:21:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726777286; 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=Pg0X9wCl4dKKgSdcF4iZmesTuAoJlPinTjUqEq3Rdqg=; b=jTrnJ5Qo5KLf2KiKg/2Fu4f7pCaVZ6ycFNCFB0/s8Z8Zun4rFf7XKECdjd1LqSLLrP96gV NFSQNjVwoM3kXeSjlg50GDsrUiQEpoPMs2t8tP6/z4N4XXeNJWBc8HNASUFN3WhZwBt/xz +D3w/pPvinzVhCsGHAOYwIZBVph2+mmf0efZcEJR6WMaSM/5hbyOP0MnQdXjlereU5pcmJ 3930FI3snvcWTZ2Z1CccFpNbsSxmqKl5Xe6+mmtFuUZoc+H9Qj52/zIe2ciZT4HE/+izu9 7LKjxZ7b/1c4mIJ6AXlApZvM6cVK9fh1FZ0plF1eNLoIKvf4FBlONyjbB8vIZQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726777286; a=rsa-sha256; cv=none; b=xlv1RpDQWnm+VjxSMXEWFSqqlgzNjnKIdZKOWPpEOh4sltyE8L7hYL10QGfw1qVu3fRH9b qp7Sh4oRmNxb/lo56Y/6+iAMgfsZv8zIPruxebvy4xKvy76aKOTggKyaFFqe22HYFc0h/9 X9DssaiRA4r4W64YDhaLDryjKYi8ivLkkyrM7wEOrLlBVWlapitSkAr/oEcaqoH6Cy3JqQ uuh3lDzrVh01A+HVFzB+FkyA7lIN4oARf6hCnLfW8VbDPuR4T2EqVr3Tml+mQqePX53eEo FpF6auawP89zW0qJPGQMTroEZcM1FaGootVnBHZvYxLUu6+rEKX9fHxquPLPBQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726777286; 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=Pg0X9wCl4dKKgSdcF4iZmesTuAoJlPinTjUqEq3Rdqg=; b=FNhEDPdEnG7sXBAqgKTIaRTDk8rxXPz8R0pLUFkoRU5o1yKDR+HyIrCgcj7AGZaspDT5dO RvSPERZXUyL3PK8L/hW8kGus9NnrDn+NImMszuT46IcwPWmEh2fEkaye1oYM9HZ785bbTN c/ecde01x3OpbbuxnycM0fz4AOsTy6dKRdOaTB1GLWpbdpMeYrArFjgIN4Gft/JnggFdQL 9KJLHKX89P0s/UwyXzxEuI2lnND29W7ZPAgkW318i1inIRqiC+8tRc773ogyd4mASaNOgQ 2/IDKtmj2IcTEg7OQWN5Wr73ISeZoWVNIfp6ekvYsQyTJwQBi87yHXHu3mjcgg== 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 4X8n3V4mP1zKt2; Thu, 19 Sep 2024 20:21:26 +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 48JKLQDt046761; Thu, 19 Sep 2024 20:21:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48JKLQHm046758; Thu, 19 Sep 2024 20:21:26 GMT (envelope-from git) Date: Thu, 19 Sep 2024 20:21:26 GMT Message-Id: <202409192021.48JKLQHm046758@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: 7d381d0a5b50 - main - pf: exclude link local address from the dynamic interface address pool 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: 7d381d0a5b50539638a2460c9ae2213af5c3fad8 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=7d381d0a5b50539638a2460c9ae2213af5c3fad8 commit 7d381d0a5b50539638a2460c9ae2213af5c3fad8 Author: Kristof Provost AuthorDate: 2024-09-05 15:38:20 +0000 Commit: Kristof Provost CommitDate: 2024-09-19 20:20:14 +0000 pf: exclude link local address from the dynamic interface address pool so that rules like "pass out on vr1 inet6 nat-to (vr1)" won't map to the non routable ipv6 link local address; with suggestions and ok claudio, henning Reviewed by: zlei Obtained from: OpenBSD, mikeb , e41548933f Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D46594 --- sys/net/pfvar.h | 4 +++- sys/netpfil/pf/pf_lb.c | 17 +++++++++++++---- sys/netpfil/pf/pf_table.c | 9 ++++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index 8335fbfaedb8..a5a0ed257ef3 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1228,6 +1228,7 @@ typedef void pfsync_clear_states_t(u_int32_t, const char *); typedef int pfsync_defer_t(struct pf_kstate *, struct mbuf *); typedef void pfsync_detach_ifnet_t(struct ifnet *); typedef void pflow_export_state_t(const struct pf_kstate *); +typedef bool pf_addr_filter_func_t(const sa_family_t, const struct pf_addr *); VNET_DECLARE(pfsync_state_import_t *, pfsync_state_import_ptr); #define V_pfsync_state_import_ptr VNET(pfsync_state_import_ptr) @@ -2429,7 +2430,8 @@ void pfr_cleanup(void); int pfr_match_addr(struct pfr_ktable *, struct pf_addr *, sa_family_t); void pfr_update_stats(struct pfr_ktable *, struct pf_addr *, sa_family_t, u_int64_t, int, int, int); -int pfr_pool_get(struct pfr_ktable *, int *, struct pf_addr *, sa_family_t); +int pfr_pool_get(struct pfr_ktable *, int *, struct pf_addr *, sa_family_t, + pf_addr_filter_func_t); void pfr_dynaddr_update(struct pfr_ktable *, struct pfi_dynaddr *); struct pfr_ktable * pfr_attach_table(struct pf_kruleset *, char *); diff --git a/sys/netpfil/pf/pf_lb.c b/sys/netpfil/pf/pf_lb.c index 6541a42aa236..b322bd65cfd3 100644 --- a/sys/netpfil/pf/pf_lb.c +++ b/sys/netpfil/pf/pf_lb.c @@ -71,6 +71,7 @@ static int pf_get_sport(sa_family_t, uint8_t, struct pf_krule *, struct pf_addr *, uint16_t, struct pf_addr *, uint16_t, struct pf_addr *, uint16_t *, uint16_t, uint16_t, struct pf_ksrc_node **, struct pf_udp_mapping **); +static bool pf_islinklocal(const sa_family_t, const struct pf_addr *); #define mix(a,b,c) \ do { \ @@ -401,6 +402,14 @@ failed: return (1); /* none available */ } +static bool +pf_islinklocal(const sa_family_t af, const struct pf_addr *addr) +{ + if (af == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&addr->v6)) + return (true); + return (false); +} + static int pf_get_mape_sport(sa_family_t af, u_int8_t proto, struct pf_krule *r, struct pf_addr *saddr, uint16_t sport, struct pf_addr *daddr, @@ -585,11 +594,11 @@ pf_map_addr(sa_family_t af, struct pf_krule *r, struct pf_addr *saddr, if (rpool->cur->addr.type == PF_ADDR_TABLE) { if (!pfr_pool_get(rpool->cur->addr.p.tbl, - &rpool->tblidx, &rpool->counter, af)) + &rpool->tblidx, &rpool->counter, af, NULL)) goto get_addr; } else if (rpool->cur->addr.type == PF_ADDR_DYNIFTL) { if (!pfr_pool_get(rpool->cur->addr.p.dyn->pfid_kt, - &rpool->tblidx, &rpool->counter, af)) + &rpool->tblidx, &rpool->counter, af, pf_islinklocal)) goto get_addr; } else if (pf_match_addr(0, raddr, rmask, &rpool->counter, af)) goto get_addr; @@ -602,7 +611,7 @@ pf_map_addr(sa_family_t af, struct pf_krule *r, struct pf_addr *saddr, if (rpool->cur->addr.type == PF_ADDR_TABLE) { rpool->tblidx = -1; if (pfr_pool_get(rpool->cur->addr.p.tbl, - &rpool->tblidx, &rpool->counter, af)) { + &rpool->tblidx, &rpool->counter, af, NULL)) { /* table contains no address of type 'af' */ if (rpool->cur != acur) goto try_next; @@ -612,7 +621,7 @@ pf_map_addr(sa_family_t af, struct pf_krule *r, struct pf_addr *saddr, } else if (rpool->cur->addr.type == PF_ADDR_DYNIFTL) { rpool->tblidx = -1; if (pfr_pool_get(rpool->cur->addr.p.dyn->pfid_kt, - &rpool->tblidx, &rpool->counter, af)) { + &rpool->tblidx, &rpool->counter, af, pf_islinklocal)) { /* table contains no address of type 'af' */ if (rpool->cur != acur) goto try_next; diff --git a/sys/netpfil/pf/pf_table.c b/sys/netpfil/pf/pf_table.c index 4d248e40443d..690cb6d9ab90 100644 --- a/sys/netpfil/pf/pf_table.c +++ b/sys/netpfil/pf/pf_table.c @@ -2240,7 +2240,7 @@ pfr_detach_table(struct pfr_ktable *kt) int pfr_pool_get(struct pfr_ktable *kt, int *pidx, struct pf_addr *counter, - sa_family_t af) + sa_family_t af, pf_addr_filter_func_t filter) { struct pf_addr addr, cur, mask, umask_addr; union sockaddr_union uaddr, umask; @@ -2299,6 +2299,10 @@ _next_block: if (!KENTRY_NETWORK(ke)) { /* this is a single IP address - no possible nested block */ + if (filter && filter(af, &addr)) { + idx++; + goto _next_block; + } PF_ACPY(counter, &addr, af); *pidx = idx; pfr_kstate_counter_add(&kt->pfrkt_match, 1); @@ -2319,12 +2323,15 @@ _next_block: /* no need to check KENTRY_RNF_ROOT() here */ if (ke2 == ke) { /* lookup return the same block - perfect */ + if (filter && filter(af, &addr)) + goto _next_entry; PF_ACPY(counter, &addr, af); *pidx = idx; pfr_kstate_counter_add(&kt->pfrkt_match, 1); return (0); } +_next_entry: /* we need to increase the counter past the nested block */ pfr_prepare_network(&umask, AF_INET, ke2->pfrke_net); pfr_sockaddr_to_pf_addr(&umask, &umask_addr);