Registering and Unregistering Devices
Network devices are registered and
unregistered with the kernel with register_netdev and
unregister_netdev, respectively. These are simple
wrappers that take care of locking and then invoke the routines register_netdevice and unregister_netdevice, respectively. We already briefly introduced these
functions in Figure 8-1. All of them are
defined in net/core/dev.c.
Figure 8-4 shows the registration
states a net_device can be set to, and shows where the
aforementioned routines come into the picture. It also shows where other key routines are
called. All of them will be described in later sections. In particular, note that:
Changes of state may use intermediate states between
NETREG_UNINITIALIZEDandNETREG_REGISTERED. These progressions are handled bynetdev_run_todo, described in the section "Split Operations: netdev_run_todo."The two
net_devicevirtual functionsinitanduninitcan be used by device drivers to initialize and clean up private data, respectively, when registering and unregistering a device. They are mainly used by virtual devices. See the section "Virtual Devices."The unregistration of a device cannot be completed until all references to the associated
net_devicedata structure have been released:netdev_wait_allrefsdoes not return until that condition is met. See the section "Reference Counts."Both the registration and unregistration of a device are completed by
netdev_run_todo. We will see in the section "Split Operations: netdev_run_todo ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access