Preparation of Linux kernel network stack code (2)

Source: Internet
Author: User
Article title: Preparations for Linux kernel network stack code (2 ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

2.3 protocol initialization

This section describes the inet protocol initialization process.

Static int _ init inet_init (void)

{

Struct sk_buff * dummy_skb;

Struct inet_protocol * p;

Struct inet_protosw * q;

Struct list_head * r;

Printk (KERN_INFO "NET4: Linux TCP/IP 1.0 for NET4.0 \ n ");

If (sizeof (struct inet_skb_parm)> sizeof (dummy_skb-> cb )){

Printk (KERN_CRIT "inet_proto_init: panic \ n ");

Return-EINVAL;

}

/*

* Tell SOCKET that we are alive... register the socket and Tell the socket inet type address family that is ready

*/

(Void) sock_register (& inet_family_ops );

/*

* Add all the protocols. including arp, ip, ICMP, UPD, tcp_v4, tcp, and igmp initialization. it mainly initializes inode and socket variables corresponding to various protocols.

Arp_init initializes the neighbor table in the system.

Ip_init initializes the IP protocol. In these two functions, both define a variable in the packet_type structure to send data to the protocol corresponding to this data packet, and enable the sender device to initialize.

*/

Printk (KERN_INFO "IP Protocols :");

For (p = inet_protocol_base; p! = NULL ;){

Struct inet_protocol * tmp = (struct inet_protocol *) p-> next;

Inet_add_protocol (p );

Printk ("% s", p-> name, tmp? ",": "\ N ");

P = tmp;

}

/* Register the socket-side information for inet_create .*/

For (r = & inetsw [0]; r <& inetsw [SOCK_MAX]; ++ r)

INIT_LIST_HEAD (r );

For (q = inetsw_array; q <& inetsw_array [INETSW_ARRAY_LEN]; ++ q)

Inet_register_protosw (q );

/*

* Set the ARP module up

*/

Arp_init ();

/*

* Set the IP module up

*/

Ip_init ();

Tcp_v4_init (& inet_family_ops );

/* Setup TCP slab cache for open requests .*/

Tcp_init ();

/*

* Set the ICMP layer up

*/

Icmp_init (& inet_family_ops );

/* I wish inet_add_protocol had no constructor hook...

I had to move IPIP from net/ipv4/protocol. c:-(-- ANK

*/

# Ifdef CONFIG_NET_IPIP

Ipip_init ();

# Endif

# Ifdef CONFIG_NET_IPGRE

Ipgre_init ();

# Endif

/*

* Initialise the multicast router

*/

# If defined (CONFIG_IP_MROUTE)

Ip_mr_init ();

# Endif

/*

* Create all the/proc entries.

*/

# Ifdef CONFIG_PROC_FS

Proc_net_create ("raw", 0, raw_get_info );

Proc_net_create ("netstat", 0, netstat_get_info );

Proc_net_create ("snmp", 0, snmp_get_info );

Proc_net_create ("sockstat", 0, afinet_get_info );

Proc_net_create ("tcp", 0, tcp_get_info );

Proc_net_create ("udp", 0, udp_get_info );

# Endif/* CONFIG_PROC_FS */

Ipfrag_init ();

Return 0;

}

Module_init (inet_init );

[1] [2] Next page

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.