git: 960c5bb0f6bf - main - if_vxlan(4): Invoke vxlan_stop event handler only when the interface is configured

From: Zhenlei Huang <zlei_at_FreeBSD.org>
Date: Tue, 21 Jan 2025 15:03:05 UTC
The branch main has been updated by zlei:

URL: https://cgit.FreeBSD.org/src/commit/?id=960c5bb0f6bf44aeb09fa14fd0f82c2e82ebe2e2

commit 960c5bb0f6bf44aeb09fa14fd0f82c2e82ebe2e2
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2025-01-21 15:02:13 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2025-01-21 15:02:13 +0000

    if_vxlan(4): Invoke vxlan_stop event handler only when the interface is configured
    
    It is harmless but pointless to invoke vxlan_stop event handler when the
    interface was not previously configured. This change will also prevent
    an assert panic from t4_vxlan_stop_handler().
    
    Reviewed by:    kib
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D48494
---
 sys/net/if_vxlan.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/sys/net/if_vxlan.c b/sys/net/if_vxlan.c
index bb2de793550f..b7af304e3126 100644
--- a/sys/net/if_vxlan.c
+++ b/sys/net/if_vxlan.c
@@ -1813,6 +1813,7 @@ vxlan_teardown_locked(struct vxlan_softc *sc)
 {
 	struct ifnet *ifp;
 	struct vxlan_socket *vso;
+	bool running;
 
 	sx_assert(&vxlan_sx, SA_XLOCKED);
 	VXLAN_LOCK_WASSERT(sc);
@@ -1820,6 +1821,7 @@ vxlan_teardown_locked(struct vxlan_softc *sc)
 
 	ifp = sc->vxl_ifp;
 	ifp->if_flags &= ~IFF_UP;
+	running = (ifp->if_drv_flags & IFF_DRV_RUNNING) != 0;
 	ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
 	callout_stop(&sc->vxl_callout);
 	vso = sc->vxl_sock;
@@ -1827,8 +1829,10 @@ vxlan_teardown_locked(struct vxlan_softc *sc)
 
 	VXLAN_WUNLOCK(sc);
 	if_link_state_change(ifp, LINK_STATE_DOWN);
-	EVENTHANDLER_INVOKE(vxlan_stop, ifp, sc->vxl_src_addr.in4.sin_family,
-	    ntohs(sc->vxl_src_addr.in4.sin_port));
+	if (running)
+		EVENTHANDLER_INVOKE(vxlan_stop, ifp,
+		    sc->vxl_src_addr.in4.sin_family,
+		    ntohs(sc->vxl_src_addr.in4.sin_port));
 
 	if (vso != NULL) {
 		vxlan_socket_remove_softc(vso, sc);