Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / ospf.c @ 1a61882d

History | View | Annotate | Download (24.5 KB)

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

    
9
/**
10
 * DOC: Open Shortest Path First (OSPF)
11
 * 
12
 * The OSPF protocol is quite complicated and its complex implemenation is
13
 * split to many files. In |ospf.c|, you will find mainly the interface
14
 * for communication with the core (e.g., reconfiguration hooks, shutdown
15
 * and initialisation and so on). In |packet.c|, you will find various
16
 * functions for sending and receiving generic OSPF packets. There are
17
 * also routines for authentication and checksumming. File |iface.c| contains
18
 * the interface state machine and functions for allocation and deallocation of OSPF's
19
 * interface data structures. Source |neighbor.c| includes the neighbor state
20
 * machine and functions for election of Designated Router and Backup
21
 * Designated router. In |hello.c|, there are routines for sending
22
 * and receiving of hello packets as well as functions for maintaining
23
 * wait times and the inactivity timer. Files |lsreq.c|, |lsack.c|, |dbdes.c|
24
 * contain functions for sending and receiving of link-state requests,
25
 * link-state acknowledgements and database descriptions respectively.
26
 * In |lsupd.c|, there are functions for sending and receiving
27
 * of link-state updates and also the flooding algorithm. Source |topology.c| is
28
 * a place where routines for searching LSAs in the link-state database,
29
 * adding and deleting them reside, there also are functions for originating
30
 * of various types of LSAs (router LSA, net LSA, external LSA). File |rt.c|
31
 * contains routines for calculating the routing table. |lsalib.c| is a set
32
 * of various functions for working with the LSAs (endianity conversions,
33
 * calculation of checksum etc.).
34
 *
35
 * One instance of the protocol is able to hold LSA databases for
36
 * multiple OSPF areas, to exchange routing information between
37
 * multiple neighbors and to calculate the routing tables. The core
38
 * structure is &proto_ospf to which multiple &ospf_area and
39
 * &ospf_iface structures are connected. &ospf_area is also connected to
40
 * &top_hash_graph which is a dynamic hashing structure that
41
 * describes the link-state database. It allows fast search, addition
42
 * and deletion. Each LSA is kept in two pieces: header and body. Both of them are
43
 * kept in the endianity of the CPU.
44
 * 
45
 * Every area has its own area_disp() which is
46
 * responsible for late originating of router LSA, calculating
47
 * of the routing table and it also ages and flushes the LSAs. This
48
 * function is called in regular intervals.
49
 * To every &ospf_iface, we connect one or more
50
 * &ospf_neighbor's -- a structure containing many timers and queues
51
 * for building adjacency and for exchange of routing messages.
52
 *
53
 * BIRD's OSPF implementation respects RFC2328 in every detail, but
54
 * some of internal algorithms do differ. The RFC recommends making a snapshot
55
 * of the link-state database when a new adjacency is forming and sending
56
 * the database description packets based on the information in this 
57
 * snapshot. The database can be quite large in some networks, so
58
 * rather we walk through a &slist structure which allows us to
59
 * continue even if the actual LSA we were working with is deleted. New
60
 * LSAs are added at the tail of this &slist.
61
 *
62
 * We also don't keep a separate OSPF routing table, because the core
63
 * helps us by being able to recognize when a route is updated
64
 * to an identical one and it suppresses the update automatically.
65
 * Due to this, we can flush all the routes we've recalculated and
66
 * also those we've deleted to the core's routing table and the
67
 * core will take care of the rest. This simplifies the process
68
 * and conserves memory.
69
 */
70

    
71
#include "ospf.h"
72

    
73
static int ospf_rte_better(struct rte *new, struct rte *old);
74
static int ospf_rte_same(struct rte *new, struct rte *old);
75
static void area_disp(timer *timer);
76
static void ospf_disp(timer *timer);
77

    
78

    
79
static int
80
ospf_start(struct proto *p)
81
{
82
  struct proto_ospf *po = (struct proto_ospf *) p;
83
  struct ospf_config *c = (struct ospf_config *) (p->cf);
84
  struct ospf_area_config *ac;
85
  struct ospf_area *oa;
86
  struct area_net *anet, *antmp;
87

    
88
  po->rfc1583 = c->rfc1583;
89
  po->ebit = 0;
90

    
91
  po->tick = c->tick;
92
  po->disp_timer = tm_new(po->proto.pool);
93
  po->disp_timer->data = po;
94
  po->disp_timer->randomize = 0;
95
  po->disp_timer->hook = ospf_disp;
96
  po->disp_timer->recurrent = po->tick;
97
  tm_start(po->disp_timer, 1);
98
  init_list(&(po->iface_list));
99
  init_list(&(po->area_list));
100
  fib_init(&po->rtf[0], p->pool, sizeof(ort), 16, ospf_rt_initort);
101
  fib_init(&po->rtf[1], p->pool, sizeof(ort), 16, ospf_rt_initort);
102
  po->areano = 0;
103
  if (EMPTY_LIST(c->area_list))
104
  {
105
    log(L_ERR "Cannot start, no OSPF areas configured!");
106
    return PS_DOWN;
107
  }
108

    
109
  WALK_LIST(ac, c->area_list)
110
  {
111
    oa = mb_allocz(po->proto.pool, sizeof(struct ospf_area));
112
    add_tail(&po->area_list, NODE oa);
113
    po->areano++;
114
    oa->stub = ac->stub;
115
    oa->tick = ac->tick;
116
    oa->areaid = ac->areaid;
117
    oa->gr = ospf_top_new(p->pool);
118
    s_init_list(&(oa->lsal));
119
    oa->rt = NULL;
120
    oa->po = po;
121
    oa->disp_timer = tm_new(po->proto.pool);
122
    oa->disp_timer->data = oa;
123
    oa->disp_timer->randomize = 0;
124
    oa->disp_timer->hook = area_disp;
125
    oa->disp_timer->recurrent = oa->tick;
126
    tm_start(oa->disp_timer, 2);
127
    init_list(&oa->net_list);
128
    WALK_LIST(anet, ac->net_list)
129
    {
130
      antmp = mb_allocz(po->proto.pool, sizeof(struct area_net));
131
      antmp->px.addr = anet->px.addr;
132
      antmp->px.len = anet->px.len;
133
      antmp->hidden = anet->hidden;
134
      add_tail(&oa->net_list, NODE antmp);
135
    }
136
  }
137
  return PS_UP;
138
}
139

    
140
static void
141
ospf_dump(struct proto *p)
142
{
143
  struct ospf_iface *ifa;
144
  struct ospf_neighbor *n;
145
  struct proto_ospf *po = (struct proto_ospf *) p;
146
  struct ospf_area *oa;
147

    
148
  OSPF_TRACE(D_EVENTS, "Area number: %d", po->areano);
149

    
150
  WALK_LIST(ifa, po->iface_list)
151
  {
152
    OSPF_TRACE(D_EVENTS, "Interface: %s", ifa->iface->name);
153
    OSPF_TRACE(D_EVENTS, "state: %u", ifa->state);
154
    OSPF_TRACE(D_EVENTS, "DR:  %I", ifa->drid);
155
    OSPF_TRACE(D_EVENTS, "BDR: %I", ifa->bdrid);
156
    WALK_LIST(n, ifa->neigh_list)
157
    {
158
      OSPF_TRACE(D_EVENTS, "  neighbor %I in state %u", n->rid, n->state);
159
    }
160
  }
161

    
162
  WALK_LIST(NODE oa, po->area_list)
163
  {
164
    OSPF_TRACE(D_EVENTS, "LSA graph dump for area \"%I\" start:", oa->areaid);
165
    ospf_top_dump(oa->gr, p);
166
    OSPF_TRACE(D_EVENTS, "LSA graph dump for area \"%I\" finished",
167
               oa->areaid);
168
  }
169
  neigh_dump_all();
170
}
171

    
172
static struct proto *
173
ospf_init(struct proto_config *c)
174
{
175
  struct proto *p = proto_new(c, sizeof(struct proto_ospf));
176

    
177
  p->import_control = ospf_import_control;
178
  p->make_tmp_attrs = ospf_make_tmp_attrs;
179
  p->store_tmp_attrs = ospf_store_tmp_attrs;
180
  p->rt_notify = ospf_rt_notify;
181
  p->if_notify = ospf_iface_notify;
182
  p->rte_better = ospf_rte_better;
183
  p->rte_same = ospf_rte_same;
184

    
185
  return p;
186
}
187

    
188
/* If new is better return 1 */
189
static int
190
ospf_rte_better(struct rte *new, struct rte *old)
191
{
192
  /* FIXME this is wrong */
193
  if (new->u.ospf.metric1 == LSINFINITY)
194
    return 0;
195

    
196
  /* External paths are always longer that internal */
197
  if (((new->attrs->source == RTS_OSPF)
198
       || (new->attrs->source == RTS_OSPF_IA))
199
      && (old->attrs->source == RTS_OSPF_EXT))
200
    return 1;
201
  if (((old->attrs->source == RTS_OSPF)
202
       || (old->attrs->source == RTS_OSPF_IA))
203
      && (new->attrs->source == RTS_OSPF_EXT))
204
    return 0;
205

    
206
  if (new->u.ospf.metric2 < old->u.ospf.metric2)
207
  {
208
    if (old->u.ospf.metric2 == LSINFINITY)
209
      return 0;                        /* Old is E1, new is E2 */
210
    return 1;                        /* Both are E2 */
211
  }
212

    
213
  if (new->u.ospf.metric2 > old->u.ospf.metric2)
214
  {
215
    if (new->u.ospf.metric2 == LSINFINITY)
216
      return 1;                        /* New is E1, old is E2 */
217
    return 0;                        /* Both are E2 */
218
  }
219

    
220
  /* 
221
   * E2 metrics are the same. It means that:
222
   * 1) Paths are E2 with same metric
223
   * 2) Paths are E1.
224
   */
225

    
226
  if (new->u.ospf.metric1 < old->u.ospf.metric1)
227
    return 1;
228
  return 0;                        /* Old is shorter or same */
229
}
230

    
231
static int
232
ospf_rte_same(struct rte *new, struct rte *old)
233
{
234
  /* new->attrs == old->attrs always */
235
  return
236
    new->u.ospf.metric1 == old->u.ospf.metric1 &&
237
    new->u.ospf.metric2 == old->u.ospf.metric2 &&
238
    new->u.ospf.tag == old->u.ospf.tag;
239
}
240

    
241
static ea_list *
242
ospf_build_attrs(ea_list * next, struct linpool *pool, u32 m1, u32 m2,
243
                 u32 tag)
244
{
245
  struct ea_list *l =
246
    lp_alloc(pool, sizeof(struct ea_list) + 3 * sizeof(eattr));
247

    
248
  l->next = next;
249
  l->flags = EALF_SORTED;
250
  l->count = 3;
251
  l->attrs[0].id = EA_OSPF_METRIC1;
252
  l->attrs[0].flags = 0;
253
  l->attrs[0].type = EAF_TYPE_INT | EAF_TEMP;
254
  l->attrs[0].u.data = m1;
255
  l->attrs[1].id = EA_OSPF_METRIC2;
256
  l->attrs[1].flags = 0;
257
  l->attrs[1].type = EAF_TYPE_INT | EAF_TEMP;
258
  l->attrs[1].u.data = m2;
259
  l->attrs[2].id = EA_OSPF_TAG;
260
  l->attrs[2].flags = 0;
261
  l->attrs[2].type = EAF_TYPE_INT | EAF_TEMP;
262
  l->attrs[2].u.data = tag;
263
  return l;
264
}
265

    
266
void
267
schedule_net_lsa(struct ospf_iface *ifa)
268
{
269
  ifa->orignet = 1;
270
}
271

    
272
void
273
schedule_rt_lsa(struct ospf_area *oa)
274
{
275
  struct proto *p = &oa->po->proto;
276

    
277
  OSPF_TRACE(D_EVENTS, "Scheduling RT lsa origination for area %I.",
278
             oa->areaid);
279
  oa->origrt = 1;
280
}
281

    
282
void
283
schedule_rtcalc(struct proto_ospf *po)
284
{
285
  struct proto *p = &po->proto;
286

    
287
  if (po->calcrt)
288
    return;
289

    
290
  OSPF_TRACE(D_EVENTS, "Scheduling RT calculation.");
291
  po->calcrt = 1;
292
}
293

    
294
/**
295
 * area_disp - invokes link-state database aging, origination of
296
 * router LSA and routing table calculation
297
 * @timer: it's called every @ospf_area->tick seconds
298
 *
299
 * It invokes aging and when @ospf_area->origrt is set to 1, start
300
 * function for origination of router LSA and network LSAs.
301
 */
302
void
303
area_disp(timer * timer)
304
{
305
  struct ospf_area *oa = timer->data;
306
  struct proto_ospf *po = oa->po;
307
  struct ospf_iface *ifa;
308

    
309
  /* Now try to originage rt_lsa */
310
  if (oa->origrt)
311
    originate_rt_lsa(oa);
312

    
313
  /* Now try to originate network LSA's */
314
  WALK_LIST(ifa, po->iface_list)
315
  {
316
    if (ifa->orignet && (ifa->an == oa->areaid))
317
      originate_net_lsa(ifa);
318
  }
319

    
320
  /* Age LSA DB */
321
  ospf_age(oa);
322
}
323

    
324
void
325
ospf_disp(timer * timer)
326
{
327
  struct proto_ospf *po = timer->data;
328

    
329
  /* Calculate routing table */
330
  if (po->calcrt)
331
    ospf_rt_spf (po);
332
  po->calcrt = 0;
333
}
334

    
335

    
336

    
337
/**
338
 * ospf_import_control - accept or reject new route from nest's routing table
339
 * @p: current instance of protocol
340
 * @new: the new route
341
 * @attrs: list of attributes
342
 * @pool: pool for allocation of attributes
343
 *
344
 * Its quite simple. It does not accept our own routes and leaves the decision on
345
 * import to the filters.
346
 */
347

    
348
int
349
ospf_import_control(struct proto *p, rte ** new, ea_list ** attrs,
350
                    struct linpool *pool)
351
{
352
  rte *e = *new;
353

    
354
  if (p == e->attrs->proto)
355
    return -1;                        /* Reject our own routes */
356
  *attrs = ospf_build_attrs(*attrs, pool, LSINFINITY, 10000, 0);
357
  return 0;                        /* Leave decision to the filters */
358
}
359

    
360
struct ea_list *
361
ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool)
362
{
363
  return ospf_build_attrs(NULL, pool, rt->u.ospf.metric1, rt->u.ospf.metric2,
364
                          rt->u.ospf.tag);
365
}
366

    
367
void
368
ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs)
369
{
370
  rt->u.ospf.metric1 = ea_get_int(attrs, EA_OSPF_METRIC1, LSINFINITY);
371
  rt->u.ospf.metric2 = ea_get_int(attrs, EA_OSPF_METRIC2, 10000);
372
  rt->u.ospf.tag = ea_get_int(attrs, EA_OSPF_TAG, 0);
373
}
374

    
375
/**
376
 * ospf_shutdown - Finish of OSPF instance
377
 * @p: current instance of protocol
378
 *
379
 * RFC does not define any action that should be taken before router
380
 * shutdown. To make my neighbors react as fast as possible, I send
381
 * them hello packet with empty neighbor list. They should start
382
 * their neighbor state machine with event %NEIGHBOR_1WAY.
383
 */
384

    
385
static int
386
ospf_shutdown(struct proto *p)
387
{
388
  struct proto_ospf *po = (struct proto_ospf *) p;
389
  struct ospf_iface *ifa;
390
  OSPF_TRACE(D_EVENTS, "Shutdown requested");
391

    
392
  /* And send to all my neighbors 1WAY */
393
  WALK_LIST(ifa, po->iface_list) ospf_iface_shutdown(ifa);
394

    
395
  return PS_DOWN;
396
}
397

    
398
void
399
ospf_rt_notify(struct proto *p, net * n, rte * new, rte * old UNUSED,
400
               ea_list * attrs)
401
{
402
  struct proto_ospf *po = (struct proto_ospf *) p;
403

    
404
/* Temporarily down write anything
405
  OSPF_TRACE(D_EVENTS, "Got route %I/%d %s", p->name, n->n.prefix,
406
    n->n.pxlen, new ? "up" : "down");
407
*/
408

    
409
  if (new)                        /* Got some new route */
410
  {
411
    originate_ext_lsa(n, new, po, attrs);
412
  }
413
  else
414
  {
415
    u32 rtid = po->proto.cf->global->router_id;
416
    struct ospf_area *oa;
417
    struct top_hash_entry *en;
418
    u32 pr = ipa_to_u32(n->n.prefix);
419
    struct ospf_lsa_ext *ext;
420
    int i;
421
    int max = max_ext_lsa(n->n.pxlen);
422

    
423
    /* Flush old external LSA */
424
    WALK_LIST(oa, po->area_list)
425
    {
426
      for (i = 0; i < max; i++, pr++)
427
      {
428
        if (en = ospf_hash_find(oa->gr, pr, rtid, LSA_T_EXT))
429
        {
430
          ext = en->lsa_body;
431
          if (ipa_compare(ext->netmask, ipa_mkmask(n->n.pxlen)) == 0)
432
          {
433
            ospf_lsupd_flush_nlsa(en, oa);
434
            break;
435
          }
436
        }
437
      }
438
    }
439
  }
440
}
441

    
442
static void
443
ospf_get_status(struct proto *p, byte * buf)
444
{
445
  struct proto_ospf *po = (struct proto_ospf *) p;
446

    
447
  if (p->proto_state == PS_DOWN)
448
    buf[0] = 0;
449
  else
450
  {
451
    struct ospf_iface *ifa;
452
    struct ospf_neighbor *n;
453
    int adj = 0;
454

    
455
    WALK_LIST(ifa, po->iface_list)
456
      WALK_LIST(n, ifa->neigh_list) if (n->state == NEIGHBOR_FULL)
457
      adj = 1;
458

    
459
    if (adj == 0)
460
      strcpy(buf, "Alone");
461
    else
462
      strcpy(buf, "Running");
463
  }
464
}
465

    
466
static void
467
ospf_get_route_info(rte * rte, byte * buf, ea_list * attrs UNUSED)
468
{
469
  char met = ' ';
470
  char type = ' ';
471

    
472
  if (rte->attrs->source == RTS_OSPF_EXT)
473
  {
474
    met = '1';
475
    type = 'E';
476

    
477
  }
478
  if (rte->u.ospf.metric2 != LSINFINITY)
479
    met = '2';
480
  if (rte->attrs->source == RTS_OSPF_IA)
481
    type = 'A';
482
  if (rte->attrs->source == RTS_OSPF)
483
    type = 'I';
484
  buf += bsprintf(buf, " %c", type);
485
  if (met != ' ')
486
    buf += bsprintf(buf, "%c", met);
487
  buf += bsprintf(buf, " (%d/%d", rte->pref, rte->u.ospf.metric1);
488
  if (rte->u.ospf.metric2 != LSINFINITY)
489
    buf += bsprintf(buf, "/%d", rte->u.ospf.metric2);
490
  buf += bsprintf(buf, ")");
491
  if (rte->attrs->source == RTS_OSPF_EXT && rte->u.ospf.tag)
492
  {
493
    buf += bsprintf(buf, " [%x]", rte->u.ospf.tag);
494
  }
495
}
496

    
497
static int
498
ospf_get_attr(eattr * a, byte * buf)
499
{
500
  switch (a->id)
501
  {
502
  case EA_OSPF_METRIC1:
503
    bsprintf(buf, "metric1");
504
    return GA_NAME;
505
  case EA_OSPF_METRIC2:
506
    bsprintf(buf, "metric2");
507
    return GA_NAME;
508
  case EA_OSPF_TAG:
509
    bsprintf(buf, "tag: %08x", a->u.data);
510
    return GA_FULL;
511
  default:
512
    return GA_UNKNOWN;
513
  }
514
}
515

    
516
static int
517
ospf_patt_compare(struct ospf_iface_patt *a, struct ospf_iface_patt *b)
518
{
519
  return ((a->type == b->type) && (a->priority == b->priority));
520
}
521

    
522
/**
523
 * ospf_reconfigure - reconfiguration hook
524
 * @p: current instance of protocol (with old configuration)
525
 * @c: new configuration requested by user
526
 *
527
 * This hook tries to be a little bit intelligent. Instance of OSPF
528
 * will survive change of many constants like hello interval,
529
 * password change, addition or deletion of some neighbor on
530
 * nonbroadcast network, cost of interface, etc.
531
 */
532
static int
533
ospf_reconfigure(struct proto *p, struct proto_config *c)
534
{
535
  struct ospf_config *old = (struct ospf_config *) (p->cf);
536
  struct ospf_config *new = (struct ospf_config *) c;
537
  struct ospf_area_config *ac1, *ac2;
538
  struct proto_ospf *po = (struct proto_ospf *) p;
539
  struct ospf_iface_patt *ip1, *ip2;
540
  struct ospf_iface *ifa;
541
  struct nbma_node *nb1, *nb2, *nbnx;
542
  struct ospf_area *oa = NULL;
543
  struct area_net *anet, *antmp;
544
  int found;
545

    
546
  po->rfc1583 = new->rfc1583;
547
  schedule_rtcalc(po);
548

    
549
  ac1 = HEAD(old->area_list);
550
  ac2 = HEAD(new->area_list);
551

    
552
  /* I should get it in same order */
553

    
554
  while (((NODE(ac1))->next != NULL) && ((NODE(ac2))->next != NULL))
555
  {
556
    if (ac1->areaid != ac2->areaid)
557
      return 0;
558
    if (ac1->stub != ac2->stub)
559
      return 0;                        /* FIXME: non zero values can change */
560

    
561
    WALK_LIST(oa, po->area_list) if (oa->areaid == ac2->areaid)
562
      break;
563

    
564
    if (!oa)
565
      return 0;
566

    
567
    if (ac1->tick != ac2->tick)
568
    {
569
      if (oa->areaid == ac2->areaid)
570
      {
571
        oa->tick = ac2->tick;
572
        tm_start(oa->disp_timer, oa->tick);
573
        OSPF_TRACE(D_EVENTS,
574
                   "Changing tick interval on area %I from %d to %d",
575
                   oa->areaid, ac1->tick, ac2->tick);
576
        break;
577
      }
578
    }
579

    
580
    /* Change net_list */
581
    WALK_LIST_DELSAFE(anet, antmp, oa->net_list)
582
    {
583
      rem_node(NODE anet);
584
      mb_free(anet);
585
    }
586
    WALK_LIST(anet, ac2->net_list)
587
    {
588
      antmp = mb_alloc(p->pool, sizeof(struct area_net));
589
      antmp->px.addr = anet->px.addr;
590
      antmp->px.len = anet->px.len;
591
      antmp->hidden = anet->hidden;
592
      add_tail(&oa->net_list, NODE antmp);
593
    }
594

    
595
    if (!iface_patts_equal(&ac1->patt_list, &ac2->patt_list,
596
                           (void *) ospf_patt_compare))
597
      return 0;
598

    
599
    WALK_LIST(ifa, po->iface_list)
600
    {
601
      if (ip1 = (struct ospf_iface_patt *)
602
          iface_patt_match(&ac1->patt_list, ifa->iface))
603
      {
604
        /* Now reconfigure interface */
605
        if (!(ip2 = (struct ospf_iface_patt *)
606
              iface_patt_match(&ac2->patt_list, ifa->iface)))
607
          return 0;
608

    
609
        /* HELLO TIMER */
610
        if (ip1->helloint != ip2->helloint)
611
        {
612
          ifa->helloint = ip2->helloint;
613
          ifa->hello_timer->recurrent = ifa->helloint;
614
          tm_start(ifa->hello_timer, ifa->helloint);
615
          OSPF_TRACE(D_EVENTS,
616
                     "Changing hello interval on interface %s from %d to %d",
617
                     ifa->iface->name, ip1->helloint, ip2->helloint);
618
        }
619

    
620
        /* POLL TIMER */
621
        if (ip1->pollint != ip2->pollint)
622
        {
623
          ifa->pollint = ip2->helloint;
624
          ifa->poll_timer->recurrent = ifa->pollint;
625
          tm_start(ifa->poll_timer, ifa->pollint);
626
          OSPF_TRACE(D_EVENTS,
627
                     "Changing poll interval on interface %s from %d to %d",
628
                     ifa->iface->name, ip1->pollint, ip2->pollint);
629
        }
630

    
631
        /* COST */
632
        if (ip1->cost != ip2->cost)
633
        {
634
          ifa->cost = ip2->cost;
635
          OSPF_TRACE(D_EVENTS,
636
                     "Changing cost interface %s from %d to %d",
637
                     ifa->iface->name, ip1->cost, ip2->cost);
638
          schedule_rt_lsa(ifa->oa);
639
        }
640

    
641
        /* strict nbma */
642
        if ((ip1->strictnbma == 0) && (ip2->strictnbma != 0))
643
        {
644
          ifa->strictnbma = ip2->strictnbma;
645
          OSPF_TRACE(D_EVENTS,
646
                     "Interface %s is now strict NBMA.", ifa->iface->name);
647
        }
648
        if ((ip1->strictnbma != 0) && (ip2->strictnbma == 0))
649
        {
650
          ifa->strictnbma = ip2->strictnbma;
651
          OSPF_TRACE(D_EVENTS,
652
                     "Interface %s is no longer strict NBMA.",
653
                     ifa->iface->name);
654
        }
655

    
656
        /* stub */
657
        if ((ip1->stub == 0) && (ip2->stub != 0))
658
        {
659
          ifa->stub = ip2->stub;
660
          OSPF_TRACE(D_EVENTS, "Interface %s is now stub.", ifa->iface->name);
661
        }
662
        if ((ip1->stub != 0) && (ip2->stub == 0) &&
663
            ((ifa->ioprob & OSPF_I_IP) == 0) &&
664
            (((ifa->ioprob & OSPF_I_MC) == 0) || (ifa->type == OSPF_IT_NBMA)))
665
        {
666
          ifa->stub = ip2->stub;
667
          OSPF_TRACE(D_EVENTS,
668
                     "Interface %s is no longer stub.", ifa->iface->name);
669
        }
670

    
671
        /* AUTHENTICATION */
672
        if (ip1->autype != ip2->autype)
673
        {
674
          ifa->autype = ip2->autype;
675
          OSPF_TRACE(D_EVENTS,
676
                     "Changing authentication type on interface %s",
677
                     ifa->iface->name);
678
        }
679
        if (strncmp(ip1->password, ip2->password, 8) != 0)
680
        {
681
          memcpy(ifa->aukey, ip2->password, 8);
682
          OSPF_TRACE(D_EVENTS,
683
                     "Changing password on interface %s", ifa->iface->name);
684
        }
685

    
686
        /* RXMT */
687
        if (ip1->rxmtint != ip2->rxmtint)
688
        {
689
          ifa->rxmtint = ip2->rxmtint;
690
          OSPF_TRACE(D_EVENTS,
691
                     "Changing retransmit interval on interface %s from %d to %d",
692
                     ifa->iface->name, ip1->rxmtint, ip2->rxmtint);
693
        }
694

    
695
        /* WAIT */
696
        if (ip1->waitint != ip2->waitint)
697
        {
698
          ifa->waitint = ip2->waitint;
699
          if (ifa->wait_timer->expires != 0)
700
            tm_start(ifa->wait_timer, ifa->waitint);
701
          OSPF_TRACE(D_EVENTS,
702
                     "Changing wait interval on interface %s from %d to %d",
703
                     ifa->iface->name, ip1->waitint, ip2->waitint);
704
        }
705

    
706
        /* INFTRANS */
707
        if (ip1->inftransdelay != ip2->inftransdelay)
708
        {
709
          ifa->inftransdelay = ip2->inftransdelay;
710
          OSPF_TRACE(D_EVENTS,
711
                     "Changing transmit delay on interface %s from %d to %d",
712
                     ifa->iface->name, ip1->inftransdelay,
713
                     ip2->inftransdelay);
714
        }
715

    
716
        /* DEAD COUNT */
717
        if (ip1->deadc != ip2->deadc)
718
        {
719
          ifa->deadc = ip2->deadc;
720
          OSPF_TRACE(D_EVENTS,
721
                     "Changing dead count on interface %s from %d to %d",
722
                     ifa->iface->name, ip1->deadc, ip2->deadc);
723
        }
724

    
725
        /* NBMA LIST */
726
        /* First remove old */
727
        WALK_LIST_DELSAFE(nb1, nbnx, ifa->nbma_list)
728
        {
729
          found = 0;
730
          WALK_LIST(nb2, ip2->nbma_list)
731
            if (ipa_compare(nb1->ip, nb2->ip) == 0)
732
          {
733
            found = 1;
734
            if (nb1->eligible != nb2->eligible)
735
              OSPF_TRACE(D_EVENTS,
736
                         "Changing neighbor eligibility %I on interface %s",
737
                         nb1->ip, ifa->iface->name);
738
            break;
739
          }
740

    
741
          if (!found)
742
          {
743
            OSPF_TRACE(D_EVENTS,
744
                       "Removing NBMA neighbor %I on interface %s",
745
                       nb1->ip, ifa->iface->name);
746
            rem_node(NODE nb1);
747
            mb_free(nb1);
748
          }
749
        }
750
        /* And then add new */
751
        WALK_LIST(nb2, ip2->nbma_list)
752
        {
753
          found = 0;
754
          WALK_LIST(nb1, ifa->nbma_list)
755
            if (ipa_compare(nb1->ip, nb2->ip) == 0)
756
          {
757
            found = 1;
758
            break;
759
          }
760
          if (!found)
761
          {
762
            nb1 = mb_alloc(p->pool, sizeof(struct nbma_node));
763
            nb1->ip = nb2->ip;
764
            nb1->eligible = nb2->eligible;
765
            add_tail(&ifa->nbma_list, NODE nb1);
766
            OSPF_TRACE(D_EVENTS,
767
                       "Adding NBMA neighbor %I on interface %s",
768
                       nb1->ip, ifa->iface->name);
769
          }
770
        }
771
      }
772
    }
773

    
774
    NODE ac1 = (NODE(ac1))->next;
775
    NODE ac2 = (NODE(ac2))->next;
776
  }
777

    
778
  if (((NODE(ac1))->next) != ((NODE(ac2))->next))
779
    return 0;                        /* One is not null */
780

    
781
  return 1;                        /* Everything OK :-) */
782
}
783

    
784
void
785
ospf_sh_neigh(struct proto *p, char *iff)
786
{
787
  struct ospf_iface *ifa = NULL, *f;
788
  struct ospf_neighbor *n;
789
  struct proto_ospf *po = (struct proto_ospf *) p;
790

    
791
  if (p->proto_state != PS_UP)
792
  {
793
    cli_msg(-1013, "%s: is not up", p->name);
794
    cli_msg(0, "");
795
    return;
796
  }
797

    
798
  if (iff != NULL)
799
  {
800
    WALK_LIST(f, po->iface_list)
801
    {
802
      if (strcmp(iff, f->iface->name) == 0)
803
      {
804
        ifa = f;
805
        break;
806
      }
807
    }
808
    if (ifa == NULL)
809
    {
810
      cli_msg(0, "");
811
      return;
812
    }
813
    cli_msg(-1013, "%s:", p->name);
814
    cli_msg(-1013, "%-12s\t%3s\t%-15s\t%-5s\t%-12s\t%-10s", "Router ID",
815
            "Pri", "     State", "DTime", "Router IP", "Interface");
816
    WALK_LIST(n, ifa->neigh_list) ospf_sh_neigh_info(n);
817
    cli_msg(0, "");
818
    return;
819
  }
820

    
821
  cli_msg(-1013, "%s:", p->name);
822
  cli_msg(-1013, "%-12s\t%3s\t%-15s\t%-5s\t%-12s\t%-10s", "Router ID", "Pri",
823
          "     State", "DTime", "Router IP", "Interface");
824
  WALK_LIST(ifa, po->iface_list)
825
    WALK_LIST(n, ifa->neigh_list) ospf_sh_neigh_info(n);
826
  cli_msg(0, "");
827
}
828

    
829
void
830
ospf_sh(struct proto *p)
831
{
832
  struct ospf_area *oa;
833
  struct proto_ospf *po = (struct proto_ospf *) p;
834
  struct ospf_iface *ifa;
835
  struct ospf_neighbor *n;
836
  int ifano;
837
  int nno;
838
  int adjno;
839

    
840
  if (p->proto_state != PS_UP)
841
  {
842
    cli_msg(-1014, "%s: is not up", p->name);
843
    cli_msg(0, "");
844
    return;
845
  }
846

    
847
  cli_msg(-1014, "%s:", p->name);
848
  cli_msg(-1014, "Number of areas: %u", po->areano);
849

    
850
  WALK_LIST(oa, po->area_list)
851
  {
852
    cli_msg(-1014, "\tArea: %I (%u) %s", oa->areaid, oa->areaid,
853
            oa->areaid == 0 ? "[BACKBONE]" : "");
854
    ifano = 0;
855
    nno = 0;
856
    adjno = 0;
857
    WALK_LIST(ifa, po->iface_list)
858
    {
859
      if (oa == ifa->oa)
860
        ifano++;
861
      WALK_LIST(n, ifa->neigh_list)
862
      {
863
        nno++;
864
        if (n->state == NEIGHBOR_FULL)
865
          adjno++;
866
      }
867
    }
868
    cli_msg(-1014, "\t\tStub:\t%s", oa->stub ? "Yes" : "No");
869
    cli_msg(-1014, "\t\tRT scheduler tick:\t%u", oa->tick);
870
    cli_msg(-1014, "\t\tNumber of interfaces:\t%u", ifano);
871
    cli_msg(-1014, "\t\tNumber of LSAs in DB:\t%u", oa->gr->hash_entries);
872
    cli_msg(-1014, "\t\tNumber of neighbors:\t%u", nno);
873
    cli_msg(-1014, "\t\tNumber of adjacent neighbors:\t%u", adjno);
874
    if (!EMPTY_LIST(oa->net_list))
875
    {
876
      struct area_net *anet;
877
      cli_msg(-1014, "\t\tArea networks:");
878
      WALK_LIST(anet, oa->net_list)
879
      {
880
        cli_msg(-1014, "\t\t\t%1I/%u\t%s", anet->px.addr, anet->px.len,
881
                anet->hidden ? "Hidden" : "Advertise");
882
      }
883
    }
884
  }
885
  cli_msg(0, "");
886
}
887

    
888
void
889
ospf_sh_iface(struct proto *p, char *iff)
890
{
891
  struct proto_ospf *po = (struct proto_ospf *) p;
892
  struct ospf_iface *ifa = NULL, *f;
893

    
894
  if (p->proto_state != PS_UP)
895
  {
896
    cli_msg(-1015, "%s: is not up", p->name);
897
    cli_msg(0, "");
898
    return;
899
  }
900

    
901
  if (iff != NULL)
902
  {
903
    WALK_LIST(f, po->iface_list)
904
    {
905
      if (strcmp(iff, f->iface->name) == 0)
906
      {
907
        ifa = f;
908
        break;
909
      }
910
    }
911

    
912
    if (ifa == NULL)
913
    {
914
      cli_msg(0, "");
915
      return;
916
    }
917
    cli_msg(-1015, "%s:", p->name);
918
    ospf_iface_info(ifa);
919
    cli_msg(0, "");
920
    return;
921
  }
922
  cli_msg(-1015, "%s:", p->name);
923
  WALK_LIST(ifa, po->iface_list) ospf_iface_info(ifa);
924
  cli_msg(0, "");
925
}
926

    
927
struct protocol proto_ospf = {
928
  name:"OSPF",
929
  template:"ospf%d",
930
  attr_class:EAP_OSPF,
931
  init:ospf_init,
932
  dump:ospf_dump,
933
  start:ospf_start,
934
  shutdown:ospf_shutdown,
935
  get_route_info:ospf_get_route_info,
936
  get_attr:ospf_get_attr,
937
  get_status:ospf_get_status,
938
  reconfigure:ospf_reconfigure
939
};