1999-11-17 23:50:41 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- OSPF
|
|
|
|
*
|
2000-03-08 20:50:28 +08:00
|
|
|
* (c) 1999-2000 Ondrej Filip <feela@network.cz>
|
1999-11-17 23:50:41 +08:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ospf.h"
|
|
|
|
|
2000-03-10 06:38:05 +08:00
|
|
|
void
|
|
|
|
htonlsah(struct ospf_lsa_header *h, struct ospf_lsa_header *n)
|
|
|
|
{
|
|
|
|
n->age=htons(h->age);
|
|
|
|
n->options=h->options;
|
|
|
|
n->type=h->type;
|
|
|
|
n->id=htonl(h->id);
|
|
|
|
n->rt=htonl(h->rt);
|
|
|
|
n->sn=htonl(h->sn);
|
|
|
|
n->checksum=htons(h->checksum);
|
|
|
|
n->length=htons(h->length);
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ntohlsah(struct ospf_lsa_header *n, struct ospf_lsa_header *h)
|
|
|
|
{
|
|
|
|
h->age=ntohs(n->age);
|
|
|
|
h->options=n->options;
|
|
|
|
h->type=n->type;
|
|
|
|
h->id=ntohl(n->id);
|
|
|
|
h->rt=ntohl(n->rt);
|
|
|
|
h->sn=ntohl(n->sn);
|
|
|
|
h->checksum=ntohs(n->checksum);
|
|
|
|
h->length=ntohs(n->length);
|
|
|
|
};
|
|
|
|
|
1999-11-17 23:50:41 +08:00
|
|
|
void
|
|
|
|
ospf_dbdes_tx(struct ospf_neighbor *n)
|
|
|
|
{
|
|
|
|
struct ospf_dbdes_packet *pkt;
|
|
|
|
struct ospf_packet *op;
|
|
|
|
struct ospf_iface *ifa;
|
|
|
|
u16 length;
|
|
|
|
struct proto *p;
|
2000-03-08 20:50:28 +08:00
|
|
|
u16 i,j;
|
|
|
|
u8 *aa,*bb;
|
1999-11-17 23:50:41 +08:00
|
|
|
|
|
|
|
ifa=n->ifa;
|
|
|
|
|
|
|
|
p=(struct proto *)(ifa->proto);
|
|
|
|
|
|
|
|
switch(n->state)
|
|
|
|
{
|
|
|
|
case NEIGHBOR_EXSTART: /* Send empty packets */
|
2000-03-29 20:45:37 +08:00
|
|
|
n->myimms.bit.i=1;
|
2000-03-29 08:34:28 +08:00
|
|
|
pkt=(struct ospf_dbdes_packet *)(ifa->ip_sk->tbuf);
|
|
|
|
op=(struct ospf_packet *)pkt;
|
1999-11-17 23:50:41 +08:00
|
|
|
fill_ospf_pkt_hdr(ifa, pkt, DBDES);
|
2000-03-29 20:47:07 +08:00
|
|
|
pkt->iface_mtu=htons(ifa->iface->mtu); /*FIXME NOT for VLINK! */
|
1999-11-17 23:50:41 +08:00
|
|
|
pkt->options= ifa->options;
|
|
|
|
pkt->imms=n->myimms;
|
|
|
|
pkt->ddseq=n->dds;
|
|
|
|
length=sizeof(struct ospf_dbdes_packet);
|
|
|
|
op->length=htons(length);
|
|
|
|
ospf_pkt_finalize(ifa, op);
|
|
|
|
sk_send_to(ifa->ip_sk,length, n->ip, OSPF_PROTO);
|
2000-03-29 08:34:28 +08:00
|
|
|
debug("%s: DB_DES (I) sent for %u.\n", p->name, n->rid);
|
2000-03-08 20:50:28 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NEIGHBOR_EXCHANGE:
|
2000-03-29 20:45:37 +08:00
|
|
|
n->myimms.bit.i=0;
|
2000-03-29 20:32:25 +08:00
|
|
|
if(! (((n->myimms.bit.ms) && (n->dds==n->ddr+1)) ||
|
|
|
|
((!(n->myimms.bit.ms)) && (n->dds==n->ddr))))
|
2000-03-08 20:50:28 +08:00
|
|
|
{
|
|
|
|
snode *sn; /* Send next */
|
2000-03-10 06:38:05 +08:00
|
|
|
struct ospf_lsa_header *lsa;
|
2000-03-29 08:34:28 +08:00
|
|
|
|
|
|
|
pkt=n->ldbdes;
|
|
|
|
op=(struct ospf_packet *)pkt;
|
2000-03-08 20:50:28 +08:00
|
|
|
|
|
|
|
fill_ospf_pkt_hdr(ifa, pkt, DBDES);
|
2000-03-29 08:34:28 +08:00
|
|
|
pkt->iface_mtu=htons(ifa->iface->mtu);
|
2000-03-08 20:50:28 +08:00
|
|
|
pkt->options= ifa->options;
|
|
|
|
pkt->ddseq=n->dds;
|
|
|
|
|
2000-03-29 08:34:28 +08:00
|
|
|
j=i=(ifa->iface->mtu-sizeof(struct ospf_dbdes_packet))/
|
2000-03-10 06:38:05 +08:00
|
|
|
sizeof(struct ospf_lsa_header); /* Number of lsaheaders */
|
2000-03-08 20:50:28 +08:00
|
|
|
lsa=(n->ldbdes+sizeof(struct ospf_dbdes_packet));
|
|
|
|
|
2000-03-29 08:34:28 +08:00
|
|
|
sn=s_get(&(n->dbsi));
|
|
|
|
|
|
|
|
DBG("Number of LSA: %d\n", j);
|
2000-03-08 20:50:28 +08:00
|
|
|
for(;i>0;i--)
|
|
|
|
{
|
|
|
|
struct top_hash_entry *en;
|
|
|
|
|
|
|
|
en=(struct top_hash_entry *)sn;
|
2000-03-10 06:38:05 +08:00
|
|
|
htonlsah(&(en->lsa), lsa);
|
2000-03-29 08:34:28 +08:00
|
|
|
DBG("Working on: %d\n", i);
|
|
|
|
debug("\t%04x %08x %08x %p\n", en->lsa.type, en->lsa.id,
|
|
|
|
en->lsa.rt, en->lsa_body);
|
|
|
|
|
2000-03-08 20:50:28 +08:00
|
|
|
if(sn->next==NULL)
|
|
|
|
{
|
|
|
|
break; /* Should set some flag? */
|
|
|
|
}
|
|
|
|
sn=sn->next;
|
2000-03-29 08:34:28 +08:00
|
|
|
lsa++;
|
2000-03-08 20:50:28 +08:00
|
|
|
}
|
2000-03-29 08:34:28 +08:00
|
|
|
i--;
|
2000-03-08 20:50:28 +08:00
|
|
|
|
|
|
|
if(sn->next==NULL)
|
|
|
|
{
|
2000-03-29 08:34:28 +08:00
|
|
|
DBG("Number of LSA NOT sent: %d\n", i);
|
|
|
|
DBG("M bit unset.\n");
|
2000-03-29 20:32:25 +08:00
|
|
|
n->myimms.bit.m=0; /* Unset more bit */
|
2000-03-29 20:45:37 +08:00
|
|
|
DBG("Ini: %d, M: %d MS: %d.\n",n->imms.bit.i, n->imms.bit.m, n->imms.bit.ms);
|
2000-03-08 20:50:28 +08:00
|
|
|
}
|
|
|
|
|
2000-03-29 08:34:28 +08:00
|
|
|
s_put(&(n->dbsi),sn);
|
|
|
|
|
2000-03-29 20:45:37 +08:00
|
|
|
pkt->imms.byte=n->myimms.byte;
|
2000-03-08 20:50:28 +08:00
|
|
|
|
2000-03-29 08:34:28 +08:00
|
|
|
length=(j-i)*sizeof(struct ospf_lsa_header)+
|
2000-03-10 06:38:05 +08:00
|
|
|
sizeof(struct ospf_dbdes_packet);
|
2000-03-08 20:50:28 +08:00
|
|
|
op->length=htons(length);
|
2000-03-29 20:45:37 +08:00
|
|
|
|
2000-03-08 20:50:28 +08:00
|
|
|
ospf_pkt_finalize(ifa, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
aa=ifa->ip_sk->tbuf;
|
|
|
|
bb=n->ldbdes;
|
2000-03-29 08:34:28 +08:00
|
|
|
op=n->ldbdes;
|
2000-03-08 20:50:28 +08:00
|
|
|
length=ntohs(op->length);
|
|
|
|
|
|
|
|
for(i=0; i<ifa->iface->mtu; i++)
|
|
|
|
{
|
2000-03-29 20:45:37 +08:00
|
|
|
*(aa+i)=*(bb+i); /* Copy last sent packet again */
|
2000-03-08 20:50:28 +08:00
|
|
|
}
|
2000-03-29 20:32:25 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
u8 ii;
|
|
|
|
u8 *jj=ifa->ip_sk->tbuf;
|
|
|
|
|
|
|
|
for(ii=0;ii<length;ii+=4)
|
|
|
|
{
|
|
|
|
DBG("Out dump: %d,%d,%d,%d\n", *(jj+ii), *(jj+ii+1), *(jj+ii+2), *(jj+ii+3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-08 20:50:28 +08:00
|
|
|
sk_send_to(ifa->ip_sk,length, n->ip, OSPF_PROTO);
|
2000-03-29 08:34:28 +08:00
|
|
|
debug("%s: DB_DES sent for %u.\n", p->name, n->rid);
|
1999-11-17 23:50:41 +08:00
|
|
|
|
|
|
|
default: /* Ignore it */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rxmt_timer_hook(timer *timer)
|
|
|
|
{
|
|
|
|
struct ospf_iface *ifa;
|
|
|
|
struct proto *p;
|
|
|
|
struct ospf_neighbor *n;
|
|
|
|
|
|
|
|
ifa=(struct ospf_iface *)timer->data;
|
|
|
|
p=(struct proto *)(ifa->proto);
|
|
|
|
debug("%s: RXMT timer fired on interface %s.\n",
|
|
|
|
p->name, ifa->iface->name);
|
|
|
|
WALK_LIST (n, ifa->neigh_list) /* Try to send db_des */
|
|
|
|
{
|
|
|
|
ospf_dbdes_tx(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ospf_dbdes_rx(struct ospf_dbdes_packet *ps, struct proto *p,
|
|
|
|
struct ospf_iface *ifa, u16 size)
|
|
|
|
{
|
|
|
|
u32 nrid, myrid;
|
|
|
|
struct ospf_neighbor *n;
|
|
|
|
u8 i;
|
|
|
|
|
|
|
|
nrid=ntohl(((struct ospf_packet *)ps)->routerid);
|
|
|
|
|
|
|
|
myrid=p->cf->global->router_id;
|
|
|
|
|
|
|
|
if((n=find_neigh(ifa, nrid))==NULL)
|
|
|
|
{
|
|
|
|
debug("%s: Received dbdes from unknown neigbor! (%u)\n", p->name,
|
|
|
|
nrid);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ifa->iface->mtu<size)
|
|
|
|
{
|
|
|
|
debug("%s: Received dbdes larger than MTU from (%u)!\n", p->name, nrid);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(n->state)
|
|
|
|
{
|
|
|
|
case NEIGHBOR_DOWN:
|
|
|
|
case NEIGHBOR_ATTEMPT:
|
|
|
|
case NEIGHBOR_2WAY:
|
|
|
|
debug("%s: Received dbdes from %u in bad state. (%u)\n", p->name, nrid);
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case NEIGHBOR_INIT:
|
|
|
|
ospf_neigh_sm(n, INM_2WAYREC);
|
|
|
|
if(n->state!=NEIGHBOR_EXSTART) return;
|
|
|
|
case NEIGHBOR_EXSTART:
|
2000-03-29 20:32:25 +08:00
|
|
|
if((ps->imms.bit.m && ps->imms.bit.ms && ps->imms.bit.i)
|
|
|
|
&& (n->rid > myrid) &&
|
1999-11-17 23:50:41 +08:00
|
|
|
(size == sizeof(struct ospf_dbdes_packet)))
|
|
|
|
{
|
|
|
|
/* I'm slave! */
|
|
|
|
n->dds=ps->ddseq;
|
|
|
|
n->options=ps->options;
|
2000-03-29 20:32:25 +08:00
|
|
|
n->myimms.bit.ms=0;
|
1999-11-17 23:50:41 +08:00
|
|
|
n->ddr=ps->ddseq;
|
2000-03-29 20:32:25 +08:00
|
|
|
n->imms.byte=ps->imms.byte;
|
1999-11-17 23:50:41 +08:00
|
|
|
debug("%s: I'm slave to %u. \n", p->name, nrid);
|
|
|
|
ospf_neigh_sm(n, INM_NEGDONE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-03-29 20:32:25 +08:00
|
|
|
if(((ps->imms.bit.i==0) && (ps->imms.bit.ms==0)) &&
|
|
|
|
(n->rid < myrid) && (n->dds == ps->ddseq))
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
|
|
|
/* I'm master! */
|
|
|
|
n->options=ps->options;
|
|
|
|
n->ddr=ps->ddseq;
|
2000-03-29 20:32:25 +08:00
|
|
|
n->imms.byte=ps->imms.byte;
|
1999-11-17 23:50:41 +08:00
|
|
|
debug("%s: I'm master to %u. \n", p->name, nrid);
|
|
|
|
ospf_neigh_sm(n, INM_NEGDONE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debug("%s: Nothing happend to %u (imms=%u)", p->name, nrid,
|
|
|
|
ps->imms);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break; /* I should probably continue processing packet */
|
|
|
|
|
|
|
|
case NEIGHBOR_EXCHANGE:
|
2000-03-29 20:32:25 +08:00
|
|
|
if((ps->imms.byte==n->imms.byte) && (ps->options=n->options) &&
|
1999-11-17 23:50:41 +08:00
|
|
|
(ps->ddseq==n->dds))
|
|
|
|
{
|
|
|
|
/* Duplicate packet */
|
|
|
|
debug("%s: Received duplicate dbdes from (%u)!\n", p->name, nrid);
|
2000-03-29 20:32:25 +08:00
|
|
|
if(n->imms.bit.ms==0)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
|
|
|
ospf_dbdes_tx(n);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-03-29 20:32:25 +08:00
|
|
|
if(ps->imms.bit.ms!=n->myimms.bit.m) /* M/S bit differs */
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2000-03-29 08:34:28 +08:00
|
|
|
DBG("SEQMIS-IMMS\n");
|
1999-11-17 23:50:41 +08:00
|
|
|
ospf_neigh_sm(n, INM_SEQMIS);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-03-29 20:32:25 +08:00
|
|
|
if(ps->imms.bit.i) /* I bit is set */
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2000-03-29 08:34:28 +08:00
|
|
|
DBG("SEQMIS-BIT-I\n");
|
1999-11-17 23:50:41 +08:00
|
|
|
ospf_neigh_sm(n, INM_SEQMIS);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ps->options!=n->options) /* Options differs */
|
|
|
|
{
|
2000-03-29 08:34:28 +08:00
|
|
|
DBG("SEQMIS-OPT\n");
|
1999-11-17 23:50:41 +08:00
|
|
|
ospf_neigh_sm(n, INM_SEQMIS);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-03-29 20:32:25 +08:00
|
|
|
if(n->myimms.bit.ms)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
|
|
|
if(ps->ddseq!=n->dds)
|
|
|
|
{
|
2000-03-29 08:34:28 +08:00
|
|
|
DBG("SEQMIS-MASTER\n");
|
1999-11-17 23:50:41 +08:00
|
|
|
ospf_neigh_sm(n, INM_SEQMIS);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(ps->ddseq!=(n->dds+1))
|
|
|
|
{
|
2000-03-29 08:34:28 +08:00
|
|
|
DBG("SEQMIS-SLAVE\n");
|
1999-11-17 23:50:41 +08:00
|
|
|
ospf_neigh_sm(n, INM_SEQMIS);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: Packet accepted, go on */
|
|
|
|
|
|
|
|
break;
|
|
|
|
case NEIGHBOR_LOADING:
|
|
|
|
case NEIGHBOR_FULL:
|
2000-03-29 20:32:25 +08:00
|
|
|
if((ps->imms.byte==n->imms.byte) && (ps->options=n->options) &&
|
1999-11-17 23:50:41 +08:00
|
|
|
(ps->ddseq==n->dds)) /* Only duplicate are accepted */
|
|
|
|
{
|
|
|
|
debug("%s: Received duplicate dbdes from (%u)!\n", p->name, nrid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ospf_neigh_sm(n, INM_SEQMIS);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
defaut:
|
|
|
|
die("%s: Received dbdes from %u in unknown state. (%u)\n", p->name, nrid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|