Linux 网络系统学习: Neighboring Subsystem

Linux 网络系统学习: Neighboring Subsystem

1. 概述

在数据包的发送过程中,通过路由获得下一跳的 L3 地址,下一步是获得此 L3 地址所对应的 L2 地址,这个过程称为 neighbor discovery。IPv4对应的是 ARP 协议,IPv6 对应的是Neighbor Discovery 协议。

Linux 中,用于处理neighbor discovery的模块称为 neighboring subsystem。它分为两层,底层是通用框架 neighboring infrastructure,在此之上,又有不同的具体实现,例如ARP 模块、 ND 模块等。

Neighboring subsystem 的主要任务包括:

1、Neighbour discovery;通过 L3 地址找到 L2 地址;为发送数据提供保障
2、接收 neighbor 包并进行处理
3、提供 cache,以加速 neighboring 的过程
4、为系统中其它模块需要 neighboring discovery 而提供 APIs


2. Neighboring infrastructure  

2.1 主要数据结构:

1、  struct neighbour
最主要的结构

2、  struct neigh_table
用于管理 struct neighbour

3、  struct neigh_ops
用于映射到 L2  的输出函数

4、  struct neigh_parms

5、  struct hh_cache

           

2.2 数据结构关系:

下图是 neighboring subsystem 中数据结构关系图,其关系可描述如下:

1、系统通过 neigh_tables 来管理各种具体的 neigh_table,包括 arp_tbl 和 nd_table
2、Neigh_table 通过 hash_buckets 来维护一个 neigh_table 的 hash 表。可以迅速的增加、删除、查找  neighbour
3、neighbour  的作用??? Neighbour 的 parms 指向 neigh_parms 结构,此结构用于 neighbour 的维护,例如重传次数,状态转换时间,垃圾收集时间等。
4、neighbour 的 ops 指向 neigh_ops 结构,此结构用于???
5、neighbour 的 hh 指向 hh_cache,此结构用于 cache L2 地址,以加速 L3 到 L2 的映射过程。

 


 

2.3 工具函数

1、struct neighbour *neigh_alloc(struct neigh_table *tbl)
创建一个 neighbour,并初始化,它只被  neighbour_create() 调用

2、struct neighbour * neigh_create(struct neigh_table *tbl, const void *pkey, struct net_device *dev)
调用 neigh_alloc() 分配一个 neighboure ,然后进一步调用具体协议的构造函数,以及具体设备的特殊的设置函数;最后,将此 neighbour 加入 neighbour table 中
它主要被  __neigh_lookup() 调用,也就是说,当在 neighbour table 中找不到 neighbour 的时候,调用此函数来创建一个新的 neighbour

3、struct neighbour *neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev)
在 neighbour table 中寻找特定的 neighbour

4、static void neigh_timer_handler(unsigned long arg)
这是一个定时器处理函数。当某个 neighbour 超时后,由此函数处理。

5、int neigh_update(struct neighbour *neigh, co
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值