Registration and initialization of network devices

Source: Internet
Author: User

Before network device registration and NIC initialization are available, the associated net_device data structure must be initialized and added to the kernel Network Device database,
Configure and enable. It is important not to confuse registration/de-listing and enabling/disabling. There are two different concepts: if you exclude the actions of the device driver module, registration and delisting are independent of users,
Is driven by the kernel. Only registered devices cannot run. Users are required to enable and disable the device. Once the device has been registered by the kernel, you can view the device through user commands,
Configure and enable it. The NIC device driver is loaded when the device registers. If the NIC device driver is built into the kernel, It is initialized during the boot; otherwise, if it is loaded as a module,
It will be initialized during running; otherwise, if it is loaded as a module, it will be initialized during running.
During initialization, all NICs controlled by the driver are registered. Insert a hot swappable network device to www.2cto.com. When you insert a hot swappable NIC device into the device, the kernel will notify its driver, and the driver is registering the device. Detach NIC device drivers when removing a device. This is only for drivers loaded with modules and is not suitable for drivers built into the kernel.
When the Administrator uninstalls the NIC device driver, all associated NICs must be removed. Delete a hot swappable network device when a user deletes a hot swappable NIC from the system (its running kernel supports hot swappable devices), the network device is removed. The device registration status indicates that kernel components and user space applications may want to know when network devices are registered, removed, disabled, or enabled.
Notifications of such events are sent through netdev_chain, which can be registered by kernel components. The registration and de-listing of devices are progressing at various stages.
Reported by the netdev_chain notification chain. This chain is defined in net/core/dev. c and is interested in such events
The kernel component can register or remove the chain through register_netdevice_notifier and unregister_netdevice_notifier. Netdev_chain reports events: NETDEV_UP, NETDEV_GOING_DOWN, NETDEV_DOWN, and sends NETDEV_UP to report that the device is enabled,
This event is generated by dev_open. When the device is closed, NETDEV_GOING_DOWN is sent.
When the device is disabled, NETDEV_DOWN will be sent. These events are all generated by dev_close. The NETDEV_REGISTER device has been registered. This event is generated by register_netdevice. NETDEV_UNREGISTER: the device has been removed. This event is generated by unregister_netdevice. The hardware address of the NETDEV_CHANGEADDR device has changed. The status or configuration of the NETDEV_CHANGENAME device whose name is www.2cto.com has been changed. This event is used in other cases that are not included in this case. Note: When registering with a chain, register_netdevice_notifier also replays the current system (only for new registrants ).
All past NETDEV_REGISTER and NETDEV_UP notifications of registered devices. In this way, you can give new registrants
Clear images of registered devices. The kernel registers the subsystem of the chain: route. Use this notification to add or delete the chain.
All routing items associated with the device. Protocol code. When you change the MAC address of a local device, the ARP table must be updated accordingly. RTnetlink. The RTMGRP_LINK multicast group of Netlink. The user space program can register the RTMGRP_LINK multicast group of netlink,
When the device status or configuration changes, rtmsg_ifinfo is used to send the notification information to the Link multicast group RTMGRP_LINK,
Some of the notifications are as follows: when the netdev_chain notification chain receives a notification, RTnetlink registers the netdev_chain mentioned in the previous section,
Then replay the received notification information. When a disabled device is enabled or in the opposite process. When an identifier in net_device-> flags changes. Netplugd is a daemon that listens to the notification information and then responds according to the user configuration file. The netdev_wait_allrefs function of www.2cto.com is composed of a loop. It ends only when dev-> refcnt is set to zero. This function per second
A NETDEV_UNREGISTER notification is sent, and a warning message is printed on the console in less than 10 seconds.
The rest of the time is sleep. This function is used until all references to the input net_device structure are released.
There are two common cases where more than one notification message needs to be sent: bug, for example, some code holds a reference to the net_device structure, but because it is not registered in the netdev_chain notification chain,
Or the notification cannot be released because the notification information is not properly processed. Www.2cto.com. For example, assume that the data that the function must be accessed when the timer expires contains
References the net_device structure. In this case, you must wait until the timer expires and its processing function
It is expected to release its reference. 1:/* 2: * netdev_wait_allrefs-wait until all references are gone. 3: * 4: * This is called when unregistering network devices. 5: * 6: * Any protocol or device that holds a reference shocould register 7: * for netdevice notification, and cleanup and put back the 8: * reference if they receive an UNREGISTER. 9: * We can get stuck here if buggy protocols don't correctly 10: * call dev_put. 11: */12: static void netdev_wait_allrefs (struct net_device * dev) 13: {14: unsigned long rebroadcast_time, warning_time; 15: int refcnt; 16: 17: linkwatch_forget_dev (dev ); 18: 19: rebroadcast_time = warning_time = jiffies; 20: refcnt = netdev_refcnt_read (dev); 21: 22: while (refcnt! = 0) {23: if (time_after (jiffies, rebroadcast_time + 1 * HZ) {24: rtnl_lock (); www.2cto.com 25: 26:/* Rebroadcast unregnotification */27: call_netdevice_notifiers (NETDEV_UNREGISTER, dev); 28:/* don't resend NETDEV_UNREGISTER_BATCH, _ BATCH users 29: * shocould have already handle it the first time */30: 31: if (test_bit (_ LINK_STATE_LINKWATCH_PENDING, 32: & dev-> state) {33:/* We must no T have linkwatch events 34: * pending on unregister. if this 35: * happens, we simply run the queue 36: * unscheduled, resulting in a noop 37: * for this device. 38: */39: linkwatch_run_queue (); 40:} 41: 42: _ rtnl_unlock (); 43: 44: rebroadcast_time = jiffies; 45:} 46: 47: msleep (250); 48: 49: refcnt = netdev_refcnt_read (dev); 50: 51: if (time_after (jiffies, warning_time + 10 * HZ) {52: print K (KERN_EMERG "unregister_netdevice:" 53: "waiting for % s to become free. usage "54:" count = % d \ n ", 55: dev-> name, refcnt); 56: warning_time = jiffies; 57:} www.2cto.com 58:} 59 :} once a network device is registered, it can be enabled or disabled. However, data streams cannot be transmitted or received unless explicitly enabled.
The start device function is dev_open. If it is defined, call dev-> open. Not all device drivers initialize this function to set the _ LINK_STATE_START identifier in dev-> state to start and run the device. Set the IFF_UP identifier in dev-> flags to enable the device identifier. Call dev_activate to initialize the egress queue rules used by traffic control, and then start the watchdog timer.
If the traffic control is not configured by the user, specify the default FIFO to send the NETDEV_UP notification information to the netdev_chain notification chain to notify the kernel component of interest. This device is now enabled. The device disables the transfer of NETDEV_GOING_DOWN notification information to the netdev_chain notification chain to notify interested kernel components that the device is about to be disabled call dev_deactivate to disable the egress queue rules, so that the device can no longer be used for transmission, then, because it is not necessary,
Stop the watchdog timer to clear the _ LINK_STATE_START identifier in dev-> state and mark the device as disabled. If a polling action is scheduled to read the entry packet on the device, wait until the action is completed.
Because the _ LINK_STATE_START identifier has been cleared, the device cannot schedule other received polling actions,
However, a polling action may be pending before the flag is cleared. If www.2cto.com is defined, call dev-> stop. Clear the IFF_UP identifier in dev-> flags and mark the device as the status change detection of the NETDEV_DOWN notification link that may cause the link status change: 1. Insert the cable into the NIC, or unplug from the NIC. 2. The power of the device at the other end of the cable is turned off or off. This type of equipment is composed of hubs, bridges, routers, and PC NICs. I am * Li Shimin *

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.