Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / ospf.c @ 6567e6cf

History | View | Annotate | Download (21 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 can find mostly interface
14
 * for communication with the core (e.g., reconfiguration hooks, shutdown
15
 * and initialisation and so on). In |packet.c|, you can find various
16
 * functions for sending and receiving of generic OSPF packets. There are
17
 * also routines for autentication and checksumming. File |iface.c| contains
18
 * the interface state machine, allocation and deallocation of OSPF's
19
 * interface data structures. Source |neighbor.c| includes the neighbor state
20
 * machine and functions for election of Designed Router and Backup
21
 * Designed 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 acknoledges 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 LSA's in the link-state database,
29
 * adding and deleting them reside, there also are functions for originating
30
 * of various types of LSA's (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 LSA's (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. To &ospf_area is also connected
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 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 LSA's. 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 to make a snapshot
55
 * of the link-state database when a new adjacency is forming and send
56
 * the database description packets based on information of this 
57
 * snapshot. The database can be quite large in some networks, so
58
 * we rather walk through a &slist structure which allows us to
59
 * continue even if the actual LSA we were worked with is deleted. New
60
 * LSA's 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're 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
74
ospf_start(struct proto *p)
75
{
76
  struct proto_ospf *po=(struct proto_ospf *)p;
77
  struct ospf_config *c=(struct ospf_config *)(p->cf);
78
  struct ospf_area_config *ac;
79
  struct ospf_area *oa;
80

    
81
  fib_init(&po->efib,p->pool,sizeof(struct extfib),16,init_efib);
82
  init_list(&(po->iface_list));
83
  init_list(&(po->area_list));
84
  po->areano=0;
85
  if(EMPTY_LIST(c->area_list))
86
  {
87
    log("%s: Cannot start, no OSPF areas configured", p->name);
88
    return PS_DOWN;
89
  }
90

    
91
  WALK_LIST(ac,c->area_list)
92
  {
93
    oa=mb_allocz(po->proto.pool, sizeof(struct ospf_area));
94
    add_tail(&po->area_list,NODE oa);
95
    po->areano++;
96
    oa->stub=ac->stub;
97
    oa->tick=ac->tick;
98
    oa->areaid=ac->areaid;
99
    oa->gr=ospf_top_new(po);
100
    s_init_list(&(oa->lsal));
101
    oa->rt=NULL;
102
    oa->po=po;
103
    oa->disp_timer=tm_new(po->proto.pool);
104
    oa->disp_timer->data=oa;
105
    oa->disp_timer->randomize=0;
106
    oa->disp_timer->hook=area_disp;
107
    oa->disp_timer->recurrent=oa->tick;
108
    tm_start(oa->disp_timer,oa->tick);
109
    oa->calcrt=0;
110
    oa->origrt=0;
111
    fib_init(&oa->infib,po->proto.pool,sizeof(struct infib),16,init_infib);
112
  }
113
  return PS_UP;
114
}
115

    
116
static void
117
ospf_dump(struct proto *p)
118
{
119
  char areastr[20];
120
  struct ospf_iface *ifa;
121
  struct ospf_neighbor *n;
122
  struct ospf_config *c = (void *) p->cf;
123
  struct proto_ospf *po=(struct proto_ospf *)p;
124
  struct ospf_area *oa;
125

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

    
128
  WALK_LIST(ifa, po->iface_list)
129
  {
130
    OSPF_TRACE(D_EVENTS, "Interface: %s", ifa->iface->name);
131
    OSPF_TRACE(D_EVENTS, "state: %u", ifa->state);
132
    OSPF_TRACE(D_EVENTS, "DR:  %I", ifa->drid);
133
    OSPF_TRACE(D_EVENTS, "BDR: %I", ifa->bdrid);
134
    WALK_LIST(n, ifa->neigh_list)
135
    {
136
      OSPF_TRACE(D_EVENTS, "  neighbor %I in state %u", n->rid, n->state);
137
    }
138
  }
139

    
140
  WALK_LIST(NODE oa,po->area_list)
141
  {
142
    OSPF_TRACE(D_EVENTS, "LSA graph dump for area \"%I\" start:", oa->areaid);
143
    ospf_top_dump(oa->gr,p);
144
    OSPF_TRACE(D_EVENTS, "LSA graph dump for area \"%I\" finished", oa->areaid);
145
  }
146
  neigh_dump_all();
147
}
148

    
149
static struct proto *
150
ospf_init(struct proto_config *c)
151
{
152
  struct proto *p = proto_new(c, sizeof(struct proto_ospf));
153
  struct proto_ospf *po=(struct proto_ospf *)p;
154
  struct ospf_config *oc=(struct ospf_config *)c;
155
  struct ospf_area_config *ac;
156
  struct ospf_iface_patt *patt;
157

    
158
  p->import_control = ospf_import_control;
159
  p->make_tmp_attrs = ospf_make_tmp_attrs;
160
  p->store_tmp_attrs = ospf_store_tmp_attrs;
161
  p->rt_notify = ospf_rt_notify;
162
  p->if_notify = ospf_if_notify;
163
  p->rte_better = ospf_rte_better;
164
  p->rte_same = ospf_rte_same;
165

    
166
  po->rfc1583=oc->rfc1583;
167
  return p;
168
}
169

    
170
/* If new is better return 1 */
171
static int
172
ospf_rte_better(struct rte *new, struct rte *old)
173
{
174
  struct proto *p = new->attrs->proto;
175

    
176
  if(new->u.ospf.metric1=LSINFINITY) return 0;
177

    
178
  if(((new->attrs->source==RTS_OSPF) || (new->attrs->source==RTS_OSPF_IA))
179
    && (old->attrs->source==RTS_OSPF_EXT)) return 1;
180

    
181
  if(((old->attrs->source==RTS_OSPF) || (old->attrs->source==RTS_OSPF_IA))
182
    && (new->attrs->source==RTS_OSPF_EXT)) return 0;
183

    
184
  if(new->u.ospf.metric2!=0)
185
  {
186
    if(old->u.ospf.metric2==0) return 0;
187
    if(new->u.ospf.metric2<old->u.ospf.metric2) return 1;
188
    return 0;
189
  }
190
  else
191
  {
192
    if(old->u.ospf.metric2!=0) return 1;
193
    if(new->u.ospf.metric1<old->u.ospf.metric1) return 1;
194
    return 0;
195
  }
196
}
197

    
198
static int
199
ospf_rte_same(struct rte *new, struct rte *old)
200
{
201
  /* new->attrs == old->attrs always */
202
  return
203
    new->u.ospf.metric1 == old->u.ospf.metric1 &&
204
    new->u.ospf.metric2 == old->u.ospf.metric2 &&
205
    new->u.ospf.tag     == old->u.ospf.tag;
206
}
207

    
208
static ea_list *
209
ospf_build_attrs(ea_list *next, struct linpool *pool, u32 m1, u32 m2, u32 tag)
210
{
211
  struct ea_list *l = lp_alloc(pool, sizeof(struct ea_list) + 3*sizeof(eattr));
212

    
213
  l->next = next;
214
  l->flags = EALF_SORTED;
215
  l->count = 3;
216
  l->attrs[0].id = EA_OSPF_METRIC1;
217
  l->attrs[0].flags = 0;
218
  l->attrs[0].type = EAF_TYPE_INT | EAF_TEMP;
219
  l->attrs[0].u.data = m1;
220
  l->attrs[1].id = EA_OSPF_METRIC2;
221
  l->attrs[1].flags = 0;
222
  l->attrs[1].type = EAF_TYPE_INT | EAF_TEMP;
223
  l->attrs[1].u.data = m2;
224
  l->attrs[2].id = EA_OSPF_TAG;
225
  l->attrs[2].flags = 0;
226
  l->attrs[2].type = EAF_TYPE_INT | EAF_TEMP;
227
  l->attrs[2].u.data = tag;
228
  return l;
229
}
230

    
231
void
232
schedule_rt_lsa(struct ospf_area *oa)
233
{
234
  struct proto_ospf *po=oa->po;
235
  struct proto *p=&po->proto;
236

    
237
  OSPF_TRACE(D_EVENTS, "Scheduling RT lsa origination for area %I.",
238
    oa->areaid);
239
  oa->origrt=1;
240
}
241

    
242
void
243
schedule_rtcalc(struct ospf_area *oa)
244
{
245
  struct proto_ospf *po=oa->po;
246
  struct proto *p=&po->proto;
247

    
248
  OSPF_TRACE(D_EVENTS, "Scheduling RT calculation for area %I.", 
249
    oa->areaid);
250
  oa->calcrt=1;
251
}
252

    
253
/**
254
 * area_disp - invokes link-state database aging, originating of
255
 * router LSA and routing table calculation
256
 * @timer: it's called every @ospf_area->tick seconds
257
 *
258
 * It ivokes aging and when @ospf_area->origrt is set to 1, start
259
 * function for origination of router LSA. It also start routing
260
 * table calculation when @ospf_area->calcrt is set.
261
 */
262
void
263
area_disp(timer *timer)
264
{
265
  struct ospf_area *oa=timer->data;
266
  struct top_hash_entry *en,*nxt;
267

    
268
  /* First of all try to age LSA DB */
269
  ospf_age(oa);
270

    
271
  /* Now try to originage rt_lsa */
272
  if(oa->origrt) originate_rt_lsa(oa);
273
  oa->origrt=0;
274

    
275
  if(oa->calcrt) ospf_rt_spfa(oa);
276
  oa->calcrt=0;
277
}
278

    
279
/**
280
 * ospf_import_control - accept or reject new route from nest's routing table
281
 * @p: current instance of protocol
282
 * @new: the new route
283
 * @attrs: list of arttributes
284
 * @pool: pool for alloction of attributes
285
 *
286
 * Its quite simple. It does not accept our own routes and decision of
287
 * import leaves to the filters.
288
 */
289

    
290
int
291
ospf_import_control(struct proto *p, rte **new, ea_list **attrs, struct linpool *pool)
292
{
293
  rte *e=*new;
294
  struct proto_ospf *po=(struct proto_ospf *)p;
295

    
296
  if(p==e->attrs->proto) return -1;        /* Reject our own routes */
297
  *attrs = ospf_build_attrs(*attrs, pool, LSINFINITY, 10000, 0);
298
  return 0;                                /* Leave decision to the filters */
299
}
300

    
301
struct ea_list *
302
ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool)
303
{
304
  return ospf_build_attrs(NULL, pool, rt->u.ospf.metric1, rt->u.ospf.metric2, rt->u.ospf.tag);
305
}
306

    
307
void
308
ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs)
309
{
310
  rt->u.ospf.metric1 = ea_get_int(attrs, EA_OSPF_METRIC1, LSINFINITY);
311
  rt->u.ospf.metric2 = ea_get_int(attrs, EA_OSPF_METRIC2, 10000);
312
  rt->u.ospf.tag     = ea_get_int(attrs, EA_OSPF_TAG,     0);
313
}
314

    
315
/**
316
 * ospf_shutdown - Finnish of OSPF instance
317
 * @p: current instance of protocol
318
 *
319
 * RFC does not define any action that should be taken befor router
320
 * shutdown. To make my neighbors react as fast as possible, I send
321
 * them hello packet with empty neighbor list. They should start
322
 * theirs neighbor state machine with event %NEIGHBOR_1WAY.
323
 */
324

    
325
static int
326
ospf_shutdown(struct proto *p)
327
{
328
  struct proto_ospf *po=(struct proto_ospf *)p;
329
  struct ospf_iface *ifa;
330
  struct ospf_neighbor *n;
331
  struct ospf_area *oa;
332
  OSPF_TRACE(D_EVENTS, "Shutdown requested");
333

    
334
  /* And send to all my neighbors 1WAY */
335
  WALK_LIST(ifa, po->iface_list)
336
  {
337
    init_list(&ifa->neigh_list);
338
    hello_timer_hook(ifa->hello_timer);
339
  }
340
  
341
  return PS_DOWN;
342
}
343

    
344
void
345
ospf_rt_notify(struct proto *p, net *n, rte *new, rte *old, ea_list *attrs)
346
{
347
  struct proto_ospf *po=(struct proto_ospf *)p;
348

    
349
  OSPF_TRACE(D_EVENTS, "Got route %I/%d %s", p->name, n->n.prefix,
350
    n->n.pxlen, new ? "up" : "down");
351

    
352
  if(new)                /* Got some new route */
353
  {
354
    originate_ext_lsa(n, new, po, attrs);
355
  }
356
  else
357
  {
358
    u32 rtid=po->proto.cf->global->router_id;
359
    struct ospf_area *oa;
360
    struct top_hash_entry *en;
361
    u32 pr=ipa_to_u32(n->n.prefix);
362
    struct ospf_lsa_ext *ext;
363
    int i;
364

    
365
    /* Flush old external LSA */
366
    WALK_LIST(oa, po->area_list)
367
    {
368
      for(i=0;i<MAXNETS;i++,pr++)
369
      {
370
        if(en=ospf_hash_find(oa->gr, pr, rtid, LSA_T_EXT))
371
        {
372
          ext=en->lsa_body;
373
          if(ipa_compare(ext->netmask, ipa_mkmask(n->n.pxlen))==0)
374
          {
375
            net_flush_lsa(en,po,oa);
376
            break;
377
          }
378
        }
379
      }
380
    }
381
  }
382
}
383

    
384
static void
385
ospf_get_status(struct proto *p, byte *buf)
386
{
387
  struct proto_ospf *po=(struct proto_ospf *)p;
388

    
389
  if (p->proto_state == PS_DOWN) buf[0] = 0;
390
  else
391
  {
392
    struct ospf_iface *ifa;
393
    struct ospf_neighbor *n;
394
    int adj=0;
395

    
396
    WALK_LIST(ifa,po->iface_list)
397
      WALK_LIST(n,ifa->neigh_list)
398
        if(n->state==NEIGHBOR_FULL) adj=1;
399

    
400
    if(adj==0) strcpy(buf, "Alone");
401
    else strcpy(buf, "Running");
402
  }
403
}
404

    
405
static void
406
ospf_get_route_info(rte *rte, byte *buf, ea_list *attrs)
407
{
408
  char met=' ';
409
  char type=' ';
410

    
411
  if(rte->attrs->source==RTS_OSPF_EXT)
412
  {
413
    met='1';
414
    type='E';
415

    
416
  }
417
  if(rte->u.ospf.metric2!=LSINFINITY) met='2';
418
  if(rte->attrs->source==RTS_OSPF_IA) type='A';
419
  if(rte->attrs->source==RTS_OSPF) type='I';
420
  buf += bsprintf(buf, " %c", type);
421
  if(met!=' ') buf += bsprintf(buf, "%c", met);
422
  buf += bsprintf(buf, " (%d/%d)", rte->pref,
423
    (rte->u.ospf.metric2==LSINFINITY) ? rte->u.ospf.metric1 :
424
    rte->u.ospf.metric2);
425
  if(rte->attrs->source==RTS_OSPF_EXT && rte->u.ospf.tag)
426
  {
427
    buf += bsprintf(buf, " [%x]", rte->u.ospf.tag);
428
  }
429
}
430

    
431
static int
432
ospf_get_attr(eattr *a, byte *buf)
433
{
434
  switch (a->id)
435
    {
436
    case EA_OSPF_METRIC1: bsprintf(buf, "metric1"); return GA_NAME;
437
    case EA_OSPF_METRIC2: bsprintf(buf, "metric2"); return GA_NAME;
438
    case EA_OSPF_TAG: bsprintf(buf, "tag: %08x", a->u.data); return GA_FULL;
439
    default: return GA_UNKNOWN;
440
    }
441
}
442

    
443
static int
444
ospf_patt_compare(struct ospf_iface_patt *a, struct ospf_iface_patt *b)
445
{
446
  return ((a->type==b->type)&&(a->priority==b->priority));
447
}
448

    
449
/**
450
 * ospf_reconfigure - reconfiguration hook
451
 * @p: current instance of protocol (with old configuration)
452
 * @c: new configuration requested by user
453
 *
454
 * This hook tries to be a little bit inteligent. Instance of OSPF
455
 * will survive change of many constants like hello interval,
456
 * password change, addition of deletion of some neighbor on
457
 * nonbroadcast network, cost of interface, etc.
458
 */
459
static int
460
ospf_reconfigure(struct proto *p, struct proto_config *c)
461
{
462
  struct ospf_config *old=(struct ospf_config *)(p->cf);
463
  struct ospf_config *new=(struct ospf_config *)c;
464
  struct ospf_area_config *ac1,*ac2;
465
  struct proto_ospf *po=( struct proto_ospf *)p;
466
  struct ospf_iface_patt *ip1,*ip2;
467
  struct ospf_iface *ifa;
468
  struct nbma_node *nb1,*nb2,*nbnx;
469
  struct ospf_area *oa;
470
  int found;
471

    
472
  po->rfc1583=new->rfc1583;
473
  WALK_LIST(oa, po->area_list)        /* Routing table must be recalculated */
474
  {
475
    schedule_rtcalc(oa);
476
  }
477

    
478
  ac1=HEAD(old->area_list);
479
  ac2=HEAD(new->area_list);
480

    
481
  /* I should get it in same order */
482
  
483
  while(((NODE (ac1))->next!=NULL) && ((NODE (ac2))->next!=NULL))
484
  {
485
    if(ac1->areaid!=ac2->areaid) return 0;
486
    if(ac1->stub!=ac2->stub) return 0;
487
    if(ac1->tick!=ac2->tick)
488
    {
489
      WALK_LIST(oa,po->area_list)
490
      {
491
        if(oa->areaid==ac2->areaid)
492
        {
493
          oa->tick=ac2->tick;
494
          tm_start(oa->disp_timer,oa->tick);
495
          OSPF_TRACE(D_EVENTS,
496
            "Changing tick interval on area %I from %d to %d",
497
            oa->areaid, ac1->tick, ac2->tick);
498
          break;
499
        }
500
      }
501
    }
502

    
503
    if(!iface_patts_equal(&ac1->patt_list, &ac2->patt_list,
504
      (void *) ospf_patt_compare))
505
        return 0;
506

    
507
    WALK_LIST(ifa, po->iface_list)
508
    {
509
      if(ip1=(struct ospf_iface_patt *)
510
        iface_patt_match(&ac1->patt_list, ifa->iface))
511
      {
512
        /* Now reconfigure interface */
513
        if(!(ip2=(struct ospf_iface_patt *)
514
          iface_patt_match(&ac2->patt_list, ifa->iface))) return 0;
515

    
516
        /* HELLO TIMER */
517
        if(ip1->helloint!=ip2->helloint)
518
        {
519
          ifa->helloint=ip2->helloint;
520
          ifa->hello_timer->recurrent=ifa->helloint;
521
          tm_start(ifa->hello_timer,ifa->helloint);
522
          OSPF_TRACE(D_EVENTS,
523
            "Changing hello interval on interface %s from %d to %d",
524
            ifa->iface->name,ip1->helloint,ip2->helloint);
525
        }
526

    
527
        /* COST */
528
        if(ip1->cost!=ip2->cost)
529
        {
530
          ifa->cost=ip2->cost;
531
          OSPF_TRACE(D_EVENTS,
532
            "Changing cost interface %s from %d to %d",
533
            ifa->iface->name,ip1->cost,ip2->cost);
534
          schedule_rt_lsa(ifa->oa);
535
        }
536

    
537
        /* AUTHETICATION */
538
        if(ip1->autype!=ip2->autype)
539
        {
540
          ifa->autype=ip2->autype;
541
          OSPF_TRACE(D_EVENTS,
542
            "Changing autentication type on interface %s",
543
            ifa->iface->name);
544
        }
545
        if(strncmp(ip1->password,ip2->password,8)!=0)
546
        {
547
          memcpy(ifa->aukey,ip2->password,8);
548
          OSPF_TRACE(D_EVENTS,
549
            "Changing password on interface %s",
550
            ifa->iface->name);
551
        }
552

    
553
        /* RXMT */
554
        if(ip1->rxmtint!=ip2->rxmtint)
555
        {
556
          ifa->rxmtint=ip2->rxmtint;
557
          OSPF_TRACE(D_EVENTS,
558
            "Changing retransmit interval on interface %s from %d to %d",
559
            ifa->iface->name,ip1->rxmtint,ip2->rxmtint);
560
        }
561

    
562
        /* WAIT */
563
        if(ip1->waitint!=ip2->waitint)
564
        {
565
          ifa->waitint=ip2->waitint;
566
          if(ifa->wait_timer->expires!=0)
567
            tm_start(ifa->wait_timer,ifa->waitint);
568
          OSPF_TRACE(D_EVENTS,
569
            "Changing wait interval on interface %s from %d to %d",
570
            ifa->iface->name,ip1->waitint,ip2->waitint);
571
        }
572

    
573
        /* INFTRANS */
574
        if(ip1->inftransdelay!=ip2->inftransdelay)
575
        {
576
          ifa->inftransdelay=ip2->inftransdelay;
577
          OSPF_TRACE(D_EVENTS,
578
            "Changing transmit delay on interface %s from %d to %d",
579
            ifa->iface->name,ip1->inftransdelay,ip2->inftransdelay);
580
        }
581

    
582
        /* DEAD COUNT */
583
        if(ip1->deadc!=ip2->deadc)
584
        {
585
          ifa->deadc=ip2->deadc;
586
          OSPF_TRACE(D_EVENTS,
587
            "Changing dead count on interface %s from %d to %d",
588
            ifa->iface->name,ip1->deadc,ip2->deadc);
589
        }
590

    
591
        /* NBMA LIST */
592
        /* First remove old */
593
        WALK_LIST_DELSAFE(nb1, nbnx, ifa->nbma_list)
594
        {
595
          found=0;
596
          WALK_LIST(nb2, ip2->nbma_list)
597
            if(ipa_compare(nb1->ip,nb2->ip)==0)
598
            {
599
              found=1;
600
              break;
601
            }
602

    
603
          if(!found)
604
          {
605
            OSPF_TRACE(D_EVENTS,
606
              "Removing NBMA neighbor %I on interface %s",
607
              nb1->ip,ifa->iface->name);
608
            rem_node(NODE nb1);
609
            mb_free(nb1);
610
          }
611
        }
612
        /* And then add new */
613
        WALK_LIST(nb2, ip2->nbma_list)
614
        {
615
          found=0;
616
          WALK_LIST(nb1, ifa->nbma_list)
617
            if(ipa_compare(nb1->ip,nb2->ip)==0)
618
            {
619
              found=1;
620
              break;
621
            }
622
          if(!found)
623
          {
624
            nb1=mb_alloc(p->pool,sizeof(struct nbma_node));
625
            nb1->ip=nb2->ip;
626
            add_tail(&ifa->nbma_list, NODE nb1);
627
            OSPF_TRACE(D_EVENTS,
628
              "Adding NBMA neighbor %I on interface %s",
629
              nb1->ip,ifa->iface->name);
630
          }
631
        }
632
      }
633
    }
634

    
635
    NODE ac1=(NODE (ac1))->next;
636
    NODE ac2=(NODE (ac2))->next;
637
  }
638

    
639
  if(((NODE (ac1))->next)!=((NODE (ac2))->next))
640
    return 0;        /* One is not null */
641

    
642
  return 1;        /* Everythink OK :-) */
643
}
644

    
645
void
646
ospf_sh_neigh(struct proto *p, char *iff)
647
{
648
  struct ospf_iface *ifa=NULL,*f;
649
  struct ospf_neighbor *n;
650
  struct proto_ospf *po=(struct proto_ospf *)p;
651

    
652
  if(p->proto_state != PS_UP)
653
  {
654
    cli_msg(-1013,"%s: is not up", p->name);
655
    cli_msg(0,"");
656
    return;
657
  }
658
  
659
  if(iff!=NULL)
660
  {
661
    WALK_LIST(f, po->iface_list)
662
    {
663
      if(strcmp(iff,f->iface->name)==0)
664
      {
665
        ifa=f;
666
        break;
667
      }
668
    }
669
    if(ifa==NULL)
670
    {
671
      cli_msg(0,"");
672
      return;
673
    }
674
    cli_msg(-1013,"%s:", p->name);
675
    cli_msg(-1013,"%-12s\t%3s\t%-15s\t%-5s\t%-12s\t%-10s","Router ID","Pri",
676
      "     State", "DTime", "Router IP", "Interface");
677
    WALK_LIST(n, ifa->neigh_list) ospf_sh_neigh_info(n);
678
    cli_msg(0,"");
679
    return;
680
  }
681

    
682
  cli_msg(-1013,"%s:", p->name);
683
  cli_msg(-1013,"%-12s\t%3s\t%-15s\t%-5s\t%-12s\t%-10s","Router ID","Pri",
684
    "     State", "DTime", "Router IP", "Interface");
685
  WALK_LIST(ifa,po->iface_list)
686
    WALK_LIST(n, ifa->neigh_list)
687
      ospf_sh_neigh_info(n);
688
  cli_msg(0,"");
689
}
690

    
691
void
692
ospf_sh(struct proto *p)
693
{
694
  struct ospf_area *oa;
695
  struct proto_ospf *po=(struct proto_ospf *)p;
696
  struct ospf_iface *ifa;
697
  struct ospf_neighbor *n;
698
  int ifano;
699
  int nno;
700
  int adjno;
701

    
702
  if(p->proto_state != PS_UP)
703
  {
704
    cli_msg(-1014,"%s: is not up", p->name);
705
    cli_msg(0,"");
706
    return;
707
  }
708

    
709
  cli_msg(-1014,"%s:", p->name);
710
  cli_msg(-1014,"Number of areas: %u", po->areano);
711
  
712
  WALK_LIST(oa,po->area_list)
713
  {
714
    cli_msg(-1014,"\tArea: %I (%u) %s", oa->areaid, oa->areaid,
715
      oa->areaid==0 ? "[BACKBONE]" : "");
716
    ifano=0;
717
    nno=0;
718
    adjno=0;
719
    WALK_LIST(ifa, po->iface_list)
720
    {
721
      if(oa==ifa->oa) ifano++;
722
      WALK_LIST(n, ifa->neigh_list)
723
      {
724
        nno++;
725
        if(n->state==NEIGHBOR_FULL) adjno++;
726
      }
727
    }
728
    cli_msg(-1014,"\t\tStub:\t%s", oa->stub ? "Yes" : "No");
729
    cli_msg(-1014,"\t\tRT scheduler tick:\t%u", oa->tick);
730
    cli_msg(-1014,"\t\tNumber of interfaces:\t%u", ifano);
731
    cli_msg(-1014,"\t\tNumber of LSAs in DB:\t%u", oa->gr->hash_entries);
732
    cli_msg(-1014,"\t\tNumber of neighbors:\t%u", nno);
733
    cli_msg(-1014,"\t\tNumber of adjacent neighbors:\t%u", adjno);
734
  }
735
  cli_msg(0,"");
736
}
737

    
738
void
739
ospf_sh_iface(struct proto *p, char *iff)
740
{
741
  struct ospf_area *oa;
742
  struct proto_ospf *po=(struct proto_ospf *)p;
743
  struct ospf_iface *ifa=NULL,*f;
744
  struct ospf_neighbor *n;
745
  int ifano;
746
  int nno;
747
  int adjno;
748

    
749
  if(p->proto_state != PS_UP)
750
  {
751
    cli_msg(-1015,"%s: is not up", p->name);
752
    cli_msg(0,"");
753
    return;
754
  }
755

    
756
  if(iff!=NULL)
757
  {
758
    WALK_LIST(f, po->iface_list)
759
    {
760
      if(strcmp(iff,f->iface->name)==0)
761
      {
762
        ifa=f;
763
        break;
764
      }
765
    }
766

    
767
    if(ifa==NULL)
768
    {
769
      cli_msg(0,"");
770
      return;
771
    }
772
    cli_msg(-1015,"%s:", p->name);
773
    ospf_iface_info(ifa);
774
    cli_msg(0,"");
775
    return;
776
  }
777
  cli_msg(-1015,"%s:", p->name);
778
  WALK_LIST(ifa, po->iface_list) ospf_iface_info(ifa);
779
  cli_msg(0,"");
780
}
781

    
782
struct protocol proto_ospf = {
783
  name:                 "OSPF",
784
  template:                "ospf%d",
785
  attr_class:                EAP_OSPF,
786
  init:                        ospf_init,
787
  dump:                        ospf_dump,
788
  start:                ospf_start,
789
  shutdown:                ospf_shutdown,
790
  get_route_info:        ospf_get_route_info,
791
  get_attr:                ospf_get_attr,
792
  get_status:                ospf_get_status,
793
  reconfigure:                ospf_reconfigure
794
};
795