Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (8.86 KB)

1 de769e24 Ondrej Filip
/*
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 2c971094 Ondrej Filip
void
18
flood_lsa(struct ospf_neighbor *n, struct ospf_lsa_header *hn,
19 38130b86 Ondrej Filip
  struct ospf_lsa_header *hh, struct proto_ospf *po, struct ospf_iface *iff,
20
  struct ospf_area *oa)
21 2c971094 Ondrej Filip
{
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 38130b86 Ondrej Filip
      if(oa->areaid==BACKBONE)
38 2c971094 Ondrej Filip
      {
39 38130b86 Ondrej Filip
        if((ifa->type!=OSPF_IT_VLINK)&&(ifa->oa!=oa)) continue;
40 2c971094 Ondrej Filip
      }
41
      else
42
      {
43 38130b86 Ondrej Filip
        if(ifa->oa!=oa) continue;
44 2c971094 Ondrej Filip
      }
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 44724025 Ondrej Filip
              DBG("Removing from lsreq list for neigh %I\n", nn->rid);
63 2c971094 Ondrej Filip
              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 44724025 Ondrej Filip
              DBG("Removing from lsreq list for neigh %I\n", nn->rid);
70 2c971094 Ondrej Filip
              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 38130b86 Ondrej Filip
      if(ifa->type==OSPF_IT_NBMA)  sk=ifa->ip_sk;
97
      else sk=ifa->hello_sk;        /* FIXME is this true for PTP? */
98 2c971094 Ondrej Filip
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 38130b86 Ondrej Filip
      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 2c971094 Ondrej Filip
      op->length=htons(len);
121
      ospf_pkt_finalize(ifa, op);
122
123
      if(ifa->type==OSPF_IT_NBMA)
124
      {
125 67315ef6 Ondrej Filip
        sk_send_to_agt(sk ,len, ifa, NEIGHBOR_EXCHANGE);
126 2c971094 Ondrej Filip
      }
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 f45fd316 Ondrej Filip
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 9f940976 Ondrej Filip
  u8 ii;
148
  u8 *jj=n->ifa->ip_sk->tbuf;
149 f45fd316 Ondrej Filip
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 9f940976 Ondrej Filip
155
  DBG("LSupd: 1st packet\n");
156 f45fd316 Ondrej Filip
       
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 44724025 Ondrej Filip
    DBG("Sending ID=%I, Type=%u, RT=%I\n", llsh->lsh.id, llsh->lsh.type,
166 9f940976 Ondrej Filip
      llsh->lsh.rt);
167
    if((len+sizeof(struct ospf_lsa_header)+en->lsa.length)>n->ifa->iface->mtu)
168 f45fd316 Ondrej Filip
    {
169
      pk->lsano=htonl(lsano);
170
      op->length=htons(len);
171
      ospf_pkt_finalize(n->ifa, op);
172 9f940976 Ondrej Filip
                       
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 f45fd316 Ondrej Filip
      sk_send_to(n->ifa->ip_sk,len, n->ip, OSPF_PROTO);
177
178 9f940976 Ondrej Filip
      DBG("LSupd: next packet\n");
179 f45fd316 Ondrej Filip
      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 9f940976 Ondrej Filip
    pktpos=pktpos+en->lsa.length-sizeof(struct ospf_lsa_header);
188
    len=len+en->lsa.length;
189
    lsano++;
190 f45fd316 Ondrej Filip
  }
191
  pk->lsano=htonl(lsano);
192 9f940976 Ondrej Filip
  op->length=htons(len-SIPH);
193 f45fd316 Ondrej Filip
  ospf_pkt_finalize(n->ifa, op);
194 9f940976 Ondrej Filip
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 f45fd316 Ondrej Filip
  sk_send_to(n->ifa->ip_sk,len, n->ip, OSPF_PROTO);
199 9f940976 Ondrej Filip
  DBG("LSupd: sent\n");
200 f45fd316 Ondrej Filip
}
201
202 de769e24 Ondrej Filip
void
203
ospf_lsupd_rx(struct ospf_lsupd_packet *ps, struct proto *p,
204
  struct ospf_iface *ifa, u16 size)
205
{
206 394acced Ondrej Filip
  u32 area,nrid,myrid;
207 d8852b36 Ondrej Filip
  struct ospf_neighbor *n,*ntmp;
208 394acced Ondrej Filip
  struct ospf_lsa_header *lsa;
209 8496b2e4 Ondrej Filip
  struct ospf_area *oa;
210 921a93f2 Ondrej Filip
  struct proto_ospf *po=(struct proto_ospf *)p;
211 394acced Ondrej Filip
  u16 length;
212 de769e24 Ondrej Filip
  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 44724025 Ondrej Filip
    debug("%s: Received lsupd from unknown neigbor! (%I)\n", p->name,
221 de769e24 Ondrej Filip
      nrid);
222
    return ;
223
  }
224 394acced Ondrej Filip
  if(n->state<NEIGHBOR_EXCHANGE)
225
  {
226 44724025 Ondrej Filip
    debug("%s: Received lsupd in lesser state than EXCHANGE from (%I)\n",
227 394acced Ondrej Filip
      p->name);
228
    return;
229
  }
230
231
  lsa=(struct ospf_lsa_header *)(ps+1);
232
  area=htonl(ps->ospf_packet.areaid);
233 8496b2e4 Ondrej Filip
  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 394acced Ondrej Filip
  {
237 921a93f2 Ondrej Filip
    struct ospf_lsa_header lsatmp;
238
    struct top_hash_entry *lsadb;
239 2c971094 Ondrej Filip
    /* pg 143 (1) */
240 921a93f2 Ondrej Filip
    if(lsa->checksum!=lsasum_check(lsa,NULL,po))
241 394acced Ondrej Filip
    {
242 44724025 Ondrej Filip
      log("Received bad lsa checksum from %I\n",n->rid);
243 8496b2e4 Ondrej Filip
      continue;
244
    }
245 2c971094 Ondrej Filip
    /* pg 143 (2) */
246 8496b2e4 Ondrej Filip
    if((lsa->type<LSA_T_RT)||(lsa->type>LSA_T_EXT))
247
    {
248 44724025 Ondrej Filip
      log("Unknown LSA type from %I\n",n->rid);
249 8496b2e4 Ondrej Filip
      continue;
250 394acced Ondrej Filip
    }
251 2c971094 Ondrej Filip
    /* pg 143 (3) */
252 8496b2e4 Ondrej Filip
    if((lsa->type==LSA_T_EXT)&&oa->stub)
253
    {
254 44724025 Ondrej Filip
      log("Received External LSA in stub area from %I\n",n->rid);
255 8496b2e4 Ondrej Filip
      continue;
256
    }
257 921a93f2 Ondrej Filip
    ntohlsah(lsa,&lsatmp);
258 44724025 Ondrej Filip
    DBG("Processing update Type: %u ID: %I RT: %I\n",lsatmp.type,
259 d8852b36 Ondrej Filip
        lsatmp.id, lsatmp.rt);
260 921a93f2 Ondrej Filip
    lsadb=ospf_hash_find_header(oa->gr, &lsatmp);
261 d8852b36 Ondrej Filip
262 2c971094 Ondrej Filip
    /* pg 143 (4) */
263 921a93f2 Ondrej Filip
    if((lsatmp.age==LSA_MAXAGE)&&(lsadb==NULL))
264
    {
265
      int flag=0;
266 67315ef6 Ondrej Filip
      struct ospf_iface *ifatmp;
267 921a93f2 Ondrej Filip
268 67315ef6 Ondrej Filip
      WALK_LIST(NODE ifatmp,po->iface_list)
269
        WALK_LIST(NODE ntmp,ifatmp->neigh_list)
270 d8852b36 Ondrej Filip
          if((ntmp->state==NEIGHBOR_EXCHANGE)&&
271
            (ntmp->state==NEIGHBOR_LOADING))
272 921a93f2 Ondrej Filip
            flag=1;
273
274
      if(flag==0)
275
      {
276 67315ef6 Ondrej Filip
        ospf_lsack_direct_tx(n,lsa);
277
278 921a93f2 Ondrej Filip
        continue;
279
      }
280
    }
281 2c971094 Ondrej Filip
    /* pg 144 (5) */
282 921a93f2 Ondrej Filip
    if((lsadb==NULL)||(lsa_comp(&lsatmp,&lsadb->lsa)==CMP_NEWER))
283
    {
284 2c971094 Ondrej Filip
       struct ospf_iface *ift=NULL;
285 d8852b36 Ondrej Filip
       void *body;
286 921a93f2 Ondrej Filip
287
288 2c971094 Ondrej Filip
      /* pg 144 (5a) */
289 921a93f2 Ondrej Filip
      if(lsadb && ((lsadb->inst_t-now)<MINLSARRIVAL)) continue;
290
291 38130b86 Ondrej Filip
      flood_lsa(n,lsa,&lsatmp,po,ifa,ifa->oa);
292 2c971094 Ondrej Filip
293 921a93f2 Ondrej Filip
      /* Remove old from all ret lists */
294 2c971094 Ondrej Filip
      /* pg 144 (5c) */
295 d8852b36 Ondrej Filip
      if(lsadb)
296 2c971094 Ondrej Filip
        WALK_LIST(NODE ift,po->iface_list)
297
          WALK_LIST(NODE ntmp,ift->neigh_list)
298 d8852b36 Ondrej Filip
          {
299
            struct top_hash_entry *en;
300 f1f7face Ondrej Filip
            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 d8852b36 Ondrej Filip
          }
307 921a93f2 Ondrej Filip
308 2c971094 Ondrej Filip
      /* pg 144 (5d) */
309 d8852b36 Ondrej Filip
      body=mb_alloc(p->pool,lsatmp.length-sizeof(struct ospf_lsa_header));
310 2c971094 Ondrej Filip
      ntohlsab(lsa+1,body,lsatmp.type,
311
        lsatmp.length-sizeof(struct ospf_lsa_header));
312 d8852b36 Ondrej Filip
      lsadb=lsa_install_new(&lsatmp,body, oa);
313 10000b96 Ondrej Filip
      DBG("New LSA installed in DB\n");
314 d8852b36 Ondrej Filip
315 67315ef6 Ondrej Filip
      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 2c971094 Ondrej Filip
      /* FIXME 145 (5f) self originated? */
321
322 921a93f2 Ondrej Filip
      continue;
323
    }
324
325 2c971094 Ondrej Filip
    /* FIXME pg145 (6)?? */
326 921a93f2 Ondrej Filip
327 2c971094 Ondrej Filip
    /* pg145 (7) */
328 921a93f2 Ondrej Filip
    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 67315ef6 Ondrej Filip
        {
333 921a93f2 Ondrej Filip
          s_rem_node(SNODE en);
334 67315ef6 Ondrej Filip
          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 921a93f2 Ondrej Filip
        continue;
344
    }
345
346 2c971094 Ondrej Filip
    /* pg145 (8) */
347 67315ef6 Ondrej Filip
    if((lsadb->lsa.age==LSA_MAXAGE)&&(lsadb->lsa.sn==LSA_MAXSEQNO))
348
    {
349
      continue;
350
    }
351 921a93f2 Ondrej Filip
352 2c971094 Ondrej Filip
    {
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 394acced Ondrej Filip
  }
361 de769e24 Ondrej Filip
}