慢慢欣赏linux 网络协议栈一 全景图

用户态软件
	/\
	||
	\/
系统库函数
	/\
	||
	\/
C标准库或者glibc
	/\
	|| 系统调用
	\/
内核态系统调用接口
	/\
	||
	\/
内核协议栈L3到最上层
	/\
	||
	\/
L2协议栈以及驱动
	/\
	||
	\/
L1硬件网卡NIC

网络初始化入口

int __init net_dev_init(void)
	dev_proc_init()
	=>int __init dev_proc_init(void)
		return register_pernet_subsys(&dev_proc_ops);
			static struct pernet_operations __net_initdata dev_proc_ops = {
				.init = dev_proc_net_init,
				.exit = dev_proc_net_exit,
			};
		=>int register_pernet_subsys(struct pernet_operations *ops)
			error =  register_pernet_operations(first_device, ops);
			=>int register_pernet_operations(struct list_head *list, struct pernet_operations *ops)
				error = __register_pernet_operations(list, ops);
				=>int __register_pernet_operations(struct list_head *list, struct pernet_operations *ops)
					err = ops_init(ops, &init_net);
					=>int ops_init(const struct pernet_operations *ops, struct net *net)
						return ops->init(net);
						=>int __net_init dev_proc_net_init(struct net *net)
							proc_net_fops_create(net, "dev", S_IRUGO, &dev_seq_fops)
							proc_net_fops_create(net, "softnet_stat", S_IRUGO, &softnet_seq_fops)
							proc_net_fops_create(net, "ptype", S_IRUGO, &ptype_seq_fops)
	netdev_kobject_init()
	=>int netdev_kobject_init(void)
		return class_register(&net_class);//在/sys/class下注册net类
		
	INIT_LIST_HEAD(&ptype_all);
	for (i = 0; i < PTYPE_HASH_SIZE; i++)
		INIT_LIST_HEAD(&ptype_base[i]);
		
	register_pernet_subsys(&netdev_net_ops)
		struct pernet_operations __net_initdata netdev_net_ops = {
			.init = netdev_init,
			.exit = netdev_exit,
		};
		... ...//同register_pernet_subsys(&dev_proc_ops);
			=>int __net_init netdev_init(struct net *net)
				INIT_LIST_HEAD(&net->dev_base_head);
				net->dev_name_head = netdev_create_hash();
				net->dev_index_head = netdev_create_hash();
	
	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);

		queue->backlog.poll = process_backlog;
		queue->backlog.weight = weight_p;
		queue->backlog.gro_list = NULL;
		queue->backlog.gro_count = 0;
		
	register_pernet_device(&loopback_net_ops)
	
	register_pernet_device(&default_device_ops)
	
	open_softirq(NET_TX_SOFTIRQ, net_tx_action);
	open_softirq(NET_RX_SOFTIRQ, net_rx_action);
	
	hotcpu_notifier(dev_cpu_callback, 0);
	dst_init();
	dev_mcast_init();

理解 Linux 网络栈(1):Linux 网络协议栈简单总结
https://www.cnblogs.com/sammyliu/p/5225623.html

网络设备模块初始化(net/core/dev.c/net_dev_init)
https://blog.csdn.net/sun172270102/article/details/80643164

register_pernet_subsys相关学习
https://blog.csdn.net/lickylin/article/details/18013879

Linux 以太网驱动
https://blog.csdn.net/dongkun152/article/details/74906670

环回设备接口(loopback)上如何发送和接收数据报      //上下文的网口驱动文章可以学习一下
http://blog.chinaunix.net/uid-26675482-id-3067061.html

suiming2005的ChinaUnix博客
http://blog.chinaunix.net/uid-23250294-id-5790231.html

Linux网络设备驱动框架
http://t.zoukankan.com/linfeng-learning-p-9547356.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TCP/IP协议是计算机网络中最常用的协议之一,它是由多个不同层次的协议组成的。下面是TCP/IP协议全景: ``` +---------------------------------------------------+ | 应用层 (HTTP, FTP, SMTP, DNS, ...) | +--------------------------+------------------------+ | 传输层 (TCP, UDP) | 网际层 (IP) | +--------------------------+------------------------+ | 网络接口层 (Ethernet, Wi-Fi, ...) | +---------------------------------------------------+ ``` 在上述协议中,每个层次都有自己的作用和功能,如下所示: 1. 应用层:应用层协议用于在应用程序之间提供通信服务。常见的应用层协议包括 HTTP、FTP、SMTP 和 DNS 等。 2. 传输层:传输层协议在主机之间提供端到端的数据传输。常见的传输层协议包括 TCP 和 UDP。 3. 网际层:网际层协议用于将数据包从源主机发送到目的主机,它是互联网的核心协议。常见的网际层协议包括 IP。 4. 网络接口层:网络接口层协议用于在主机和物理网络之间提供通信服务。常见的网络接口层协议包括 Ethernet 和 Wi-Fi 等。 在这个协议中,每个层次都有自己的协议和功能。从上到下,每个层次都依赖于下面一层的协议和服务。应用层协议需要传输层协议,传输层协议需要网际层协议,网际层协议需要网络接口层协议。因此,TCP/IP协议是一个分层的协议,每个层次都有自己的职责和责任。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值