Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / lsupd.c @ 44724025

History | View | Annotate | Download (8.86 KB)

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

    
9
#include "ospf.h"
10

    
11
void
12
ospf_lsupd_tx(struct ospf_neighbor *n)
13
{
14
  /* FIXME Go on! */
15
}
16

    
17
void
18
flood_lsa(struct ospf_neighbor *n, struct ospf_lsa_header *hn,
19
  struct ospf_lsa_header *hh, struct proto_ospf *po, struct ospf_iface *iff,
20
  struct ospf_area *oa)
21
{
22
  struct ospf_iface *ifa;
23
  struct ospf_neighbor *nn;
24
  struct top_hash_entry *en;
25
  int ret;
26

    
27
  /* pg 148 */
28
  WALK_LIST(NODE ifa,po->iface_list)
29
  {
30
    if(hh->type==LSA_T_EXT)
31
    {
32
      if(ifa->type==OSPF_IT_VLINK) continue;
33
      if(ifa->oa->stub) continue;
34
    }
35
    else
36
    {
37
      if(oa->areaid==BACKBONE)
38
      {
39
        if((ifa->type!=OSPF_IT_VLINK)&&(ifa->oa!=oa)) continue;
40
      }
41
      else
42
      {
43
        if(ifa->oa!=oa) continue;
44
      }
45
    }
46
    ret=0;
47
    WALK_LIST(NODE nn, ifa->neigh_list)
48
    {
49
      if(nn->state<NEIGHBOR_EXCHANGE) continue;
50
      if(nn->state<NEIGHBOR_FULL)
51
      {
52

    
53
        if((en=ospf_hash_find_header(nn->lsrqh,hh))!=NULL)
54
        {
55
          switch(lsa_comp(hh,&en->lsa))
56
          {
57
            case CMP_OLDER:
58
              continue;
59
              break;
60
            case CMP_SAME:
61
              s_rem_node(SNODE en);
62
              DBG("Removing from lsreq list for neigh %I\n", nn->rid);
63
              ospf_hash_delete(nn->lsrqh,en);
64
              if(EMPTY_SLIST(nn->lsrql)) ospf_neigh_sm(nn, INM_LOADDONE);
65
              continue;
66
              break;
67
            case CMP_NEWER:
68
              s_rem_node(SNODE en);
69
              DBG("Removing from lsreq list for neigh %I\n", nn->rid);
70
              ospf_hash_delete(nn->lsrqh,en);
71
              if(EMPTY_SLIST(nn->lsrql)) ospf_neigh_sm(nn, INM_LOADDONE);
72
              break;
73
            default: bug("Bug in lsa_comp?\n");
74
          }
75
        }
76
      }
77
      if(nn==n) continue;
78
      en=ospf_hash_get_header(nn->lsrth, hh);
79
      s_add_tail(&nn->lsrtl, SNODE en);
80
      ret=1;
81
    }
82
    if(ret==0) continue;
83
    if(ifa==iff)
84
    {
85
      if((n->rid==iff->drid)||n->rid==iff->bdrid) continue;
86
      if(iff->state=OSPF_IS_BACKUP) continue;
87
    }
88
    /* FIXME directly flood */
89
    {
90
      sock *sk;
91
      ip_addr to;
92
      u16 len;
93
      struct ospf_lsupd_packet *pk;
94
      struct ospf_packet *op;
95

    
96
      if(ifa->type==OSPF_IT_NBMA)  sk=ifa->ip_sk;
97
      else sk=ifa->hello_sk;        /* FIXME is this true for PTP? */
98

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

    
102
      fill_ospf_pkt_hdr(ifa, pk, LSUPD);
103
      pk->lsano=htonl(1);
104
      if(hn!=NULL)
105
      {
106
        memcpy(pk+1,hn,ntohs(hn->length));
107
        len=sizeof(struct ospf_lsupd_packet)+ntohs(hn->length);
108
      }
109
      else
110
      {
111
        u8 *help;
112
        struct top_hash_entry *en;
113
        htonlsah(hh,(struct ospf_lsa_header *)(pk+1));
114
        help=(u8 *)(pk+1);
115
        help+=sizeof(struct ospf_lsa_header);
116
        en=ospf_hash_find_header(oa->gr,hh);
117
        htonlsab(en->lsa_body,help,hh->type,hh->length);
118
        len=hh->length;
119
      }
120
      op->length=htons(len);
121
      ospf_pkt_finalize(ifa, op);
122

    
123
      if(ifa->type==OSPF_IT_NBMA)
124
      {
125
        sk_send_to_agt(sk ,len, ifa, NEIGHBOR_EXCHANGE);
126
      }
127
      else
128
      {
129
        if((ifa->state==OSPF_IS_BACKUP)||(ifa->state==OSPF_IS_DR))
130
          sk_send_to(sk,len, AllSPFRouters, OSPF_PROTO);
131
        else sk_send_to(sk,len, AllDRouters, OSPF_PROTO);
132
      }
133
    }
134
  }
135
}
136

    
137
void                /* I send all I received in LSREQ */
138
ospf_lsupd_tx_list(struct ospf_neighbor *n, list *l)
139
{
140
  struct l_lsr_head *llsh;
141
  u16 len;
142
  u32 lsano;
143
  struct top_hash_entry *en;
144
  struct ospf_lsupd_packet *pk;
145
  struct ospf_packet *op;
146
  void *pktpos;
147
  u8 ii;
148
  u8 *jj=n->ifa->ip_sk->tbuf;
149

    
150
  if(HEAD(*l)==NULL) return;
151

    
152
  pk=(struct ospf_lsupd_packet *)n->ifa->ip_sk->tbuf;
153
  op=(struct ospf_packet *)n->ifa->ip_sk->tbuf;
154

    
155
  DBG("LSupd: 1st packet\n");
156
       
157
  fill_ospf_pkt_hdr(n->ifa, pk, LSUPD);
158
  len=SIPH+sizeof(struct ospf_lsupd_packet);
159
  lsano=0;
160
  pktpos=(pk+1);
161

    
162
  WALK_LIST(llsh, *l)
163
  {
164
    en=ospf_hash_find(n->ifa->oa->gr,llsh->lsh.id,llsh->lsh.rt,llsh->lsh.type);
165
    DBG("Sending ID=%I, Type=%u, RT=%I\n", llsh->lsh.id, llsh->lsh.type,
166
      llsh->lsh.rt);
167
    if((len+sizeof(struct ospf_lsa_header)+en->lsa.length)>n->ifa->iface->mtu)
168
    {
169
      pk->lsano=htonl(lsano);
170
      op->length=htons(len);
171
      ospf_pkt_finalize(n->ifa, op);
172
                       
173
      for(ii=0;ii<(len-SIPH);ii+=4)
174
        DBG("Out dump: %d,%d,%d,%d\n", *(jj+ii), *(jj+ii+1), *(jj+ii+2), *(jj+ii+3));
175

    
176
      sk_send_to(n->ifa->ip_sk,len, n->ip, OSPF_PROTO);
177

    
178
      DBG("LSupd: next packet\n");
179
      fill_ospf_pkt_hdr(n->ifa, pk, LSUPD);
180
      len=SIPH+sizeof(struct ospf_lsupd_packet);
181
      lsano=0;
182
      pktpos=(pk+1);
183
    }
184
    htonlsah(&(en->lsa), pktpos);
185
    pktpos=pktpos+sizeof(struct ospf_lsa_header);
186
    htonlsab(en->lsa_body, pktpos, en->lsa.type, en->lsa.length);
187
    pktpos=pktpos+en->lsa.length-sizeof(struct ospf_lsa_header);
188
    len=len+en->lsa.length;
189
    lsano++;
190
  }
191
  pk->lsano=htonl(lsano);
192
  op->length=htons(len-SIPH);
193
  ospf_pkt_finalize(n->ifa, op);
194

    
195
  for(ii=0;ii<(len-SIPH);ii+=4)
196
    DBG("Out dump: %d,%d,%d,%d\n", *(jj+ii), *(jj+ii+1), *(jj+ii+2), *(jj+ii+3));
197

    
198
  sk_send_to(n->ifa->ip_sk,len, n->ip, OSPF_PROTO);
199
  DBG("LSupd: sent\n");
200
}
201

    
202
void
203
ospf_lsupd_rx(struct ospf_lsupd_packet *ps, struct proto *p,
204
  struct ospf_iface *ifa, u16 size)
205
{
206
  u32 area,nrid,myrid;
207
  struct ospf_neighbor *n,*ntmp;
208
  struct ospf_lsa_header *lsa;
209
  struct ospf_area *oa;
210
  struct proto_ospf *po=(struct proto_ospf *)p;
211
  u16 length;
212
  u8 i;
213

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

    
216
  myrid=p->cf->global->router_id;
217

    
218
  if((n=find_neigh(ifa, nrid))==NULL)
219
  {
220
    debug("%s: Received lsupd from unknown neigbor! (%I)\n", p->name,
221
      nrid);
222
    return ;
223
  }
224
  if(n->state<NEIGHBOR_EXCHANGE)
225
  {
226
    debug("%s: Received lsupd in lesser state than EXCHANGE from (%I)\n",
227
      p->name);
228
    return;
229
  }
230

    
231
  lsa=(struct ospf_lsa_header *)(ps+1);
232
  area=htonl(ps->ospf_packet.areaid);
233
  oa=ospf_find_area((struct proto_ospf *)p,area);
234
  for(i=0;i<ntohl(ps->lsano);i++,
235
    lsa=(struct ospf_lsa_header *)(((u8 *)lsa)+ntohs(lsa->length)))
236
  {
237
    struct ospf_lsa_header lsatmp;
238
    struct top_hash_entry *lsadb;
239
    /* pg 143 (1) */
240
    if(lsa->checksum!=lsasum_check(lsa,NULL,po))
241
    {
242
      log("Received bad lsa checksum from %I\n",n->rid);
243
      continue;
244
    }
245
    /* pg 143 (2) */
246
    if((lsa->type<LSA_T_RT)||(lsa->type>LSA_T_EXT))
247
    {
248
      log("Unknown LSA type from %I\n",n->rid);
249
      continue;
250
    }
251
    /* pg 143 (3) */
252
    if((lsa->type==LSA_T_EXT)&&oa->stub)
253
    {
254
      log("Received External LSA in stub area from %I\n",n->rid);
255
      continue;
256
    }
257
    ntohlsah(lsa,&lsatmp);
258
    DBG("Processing update Type: %u ID: %I RT: %I\n",lsatmp.type,
259
        lsatmp.id, lsatmp.rt);
260
    lsadb=ospf_hash_find_header(oa->gr, &lsatmp);
261

    
262
    /* pg 143 (4) */
263
    if((lsatmp.age==LSA_MAXAGE)&&(lsadb==NULL))
264
    {
265
      int flag=0;
266
      struct ospf_iface *ifatmp;
267

    
268
      WALK_LIST(NODE ifatmp,po->iface_list)
269
        WALK_LIST(NODE ntmp,ifatmp->neigh_list)
270
          if((ntmp->state==NEIGHBOR_EXCHANGE)&&
271
            (ntmp->state==NEIGHBOR_LOADING))
272
            flag=1;
273

    
274
      if(flag==0)
275
      {
276
        ospf_lsack_direct_tx(n,lsa);
277

    
278
        continue;
279
      }
280
    }
281
    /* pg 144 (5) */
282
    if((lsadb==NULL)||(lsa_comp(&lsatmp,&lsadb->lsa)==CMP_NEWER))
283
    {
284
       struct ospf_iface *ift=NULL;
285
       void *body;
286

    
287

    
288
      /* pg 144 (5a) */
289
      if(lsadb && ((lsadb->inst_t-now)<MINLSARRIVAL)) continue;
290

    
291
      flood_lsa(n,lsa,&lsatmp,po,ifa,ifa->oa);
292

    
293
      /* Remove old from all ret lists */
294
      /* pg 144 (5c) */
295
      if(lsadb)
296
        WALK_LIST(NODE ift,po->iface_list)
297
          WALK_LIST(NODE ntmp,ift->neigh_list)
298
          {
299
            struct top_hash_entry *en;
300
            if(ntmp->state>NEIGHBOR_EXSTART)
301
              if((en=ospf_hash_find_header(ntmp->lsrth,&lsadb->lsa))!=NULL)
302
              {
303
                s_rem_node(SNODE en);
304
                ospf_hash_delete(ntmp->lsrth,en);
305
              }
306
          }
307

    
308
      /* pg 144 (5d) */
309
      body=mb_alloc(p->pool,lsatmp.length-sizeof(struct ospf_lsa_header));
310
      ntohlsab(lsa+1,body,lsatmp.type,
311
        lsatmp.length-sizeof(struct ospf_lsa_header));
312
      lsadb=lsa_install_new(&lsatmp,body, oa);
313
      DBG("New LSA installed in DB\n");
314

    
315
      if(ifa->state==OSPF_IS_BACKUP)
316
      {
317
        if(ifa->drid==n->rid) ospf_lsa_delay(n, lsa, p);
318
      }
319
      else if(ifa->drid==n->rid) ospf_lsa_delay(n, lsa, p);
320
      /* FIXME 145 (5f) self originated? */
321

    
322
      continue;
323
    }
324

    
325
    /* FIXME pg145 (6)?? */
326

    
327
    /* pg145 (7) */
328
    if(lsa_comp(&lsatmp,&lsadb->lsa)==CMP_SAME)
329
    {
330
        struct top_hash_entry *en;
331
        if((en=ospf_hash_find_header(n->lsrth,&lsadb->lsa))!=NULL)
332
        {
333
          s_rem_node(SNODE en);
334
          if(ifa->state==OSPF_IS_BACKUP)
335
          {
336
            if(n->rid==ifa->drid) ospf_lsa_delay(n, lsa, p);
337
          }
338
        }
339
        else
340
        {
341
          ospf_lsack_direct_tx(n,lsa);
342
        }
343
        continue;
344
    }
345

    
346
    /* pg145 (8) */
347
    if((lsadb->lsa.age==LSA_MAXAGE)&&(lsadb->lsa.sn==LSA_MAXSEQNO))
348
    {
349
      continue;
350
    }
351

    
352
    {
353
      list l;
354
      struct l_lsr_head llsh;
355
      init_list(&l);
356
      memcpy(&llsh.lsh,&lsadb->lsa,sizeof(struct ospf_lsa_header));
357
      add_tail(&l, NODE &llsh);
358
      ospf_lsupd_tx_list(n, &l);
359
    }
360
  }
361
}
362