Index: sys/net/if.c =================================================================== --- sys/net/if.c +++ sys/net/if.c @@ -615,6 +615,8 @@ struct ifnet *ifp; ifp = __containerof(ctx, struct ifnet, if_epoch_ctx); + if (ifp->if_cleanup != NULL) + ifp->if_cleanup(ifp); if_free_internal(ifp); } Index: sys/net/if_lagg.c =================================================================== --- sys/net/if_lagg.c +++ sys/net/if_lagg.c @@ -129,6 +129,7 @@ static void lagg_init(void *); static void lagg_stop(struct lagg_softc *); static int lagg_ioctl(struct ifnet *, u_long, caddr_t); +static void lagg_cleanup(struct ifnet *); #ifdef RATELIMIT static int lagg_snd_tag_alloc(struct ifnet *, union if_snd_tag_alloc_params *, @@ -511,6 +512,7 @@ ifp->if_init = lagg_init; ifp->if_ioctl = lagg_ioctl; ifp->if_get_counter = lagg_get_counter; + ifp->if_cleanup = lagg_cleanup; ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST; #ifdef RATELIMIT ifp->if_snd_tag_alloc = lagg_snd_tag_alloc; @@ -568,6 +570,12 @@ LAGG_LIST_LOCK(); SLIST_REMOVE(&V_lagg_list, sc, lagg_softc, sc_entries); LAGG_LIST_UNLOCK(); +} + +static void +lagg_cleanup(struct ifnet *ifp) +{ + struct lagg_softc *sc = ifp->if_softc; LAGG_SX_DESTROY(sc); free(sc, M_DEVBUF); Index: sys/net/if_var.h =================================================================== --- sys/net/if_var.h +++ sys/net/if_var.h @@ -133,6 +133,7 @@ typedef void (*if_qflush_fn_t)(if_t); typedef int (*if_transmit_fn_t)(if_t, struct mbuf *); typedef uint64_t (*if_get_counter_t)(if_t, ift_counter); +typedef void (*if_cleanup_fn_t)(if_t); struct ifnet_hw_tsomax { u_int tsomaxbytes; /* TSO total burst length limit in bytes */ @@ -331,7 +332,8 @@ int (*if_resolvemulti) /* validate/resolve multicast */ (struct ifnet *, struct sockaddr **, struct sockaddr *); if_qflush_fn_t if_qflush; /* flush any queue */ - if_transmit_fn_t if_transmit; /* initiate output routine */ + if_transmit_fn_t if_transmit; /* initiate output routine */ + if_cleanup_fn_t if_cleanup; /* clean up and free softc */ void (*if_reassign) /* reassign to vnet routine */ (struct ifnet *, struct vnet *, char *);