📄 dev.c.txt
字号:
any questions,send email to netxiong@eyou.com
相关文件
/linux/netdevice.h
********************基本数据结构****************************
各种网络协议的哈希表,系统中使用的各种协议都填写到这个表中的相应位置。
用户使用哈希值访问这个表,得到这种协议的处理函数。继而得到处理。
用户使用函数dev_add_pack(struct packet_type *pt)来将各种协议的处理函数挂接到系统中
static struct packet_type *ptype_base[16];
************************************************************
**********************注册函数****************************
(1)int register_netdevice(struct net_device *dev)
**********************************************************
************************核心处理函数**************************
这个函数是协议栈的开始,接收到的skb就是下层的网卡驱动程序为每一个接收到的ip包
做得封装。
(1)int netif_rx(struct sk_buff *skb)
queue = &softnet_data[this_cpu]; //先得到当前cpu的skb队列
local_irq_save(flags); //封锁中断
netdev_rx_stat[this_cpu].total++; //进行skb统计
enqueue:
if (queue->input_pkt_queue.qlen <= netdev_max_backlog) { //这个队列中的skb还不超长
if (queue->input_pkt_queue.qlen) { //
if (queue->throttle) //如果throttle置位,丢弃
goto drop; //如果队列满了,丢弃这个skb包
__skb_queue_tail(&queue->input_pkt_queue,skb); //将新的skb包加入到这个队列中
cpu_raise_softirq(this_cpu, NET_RX_SOFTIRQ); //设置softirq
local_irq_restore(flags); //解锁中断
return softnet_data[this_cpu].cng_level; //成功返回
}
if (queue->throttle) { //如果走到这里,说明队列中还没有skb连接,检查throttle状态
queue->throttle = 0; //如果置位了,清除。
}
goto enqueue; //重新将skb加入队列中
}
drop:
netdev_rx_stat[this_cpu].dropped++; //丢弃处理
local_irq_restore(flags);
kfree_skb(skb);
return NET_RX_DROP;
**************************************************************
******************各种网络协议栈的建立过程以及数据结构***********************
????
static struct packet_type *ptype_all = NULL; /* Taps */
这个函数将一个协议集加入到linux系统的网络协议栈中
void dev_add_pack(struct packet_type *pt)
#ifdef CONFIG_NET_FASTROUTE //?????????
if ((pt->data) && ((int)(pt->data)!=1)) {
netdev_fastroute_obstacles++;
dev_clear_fastroute(pt->dev);
}
#endif
if (pt->type == htons(ETH_P_ALL)) { //如果协议处理集标志为ETH_P_ALL,就加入到ptype_all链表中
netdev_nit++;
pt->next=ptype_all;
ptype_all=pt;
} else { //否则按照hash函数加入到ptype_base数组中。
hash=ntohs(pt->type)&15;
pt->next = ptype_base[hash];
ptype_base[hash] = pt;
}
*****************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -