Work on lsupdates continues. Some checksum cleanup.
This commit is contained in:
parent
db9fb72769
commit
394acced11
5 changed files with 78 additions and 41 deletions
|
@ -189,11 +189,10 @@ ospf_dbdes_reqladd(struct ospf_dbdes_packet *ps, struct proto *p,
|
||||||
for(i=0;i<j;i++)
|
for(i=0;i<j;i++)
|
||||||
{
|
{
|
||||||
ntohlsah(plsa+i, &lsa);
|
ntohlsah(plsa+i, &lsa);
|
||||||
/* FIXME Test Checksum */
|
|
||||||
if(((he=ospf_hash_find(gr,lsa.id,lsa.rt,lsa.type))==NULL)||
|
if(((he=ospf_hash_find(gr,lsa.id,lsa.rt,lsa.type))==NULL)||
|
||||||
(lsa_comp(&lsa, &(he->lsa))==1))
|
(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)
|
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);
|
sn=ospf_hash_get(n->lsrqh,lsa.id,lsa.rt,lsa.type);
|
||||||
|
|
|
@ -230,40 +230,60 @@ ntohlsab(void *n, void *h, u8 type, u16 len)
|
||||||
#define LSA_CHECKSUM_OFFSET 15
|
#define LSA_CHECKSUM_OFFSET 15
|
||||||
|
|
||||||
/* FIXME This is VERY uneficient, I have huge endianity problems */
|
/* FIXME This is VERY uneficient, I have huge endianity problems */
|
||||||
|
|
||||||
void
|
void
|
||||||
lsasum_calculate(struct ospf_lsa_header *h,void *body,struct proto_ospf *po)
|
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;
|
u8 *sp, *ep, *p, *q, *b;
|
||||||
int c0 = 0, c1 = 0;
|
int c0 = 0, c1 = 0;
|
||||||
int x, y;
|
int x, y;
|
||||||
u16 length;
|
u16 length,chsum;
|
||||||
|
|
||||||
h->checksum = 0;
|
|
||||||
b=body;
|
b=body;
|
||||||
length = h->length-2;
|
|
||||||
sp = (char *) &h->options;
|
sp = (char *) &h->options;
|
||||||
|
length=ntohs(h->length)-2;
|
||||||
htonlsah(h,h);
|
h->checksum = 0;
|
||||||
htonlsab(b,b,h->type,length+2);
|
|
||||||
|
|
||||||
for (ep = sp + length; sp < ep; sp = q)
|
for (ep = sp + length; sp < ep; sp = q)
|
||||||
{
|
{ /* Actually MODX is very large, do we need the for-cyclus? */
|
||||||
q = sp + MODX;
|
q = sp + MODX;
|
||||||
if (q > ep)
|
if (q > ep) q = ep;
|
||||||
q = ep;
|
|
||||||
for (p = sp; p < q; p++)
|
for (p = sp; p < q; p++)
|
||||||
{
|
{
|
||||||
if(p<(u8 *)(h+1))
|
/*
|
||||||
|
* 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;
|
c0 += *p;
|
||||||
/*DBG("XXXXXX: %u\t%u\n", p-sp, *p);*/
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
c0 += *(b+(p-sp)-sizeof(struct ospf_lsa_header)+2);
|
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;
|
c1 += c0;
|
||||||
}
|
}
|
||||||
c0 %= 255;
|
c0 %= 255;
|
||||||
|
@ -271,21 +291,18 @@ lsasum_calculate(struct ospf_lsa_header *h,void *body,struct proto_ospf *po)
|
||||||
}
|
}
|
||||||
|
|
||||||
x = ((length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255;
|
x = ((length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255;
|
||||||
if (x <= 0)
|
if (x <= 0) x += 255;
|
||||||
x += 255;
|
|
||||||
y = 510 - c0 - x;
|
y = 510 - c0 - x;
|
||||||
if (y > 255)
|
if (y > 255) y -= 255;
|
||||||
y -= 255;
|
|
||||||
|
|
||||||
h->checksum = x + (y << 8);
|
chsum= x + (y << 8);
|
||||||
|
h->checksum = chsum;
|
||||||
ntohlsah(h,h);
|
return chsum;
|
||||||
ntohlsab(b,b,h->type,length+2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
lsa_comp(struct ospf_lsa_header *l1, struct ospf_lsa_header *l2)
|
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) return CMP_NEWER;
|
||||||
if(l1->sn==l2->sn)
|
if(l1->sn==l2->sn)
|
||||||
|
|
|
@ -16,6 +16,8 @@ void htonlsab(void *h, void *n, u8 type, u16 len);
|
||||||
void ntohlsab(void *n, void *h, u8 type, u16 len);
|
void ntohlsab(void *n, void *h, u8 type, u16 len);
|
||||||
void lsasum_calculate(struct ospf_lsa_header *header, void *body,
|
void lsasum_calculate(struct ospf_lsa_header *header, void *body,
|
||||||
struct proto_ospf *p);
|
struct proto_ospf *p);
|
||||||
|
u16 lsasum_check(struct ospf_lsa_header *h,void *body,struct proto_ospf *po);
|
||||||
|
|
||||||
#define CMP_NEWER 1
|
#define CMP_NEWER 1
|
||||||
#define CMP_SAME 0
|
#define CMP_SAME 0
|
||||||
#define CMP_OLDER -1
|
#define CMP_OLDER -1
|
||||||
|
|
|
@ -83,10 +83,10 @@ void
|
||||||
ospf_lsupd_rx(struct ospf_lsupd_packet *ps, struct proto *p,
|
ospf_lsupd_rx(struct ospf_lsupd_packet *ps, struct proto *p,
|
||||||
struct ospf_iface *ifa, u16 size)
|
struct ospf_iface *ifa, u16 size)
|
||||||
{
|
{
|
||||||
u32 nrid, myrid;
|
u32 area,nrid,myrid;
|
||||||
struct ospf_neighbor *n;
|
struct ospf_neighbor *n;
|
||||||
struct ospf_lsreq_header *lsh;
|
struct ospf_lsa_header *lsa;
|
||||||
int length;
|
u16 length;
|
||||||
u8 i;
|
u8 i;
|
||||||
|
|
||||||
nrid=ntohl(ps->ospf_packet.routerid);
|
nrid=ntohl(ps->ospf_packet.routerid);
|
||||||
|
@ -99,6 +99,24 @@ ospf_lsupd_rx(struct ospf_lsupd_packet *ps, struct proto *p,
|
||||||
nrid);
|
nrid);
|
||||||
return ;
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,6 +145,7 @@ ospf_rx_hook(sock *sk, int size)
|
||||||
break;
|
break;
|
||||||
case LSUPD:
|
case LSUPD:
|
||||||
DBG("%s: Link state update received.\n", p->name);
|
DBG("%s: Link state update received.\n", p->name);
|
||||||
|
ospf_lsupd_rx((struct ospf_lsupd_packet *)ps, p, ifa, size);
|
||||||
break;
|
break;
|
||||||
case LSACK:
|
case LSACK:
|
||||||
DBG("%s: Link state ack received.\n", p->name);
|
DBG("%s: Link state ack received.\n", p->name);
|
||||||
|
|
Loading…
Reference in a new issue