Understanding. Linux. Network. internals Reading Notes chapte8 Network Device

Source: Internet
Author: User

After reading chapter 1, I will go back to some knowledge points of chapter 5, chapter 5, and Chapter 7. This chapter mainly describes the registration, cancellation, activation, and prohibition of registration of devices.
When is the device registered?
1) when the driver is loaded (registration at startup of the statically compiled kernel, registration at loading of the dynamic module)
2) When a hot swapping device is inserted (the kernel notifies its device driver to register the device during the insertion) the registration of a device is actually completed by executing the pci_driver-> probe function (when to call probe, refer to the previous chapters). The process is as follows: alloc_netdev allocates memory blocks (including the net_device structure, private driver data blocks, and forced alignment filling data ),
Xxx_setup (Dev) initializes the net_device structure (only initializes the fields and function pointers shared by any Ethernet Card)
Netdev_boot_setup_check checks whether the user provides parameters when loading the kernel,
Register_netdev (Dev) (the main function in registration) inserts the new net_device into dev_base. The register_netdev process is protected by rtnl_lock rtnl_unlock because of the change in the net_device structure, therefore, the register_netdev function obtains the lock at the beginning and releases the lock before the return. Once register_netdevice completes its work, it will call net_set_todo to add the new net_device to net_todo_list, this list contains the registered devices. Finally, rtnl_unlock not only releases the lock, but also calls the netdev_run_todo function, which scans net_todo_list to complete registration.
Register_netdevice:
1) initialize some net_device Fields
2) The allow_divert_blk function allocates the configuration blocks required by the feature and connects them to Dev-> divert.
3) execute the custom initialization function of the driver.
4) The dev_new_index function assigns a unique identifier.
5) add net_device to the global linked list dev_base and insert it into the dev_name_base and dev_index_head hash tables (for searching)
6) check whether the feature mark is valid
7) set the _ link_state_present flag in Dev-> state.
8) initialize queue rules and Traffic Control
9) netdev_chain notifies all subsystems interested in the device
10) Call netdev_run_todo to update Dev-> reg_state and register the device in the sysfs File System to log out.
When will the device be canceled?
1) uninstall the driver
2) remove hot swapping Devices
The device logout is performed by the pci_driver-> remove function. The process is as follows: unregister_netdevice performs the following operations;
1) if the device is not disabled at this time, call dev_close to disable it.
2) Delete the net_device structure from dev_base and delete the device from the two hash tables.
3) Call the dev_shutdown function to release all device-related queue rule instances.
4) Send netdev_unregister notifications to netdev_chain to notify other kernel components of the logout event
5) release all data blocks linked to the net_device Structure
6) Call the net_set_todo function to reduce the reference count. Call the net_run_todo function to unregister the device from sysfs and set Dev-> state to netreg_unregistered. After all references are released, call Dev-> destructor to end the logout process. Enable, disable network device
Enable
After registering a network device, you must enable it to send and receive data. (The same applies to other devices. Here, we use network devices as an example)
First, call Dev-> open to process the Enable request of the device. Set the _ link_state_start flag of Dev-> state to mark that the device is open and running, set the iff_up flag of Dev-> flags to mark the startup of the device.
Call the function dev_activate to initialize the queuing rules for traffic control and start the monitoring timer.
Send a netdev_up notification to the netdev_chain notification chain to notify the kernel component disable interested in the Enable of the device.
When a device is logged out, call dev_close to disable the network device.
Send a netdev_going_down notification to the netdev_chain notification chain to notify kernel components that are not interested in the device
Call the dev_deactivate function to disable egress queue rules, so that the device is no longer used for transmission and the monitoring timer is stopped.
Clear Dev-> state's _ link_state_start
If you have already scheduled a round-robin Read Device data packet in the queue, wait until this operation is completed.
Clear Dev-> flags iff_up
Send a netdev_down notification to the netdev_chain notification chain to notify kernel components that are not interested in the device

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.