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

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

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

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

有三种路由结构:

1,neigh_table{}结构和neighbour{}结构

 存储和本机物理上相邻的主机地址信息表,通常称为邻居子节点,指的是和本机相邻只有

 一跳的机器,其中neigh_table{}作为数据结构链表来表示neighbour{}表示相邻的机器节点

2,路由规则的存储,判断了一个到达一个网络地址必须经过怎样的路由,使用fib_table来表示

3, 提供了路由地址的缓存机制,使用 rtable 链表来表示.

neigh_table结构

struct neigh_table

{

struct neigh_table   *next;

int                  family;

int                  entry_size;

int                  key_len;

__u32                   (*hash)(const void *pkey, const struct net_device *);

int                  (*constructor)(struct neighbour *);

int                  (*pconstructor)(struct pneigh_entry *);

void               (*pdestructor)(struct pneigh_entry *);

void               (*proxy_redo)(struct sk_buff *skb);

char               *id;

struct neigh_parms parms;

int                  gc_interval;

int                  gc_thresh1;

int                  gc_thresh2;

int                  gc_thresh3;

unsigned long         last_flush;

struct timer_list     gc_timer;

struct timer_list     proxy_timer;

struct sk_buff_head       proxy_queue;

atomic_t         entries;

rwlock_t        lock;

unsigned long         last_rand;

struct kmem_cache              *kmem_cachep;

struct neigh_statistics    *stats;

struct neighbour     **hash_buckets;

unsigned int           hash_mask;

__u32                   hash_rnd;

unsigned int           hash_chain_gc;

struct pneigh_entry **phash_buckets;

#ifdef CONFIG_PROC_FS

struct proc_dir_entry     *pde;

#endif

};

struct proc_dir_entry     *pde

这个成员是linux 2.6中添加了对proc文件系统的支持,但是我没有找到proc文件系统中

有直接相关于邻居节点的信息,估计是和其他结构一起向用户态提供了路由信息,有可能

是输出到/proc/net/route里面.

struct neigh_table *next; //下一个邻居表,实际上就是ARP报文到达的下一台机器

int family;//地址族,对于以太网而言就是 AF_INET

int entry_size; //入口长度,也就是一个邻居结构的大小,初始化为sizeof(neighbour)+4(4为一个IP地址的长度)

//哈希关键值长度 即IP地址的长度,为4

int  key_len;

__u32 (*hash)(const void *pkey, const struct net_device *);构造出存放和检索这个neigh_table的neighbour的哈希函数  

//允许邻居的上限,根据网络的类型,大小会有所变化,例如C类地址,邻居限制就应该小于255

int gc_thresh3

//哈希数组,存入其中的邻居,在一个neigh_table里面,最多可以有32个neighbour结构的链表.

struct neighbour  **hash_buckets;

int entries //整个neigh_table中邻居的数量

unsigned int hash_mask; //哈希数组大小的掩码

neighbour结构

struct neighbour

{

struct neighbour     *next;

struct neigh_table   *tbl;

struct neigh_parms *parms;

struct net_device    *dev;

unsigned long         used;

unsigned long         confirmed;

unsigned long         updated;

__u8                     flags;

__u8                     nud_state;

__u8                     type;

__u8                     dead;

atomic_t         probes;

rwlock_t        lock;

unsigned char        ha[(MAX_ADDR_LEN+sizeof(unsigned long)-1)&~(sizeof(unsigned long)-1)];

struct hh_cache            *hh;

atomic_t         refcnt;

int                  (*output)(struct sk_buff *skb);

struct sk_buff_head       arp_queue;

struct timer_list      timer;

struct neigh_ops     *ops;

u8                  primary_key[0];

};

struct neigh_table *tbl;//所在的邻居表,指向上层的neigh_table结构

struct net_device *dev;//邻居所对应的网络设备接口指针

int (*output)(struct sk_buff *skb);//找到合适的邻居节点之后,系统将调用这个函数指针,

使用结构中的dev设备,将数据包发送出去,如果协议

               族是AF_INET,将调用dev_queue_xmit函数发送数据

u8 primary_key[0];//哈希关键字

//这段代码完成函数指针的转换(net/ipv4/arp.c)

static struct neigh_ops arp_hh_ops = {

.family =        AF_INET,

.solicit =         arp_solicit,

.error_report =              arp_error_report,

.output =        neigh_resolve_output,

.connected_output =      neigh_resolve_output,

.hh_output =          dev_queue_xmit,

.queue_xmit =        dev_queue_xmit,

};

linux路由内核实现分析(一)----邻居子节点(1)相关推荐

  1. linux路由内核实现分析(一)----邻居子节点(2)

    邻居节点相关的操作:   查找到路由后,会调用arp_bind_neighbour绑定一个邻居项 int arp_bind_neighbour(struct dst_entry *dst) { str ...

  2. linux路由内核实现分析(三)---路由查找过程

    ------------------------------------------------------------------------------------------ 以下是我根据 li ...

  3. linux路由内核实现分析(二)---FIB相关数据结构(1)

    ------------------------------------------------------------------------------------------ 以下是我根据 li ...

  4. linux路由内核实现分析 四,linux路由内核实现分析(二)---FIB相关数据结构(4)

    fib_info结构 struct fib_info { struct hlist_node fib_hash; struct hlist_node fib_lhash; int fib_treere ...

  5. linux路由内核实现分析(四)---路由缓存机制(4)

    ip_route_input函数   int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr, u8 tos, struc ...

  6. linux路由内核实现分析(四)---路由缓存机制(2)

    dst_entry结构   struct dst_entry { struct rcu_head             rcu_head; struct dst_entry      *child; ...

  7. linux路由内核实现分析(四)---路由缓存机制(1)

    ------------------------------------------------------------------------------------------ 以下是我根据 li ...

  8. linux路由内核实现分析(二)---FIB相关数据结构(4)

    fib_info结构 struct fib_info {struct hlist_node fib_hash;struct hlist_node fib_lhash;int fib_treeref;a ...

  9. linux路由内核实现分析(二)---FIB相关数据结构(3)

    fib_node结构 struct fib_node {struct hlist_node fn_hash;struct list_head fn_alias;u32 fn_key; }; 这个结构实 ...

最新文章

  1. OpenCV中minAreaRect()最小外接矩形 cvBoxPoints()计算矩形顶点 RotatedRect和CvBox2D详解
  2. 鸿蒙系统首批更新机器,鸿蒙系统升级名单
  3. 字节跳动端到端深度学习召回算法
  4. zabbix文档3.4-7配置
  5. 串行线路上传输数据报的非标准协议:SLIP
  6. USB 设备类代码表
  7. 746. 使用zui小花费爬楼梯(JavaScript)
  8. 将CMD内的显示内容输出到txt文件
  9. 【学术分享】推荐一个免费下载外文文献的网站
  10. paip.win7 减肥记
  11. 【转】ASP.NET使用ECharts展示后台数据
  12. php怎么更换图片背景颜色,照片换底色红色变白色怎么变 怎么换照片底色
  13. 苹果雪豹操作系统正式版_苹果发布WatchOS 6.1.2第三个测试版本,修复Bug、提升设备稳定性...
  14. 举个简单例子说明条件独立
  15. JS逆向 2021-8-16 网易云音乐 params、encSecKey参数
  16. 一篇高中生都能看懂的MySQL入门博客(长文)
  17. 6W字的Hive讲解只为你更懂它
  18. JAVA面试题(选择题)
  19. 掌握这些电脑知识,你可以玩的很无耻(暴强)
  20. c语言的积木编程,c语言入门3,自己造积木,掌握它就能随心所欲的完成各种工作了...

热门文章

  1. 二维均匀分布的边缘密度函数_理解概率密度函数
  2. java spring 容器_java – Spring容器实现
  3. jupyter配置不同的conda环境
  4. CSV格式整理,去除与上一行数据重复的单元格
  5. 怎么将ip地址改成域名访问_什么是域名解析?怎么把域名解析成IP地址?
  6. linux ext4的块大小,linux – ext3 / ext4物理块大小视图
  7. 模板三连击:树状数组+线段树+主席树
  8. Java蓝桥杯--基础练习(7)特殊回文数
  9. 170504、MongoDB和MySQL对比(译)
  10. 算法系列之选择排序算法