linux内核协议栈说明
作者:互联网
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);
}
标签:arp,协议,struct,linux,ptype,dev,内核,skb,net 来源: https://blog.csdn.net/lyeffort/article/details/122328598