0
点赞
收藏
分享

微信扫一扫

linux内核协议栈说明

香小蕉 01-05 18:00 阅读 5

在这里插入图片描述在这里插入图片描述
在这里插入图片描述

root@ubuntu:~/rtk-9310/kernel/uClinux/linux-3.18.24.x# grep “\bstruct list_head ptype_all\b” ./ -nR
./net/core/net-procfs.c:12:extern struct list_head ptype_all __read_mostly;
./net/core/dev.c:149:struct list_head ptype_all __read_mostly; /* Taps */

///root/rtk-9310/kernel/uClinux/linux-3.18.24.x/net/core/dev.c
list_for_each_entry_rcu(ptype, &ptype_all, list) {
if (!ptype->dev || ptype->dev == skb->dev) {
if (pt_prev)
ret = deliver_skb(skb, pt_prev, orig_dev);
pt_prev = ptype;
}
}

///root/rtk-9310/kernel/uClinux/linux-3.18.24.x/net/core/dev.c
static inline int deliver_skb(struct sk_buff *skb,
struct packet_type *pt_prev,
struct net_device *orig_dev)
{
if (unlikely(skb_orphan_frags(skb, GFP_ATOMIC)))
return -ENOMEM;
atomic_inc(&skb->users);
return pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
}

Note: 根据注册的协议类型 调用对应注册的回调函数

///root/rtk-9310/kernel/uClinux/linux-3.18.24.x/net/ipv4/arp.c
static struct packet_type arp_packet_type __read_mostly = {
.type = cpu_to_be16(ETH_P_ARP),
.func = arp_rcv,
};
static int arp_proc_init(void);
void __init arp_init(void)
{
neigh_table_init(&arp_tbl);
dev_add_pack(&arp_packet_type);
arp_proc_init();
#ifdef CONFIG_SYSCTL
neigh_sysctl_register(NULL, &arp_tbl.parms, NULL);
#endif
register_netdevice_notifier(&arp_netdev_notifier);
}

举报

相关推荐

0 条评论