Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / ospf.c @ d6a7e2fb

History | View | Annotate | Download (21.4 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
  /* External paths are always longer that internal */
179
  if(((new->attrs->source==RTS_OSPF) || (new->attrs->source==RTS_OSPF_IA))
180
    && (old->attrs->source==RTS_OSPF_EXT)) return 1;
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<old->u.ospf.metric2)
185
  {
186
    if(old->u.ospf.metric2==LSINFINITY) return 0; /* Old is E1, new is E2 */
187
    return 1;        /* Both are E2 */
188
  }
189
        
190
  if(new->u.ospf.metric2>old->u.ospf.metric2)
191
  {
192
    if(new->u.ospf.metric2==LSINFINITY) return 1; /* New is E1, old is E2 */
193
    return 0;        /* Both are E2 */
194
  }
195

    
196
  /* 
197
   * E2 metrics are the same. It means that:
198
   * 1) Paths are E2 with same metric
199
   * 2) Paths are E1.
200
   */
201

    
202
  if(new->u.ospf.metric1<old->u.ospf.metric1) return 1;
203
  return 0;        /* Old is shorter or same */
204
}
205

    
206
static int
207
ospf_rte_same(struct rte *new, struct rte *old)
208
{
209
  /* new->attrs == old->attrs always */
210
  return
211
    new->u.ospf.metric1 == old->u.ospf.metric1 &&
212
    new->u.ospf.metric2 == old->u.ospf.metric2 &&
213
    new->u.ospf.tag     == old->u.ospf.tag;
214
}
215

    
216
static ea_list *
217
ospf_build_attrs(ea_list *next, struct linpool *pool, u32 m1, u32 m2, u32 tag)
218
{
219
  struct ea_list *l = lp_alloc(pool, sizeof(struct ea_list) + 3*sizeof(eattr));
220

    
221
  l->next = next;
222
  l->flags = EALF_SORTED;
223
  l->count = 3;
224
  l->attrs[0].id = EA_OSPF_METRIC1;
225
  l->attrs[0].flags = 0;
226
  l->attrs[0].type = EAF_TYPE_INT | EAF_TEMP;
227
  l->attrs[0].u.data = m1;
228
  l->attrs[1].id = EA_OSPF_METRIC2;
229
  l->attrs[1].flags = 0;
230
  l->attrs[1].type = EAF_TYPE_INT | EAF_TEMP;
231
  l->attrs[1].u.data = m2;
232
  l->attrs[2].id = EA_OSPF_TAG;
233
  l->attrs[2].flags = 0;
234
  l->attrs[2].type = EAF_TYPE_INT | EAF_TEMP;
235
  l->attrs[2].u.data = tag;
236
  return l;
237
}
238

    
239
void
240
schedule_rt_lsa(struct ospf_area *oa)
241
{
242
  struct proto_ospf *po=oa->po;
243
  struct proto *p=&po->proto;
244

    
245
  OSPF_TRACE(D_EVENTS, "Scheduling RT lsa origination for area %I.",
246
    oa->areaid);
247
  oa->origrt=1;
248
}
249

    
250
void
251
schedule_rtcalc(struct ospf_area *oa)
252
{
253
  struct proto_ospf *po=oa->po;
254
  struct proto *p=&po->proto;
255

    
256
  OSPF_TRACE(D_EVENTS, "Scheduling RT calculation for area %I.", 
257
    oa->areaid);
258
  oa->calcrt=1;
259
}
260

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

    
276
  /* First of all try to age LSA DB */
277
  ospf_age(oa);
278

    
279
  /* Now try to originage rt_lsa */
280
  if(oa->origrt) originate_rt_lsa(oa);
281
  oa->origrt=0;
282

    
283
  if(oa->calcrt) ospf_rt_spfa(oa);
284
  oa->calcrt=0;
285
}
286

    
287
/**
288
 * ospf_import_control - accept or reject new route from nest's routing table
289
 * @p: current instance of protocol
290
 * @new: the new route
291
 * @attrs: list of arttributes
292
 * @pool: pool for alloction of attributes
293
 *
294
 * Its quite simple. It does not accept our own routes and decision of
295
 * import leaves to the filters.
296
 */
297

    
298
int
299
ospf_import_control(struct proto *p, rte **new, ea_list **attrs, struct linpool *pool)
300
{
301
  rte *e=*new;
302
  struct proto_ospf *po=(struct proto_ospf *)p;
303

    
304
  if(p==e->attrs->proto) return -1;        /* Reject our own routes */
305
  *attrs = ospf_build_attrs(*attrs, pool, LSINFINITY, 10000, 0);
306
  return 0;                                /* Leave decision to the filters */
307
}
308

    
309
struct ea_list *
310
ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool)
311
{
312
  return ospf_build_attrs(NULL, pool, rt->u.ospf.metric1, rt->u.ospf.metric2, rt->u.ospf.tag);
313
}
314

    
315
void
316
ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs)
317
{
318
  rt->u.ospf.metric1 = ea_get_int(attrs, EA_OSPF_METRIC1, LSINFINITY);
319
  rt->u.ospf.metric2 = ea_get_int(attrs, EA_OSPF_METRIC2, 10000);
320
  rt->u.ospf.tag     = ea_get_int(attrs, EA_OSPF_TAG,     0);
321
}
322

    
323
/**
324
 * ospf_shutdown - Finnish of OSPF instance
325
 * @p: current instance of protocol
326
 *
327
 * RFC does not define any action that should be taken befor router
328
 * shutdown. To make my neighbors react as fast as possible, I send
329
 * them hello packet with empty neighbor list. They should start
330
 * theirs neighbor state machine with event %NEIGHBOR_1WAY.
331
 */
332

    
333
static int
334
ospf_shutdown(struct proto *p)
335
{
336
  struct proto_ospf *po=(struct proto_ospf *)p;
337
  struct ospf_iface *ifa;
338
  struct ospf_neighbor *n;
339
  struct ospf_area *oa;
340
  OSPF_TRACE(D_EVENTS, "Shutdown requested");
341

    
342
  /* And send to all my neighbors 1WAY */
343
  WALK_LIST(ifa, po->iface_list)
344
  {
345
    init_list(&ifa->neigh_list);
346
    hello_timer_hook(ifa->hello_timer);
347
  }
348
  
349
  return PS_DOWN;
350
}
351

    
352
void
353
ospf_rt_notify(struct proto *p, net *n, rte *new, rte *old, ea_list *attrs)
354
{
355
  struct proto_ospf *po=(struct proto_ospf *)p;
356

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

    
360
  if(new)                /* Got some new route */
361
  {
362
    originate_ext_lsa(n, new, po, attrs);
363
  }
364
  else
365
  {
366
    u32 rtid=po->proto.cf->global->router_id;
367
    struct ospf_area *oa;
368
    struct top_hash_entry *en;
369
    u32 pr=ipa_to_u32(n->n.prefix);
370
    struct ospf_lsa_ext *ext;
371
    int i;
372

    
373
    /* Flush old external LSA */
374
    WALK_LIST(oa, po->area_list)
375
    {
376
      for(i=0;i<MAXNETS;i++,pr++)
377
      {
378
        if(en=ospf_hash_find(oa->gr, pr, rtid, LSA_T_EXT))
379
        {
380
          ext=en->lsa_body;
381
          if(ipa_compare(ext->netmask, ipa_mkmask(n->n.pxlen))==0)
382
          {
383
            net_flush_lsa(en,po,oa);
384
            break;
385
          }
386
        }
387
      }
388
    }
389
  }
390
}
391

    
392
static void
393
ospf_get_status(struct proto *p, byte *buf)
394
{
395
  struct proto_ospf *po=(struct proto_ospf *)p;
396

    
397
  if (p->proto_state == PS_DOWN) buf[0] = 0;
398
  else
399
  {
400
    struct ospf_iface *ifa;
401
    struct ospf_neighbor *n;
402
    int adj=0;
403

    
404
    WALK_LIST(ifa,po->iface_list)
405
      WALK_LIST(n,ifa->neigh_list)
406
        if(n->state==NEIGHBOR_FULL) adj=1;
407

    
408
    if(adj==0) strcpy(buf, "Alone");
409
    else strcpy(buf, "Running");
410
  }
411
}
412

    
413
static void
414
ospf_get_route_info(rte *rte, byte *buf, ea_list *attrs)
415
{
416
  char met=' ';
417
  char type=' ';
418

    
419
  if(rte->attrs->source==RTS_OSPF_EXT)
420
  {
421
    met='1';
422
    type='E';
423

    
424
  }
425
  if(rte->u.ospf.metric2!=LSINFINITY) met='2';
426
  if(rte->attrs->source==RTS_OSPF_IA) type='A';
427
  if(rte->attrs->source==RTS_OSPF) type='I';
428
  buf += bsprintf(buf, " %c", type);
429
  if(met!=' ') buf += bsprintf(buf, "%c", met);
430
  buf += bsprintf(buf, " (%d/%d", rte->pref, rte->u.ospf.metric1);
431
  if(rte->u.ospf.metric2!=LSINFINITY) buf += bsprintf(buf, "/%d", rte->u.ospf.metric2);
432
  buf += bsprintf(buf, ")");
433
  if(rte->attrs->source==RTS_OSPF_EXT && rte->u.ospf.tag)
434
  {
435
    buf += bsprintf(buf, " [%x]", rte->u.ospf.tag);
436
  }
437
}
438

    
439
static int
440
ospf_get_attr(eattr *a, byte *buf)
441
{
442
  switch (a->id)
443
    {
444
    case EA_OSPF_METRIC1: bsprintf(buf, "metric1"); return GA_NAME;
445
    case EA_OSPF_METRIC2: bsprintf(buf, "metric2"); return GA_NAME;
446
    case EA_OSPF_TAG: bsprintf(buf, "tag: %08x", a->u.data); return GA_FULL;
447
    default: return GA_UNKNOWN;
448
    }
449
}
450

    
451
static int
452
ospf_patt_compare(struct ospf_iface_patt *a, struct ospf_iface_patt *b)
453
{
454
  return ((a->type==b->type)&&(a->priority==b->priority));
455
}
456

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

    
480
  po->rfc1583=new->rfc1583;
481
  WALK_LIST(oa, po->area_list)        /* Routing table must be recalculated */
482
  {
483
    schedule_rtcalc(oa);
484
  }
485

    
486
  ac1=HEAD(old->area_list);
487
  ac2=HEAD(new->area_list);
488

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

    
511
    if(!iface_patts_equal(&ac1->patt_list, &ac2->patt_list,
512
      (void *) ospf_patt_compare))
513
        return 0;
514

    
515
    WALK_LIST(ifa, po->iface_list)
516
    {
517
      if(ip1=(struct ospf_iface_patt *)
518
        iface_patt_match(&ac1->patt_list, ifa->iface))
519
      {
520
        /* Now reconfigure interface */
521
        if(!(ip2=(struct ospf_iface_patt *)
522
          iface_patt_match(&ac2->patt_list, ifa->iface))) return 0;
523

    
524
        /* HELLO TIMER */
525
        if(ip1->helloint!=ip2->helloint)
526
        {
527
          ifa->helloint=ip2->helloint;
528
          ifa->hello_timer->recurrent=ifa->helloint;
529
          tm_start(ifa->hello_timer,ifa->helloint);
530
          OSPF_TRACE(D_EVENTS,
531
            "Changing hello interval on interface %s from %d to %d",
532
            ifa->iface->name,ip1->helloint,ip2->helloint);
533
        }
534

    
535
        /* COST */
536
        if(ip1->cost!=ip2->cost)
537
        {
538
          ifa->cost=ip2->cost;
539
          OSPF_TRACE(D_EVENTS,
540
            "Changing cost interface %s from %d to %d",
541
            ifa->iface->name,ip1->cost,ip2->cost);
542
          schedule_rt_lsa(ifa->oa);
543
        }
544

    
545
        /* AUTHETICATION */
546
        if(ip1->autype!=ip2->autype)
547
        {
548
          ifa->autype=ip2->autype;
549
          OSPF_TRACE(D_EVENTS,
550
            "Changing autentication type on interface %s",
551
            ifa->iface->name);
552
        }
553
        if(strncmp(ip1->password,ip2->password,8)!=0)
554
        {
555
          memcpy(ifa->aukey,ip2->password,8);
556
          OSPF_TRACE(D_EVENTS,
557
            "Changing password on interface %s",
558
            ifa->iface->name);
559
        }
560

    
561
        /* RXMT */
562
        if(ip1->rxmtint!=ip2->rxmtint)
563
        {
564
          ifa->rxmtint=ip2->rxmtint;
565
          OSPF_TRACE(D_EVENTS,
566
            "Changing retransmit interval on interface %s from %d to %d",
567
            ifa->iface->name,ip1->rxmtint,ip2->rxmtint);
568
        }
569

    
570
        /* WAIT */
571
        if(ip1->waitint!=ip2->waitint)
572
        {
573
          ifa->waitint=ip2->waitint;
574
          if(ifa->wait_timer->expires!=0)
575
            tm_start(ifa->wait_timer,ifa->waitint);
576
          OSPF_TRACE(D_EVENTS,
577
            "Changing wait interval on interface %s from %d to %d",
578
            ifa->iface->name,ip1->waitint,ip2->waitint);
579
        }
580

    
581
        /* INFTRANS */
582
        if(ip1->inftransdelay!=ip2->inftransdelay)
583
        {
584
          ifa->inftransdelay=ip2->inftransdelay;
585
          OSPF_TRACE(D_EVENTS,
586
            "Changing transmit delay on interface %s from %d to %d",
587
            ifa->iface->name,ip1->inftransdelay,ip2->inftransdelay);
588
        }
589

    
590
        /* DEAD COUNT */
591
        if(ip1->deadc!=ip2->deadc)
592
        {
593
          ifa->deadc=ip2->deadc;
594
          OSPF_TRACE(D_EVENTS,
595
            "Changing dead count on interface %s from %d to %d",
596
            ifa->iface->name,ip1->deadc,ip2->deadc);
597
        }
598

    
599
        /* NBMA LIST */
600
        /* First remove old */
601
        WALK_LIST_DELSAFE(nb1, nbnx, ifa->nbma_list)
602
        {
603
          found=0;
604
          WALK_LIST(nb2, ip2->nbma_list)
605
            if(ipa_compare(nb1->ip,nb2->ip)==0)
606
            {
607
              found=1;
608
              break;
609
            }
610

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

    
643
    NODE ac1=(NODE (ac1))->next;
644
    NODE ac2=(NODE (ac2))->next;
645
  }
646

    
647
  if(((NODE (ac1))->next)!=((NODE (ac2))->next))
648
    return 0;        /* One is not null */
649

    
650
  return 1;        /* Everythink OK :-) */
651
}
652

    
653
void
654
ospf_sh_neigh(struct proto *p, char *iff)
655
{
656
  struct ospf_iface *ifa=NULL,*f;
657
  struct ospf_neighbor *n;
658
  struct proto_ospf *po=(struct proto_ospf *)p;
659

    
660
  if(p->proto_state != PS_UP)
661
  {
662
    cli_msg(-1013,"%s: is not up", p->name);
663
    cli_msg(0,"");
664
    return;
665
  }
666
  
667
  if(iff!=NULL)
668
  {
669
    WALK_LIST(f, po->iface_list)
670
    {
671
      if(strcmp(iff,f->iface->name)==0)
672
      {
673
        ifa=f;
674
        break;
675
      }
676
    }
677
    if(ifa==NULL)
678
    {
679
      cli_msg(0,"");
680
      return;
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(n, ifa->neigh_list) ospf_sh_neigh_info(n);
686
    cli_msg(0,"");
687
    return;
688
  }
689

    
690
  cli_msg(-1013,"%s:", p->name);
691
  cli_msg(-1013,"%-12s\t%3s\t%-15s\t%-5s\t%-12s\t%-10s","Router ID","Pri",
692
    "     State", "DTime", "Router IP", "Interface");
693
  WALK_LIST(ifa,po->iface_list)
694
    WALK_LIST(n, ifa->neigh_list)
695
      ospf_sh_neigh_info(n);
696
  cli_msg(0,"");
697
}
698

    
699
void
700
ospf_sh(struct proto *p)
701
{
702
  struct ospf_area *oa;
703
  struct proto_ospf *po=(struct proto_ospf *)p;
704
  struct ospf_iface *ifa;
705
  struct ospf_neighbor *n;
706
  int ifano;
707
  int nno;
708
  int adjno;
709

    
710
  if(p->proto_state != PS_UP)
711
  {
712
    cli_msg(-1014,"%s: is not up", p->name);
713
    cli_msg(0,"");
714
    return;
715
  }
716

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

    
746
void
747
ospf_sh_iface(struct proto *p, char *iff)
748
{
749
  struct ospf_area *oa;
750
  struct proto_ospf *po=(struct proto_ospf *)p;
751
  struct ospf_iface *ifa=NULL,*f;
752
  struct ospf_neighbor *n;
753
  int ifano;
754
  int nno;
755
  int adjno;
756

    
757
  if(p->proto_state != PS_UP)
758
  {
759
    cli_msg(-1015,"%s: is not up", p->name);
760
    cli_msg(0,"");
761
    return;
762
  }
763

    
764
  if(iff!=NULL)
765
  {
766
    WALK_LIST(f, po->iface_list)
767
    {
768
      if(strcmp(iff,f->iface->name)==0)
769
      {
770
        ifa=f;
771
        break;
772
      }
773
    }
774

    
775
    if(ifa==NULL)
776
    {
777
      cli_msg(0,"");
778
      return;
779
    }
780
    cli_msg(-1015,"%s:", p->name);
781
    ospf_iface_info(ifa);
782
    cli_msg(0,"");
783
    return;
784
  }
785
  cli_msg(-1015,"%s:", p->name);
786
  WALK_LIST(ifa, po->iface_list) ospf_iface_info(ifa);
787
  cli_msg(0,"");
788
}
789

    
790
struct protocol proto_ospf = {
791
  name:                 "OSPF",
792
  template:                "ospf%d",
793
  attr_class:                EAP_OSPF,
794
  init:                        ospf_init,
795
  dump:                        ospf_dump,
796
  start:                ospf_start,
797
  shutdown:                ospf_shutdown,
798
  get_route_info:        ospf_get_route_info,
799
  get_attr:                ospf_get_attr,
800
  get_status:                ospf_get_status,
801
  reconfigure:                ospf_reconfigure
802
};
803