2000-03-31 04:00:42 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- OSPF
|
|
|
|
*
|
|
|
|
* (c) 2000 Ondrej Filip <feela@network.cz>
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ospf.h"
|
|
|
|
|
2000-04-18 09:06:16 +08:00
|
|
|
/* Note, that h is in network endianity! */
|
2000-03-31 04:00:42 +08:00
|
|
|
void
|
2000-04-18 09:06:16 +08:00
|
|
|
ospf_lsack_direct_tx(struct ospf_neighbor *n,struct ospf_lsa_header *h)
|
2000-03-31 04:00:42 +08:00
|
|
|
{
|
2000-04-18 09:06:16 +08:00
|
|
|
struct ospf_packet *op;
|
|
|
|
struct ospf_lsack_packet *pk;
|
|
|
|
sock *sk=n->ifa->ip_sk;
|
2000-05-10 02:17:34 +08:00
|
|
|
struct proto *p=&n->ifa->proto->proto;
|
2000-04-18 09:06:16 +08:00
|
|
|
u16 len;
|
|
|
|
|
2000-04-19 04:34:19 +08:00
|
|
|
DBG("Sending direct ACK to %I for Type: %u, ID: %I, RT: %I\n",n->rid,
|
|
|
|
h->type, ntohl(h->id), ntohl(h->rt));
|
2000-04-19 01:00:56 +08:00
|
|
|
|
2000-04-18 09:06:16 +08:00
|
|
|
pk=(struct ospf_lsack_packet *)sk->tbuf;
|
|
|
|
op=(struct ospf_packet *)sk->tbuf;
|
|
|
|
|
2000-04-19 03:44:16 +08:00
|
|
|
fill_ospf_pkt_hdr(n->ifa, pk, LSACK);
|
2000-04-18 09:06:16 +08:00
|
|
|
|
|
|
|
memcpy(pk+1,h,sizeof(struct ospf_lsa_header));
|
|
|
|
len=sizeof(struct ospf_lsack_packet)+sizeof(struct ospf_lsa_header);
|
|
|
|
op->length=htons(len);
|
|
|
|
ospf_pkt_finalize(n->ifa, op);
|
|
|
|
sk_send_to(sk,len, n->ip, OSPF_PROTO);
|
2000-05-10 02:17:34 +08:00
|
|
|
debug("%s: LS ack sent to %I\n", p->name, n->ip);
|
2000-04-18 09:06:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ospf_lsa_delay(struct ospf_neighbor *n,struct ospf_lsa_header *h,
|
|
|
|
struct proto *p)
|
|
|
|
{
|
|
|
|
struct lsah_n *no;
|
|
|
|
|
|
|
|
no=mb_alloc(p->pool,sizeof(struct lsah_n));
|
|
|
|
memcpy(&no->lsa,h,sizeof(struct ospf_lsa_header));
|
|
|
|
add_tail(&n->ackl, NODE no);
|
2000-04-19 01:36:46 +08:00
|
|
|
DBG("Adding delay ack for %I, ID: %I, RT: %I, Type: %u\n",n->rid,
|
|
|
|
ntohl(h->id), ntohl(h->rt),h->type);
|
2000-04-18 09:06:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ackd_timer_hook(timer *t)
|
|
|
|
{
|
|
|
|
struct ospf_neighbor *n=t->data;
|
|
|
|
if(!EMPTY_LIST(n->ackl)) ospf_lsack_delay_tx(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ospf_lsack_delay_tx(struct ospf_neighbor *n)
|
|
|
|
{
|
|
|
|
struct ospf_packet *op;
|
|
|
|
struct ospf_lsack_packet *pk;
|
|
|
|
sock *sk;
|
|
|
|
u16 len,i=0;
|
|
|
|
struct ospf_lsa_header *h;
|
|
|
|
struct lsah_n *no;
|
|
|
|
struct ospf_iface *ifa=n->ifa;
|
|
|
|
|
2000-05-12 06:00:16 +08:00
|
|
|
debug("%s: LS ack sent to %I (delayed)\n",n->ifa->proto->proto.name,n->ip);
|
2000-04-19 01:00:56 +08:00
|
|
|
|
2000-04-18 09:06:16 +08:00
|
|
|
if(ifa->type==OSPF_IT_BCAST)
|
|
|
|
{
|
|
|
|
sk=ifa->hello_sk;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sk=ifa->ip_sk;
|
|
|
|
}
|
|
|
|
|
|
|
|
pk=(struct ospf_lsack_packet *)sk->tbuf;
|
|
|
|
op=(struct ospf_packet *)sk->tbuf;
|
|
|
|
|
2000-04-19 03:44:16 +08:00
|
|
|
fill_ospf_pkt_hdr(n->ifa, pk, LSACK);
|
2000-04-18 09:06:16 +08:00
|
|
|
h=(struct ospf_lsa_header *)(pk+1);
|
|
|
|
|
|
|
|
while(!EMPTY_LIST(n->ackl))
|
|
|
|
{
|
|
|
|
no=(struct lsah_n *)HEAD(n->ackl);
|
|
|
|
memcpy(h+i,&no->lsa, sizeof(struct ospf_lsa_header));
|
|
|
|
i++;
|
2000-04-19 01:00:56 +08:00
|
|
|
DBG("Iter %u ID: %I, RT: %I, Type: %u\n",i, ntohl((h+i)->id),
|
|
|
|
ntohl((h+i)->rt),(h+i)->type);
|
|
|
|
rem_node(NODE no);
|
2000-04-19 01:36:46 +08:00
|
|
|
mb_free(no);
|
2000-04-19 01:00:56 +08:00
|
|
|
if((i*sizeof(struct ospf_lsa_header)+sizeof(struct ospf_lsack_packet)+SIPH)>
|
2000-04-18 09:06:16 +08:00
|
|
|
n->ifa->iface->mtu)
|
|
|
|
{
|
|
|
|
if(!EMPTY_LIST(n->ackl))
|
|
|
|
{
|
|
|
|
len=sizeof(struct ospf_lsack_packet)+i*sizeof(struct ospf_lsa_header);
|
|
|
|
op->length=htons(len);
|
|
|
|
ospf_pkt_finalize(n->ifa, op);
|
2000-04-19 01:36:46 +08:00
|
|
|
DBG("Sending and continueing! Len=%u\n",len);
|
2000-04-18 09:06:16 +08:00
|
|
|
if(ifa->type==OSPF_IT_BCAST)
|
|
|
|
{
|
|
|
|
if((ifa->state==OSPF_IS_DR)||(ifa->state==OSPF_IS_BACKUP))
|
|
|
|
{
|
|
|
|
sk_send_to(sk ,len, AllSPFRouters, OSPF_PROTO);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sk_send_to(sk ,len, AllDRouters, OSPF_PROTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sk_send_to_agt(sk, len, ifa, NEIGHBOR_EXCHANGE);
|
|
|
|
}
|
2000-04-19 01:36:46 +08:00
|
|
|
|
2000-04-19 03:44:16 +08:00
|
|
|
fill_ospf_pkt_hdr(n->ifa, pk, LSACK);
|
2000-04-18 09:06:16 +08:00
|
|
|
i=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
len=sizeof(struct ospf_lsack_packet)+i*sizeof(struct ospf_lsa_header);
|
|
|
|
op->length=htons(len);
|
|
|
|
ospf_pkt_finalize(n->ifa, op);
|
2000-04-19 01:00:56 +08:00
|
|
|
DBG("Sending! Len=%u\n",len);
|
2000-04-18 09:06:16 +08:00
|
|
|
if(ifa->type==OSPF_IT_BCAST)
|
|
|
|
{
|
|
|
|
if((ifa->state==OSPF_IS_DR)||(ifa->state==OSPF_IS_BACKUP))
|
|
|
|
{
|
|
|
|
sk_send_to(sk ,len, AllSPFRouters, OSPF_PROTO);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sk_send_to(sk ,len, AllDRouters, OSPF_PROTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sk_send_to_agt(sk, len, ifa, NEIGHBOR_EXCHANGE);
|
|
|
|
}
|
2000-03-31 04:00:42 +08:00
|
|
|
}
|
|
|
|
|
2000-04-18 09:06:16 +08:00
|
|
|
|
|
|
|
|
2000-03-31 04:00:42 +08:00
|
|
|
void
|
|
|
|
ospf_lsack_rx(struct ospf_lsack_packet *ps, struct proto *p,
|
|
|
|
struct ospf_iface *ifa, u16 size)
|
|
|
|
{
|
|
|
|
u32 nrid, myrid;
|
|
|
|
struct ospf_neighbor *n;
|
2000-04-12 23:20:13 +08:00
|
|
|
struct ospf_lsa_header lsa,*plsa;
|
2000-03-31 04:00:42 +08:00
|
|
|
int length;
|
2000-04-12 23:20:13 +08:00
|
|
|
u16 nolsa,i;
|
|
|
|
struct top_hash_entry *en;
|
2000-05-12 06:00:16 +08:00
|
|
|
u16 lenn=ntohs(ps->ospf_packet.length);
|
2000-03-31 04:00:42 +08:00
|
|
|
|
|
|
|
nrid=ntohl(ps->ospf_packet.routerid);
|
|
|
|
|
|
|
|
myrid=p->cf->global->router_id;
|
|
|
|
|
|
|
|
if((n=find_neigh(ifa, nrid))==NULL)
|
|
|
|
{
|
2000-05-10 02:17:34 +08:00
|
|
|
debug("%s: Received LS ack from unknown neigbor! (%I)\n", p->name,
|
2000-03-31 04:00:42 +08:00
|
|
|
nrid);
|
|
|
|
return ;
|
|
|
|
}
|
2000-04-12 23:37:52 +08:00
|
|
|
|
2000-05-12 06:00:16 +08:00
|
|
|
debug("%s: Received LS ack from %I\n", p->name, n->ip);
|
2000-05-10 02:17:34 +08:00
|
|
|
|
2000-05-12 06:00:16 +08:00
|
|
|
if(n->state<NEIGHBOR_EXCHANGE) return;
|
2000-05-10 02:17:34 +08:00
|
|
|
|
2000-05-12 06:00:16 +08:00
|
|
|
nolsa=(lenn-sizeof(struct ospf_lsack_packet))/
|
2000-04-12 23:20:13 +08:00
|
|
|
sizeof(struct ospf_lsa_header);
|
2000-05-12 06:00:16 +08:00
|
|
|
|
|
|
|
if((nolsa<1)||((lenn-sizeof(struct ospf_lsack_packet))!=
|
|
|
|
(nolsa*sizeof(struct ospf_lsa_header))))
|
|
|
|
{
|
|
|
|
log("%s: Received corrupted LS ack from %I\n", p->name, n->ip);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
plsa=(struct ospf_lsa_header *)(ps+1);
|
2000-04-12 23:20:13 +08:00
|
|
|
|
|
|
|
for(i=0;i<nolsa;i++)
|
|
|
|
{
|
|
|
|
ntohlsah(plsa+i,&lsa);
|
|
|
|
if((en=ospf_hash_find_header(n->lsrth,&lsa))==NULL) continue;
|
|
|
|
|
|
|
|
if(lsa_comp(&lsa,&en->lsa)!=CMP_SAME)
|
|
|
|
{
|
2000-05-12 06:00:16 +08:00
|
|
|
debug("%s: Strange LS acknoledgement from %I\n",p->name,n->ip);
|
|
|
|
debug("%s: Id: %I, Rt: %I, Type: %u\n",p->name,lsa.id,lsa.rt,lsa.type);
|
|
|
|
debug("%s: I have: Age: %4u, Seqno: 0x%08x\n",p->name,en->lsa.age,
|
|
|
|
en->lsa.sn);
|
|
|
|
debug("%s: He has: Age: %4u, Seqno: 0x%08x\n",p->name,lsa.age,lsa.sn);
|
2000-04-12 23:20:13 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2000-04-12 23:37:52 +08:00
|
|
|
DBG("Deleting LS Id: %I RT: %I Type: %u from LS Retl for neighbor %I\n",
|
2000-04-12 23:20:13 +08:00
|
|
|
lsa.id,lsa.rt,lsa.type,n->rid);
|
|
|
|
s_rem_node(SNODE en);
|
|
|
|
ospf_hash_delete(n->lsrth,en);
|
|
|
|
}
|
2000-03-31 04:00:42 +08:00
|
|
|
}
|