git: 6a0355a0fe75 - stable/12 - bridge: Remove members when assigned to a new vnet

Kristof Provost kp at FreeBSD.org
Tue Mar 2 15:17:48 UTC 2021


The branch stable/12 has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=6a0355a0fe751368c66ea2e7debee86badb50d2a

commit 6a0355a0fe751368c66ea2e7debee86badb50d2a
Author:     Kristof Provost <kp at FreeBSD.org>
AuthorDate: 2021-02-21 20:20:32 +0000
Commit:     Kristof Provost <kp at FreeBSD.org>
CommitDate: 2021-03-02 08:31:02 +0000

    bridge: Remove members when assigned to a new vnet
    
    When the bridge is moved to a different vnet we must remove all of its
    member interfaces (and span interfaces), because we don't know if those
    will be moved along with it. We don't want to hold references to
    interfaces not in our vnet.
    
    Reviewed by:    donner@
    MFC after:      1 week
    Sponsored by:   Orange Business Services
    Differential Revision:  https://reviews.freebsd.org/D28859
    
    (cherry picked from commit 38c0951386d82f4c51cf4e245253cdef18d2254a)
---
 sys/net/ethernet.h     |  4 ++++
 sys/net/if_bridge.c    | 25 +++++++++++++++++++++++++
 sys/net/if_ethersubr.c |  3 ---
 3 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/sys/net/ethernet.h b/sys/net/ethernet.h
index fdfc41b55037..1f718e6e69d2 100644
--- a/sys/net/ethernet.h
+++ b/sys/net/ethernet.h
@@ -429,6 +429,10 @@ extern	uint32_t ether_crc32_be(const uint8_t *, size_t);
 extern	void ether_demux(struct ifnet *, struct mbuf *);
 extern	void ether_ifattach(struct ifnet *, const u_int8_t *);
 extern	void ether_ifdetach(struct ifnet *);
+#ifdef VIMAGE
+struct vnet;
+extern	void ether_reassign(struct ifnet *, struct vnet *, char *);
+#endif
 extern	int  ether_ioctl(struct ifnet *, u_long, caddr_t);
 extern	int  ether_output(struct ifnet *, struct mbuf *,
 	    const struct sockaddr *, struct route *);
diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c
index 6ff9cd95e090..4e5c9ada12d1 100644
--- a/sys/net/if_bridge.c
+++ b/sys/net/if_bridge.c
@@ -674,6 +674,28 @@ SYSCTL_PROC(_net_link_bridge, OID_AUTO, ipfw,
     &VNET_NAME(pfil_ipfw), 0, &sysctl_pfil_ipfw, "I",
     "Layer2 filter with IPFW");
 
+#ifdef VIMAGE
+static void
+bridge_reassign(struct ifnet *ifp, struct vnet *newvnet, char *arg)
+{
+	struct bridge_softc *sc = ifp->if_softc;
+	struct bridge_iflist *bif;
+
+	BRIDGE_LOCK(sc);
+
+	while ((bif = CK_LIST_FIRST(&sc->sc_iflist)) != NULL)
+		bridge_delete_member(sc, bif, 0);
+
+	while ((bif = CK_LIST_FIRST(&sc->sc_spanlist)) != NULL) {
+		bridge_delete_span(sc, bif);
+	}
+
+	BRIDGE_UNLOCK(sc);
+
+	ether_reassign(ifp, newvnet, arg);
+}
+#endif
+
 /*
  * bridge_clone_create:
  *
@@ -756,6 +778,9 @@ bridge_clone_create(struct if_clone *ifc, int unit, caddr_t params)
 	/* Now undo some of the damage... */
 	ifp->if_baudrate = 0;
 	ifp->if_type = IFT_BRIDGE;
+#ifdef VIMAGE
+	ifp->if_reassign = bridge_reassign;
+#endif
 
 	BRIDGE_LIST_LOCK();
 	LIST_INSERT_HEAD(&V_bridge_list, sc, sc_list);
diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c
index 532d6a7a342b..5e255f862221 100644
--- a/sys/net/if_ethersubr.c
+++ b/sys/net/if_ethersubr.c
@@ -117,9 +117,6 @@ static const u_char etherbroadcastaddr[ETHER_ADDR_LEN] =
 
 static	int ether_resolvemulti(struct ifnet *, struct sockaddr **,
 		struct sockaddr *);
-#ifdef VIMAGE
-static	void ether_reassign(struct ifnet *, struct vnet *, char *);
-#endif
 static	int ether_requestencap(struct ifnet *, struct if_encap_req *);
 
 


More information about the dev-commits-src-all mailing list