内核版本:2.6.18
inet_init函数调用dev_add_pack函数:
-
/*
-
* Called once on startup.
-
*/
-
-
static struct packet_type arp_packet_type = {
-
.type = __constant_htons(ETH_P_ARP),
-
.func = arp_rcv,
-
}
以太网帧类型为ARP的数据帧。
-
/*
-
* IP protocol layer initialiser
-
*/
-
-
static struct packet_type ip_packet_type = {
-
.type = __constant_htons(ETH_P_IP), //转化为网络字节序
-
.func = ip_rcv,
-
.gso_send_check = inet_gso_send_check,
-
.gso_segment = inet_gso_segment,
-
};
以太网帧类型为IP的数据帧。
-
dev_add_pack(&ip_packet_type)
把处理ETH_P_IP数据的handler加入到相应的链表中。
-
static struct list_head ptype_base[16]; /* 16 way hashed list */
-
static struct list_head ptype_all; /* Taps */
-
/**
-
* dev_add_pack - add packet handler
-
* @pt: packet type declaration
-
*
-
* Add a protocol handler to the networking stack. The passed &packet_type
-
* is linked into kernel lists and may not be freed until it has been
-
* removed from the kernel lists.
-
*
-
* This call does not sleep therefore it can not
-
* guarantee all CPU's that are in middle of receiving packets
-
* will see the new packet type (until the next received packet).
-
*/
-
-
void dev_add_pack(struct packet_type *pt)
-
{
-
int hash;
-
-
spin_lock_bh(&ptype_lock);
-
if (pt->type == htons(ETH_P_ALL)) {
-
netdev_nit++;
-
list_add_rcu(&pt->list, &ptype_all);
-
} else {
-
hash = ntohs(pt->type) & 15;
-
list_add_rcu(&pt->list, &ptype_base[hash]);
-
}
-
spin_unlock_bh(&ptype_lock);
-
}
阅读(3660) | 评论(0) | 转发(1) |