static void neigh_timer_handler(unsigned long arg)
{
unsigned long now, next;
struct neighbour *neigh = (struct neighbour *)arg;
unsigned state;
int notify = 0;
write_lock(&neigh->lock);
state = neigh->nud_state;
now = jiffies;
next = now + HZ;
//有效性判断,若状态没有定时器运行
if (!(state & NUD_IN_TIMER)) {
#ifndef CONFIG_SMP
printk(KERN_WARNING "neigh: timer & !nud_in_timer\n");
#endif
goto out;
}
//若是NUD_REACHABLE延迟到达
if (state & NUD_REACHABLE) {
//若时间小于被证实可用时间与规定NUD_REACHABLE之间之和
//则说明对应邻居项仍然有效
if (time_before_eq(now,
neigh->confirmed + neigh->parms->reachable_time)) {
NEIGH_PRINTK2("neigh %p is still alive.\n", neigh);
//设置下次定时器到达时间
next = neigh->confirmed + neigh->parms->reachable_time;
} else if (
//若时间少于上次使用时间与delay时间。设定状定为
//NUD_DELAY
time_before_eq(now,
neigh->used + neigh->parms->delay_probe_time)) {
NEIGH_PRINTK2("neigh %p is delayed.\n", neigh);
neigh->nud_state = NUD_DELAY;
neigh_suspect(neigh);
//设定下次定时器到达时间
next = now + neigh->parms->delay_probe_time;
} else {
//否则将状态改为NUD_STALE
NEIGH_PRINTK2("neigh %p is suspected.\n", neigh);
neigh->nud_state = NUD_STALE;
neigh_suspect(neigh);
}
}
//如果是在NUD_DELAY状态中时间到达
else if (state & NUD_DELAY) {
//如果时间小于上次被证时间与延时之间之和
//表明在处理过程中又收到了应答包
//把状态更改为NUD_REACHABLE
if (time_before_eq(now,
neigh->confirmed + neigh->parms->delay_probe_time)) {
NEIGH_PRINTK2("neigh %p is now reachable.\n", neigh);
neigh->nud_state = NUD_REACHABLE;
//将邻居项对应out函数更改为conect_output函数
//加快发包速度
neigh_connect(neigh);
next = neigh->confirmed + neigh->parms->reachable_time;
} else {
//否则,则将状态更改为NUD_PROBE
NEIGH_PRINTK2("neigh %p is probed.\n", neigh);
neigh->nud_state = NUD_PROBE;
atomic_set(&neigh->probes, 0);
next = now + neigh->parms->retrans_time;
}
}
else {
//若时其它的状态
/* NUD_PROBE|NUD_INCOMPLETE */
next = now + neigh->parms->retrans_time;
}
//如果状态为NUD_INCOMPLETE或者NUD_PROBE
//而且重发数据包的次数超过neigh_max_probes()
//则将状态更为NUD_FAILED
if ((neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) &&
atomic_read(&neigh->probes) >= neigh_max_probes(neigh)) {
struct sk_buff *skb;
neigh->nud_state = NUD_FAILED;
notify = 1;
NEIGH_CACHE_STAT_INC(neigh->tbl, res_failed);
NEIGH_PRINTK2("neigh %p is failed.\n", neigh);
/* It is very thin place. report_unreachable is very complicated
routine. Particularly, it can hit the same neighbour entry!
So that, we try to be accurate and avoid dead loop. --ANK
*/
//如果定义了错误报告,运行之
while (neigh->nud_state == NUD_FAILED &&
(skb = __skb_dequeue(&neigh->arp_queue)) != NULL) {
write_unlock(&neigh->lock);
neigh->ops->error_report(neigh, skb);
write_lock(&neigh->lock);
}
//此邻居项不可用,释放arp_queue中的skb
skb_queue_purge(&neigh->arp_queue);
}
//调整定时器到达时间,设置定时器
if (neigh->nud_state & NUD_IN_TIMER) {
neigh_hold(neigh);
if (time_before(next, jiffies + HZ/2))
next = jiffies + HZ/2;
neigh->timer.expires = next;
add_timer(&neigh->timer);
}
//重发arp请求包
if (neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) {
//取队列中的第一个skb,如果队列为空,则返回NULL