Module Name: src
Committed By: ozaki-r
Date: Mon Dec 16 05:21:24 UTC 2024
Modified Files:
src/sys/net: if_bridge.c
Log Message:
bridge: unify frame discarding paths (NFC)
To generate a diff of this commit:
cvs rdiff -u -r1.195 -r1.196 src/sys/net/if_bridge.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/net/if_bridge.c
diff -u src/sys/net/if_bridge.c:1.195 src/sys/net/if_bridge.c:1.196
--- src/sys/net/if_bridge.c:1.195 Mon Dec 16 05:20:31 2024
+++ src/sys/net/if_bridge.c Mon Dec 16 05:21:24 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: if_bridge.c,v 1.195 2024/12/16 05:20:31 ozaki-r Exp $ */
+/* $NetBSD: if_bridge.c,v 1.196 2024/12/16 05:21:24 ozaki-r Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.195 2024/12/16 05:20:31 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.196 2024/12/16 05:21:24 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -1816,8 +1816,7 @@ bridge_forward(struct bridge_softc *sc,
src_if = m_get_rcvif_psref(m, &psref_src);
if (src_if == NULL) {
/* Interface is being destroyed? */
- m_freem(m);
- goto out;
+ goto discard;
}
if_statadd2(&sc->sc_if, if_ipackets, 1, if_ibytes, m->m_pkthdr.len);
@@ -1828,8 +1827,7 @@ bridge_forward(struct bridge_softc *sc,
bif = bridge_lookup_member_if(sc, src_if, &psref);
if (bif == NULL) {
/* Interface is not a bridge member (anymore?) */
- m_freem(m);
- goto out;
+ goto discard;
}
if (bif->bif_flags & IFBIF_STP) {
@@ -1837,9 +1835,8 @@ bridge_forward(struct bridge_softc *sc,
case BSTP_IFSTATE_BLOCKING:
case BSTP_IFSTATE_LISTENING:
case BSTP_IFSTATE_DISABLED:
- m_freem(m);
bridge_release_member(sc, bif, &psref);
- goto out;
+ goto discard;
}
}
@@ -1864,9 +1861,8 @@ bridge_forward(struct bridge_softc *sc,
if ((bif->bif_flags & IFBIF_STP) != 0 &&
bif->bif_state == BSTP_IFSTATE_LEARNING) {
- m_freem(m);
bridge_release_member(sc, bif, &psref);
- goto out;
+ goto discard;
}
src_if_protected = ((bif->bif_flags & IFBIF_PROTECTED) != 0);
@@ -1884,22 +1880,18 @@ bridge_forward(struct bridge_softc *sc,
*/
if ((m->m_flags & (M_BCAST|M_MCAST)) == 0) {
dst_if = bridge_rtlookup(sc, eh->ether_dhost);
- if (src_if == dst_if) {
- m_freem(m);
- goto out;
- }
+ if (src_if == dst_if)
+ goto discard;
} else {
/* ...forward it to all interfaces. */
if_statinc(&sc->sc_if, if_imcasts);
dst_if = NULL;
}
- if (pfil_run_hooks(sc->sc_if.if_pfil, &m, src_if, PFIL_IN) != 0) {
- m_freem(m);
- goto out;
+ if (pfil_run_hooks(sc->sc_if.if_pfil, &m, src_if, PFIL_IN) != 0 ||
+ m == NULL) {
+ goto discard;
}
- if (m == NULL)
- goto out;
if (dst_if == NULL) {
bridge_broadcast(sc, src_if, src_if_protected, m);
@@ -1913,32 +1905,27 @@ bridge_forward(struct bridge_softc *sc,
* At this point, we're dealing with a unicast frame
* going to a different interface.
*/
- if ((dst_if->if_flags & IFF_RUNNING) == 0) {
- m_freem(m);
- goto out;
- }
+ if ((dst_if->if_flags & IFF_RUNNING) == 0)
+ goto discard;
bif = bridge_lookup_member_if(sc, dst_if, &psref);
if (bif == NULL) {
/* Not a member of the bridge (anymore?) */
- m_freem(m);
- goto out;
+ goto discard;
}
if (bif->bif_flags & IFBIF_STP) {
switch (bif->bif_state) {
case BSTP_IFSTATE_DISABLED:
case BSTP_IFSTATE_BLOCKING:
- m_freem(m);
bridge_release_member(sc, bif, &psref);
- goto out;
+ goto discard;
}
}
if ((bif->bif_flags & IFBIF_PROTECTED) && src_if_protected) {
- m_freem(m);
bridge_release_member(sc, bif, &psref);
- goto out;
+ goto discard;
}
bridge_release_member(sc, bif, &psref);
@@ -1957,6 +1944,10 @@ out:
if (src_if != NULL)
m_put_rcvif_psref(src_if, &psref_src);
return;
+
+discard:
+ m_freem(m);
+ goto out;
}
static bool