邻居表项的delay_probe_time时长

2023-12-19 09:38

本文主要是介绍邻居表项的delay_probe_time时长,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

delay_probe_time控制首次发送邻居请求报文的等待时长,对于arp协议,内核默认的delay_probe_time时长为5秒钟。

struct neigh_table arp_tbl = {.family     = AF_INET,.key_len    = 4,.protocol   = cpu_to_be16(ETH_P_IP),.hash       = arp_hash,.key_eq     = arp_key_eq,.constructor    = arp_constructor,.proxy_redo = parp_redo,.id     = "arp_cache",.parms      = {.tbl            = &arp_tbl,.reachable_time     = 30 * HZ,.data   = {...[NEIGH_VAR_DELAY_PROBE_TIME] = 5 * HZ,

通过PROC文件delay_first_probe_time可查看和修改此时长,如下,修改为10秒钟。

$ cat /proc/sys/net/ipv4/neigh/eth0/delay_first_probe_time 
5
$ echo 10 > /proc/sys/net/ipv4/neigh/eth0/delay_first_probe_time  
$     
$ cat /proc/sys/net/ipv4/neigh/eth0/delay_first_probe_time       
10

内核中静态变量neigh_sysctl_table定义了gc_stale_time的PROC文件信息。

static struct neigh_sysctl_table {struct ctl_table_header *sysctl_header;struct ctl_table neigh_vars[NEIGH_VAR_MAX + 1];
} neigh_sysctl_template __read_mostly = {.neigh_vars = {...NEIGH_SYSCTL_JIFFIES_ENTRY(DELAY_PROBE_TIME, "delay_first_probe_time"),

netlink接口

除了以上的PROC文件外,还可使用ip ntable命令查看和修改设备的邻居表参数。

# ip ntable show dev eth0
inet arp_cache dev eth0refcnt 12 reachable 28884 base_reachable 30000 retrans 1000 gc_stale 60000 delay_probe 5000 queue 31 app_probes 0 ucast_probes 3 mcast_probes 3 anycast_delay 1000 proxy_delay 800 proxy_queue 64 locktime 1000 

与PROC文件不同,这里显示的delay_probe时间单位为毫秒。如下将设备eth0的邻居表参数delay_probe修改为10秒钟。

# ip ntable change name arp_cache dev eth0 delay_probe 10000

内核函数neigh_init负责以上ip ntable change命令的处理。

static int __init neigh_init(void)
{...rtnl_register(PF_UNSPEC, RTM_SETNEIGHTBL, neightbl_set, NULL, 0);

如下为neightbl_set的实现,函数nla_get_msecs读取IP命令行设置的delay_probe_time的毫秒值参数。

static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack)
{struct neigh_table *tbl;struct nlattr *tb[NDTA_MAX+1];if (tb[NDTA_PARMS]) {struct neigh_parms *p;p = lookup_neigh_parms(tbl, net, ifindex);...for (i = 1; i <= NDTPA_MAX; i++) {if (tbp[i] == NULL) continue;switch (i) {...case NDTPA_DELAY_PROBE_TIME:NEIGH_VAR_SET(p, DELAY_PROBE_TIME, nla_get_msecs(tbp[i]));call_netevent_notifiers(NETEVENT_DELAY_PROBE_TIME_UPDATE, p);break;

对于arp协议,宏NEIGH_VAR_SET将修改全局变量arp_tbl的成员parms的data数组,具体为以NEIGH_VAR_DELAY_PROBE_TIME为所对应的成员的值。函数nla_get_msecs将命令行输入的毫秒值转换为内核使用的jiffies值。

#define NEIGH_VAR_SET(p, attr, val) neigh_var_set(p, NEIGH_VAR_ ## attr, val)static inline void neigh_var_set(struct neigh_parms *p, int index, int val)
{                set_bit(index, p->data_state);p->data[index] = val;
}

显示命令ip ntable show由内核中的函数neightbl_fill_parms填充值,对于delay_probe_time的值,由nla_put_msecs填充。

static int neightbl_fill_parms(struct sk_buff *skb, struct neigh_parms *parms)
{...if ((parms->dev &&...nla_put_msecs(skb, NDTPA_DELAY_PROBE_TIME,NEIGH_VAR(parms, DELAY_PROBE_TIME), NDTPA_PAD) ||

如下函数nla_put_msecs,其需要将内核使用delay_probe_time的jiffies表示的值转换为ip ntable show显示时的毫秒值,通过jiffies_to_msecs实现。

static inline int nla_put_msecs(struct sk_buff *skb, int attrtype,unsigned long njiffies, int padattr)
{u64 tmp = jiffies_to_msecs(njiffies);return nla_put_64bit(skb, attrtype, sizeof(u64), &tmp, padattr);
}

delay_probe_time处理

如下邻居表项超时处理函数neigh_timer_handler,如果表项状态为NUD_REACHABLE,但是已经超过reachable_time规定的时长没有确认了,分成以下两种情况处理:

1) 此表项还在被使用,最后一次的使用时间戳到当下时刻还没有超出DELAY_PROBE_TIME(默认5秒钟)定义的时长,将表项状态设置为NUD_DELAY。
2) 如果条件1)不满足,即表项上一次使用时间戳到当下时刻时长超过DELAY_PROBE_TIME定义,将表项状态设置为NUD_STALE。

static void neigh_timer_handler(struct timer_list *t)
{struct neighbour *neigh = from_timer(neigh, t, timer);...state = neigh->nud_state;now = jiffies;next = now + HZ;if (!(state & NUD_IN_TIMER))goto out;if (state & NUD_REACHABLE) {if (time_before_eq(now,neigh->confirmed + neigh->parms->reachable_time)) {neigh_dbg(2, "neigh %p is still alive\n", neigh);next = neigh->confirmed + neigh->parms->reachable_time;} else if (time_before_eq(now,neigh->used +NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME))) {neigh_dbg(2, "neigh %p is delayed\n", neigh);neigh->nud_state = NUD_DELAY;neigh->updated = jiffies;neigh_suspect(neigh);next = now + NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME);} else {neigh_dbg(2, "neigh %p is suspected\n", neigh);neigh->nud_state = NUD_STALE;neigh->updated = jiffies;neigh_suspect(neigh);notify = 1;}

如果此表项的初始状态已经为NUD_DELAY,但是在定时器超时(DELAY_PROBE_TIME)之前,邻居表项得到了确认,重新将表项状态设置为NUD_REACHABLE。否则,如果表项没有被确认,将其状态设置为NUD_PROBE,发送ARP请求报文,由函数neigh_probe实现。

    } else if (state & NUD_DELAY) {if (time_before_eq(now,neigh->confirmed +NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME))) {neigh_dbg(2, "neigh %p is now reachable\n", neigh);neigh->nud_state = NUD_REACHABLE;neigh->updated = jiffies;neigh_connect(neigh);notify = 1;next = neigh->confirmed + neigh->parms->reachable_time;} else {neigh_dbg(2, "neigh %p is probed\n", neigh);neigh->nud_state = NUD_PROBE;neigh->updated = jiffies;atomic_set(&neigh->probes, 0);notify = 1;next = now + NEIGH_VAR(neigh->parms, RETRANS_TIME);}} else {/* NUD_PROBE|NUD_INCOMPLETE */next = now + NEIGH_VAR(neigh->parms, RETRANS_TIME);}

邻居表项定时处理函数的时长不小于1/2秒。

    if (neigh->nud_state & NUD_IN_TIMER) {if (time_before(next, jiffies + HZ/2))next = jiffies + HZ/2;if (!mod_timer(&neigh->timer, next))neigh_hold(neigh);}if (neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) {neigh_probe(neigh);} else {

另外,在数据报文发送流程中,如果检测到相应邻居表项的状态为NUD_STALE,将其设置为NUD_DELAY,之后将定时器超时时间设置为DELAY_PROBE_TIME,到期之后发送probe报文,以便更新邻居表项。

int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
{int rc;bool immediate_probe = false;write_lock_bh(&neigh->lock);rc = 0;if (neigh->nud_state & (NUD_CONNECTED | NUD_DELAY | NUD_PROBE))goto out_unlock_bh;if (neigh->dead)goto out_dead;if (!(neigh->nud_state & (NUD_STALE | NUD_INCOMPLETE))) {...} else if (neigh->nud_state & NUD_STALE) {neigh_dbg(2, "neigh %p is delayed\n", neigh);neigh->nud_state = NUD_DELAY;neigh->updated = jiffies;neigh_add_timer(neigh, jiffies +NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME));}

内核版本 5.0

这篇关于邻居表项的delay_probe_time时长的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/511719

相关文章

nginx 504 Gateway Time-out

环境:PHP7.1,NGINX,Mysql 问题描述: 本地写了一个需要执行比较长时间的脚本,放到了php-fpm里面跑。用一个链接调用起这个脚本。发现第一次调用的时候,需要等比较久的时间,但是如果在执行期间再次请求这个链接。第二个请求的链接会返回504。甚至,直接在脚本最开始的地方中断都还是报 504. 但是如果请求其他链接,可以正常请求。 nginx 返回码、、 504 Gateway

Windows 内核驱动无法使用 __DATA__、__TIME__、__TIMESTAMP__ 解决方法

项目 -> 属性 -> Driver Settings -> Driver Model -> Allow Date, Time and Timestamp -> Yes。 感谢单总的解答和这篇文章:https://developercommunity.visualstudio.com/content/problem/186922/-timestamp-macro-not-defined-in-r

linux设备上的Onvif 实现5:实现Probe命令检测设备

学习Onvif的最关键步骤就是设备发现,一般来说开发的设备都是客户端,只要能被服务端正确发现就大功告成啦! 本文分别实现了客户端和服务端的识别流程,可以配合起来运行测试。 第一部分:实现Probe检测实例 代码目录: \\192.168.0.234\work\gaoht\gsoap\test \\192.168.0.234\work\gaoht\gsoap\probe-sample G

OSS报错The difference between the request time and the current time is too large

目录 一、问题描述二、问题原因三、解决方法 一、问题描述 文件上传阿里云 OSS 报错: The difference between the request time and the current time is too large 二、问题原因 请求发起的时间超过 OSS 服务器当前时间 15 分钟,OSS 判定该请求无效,返回报错。 三、解决方法 OSS

关于面试经常被问到的socket的TIME_WAIT状态的原因及解决办法和避免的办法

一查看现在time_wait的数量及浅析          netstat -an | grep TIME_WAIT | wc -l  发现系统存在大量TIME_WAIT状态的连接,通过调整内核参数解决,在 /etc/sysctl.conf中加入          net.ipv4.tcp_tw_recycle = 1    (表示开启TCP连接中TIME-WAIT sockets的快速回

Mysql中CURRENT_TIMESTAMP,CURRENT_DATE,CURRENT_TIME,now(),sysdate()各项值的区别

CURRENT_TIMESTAMP,CURRENT_DATE,CURRENT_TIME,now(),sysdate()各项值的区别,我们可以通过在终端下,查看结果就能知道: SELECT CURRENT_TIME, CURRENT_DATE, CURRENT_TIMESTAMP, now(), sysdate(); 比如我们要对某表插入数据,这个表add_time字段是datetime类

论文浅读之Mamba: Linear-Time Sequence Modeling with Selective State Spaces

介绍 这篇论文提出了一种新型的"选择性状态空间模型"(Selective State Space Model, S6)来解决之前结构化状态空间模型(SSM)在离散且信息密集的数据(如文本)上效果较差的问题。 Mamba 在语言处理、基因组学和音频分析等领域的应用中表现出色。其创新的模型采用了线性时间序列建模架构,结合了选择性状态空间,能够在语言、音频和基因组学等不同模式中提供卓越的性能。这种突破

一步步学习微软InfoPath2010和SP2010--第三章节--表单设计基础:处理InfoPath布局、控件和视图(7)--添加含规则的提交按钮到Flight Delay表单

准备:打开之前创建的Flight Delay表单。也可以下载Flight Delay Post exercise 2.xsn.右击模板文件,选择设计。         本练习,添加按钮控件到表单,按钮包含规则提交表单到一个邮件数据连接。 1. 在选项组控件下方或右边按下Enter几次。注意光标必须在控件外边。 2. 插入按钮控件 3. 在开始选项卡,点击居中 4. 控件工具选项卡,在标

一步步学习微软InfoPath2010和SP2010--第三章节--表单设计基础:处理InfoPath布局、控件和视图(6)--添加控件到Flight Delay表单

准备:打开之前创建的Flight Delay表单。也可以下载Flight Delay Post exercise 1.xsn.右击模板文件,选择设计。         本练习,继续创建Flight Delay表单。添加控件提供需要的功能。你需要捕获的数据包括在下边: 需要的数据 使用的控件 日期 日期选取器 航班号 文本框 航班延迟原因 下拉列表框 Fo

【读论文】Learning perturbations to explain time series predictions

文章目录 Abstract1. Introduction2. Background Work3. Method4. Experiments4.1 Hidden Markov model experiment4.2 MIMIC-III experiment 5. ConclusionReferences 论文地址:Learning Perturbations to Explain