Device initialization for Linux network protocol stack

Source: Internet
Author: User
Linux network protocol stack kernel initialization can be divided into device link layer (e100_module_init, net_dev_init), network layer (inet_init), transmission layer (proto_init), and application layer (sock_init) initialization. Because the physical layer is a specific network device, so the kernel on the network protocol... linux network protocol stack kernel initialization can be divided into device link layer (e100_module_init, net_dev_init), network layer (inet_init), transmission layer (proto_init), and application layer (sock_init) initialization. Because the physical layer is a specific network device, the kernel has no physical layer (L1) for the implementation of the network protocol stack and NIC driver, and the initialization functions of the driver and device should be converted to the L2 layer. We have introduced the implementation of the e100 series NIC driver. next we will look at another function net_dev_init initialized to the device during kernel initialization. /* Device processing layer initialization function */static int _ init net_dev_init (void) {www.2cto.com int I, rc =-ENOMEM;/* not initialized */BUG_ON (! Dev_boot_phase);/* This function creates three files in the/proc directory to read network-related statistics. as we can see, the files in/proc are basically read-only, the three files provided here do not have write operations */if (dev_proc_init () goto out; /* register the net node */if (netdev_sysfs_init () goto out in the class of the/sysfs device file system;/* initialize the linked list and hash list of network processing functions, these functions are used to process received packets of different protocol families */INIT_LIST_HEAD (& ptype_all); for (I = 0; I <16; I ++) INIT_LIST_HEAD (& ptype_base [I]); under www.2cto.com/*, the hash list of initialized network devices * // * the keyword of the hash list is calculated by the device name */for (I = 0; I <ARRAY_SIZ E (dev_name_head); I ++) INIT_HLIST_HEAD (& dev_name_head [I]);/* the keywords of the hash list are calculated by the index of the device interface */for (I = 0; I <ARRAY_SIZE (dev_index_head); I ++) INIT_HLIST_HEAD (& dev_index_head [I]);/*** Initialise the packet receive queues. * // * initialize the CPU-related data receiving queue */for_each_possible_cpu (I) {struct softnet_data * queue; queue = & per_cpu (softnet_data, I ); skb_queue_head_init (& queue-> input_pkt_queue); queue-> completion_queue = NULL; INIT_LIST_HEAD (& queue-> poll_list); set_bit (_ LINK_STATE_START, & queue-> backlog_dev.state); queue-> queue = weight_p; queue-> queue = process_backlog; atomic_set (& queue-> backlog_dev.refcnt, 1);}/* register the network DMA client */netdev_dma_register ();/* indicates that the client has been initialized */dev_boot_phase = 0; /* register two software interruptions for data receiving and sending */open_softirq (NET_TX_SOFTIRQ, net_tx_action, NULL); open_softirq (NET_RX_SOFTIRQ, net_rx_ac Tion, NULL);/* register a callback function in the notification linked list for corresponding CPU hot swapping events. it can be seen from the callback function that once a notification is received, packets in the CPU input queue are processed by netif_rx () */www.2cto.com hotcpu_notifier (dev_cpu_callback, 0);/* initialize the destination route cache and notify the link */dst_init (); /* initialize the multicast module at the network link layer, and create the file dev_mcast in/proc/net to store the network device parameters related to IP multicast in the kernel */dev_mcast_init (); rc = 0; out: return rc;} the Net_dev_init function is called before the driver to initialize necessary information, two device queues, data input and output queues, and two soft interruptions for receiving and sending data are registered. In addition, the hierarchy of the above initialization functions may be incorrect, but it is easy to understand. Author bullbat
Related Article

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.