Revision 394acced

View differences:

proto/ospf/dbdes.c
189 189
  for(i=0;i<j;i++)
190 190
  {
191 191
    ntohlsah(plsa+i, &lsa);
192
    /* FIXME Test Checksum */
193 192
    if(((he=ospf_hash_find(gr,lsa.id,lsa.rt,lsa.type))==NULL)||
194 193
      (lsa_comp(&lsa, &(he->lsa))==1))
195 194
    {
196
      /* Is this confition necessary? */
195
      /* Is this condition necessary? */
197 196
      if(ospf_hash_find(n->lsrqh,lsa.id,lsa.rt,lsa.type)==NULL)
198 197
      {
199 198
        sn=ospf_hash_get(n->lsrqh,lsa.id,lsa.rt,lsa.type);
proto/ospf/lsalib.c
230 230
#define LSA_CHECKSUM_OFFSET    15
231 231

  
232 232
/* FIXME This is VERY uneficient, I have huge endianity problems */
233

  
234 233
void
235 234
lsasum_calculate(struct ospf_lsa_header *h,void *body,struct proto_ospf *po)
236 235
{
236
  u16 length;
237
  
238
  length=h->length;
239

  
240
  htonlsah(h,h);
241
  htonlsab(body,body,h->type,length);
242

  
243
  (void)lsasum_check(h,body,po);
244
  
245
  ntohlsah(h,h);
246
  ntohlsab(body,body,h->type,length);
247
}
248

  
249
/*
250
 * Note, that this function expects that LSA is in big endianity
251
 * It also returns value in big endian
252
 */
253
u16
254
lsasum_check(struct ospf_lsa_header *h,void *body,struct proto_ospf *po)
255
{
237 256
  u8 *sp, *ep, *p, *q, *b;
238 257
  int c0 = 0, c1 = 0;
239 258
  int x, y;
240
  u16 length;
259
  u16 length,chsum;
241 260

  
242
  h->checksum = 0;
243 261
  b=body;
244
  length = h->length-2;
245 262
  sp = (char *) &h->options;
246

  
247
  htonlsah(h,h);
248
  htonlsab(b,b,h->type,length+2);
263
  length=ntohs(h->length)-2;
264
  h->checksum = 0;
249 265

  
250 266
  for (ep = sp + length; sp < ep; sp = q)
267
  {		/* Actually MODX is very large, do we need the for-cyclus? */
268
    q = sp + MODX;
269
    if (q > ep) q = ep;
270
    for (p = sp; p < q; p++)
251 271
    {
252
      q = sp + MODX;
253
      if (q > ep)
254
        q = ep;
255
      for (p = sp; p < q; p++)
256
        {
257
          if(p<(u8 *)(h+1))
258
	  {
259
            c0 += *p;
260
	    /*DBG("XXXXXX: %u\t%u\n", p-sp, *p);*/
261
	  }
262
	  else
263
          {
264
            c0 += *(b+(p-sp)-sizeof(struct ospf_lsa_header)+2);
265
	    /*DBG("YYYYYY: %u\t%u\n", p-sp,*(b+(p-sp)-sizeof(struct ospf_lsa_header)+2));*/
266
          }
267
          c1 += c0;
268
        }
269
      c0 %= 255;
270
      c1 %= 255;
272
      /* 
273
       * I count with bytes from header and than from body
274
       * but if there is no body, it's appended to header
275
       * (probably checksum in update receiving) and I go on
276
       * after header
277
       */
278
      if((b==NULL) || (p<(u8 *)(h+1)))
279
      {
280
	      c0 += *p;
281
      }
282
      else
283
      {
284
	      c0 += *(b+(p-sp)-sizeof(struct ospf_lsa_header)+2);
285
      }
286

  
287
      c1 += c0;
271 288
    }
289
    c0 %= 255;
290
    c1 %= 255;
291
  }
272 292

  
273 293
  x = ((length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255;
274
  if (x <= 0)
275
    x += 255;
294
  if (x <= 0) x += 255;
276 295
  y = 510 - c0 - x;
277
  if (y > 255)
278
    y -= 255;
296
  if (y > 255) y -= 255;
279 297

  
280
  h->checksum = x + (y << 8);
281
  
282
  ntohlsah(h,h);
283
  ntohlsab(b,b,h->type,length+2);
298
  chsum= x + (y << 8);
299
  h->checksum = chsum;
300
  return chsum;
284 301
}
285 302

  
286 303
int
287 304
lsa_comp(struct ospf_lsa_header *l1, struct ospf_lsa_header *l2)
288
			/* Return codes form view of l1 */
305
			/* Return codes from point of view of l1 */
289 306
{
290 307
  if(l1->sn<l2->sn) return CMP_NEWER;
291 308
    if(l1->sn==l2->sn)
proto/ospf/lsalib.h
16 16
void ntohlsab(void *n, void *h, u8 type, u16 len);
17 17
void lsasum_calculate(struct ospf_lsa_header *header, void *body,
18 18
  struct proto_ospf *p);
19
u16 lsasum_check(struct ospf_lsa_header *h,void *body,struct proto_ospf *po);
20

  
19 21
#define CMP_NEWER 1
20 22
#define CMP_SAME 0
21 23
#define CMP_OLDER -1
proto/ospf/lsupd.c
83 83
ospf_lsupd_rx(struct ospf_lsupd_packet *ps, struct proto *p,
84 84
  struct ospf_iface *ifa, u16 size)
85 85
{
86
  u32 nrid, myrid;
86
  u32 area,nrid,myrid;
87 87
  struct ospf_neighbor *n;
88
  struct ospf_lsreq_header *lsh;
89
  int length;
88
  struct ospf_lsa_header *lsa;
89
  u16 length;
90 90
  u8 i;
91 91

  
92 92
  nrid=ntohl(ps->ospf_packet.routerid);
......
99 99
      nrid);
100 100
    return ;
101 101
  }
102
  /* FIXME Go on! */
102
  if(n->state<NEIGHBOR_EXCHANGE)
103
  {
104
    debug("%s: Received lsupd in lesser state than EXCHANGE from (%u)\n",
105
      p->name);
106
    return;
107
  }
108

  
109
  lsa=(struct ospf_lsa_header *)(ps+1);
110
  area=htonl(ps->ospf_packet.areaid);
111
  for(i=0;i<ntohl(ps->lsano);i++)
112
  {
113
    if(lsa->checksum==lsasum_check(lsa,NULL,(struct proto_ospf *)p))
114
    {
115
      DBG("Processing update Type: %u ID: %u RT: %u\n",lsa->type,
116
        ntohl(lsa->id), ntohl(lsa->rt));
117
      /* FIXME Go on */
118
    }
119
    lsa=(struct ospf_lsa_header *)(((u8 *)lsa)+ntohs(lsa->length));
120
  }
103 121
}
104 122

  
proto/ospf/packet.c
145 145
      break;
146 146
    case LSUPD:
147 147
      DBG("%s: Link state update received.\n", p->name);
148
      ospf_lsupd_rx((struct ospf_lsupd_packet *)ps, p, ifa, size);
148 149
      break;
149 150
    case LSACK:
150 151
      DBG("%s: Link state ack received.\n", p->name);

Also available in: Unified diff