Linux系統(tǒng)內(nèi)核接收以太幀的處理程序 2
2007-02-12 中國IT實驗室
3.2 刪除節(jié)點
/**
* __dev_remove_pack - remove packet handler
* @pt: packet type declaration
*
* Remove a protocol handler that was previously added to the kernel
* protocol handlers by dev_add_pack(). The passed &packet_type is removed
* from the kernel lists and can be freed or reused once this function
* returns.
*
* The packet type might still be in use by receivers
* and must not be freed until after all the CPU's have gone
* through a quiescent state.
*/
void __dev_remove_pack(struct packet_type *pt)
{
struct list_head *head;
struct packet_type *pt1;
spin_lock_bh(&ptype_lock);
// 根據(jù)協(xié)議類型找是在ptype_all表還是某一HASH鏈表中
if (pt->type == htons(ETH_P_ALL)) {
netdev_nit--;
head = &ptype_all;
} else
head = &ptype_base[ntohs(pt->type) & 15];
// 直接用地址比對進行查找,而不是類型,因為同一個類型也可能有多個節(jié)點
list_for_each_entry(pt1, head, list) {
if (pt == pt1) {
list_del_rcu(&pt->list);
goto out;
}
}
printk(KERN_WARNING "dev_remove_pack: %p not found.\n", pt);
out:
spin_unlock_bh(&ptype_lock);
}
/**
* dev_remove_pack - remove packet handler
* @pt: packet type declaration
*
* Remove a protocol handler that was previously added to the kernel
* protocol handlers by dev_add_pack(). The passed &packet_type is removed
* from the kernel lists and can be freed or reused once this function
* returns.
*
* This call sleeps to guarantee that no CPU is looking at the packet
* type after return.
*/
// 只是__dev_remove_pack()的包裹函數(shù)
void dev_remove_pack(struct packet_type *pt)
{
__dev_remove_pack(pt);
synchronize_net();
} |
4. 實例
4.1 IP
/* net/ipv4/af_inet.c */
static struct packet_type ip_packet_type = {
.type = __constant_htons(ETH_P_IP),
.func = ip_rcv, // IP接收數(shù)據(jù)的入口點
};
static int __init inet_init(void)
{
......
dev_add_pack(&ip_packet_type);
...... |
由于IP協(xié)議部分不能作為內(nèi)核模塊,所以是沒有卸載函數(shù)的,沒必要調(diào)用dev_remove_pack()函數(shù)。
熱詞搜索:
上一篇:Linux系統(tǒng)內(nèi)核接收以太幀的處理程序 1
下一篇:戴爾部分PC將支持Novell Linux