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

----------------------------------------------------------------------------------以下是我根据

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地址进行哈希运算得到的一个值,如下图:

a4c26d1e5885305701be709a3d33442f.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值