User reported netlink-related panic kern/270813 when unloading if_ena kernel module.
The crash happens when the swi-enqueued link state event is triggered. By the time of execution, the ifp in question and its resources are already freed, triggering the panic.
The following call chain leads to this:
ena_detach() ether_ifdetach() if_detach() if_detach_internal() # here we drain taskqueue_swi from link events ena_destroy_device() if_link_state_change() # here we enqueue new link event
In order to fix the bug, this change proposes ignoring all link state events after ifnet was unlinked. The implementation assumes that the destruction happens in the single thread and avoid lock-based flag checking.