for(i=0;i<j;i++)
{
ntohlsah(plsa+i, &lsa);
- /* FIXME Test Checksum */
if(((he=ospf_hash_find(gr,lsa.id,lsa.rt,lsa.type))==NULL)||
(lsa_comp(&lsa, &(he->lsa))==1))
{
- /* Is this confition necessary? */
+ /* Is this condition necessary? */
if(ospf_hash_find(n->lsrqh,lsa.id,lsa.rt,lsa.type)==NULL)
{
sn=ospf_hash_get(n->lsrqh,lsa.id,lsa.rt,lsa.type);
#define LSA_CHECKSUM_OFFSET 15
/* FIXME This is VERY uneficient, I have huge endianity problems */
-
void
lsasum_calculate(struct ospf_lsa_header *h,void *body,struct proto_ospf *po)
+{
+ u16 length;
+
+ length=h->length;
+
+ htonlsah(h,h);
+ htonlsab(body,body,h->type,length);
+
+ (void)lsasum_check(h,body,po);
+
+ ntohlsah(h,h);
+ ntohlsab(body,body,h->type,length);
+}
+
+/*
+ * Note, that this function expects that LSA is in big endianity
+ * It also returns value in big endian
+ */
+u16
+lsasum_check(struct ospf_lsa_header *h,void *body,struct proto_ospf *po)
{
u8 *sp, *ep, *p, *q, *b;
int c0 = 0, c1 = 0;
int x, y;
- u16 length;
+ u16 length,chsum;
- h->checksum = 0;
b=body;
- length = h->length-2;
sp = (char *) &h->options;
-
- htonlsah(h,h);
- htonlsab(b,b,h->type,length+2);
+ length=ntohs(h->length)-2;
+ h->checksum = 0;
for (ep = sp + length; sp < ep; sp = q)
+ { /* Actually MODX is very large, do we need the for-cyclus? */
+ q = sp + MODX;
+ if (q > ep) q = ep;
+ for (p = sp; p < q; p++)
{
- q = sp + MODX;
- if (q > ep)
- q = ep;
- for (p = sp; p < q; p++)
- {
- if(p<(u8 *)(h+1))
- {
- c0 += *p;
- /*DBG("XXXXXX: %u\t%u\n", p-sp, *p);*/
- }
- else
- {
- c0 += *(b+(p-sp)-sizeof(struct ospf_lsa_header)+2);
- /*DBG("YYYYYY: %u\t%u\n", p-sp,*(b+(p-sp)-sizeof(struct ospf_lsa_header)+2));*/
- }
- c1 += c0;
- }
- c0 %= 255;
- c1 %= 255;
+ /*
+ * I count with bytes from header and than from body
+ * but if there is no body, it's appended to header
+ * (probably checksum in update receiving) and I go on
+ * after header
+ */
+ if((b==NULL) || (p<(u8 *)(h+1)))
+ {
+ c0 += *p;
+ }
+ else
+ {
+ c0 += *(b+(p-sp)-sizeof(struct ospf_lsa_header)+2);
+ }
+
+ c1 += c0;
}
+ c0 %= 255;
+ c1 %= 255;
+ }
x = ((length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255;
- if (x <= 0)
- x += 255;
+ if (x <= 0) x += 255;
y = 510 - c0 - x;
- if (y > 255)
- y -= 255;
+ if (y > 255) y -= 255;
- h->checksum = x + (y << 8);
-
- ntohlsah(h,h);
- ntohlsab(b,b,h->type,length+2);
+ chsum= x + (y << 8);
+ h->checksum = chsum;
+ return chsum;
}
int
lsa_comp(struct ospf_lsa_header *l1, struct ospf_lsa_header *l2)
- /* Return codes form view of l1 */
+ /* Return codes from point of view of l1 */
{
if(l1->sn<l2->sn) return CMP_NEWER;
if(l1->sn==l2->sn)
ospf_lsupd_rx(struct ospf_lsupd_packet *ps, struct proto *p,
struct ospf_iface *ifa, u16 size)
{
- u32 nrid, myrid;
+ u32 area,nrid,myrid;
struct ospf_neighbor *n;
- struct ospf_lsreq_header *lsh;
- int length;
+ struct ospf_lsa_header *lsa;
+ u16 length;
u8 i;
nrid=ntohl(ps->ospf_packet.routerid);
nrid);
return ;
}
- /* FIXME Go on! */
+ if(n->state<NEIGHBOR_EXCHANGE)
+ {
+ debug("%s: Received lsupd in lesser state than EXCHANGE from (%u)\n",
+ p->name);
+ return;
+ }
+
+ lsa=(struct ospf_lsa_header *)(ps+1);
+ area=htonl(ps->ospf_packet.areaid);
+ for(i=0;i<ntohl(ps->lsano);i++)
+ {
+ if(lsa->checksum==lsasum_check(lsa,NULL,(struct proto_ospf *)p))
+ {
+ DBG("Processing update Type: %u ID: %u RT: %u\n",lsa->type,
+ ntohl(lsa->id), ntohl(lsa->rt));
+ /* FIXME Go on */
+ }
+ lsa=(struct ospf_lsa_header *)(((u8 *)lsa)+ntohs(lsa->length));
+ }
}