neighbor.c 14.5 KB
Newer Older
1 2 3
/*
 *	BIRD -- OSPF
 *
4
 *	(c) 1999 - 2004 Ondrej Filip <feela@network.cz>
5 6 7 8 9 10
 *
 *	Can be freely distributed and used under the terms of the GNU GPL.
 */

#include "ospf.h"

Ondřej Filip's avatar
Ondřej Filip committed
11 12 13 14 15 16 17 18 19 20 21 22
char *ospf_ns[] = { "    down",
  " attempt",
  "    init",
  "    2way",
  " exstart",
  "exchange",
  " loading",
  "    full"
};

const char *ospf_inm[] =
  { "hello received", "neighbor start", "2-way received",
Ondřej Filip's avatar
Ondřej Filip committed
23 24
  "negotiation done", "exstart done", "bad ls request", "load done",
  "adjacency ok?", "sequence mismatch", "1-way received", "kill neighbor",
Ondřej Filip's avatar
Ondřej Filip committed
25 26
  "inactivity timer", "line down"
};
Ondřej Filip's avatar
Ondřej Filip committed
27

28

Ondřej Filip's avatar
Ondřej Filip committed
29 30 31
void neighbor_timer_hook(timer * timer);
void rxmt_timer_hook(timer * timer);
void ackd_timer_hook(timer * t);
32 33 34 35

struct ospf_neighbor *
ospf_neighbor_new(struct ospf_iface *ifa)
{
36
  struct proto *p = (struct proto *) (ifa->oa->po);
37 38 39 40 41 42 43
  struct pool *pool = rp_new(p->pool, "OSPF Neighbor");
  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;
44
  n->csn = 0;
Ondřej Filip's avatar
Ondřej Filip committed
45 46
  n->ldbdes = mb_allocz(pool, ifa->iface->mtu);
  n->state = NEIGHBOR_DOWN;
47 48 49 50 51 52 53 54 55 56 57 58 59 60

  n->inactim = tm_new(pool);
  n->inactim->data = n;
  n->inactim->randomize = 0;
  n->inactim->hook = neighbor_timer_hook;
  n->inactim->recurrent = 0;
  DBG("%s: Installing inactivity timer.\n", p->name);

  n->rxmt_timer = tm_new(pool);
  n->rxmt_timer->data = n;
  n->rxmt_timer->randomize = 0;
  n->rxmt_timer->hook = rxmt_timer_hook;
  n->rxmt_timer->recurrent = ifa->rxmtint;
  s_init_list(&(n->lsrql));
61
  n->lsrqh = ospf_top_new(pool);
62
  s_init_list(&(n->lsrtl));
63
  n->lsrth = ospf_top_new(pool);
64 65
  s_init(&(n->lsrqi), &(n->lsrql));
  s_init(&(n->lsrti), &(n->lsrtl));
Ondřej Filip's avatar
Ondřej Filip committed
66
  tm_start(n->rxmt_timer, n->ifa->rxmtint);
67 68 69 70 71 72
  DBG("%s: Installing rxmt timer.\n", p->name);

  n->ackd_timer = tm_new(pool);
  n->ackd_timer->data = n;
  n->ackd_timer->randomize = 0;
  n->ackd_timer->hook = ackd_timer_hook;
Ondřej Filip's avatar
Ondřej Filip committed
73
  n->ackd_timer->recurrent = ifa->rxmtint / 2;
74 75
  init_list(&n->ackl[ACKL_DIRECT]);
  init_list(&n->ackl[ACKL_DELAY]);
Ondřej Filip's avatar
Ondřej Filip committed
76
  tm_start(n->ackd_timer, n->ifa->rxmtint / 2);
77 78
  DBG("%s: Installing ackd timer.\n", p->name);

Ondřej Filip's avatar
Ondřej Filip committed
79
  return (n);
80 81
}

82 83 84 85 86
/**
 * neigh_chstate - handles changes related to new or lod state of neighbor
 * @n: OSPF neighbor
 * @state: new state
 *
87
 * Many actions have to be taken acording to a change of state of a neighbor. It
88 89 90
 * starts rxmt timers, call interface state machine etc.
 */

91 92 93
void
neigh_chstate(struct ospf_neighbor *n, u8 state)
{
94
  u8 oldstate;
95

Ondřej Filip's avatar
Ondřej Filip committed
96
  oldstate = n->state;
97

Ondřej Filip's avatar
Ondřej Filip committed
98
  if (oldstate != state)
99
  {
Ondřej Filip's avatar
Ondřej Filip committed
100 101 102
    struct ospf_iface *ifa = n->ifa;
    struct proto_ospf *po = ifa->oa->po;
    struct proto *p = &po->proto;
Ondřej Filip's avatar
Ondřej Filip committed
103

Ondřej Filip's avatar
Ondřej Filip committed
104
    n->state = state;
Ondřej Filip's avatar
Ondřej Filip committed
105

Ondřej Filip's avatar
Ondřej Filip committed
106 107
    OSPF_TRACE(D_EVENTS, "Neighbor %I changes state from \"%s\" to \"%s\".",
	       n->ip, ospf_ns[oldstate], ospf_ns[state]);
Ondřej Filip's avatar
Ondřej Filip committed
108

Ondřej Filip's avatar
Ondřej Filip committed
109
    if ((state == NEIGHBOR_2WAY) && (oldstate < NEIGHBOR_2WAY))
Ondřej Filip's avatar
Ondřej Filip committed
110
      ospf_iface_sm(ifa, ISM_NEICH);
Ondřej Filip's avatar
Ondřej Filip committed
111
    if ((state < NEIGHBOR_2WAY) && (oldstate >= NEIGHBOR_2WAY))
Ondřej Filip's avatar
Ondřej Filip committed
112
      ospf_iface_sm(ifa, ISM_NEICH);
Ondřej Filip's avatar
Ondřej Filip committed
113

Ondřej Filip's avatar
Ondřej Filip committed
114
    if (oldstate == NEIGHBOR_FULL)	/* Decrease number of adjacencies */
115
    {
116
      ifa->fadj--;
117
      schedule_rt_lsa(ifa->oa);
118
      if (ifa->type == OSPF_IT_VLINK) schedule_rt_lsa(ifa->voa);
119
      schedule_net_lsa(ifa);
120
    }
Ondřej Filip's avatar
Ondřej Filip committed
121 122

    if (state == NEIGHBOR_FULL)	/* Increase number of adjacencies */
123
    {
124
      ifa->fadj++;
125
      schedule_rt_lsa(ifa->oa);
126
      if (ifa->type == OSPF_IT_VLINK) schedule_rt_lsa(ifa->voa);
127
      schedule_net_lsa(ifa);
128
    }
Ondřej Filip's avatar
Ondřej Filip committed
129
    if (state == NEIGHBOR_EXSTART)
130
    {
Ondřej Filip's avatar
Ondřej Filip committed
131
      if (n->adj == 0)		/* First time adjacency */
132
      {
Ondřej Filip's avatar
Ondřej Filip committed
133
	n->dds = random_u32();
134 135
      }
      n->dds++;
Ondřej Filip's avatar
Ondřej Filip committed
136 137 138 139
      n->myimms.byte = 0;
      n->myimms.bit.ms = 1;
      n->myimms.bit.m = 1;
      n->myimms.bit.i = 1;
140
    }
Ondřej Filip's avatar
Ondřej Filip committed
141 142
    if (state > NEIGHBOR_EXSTART)
      n->myimms.bit.i = 0;
143 144 145 146 147 148
  }
}

struct ospf_neighbor *
electbdr(list nl)
{
Ondřej Filip's avatar
Ondřej Filip committed
149
  struct ospf_neighbor *neigh, *n1, *n2;
150

Ondřej Filip's avatar
Ondřej Filip committed
151 152 153
  n1 = NULL;
  n2 = NULL;
  WALK_LIST(neigh, nl)		/* First try those decl. themselves */
154
  {
Ondřej Filip's avatar
Ondřej Filip committed
155 156 157
    if (neigh->state >= NEIGHBOR_2WAY)	/* Higher than 2WAY */
      if (neigh->priority > 0)	/* Eligible */
	if (ipa_compare(neigh->ip, neigh->dr) != 0)	/* And not decl. itself DR */
158
	{
Ondřej Filip's avatar
Ondřej Filip committed
159 160 161 162 163 164 165 166 167 168
	  if (ipa_compare(neigh->ip, neigh->bdr) == 0)	/* 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;
	    }
169
	    else
Ondřej Filip's avatar
Ondřej Filip committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183
	    {
	      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;
	    }
184
	    else
Ondřej Filip's avatar
Ondřej Filip committed
185 186 187 188 189
	    {
	      n2 = neigh;
	    }
	  }
	}
190
  }
Ondřej Filip's avatar
Ondřej Filip committed
191 192
  if (n1 == NULL)
    n1 = n2;
193

Ondřej Filip's avatar
Ondřej Filip committed
194
  return (n1);
195 196 197 198 199
}

struct ospf_neighbor *
electdr(list nl)
{
Ondřej Filip's avatar
Ondřej Filip committed
200
  struct ospf_neighbor *neigh, *n;
201

Ondřej Filip's avatar
Ondřej Filip committed
202 203
  n = NULL;
  WALK_LIST(neigh, nl)		/* And now DR */
204
  {
Ondřej Filip's avatar
Ondřej Filip committed
205 206 207
    if (neigh->state >= NEIGHBOR_2WAY)	/* Higher than 2WAY */
      if (neigh->priority > 0)	/* Eligible */
	if (ipa_compare(neigh->ip, neigh->dr) == 0)	/* And declaring itself DR */
208
	{
Ondřej Filip's avatar
Ondřej Filip committed
209 210 211 212 213 214 215 216
	  if (n != NULL)
	  {
	    if (neigh->priority > n->priority)
	      n = neigh;
	    else if (neigh->priority == n->priority)
	      if (neigh->rid > n->rid)
		n = neigh;
	  }
217
	  else
Ondřej Filip's avatar
Ondřej Filip committed
218 219 220 221
	  {
	    n = neigh;
	  }
	}
222 223
  }

Ondřej Filip's avatar
Ondřej Filip committed
224
  return (n);
225 226
}

227
static int
228 229 230 231 232 233
can_do_adj(struct ospf_neighbor *n)
{
  struct ospf_iface *ifa;
  struct proto *p;
  int i;

Ondřej Filip's avatar
Ondřej Filip committed
234
  ifa = n->ifa;
235
  p = (struct proto *) (ifa->oa->po);
Ondřej Filip's avatar
Ondřej Filip committed
236
  i = 0;
237

Ondřej Filip's avatar
Ondřej Filip committed
238
  switch (ifa->type)
239
  {
Ondřej Filip's avatar
Ondřej Filip committed
240 241 242 243 244 245 246 247 248 249
  case OSPF_IT_PTP:
  case OSPF_IT_VLINK:
    i = 1;
    break;
  case OSPF_IT_BCAST:
  case OSPF_IT_NBMA:
    switch (ifa->state)
    {
    case OSPF_IS_DOWN:
      bug("%s: Iface %s in down state?", p->name, ifa->iface->name);
250
      break;
Ondřej Filip's avatar
Ondřej Filip committed
251 252 253 254 255 256 257 258 259 260 261 262 263
    case OSPF_IS_WAITING:
      DBG("%s: Neighbor? on iface %s\n", p->name, ifa->iface->name);
      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;
264 265
      break;
    default:
Ondřej Filip's avatar
Ondřej Filip committed
266
      bug("%s: Iface %s in unknown state?", p->name, ifa->iface->name);
267
      break;
Ondřej Filip's avatar
Ondřej Filip committed
268 269 270 271 272
    }
    break;
  default:
    bug("%s: Iface %s is unknown type?", p->name, ifa->iface->name);
    break;
273
  }
Ondřej Filip's avatar
Ondřej Filip committed
274
  DBG("%s: Iface %s can_do_adj=%d\n", p->name, ifa->iface->name, i);
275 276 277
  return i;
}

278 279 280 281 282
/**
 * ospf_neigh_sm - ospf neighbor state machine
 * @n: neighor
 * @event: actual event
 *
283 284 285 286 287
 * 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
288 289
 * @ospf_iface->nbma_list .
 */
290 291 292
void
ospf_neigh_sm(struct ospf_neighbor *n, int event)
{
293 294
  struct proto_ospf *po = n->ifa->oa->po;
  struct proto *p = &po->proto;
295

Ondřej Filip's avatar
Ondřej Filip committed
296
  DBG("Neighbor state machine for neighbor %I, event \"%s\".", n->ip,
Ondřej Filip's avatar
Ondřej Filip committed
297
	     ospf_inm[event]);
Ondřej Filip's avatar
Ondřej Filip committed
298

Ondřej Filip's avatar
Ondřej Filip committed
299
  switch (event)
300
  {
Ondřej Filip's avatar
Ondřej Filip committed
301 302 303 304 305 306 307 308 309 310 311 312
  case INM_START:
    neigh_chstate(n, NEIGHBOR_ATTEMPT);
    /* NBMA are used different way */
    break;
  case INM_HELLOREC:
    switch (n->state)
    {
    case NEIGHBOR_ATTEMPT:
    case NEIGHBOR_DOWN:
      neigh_chstate(n, NEIGHBOR_INIT);
    default:
      tm_start(n->inactim, n->ifa->deadc * n->ifa->helloint);	/* Restart inactivity timer */
313
      break;
Ondřej Filip's avatar
Ondřej Filip committed
314 315 316 317 318 319 320 321 322 323 324 325
    }
    break;
  case INM_2WAYREC:
    if (n->state < NEIGHBOR_2WAY)
      neigh_chstate(n, NEIGHBOR_2WAY);
    if ((n->state == NEIGHBOR_2WAY) && can_do_adj(n))
      neigh_chstate(n, NEIGHBOR_EXSTART);
    break;
  case INM_NEGDONE:
    if (n->state == NEIGHBOR_EXSTART)
    {
      neigh_chstate(n, NEIGHBOR_EXCHANGE);
326
      s_init(&(n->dbsi), &po->lsal);
Ondřej Filip's avatar
Ondřej Filip committed
327
      while (!EMPTY_LIST(n->ackl[ACKL_DELAY]))
328
      {
Ondřej Filip's avatar
Ondřej Filip committed
329 330 331 332
	struct lsah_n *no;
	no = (struct lsah_n *) HEAD(n->ackl[ACKL_DELAY]);
	rem_node(NODE no);
	mb_free(no);
333
      }
Ondřej Filip's avatar
Ondřej Filip committed
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
    }
    else
      bug("NEGDONE and I'm not in EXSTART?");
    break;
  case INM_EXDONE:
    neigh_chstate(n, NEIGHBOR_LOADING);
    break;
  case INM_LOADDONE:
    neigh_chstate(n, NEIGHBOR_FULL);
    break;
  case INM_ADJOK:
    switch (n->state)
    {
    case NEIGHBOR_2WAY:
      /* Can In build adjacency? */
      if (can_do_adj(n))
350
      {
Ondřej Filip's avatar
Ondřej Filip committed
351
	neigh_chstate(n, NEIGHBOR_EXSTART);
352 353 354
      }
      break;
    default:
Ondřej Filip's avatar
Ondřej Filip committed
355 356 357 358 359
      if (n->state >= NEIGHBOR_EXSTART)
	if (!can_do_adj(n))
	{
	  neigh_chstate(n, NEIGHBOR_2WAY);
	}
360
      break;
Ondřej Filip's avatar
Ondřej Filip committed
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
    }
    break;
  case INM_SEQMIS:
  case INM_BADLSREQ:
    if (n->state >= NEIGHBOR_EXCHANGE)
    {
      neigh_chstate(n, NEIGHBOR_EXSTART);
    }
    break;
  case INM_KILLNBR:
  case INM_LLDOWN:
  case INM_INACTTIM:
    neigh_chstate(n, NEIGHBOR_DOWN);
    break;
  case INM_1WAYREC:
    neigh_chstate(n, NEIGHBOR_INIT);
    break;
  default:
    bug("%s: INM - Unknown event?", p->name);
    break;
381 382 383
  }
}

384 385 386 387
/**
 * bdr_election - (Backup) Designed Router election
 * @ifa: actual interface
 *
388
 * When the wait timer fires, it is time to elect (Backup) Designated Router.
389
 * Structure describing me is added to this list so every electing router
390
 * has the same list. Backup Designated Router is elected before Designated
391 392
 * Router. This process is described in 9.4 of RFC 2328.
 */
393
void
394
bdr_election(struct ospf_iface *ifa)
395
{
Ondřej Filip's avatar
Ondřej Filip committed
396
  struct ospf_neighbor *neigh, *ndr, *nbdr, me;
397 398
  u32 myid;
  ip_addr ndrip, nbdrip;
399
  int doadj;
400
  struct proto *p = &ifa->oa->po->proto;
401

402
  DBG("(B)DR election.\n");
403

Ondřej Filip's avatar
Ondřej Filip committed
404
  myid = p->cf->global->router_id;
405

Ondřej Filip's avatar
Ondřej Filip committed
406 407 408 409 410 411
  me.state = NEIGHBOR_2WAY;
  me.rid = myid;
  me.priority = ifa->priority;
  me.dr = ifa->drip;
  me.bdr = ifa->bdrip;
  me.ip = ifa->iface->addr->ip;
412

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

Ondřej Filip's avatar
Ondřej Filip committed
415 416
  nbdr = electbdr(ifa->neigh_list);
  ndr = electdr(ifa->neigh_list);
417

Ondřej Filip's avatar
Ondřej Filip committed
418 419
  if (ndr == NULL)
    ndr = nbdr;
420

Ondřej Filip's avatar
Ondřej Filip committed
421 422 423 424
  if (((ifa->drid == myid) && (ndr != &me))
      || ((ifa->drid != myid) && (ndr == &me))
      || ((ifa->bdrid == myid) && (nbdr != &me))
      || ((ifa->bdrid != myid) && (nbdr == &me)))
425
  {
Ondřej Filip's avatar
Ondřej Filip committed
426
    if (ndr == NULL)
427
      ifa->drip = me.dr = IPA_NONE;
Ondřej Filip's avatar
Ondřej Filip committed
428 429 430 431
    else
      ifa->drip = me.dr = ndr->ip;

    if (nbdr == NULL)
432
      ifa->bdrip = me.bdr = IPA_NONE;
Ondřej Filip's avatar
Ondřej Filip committed
433 434 435 436 437
    else
      ifa->bdrip = me.bdr = nbdr->ip;

    nbdr = electbdr(ifa->neigh_list);
    ndr = electdr(ifa->neigh_list);
438 439
  }

Ondřej Filip's avatar
Ondřej Filip committed
440
  if (ndr == NULL)
441
    ndrip = IPA_NONE;
Ondřej Filip's avatar
Ondřej Filip committed
442 443
  else
    ndrip = ndr->ip;
444

Ondřej Filip's avatar
Ondřej Filip committed
445
  if (nbdr == NULL)
446
    nbdrip = IPA_NONE;
Ondřej Filip's avatar
Ondřej Filip committed
447 448
  else
    nbdrip = nbdr->ip;
449

Ondřej Filip's avatar
Ondřej Filip committed
450 451 452 453
  doadj = 0;
  if ((ipa_compare(ifa->drip, ndrip) != 0)
      || (ipa_compare(ifa->bdrip, nbdrip) != 0))
    doadj = 1;
454

Ondřej Filip's avatar
Ondřej Filip committed
455
  if (ndr == NULL)
456
  {
Ondřej Filip's avatar
Ondřej Filip committed
457
    ifa->drid = 0;
458
    ifa->drip = IPA_NONE;
459 460 461
  }
  else
  {
Ondřej Filip's avatar
Ondřej Filip committed
462 463
    ifa->drid = ndr->rid;
    ifa->drip = ndr->ip;
464 465
  }

Ondřej Filip's avatar
Ondřej Filip committed
466
  if (nbdr == NULL)
467
  {
Ondřej Filip's avatar
Ondřej Filip committed
468
    ifa->bdrid = 0;
469
    ifa->bdrip = IPA_NONE;
470 471 472
  }
  else
  {
Ondřej Filip's avatar
Ondřej Filip committed
473 474
    ifa->bdrid = nbdr->rid;
    ifa->bdrip = nbdr->ip;
475
  }
476

477
  DBG("DR=%I, BDR=%I\n", ifa->drid, ifa->bdrid);
478

Ondřej Filip's avatar
Ondřej Filip committed
479 480
  if (myid == ifa->drid)
    ospf_iface_chstate(ifa, OSPF_IS_DR);
481 482
  else
  {
Ondřej Filip's avatar
Ondřej Filip committed
483 484 485 486
    if (myid == ifa->bdrid)
      ospf_iface_chstate(ifa, OSPF_IS_BACKUP);
    else
      ospf_iface_chstate(ifa, OSPF_IS_DROTHER);
487 488
  }

Ondřej Filip's avatar
Ondřej Filip committed
489
  rem_node(NODE & me);
490

Ondřej Filip's avatar
Ondřej Filip committed
491
  if (doadj)
492
  {
Ondřej Filip's avatar
Ondřej Filip committed
493
    WALK_LIST(neigh, ifa->neigh_list)
494 495 496 497 498 499 500 501 502 503 504
    {
      ospf_neigh_sm(neigh, INM_ADJOK);
    }
  }
}

struct ospf_neighbor *
find_neigh(struct ospf_iface *ifa, u32 rid)
{
  struct ospf_neighbor *n;

Ondřej Filip's avatar
Ondřej Filip committed
505 506
  WALK_LIST(n, ifa->neigh_list) if (n->rid == rid)
    return n;
507 508 509
  return NULL;
}

510

511
/* Find a closest neighbor which is at least 2-Way */
512 513 514
struct ospf_neighbor *
find_neigh_noifa(struct proto_ospf *po, u32 rid)
{
Ondřej Filip's avatar
Ondřej Filip committed
515
  struct ospf_neighbor *n = NULL, *m;
516 517
  struct ospf_iface *ifa;

Ondřej Filip's avatar
Ondřej Filip committed
518 519 520
  WALK_LIST(ifa, po->iface_list) if ((m = find_neigh(ifa, rid)) != NULL)
  {
    if (m->state >= NEIGHBOR_2WAY)
521
    {
Ondřej Filip's avatar
Ondřej Filip committed
522 523 524 525
      if (n == NULL)
	n = m;
      else if (m->ifa->cost < n->ifa->cost)
	n = m;
526
    }
Ondřej Filip's avatar
Ondřej Filip committed
527
  }
528
  return n;
529 530
}

531 532 533 534
struct ospf_area *
ospf_find_area(struct proto_ospf *po, u32 aid)
{
  struct ospf_area *oa;
Ondřej Filip's avatar
Ondřej Filip committed
535 536 537
  WALK_LIST(NODE oa, po->area_list)
    if (((struct ospf_area *) oa)->areaid == aid)
    return oa;
538 539 540
  return NULL;
}

541 542
/* Neighbor is inactive for a long time. Remove it. */
void
Ondřej Filip's avatar
Ondřej Filip committed
543
neighbor_timer_hook(timer * timer)
544
{
545 546 547
  struct ospf_neighbor *n = (struct ospf_neighbor *) timer->data;
  struct ospf_iface *ifa = n->ifa;
  struct proto *p = &ifa->oa->po->proto;
548

Ondřej Filip's avatar
Ondřej Filip committed
549 550 551
  OSPF_TRACE(D_EVENTS,
	     "Inactivity timer fired on interface %s for neighbor %I.",
	     ifa->iface->name, n->ip);
552 553 554 555 556 557
  ospf_neigh_remove(n);
}

void
ospf_neigh_remove(struct ospf_neighbor *n)
{
558 559
  struct ospf_iface *ifa = n->ifa;
  struct proto *p = &ifa->oa->po->proto;
560

561 562
  neigh_chstate(n, NEIGHBOR_DOWN);
  rem_node(NODE n);
563
  rfree(n->pool);
Ondřej Filip's avatar
Ondřej Filip committed
564
  OSPF_TRACE(D_EVENTS, "Deleting neigbor.");
565
}
566 567 568 569

void
ospf_sh_neigh_info(struct ospf_neighbor *n)
{
Ondřej Filip's avatar
Ondřej Filip committed
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
  struct ospf_iface *ifa = n->ifa;
  char *pos = "other";
  char etime[6];
  int exp, sec, min;

  exp = n->inactim->expires - now;
  sec = exp - (exp / 60);
  min = (exp - sec) / 60;
  if (min > 59)
  {
    bsprintf(etime, "-Inf-");
  }
  else
  {
    bsprintf(etime, "%02u:%02u", min, sec);
  }

  if (n->rid == ifa->drid)
    pos = "dr   ";
  if (n->rid == ifa->bdrid)
    pos = "bdr  ";
591
  if ((n->ifa->type == OSPF_IT_PTP) || (n->ifa->type == OSPF_IT_VLINK))
Ondřej Filip's avatar
Ondřej Filip committed
592 593 594
    pos = "ptp  ";

  cli_msg(-1013, "%-1I\t%3u\t%s/%s\t%-5s\t%-1I\t%-10s", n->rid, n->priority,
595 596
	  ospf_ns[n->state], pos, etime, n->ip,
          (ifa->type == OSPF_IT_VLINK ? "vlink" : ifa->iface->name));
597
}
598 599

void
Ondřej Filip's avatar
Ondřej Filip committed
600
rxmt_timer_hook(timer * timer)
601
{
Ondřej Filip's avatar
Ondřej Filip committed
602
  struct ospf_neighbor *n = (struct ospf_neighbor *) timer->data;
603 604 605
  struct top_hash_entry *en;

  DBG("%s: RXMT timer fired on interface %s for neigh: %I.\n",
Ondřej Filip's avatar
Ondřej Filip committed
606
      p->name, ifa->iface->name, n->ip);
607 608 609 610 611

  if(n->state < NEIGHBOR_EXSTART) return;

  if (n->state == NEIGHBOR_EXSTART)
  {
Ondřej Filip's avatar
Ondřej Filip committed
612
    ospf_dbdes_send(n);
613 614 615 616 617 618
    return;
  }

  if ((n->state == NEIGHBOR_EXCHANGE) && n->myimms.bit.ms)	/* I'm master */
    ospf_dbdes_send(n);

619

620 621
  if (n->state < NEIGHBOR_FULL)	
    ospf_lsreq_send(n);	/* EXCHANGE or LOADING */
622 623
  else
  {
624
    if (!EMPTY_SLIST(n->lsrtl))	/* FULL */
625 626 627 628 629 630
    {
      list uplist;
      slab *upslab;
      struct l_lsr_head *llsh;

      init_list(&uplist);
Ondřej Filip's avatar
Ondřej Filip committed
631
      upslab = sl_new(n->pool, sizeof(struct l_lsr_head));
632

Ondřej Filip's avatar
Ondřej Filip committed
633
      WALK_SLIST(SNODE en, n->lsrtl)
634
      {
Ondřej Filip's avatar
Ondřej Filip committed
635 636 637 638 639 640
	if ((SNODE en)->next == (SNODE en))
	  bug("RTList is cycled");
	llsh = sl_alloc(upslab);
	llsh->lsh.id = en->lsa.id;
	llsh->lsh.rt = en->lsa.rt;
	llsh->lsh.type = en->lsa.type;
641
	DBG("Working on ID: %I, RT: %I, Type: %u\n",
Ondřej Filip's avatar
Ondřej Filip committed
642 643
	    en->lsa.id, en->lsa.rt, en->lsa.type);
	add_tail(&uplist, NODE llsh);
644
      }
645
      ospf_lsupd_send_list(n, &uplist);
646 647 648 649 650
      rfree(upslab);
    }
  }
}

651
void
Ondřej Filip's avatar
Ondřej Filip committed
652
ackd_timer_hook(timer * t)
653
{
Ondřej Filip's avatar
Ondřej Filip committed
654
  struct ospf_neighbor *n = t->data;
655
  ospf_lsack_send(n, ACKL_DELAY);
656
}