Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / ospf.c @ 035f6acb

History | View | Annotate | Download (24.3 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

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

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

    
95
  WALK_LIST(ac,c->area_list)
96
  {
97
    oa=mb_allocz(po->proto.pool, sizeof(struct ospf_area));
98
    add_tail(&po->area_list, NODE oa);
99
    po->areano++;
100
    oa->stub=ac->stub;
101
    oa->tick=ac->tick;
102
    oa->areaid=ac->areaid;
103
    oa->gr=ospf_top_new(po->proto.pool, po);
104
    s_init_list(&(oa->lsal));
105
    oa->rt=NULL;
106
    oa->po=po;
107
    oa->disp_timer=tm_new(po->proto.pool);
108
    oa->disp_timer->data=oa;
109
    oa->disp_timer->randomize=0;
110
    oa->disp_timer->hook=area_disp;
111
    oa->disp_timer->recurrent=oa->tick;
112
    tm_start(oa->disp_timer,oa->tick);
113
    oa->calcrt=0;
114
    oa->origrt=0;
115
    init_list(&oa->net_list);
116
    WALK_LIST(anet,ac->net_list)
117
    {
118
      antmp=mb_allocz(po->proto.pool, sizeof(struct area_net));
119
      antmp->net=anet->net;
120
      antmp->mlen=anet->mlen;
121
      antmp->hidden=anet->hidden;
122
      add_tail(&oa->net_list, NODE antmp);
123
    }
124
    fib_init(&oa->infib,po->proto.pool,sizeof(struct infib),16,init_infib);
125
  }
126
  return PS_UP;
127
}
128

    
129
static void
130
ospf_dump(struct proto *p)
131
{
132
  char areastr[20];
133
  struct ospf_iface *ifa;
134
  struct ospf_neighbor *n;
135
  struct ospf_config *c = (void *) p->cf;
136
  struct proto_ospf *po=(struct proto_ospf *)p;
137
  struct ospf_area *oa;
138

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

    
141
  WALK_LIST(ifa, po->iface_list)
142
  {
143
    OSPF_TRACE(D_EVENTS, "Interface: %s", ifa->iface->name);
144
    OSPF_TRACE(D_EVENTS, "state: %u", ifa->state);
145
    OSPF_TRACE(D_EVENTS, "DR:  %I", ifa->drid);
146
    OSPF_TRACE(D_EVENTS, "BDR: %I", ifa->bdrid);
147
    WALK_LIST(n, ifa->neigh_list)
148
    {
149
      OSPF_TRACE(D_EVENTS, "  neighbor %I in state %u", n->rid, n->state);
150
    }
151
  }
152

    
153
  WALK_LIST(NODE oa,po->area_list)
154
  {
155
    OSPF_TRACE(D_EVENTS, "LSA graph dump for area \"%I\" start:", oa->areaid);
156
    ospf_top_dump(oa->gr,p);
157
    OSPF_TRACE(D_EVENTS, "LSA graph dump for area \"%I\" finished", oa->areaid);
158
  }
159
  neigh_dump_all();
160
}
161

    
162
static struct proto *
163
ospf_init(struct proto_config *c)
164
{
165
  struct proto *p = proto_new(c, sizeof(struct proto_ospf));
166
  struct proto_ospf *po=(struct proto_ospf *)p;
167
  struct ospf_config *oc=(struct ospf_config *)c;
168
  struct ospf_area_config *ac;
169
  struct ospf_iface_patt *patt;
170

    
171
  p->import_control = ospf_import_control;
172
  p->make_tmp_attrs = ospf_make_tmp_attrs;
173
  p->store_tmp_attrs = ospf_store_tmp_attrs;
174
  p->rt_notify = ospf_rt_notify;
175
  p->if_notify = ospf_if_notify;
176
  p->rte_better = ospf_rte_better;
177
  p->rte_same = ospf_rte_same;
178

    
179
  po->rfc1583=oc->rfc1583;
180
  po->ebit=0;
181
  return p;
182
}
183

    
184
/* If new is better return 1 */
185
static int
186
ospf_rte_better(struct rte *new, struct rte *old)
187
{
188
  struct proto *p = new->attrs->proto;
189

    
190
  if(new->u.ospf.metric1==LSINFINITY) return 0;
191

    
192
  /* External paths are always longer that internal */
193
  if(((new->attrs->source==RTS_OSPF) || (new->attrs->source==RTS_OSPF_IA))
194
    && (old->attrs->source==RTS_OSPF_EXT)) return 1;
195
  if(((old->attrs->source==RTS_OSPF) || (old->attrs->source==RTS_OSPF_IA))
196
    && (new->attrs->source==RTS_OSPF_EXT)) return 0;
197

    
198
  if(new->u.ospf.metric2<old->u.ospf.metric2)
199
  {
200
    if(old->u.ospf.metric2==LSINFINITY) return 0; /* Old is E1, new is E2 */
201
    return 1;        /* Both are E2 */
202
  }
203
        
204
  if(new->u.ospf.metric2>old->u.ospf.metric2)
205
  {
206
    if(new->u.ospf.metric2==LSINFINITY) return 1; /* New is E1, old is E2 */
207
    return 0;        /* Both are E2 */
208
  }
209

    
210
  /* 
211
   * E2 metrics are the same. It means that:
212
   * 1) Paths are E2 with same metric
213
   * 2) Paths are E1.
214
   */
215

    
216
  if(new->u.ospf.metric1<old->u.ospf.metric1) return 1;
217
  return 0;        /* Old is shorter or same */
218
}
219

    
220
static int
221
ospf_rte_same(struct rte *new, struct rte *old)
222
{
223
  /* new->attrs == old->attrs always */
224
  return
225
    new->u.ospf.metric1 == old->u.ospf.metric1 &&
226
    new->u.ospf.metric2 == old->u.ospf.metric2 &&
227
    new->u.ospf.tag     == old->u.ospf.tag;
228
}
229

    
230
static ea_list *
231
ospf_build_attrs(ea_list *next, struct linpool *pool, u32 m1, u32 m2, u32 tag)
232
{
233
  struct ea_list *l = lp_alloc(pool, sizeof(struct ea_list) + 3*sizeof(eattr));
234

    
235
  l->next = next;
236
  l->flags = EALF_SORTED;
237
  l->count = 3;
238
  l->attrs[0].id = EA_OSPF_METRIC1;
239
  l->attrs[0].flags = 0;
240
  l->attrs[0].type = EAF_TYPE_INT | EAF_TEMP;
241
  l->attrs[0].u.data = m1;
242
  l->attrs[1].id = EA_OSPF_METRIC2;
243
  l->attrs[1].flags = 0;
244
  l->attrs[1].type = EAF_TYPE_INT | EAF_TEMP;
245
  l->attrs[1].u.data = m2;
246
  l->attrs[2].id = EA_OSPF_TAG;
247
  l->attrs[2].flags = 0;
248
  l->attrs[2].type = EAF_TYPE_INT | EAF_TEMP;
249
  l->attrs[2].u.data = tag;
250
  return l;
251
}
252

    
253
void
254
schedule_rt_lsa(struct ospf_area *oa)
255
{
256
  struct proto_ospf *po=oa->po;
257
  struct proto *p=&po->proto;
258

    
259
  OSPF_TRACE(D_EVENTS, "Scheduling RT lsa origination for area %I.",
260
    oa->areaid);
261
  oa->origrt=1;
262
}
263

    
264
void
265
schedule_rtcalc(struct ospf_area *oa)
266
{
267
  struct proto_ospf *po=oa->po;
268
  struct proto *p=&po->proto;
269

    
270
  OSPF_TRACE(D_EVENTS, "Scheduling RT calculation for area %I.", 
271
    oa->areaid);
272
  oa->calcrt=1;
273
}
274

    
275
/**
276
 * area_disp - invokes link-state database aging, origination of
277
 * router LSA and routing table calculation
278
 * @timer: it's called every @ospf_area->tick seconds
279
 *
280
 * It invokes aging and when @ospf_area->origrt is set to 1, start
281
 * function for origination of router LSA and network LSAs.
282
 * It also starts routing
283
 * table calculation when @ospf_area->calcrt is set.
284
 */
285
void
286
area_disp(timer *timer)
287
{
288
  struct ospf_area *oa=timer->data;
289
  struct top_hash_entry *en,*nxt;
290
  struct proto_ospf *po=oa->po;
291
  struct ospf_iface *ifa;
292

    
293
  /* Now try to originage rt_lsa */
294
  if(oa->origrt) originate_rt_lsa(oa);
295

    
296
  /* Now try to originate network LSA's */
297
  WALK_LIST(ifa, po->iface_list)
298
  {
299
    if(ifa->orignet&&(ifa->an==oa->areaid)) originate_net_lsa(ifa);
300
  }
301

    
302
  /* Age LSA DB */
303
  ospf_age(oa);
304

    
305
  /* Calculate routing table */
306
  if(oa->calcrt) ospf_rt_spfa(oa);
307
  oa->calcrt=0;
308
}
309

    
310
/**
311
 * ospf_import_control - accept or reject new route from nest's routing table
312
 * @p: current instance of protocol
313
 * @new: the new route
314
 * @attrs: list of attributes
315
 * @pool: pool for allocation of attributes
316
 *
317
 * Its quite simple. It does not accept our own routes and leaves the decision on
318
 * import to the filters.
319
 */
320

    
321
int
322
ospf_import_control(struct proto *p, rte **new, ea_list **attrs, struct linpool *pool)
323
{
324
  rte *e=*new;
325
  struct proto_ospf *po=(struct proto_ospf *)p;
326

    
327
  if(p==e->attrs->proto) return -1;        /* Reject our own routes */
328
  *attrs = ospf_build_attrs(*attrs, pool, LSINFINITY, 10000, 0);
329
  return 0;                                /* Leave decision to the filters */
330
}
331

    
332
struct ea_list *
333
ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool)
334
{
335
  return ospf_build_attrs(NULL, pool, rt->u.ospf.metric1, rt->u.ospf.metric2, rt->u.ospf.tag);
336
}
337

    
338
void
339
ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs)
340
{
341
  rt->u.ospf.metric1 = ea_get_int(attrs, EA_OSPF_METRIC1, LSINFINITY);
342
  rt->u.ospf.metric2 = ea_get_int(attrs, EA_OSPF_METRIC2, 10000);
343
  rt->u.ospf.tag     = ea_get_int(attrs, EA_OSPF_TAG,     0);
344
}
345

    
346
/**
347
 * ospf_shutdown - Finish of OSPF instance
348
 * @p: current instance of protocol
349
 *
350
 * RFC does not define any action that should be taken before router
351
 * shutdown. To make my neighbors react as fast as possible, I send
352
 * them hello packet with empty neighbor list. They should start
353
 * their neighbor state machine with event %NEIGHBOR_1WAY.
354
 */
355

    
356
static int
357
ospf_shutdown(struct proto *p)
358
{
359
  struct proto_ospf *po=(struct proto_ospf *)p;
360
  struct ospf_iface *ifa;
361
  struct ospf_neighbor *n;
362
  struct ospf_area *oa;
363
  OSPF_TRACE(D_EVENTS, "Shutdown requested");
364

    
365
  /* And send to all my neighbors 1WAY */
366
  WALK_LIST(ifa, po->iface_list)
367
  {
368
    init_list(&ifa->neigh_list);
369
    hello_timer_hook(ifa->hello_timer);
370
  }
371
  
372
  return PS_DOWN;
373
}
374

    
375
void
376
ospf_rt_notify(struct proto *p, net *n, rte *new, rte *old, ea_list *attrs)
377
{
378
  struct proto_ospf *po=(struct proto_ospf *)p;
379

    
380
/* Temporarily down write anything
381
  OSPF_TRACE(D_EVENTS, "Got route %I/%d %s", p->name, n->n.prefix,
382
    n->n.pxlen, new ? "up" : "down");
383
*/
384

    
385
  if(new)                /* Got some new route */
386
  {
387
    originate_ext_lsa(n, new, po, attrs);
388
  }
389
  else
390
  {
391
    u32 rtid=po->proto.cf->global->router_id;
392
    struct ospf_area *oa;
393
    struct top_hash_entry *en;
394
    u32 pr=ipa_to_u32(n->n.prefix);
395
    struct ospf_lsa_ext *ext;
396
    int i;
397
    int max=max_ext_lsa(n->n.pxlen);
398

    
399
    /* Flush old external LSA */
400
    WALK_LIST(oa, po->area_list)
401
    {
402
      for(i=0;i<max;i++,pr++)
403
      {
404
        if(en=ospf_hash_find(oa->gr, pr, rtid, LSA_T_EXT))
405
        {
406
          ext=en->lsa_body;
407
          if(ipa_compare(ext->netmask, ipa_mkmask(n->n.pxlen))==0)
408
          {
409
            net_flush_lsa(en,po,oa);
410
            break;
411
          }
412
        }
413
      }
414
    }
415
  }
416
}
417

    
418
static void
419
ospf_get_status(struct proto *p, byte *buf)
420
{
421
  struct proto_ospf *po=(struct proto_ospf *)p;
422

    
423
  if (p->proto_state == PS_DOWN) buf[0] = 0;
424
  else
425
  {
426
    struct ospf_iface *ifa;
427
    struct ospf_neighbor *n;
428
    int adj=0;
429

    
430
    WALK_LIST(ifa,po->iface_list)
431
      WALK_LIST(n,ifa->neigh_list)
432
        if(n->state==NEIGHBOR_FULL) adj=1;
433

    
434
    if(adj==0) strcpy(buf, "Alone");
435
    else strcpy(buf, "Running");
436
  }
437
}
438

    
439
static void
440
ospf_get_route_info(rte *rte, byte *buf, ea_list *attrs)
441
{
442
  char met=' ';
443
  char type=' ';
444

    
445
  if(rte->attrs->source==RTS_OSPF_EXT)
446
  {
447
    met='1';
448
    type='E';
449

    
450
  }
451
  if(rte->u.ospf.metric2!=LSINFINITY) met='2';
452
  if(rte->attrs->source==RTS_OSPF_IA) type='A';
453
  if(rte->attrs->source==RTS_OSPF) type='I';
454
  buf += bsprintf(buf, " %c", type);
455
  if(met!=' ') buf += bsprintf(buf, "%c", met);
456
  buf += bsprintf(buf, " (%d/%d", rte->pref, rte->u.ospf.metric1);
457
  if(rte->u.ospf.metric2!=LSINFINITY) buf += bsprintf(buf, "/%d", rte->u.ospf.metric2);
458
  buf += bsprintf(buf, ")");
459
  if(rte->attrs->source==RTS_OSPF_EXT && rte->u.ospf.tag)
460
  {
461
    buf += bsprintf(buf, " [%x]", rte->u.ospf.tag);
462
  }
463
}
464

    
465
static int
466
ospf_get_attr(eattr *a, byte *buf)
467
{
468
  switch (a->id)
469
    {
470
    case EA_OSPF_METRIC1: bsprintf(buf, "metric1"); return GA_NAME;
471
    case EA_OSPF_METRIC2: bsprintf(buf, "metric2"); return GA_NAME;
472
    case EA_OSPF_TAG: bsprintf(buf, "tag: %08x", a->u.data); return GA_FULL;
473
    default: return GA_UNKNOWN;
474
    }
475
}
476

    
477
static int
478
ospf_patt_compare(struct ospf_iface_patt *a, struct ospf_iface_patt *b)
479
{
480
  return ((a->type==b->type)&&(a->priority==b->priority));
481
}
482

    
483
/**
484
 * ospf_reconfigure - reconfiguration hook
485
 * @p: current instance of protocol (with old configuration)
486
 * @c: new configuration requested by user
487
 *
488
 * This hook tries to be a little bit intelligent. Instance of OSPF
489
 * will survive change of many constants like hello interval,
490
 * password change, addition or deletion of some neighbor on
491
 * nonbroadcast network, cost of interface, etc.
492
 */
493
static int
494
ospf_reconfigure(struct proto *p, struct proto_config *c)
495
{
496
  struct ospf_config *old=(struct ospf_config *)(p->cf);
497
  struct ospf_config *new=(struct ospf_config *)c;
498
  struct ospf_area_config *ac1,*ac2;
499
  struct proto_ospf *po=( struct proto_ospf *)p;
500
  struct ospf_iface_patt *ip1,*ip2;
501
  struct ospf_iface *ifa;
502
  struct nbma_node *nb1,*nb2,*nbnx;
503
  struct ospf_area *oa=NULL;
504
  struct area_net *anet,*antmp;
505
  int found;
506

    
507
  po->rfc1583=new->rfc1583;
508
  WALK_LIST(oa, po->area_list)        /* Routing table must be recalculated */
509
  {
510
    schedule_rtcalc(oa);
511
  }
512

    
513
  ac1=HEAD(old->area_list);
514
  ac2=HEAD(new->area_list);
515

    
516
  /* I should get it in same order */
517
  
518
  while(((NODE (ac1))->next!=NULL) && ((NODE (ac2))->next!=NULL))
519
  {
520
    if(ac1->areaid!=ac2->areaid) return 0;
521
    if(ac1->stub!=ac2->stub) return 0;        /* FIXME: non zero values can change */
522

    
523
    WALK_LIST(oa,po->area_list)
524
      if(oa->areaid==ac2->areaid) break;
525

    
526
    if(!oa) return 0;
527

    
528
    if(ac1->tick!=ac2->tick)
529
    {
530
      if(oa->areaid==ac2->areaid)
531
      {
532
        oa->tick=ac2->tick;
533
        tm_start(oa->disp_timer,oa->tick);
534
        OSPF_TRACE(D_EVENTS,
535
         "Changing tick interval on area %I from %d to %d",
536
         oa->areaid, ac1->tick, ac2->tick);
537
        break;
538
      }
539
    }
540

    
541
    /* Change net_list */
542
    WALK_LIST_DELSAFE(anet, antmp, oa->net_list)
543
    {
544
       rem_node(NODE anet);
545
       mb_free(anet);
546
    }
547
    WALK_LIST(anet, ac2->net_list)
548
    {
549
       antmp=mb_alloc(p->pool, sizeof(struct area_net));
550
       antmp->net=anet->net;
551
       antmp->mlen=anet->mlen;
552
       antmp->hidden=anet->hidden;
553
       add_tail(&oa->net_list, NODE antmp);
554
    }
555

    
556
    if(!iface_patts_equal(&ac1->patt_list, &ac2->patt_list,
557
      (void *) ospf_patt_compare))
558
        return 0;
559

    
560
    WALK_LIST(ifa, po->iface_list)
561
    {
562
      if(ip1=(struct ospf_iface_patt *)
563
        iface_patt_match(&ac1->patt_list, ifa->iface))
564
      {
565
        /* Now reconfigure interface */
566
        if(!(ip2=(struct ospf_iface_patt *)
567
          iface_patt_match(&ac2->patt_list, ifa->iface))) return 0;
568

    
569
        /* HELLO TIMER */
570
        if(ip1->helloint!=ip2->helloint)
571
        {
572
          ifa->helloint=ip2->helloint;
573
          ifa->hello_timer->recurrent=ifa->helloint;
574
          tm_start(ifa->hello_timer,ifa->helloint);
575
          OSPF_TRACE(D_EVENTS,
576
            "Changing hello interval on interface %s from %d to %d",
577
            ifa->iface->name,ip1->helloint,ip2->helloint);
578
        }
579

    
580
        /* POLL TIMER */
581
        if(ip1->pollint!=ip2->pollint)
582
        {
583
          ifa->pollint=ip2->helloint;
584
          ifa->poll_timer->recurrent=ifa->pollint;
585
          tm_start(ifa->poll_timer,ifa->pollint);
586
          OSPF_TRACE(D_EVENTS,
587
            "Changing poll interval on interface %s from %d to %d",
588
            ifa->iface->name,ip1->pollint,ip2->pollint);
589
        }
590

    
591
        /* COST */
592
        if(ip1->cost!=ip2->cost)
593
        {
594
          ifa->cost=ip2->cost;
595
          OSPF_TRACE(D_EVENTS,
596
            "Changing cost interface %s from %d to %d",
597
            ifa->iface->name,ip1->cost,ip2->cost);
598
          schedule_rt_lsa(ifa->oa);
599
        }
600

    
601
        /* strict nbma */
602
        if((ip1->strictnbma==0)&&(ip2->strictnbma!=0))
603
        {
604
          ifa->strictnbma=ip2->strictnbma;
605
          OSPF_TRACE(D_EVENTS,
606
            "Interface %s is now strict NBMA.",
607
            ifa->iface->name);
608
        }
609
        if((ip1->strictnbma!=0)&&(ip2->strictnbma==0))
610
        {
611
          ifa->strictnbma=ip2->strictnbma;
612
          OSPF_TRACE(D_EVENTS,
613
            "Interface %s is no longer strict NBMA.",
614
            ifa->iface->name);
615
        }
616

    
617
        /* stub */
618
        if((ip1->stub==0)&&(ip2->stub!=0))
619
        {
620
          ifa->stub=ip2->stub;
621
          OSPF_TRACE(D_EVENTS,
622
            "Interface %s is now stub.",
623
            ifa->iface->name);
624
        }
625
        if((ip1->stub!=0)&&(ip2->stub==0)&&
626
          ((ifa->ioprob & OSPF_I_IP)==0)&&
627
          (((ifa->ioprob & OSPF_I_MC)==0)||
628
          (ifa->type==OSPF_IT_NBMA)))
629
        {
630
          ifa->stub=ip2->stub;
631
          OSPF_TRACE(D_EVENTS,
632
            "Interface %s is no longer stub.",
633
            ifa->iface->name);
634
        }
635

    
636
        /* AUTHENTICATION */
637
        if(ip1->autype!=ip2->autype)
638
        {
639
          ifa->autype=ip2->autype;
640
          OSPF_TRACE(D_EVENTS,
641
            "Changing authentication type on interface %s",
642
            ifa->iface->name);
643
        }
644
        if(strncmp(ip1->password,ip2->password,8)!=0)
645
        {
646
          memcpy(ifa->aukey,ip2->password,8);
647
          OSPF_TRACE(D_EVENTS,
648
            "Changing password on interface %s",
649
            ifa->iface->name);
650
        }
651

    
652
        /* RXMT */
653
        if(ip1->rxmtint!=ip2->rxmtint)
654
        {
655
          ifa->rxmtint=ip2->rxmtint;
656
          OSPF_TRACE(D_EVENTS,
657
            "Changing retransmit interval on interface %s from %d to %d",
658
            ifa->iface->name,ip1->rxmtint,ip2->rxmtint);
659
        }
660

    
661
        /* WAIT */
662
        if(ip1->waitint!=ip2->waitint)
663
        {
664
          ifa->waitint=ip2->waitint;
665
          if(ifa->wait_timer->expires!=0)
666
            tm_start(ifa->wait_timer,ifa->waitint);
667
          OSPF_TRACE(D_EVENTS,
668
            "Changing wait interval on interface %s from %d to %d",
669
            ifa->iface->name,ip1->waitint,ip2->waitint);
670
        }
671

    
672
        /* INFTRANS */
673
        if(ip1->inftransdelay!=ip2->inftransdelay)
674
        {
675
          ifa->inftransdelay=ip2->inftransdelay;
676
          OSPF_TRACE(D_EVENTS,
677
            "Changing transmit delay on interface %s from %d to %d",
678
            ifa->iface->name,ip1->inftransdelay,ip2->inftransdelay);
679
        }
680

    
681
        /* DEAD COUNT */
682
        if(ip1->deadc!=ip2->deadc)
683
        {
684
          ifa->deadc=ip2->deadc;
685
          OSPF_TRACE(D_EVENTS,
686
            "Changing dead count on interface %s from %d to %d",
687
            ifa->iface->name,ip1->deadc,ip2->deadc);
688
        }
689

    
690
        /* NBMA LIST */
691
        /* First remove old */
692
        WALK_LIST_DELSAFE(nb1, nbnx, ifa->nbma_list)
693
        {
694
          found=0;
695
          WALK_LIST(nb2, ip2->nbma_list)
696
            if(ipa_compare(nb1->ip,nb2->ip)==0)
697
            {
698
              found=1;
699
              if(nb1->eligible!=nb2->eligible)
700
                OSPF_TRACE(D_EVENTS,
701
                  "Changing neighbor eligibility %I on interface %s",
702
                  nb1->ip,ifa->iface->name);
703
              break;
704
            }
705

    
706
          if(!found)
707
          {
708
            OSPF_TRACE(D_EVENTS,
709
              "Removing NBMA neighbor %I on interface %s",
710
              nb1->ip,ifa->iface->name);
711
            rem_node(NODE nb1);
712
            mb_free(nb1);
713
          }
714
        }
715
        /* And then add new */
716
        WALK_LIST(nb2, ip2->nbma_list)
717
        {
718
          found=0;
719
          WALK_LIST(nb1, ifa->nbma_list)
720
            if(ipa_compare(nb1->ip,nb2->ip)==0)
721
            {
722
              found=1;
723
              break;
724
            }
725
          if(!found)
726
          {
727
            nb1=mb_alloc(p->pool,sizeof(struct nbma_node));
728
            nb1->ip=nb2->ip;
729
            nb1->eligible=nb2->eligible;
730
            add_tail(&ifa->nbma_list, NODE nb1);
731
            OSPF_TRACE(D_EVENTS,
732
              "Adding NBMA neighbor %I on interface %s",
733
              nb1->ip,ifa->iface->name);
734
          }
735
        }
736
      }
737
    }
738

    
739
    NODE ac1=(NODE (ac1))->next;
740
    NODE ac2=(NODE (ac2))->next;
741
  }
742

    
743
  if(((NODE (ac1))->next)!=((NODE (ac2))->next))
744
    return 0;        /* One is not null */
745

    
746
  return 1;        /* Everything OK :-) */
747
}
748

    
749
void
750
ospf_sh_neigh(struct proto *p, char *iff)
751
{
752
  struct ospf_iface *ifa=NULL,*f;
753
  struct ospf_neighbor *n;
754
  struct proto_ospf *po=(struct proto_ospf *)p;
755

    
756
  if(p->proto_state != PS_UP)
757
  {
758
    cli_msg(-1013,"%s: is not up", p->name);
759
    cli_msg(0,"");
760
    return;
761
  }
762
  
763
  if(iff!=NULL)
764
  {
765
    WALK_LIST(f, po->iface_list)
766
    {
767
      if(strcmp(iff,f->iface->name)==0)
768
      {
769
        ifa=f;
770
        break;
771
      }
772
    }
773
    if(ifa==NULL)
774
    {
775
      cli_msg(0,"");
776
      return;
777
    }
778
    cli_msg(-1013,"%s:", p->name);
779
    cli_msg(-1013,"%-12s\t%3s\t%-15s\t%-5s\t%-12s\t%-10s","Router ID","Pri",
780
      "     State", "DTime", "Router IP", "Interface");
781
    WALK_LIST(n, ifa->neigh_list) ospf_sh_neigh_info(n);
782
    cli_msg(0,"");
783
    return;
784
  }
785

    
786
  cli_msg(-1013,"%s:", p->name);
787
  cli_msg(-1013,"%-12s\t%3s\t%-15s\t%-5s\t%-12s\t%-10s","Router ID","Pri",
788
    "     State", "DTime", "Router IP", "Interface");
789
  WALK_LIST(ifa,po->iface_list)
790
    WALK_LIST(n, ifa->neigh_list)
791
      ospf_sh_neigh_info(n);
792
  cli_msg(0,"");
793
}
794

    
795
void
796
ospf_sh(struct proto *p)
797
{
798
  struct ospf_area *oa;
799
  struct proto_ospf *po=(struct proto_ospf *)p;
800
  struct ospf_iface *ifa;
801
  struct ospf_neighbor *n;
802
  int ifano;
803
  int nno;
804
  int adjno;
805

    
806
  if(p->proto_state != PS_UP)
807
  {
808
    cli_msg(-1014,"%s: is not up", p->name);
809
    cli_msg(0,"");
810
    return;
811
  }
812

    
813
  cli_msg(-1014,"%s:", p->name);
814
  cli_msg(-1014,"Number of areas: %u", po->areano);
815
  
816
  WALK_LIST(oa,po->area_list)
817
  {
818
    cli_msg(-1014,"\tArea: %I (%u) %s", oa->areaid, oa->areaid,
819
      oa->areaid==0 ? "[BACKBONE]" : "");
820
    ifano=0;
821
    nno=0;
822
    adjno=0;
823
    WALK_LIST(ifa, po->iface_list)
824
    {
825
      if(oa==ifa->oa) ifano++;
826
      WALK_LIST(n, ifa->neigh_list)
827
      {
828
        nno++;
829
        if(n->state==NEIGHBOR_FULL) adjno++;
830
      }
831
    }
832
    cli_msg(-1014,"\t\tStub:\t%s", oa->stub ? "Yes" : "No");
833
    cli_msg(-1014,"\t\tRT scheduler tick:\t%u", oa->tick);
834
    cli_msg(-1014,"\t\tNumber of interfaces:\t%u", ifano);
835
    cli_msg(-1014,"\t\tNumber of LSAs in DB:\t%u", oa->gr->hash_entries);
836
    cli_msg(-1014,"\t\tNumber of neighbors:\t%u", nno);
837
    cli_msg(-1014,"\t\tNumber of adjacent neighbors:\t%u", adjno);
838
    if(!EMPTY_LIST(oa->net_list))
839
    {
840
      struct area_net *anet;
841
      cli_msg(-1014,"\t\tArea networks:");
842
      WALK_LIST(anet, oa->net_list)
843
      {
844
        cli_msg(-1014,"\t\t\t%1I/%u\t%s", anet->net, anet->mlen,
845
          anet->hidden ? "Hidden" : "Advertise");
846
      }
847
    }
848
  }
849
  cli_msg(0,"");
850
}
851

    
852
void
853
ospf_sh_iface(struct proto *p, char *iff)
854
{
855
  struct ospf_area *oa;
856
  struct proto_ospf *po=(struct proto_ospf *)p;
857
  struct ospf_iface *ifa=NULL,*f;
858
  struct ospf_neighbor *n;
859
  int ifano;
860
  int nno;
861
  int adjno;
862

    
863
  if(p->proto_state != PS_UP)
864
  {
865
    cli_msg(-1015,"%s: is not up", p->name);
866
    cli_msg(0,"");
867
    return;
868
  }
869

    
870
  if(iff!=NULL)
871
  {
872
    WALK_LIST(f, po->iface_list)
873
    {
874
      if(strcmp(iff,f->iface->name)==0)
875
      {
876
        ifa=f;
877
        break;
878
      }
879
    }
880

    
881
    if(ifa==NULL)
882
    {
883
      cli_msg(0,"");
884
      return;
885
    }
886
    cli_msg(-1015,"%s:", p->name);
887
    ospf_iface_info(ifa);
888
    cli_msg(0,"");
889
    return;
890
  }
891
  cli_msg(-1015,"%s:", p->name);
892
  WALK_LIST(ifa, po->iface_list) ospf_iface_info(ifa);
893
  cli_msg(0,"");
894
}
895

    
896
struct protocol proto_ospf = {
897
  name:                 "OSPF",
898
  template:                "ospf%d",
899
  attr_class:                EAP_OSPF,
900
  init:                        ospf_init,
901
  dump:                        ospf_dump,
902
  start:                ospf_start,
903
  shutdown:                ospf_shutdown,
904
  get_route_info:        ospf_get_route_info,
905
  get_attr:                ospf_get_attr,
906
  get_status:                ospf_get_status,
907
  reconfigure:                ospf_reconfigure
908
};
909