Chinaunix首页 | 论坛 | 博客
  • 博客访问: 314155
  • 博文数量: 57
  • 博客积分: 146
  • 博客等级: 入伍新兵
  • 技术积分: 769
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-29 14:57
文章分类
文章存档

2014年(39)

2013年(13)

2012年(5)

我的朋友

分类: C/C++

2014-10-11 15:17:10

内核版本:2.6.18

inet_init函数调用dev_add_pack函数:


点击(此处)折叠或打开

  1. /*
  2.  *    Called once on startup.
  3.  */

  4. static struct packet_type arp_packet_type = {
  5.     .type =    __constant_htons(ETH_P_ARP),
  6.     .func =    arp_rcv,
  7. }
以太网帧类型为ARP的数据帧。

点击(此处)折叠或打开

  1. /*
  2.  *    IP protocol layer initialiser
  3.  */

  4. static struct packet_type ip_packet_type = {
  5.     .type = __constant_htons(ETH_P_IP), //转化为网络字节序
  6.     .func = ip_rcv,
  7.     .gso_send_check = inet_gso_send_check,
  8.     .gso_segment = inet_gso_segment,
  9. };
以太网帧类型为IP的数据帧。

点击(此处)折叠或打开

  1. dev_add_pack(&ip_packet_type)
把处理ETH_P_IP数据的handler加入到相应的链表中。



点击(此处)折叠或打开

  1. static struct list_head ptype_base[16];    /* 16 way hashed list */
  2. static struct list_head ptype_all;        /* Taps */

点击(此处)折叠或打开

  1. /**
  2.  *    dev_add_pack - add packet handler
  3.  *    @pt: packet type declaration
  4.  *
  5.  *    Add a protocol handler to the networking stack. The passed &packet_type
  6.  *    is linked into kernel lists and may not be freed until it has been
  7.  *    removed from the kernel lists.
  8.  *
  9.  *    This call does not sleep therefore it can not
  10.  *    guarantee all CPU's that are in middle of receiving packets
  11.  *    will see the new packet type (until the next received packet).
  12.  */

  13. void dev_add_pack(struct packet_type *pt)
  14. {
  15.     int hash;

  16.     spin_lock_bh(&ptype_lock);
  17.     if (pt->type == htons(ETH_P_ALL)) {
  18.         netdev_nit++;
  19.         list_add_rcu(&pt->list, &ptype_all);
  20.     } else {
  21.         hash = ntohs(pt->type) & 15;
  22.         list_add_rcu(&pt->list, &ptype_base[hash]);
  23.     }
  24.     spin_unlock_bh(&ptype_lock);
  25. }




























阅读(3481) | 评论(0) | 转发(1) |
1

上一篇:inet_init函数中的iinet_register_protosw函数

下一篇:没有了

给主人留下些什么吧!~~