分享

linux网桥内核实现分析(一))---CAM表的学习和查找(1)

 enchen008 2012-04-10

----------------------------------------------------------------------------------以下是我根据 linux-2.6.23.9版本内核源代码所做阅读笔记,属个人兴趣而为,希望找到有共同兴趣

的朋友一起讨论和研究,有谬误之处,笔者水平有限,欢迎大家拍砖:)

----------------------------------------------------------------------------------

CAM表的学习和查找

每一个MAC地址-端口对应着一个fdb项,内核中使用链表来组织,使用net_bridge_fdb_entry类型。

 

net_bridge_fdb_entry结构

 

struct net_bridge_fdb_entry

{

       struct hlist_node            hlist;

       struct net_bridge_port           *dst;

 

       struct rcu_head                    rcu;

       atomic_t                use_count;

       unsigned long                ageing_timer;

       mac_addr                     addr;

       unsigned char               is_local;

       unsigned char               is_static;

};

 

struct hlist_node               hlist; // 用于CAM表连接的链表指针

struct net_bridge_port           *dst;//对应的物理接口指针,其中包含一个

                                                 net_device的指针指向该物理网口

atomic_t                        use_count;//当前引用计数

unsigned long                   ageing_timer;//超时时间

mac_addr                         addr;//MAC地址

unsigned char                   is_local;//标明是否为本机MAC地址

unsigned char                   is_static;//标明是否为静态地址

 

net_bridge结构

 

一个net_bridge结构描述了一个桥设备

 

struct net_bridge

{

       spinlock_t                     lock;

       struct list_head              port_list;

       struct net_device           *dev;

       struct net_device_stats          statistics;

       spinlock_t                     hash_lock;

       struct hlist_head            hash[BR_HASH_SIZE];

       struct list_head              age_list;

       unsigned long                feature_mask;

 

      

       bridge_id               designated_root;

       bridge_id               bridge_id;

       u32                       root_path_cost;

       unsigned long                max_age;

       unsigned long                hello_time;

       unsigned long                forward_delay;

       unsigned long                bridge_max_age;

       unsigned long                ageing_time;

       unsigned long                bridge_hello_time;

       unsigned long                bridge_forward_delay;

 

       u8                         group_addr[ETH_ALEN];

       u16                       root_port;

 

       enum {

              BR_NO_STP,              

              BR_KERNEL_STP,       

              BR_USER_STP,           

       } stp_enabled;

 

       unsigned char               topology_change;

       unsigned char               topology_change_detected;

 

       struct timer_list             hello_timer;

       struct timer_list             tcn_timer;

       struct timer_list             topology_change_timer;

       struct timer_list             gc_timer;

       struct kobject                ifobj;

};

 

struct list_head             port_list; //桥组中的端口列表

struct net_device           *dev;//网桥会建立一个虚拟设备来进行管理,这个设备的MAC

                         地址是动态指定的,通常就是桥组中一个物理端口的MAC地址

 

struct net_device_stats  statistics;//网桥中虚拟网卡的统计数据

struct hlist_head       hash[BR_HASH_SIZE];//存放的是net_bridge_fdb_entry的哈希表,实际上就是mac和port的对应表

 

bridge_id             bridge_id;//这个成员一下是stp相关的信息

 

实际上在内核中,整个CAM表是用net_bridge->hash[]这个数组来存储的,其哈希值是使用MAC地址进行哈希运算得到的一个值,如下图:

linux网桥内核实现分析(一)---CAM表的学习和查找(1)

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多