neighbor.c 15.9 KB
Newer Older
1 2 3
/*
 *	BIRD -- OSPF
 *
4 5 6
 *	(c) 1999--2004 Ondrej Filip <feela@network.cz>
 *	(c) 2009--2014 Ondrej Zajicek <santiago@crfreenet.org>
 *	(c) 2009--2014 CZ.NIC z.s.p.o.
7 8 9 10 11 12
 *
 *	Can be freely distributed and used under the terms of the GNU GPL.
 */

#include "ospf.h"

13 14 15

const char *ospf_ns_names[] = {
  "Down", "Attempt", "Init", "2-Way", "ExStart", "Exchange", "Loading", "Full"
Ondřej Filip's avatar
Ondřej Filip committed
16 17
};

18 19 20 21
const char *ospf_inm_names[] = {
  "HelloReceived", "Start", "2-WayReceived", "NegotiationDone", "ExchangeDone",
  "BadLSReq", "LoadingDone", "AdjOK?", "SeqNumberMismatch", "1-WayReceived",
  "KillNbr", "InactivityTimer", "LLDown"
Ondřej Filip's avatar
Ondřej Filip committed
22
};
Ondřej Filip's avatar
Ondřej Filip committed
23

24 25

static int can_do_adj(struct ospf_neighbor *n);
26 27 28 29 30 31
static void inactivity_timer_hook(timer * timer);
static void dbdes_timer_hook(timer *t);
static void lsrq_timer_hook(timer *t);
static void lsrt_timer_hook(timer *t);
static void ackd_timer_hook(timer *t);

32 33

static void
34
init_lists(struct ospf_proto *p, struct ospf_neighbor *n)
35 36
{
  s_init_list(&(n->lsrql));
37
  n->lsrqi = SHEAD(n->lsrql);
38
  n->lsrqh = ospf_top_new(p, n->pool);
39 40

  s_init_list(&(n->lsrtl));
41 42 43 44 45 46 47 48 49 50 51 52 53 54
  n->lsrth = ospf_top_new(p, n->pool);
}

static void
release_lsrtl(struct ospf_proto *p, struct ospf_neighbor *n)
{
  struct top_hash_entry *ret, *en;

  WALK_SLIST(ret, n->lsrtl)
  {
    en = ospf_hash_find_entry(p->gr, ret);
    if (en)
      en->ret_count--;
  }
55
}
56

Ondřej Zajíček's avatar
Ondřej Zajíček committed
57
/* Resets LSA request and retransmit lists.
58
 * We do not reset DB summary list iterator here,
59 60 61
 * it is reset during entering EXCHANGE state.
 */
static void
62
reset_lists(struct ospf_proto *p, struct ospf_neighbor *n)
63
{
64
  release_lsrtl(p, n);
65 66
  ospf_top_free(n->lsrqh);
  ospf_top_free(n->lsrth);
67 68 69 70 71 72 73
  ospf_reset_lsack_queue(n);

  tm_stop(n->dbdes_timer);
  tm_stop(n->lsrq_timer);
  tm_stop(n->lsrt_timer);
  tm_stop(n->ackd_timer);

74
  init_lists(p, n);
75
}
76 77 78 79

struct ospf_neighbor *
ospf_neighbor_new(struct ospf_iface *ifa)
{
80 81
  struct ospf_proto *p = ifa->oa->po;
  struct pool *pool = rp_new(p->p.pool, "OSPF Neighbor");
82 83 84 85 86 87
  struct ospf_neighbor *n = mb_allocz(pool, sizeof(struct ospf_neighbor));

  n->pool = pool;
  n->ifa = ifa;
  add_tail(&ifa->neigh_list, NODE n);
  n->adj = 0;
88
  n->csn = 0;
Ondřej Filip's avatar
Ondřej Filip committed
89
  n->state = NEIGHBOR_DOWN;
90

91
  init_lists(p, n);
92
  s_init(&(n->dbsi), &(p->lsal));
93

94 95
  init_list(&n->ackl[ACKL_DIRECT]);
  init_list(&n->ackl[ACKL_DELAY]);
96 97 98 99 100 101

  n->inactim = tm_new_set(pool, inactivity_timer_hook, n, 0, 0);
  n->dbdes_timer = tm_new_set(pool, dbdes_timer_hook, n, 0, ifa->rxmtint);
  n->lsrq_timer = tm_new_set(pool, lsrq_timer_hook, n, 0, ifa->rxmtint);
  n->lsrt_timer = tm_new_set(pool, lsrt_timer_hook, n, 0, ifa->rxmtint);
  n->ackd_timer = tm_new_set(pool, ackd_timer_hook, n, 0, ifa->rxmtint / 2);
102

Ondřej Filip's avatar
Ondřej Filip committed
103
  return (n);
104 105
}

106 107 108 109 110
static void
ospf_neigh_down(struct ospf_neighbor *n)
{
  struct ospf_iface *ifa = n->ifa;
  struct ospf_proto *p = ifa->oa->po;
111
  u32 rid = n->rid;
112 113 114 115 116 117 118 119 120 121 122 123 124

  if ((ifa->type == OSPF_IT_NBMA) || (ifa->type == OSPF_IT_PTMP))
  {
    struct nbma_node *nn = find_nbma_node(ifa, n->ip);
    if (nn)
      nn->found = 0;
  }

  s_get(&(n->dbsi));
  release_lsrtl(p, n);
  rem_node(NODE n);
  rfree(n->pool);

125
  OSPF_TRACE(D_EVENTS, "Neighbor %R on %s removed", rid, ifa->ifname);
126 127
}

128
/**
129
 * ospf_neigh_chstate - handles changes related to new or lod state of neighbor
130 131 132
 * @n: OSPF neighbor
 * @state: new state
 *
133
 * Many actions have to be taken acording to a change of state of a neighbor. It
134 135
 * starts rxmt timers, call interface state machine etc.
 */
136
static void
137
ospf_neigh_chstate(struct ospf_neighbor *n, u8 state)
138
{
139 140 141 142
  struct ospf_iface *ifa = n->ifa;
  struct ospf_proto *p = ifa->oa->po;
  u8 old_state = n->state;
  int old_fadj = ifa->fadj;
143

144 145
  if (state == old_state)
    return;
146

147 148
  OSPF_TRACE(D_EVENTS, "Neighbor %R on %s changed state from %s to %s",
	     n->rid, ifa->ifname, ospf_ns_names[old_state], ospf_ns_names[state]);
Ondřej Filip's avatar
Ondřej Filip committed
149

150
  n->state = state;
Ondřej Filip's avatar
Ondřej Filip committed
151

152 153 154
  /* Increase number of partial adjacencies */
  if ((state == NEIGHBOR_EXCHANGE) || (state == NEIGHBOR_LOADING))
    p->padj++;
Ondřej Filip's avatar
Ondřej Filip committed
155

156 157 158
  /* Decrease number of partial adjacencies */
  if ((old_state == NEIGHBOR_EXCHANGE) || (old_state == NEIGHBOR_LOADING))
    p->padj--;
Ondřej Filip's avatar
Ondřej Filip committed
159

160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
  /* Increase number of full adjacencies */
  if (state == NEIGHBOR_FULL)
    ifa->fadj++;

  /* Decrease number of full adjacencies */
  if (old_state == NEIGHBOR_FULL)
    ifa->fadj--;

  if (ifa->fadj != old_fadj)
  {
    /* RFC 2328 12.4 Event 4 - neighbor enters/leaves Full state */
    ospf_notify_rt_lsa(ifa->oa);
    ospf_notify_net_lsa(ifa);

    /* RFC 2328 12.4 Event 8 - vlink state change */
    if (ifa->type == OSPF_IT_VLINK)
      ospf_notify_rt_lsa(ifa->voa);
  }

  if (state == NEIGHBOR_EXSTART)
  {
    /* First time adjacency */
    if (n->adj == 0)
      n->dds = random_u32();

    n->dds++;
    n->myimms = DBDES_IMMS;
187 188 189

    tm_start(n->dbdes_timer, 0);
    tm_start(n->ackd_timer, ifa->rxmtint / 2);
190
  }
191 192 193

  if (state > NEIGHBOR_EXSTART)
    n->myimms &= ~DBDES_I;
194

195 196 197 198 199
  /* Generate NeighborChange event if needed, see RFC 2328 9.2 */
  if ((state == NEIGHBOR_2WAY) && (old_state < NEIGHBOR_2WAY))
    ospf_iface_sm(ifa, ISM_NEICH);
  if ((state < NEIGHBOR_2WAY) && (old_state >= NEIGHBOR_2WAY))
    ospf_iface_sm(ifa, ISM_NEICH);
200 201
}

202 203 204 205 206
/**
 * ospf_neigh_sm - ospf neighbor state machine
 * @n: neighor
 * @event: actual event
 *
207 208 209 210 211
 * This part implements the neighbor state machine as described in 10.3 of
 * RFC 2328. The only difference is that state %NEIGHBOR_ATTEMPT is not
 * used. We discover neighbors on nonbroadcast networks in the
 * same way as on broadcast networks. The only difference is in
 * sending hello packets. These are sent to IPs listed in
212 213
 * @ospf_iface->nbma_list .
 */
214 215 216
void
ospf_neigh_sm(struct ospf_neighbor *n, int event)
{
217
  struct ospf_proto *p = n->ifa->oa->po;
218

219 220
  DBG("Neighbor state machine for %R on %s, event %s\n",
      n->rid, n->ifa->ifname, ospf_inm_names[event]);
Ondřej Filip's avatar
Ondřej Filip committed
221

Ondřej Filip's avatar
Ondřej Filip committed
222
  switch (event)
223
  {
Ondřej Filip's avatar
Ondřej Filip committed
224
  case INM_START:
225
    ospf_neigh_chstate(n, NEIGHBOR_ATTEMPT);
Ondřej Filip's avatar
Ondřej Filip committed
226 227
    /* NBMA are used different way */
    break;
228

Ondřej Filip's avatar
Ondřej Filip committed
229
  case INM_HELLOREC:
230 231
    if (n->state < NEIGHBOR_INIT)
      ospf_neigh_chstate(n, NEIGHBOR_INIT);
232 233 234

    /* Restart inactivity timer */
    tm_start(n->inactim, n->ifa->deadint);
Ondřej Filip's avatar
Ondřej Filip committed
235
    break;
236

Ondřej Filip's avatar
Ondřej Filip committed
237 238
  case INM_2WAYREC:
    if (n->state < NEIGHBOR_2WAY)
239
      ospf_neigh_chstate(n, NEIGHBOR_2WAY);
Ondřej Filip's avatar
Ondřej Filip committed
240
    if ((n->state == NEIGHBOR_2WAY) && can_do_adj(n))
241
      ospf_neigh_chstate(n, NEIGHBOR_EXSTART);
Ondřej Filip's avatar
Ondřej Filip committed
242
    break;
243

Ondřej Filip's avatar
Ondřej Filip committed
244 245 246
  case INM_NEGDONE:
    if (n->state == NEIGHBOR_EXSTART)
    {
247
      ospf_neigh_chstate(n, NEIGHBOR_EXCHANGE);
248 249 250

      /* Reset DB summary list iterator */
      s_get(&(n->dbsi));
251
      s_init(&(n->dbsi), &p->lsal);
252

253 254
      /* Add MaxAge LSA entries to retransmission list */
      ospf_add_flushed_to_lsrt(p, n);
Ondřej Filip's avatar
Ondřej Filip committed
255 256 257 258
    }
    else
      bug("NEGDONE and I'm not in EXSTART?");
    break;
259

Ondřej Filip's avatar
Ondřej Filip committed
260
  case INM_EXDONE:
261 262 263 264
    if (!EMPTY_SLIST(n->lsrql))
      ospf_neigh_chstate(n, NEIGHBOR_LOADING);
    else
      ospf_neigh_chstate(n, NEIGHBOR_FULL);
Ondřej Filip's avatar
Ondřej Filip committed
265
    break;
266

Ondřej Filip's avatar
Ondřej Filip committed
267
  case INM_LOADDONE:
268
    ospf_neigh_chstate(n, NEIGHBOR_FULL);
Ondřej Filip's avatar
Ondřej Filip committed
269
    break;
270

Ondřej Filip's avatar
Ondřej Filip committed
271
  case INM_ADJOK:
272 273
    /* Can In build adjacency? */
    if ((n->state == NEIGHBOR_2WAY) && can_do_adj(n))
Ondřej Filip's avatar
Ondřej Filip committed
274
    {
275 276 277 278 279 280
      ospf_neigh_chstate(n, NEIGHBOR_EXSTART);
    }
    else if ((n->state >= NEIGHBOR_EXSTART) && !can_do_adj(n))
    {
      reset_lists(p, n);
      ospf_neigh_chstate(n, NEIGHBOR_2WAY);
Ondřej Filip's avatar
Ondřej Filip committed
281 282
    }
    break;
283

Ondřej Filip's avatar
Ondřej Filip committed
284 285 286 287
  case INM_SEQMIS:
  case INM_BADLSREQ:
    if (n->state >= NEIGHBOR_EXCHANGE)
    {
288
      reset_lists(p, n);
289
      ospf_neigh_chstate(n, NEIGHBOR_EXSTART);
Ondřej Filip's avatar
Ondřej Filip committed
290 291
    }
    break;
292

Ondřej Filip's avatar
Ondřej Filip committed
293 294 295
  case INM_KILLNBR:
  case INM_LLDOWN:
  case INM_INACTTIM:
296 297 298
    /* No need for reset_lists() */
    ospf_neigh_chstate(n, NEIGHBOR_DOWN);
    ospf_neigh_down(n);
Ondřej Filip's avatar
Ondřej Filip committed
299
    break;
300

Ondřej Filip's avatar
Ondřej Filip committed
301
  case INM_1WAYREC:
302
    reset_lists(p, n);
303
    ospf_neigh_chstate(n, NEIGHBOR_INIT);
Ondřej Filip's avatar
Ondřej Filip committed
304
    break;
305

Ondřej Filip's avatar
Ondřej Filip committed
306
  default:
307
    bug("%s: INM - Unknown event?", p->p.name);
Ondřej Filip's avatar
Ondřej Filip committed
308
    break;
309 310 311
  }
}

312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
static int
can_do_adj(struct ospf_neighbor *n)
{
  struct ospf_iface *ifa = n->ifa;
  struct ospf_proto *p = ifa->oa->po;
  int i = 0;

  switch (ifa->type)
  {
  case OSPF_IT_PTP:
  case OSPF_IT_PTMP:
  case OSPF_IT_VLINK:
    i = 1;
    break;
  case OSPF_IT_BCAST:
  case OSPF_IT_NBMA:
    switch (ifa->state)
    {
    case OSPF_IS_DOWN:
    case OSPF_IS_LOOP:
      bug("%s: Iface %s in down state?", p->p.name, ifa->ifname);
      break;
    case OSPF_IS_WAITING:
      DBG("%s: Neighbor? on iface %s\n", p->p.name, ifa->ifname);
      break;
    case OSPF_IS_DROTHER:
      if (((n->rid == ifa->drid) || (n->rid == ifa->bdrid))
	  && (n->state >= NEIGHBOR_2WAY))
	i = 1;
      break;
    case OSPF_IS_PTP:
    case OSPF_IS_BACKUP:
    case OSPF_IS_DR:
      if (n->state >= NEIGHBOR_2WAY)
	i = 1;
      break;
    default:
      bug("%s: Iface %s in unknown state?", p->p.name, ifa->ifname);
      break;
    }
    break;
  default:
    bug("%s: Iface %s is unknown type?", p->p.name, ifa->ifname);
    break;
  }
  DBG("%s: Iface %s can_do_adj=%d\n", p->p.name, ifa->ifname, i);
  return i;
}


362
static inline u32 neigh_get_id(struct ospf_proto *p UNUSED4 UNUSED6, struct ospf_neighbor *n)
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
{ return ospf_is_v2(p) ? ipa_to_u32(n->ip) : n->rid; }

static struct ospf_neighbor *
elect_bdr(struct ospf_proto *p, list nl)
{
  struct ospf_neighbor *neigh, *n1, *n2;
  u32 nid;

  n1 = NULL;
  n2 = NULL;
  WALK_LIST(neigh, nl)			/* First try those decl. themselves */
  {
    nid = neigh_get_id(p, neigh);

    if (neigh->state >= NEIGHBOR_2WAY)	/* Higher than 2WAY */
      if (neigh->priority > 0)		/* Eligible */
	if (neigh->dr != nid)		/* And not decl. itself DR */
	{
	  if (neigh->bdr == nid)	/* Declaring BDR */
	  {
	    if (n1 != NULL)
	    {
	      if (neigh->priority > n1->priority)
		n1 = neigh;
	      else if (neigh->priority == n1->priority)
		if (neigh->rid > n1->rid)
		  n1 = neigh;
	    }
	    else
	    {
	      n1 = neigh;
	    }
	  }
	  else			/* And NOT declaring BDR */
	  {
	    if (n2 != NULL)
	    {
	      if (neigh->priority > n2->priority)
		n2 = neigh;
	      else if (neigh->priority == n2->priority)
		if (neigh->rid > n2->rid)
		  n2 = neigh;
	    }
	    else
	    {
	      n2 = neigh;
	    }
	  }
	}
  }
  if (n1 == NULL)
    n1 = n2;

  return (n1);
}

static struct ospf_neighbor *
elect_dr(struct ospf_proto *p, list nl)
{
  struct ospf_neighbor *neigh, *n;
  u32 nid;

  n = NULL;
  WALK_LIST(neigh, nl)			/* And now DR */
  {
    nid = neigh_get_id(p, neigh);

    if (neigh->state >= NEIGHBOR_2WAY)	/* Higher than 2WAY */
      if (neigh->priority > 0)		/* Eligible */
	if (neigh->dr == nid)		/* And declaring itself DR */
	{
	  if (n != NULL)
	  {
	    if (neigh->priority > n->priority)
	      n = neigh;
	    else if (neigh->priority == n->priority)
	      if (neigh->rid > n->rid)
		n = neigh;
	  }
	  else
	  {
	    n = neigh;
	  }
	}
  }

  return (n);
}

452
/**
453
 * ospf_dr_election - (Backup) Designed Router election
454 455
 * @ifa: actual interface
 *
456
 * When the wait timer fires, it is time to elect (Backup) Designated Router.
457 458 459 460 461
 * Structure describing me is added to this list so every electing router has
 * the same list. Backup Designated Router is elected before Designated
 * Router. This process is described in 9.4 of RFC 2328. The function is
 * supposed to be called only from ospf_iface_sm() as a part of the interface
 * state machine.
462
 */
463
void
464
ospf_dr_election(struct ospf_iface *ifa)
465
{
466
  struct ospf_proto *p = ifa->oa->po;
Ondřej Filip's avatar
Ondřej Filip committed
467
  struct ospf_neighbor *neigh, *ndr, *nbdr, me;
468
  u32 myid = p->router_id;
469

470
  DBG("(B)DR election.\n");
471

Ondřej Filip's avatar
Ondřej Filip committed
472 473 474
  me.state = NEIGHBOR_2WAY;
  me.rid = myid;
  me.priority = ifa->priority;
475
  me.ip = ifa->addr->ip;
476

477 478
  me.dr  = ospf_is_v2(p) ? ipa_to_u32(ifa->drip) : ifa->drid;
  me.bdr = ospf_is_v2(p) ? ipa_to_u32(ifa->bdrip) : ifa->bdrid;
479
  me.iface_id = ifa->iface_id;
480

Ondřej Filip's avatar
Ondřej Filip committed
481
  add_tail(&ifa->neigh_list, NODE & me);
482

483 484
  nbdr = elect_bdr(p, ifa->neigh_list);
  ndr = elect_dr(p, ifa->neigh_list);
485

Ondřej Filip's avatar
Ondřej Filip committed
486 487
  if (ndr == NULL)
    ndr = nbdr;
488

489
  /* 9.4. (4) */
Ondřej Filip's avatar
Ondřej Filip committed
490 491 492 493
  if (((ifa->drid == myid) && (ndr != &me))
      || ((ifa->drid != myid) && (ndr == &me))
      || ((ifa->bdrid == myid) && (nbdr != &me))
      || ((ifa->bdrid != myid) && (nbdr == &me)))
494
  {
495 496
    me.dr = ndr ? neigh_get_id(p, ndr) : 0;
    me.bdr = nbdr ? neigh_get_id(p, nbdr) : 0;
Ondřej Filip's avatar
Ondřej Filip committed
497

498 499
    nbdr = elect_bdr(p, ifa->neigh_list);
    ndr = elect_dr(p, ifa->neigh_list);
500

501 502
    if (ndr == NULL)
      ndr = nbdr;
503 504
  }

505 506 507 508 509
  rem_node(NODE & me);


  u32 old_drid = ifa->drid;
  u32 old_bdrid = ifa->bdrid;
510

511 512
  ifa->drid = ndr ? ndr->rid : 0;
  ifa->drip = ndr ? ndr->ip  : IPA_NONE;
513 514
  ifa->dr_iface_id = ndr ? ndr->iface_id : 0;

515 516 517
  ifa->bdrid = nbdr ? nbdr->rid : 0;
  ifa->bdrip = nbdr ? nbdr->ip  : IPA_NONE;

518
  DBG("DR=%R, BDR=%R\n", ifa->drid, ifa->bdrid);
519

520
  /* We are part of the interface state machine */
521
  if (ifa->drid == myid)
Ondřej Filip's avatar
Ondřej Filip committed
522
    ospf_iface_chstate(ifa, OSPF_IS_DR);
523 524
  else if (ifa->bdrid == myid)
    ospf_iface_chstate(ifa, OSPF_IS_BACKUP);
525
  else
526
    ospf_iface_chstate(ifa, OSPF_IS_DROTHER);
527

528 529
  /* Review neighbor adjacencies if DR or BDR changed */
  if ((ifa->drid != old_drid) || (ifa->bdrid != old_bdrid))
Ondřej Filip's avatar
Ondřej Filip committed
530
    WALK_LIST(neigh, ifa->neigh_list)
531 532 533 534 535 536
      if (neigh->state >= NEIGHBOR_2WAY)
	ospf_neigh_sm(neigh, INM_ADJOK);

  /* RFC 2328 12.4 Event 3 - DR change */
  if (ifa->drid != old_drid)
    ospf_notify_rt_lsa(ifa->oa);
537 538 539 540 541 542
}

struct ospf_neighbor *
find_neigh(struct ospf_iface *ifa, u32 rid)
{
  struct ospf_neighbor *n;
543 544 545 546 547
  WALK_LIST(n, ifa->neigh_list)
    if (n->rid == rid)
      return n;
  return NULL;
}
548

549 550 551 552 553 554 555
struct ospf_neighbor *
find_neigh_by_ip(struct ospf_iface *ifa, ip_addr ip)
{
  struct ospf_neighbor *n;
  WALK_LIST(n, ifa->neigh_list)
    if (ipa_equal(n->ip, ip))
      return n;
556 557 558
  return NULL;
}

559
static void
560
inactivity_timer_hook(timer * timer)
561
{
562
  struct ospf_neighbor *n = (struct ospf_neighbor *) timer->data;
563
  struct ospf_proto *p = n->ifa->oa->po;
564

565
  OSPF_TRACE(D_EVENTS, "Inactivity timer expired for nbr %R on %s",
566 567
	     n->rid, n->ifa->ifname);
  ospf_neigh_sm(n, INM_INACTTIM);
568
}
569

570 571 572 573
static void
ospf_neigh_bfd_hook(struct bfd_request *req)
{
  struct ospf_neighbor *n = req->data;
574
  struct ospf_proto *p = n->ifa->oa->po;
575 576 577

  if (req->down)
  {
578
    OSPF_TRACE(D_EVENTS, "BFD session down for nbr %R on %s",
579 580
	       n->rid, n->ifa->ifname);
    ospf_neigh_sm(n, INM_INACTTIM);
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
  }
}

void
ospf_neigh_update_bfd(struct ospf_neighbor *n, int use_bfd)
{
  if (use_bfd && !n->bfd_req)
    n->bfd_req = bfd_request_session(n->pool, n->ip, n->ifa->addr->ip, n->ifa->iface,
				     ospf_neigh_bfd_hook, n);

  if (!use_bfd && n->bfd_req)
  {
    rfree(n->bfd_req);
    n->bfd_req = NULL;
  }
}


599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
static void
dbdes_timer_hook(timer *t)
{
  struct ospf_neighbor *n = t->data;
  struct ospf_proto *p = n->ifa->oa->po;

  // OSPF_TRACE(D_EVENTS, "DBDES timer expired for nbr %R on %s", n->rid, n->ifa->ifname);

  if (n->state == NEIGHBOR_EXSTART)
    ospf_send_dbdes(p, n);

  if ((n->state == NEIGHBOR_EXCHANGE) && (n->myimms & DBDES_MS))
    ospf_rxmt_dbdes(p, n);
}

static void
lsrq_timer_hook(timer *t)
{
  struct ospf_neighbor *n = t->data;
  struct ospf_proto *p = n->ifa->oa->po;

  // OSPF_TRACE(D_EVENTS, "LSRQ timer expired for nbr %R on %s", n->rid, n->ifa->ifname);

  if ((n->state >= NEIGHBOR_EXCHANGE) && !EMPTY_SLIST(n->lsrql))
    ospf_send_lsreq(p, n);
}

static void
lsrt_timer_hook(timer *t)
{
  struct ospf_neighbor *n = t->data;
  struct ospf_proto *p = n->ifa->oa->po;

  // OSPF_TRACE(D_EVENTS, "LSRT timer expired for nbr %R on %s", n->rid, n->ifa->ifname);

  if ((n->state >= NEIGHBOR_EXCHANGE) && !EMPTY_SLIST(n->lsrtl))
    ospf_rxmt_lsupd(p, n);
}

static void
ackd_timer_hook(timer *t)
{
  struct ospf_neighbor *n = t->data;
  struct ospf_proto *p = n->ifa->oa->po;

  ospf_send_lsack(p, n, ACKL_DELAY);
}


648 649 650
void
ospf_sh_neigh_info(struct ospf_neighbor *n)
{
Ondřej Filip's avatar
Ondřej Filip committed
651
  struct ospf_iface *ifa = n->ifa;
652
  char *pos = "PtP  ";
Ondřej Filip's avatar
Ondřej Filip committed
653 654 655 656
  char etime[6];
  int exp, sec, min;

  exp = n->inactim->expires - now;
657 658
  sec = exp % 60;
  min = exp / 60;
Ondřej Filip's avatar
Ondřej Filip committed
659 660 661 662 663 664 665 666 667
  if (min > 59)
  {
    bsprintf(etime, "-Inf-");
  }
  else
  {
    bsprintf(etime, "%02u:%02u", min, sec);
  }

668 669 670
  if ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_NBMA))
  {
    if (n->rid == ifa->drid)
671
      pos = "DR   ";
672
    else if (n->rid == ifa->bdrid)
673
      pos = "BDR  ";
674
    else
675
      pos = "Other";
676
  }
Ondřej Filip's avatar
Ondřej Filip committed
677

678
  cli_msg(-1013, "%-1R\t%3u\t%s/%s\t%-5s\t%-10s %-1I", n->rid, n->priority,
679
	  ospf_ns_names[n->state], pos, etime, ifa->ifname, n->ip);
680
}