From nobody Mon Apr 22 16:04:23 2024 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 4VNVS71yBPz5HN9M; Mon, 22 Apr 2024 16:04:23 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VNVS71VKsz456x; Mon, 22 Apr 2024 16:04:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713801863; 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=2vJtOyBGtu0rmVJd+Wc7SXUSsgFvIlhdnGGkN1kaB8E=; b=S5DLW24o+tCgN5o2k1lHT2BZ0NKxFM9hqIF7uB0bwCvJY44aovU8DbGYnK2X5uCp9aqyHg Jfjdp0+BHvws822WgAQKToiF3VU9s9xuMqj0k3xKiyBdC0F4KKIVbyvqNy2oe8KycSdSxW 59bs09KLFdRTWDN5IOInlRspYCcQayb2WWbIcNy0oriYLhJqItKJZukGfkLpR8kbR13Yhg HdLmI1/SjrBqk7fg9xpflYIIr2pt1cVSwKeTUC1YyWZj8Hk7XSNKdEyqHeUxxta/iR22Gl lfl/WnYh0ehKixVNA8IXMOHqXrfhBvpqaN+Sqp0fGgzMlG2whNBmVsdSVwMSrw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713801863; a=rsa-sha256; cv=none; b=tfKEn1lW03RKyVTzKkFQ1QRRxM9IxrIz8247OMC+IzYmmq8mAxIDFuC8YompHK/0JYPy+V I7l/dopfavBFrQqj3vdwzshYEo1bzQYL4RJv4mcjQmfIBdm9zafh7b5JxYIvJiiSsyEf+E GwHNc5EVpDujCD8xQk+wn2wnJqnZFB+oouK4uIWSeI0gy6WdfOpQ/Y58+M4CRqISRE/VFB m6HhTaq89Lhu8GGYNbgcEfRKFE2XNHMwM3VWAh7dBtzL8sBcD76F7iK1HVpczJHOVoczyA PguUb66S3r3p4noGhVe9X12Buih/LefD+TGsNl7CwGSwnjdT4cq3e2oVBdAynQ== 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=1713801863; 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=2vJtOyBGtu0rmVJd+Wc7SXUSsgFvIlhdnGGkN1kaB8E=; b=wvWHeTNsyWhMTDZRXI4sIWvaRm4CTKDUyprG7bmxTowSdADJEJgRYDljEAZydcRL4uvxmo 6ngmzR2/5dGPeD7LX2fZd+CjPKpURkBu6Di+qzh8WIKg52zGFGArX3FxPM9eZJE1kFlTMY eFb9vXSCB/Fv/MdXC5fJqf9v0jEe5Ob81DdmmHKXELVWx/x3nrGicTuA80o6H94THFibm4 bbrjaaoHb5S7MAgSKEwF94CawMgoQsa9uE0XhPvrkkgAQXDO2CdPA5kmBqChYDyOtcQ2M2 ol4DnBDpgALZD7si5Evgz4LVWkmRh7eGjza/J/Jk3w1M0glsyPTFUY0IgzatJA== 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 4VNVS715p2zvTZ; Mon, 22 Apr 2024 16:04:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43MG4NI2058935; Mon, 22 Apr 2024 16:04:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43MG4NIT058932; Mon, 22 Apr 2024 16:04:23 GMT (envelope-from git) Date: Mon, 22 Apr 2024 16:04:23 GMT Message-Id: <202404221604.43MG4NIT058932@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: ef84dd8f4926 - main - if_bridge: clean up INET/INET6 handling 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ef84dd8f4926304306d5989ca9afdbf760c6d813 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=ef84dd8f4926304306d5989ca9afdbf760c6d813 commit ef84dd8f4926304306d5989ca9afdbf760c6d813 Author: Lexi Winter AuthorDate: 2024-04-21 18:56:23 +0000 Commit: Mark Johnston CommitDate: 2024-04-22 16:01:27 +0000 if_bridge: clean up INET/INET6 handling The if_bridge contains several instances of: if (AF_INET code ... #ifdef INET6 AF_INET6 code ... #endif ) { ... Clean this up by adding a couple of macros at the top of the file that are conditionally defined based on whether INET and/or INET6 are enabled, which makes the code more readable and easier to maintain. No functional change intended. Reviewed by: zlei, markj MFC after: 1 week Pull Request: https://github.com/freebsd/freebsd-src/pull/1191 --- sys/net/if_bridge.c | 65 +++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c index 31758733adb1..1b4ac92b62a3 100644 --- a/sys/net/if_bridge.c +++ b/sys/net/if_bridge.c @@ -134,6 +134,31 @@ #include +/* + * At various points in the code we need to know if we're hooked into the INET + * and/or INET6 pfil. Define some macros to do that based on which IP versions + * are enabled in the kernel. This avoids littering the rest of the code with + * #ifnet INET6 to avoid referencing V_inet6_pfil_head. + */ +#ifdef INET6 +#define PFIL_HOOKED_IN_INET6 PFIL_HOOKED_IN(V_inet6_pfil_head) +#define PFIL_HOOKED_OUT_INET6 PFIL_HOOKED_OUT(V_inet6_pfil_head) +#else +#define PFIL_HOOKED_IN_INET6 false +#define PFIL_HOOKED_OUT_INET6 false +#endif + +#ifdef INET +#define PFIL_HOOKED_IN_INET PFIL_HOOKED_IN(V_inet_pfil_head) +#define PFIL_HOOKED_OUT_INET PFIL_HOOKED_OUT(V_inet_pfil_head) +#else +#define PFIL_HOOKED_IN_INET false +#define PFIL_HOOKED_OUT_INET false +#endif + +#define PFIL_HOOKED_IN_46 (PFIL_HOOKED_IN_INET6 || PFIL_HOOKED_IN_INET) +#define PFIL_HOOKED_OUT_46 (PFIL_HOOKED_OUT_INET6 || PFIL_HOOKED_OUT_INET) + /* * Size of the route hash table. Must be a power of two. */ @@ -2127,11 +2152,7 @@ bridge_dummynet(struct mbuf *m, struct ifnet *ifp) return; } - if (PFIL_HOOKED_OUT(V_inet_pfil_head) -#ifdef INET6 - || PFIL_HOOKED_OUT(V_inet6_pfil_head) -#endif - ) { + if (PFIL_HOOKED_OUT_46) { if (bridge_pfil(&m, sc->sc_ifp, ifp, PFIL_OUT) != 0) return; if (m == NULL) @@ -2429,11 +2450,7 @@ bridge_forward(struct bridge_softc *sc, struct bridge_iflist *sbif, ETHER_BPF_MTAP(ifp, m); /* run the packet filter */ - if (PFIL_HOOKED_IN(V_inet_pfil_head) -#ifdef INET6 - || PFIL_HOOKED_IN(V_inet6_pfil_head) -#endif - ) { + if (PFIL_HOOKED_IN_46) { if (bridge_pfil(&m, ifp, src_if, PFIL_IN) != 0) return; if (m == NULL) @@ -2465,11 +2482,7 @@ bridge_forward(struct bridge_softc *sc, struct bridge_iflist *sbif, dbif->bif_stp.bp_state == BSTP_IFSTATE_DISCARDING) goto drop; - if (PFIL_HOOKED_OUT(V_inet_pfil_head) -#ifdef INET6 - || PFIL_HOOKED_OUT(V_inet6_pfil_head) -#endif - ) { + if (PFIL_HOOKED_OUT_46) { if (bridge_pfil(&m, ifp, dst_if, PFIL_OUT) != 0) return; if (m == NULL) @@ -2626,12 +2639,6 @@ bridge_input(struct ifnet *ifp, struct mbuf *m) #define CARP_CHECK_WE_ARE_SRC(iface) false #endif -#ifdef INET6 -#define PFIL_HOOKED_INET6 PFIL_HOOKED_IN(V_inet6_pfil_head) -#else -#define PFIL_HOOKED_INET6 false -#endif - #ifdef DEV_NETMAP #define GRAB_FOR_NETMAP(ifp, m) do { \ if ((if_getcapenable(ifp) & IFCAP_NETMAP) != 0 && \ @@ -2670,8 +2677,7 @@ bridge_input(struct ifnet *ifp, struct mbuf *m) /* Hand the packet over to netmap if necessary. */ \ GRAB_FOR_NETMAP(bifp, m); \ /* Filter on the physical interface. */ \ - if (V_pfil_local_phys && (PFIL_HOOKED_IN(V_inet_pfil_head) || \ - PFIL_HOOKED_INET6)) { \ + if (V_pfil_local_phys && PFIL_HOOKED_IN_46) { \ if (bridge_pfil(&m, NULL, ifp, \ PFIL_IN) != 0 || m == NULL) { \ return (NULL); \ @@ -2710,7 +2716,6 @@ bridge_input(struct ifnet *ifp, struct mbuf *m) #undef CARP_CHECK_WE_ARE_DST #undef CARP_CHECK_WE_ARE_SRC -#undef PFIL_HOOKED_INET6 #undef GRAB_FOR_NETMAP #undef GRAB_OUR_PACKETS @@ -2765,11 +2770,7 @@ bridge_broadcast(struct bridge_softc *sc, struct ifnet *src_if, sbif = bridge_lookup_member_if(sc, src_if); /* Filter on the bridge interface before broadcasting */ - if (runfilt && (PFIL_HOOKED_OUT(V_inet_pfil_head) -#ifdef INET6 - || PFIL_HOOKED_OUT(V_inet6_pfil_head) -#endif - )) { + if (runfilt && PFIL_HOOKED_OUT_46) { if (bridge_pfil(&m, sc->sc_ifp, NULL, PFIL_OUT) != 0) return; if (m == NULL) @@ -2812,11 +2813,7 @@ bridge_broadcast(struct bridge_softc *sc, struct ifnet *src_if, * pointer so we do not redundantly filter on the bridge for * each interface we broadcast on. */ - if (runfilt && (PFIL_HOOKED_OUT(V_inet_pfil_head) -#ifdef INET6 - || PFIL_HOOKED_OUT(V_inet6_pfil_head) -#endif - )) { + if (runfilt && PFIL_HOOKED_OUT_46) { if (used == 0) { /* Keep the layer3 header aligned */ i = min(mc->m_pkthdr.len, max_protohdr);