Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (16.9 KB)

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

    
10
#include "nest/bird.h"
11
#include "lib/string.h"
12

    
13
#include "ospf.h"
14

    
15
#define HASH_DEF_ORDER 6
16
#define HASH_HI_MARK *4
17
#define HASH_HI_STEP 2
18
#define HASH_HI_MAX 16
19
#define HASH_LO_MARK /5
20
#define HASH_LO_STEP 2
21
#define HASH_LO_MIN 8
22

    
23
void *
24
originate_rt_lsa_body(struct ospf_area *oa, u16 *length, struct proto_ospf *p)
25
{
26
  struct ospf_iface *ifa;
27
  int j=0,k=0,v=0;
28
  u16 i=0;
29
  struct ospf_lsa_rt *rt;
30
  struct ospf_lsa_rt_link *ln;
31
  struct ospf_neighbor *neigh;
32
  struct top_hash_entry *old;
33
  struct proto_ospf *po=(struct proto_ospf *)p;
34

    
35
  DBG("%s: Originating RT_lsa body for area \"%I\".\n", po->proto.name,
36
    oa->areaid);
37

    
38
  WALK_LIST (ifa, p->iface_list)
39
  {
40
    if((ifa->an==oa->areaid) && (ifa->state!=OSPF_IS_DOWN))
41
    {
42
      i++;
43
      if(ifa->type==OSPF_IT_VLINK) v=1;
44
    }
45
  }
46
  rt=mb_allocz(p->proto.pool, sizeof(struct ospf_lsa_rt)+
47
    i*sizeof(struct ospf_lsa_rt_link));
48
  if(p->areano>1) rt->veb.bit.b=1;
49
  if((p->ebit)&&(!oa->stub)) rt->veb.bit.e=1;
50
  rt->veb.bit.v=v;
51
  ln=(struct ospf_lsa_rt_link *)(rt+1);
52

    
53
  WALK_LIST (ifa, p->iface_list)
54
  {
55
    if((ifa->an!=oa->areaid) || (ifa->state==OSPF_IS_DOWN)) continue;
56

    
57
    if(ifa->state==OSPF_IS_LOOP)
58
    {
59
      ln->type=3;
60
      ln->id=ipa_to_u32(ifa->iface->addr->ip);
61
      ln->data=0xffffffff;
62
      ln->metric=0;
63
      ln->notos=0;
64
    }
65
    else
66
    {
67
      switch(ifa->type)
68
      {
69
        case OSPF_IT_PTP:                /* rfc2328 - pg126 */
70
          neigh=(struct ospf_neighbor *)HEAD(ifa->neigh_list);
71
          if((!EMPTY_LIST(ifa->neigh_list)) && (neigh->state==NEIGHBOR_FULL))
72
          {
73
             ln->type=LSART_PTP;
74
             ln->id=neigh->rid;
75
             ln->metric=ifa->cost;
76
             ln->notos=0;
77
             if(ifa->iface->flags && IA_UNNUMBERED)
78
             {
79
               ln->data=ifa->iface->index;
80
             }
81
             else
82
             {
83
               ln->id=ipa_to_u32(ifa->iface->addr->ip);
84
             }
85
          }
86
          else
87
          {
88
            if(ifa->state==OSPF_IS_PTP)
89
            {
90
              ln->type=LSART_STUB;
91
              ln->id=ln->id=ipa_to_u32(ifa->iface->addr->opposite);
92
              ln->metric=ifa->cost;
93
              ln->notos=0;
94
              ln->data=0xffffffff;
95
            }
96
            else
97
            {
98
              i--; /* No link added */
99
            }
100
          }
101
          break;
102
        case OSPF_IT_BCAST:
103
        case OSPF_IT_NBMA:
104
          if(ifa->state==OSPF_IS_WAITING)
105
          {
106
            ln->type=LSART_STUB;
107
            ln->id=ipa_to_u32(ifa->iface->addr->prefix);
108
            ln->data=ipa_to_u32(ipa_mkmask(ifa->iface->addr->pxlen));
109
            ln->metric=ifa->cost;
110
            ln->notos=0;
111
          }
112
          else
113
          {
114
            j=0,k=0;
115
            WALK_LIST(neigh, ifa->neigh_list)
116
            {
117
              if((neigh->rid==ifa->drid) &&
118
                (neigh->state==NEIGHBOR_FULL)) k=1;
119
              if(neigh->state==NEIGHBOR_FULL) j=1;
120
            }
121
            if(((ifa->state==OSPF_IS_DR) && (j==1)) || (k==1))
122
            {
123
              ln->type=LSART_NET;
124
              ln->id=ipa_to_u32(ifa->drip);
125
              ln->data=ipa_to_u32(ifa->iface->addr->ip);
126
              ln->metric=ifa->cost;
127
              ln->notos=0;
128
            }
129
            else
130
            {
131
              ln->type=LSART_STUB;
132
              ln->id=ipa_to_u32(ifa->iface->addr->prefix);
133
              ln->data=ipa_to_u32(ipa_mkmask(ifa->iface->addr->pxlen));
134
              ln->metric=ifa->cost;
135
              ln->notos=0;
136
            }
137
          }
138
          break;
139
        case OSPF_IT_VLINK:        /* FIXME Add virtual links! */
140
          i--;
141
          break;
142
      }
143
    }
144
    if(ifa->type==OSPF_IT_VLINK) v=1;
145
    ln=(ln+1);
146
  }
147
  rt->links=i;
148
  *length=i*sizeof(struct ospf_lsa_rt_link)+sizeof(struct ospf_lsa_rt)+
149
    sizeof(struct ospf_lsa_header);
150
  return rt;
151
}
152

    
153
void
154
addifa_rtlsa(struct ospf_iface *ifa)
155
{
156
  struct ospf_area *oa;
157
  struct proto_ospf *po=ifa->proto;
158
  struct proto *p=&po->proto;
159

    
160

    
161
  WALK_LIST(NODE oa,po->area_list)
162
  {
163
    if(oa->areaid==ifa->an) break;
164
  }
165

    
166
  if(EMPTY_LIST(po->area_list) || (oa->areaid!=ifa->an))        /* New area */
167
  {
168
    bug("Cannot add any area to accepted Interface");
169
  }
170
  else ifa->oa=oa;
171
}
172

    
173
/**
174
 * originate_rt_lsa - build new instance of router LSA
175
 * @oa: ospf_area which is LSA built to
176
 *
177
 * It builds router LSA walking through all OSPF interfaces in
178
 * specified OSPF area. This function is mostly called from
179
 * area_disp(). Builds new LSA, increases sequence number (if old
180
 * instance exists) and sets age of LSA to zero.
181
 */
182
void
183
originate_rt_lsa(struct ospf_area *oa)
184
{
185
  struct ospf_lsa_header lsa;
186
  struct proto_ospf *po=oa->po;
187
  struct proto *p=&po->proto;
188
  u32 rtid=po->proto.cf->global->router_id;
189
  struct top_hash_entry *en;
190
  void *body;
191

    
192
  if((oa->rt)&&((oa->rt->inst_t+MINLSINTERVAL))>now) return;
193
        /*
194
         * Tick is probably set to very low value. We cannot
195
         * originate new LSA before MINLSINTERVAL. We will
196
         * try to do it next tick.
197
         */
198

    
199
  OSPF_TRACE(D_EVENTS, "Originating RT_lsa for area \"%I\".",oa->areaid);
200

    
201
  lsa.age=0;
202
  lsa.id=rtid;
203
  lsa.type=LSA_T_RT;
204
  lsa.rt=rtid;
205
  lsa.options=0;
206
  if(oa->rt==NULL)
207
  {
208
    lsa.sn=LSA_INITSEQNO;
209
  }
210
  else
211
  {
212
    lsa.sn=oa->rt->lsa.sn+1;
213
  }
214
  body=originate_rt_lsa_body(oa, &lsa.length, po);
215
  lsasum_calculate(&lsa,body,po);
216
  en=lsa_install_new(&lsa, body, oa);
217
  oa->rt=en;
218
  flood_lsa(NULL,NULL,&oa->rt->lsa,po,NULL,oa,1);
219
  schedule_rtcalc(oa);
220
  oa->origrt=0;
221
}
222

    
223
void *
224
originate_net_lsa_body(struct ospf_iface *ifa, u16 *length,
225
  struct proto_ospf *po)
226
{
227
  u16 i=1;
228
  struct ospf_neighbor *n;
229
  u32 *body;
230
  struct ospf_lsa_net *net;
231

    
232
  net=mb_alloc(po->proto.pool,sizeof(u32)*(ifa->fadj+1)+
233
    sizeof(struct ospf_lsa_net));
234
  net->netmask=ipa_mkmask(ifa->iface->addr->pxlen);
235

    
236
  body=(u32 *)(net+1);
237
  i=1;
238
  *body=po->proto.cf->global->router_id;
239
  WALK_LIST(n,ifa->neigh_list)
240
  {
241
    if(n->state==NEIGHBOR_FULL)
242
    {
243
      *(body+i)=n->rid;
244
      i++;
245
    }
246
  }
247
  *length=i*sizeof(u32)+sizeof(struct ospf_lsa_header)+
248
    sizeof(struct ospf_lsa_net);
249
  return net;
250
}
251

    
252
/**
253
 * originate_net_lsa - originates of deletes network LSA
254
 * @ifa: interface which is LSA originated for
255
 *
256
 * Interface counts number of adjacent neighbors. If this number is
257
 * lower than one or interface is not in state %OSPF_IS_DR it deletes
258
 * and premature ages instance of network LSA for specified interface.
259
 * In other case, new instance of network LSA is originated.
260
 */
261
void
262
originate_net_lsa(struct ospf_iface *ifa)
263
{
264
  struct proto_ospf *po=ifa->proto;
265
  struct ospf_lsa_header lsa;
266
  u32 rtid=po->proto.cf->global->router_id;
267
  struct top_hash_entry *en;
268
  struct proto *p=&po->proto;
269
  void *body;
270

    
271
  if(ifa->nlsa&&((ifa->nlsa->inst_t+MINLSINTERVAL)>now)) return;
272
  /*
273
   * It's too early to originate new network LSA. We will
274
   * try to do it next tick
275
   */
276

    
277
  if((ifa->state!=OSPF_IS_DR)||(ifa->fadj==0))
278
  {
279
    if(ifa->nlsa==NULL) return;
280

    
281
    OSPF_TRACE(D_EVENTS, "Deleting Net lsa for iface \"%s\".",
282
      ifa->iface->name);
283
    ifa->nlsa->lsa.sn+=1;
284
    ifa->nlsa->lsa.age=LSA_MAXAGE;
285
    flood_lsa(NULL,NULL,&ifa->nlsa->lsa,po,NULL,ifa->oa,0);
286
    s_rem_node(SNODE ifa->nlsa);
287
    if(ifa->nlsa->lsa_body!=NULL) mb_free(ifa->nlsa->lsa_body);
288
    ifa->nlsa->lsa_body=NULL;
289
    ospf_hash_delete(ifa->oa->gr, ifa->nlsa);
290
    schedule_rtcalc(ifa->oa);
291
    ifa->nlsa=NULL;
292
    return ;
293
  }
294

    
295
  OSPF_TRACE(D_EVENTS, "Originating Net lsa for iface \"%s\".",
296
    ifa->iface->name);
297

    
298
  lsa.age=0;
299
  lsa.id=ipa_to_u32(ifa->iface->addr->ip);
300
  lsa.type=LSA_T_NET;
301
  lsa.rt=rtid;
302
  lsa.options=0;
303
  if(ifa->nlsa==NULL)
304
  {
305
    lsa.sn=LSA_INITSEQNO;
306
  }
307
  else
308
  {
309
    lsa.sn=ifa->nlsa->lsa.sn+1;
310
  }
311

    
312
  body=originate_net_lsa_body(ifa, &lsa.length, po);
313
  lsasum_calculate(&lsa,body,po);
314
  ifa->nlsa=lsa_install_new(&lsa, body, ifa->oa);
315
  flood_lsa(NULL,NULL,&ifa->nlsa->lsa,po,NULL,ifa->oa,1);
316
  ifa->orignet=0;
317
}
318

    
319
static void *
320
originate_ext_lsa_body(net *n, rte *e, struct proto_ospf *po, struct ea_list *attrs)
321
{
322
  struct proto *p=&po->proto;
323
  struct ospf_lsa_ext *ext;
324
  struct ospf_lsa_ext_tos *et;
325
  neighbor *nn;
326
  u32 m1 = ea_get_int(attrs, EA_OSPF_METRIC1, LSINFINITY);
327
  u32 m2 = ea_get_int(attrs, EA_OSPF_METRIC2, 10000);
328
  u32 tag = ea_get_int(attrs, EA_OSPF_TAG, 0);
329
  int inas=0;
330

    
331
  ext=mb_alloc(p->pool,sizeof(struct ospf_lsa_ext)+
332
    sizeof(struct ospf_lsa_ext_tos));
333
  ext->netmask=ipa_mkmask(n->n.pxlen);
334

    
335
  et=(struct ospf_lsa_ext_tos *)(ext+1);
336

    
337
  if(m1!=LSINFINITY)
338
  {
339
    et->etos=0;
340
    et->metric=m1;
341
  }
342
  else
343
  {
344
    et->etos=0x80;
345
    et->metric=m2;
346
  }
347
  et->padding=0;
348
  et->tag=tag;
349
  if(ipa_compare(e->attrs->gw,ipa_from_u32(0))!=0)
350
  {
351
    if(find_iface((struct proto_ospf *)p, e->attrs->iface)!=NULL) inas=1;
352
  }
353
    
354
  if(!inas) et->fwaddr= ipa_from_u32(0);
355
  else et->fwaddr=e->attrs->gw;
356
  return ext;
357
}
358

    
359
/**
360
 * max_ext_lsa - calculate the maximum amount of external networks
361
 * possible for the given prefix length.
362
 * @pxlen: network prefix length
363
 *
364
 * This is a fix for the previous static use of MAXNETS which did
365
 * only work correct if MAXNETS < possible IPs for given prefix.
366
 * This solution is kind of a hack as there can now only be one
367
 * route for /32 type entries but this is better than the crashes
368
 * I did experience whith close together /32 routes originating
369
 * on different hosts.
370
 */
371

    
372
int
373
max_ext_lsa(unsigned pxlen)
374
{
375
  int i;
376
  for(i=1;pxlen<BITS_PER_IP_ADDRESS;pxlen++,i<<=1)
377
    if(i>=MAXNETS)
378
      return MAXNETS;
379
  return i;
380
}
381

    
382
/**
383
 * originate_ext_lsa - new route received from nest and filters
384
 * @n: network prefix and mask
385
 * @e: rte
386
 * @po: current instance of OSPF
387
 * @attrs: list of extended attributes
388
 *
389
 * If I receive a message that new route is installed, I try to originate an
390
 * external LSA. The LSA header of such LSA does not contain information about
391
 * prefix length, so if I have to originate multiple LSAs for route with
392
 * different prefixes I try to increment prefix id to find a "free" one.
393
 *
394
 * The function also sets flag ebit. If it's the first time, the new router lsa
395
 * origination is necessary.
396
 */
397
void
398
originate_ext_lsa(net *n, rte *e, struct proto_ospf *po, struct ea_list *attrs)
399
{
400
  struct ospf_lsa_header lsa;
401
  u32 rtid=po->proto.cf->global->router_id;
402
  struct top_hash_entry *en=NULL;
403
  void *body=NULL;
404
  struct proto *p=&po->proto;
405
  struct ospf_area *oa;
406
  struct ospf_lsa_ext *ext1,*ext2;
407
  int i;
408
  int max;
409

    
410
  OSPF_TRACE(D_EVENTS, "Originating Ext lsa for %I/%d.", n->n.prefix,
411
    n->n.pxlen);
412

    
413
  lsa.age=0;
414
  lsa.id=ipa_to_u32(n->n.prefix);
415
  lsa.type=LSA_T_EXT;
416
  lsa.rt=rtid;
417
  lsa.sn=LSA_INITSEQNO;
418
  body=originate_ext_lsa_body(n, e, po, attrs);
419
  lsa.length=sizeof(struct ospf_lsa_ext)+sizeof(struct ospf_lsa_ext_tos)+
420
    sizeof(struct ospf_lsa_header);
421
  ext1=body;
422
  max=max_ext_lsa(n->n.pxlen);
423

    
424
  oa=HEAD(po->area_list);
425

    
426
  for(i=0;i<max;i++)
427
  {
428
    if((en=ospf_hash_find_header(oa->gr, &lsa))!=NULL)
429
    {
430
      ext2=en->lsa_body;
431
      if(ipa_compare(ext1->netmask,ext2->netmask)!=0) lsa.id++;
432
      else break;
433
    }
434
    else break;
435
  }
436

    
437
  if(i==max)
438
  {
439
    log("%s: got more routes for one /%d network then %d, ignoring",p->name,
440
      n->n.pxlen,max);
441
    mb_free(body);
442
    return;
443
  }
444
  lsasum_calculate(&lsa,body,po);
445
  WALK_LIST(oa, po->area_list)
446
  {
447
    en=lsa_install_new(&lsa, body, oa);
448
    flood_lsa(NULL,NULL,&en->lsa,po,NULL,oa,1);
449
    body=originate_ext_lsa_body(n, e, po, attrs);
450
  }
451
  mb_free(body);
452

    
453
  if(po->ebit==0)
454
  {
455
    po->ebit=1;
456
    WALK_LIST(oa, po->area_list)
457
    {
458
      schedule_rt_lsa(oa);
459
    }
460
  }
461
}
462

    
463

    
464
static void
465
ospf_top_ht_alloc(struct top_graph *f)
466
{
467
  f->hash_size = 1 << f->hash_order;
468
  f->hash_mask = f->hash_size - 1;
469
  if (f->hash_order > HASH_HI_MAX - HASH_HI_STEP)
470
    f->hash_entries_max = ~0;
471
  else
472
    f->hash_entries_max = f->hash_size HASH_HI_MARK;
473
  if (f->hash_order < HASH_LO_MIN + HASH_LO_STEP)
474
    f->hash_entries_min = 0;
475
  else
476
    f->hash_entries_min = f->hash_size HASH_LO_MARK;
477
  DBG("Allocating OSPF hash of order %d: %d hash_entries, %d low, %d high\n",
478
      f->hash_order, f->hash_size, f->hash_entries_min, f->hash_entries_max);
479
  f->hash_table = mb_alloc(f->pool, f->hash_size * sizeof(struct top_hash_entry *));
480
  bzero(f->hash_table, f->hash_size * sizeof(struct top_hash_entry *));
481
}
482

    
483
static inline void
484
ospf_top_ht_free(struct top_hash_entry **h)
485
{
486
  mb_free(h);
487
}
488

    
489
static inline u32
490
ospf_top_hash_u32(u32 a)
491
{
492
  /* Shamelessly stolen from IP address hashing in ipv4.h */
493
  a ^= a >> 16;
494
  a ^= a << 10;
495
  return a;
496
}
497

    
498
static inline unsigned
499
ospf_top_hash(struct top_graph *f, u32 lsaid, u32 rtrid, u32 type)
500
{
501
#if 1        /* Dirty patch to make rt table calculation work. */
502
return (ospf_top_hash_u32(lsaid) + ospf_top_hash_u32((type==LSA_T_NET) ? lsaid : rtrid) + type) & f->hash_mask;
503
#else
504
  return (ospf_top_hash_u32(lsaid) + ospf_top_hash_u32(rtrid) + type) & f->hash_mask;
505
#endif
506
}
507

    
508
/**
509
 * ospf_top_new - allocated new topology database
510
 * @p: current instance of OSPF
511
 *
512
 * This dynamically hashed structure is often used for keeping LSAs. Mainly
513
 * its used in @ospf_area structure.
514
 */
515
struct top_graph *
516
ospf_top_new(pool *pool, struct proto_ospf *p)
517
{
518
  struct top_graph *f;
519

    
520
  f = mb_allocz(pool, sizeof(struct top_graph));
521
  f->pool = pool;
522
  f->hash_slab = sl_new(f->pool, sizeof(struct top_hash_entry));
523
  f->hash_order = HASH_DEF_ORDER;
524
  ospf_top_ht_alloc(f);
525
  f->hash_entries = 0;
526
  f->hash_entries_min = 0;
527
  return f;
528
}
529

    
530
void
531
ospf_top_free(struct top_graph *f)
532
{
533
  rfree(f->hash_slab);
534
  ospf_top_ht_free(f->hash_table);
535
  mb_free(f);
536
}
537

    
538
static void
539
ospf_top_rehash(struct top_graph *f, int step)
540
{
541
  unsigned int oldn, oldh;
542
  struct top_hash_entry **n, **oldt, **newt, *e, *x;
543

    
544
  oldn = f->hash_size;
545
  oldt = f->hash_table;
546
  DBG("Re-hashing topology hash from order %d to %d\n", f->hash_order, f->hash_order+step);
547
  f->hash_order += step;
548
  ospf_top_ht_alloc(f);
549
  newt = f->hash_table;
550

    
551
  for(oldh=0; oldh < oldn; oldh++)
552
    {
553
      e = oldt[oldh];
554
      while (e)
555
        {
556
          x = e->next;
557
          n = newt + ospf_top_hash(f, e->lsa.id, e->lsa.rt, e->lsa.type);
558
          e->next = *n;
559
          *n = e;
560
          e = x;
561
        }
562
    }
563
  ospf_top_ht_free(oldt);
564
}
565

    
566
struct top_hash_entry *
567
ospf_hash_find_header(struct top_graph *f, struct ospf_lsa_header *h)
568
{
569
  return ospf_hash_find(f,h->id,h->rt,h->type);
570
}
571

    
572
struct top_hash_entry *
573
ospf_hash_get_header(struct top_graph *f, struct ospf_lsa_header *h)
574
{
575
  return ospf_hash_get(f,h->id,h->rt,h->type);
576
}
577

    
578
struct top_hash_entry *
579
ospf_hash_find(struct top_graph *f, u32 lsa, u32 rtr, u32 type)
580
{
581
  struct top_hash_entry *e = f->hash_table[ospf_top_hash(f, lsa, rtr, type)];
582

    
583
#if 1        /* Dirty patch to make rt table calculation work. */
584
  if(type==LSA_T_NET)
585
  {
586
    while (e && (e->lsa.id != lsa || e->lsa.type != LSA_T_NET ))
587
       e = e->next;
588
  }
589
  else
590
  {
591
     while (e && (e->lsa.id != lsa || e->lsa.type != type || e->lsa.rt != rtr))
592
       e = e->next;
593
  }
594
#else
595
  while (e && (e->lsa.id != lsa || e->lsa.rt != rtr || e->lsa.type != type))
596
    e = e->next;
597
#endif
598
  return e;
599
}
600

    
601
struct top_hash_entry *
602
ospf_hash_get(struct top_graph *f, u32 lsa, u32 rtr, u32 type)
603
{
604
  struct top_hash_entry **ee = f->hash_table + ospf_top_hash(f, lsa, rtr, type);
605
  struct top_hash_entry *e = *ee;
606

    
607
  while (e && (e->lsa.id != lsa || e->lsa.rt != rtr || e->lsa.type != type))
608
    e = e->next;
609
  if (e)
610
    return e;
611
  e = sl_alloc(f->hash_slab);
612
  e->lsa.id = lsa;
613
  e->lsa.rt = rtr;
614
  e->lsa.type = type;
615
  e->lsa_body = NULL;
616
  e->nhi=NULL;
617
  e->next=*ee;                /* MJ you forgot this :-) */
618
  *ee=e;
619
  if (f->hash_entries++ > f->hash_entries_max)
620
    ospf_top_rehash(f, HASH_HI_STEP);
621
  return e;
622
}
623

    
624
void
625
ospf_hash_delete(struct top_graph *f, struct top_hash_entry *e)
626
{
627
  unsigned int h = ospf_top_hash(f, e->lsa.id, e->lsa.rt, e->lsa.type);
628
  struct top_hash_entry **ee = f->hash_table + h;
629

    
630
  while (*ee)
631
    {
632
      if (*ee == e)
633
        {
634
          *ee = e->next;
635
          sl_free(f->hash_slab, e);
636
          if (f->hash_entries-- < f->hash_entries_min)
637
            ospf_top_rehash(f, -HASH_LO_STEP);
638
          return;
639
        }
640
      ee = &((*ee)->next);
641
    }
642
  bug("ospf_hash_delete() called for invalid node");
643
}
644

    
645
void
646
ospf_top_dump(struct top_graph *f, struct proto *p)
647
{
648
  unsigned int i;
649
  OSPF_TRACE(D_EVENTS, "Hash entries: %d", f->hash_entries);
650

    
651
  for(i=0; i<f->hash_size; i++)
652
    {
653
      struct top_hash_entry *e = f->hash_table[i];
654
      while (e)
655
        {
656
          OSPF_TRACE(D_EVENTS, "\t%1x %-1I %-1I %4u 0x%08x",
657
            e->lsa.type, e->lsa.id,
658
            e->lsa.rt, e->lsa.age, e->lsa.sn);
659
          e = e->next;
660
        }
661
    }
662
}
663

    
664
/* This is very inefficient, please don't call it often */
665

    
666
/* I should also test for every LSA if it's in some link state
667
 * retransmission list for every neighbor. I will not test it.
668
 * It could happen that I'll receive some strange ls ack's.
669
 */
670

    
671
int
672
can_flush_lsa(struct ospf_area *oa)
673
{
674
  struct ospf_iface *ifa;
675
  struct ospf_neighbor *n;
676
  struct proto_ospf *po=oa->po;
677

    
678
  WALK_LIST(ifa, iface_list)
679
  {
680
    if(ifa->oa==oa)
681
    {
682
      WALK_LIST(n, ifa->neigh_list)
683
      {
684
        if((n->state==NEIGHBOR_EXCHANGE)||(n->state==NEIGHBOR_LOADING))
685
        {
686
          return 0;
687
        }
688
      }
689
    }
690
  }
691

    
692
  return 1;
693
}