An interface will be removed from the global network interface list when
is requested to be detached, either by user or by a hardware event. Once
detached, network applications or sysadmin tools, e.g. ifmcstat(8) and
ifconfig(8), shall make reference to it.
As for moving interface between vnet jails, the interface will be
detached from one jail and later be attached to another. An interface
belongs only to one vnet jail at the same time, so the above statement
still applies.
There're reports that show races between the teardown process and output
path. That, a thread on output path is entering net epoch and is
referencing a detached interface, while the detaching thread is
deallocating resources binded to the interface, notably the address
family dependent data, e.g., if_afdata[AF_INET6]. That will lead to
either NULL pointer derefence or accessing to freed memory.
There're still cases to make references to an interface, so leave
ifnet_byindex() unchanged but introduce a _attached variant. It filter
only attached ifnet. The _ref variant is redireced to use the _attached
variant. The outpaths are all converted to use the _attached or the _ref
variant.
PR: 279653
PR: 285129
MFC after: 1 month