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

#include "ospf.h"

11 12 13
/**
 * flood_lsa - send received or generated lsa to the neighbors
 * @n: neighbor than sent this lsa (or NULL if generated)
Ondřej Filip's avatar
Ondřej Filip committed
14 15
 * @hn: LSA header followed by lsa body in network endianity (may be NULL) 
 * @hh: LSA header in host endianity (must be filled)
16 17 18 19 20
 * @po: actual instance of OSPF protocol
 * @iff: interface which received this LSA (or NULL if LSA is generated)
 * @oa: ospf_area which is the LSA generated for
 * @rtl: add this LSA into retransmission list
 *
Ondřej Filip's avatar
Ondřej Filip committed
21
 * return value - was the LSA flooded back?
22 23
 */

24
int
Ondřej Filip's avatar
Ondřej Filip committed
25
flood_lsa(struct ospf_neighbor *n, struct ospf_lsa_header *hn,
26
  struct ospf_lsa_header *hh, struct proto_ospf *po, struct ospf_iface *iff,
27
  struct ospf_area *oa, int rtl)
Ondřej Filip's avatar
Ondřej Filip committed
28 29 30 31
{
  struct ospf_iface *ifa;
  struct ospf_neighbor *nn;
  struct top_hash_entry *en;
32
  struct proto *p=&po->proto;
Ondřej Filip's avatar
Ondřej Filip committed
33
  int ret, retval = 0;
Ondřej Filip's avatar
Ondřej Filip committed
34 35 36 37

  /* pg 148 */
  WALK_LIST(NODE ifa,po->iface_list)
  {
38 39
    if(ifa->stub) continue;

Ondřej Filip's avatar
Ondřej Filip committed
40 41 42 43 44 45 46
    if(hh->type==LSA_T_EXT)
    {
      if(ifa->type==OSPF_IT_VLINK) continue;
      if(ifa->oa->stub) continue;
    }
    else
    {
47
      if(oa->areaid==BACKBONE)
Ondřej Filip's avatar
Ondřej Filip committed
48
      {
49
        if((ifa->type!=OSPF_IT_VLINK)&&(ifa->oa!=oa)) continue;
Ondřej Filip's avatar
Ondřej Filip committed
50 51 52
      }
      else
      {
53
        if(ifa->oa!=oa) continue;
Ondřej Filip's avatar
Ondřej Filip committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
      }
    }
    ret=0;
    WALK_LIST(NODE nn, ifa->neigh_list)
    {
      if(nn->state<NEIGHBOR_EXCHANGE) continue;
      if(nn->state<NEIGHBOR_FULL)
      {
        if((en=ospf_hash_find_header(nn->lsrqh,hh))!=NULL)
	{
	  switch(lsa_comp(hh,&en->lsa))
	  {
            case CMP_OLDER:
              continue;
	      break;
	    case CMP_SAME:
              s_rem_node(SNODE en);
71 72
              if(en->lsa_body!=NULL) mb_free(en->lsa_body);
              en->lsa_body=NULL;
Ondřej Filip's avatar
Ondřej Filip committed
73
	      DBG("Removing from lsreq list for neigh %I\n", nn->rid);
Ondřej Filip's avatar
Ondřej Filip committed
74 75 76 77 78 79
	      ospf_hash_delete(nn->lsrqh,en);
	      if(EMPTY_SLIST(nn->lsrql)) ospf_neigh_sm(nn, INM_LOADDONE);
	      continue;
	      break;
	    case CMP_NEWER:
              s_rem_node(SNODE en);
80 81
              if(en->lsa_body!=NULL) mb_free(en->lsa_body);
              en->lsa_body=NULL;
Ondřej Filip's avatar
Ondřej Filip committed
82
	      DBG("Removing from lsreq list for neigh %I\n", nn->rid);
Ondřej Filip's avatar
Ondřej Filip committed
83 84 85
	      ospf_hash_delete(nn->lsrqh,en);
	      if(EMPTY_SLIST(nn->lsrql)) ospf_neigh_sm(nn, INM_LOADDONE);
	      break;
86
	    default: bug("Bug in lsa_comp?");
Ondřej Filip's avatar
Ondřej Filip committed
87 88 89
	  }
	}
      }
90

Ondřej Filip's avatar
Ondřej Filip committed
91
      if(nn==n) continue;
92 93

      if(rtl)
94
      {
95 96 97 98 99 100 101 102 103 104 105 106
        if((en=ospf_hash_find_header(nn->lsrth, hh))==NULL)
        {
          en=ospf_hash_get_header(nn->lsrth, hh);
        }
        else
        {
          s_rem_node(SNODE en);
        }
        s_add_tail(&nn->lsrtl, SNODE en);
        memcpy(&en->lsa,hh,sizeof(struct ospf_lsa_header));
        DBG("Adding LSA lsrt RT: %I, Id: %I, Type: %u for n: %I\n",
          en->lsa.rt,en->lsa.id, en->lsa.type, nn->ip);
107 108 109
      }
      else
      {
110 111 112
        if((en=ospf_hash_find_header(nn->lsrth, hh))!=NULL)
        {
          s_rem_node(SNODE en);
113 114
          if(en->lsa_body!=NULL) mb_free(en->lsa_body);
          en->lsa_body=NULL;
115 116
          ospf_hash_delete(nn->lsrth, en);
        }
117
      }
118

Ondřej Filip's avatar
Ondřej Filip committed
119
      ret=1;
Ondřej Filip's avatar
Ondřej Filip committed
120
    }
121

122
    if(ret==0) continue;	/* pg 150 (2) */
123

Ondřej Filip's avatar
Ondřej Filip committed
124 125
    if(ifa==iff)
    {
126 127
      if((n->rid==iff->drid)||n->rid==iff->bdrid) continue;	/* pg 150 (3) */
      if(iff->state==OSPF_IS_BACKUP) continue;			/* pg 150 (4) */
Ondřej Filip's avatar
Ondřej Filip committed
128
      retval = 1;		/* FIXME !!!!!!!!!!! */
Ondřej Filip's avatar
Ondřej Filip committed
129
    }
130

Ondřej Filip's avatar
Ondřej Filip committed
131 132 133
    {
      sock *sk;
      ip_addr to;
Ondřej Filip's avatar
Ondřej Filip committed
134
      u16 len, age;
Ondřej Filip's avatar
Ondřej Filip committed
135 136
      struct ospf_lsupd_packet *pk;
      struct ospf_packet *op;
Ondřej Filip's avatar
Ondřej Filip committed
137
      struct ospf_lsa_header *lh;
Ondřej Filip's avatar
Ondřej Filip committed
138

139 140
      if(ifa->type==OSPF_IT_NBMA)  sk=ifa->ip_sk;
      else sk=ifa->hello_sk;	/* FIXME is this true for PTP? */
Ondřej Filip's avatar
Ondřej Filip committed
141 142 143 144

      pk=(struct ospf_lsupd_packet *)sk->tbuf;
      op=(struct ospf_packet *)sk->tbuf;

Ondřej Filip's avatar
Ondřej Filip committed
145
      fill_ospf_pkt_hdr(ifa, pk, LSUPD_P);
Ondřej Filip's avatar
Ondřej Filip committed
146
      pk->lsano=htonl(1);
147

Ondřej Filip's avatar
Ondřej Filip committed
148 149 150
      lh = (struct ospf_lsa_header *)(pk+1);

      /* Copy LSA into the packet */
151
      if(hn)
152
      {
Ondřej Filip's avatar
Ondřej Filip committed
153
        memcpy(lh, hn, ntohs(hn->length));
154 155 156 157 158
      }
      else
      {
        u8 *help;
	struct top_hash_entry *en;
159 160

        htonlsah(hh,lh);
Ondřej Filip's avatar
Ondřej Filip committed
161 162
	help = (u8 *)(lh+1);
	en = ospf_hash_find_header(oa->gr,hh);
163 164
	htonlsab(en->lsa_body,help,hh->type,hh->length
          -sizeof(struct ospf_lsa_header));
165
      }
166

Ondřej Filip's avatar
Ondřej Filip committed
167 168 169 170 171 172 173
      len = sizeof(struct ospf_lsupd_packet)+ntohs(lh->length);

      age = ntohs(lh->age);
      age += ifa->inftransdelay;
      if( age > LSA_MAXAGE ) age = LSA_MAXAGE;
      lh->age = htons(age);

Ondřej Filip's avatar
Ondřej Filip committed
174 175
      op->length=htons(len);
      ospf_pkt_finalize(ifa, op);
Ondřej Filip's avatar
Ondřej Filip committed
176
      OSPF_TRACE(D_PACKETS, "LS upd flooded via %s", ifa->iface->name);
Ondřej Filip's avatar
Ondřej Filip committed
177 178 179

      if(ifa->type==OSPF_IT_NBMA)
      {
180 181 182
        if((ifa->state==OSPF_IS_BACKUP)||(ifa->state==OSPF_IS_DR))
          sk_send_to_agt(sk ,len, ifa, NEIGHBOR_EXCHANGE);
	else  sk_send_to_bdr(sk ,len, ifa);
Ondřej Filip's avatar
Ondřej Filip committed
183 184 185
      }
      else
      {
186 187
        if((ifa->state==OSPF_IS_BACKUP)||(ifa->state==OSPF_IS_DR)||
	  (ifa->type==OSPF_IT_PTP))
Ondřej Filip's avatar
Ondřej Filip committed
188 189 190 191 192
          sk_send_to(sk,len, AllSPFRouters, OSPF_PROTO);
	else sk_send_to(sk,len, AllDRouters, OSPF_PROTO);
      }
    }
  }
193
  return retval;
Ondřej Filip's avatar
Ondřej Filip committed
194 195
}

196 197 198 199 200 201 202 203 204
void		/* I send all I received in LSREQ */
ospf_lsupd_tx_list(struct ospf_neighbor *n, list *l)
{
  struct l_lsr_head *llsh;
  u16 len;
  u32 lsano;
  struct top_hash_entry *en;
  struct ospf_lsupd_packet *pk;
  struct ospf_packet *op;
205
  struct proto *p=&n->ifa->oa->po->proto;
206
  void *pktpos;
207 208
  u8 ii;
  u8 *jj=n->ifa->ip_sk->tbuf;
209

Ondřej Filip's avatar
Ondřej Filip committed
210
  if(EMPTY_LIST(*l)) return;
211 212 213

  pk=(struct ospf_lsupd_packet *)n->ifa->ip_sk->tbuf;
  op=(struct ospf_packet *)n->ifa->ip_sk->tbuf;
214 215

  DBG("LSupd: 1st packet\n");
216
       
Ondřej Filip's avatar
Ondřej Filip committed
217
  fill_ospf_pkt_hdr(n->ifa, pk, LSUPD_P);
218 219 220 221 222 223
  len=SIPH+sizeof(struct ospf_lsupd_packet);
  lsano=0;
  pktpos=(pk+1);

  WALK_LIST(llsh, *l)
  {
Ondřej Filip's avatar
Ondřej Filip committed
224 225 226
    if((en=ospf_hash_find(n->ifa->oa->gr,llsh->lsh.id,llsh->lsh.rt,
      llsh->lsh.type))==NULL) continue;		/* Probably flushed LSA */

227 228
    DBG("Sending ID=%I, Type=%u, RT=%I Sn: 0x%x Age: %u\n",
      llsh->lsh.id, llsh->lsh.type, llsh->lsh.rt, en->lsa.sn, en->lsa.age);
Ondřej Filip's avatar
Ondřej Filip committed
229
    if(((u32)(len+en->lsa.length))>n->ifa->iface->mtu)
230 231
    {
      pk->lsano=htonl(lsano);
232
      op->length=htons(len-SIPH);
233
      ospf_pkt_finalize(n->ifa, op);
234
		       
235
      sk_send_to(n->ifa->ip_sk,len-SIPH, n->ip, OSPF_PROTO);
Ondřej Filip's avatar
Ondřej Filip committed
236
      OSPF_TRACE(D_PACKETS, "LS upd sent to %I (%d LSAs)", n->ip, lsano);
237

238
      DBG("LSupd: next packet\n");
Ondřej Filip's avatar
Ondřej Filip committed
239
      fill_ospf_pkt_hdr(n->ifa, pk, LSUPD_P);
240 241 242 243 244 245
      len=SIPH+sizeof(struct ospf_lsupd_packet);
      lsano=0;
      pktpos=(pk+1);
    }
    htonlsah(&(en->lsa), pktpos);
    pktpos=pktpos+sizeof(struct ospf_lsa_header);
246 247
    htonlsab(en->lsa_body, pktpos, en->lsa.type, en->lsa.length
      -sizeof(struct ospf_lsa_header));
248
    pktpos=pktpos+en->lsa.length-sizeof(struct ospf_lsa_header);
249
    len+=en->lsa.length;
250
    lsano++;
251
  }
252 253 254 255 256
  if(lsano>0)
  {
    pk->lsano=htonl(lsano);
    op->length=htons(len-SIPH);
    ospf_pkt_finalize(n->ifa, op);
257

Ondřej Filip's avatar
Ondřej Filip committed
258
    OSPF_TRACE(D_PACKETS, "LS upd sent to %I (%d LSAs)", n->ip, lsano);
259 260
    sk_send_to(n->ifa->ip_sk,len-SIPH, n->ip, OSPF_PROTO);
  }
261 262
}

263
void
Ondřej Filip's avatar
Ondřej Filip committed
264
ospf_lsupd_receive(struct ospf_lsupd_packet *ps,
265 266
  struct ospf_iface *ifa, u16 size)
{
Ondřej Filip's avatar
Ondřej Filip committed
267
  u32 area,nrid;
268
  struct ospf_neighbor *n,*ntmp;
269
  struct ospf_lsa_header *lsa;
270
  struct ospf_area *oa;
Ondřej Filip's avatar
Ondřej Filip committed
271 272
  struct proto_ospf *po=ifa->proto;
  struct proto *p = (struct proto *)po;
273
  u16 length;
274
  u8 i;
Ondřej Filip's avatar
Ondřej Filip committed
275
  int sendreq = 1;
276 277 278 279 280

  nrid=ntohl(ps->ospf_packet.routerid);

  if((n=find_neigh(ifa, nrid))==NULL)
  {
281
    OSPF_TRACE(D_PACKETS, "Received lsupd from unknown neighbor! (%I)",
282 283 284
      nrid);
    return ;
  }
285

286 287
  if(n->state<NEIGHBOR_EXCHANGE)
  {
288
    OSPF_TRACE(D_PACKETS, "Received lsupd in lesser state than EXCHANGE from (%I)",
Ondřej Filip's avatar
Ondřej Filip committed
289
      n->ip);
290 291
    return;
  }
292

293 294
  if(size<=(sizeof(struct ospf_lsupd_packet)+sizeof(struct ospf_lsa_header)))
  {
295
    log(L_WARN "Received lsupd from %I is too short!", n->ip);
296 297
    return;
  }
298

Ondřej Filip's avatar
Ondřej Filip committed
299
  OSPF_TRACE(D_PACKETS, "Received LS upd from %I", n->ip);
300
  ospf_neigh_sm(n, INM_HELLOREC);	/* Questionable */
301

302 303
  lsa=(struct ospf_lsa_header *)(ps+1);
  area=htonl(ps->ospf_packet.areaid);
304
  oa=ospf_find_area((struct proto_ospf *)p,area);
305 306

  for(i=0; i<ntohl(ps->lsano); i++,
307
    lsa=(struct ospf_lsa_header *)(((u8 *)lsa)+ntohs(lsa->length)))
308
  {
Ondřej Filip's avatar
Ondřej Filip committed
309 310
    struct ospf_lsa_header lsatmp;
    struct top_hash_entry *lsadb;
311
    int diff=((u8 *)lsa)-((u8 *)ps);
312
    u16 chsum, lenn = ntohs(lsa->length);
313

314 315 316 317 318 319
    if(((diff+sizeof(struct ospf_lsa_header))>=size) || ((lenn+diff)>size))
    {
      log(L_WARN "Received lsupd from %I is too short!", n->ip);
      ospf_neigh_sm(n, INM_BADLSREQ);
      break;
    }
320 321 322

    if((lenn<=sizeof(struct ospf_lsa_header))||(lenn!=(4*(lenn/4))))
    {
323 324
      log(L_WARN "Received LSA from %I with bad length", n->ip);
      ospf_neigh_sm(n, INM_BADLSREQ);
325 326
      break;
    }
327

Ondřej Filip's avatar
Ondřej Filip committed
328
    /* pg 143 (1) */
Ondřej Filip's avatar
Ondřej Filip committed
329 330
    chsum=lsa->checksum;
    if(chsum!=lsasum_check(lsa,NULL,po))
331
    {
332
      log(L_WARN "Received bad lsa checksum from %I", n->ip);
333 334
      continue;
    }
335

Ondřej Filip's avatar
Ondřej Filip committed
336
    /* pg 143 (2) */
337 338
    if((lsa->type<LSA_T_RT)||(lsa->type>LSA_T_EXT))
    {
339
      log(L_WARN "Unknown LSA type from %I", n->ip);
340
      continue;
341
    }
342

Ondřej Filip's avatar
Ondřej Filip committed
343
    /* pg 143 (3) */
344 345
    if((lsa->type==LSA_T_EXT)&&oa->stub)
    {
346
      log(L_WARN "Received External LSA in stub area from %I", n->ip);
347 348
      continue;
    }
349

Ondřej Filip's avatar
Ondřej Filip committed
350
    ntohlsah(lsa,&lsatmp);
351

352
    DBG("Update Type: %u ID: %I RT: %I, Sn: 0x%08x Age: %u, Sum: %u\n",
Ondřej Filip's avatar
Ondřej Filip committed
353 354
      lsatmp.type, lsatmp.id, lsatmp.rt, lsatmp.sn, lsatmp.age,
      lsatmp.checksum);
355

Ondřej Filip's avatar
Ondřej Filip committed
356
    lsadb=ospf_hash_find_header(oa->gr, &lsatmp);
357 358

#ifdef LOCAL_DEBUG
Ondřej Filip's avatar
Ondřej Filip committed
359
    if(lsadb)
360
      DBG("I have Type: %u ID: %I RT: %I, Sn: 0x%08x Age: %u, Sum: %u\n",
Ondřej Filip's avatar
Ondřej Filip committed
361 362
      lsadb->lsa.type, lsadb->lsa.id, lsadb->lsa.rt, lsadb->lsa.sn,
      lsadb->lsa.age, lsadb->lsa.checksum);
363
#endif
364

Ondřej Filip's avatar
Ondřej Filip committed
365
    /* pg 143 (4) */
366
    if((lsatmp.age==LSA_MAXAGE)&&(lsadb==NULL)&&can_flush_lsa(oa))
Ondřej Filip's avatar
Ondřej Filip committed
367
    {
368
      ospf_lsack_enqueue(n, lsa, ACKL_DIRECT);
369
      continue;
Ondřej Filip's avatar
Ondřej Filip committed
370
    }
371

Ondřej Filip's avatar
Ondřej Filip committed
372
    /* pg 144 (5) */
Ondřej Filip's avatar
Ondřej Filip committed
373 374
    if((lsadb==NULL)||(lsa_comp(&lsatmp,&lsadb->lsa)==CMP_NEWER))
    {
375 376 377 378 379 380 381
      struct ospf_iface *ift=NULL;
      void *body;
      struct ospf_iface *nifa;
      int self = (lsatmp.rt == p->cf->global->router_id);

      DBG("PG143(5): Received LSA is newer\n");

Ondřej Filip's avatar
Ondřej Filip committed
382 383
      /* pg 145 (5f) - premature aging of self originated lsa */
      if((!self) && (lsatmp.type==LSA_T_NET))
384 385 386 387 388
      {
        WALK_LIST(nifa,po->iface_list)
        {
          if(ipa_compare(nifa->iface->addr->ip,ipa_from_u32(lsatmp.id))==0)
          {
Ondřej Filip's avatar
Ondřej Filip committed
389
            self = 1;
390 391 392 393 394 395 396 397 398 399 400
            break;
          }
        }
      }

      if(self)
      {
        struct top_hash_entry *en;

        if((lsatmp.age==LSA_MAXAGE)&&(lsatmp.sn==LSA_MAXSEQNO))
        {
401
          ospf_lsack_enqueue(n, lsa, ACKL_DIRECT);
402 403 404 405 406 407 408 409 410 411
          continue;
        }

        lsatmp.age=LSA_MAXAGE;
        lsatmp.sn=LSA_MAXSEQNO;
        lsa->age=htons(LSA_MAXAGE);
        lsa->sn=htonl(LSA_MAXSEQNO);
        OSPF_TRACE(D_EVENTS, "Premature aging self originated lsa.");
        OSPF_TRACE(D_EVENTS, "Type: %d, Id: %I, Rt: %I",lsatmp.type,
          lsatmp.id, lsatmp.rt);
Ondřej Filip's avatar
Ondřej Filip committed
412
        lsasum_check(lsa,(lsa+1),po);	/* It also calculates chsum! */
413 414 415 416 417 418 419 420
        lsatmp.checksum=ntohs(lsa->checksum);
        flood_lsa(NULL,lsa,&lsatmp,po,NULL,oa,0);
        if(en=ospf_hash_find_header(oa->gr,&lsatmp))
        {
          flood_lsa(NULL,NULL,&en->lsa,po,NULL,oa,1);
        }
        continue;
      }
421

Ondřej Filip's avatar
Ondřej Filip committed
422
      /* pg 144 (5a) */
Ondřej Filip's avatar
Ondřej Filip committed
423
      if(lsadb && ((now-lsadb->inst_t)<=MINLSARRIVAL))	/* FIXME: test for flooding? */
424 425
      {
        DBG("I got it in less that MINLSARRIVAL\n");
Ondřej Filip's avatar
Ondřej Filip committed
426
        sendreq = 0;
427 428
	continue;
      }
429
        
430
      if(flood_lsa(n,lsa,&lsatmp,po,ifa,ifa->oa,1)==0)
431
      {
Ondřej Filip's avatar
Ondřej Filip committed
432
        DBG("Wasn't flooded back\n");	/* ps 144(5e), pg 153 */
433 434
        if(ifa->state==OSPF_IS_BACKUP)
	{
435
	  if(ifa->drid==n->rid) ospf_lsack_enqueue(n, lsa, ACKL_DELAY);
436
	}
437
	else ospf_lsack_enqueue(n, lsa, ACKL_DELAY);
438
      }
Ondřej Filip's avatar
Ondřej Filip committed
439

Ondřej Filip's avatar
Ondřej Filip committed
440
      /* Remove old from all ret lists */
Ondřej Filip's avatar
Ondřej Filip committed
441
      /* pg 144 (5c) */
442 443 444 445 446 447 448 449 450 451 452 453 454 455
      if(lsadb)
        WALK_LIST(NODE ift,po->iface_list)
          WALK_LIST(NODE ntmp,ift->neigh_list)
          {
            struct top_hash_entry *en;
            if(ntmp->state>NEIGHBOR_EXSTART)
              if((en=ospf_hash_find_header(ntmp->lsrth,&lsadb->lsa))!=NULL)
              {
                s_rem_node(SNODE en);
                if(en->lsa_body!=NULL) mb_free(en->lsa_body);
                en->lsa_body=NULL;
                ospf_hash_delete(ntmp->lsrth,en);
              }
          }
456 457 458 459 460

      if((lsatmp.age==LSA_MAXAGE)&&(lsatmp.sn==LSA_MAXSEQNO)
        &&lsadb&&can_flush_lsa(oa))
      {
        flush_lsa(lsadb,oa);
461
        schedule_rtcalc(oa);
462
        continue;
Ondřej Filip's avatar
Ondřej Filip committed
463
      }		/* FIXME lsack? */
Ondřej Filip's avatar
Ondřej Filip committed
464

Ondřej Filip's avatar
Ondřej Filip committed
465
      /* pg 144 (5d) */
466
      body=mb_alloc(p->pool,lsatmp.length-sizeof(struct ospf_lsa_header));
Ondřej Filip's avatar
Ondřej Filip committed
467 468
      ntohlsab(lsa+1,body,lsatmp.type,
        lsatmp.length-sizeof(struct ospf_lsa_header));
469
      lsadb=lsa_install_new(&lsatmp,body, oa);
470
      DBG("New LSA installed in DB\n");
471

Ondřej Filip's avatar
Ondřej Filip committed
472 473 474
      continue;
    }

Ondřej Filip's avatar
Ondřej Filip committed
475
    /* FIXME pg145 (6) */
Ondřej Filip's avatar
Ondřej Filip committed
476

Ondřej Filip's avatar
Ondřej Filip committed
477
    /* pg145 (7) */
Ondřej Filip's avatar
Ondřej Filip committed
478 479
    if(lsa_comp(&lsatmp,&lsadb->lsa)==CMP_SAME)
    {
480
      struct top_hash_entry *en;
Ondřej Filip's avatar
Ondřej Filip committed
481
      DBG("PG145(7) Got the same LSA\n");
482 483
      if((en=ospf_hash_find_header(n->lsrth,&lsadb->lsa))!=NULL)
      {
Ondřej Filip's avatar
Ondřej Filip committed
484
        /* pg145 (7a) */
485
        s_rem_node(SNODE en);
486 487
        if(en->lsa_body!=NULL) mb_free(en->lsa_body);
        en->lsa_body=NULL;
488 489 490
        ospf_hash_delete(n->lsrth, en);
        if(ifa->state==OSPF_IS_BACKUP)
        {
491
          if(n->rid==ifa->drid) ospf_lsack_enqueue(n, lsa, ACKL_DELAY);
492 493 494 495
        }
      }
      else
      {
Ondřej Filip's avatar
Ondřej Filip committed
496
        /* pg145 (7b) */
497
        ospf_lsack_enqueue(n, lsa, ACKL_DIRECT);
498
      }
Ondřej Filip's avatar
Ondřej Filip committed
499
      sendreq = 0;
500
      continue;
Ondřej Filip's avatar
Ondřej Filip committed
501 502
    }

Ondřej Filip's avatar
Ondřej Filip committed
503
    /* pg145 (8) */
504 505 506 507
    if((lsadb->lsa.age==LSA_MAXAGE)&&(lsadb->lsa.sn==LSA_MAXSEQNO))
    {
      continue;
    }
Ondřej Filip's avatar
Ondřej Filip committed
508

Ondřej Filip's avatar
Ondřej Filip committed
509 510
    {
      list l;
511
      struct l_lsr_head ll;
Ondřej Filip's avatar
Ondřej Filip committed
512
      init_list(&l);
513 514 515 516
      ll.lsh.id=lsadb->lsa.id;
      ll.lsh.rt=lsadb->lsa.rt;
      ll.lsh.type=lsadb->lsa.type;
      add_tail(&l, NODE &ll);
Ondřej Filip's avatar
Ondřej Filip committed
517 518
      ospf_lsupd_tx_list(n, &l);
    }
519
  }
520

521 522 523
  /* Send direct LSAs */
  ospf_lsack_send(n, ACKL_DIRECT);

Ondřej Filip's avatar
Ondřej Filip committed
524
  if(sendreq && (n->state==NEIGHBOR_LOADING))
Ondřej Filip's avatar
Ondřej Filip committed
525
  {
Ondřej Filip's avatar
Ondřej Filip committed
526
    ospf_lsreq_send(n);	/* Ask for another part of neighbor's database */
Ondřej Filip's avatar
Ondřej Filip committed
527
  }
528 529
}

530 531 532 533 534
void
net_flush_lsa(struct top_hash_entry *en, struct proto_ospf *po,
  struct ospf_area *oa)
{
  struct ospf_lsa_header *lsa=&en->lsa;
Ondřej Filip's avatar
Ondřej Filip committed
535
  struct proto *p=&po->proto;
536 537

  lsa->age=LSA_MAXAGE;
538 539
  lsa->sn=LSA_MAXSEQNO;
  lsasum_calculate(lsa,en->lsa_body,po);
Ondřej Filip's avatar
Ondřej Filip committed
540 541
  OSPF_TRACE(D_EVENTS, "Premature aging self originated lsa!");
  OSPF_TRACE(D_EVENTS, "Type: %d, Id: %I, Rt: %I", lsa->type,
Ondřej Filip's avatar
Ondřej Filip committed
542
    lsa->id, lsa->rt);
543
  flood_lsa(NULL,NULL,lsa,po,NULL,oa,0);
544 545
}