diff --git a/sys/net/if.c b/sys/net/if.c --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1235,6 +1235,22 @@ #ifdef VIMAGE finish_vnet_shutdown: #endif + /* + * Objects associated with this ifnet have been deregistered from + * tables/lists here, but other threads may still reference the + * objects (e.g. nhop_objects). We need to clear ifp->if_afdata[] + * after the refereces are finished because other threads may access + * the contents of ifp->if_afdata[] in such references + * (in6_selecthlim() for example). + * Those references are (and should be) guarded by the net_epoch + * so we can wait for the end of the reference with + * epoch_wait_preempt() and NET_EPOCH_DRAIN_CALLBACKS(). + * After these calls, objects assosiated with this ifnet are + * not kept referenced or will not be fetched because they are + * deregistered from tables/lists. + */ + NET_EPOCH_WAIT(); + NET_EPOCH_DRAIN_CALLBACKS(); /* * We cannot hold the lock over dom_ifdetach calls as they might * sleep, for example trying to drain a callout, thus open up the