1999-11-10 12:27:01 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- OSPF Topological Database
|
|
|
|
*
|
2000-02-25 19:19:41 +00:00
|
|
|
* (c) 1999 Martin Mares <mj@ucw.cz>
|
|
|
|
* (c) 1999 - 2000 Ondrej Filip <feela@network.cz>
|
1999-11-10 12:27:01 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nest/bird.h"
|
2000-03-31 23:30:21 +00:00
|
|
|
#include "lib/string.h"
|
1999-11-10 12:27:01 +00:00
|
|
|
|
|
|
|
#include "ospf.h"
|
|
|
|
|
|
|
|
#define HASH_DEF_ORDER 6 /* FIXME: Increase */
|
|
|
|
#define HASH_HI_MARK *4
|
|
|
|
#define HASH_HI_STEP 2
|
|
|
|
#define HASH_HI_MAX 16
|
|
|
|
#define HASH_LO_MARK /5
|
|
|
|
#define HASH_LO_STEP 2
|
|
|
|
#define HASH_LO_MIN 8
|
|
|
|
|
2000-04-04 15:55:55 +00:00
|
|
|
void *
|
|
|
|
originate_rt_lsa_body(struct ospf_area *oa, u16 *length, struct proto_ospf *p)
|
2000-03-09 22:38:05 +00:00
|
|
|
{
|
|
|
|
struct ospf_iface *ifa;
|
2000-03-31 01:14:41 +00:00
|
|
|
int j=0,k=0,v=0,e=0,b=0;
|
|
|
|
u16 i=0;
|
2000-03-09 22:38:05 +00:00
|
|
|
struct ospf_lsa_rt *rt;
|
|
|
|
struct ospf_lsa_rt_link *ln;
|
|
|
|
struct ospf_neighbor *neigh;
|
|
|
|
struct top_hash_entry *old;
|
2000-04-04 15:55:55 +00:00
|
|
|
struct proto_ospf *po=(struct proto_ospf *)p;
|
2000-03-09 22:38:05 +00:00
|
|
|
|
2000-05-09 18:17:34 +00:00
|
|
|
DBG("%s: Originating RT_lsa body for area \"%I\".\n", po->proto.name,
|
|
|
|
oa->areaid);
|
2000-03-09 22:38:05 +00:00
|
|
|
|
2000-05-09 18:17:34 +00:00
|
|
|
WALK_LIST (ifa, p->iface_list)
|
2000-03-09 22:38:05 +00:00
|
|
|
{
|
|
|
|
if((ifa->an==oa->areaid) && (ifa->state!=OSPF_IS_DOWN))
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
if(ifa->type==OSPF_IT_VLINK) v=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rt=mb_allocz(p->proto.pool, sizeof(struct ospf_lsa_rt)+
|
|
|
|
i*sizeof(struct ospf_lsa_rt_link));
|
|
|
|
if((p->areano>1) && (!oa->stub)) e=1;
|
|
|
|
rt->VEB=(v>>LSA_RT_V)+(e>>LSA_RT_E)+(b>>LSA_RT_B);
|
|
|
|
ln=(struct ospf_lsa_rt_link *)(rt+1);
|
|
|
|
|
|
|
|
WALK_LIST (ifa, p->iface_list)
|
|
|
|
{
|
|
|
|
if((ifa->an==oa->areaid) && (ifa->state!=OSPF_IS_DOWN))
|
|
|
|
{
|
|
|
|
if(ifa->state==OSPF_IS_LOOP)
|
|
|
|
{
|
|
|
|
ln->type=3;
|
|
|
|
ln->id=ipa_to_u32(ifa->iface->addr->ip);
|
|
|
|
ln->data=0xffffffff;
|
|
|
|
ln->metric=0;
|
|
|
|
ln->notos=0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch(ifa->type)
|
|
|
|
{
|
|
|
|
case OSPF_IT_PTP: /* rfc2328 - pg126 */
|
|
|
|
neigh=(struct ospf_neighbor *)HEAD(ifa->neigh_list);
|
|
|
|
if((neigh!=NULL) || (neigh->state==NEIGHBOR_FULL))
|
|
|
|
{
|
|
|
|
ln->type=LSART_PTP;
|
|
|
|
ln->id=neigh->rid;
|
|
|
|
ln->metric=ifa->cost;
|
|
|
|
ln->notos=0;
|
|
|
|
if(ifa->iface->flags && IA_UNNUMBERED)
|
|
|
|
{
|
|
|
|
ln->data=ifa->iface->index;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ln->id=ipa_to_u32(ifa->iface->addr->ip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(ifa->state==OSPF_IS_PTP)
|
|
|
|
{
|
|
|
|
ln->type=LSART_STUB;
|
|
|
|
ln->id=ln->id=ipa_to_u32(ifa->iface->addr->opposite);
|
|
|
|
ln->metric=ifa->cost;
|
|
|
|
ln->notos=0;
|
|
|
|
ln->data=0xffffffff;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i--; /* No link added */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OSPF_IT_BCAST: /*FIXME Go on */
|
|
|
|
case OSPF_IT_NBMA:
|
|
|
|
if(ifa->state==OSPF_IS_WAITING)
|
|
|
|
{
|
|
|
|
ln->type=LSART_STUB;
|
|
|
|
ln->id=ipa_to_u32(ifa->iface->addr->prefix);
|
|
|
|
ln->data=ipa_to_u32(ipa_mkmask(ifa->iface->addr->pxlen));
|
|
|
|
ln->metric=ifa->cost;
|
|
|
|
ln->notos=0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
j=0,k=0;
|
|
|
|
WALK_LIST(neigh, ifa->neigh_list)
|
|
|
|
{
|
|
|
|
if((neigh->rid==ifa->drid) &&
|
|
|
|
(neigh->state==NEIGHBOR_FULL)) k=1;
|
|
|
|
if(neigh->state==NEIGHBOR_FULL) j=1;
|
|
|
|
}
|
2000-05-04 01:23:03 +00:00
|
|
|
if(((ifa->state==OSPF_IS_DR) && (j==1)) || (k==1))
|
2000-03-09 22:38:05 +00:00
|
|
|
{
|
|
|
|
ln->type=LSART_NET;
|
|
|
|
ln->id=ipa_to_u32(ifa->drip);
|
|
|
|
ln->data=ipa_to_u32(ifa->iface->addr->ip);
|
|
|
|
ln->metric=ifa->cost;
|
|
|
|
ln->notos=0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ln->type=LSART_STUB;
|
|
|
|
ln->id=ipa_to_u32(ifa->iface->addr->prefix);
|
|
|
|
ln->data=ipa_to_u32(ipa_mkmask(ifa->iface->addr->pxlen));
|
|
|
|
ln->metric=ifa->cost;
|
|
|
|
ln->notos=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OSPF_IT_VLINK: /* FIXME Add virtual links! */
|
|
|
|
i--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(ifa->type==OSPF_IT_VLINK) v=1;
|
|
|
|
}
|
|
|
|
ln=(ln+1);
|
|
|
|
}
|
|
|
|
rt->links=i;
|
2000-04-04 15:55:55 +00:00
|
|
|
*length=i*sizeof(struct ospf_lsa_rt_link)+sizeof(struct ospf_lsa_rt)+
|
|
|
|
sizeof(struct ospf_lsa_header);
|
|
|
|
return rt;
|
2000-03-09 22:38:05 +00:00
|
|
|
}
|
2000-05-02 22:19:41 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
age_timer_hook(timer *timer)
|
|
|
|
{
|
|
|
|
struct ospf_area *oa=timer->data;
|
|
|
|
bird_clock_t delta;
|
|
|
|
struct top_hash_entry *en,*nxt;
|
|
|
|
int flush=0;
|
|
|
|
|
2000-05-03 22:36:12 +00:00
|
|
|
flush=can_flush_lsa(oa);
|
2000-05-02 22:19:41 +00:00
|
|
|
|
|
|
|
if((delta=now-oa->lage)>=AGINGDELTA)
|
|
|
|
{
|
2000-05-03 22:23:41 +00:00
|
|
|
WALK_SLIST_DELSAFE(en,nxt,oa->lsal) ospf_age(en,delta,flush,oa);
|
2000-05-02 22:19:41 +00:00
|
|
|
oa->lage=now;
|
|
|
|
}
|
|
|
|
}
|
2000-03-09 22:38:05 +00:00
|
|
|
|
|
|
|
|
2000-02-24 00:26:10 +00:00
|
|
|
void
|
|
|
|
addifa_rtlsa(struct ospf_iface *ifa)
|
|
|
|
{
|
|
|
|
struct ospf_area *oa;
|
2000-05-02 22:19:41 +00:00
|
|
|
struct proto_ospf *po=ifa->proto;
|
2000-02-25 19:19:41 +00:00
|
|
|
u32 rtid;
|
|
|
|
struct top_graph_rtlsa_link *li, *lih;
|
2000-02-24 00:26:10 +00:00
|
|
|
|
2000-02-25 19:19:41 +00:00
|
|
|
rtid=po->proto.cf->global->router_id;
|
2000-04-03 22:31:07 +00:00
|
|
|
DBG("%s: New OSPF area \"%d\" adding.\n", po->proto.name, ifa->an);
|
|
|
|
oa=NULL;
|
2000-02-24 00:26:10 +00:00
|
|
|
|
2000-04-03 22:31:07 +00:00
|
|
|
|
|
|
|
WALK_LIST(NODE oa,po->area_list)
|
2000-02-24 00:26:10 +00:00
|
|
|
{
|
2000-03-08 12:50:28 +00:00
|
|
|
if(oa->areaid==ifa->an) break;
|
2000-02-24 00:26:10 +00:00
|
|
|
}
|
2000-03-08 12:50:28 +00:00
|
|
|
|
2000-04-03 22:31:07 +00:00
|
|
|
if(EMPTY_LIST(po->area_list) || (oa->areaid!=ifa->an)) /* New area */
|
2000-02-24 00:26:10 +00:00
|
|
|
{
|
2000-03-29 00:34:28 +00:00
|
|
|
struct ospf_lsa_header *lsa;
|
|
|
|
|
2000-04-26 12:54:23 +00:00
|
|
|
oa=mb_allocz(po->proto.pool, sizeof(struct ospf_area));
|
2000-04-03 22:31:07 +00:00
|
|
|
add_tail(&po->area_list,NODE oa);
|
2000-03-08 12:50:28 +00:00
|
|
|
oa->areaid=ifa->an;
|
2000-02-25 19:19:41 +00:00
|
|
|
oa->gr=ospf_top_new(po);
|
2000-03-08 12:50:28 +00:00
|
|
|
s_init_list(&(oa->lsal));
|
2000-04-04 15:55:55 +00:00
|
|
|
oa->rt=NULL;
|
2000-05-02 22:19:41 +00:00
|
|
|
oa->lage=now;
|
|
|
|
oa->po=po;
|
|
|
|
oa->age_timer=tm_new(po->proto.pool);
|
|
|
|
oa->age_timer->data=oa;
|
|
|
|
oa->age_timer->randomize=0;
|
|
|
|
oa->age_timer->hook=age_timer_hook;
|
|
|
|
oa->age_timer->recurrent=AGINGDELTA;
|
|
|
|
tm_start(oa->age_timer,AGINGDELTA);
|
2000-05-04 01:23:03 +00:00
|
|
|
fib_init(&oa->infib,po->proto.pool,sizeof(struct infib),16,init_infib);
|
|
|
|
/* FIXME 16?? (Oh, sweet 16.... :-) */
|
2000-04-03 22:31:07 +00:00
|
|
|
po->areano++;
|
2000-03-08 12:50:28 +00:00
|
|
|
DBG("%s: New OSPF area \"%d\" added.\n", po->proto.name, ifa->an);
|
2000-02-25 19:19:41 +00:00
|
|
|
}
|
2000-04-03 22:31:07 +00:00
|
|
|
|
|
|
|
ifa->oa=oa;
|
2000-04-04 15:55:55 +00:00
|
|
|
|
2000-05-03 00:08:48 +00:00
|
|
|
originate_rt_lsa(oa,po);
|
2000-04-30 22:14:31 +00:00
|
|
|
DBG("RT LSA: rt: %I, id: %I, type: %u\n",oa->rt->lsa.rt,oa->rt->lsa.id,oa->rt->lsa.type);
|
2000-05-30 17:51:22 +00:00
|
|
|
flood_lsa(NULL,NULL,&oa->rt->lsa,po,NULL,oa,1);
|
2000-04-04 15:55:55 +00:00
|
|
|
}
|
|
|
|
|
2000-05-03 00:08:48 +00:00
|
|
|
void
|
2000-04-04 15:55:55 +00:00
|
|
|
originate_rt_lsa(struct ospf_area *oa, struct proto_ospf *po)
|
|
|
|
{
|
|
|
|
struct ospf_lsa_header lsa;
|
|
|
|
u32 rtid=po->proto.cf->global->router_id;
|
|
|
|
struct top_hash_entry *en;
|
|
|
|
void *body;
|
|
|
|
|
2000-05-09 18:17:34 +00:00
|
|
|
debug("%s: Originating RT_lsa for area \"%I\".\n",po->proto.name,oa->areaid);
|
2000-04-04 15:55:55 +00:00
|
|
|
|
|
|
|
lsa.age=0;
|
|
|
|
lsa.id=rtid;
|
|
|
|
lsa.type=LSA_T_RT;
|
|
|
|
lsa.rt=rtid;
|
2000-05-30 17:51:22 +00:00
|
|
|
lsa.options=0;
|
2000-04-04 15:55:55 +00:00
|
|
|
if(oa->rt==NULL)
|
|
|
|
{
|
|
|
|
lsa.sn=LSA_INITSEQNO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lsa.sn=oa->rt->lsa.sn+1;
|
|
|
|
}
|
|
|
|
body=originate_rt_lsa_body(oa, &lsa.length, po);
|
|
|
|
lsasum_calculate(&lsa,body,po);
|
2000-04-30 22:14:31 +00:00
|
|
|
en=lsa_install_new(&lsa, body, oa, &po->proto);
|
2000-05-03 00:08:48 +00:00
|
|
|
oa->rt=en;
|
2000-05-30 17:51:22 +00:00
|
|
|
flood_lsa(NULL,NULL,&oa->rt->lsa,po,NULL,oa,1);
|
2000-02-24 00:26:10 +00:00
|
|
|
}
|
|
|
|
|
2000-05-02 23:09:44 +00:00
|
|
|
void *
|
|
|
|
originate_net_lsa_body(struct ospf_iface *ifa, u16 *length,
|
|
|
|
struct proto_ospf *po)
|
|
|
|
{
|
|
|
|
u16 i=1;
|
|
|
|
struct ospf_neighbor *n;
|
|
|
|
u32 *body;
|
2000-05-04 01:23:03 +00:00
|
|
|
struct ospf_lsa_net *net;
|
2000-05-02 23:09:44 +00:00
|
|
|
|
2000-05-04 01:23:03 +00:00
|
|
|
net=mb_alloc(po->proto.pool,sizeof(u32)*(ifa->fadj+1)+
|
|
|
|
sizeof(struct ospf_lsa_net));
|
|
|
|
net->netmask=ipa_mkmask(ifa->iface->addr->pxlen);
|
|
|
|
|
|
|
|
body=(u32 *)(net+1);
|
2000-05-02 23:09:44 +00:00
|
|
|
i=1;
|
|
|
|
*body=po->proto.cf->global->router_id;
|
|
|
|
WALK_LIST(n,ifa->neigh_list)
|
|
|
|
{
|
|
|
|
if(n->state==NEIGHBOR_FULL)
|
|
|
|
{
|
|
|
|
*(body+i)=n->rid;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2000-05-04 01:23:03 +00:00
|
|
|
*length=i*sizeof(u32)+sizeof(struct ospf_lsa_header)+
|
|
|
|
sizeof(struct ospf_lsa_net);
|
|
|
|
return net;
|
2000-05-02 23:09:44 +00:00
|
|
|
}
|
|
|
|
|
2000-05-03 00:08:48 +00:00
|
|
|
void
|
2000-05-02 23:09:44 +00:00
|
|
|
originate_net_lsa(struct ospf_iface *ifa, struct proto_ospf *po)
|
|
|
|
{
|
|
|
|
struct ospf_lsa_header lsa;
|
|
|
|
u32 rtid=po->proto.cf->global->router_id;
|
|
|
|
struct top_hash_entry *en;
|
|
|
|
void *body;
|
|
|
|
|
2000-05-09 18:17:34 +00:00
|
|
|
debug("%s: Originating Net lsa for iface \"%s\".\n", po->proto.name,
|
|
|
|
ifa->iface->name);
|
2000-05-09 11:27:31 +00:00
|
|
|
|
2000-05-30 17:51:22 +00:00
|
|
|
if((ifa->state!=OSPF_IS_DR)||(ifa->fadj==0))
|
2000-05-03 00:08:48 +00:00
|
|
|
{
|
|
|
|
if(ifa->nlsa==NULL) return;
|
|
|
|
|
2000-05-30 17:51:22 +00:00
|
|
|
ifa->nlsa->lsa.sn+=1;
|
|
|
|
ifa->nlsa->lsa.age=LSA_MAXAGE;
|
|
|
|
flood_lsa(NULL,NULL,&ifa->nlsa->lsa,po,NULL,ifa->oa,0);
|
|
|
|
ospf_hash_delete(ifa->oa->gr, ifa->nlsa);
|
2000-05-03 00:08:48 +00:00
|
|
|
ifa->nlsa=NULL;
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2000-05-02 23:09:44 +00:00
|
|
|
lsa.age=0;
|
2000-05-30 17:51:22 +00:00
|
|
|
lsa.id=ipa_to_u32(ifa->iface->addr->ip);
|
2000-05-02 23:09:44 +00:00
|
|
|
lsa.type=LSA_T_NET;
|
|
|
|
lsa.rt=rtid;
|
2000-05-30 17:51:22 +00:00
|
|
|
lsa.options=0;
|
2000-05-02 23:09:44 +00:00
|
|
|
if(ifa->nlsa==NULL)
|
|
|
|
{
|
|
|
|
lsa.sn=LSA_INITSEQNO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-05-30 17:51:22 +00:00
|
|
|
lsa.sn=ifa->nlsa->lsa.sn+1;
|
2000-05-02 23:09:44 +00:00
|
|
|
}
|
2000-05-30 17:51:22 +00:00
|
|
|
|
2000-05-02 23:09:44 +00:00
|
|
|
body=originate_net_lsa_body(ifa, &lsa.length, po);
|
|
|
|
lsasum_calculate(&lsa,body,po);
|
2000-05-11 17:14:57 +00:00
|
|
|
ifa->nlsa=lsa_install_new(&lsa, body, ifa->oa, &po->proto);
|
2000-05-30 17:51:22 +00:00
|
|
|
flood_lsa(NULL,NULL,&ifa->nlsa->lsa,po,NULL,ifa->oa,1);
|
2000-05-02 23:09:44 +00:00
|
|
|
}
|
|
|
|
|
2000-05-30 21:25:32 +00:00
|
|
|
static void *
|
|
|
|
originate_ext_lsa_body(net *n, rte *e, struct proto_ospf *po, struct ea_list *attrs)
|
2000-05-27 14:17:35 +00:00
|
|
|
{
|
|
|
|
struct proto *p=&po->proto;
|
|
|
|
struct ospf_lsa_ext *ext;
|
|
|
|
struct ospf_lsa_ext_tos *et;
|
|
|
|
neighbor *nn;
|
2000-05-30 21:25:32 +00:00
|
|
|
u32 m1 = ea_get_int(attrs, EA_OSPF_METRIC1, 0);
|
|
|
|
u32 m2 = ea_get_int(attrs, EA_OSPF_METRIC2, 0);
|
|
|
|
u32 tag = ea_get_int(attrs, EA_OSPF_TAG, 0);
|
2000-05-27 14:17:35 +00:00
|
|
|
|
|
|
|
ext=mb_alloc(p->pool,sizeof(struct ospf_lsa_ext)+
|
|
|
|
sizeof(struct ospf_lsa_ext_tos));
|
|
|
|
ext->netmask=ipa_mkmask(n->n.pxlen);
|
|
|
|
|
|
|
|
et=(struct ospf_lsa_ext_tos *)(ext+1);
|
2000-05-30 21:25:32 +00:00
|
|
|
|
|
|
|
if(!m2)
|
|
|
|
{
|
|
|
|
et->etos=0;
|
|
|
|
et->metric=m1;
|
|
|
|
}
|
2000-05-27 14:17:35 +00:00
|
|
|
else
|
2000-05-30 21:25:32 +00:00
|
|
|
{
|
|
|
|
et->etos=0x80;
|
|
|
|
et->metric=m2;
|
|
|
|
}
|
2000-05-27 14:17:35 +00:00
|
|
|
et->padding=0;
|
2000-05-30 21:25:32 +00:00
|
|
|
et->tag=tag;
|
2000-05-27 14:17:35 +00:00
|
|
|
if(1) et->fwaddr= ipa_from_u32(0); /* FIXME if e->attrs->iface is not in my AS*/
|
|
|
|
else et->fwaddr=e->attrs->gw;
|
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-05-30 21:25:32 +00:00
|
|
|
originate_ext_lsa(net *n, rte *e, struct proto_ospf *po, struct ea_list *attrs)
|
2000-05-27 14:17:35 +00:00
|
|
|
{
|
|
|
|
struct ospf_lsa_header lsa;
|
|
|
|
u32 rtid=po->proto.cf->global->router_id;
|
|
|
|
struct top_hash_entry *en=NULL;
|
|
|
|
void *body=NULL;
|
|
|
|
struct ospf_iface *ifa;
|
|
|
|
|
|
|
|
debug("%s: Originating Ext lsa for %I/%d.\n", po->proto.name, n->n.prefix,
|
|
|
|
n->n.pxlen);
|
|
|
|
|
|
|
|
lsa.age=0;
|
|
|
|
lsa.id=ipa_to_u32(n->n.prefix);
|
|
|
|
lsa.type=LSA_T_EXT;
|
|
|
|
lsa.rt=rtid;
|
|
|
|
lsa.sn=LSA_INITSEQNO;
|
2000-05-30 21:25:32 +00:00
|
|
|
body=originate_ext_lsa_body(n, e, po, attrs);
|
2000-05-27 14:17:35 +00:00
|
|
|
lsa.length=sizeof(struct ospf_lsa_ext)+sizeof(struct ospf_lsa_ext_tos)+
|
|
|
|
sizeof(struct ospf_lsa_header);
|
|
|
|
lsasum_calculate(&lsa,body,po);
|
|
|
|
WALK_LIST(ifa, po->iface_list)
|
|
|
|
{
|
|
|
|
en=lsa_install_new(&lsa, body, ifa->oa, &po->proto);
|
|
|
|
}
|
|
|
|
if(en==NULL) die("Some bug in Ext lsa generating\n");
|
2000-05-30 17:51:22 +00:00
|
|
|
flood_lsa(NULL,NULL,&en->lsa,po,NULL,ifa->oa,1);
|
2000-05-27 14:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-10 12:27:01 +00:00
|
|
|
static void
|
|
|
|
ospf_top_ht_alloc(struct top_graph *f)
|
|
|
|
{
|
|
|
|
f->hash_size = 1 << f->hash_order;
|
|
|
|
f->hash_mask = f->hash_size - 1;
|
|
|
|
if (f->hash_order > HASH_HI_MAX - HASH_HI_STEP)
|
|
|
|
f->hash_entries_max = ~0;
|
|
|
|
else
|
|
|
|
f->hash_entries_max = f->hash_size HASH_HI_MARK;
|
|
|
|
if (f->hash_order < HASH_LO_MIN + HASH_LO_STEP)
|
|
|
|
f->hash_entries_min = 0;
|
|
|
|
else
|
|
|
|
f->hash_entries_min = f->hash_size HASH_LO_MARK;
|
|
|
|
DBG("Allocating OSPF hash of order %d: %d hash_entries, %d low, %d high\n",
|
|
|
|
f->hash_order, f->hash_size, f->hash_entries_min, f->hash_entries_max);
|
|
|
|
f->hash_table = mb_alloc(f->pool, f->hash_size * sizeof(struct top_hash_entry *));
|
|
|
|
bzero(f->hash_table, f->hash_size * sizeof(struct top_hash_entry *));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
ospf_top_ht_free(struct top_hash_entry **h)
|
|
|
|
{
|
|
|
|
mb_free(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32
|
|
|
|
ospf_top_hash_u32(u32 a)
|
|
|
|
{
|
|
|
|
/* Shamelessly stolen from IP address hashing in ipv4.h */
|
|
|
|
a ^= a >> 16;
|
|
|
|
a ^= a << 10;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned
|
|
|
|
ospf_top_hash(struct top_graph *f, u32 lsaid, u32 rtrid, u32 type)
|
|
|
|
{
|
2000-04-30 22:14:31 +00:00
|
|
|
#if 1 /* Dirty patch to make rt table calculation work. */
|
|
|
|
return (ospf_top_hash_u32(lsaid) + ospf_top_hash_u32((type==2) ? lsaid : rtrid) + type) & f->hash_mask;
|
|
|
|
#else
|
1999-11-10 12:27:01 +00:00
|
|
|
return (ospf_top_hash_u32(lsaid) + ospf_top_hash_u32(rtrid) + type) & f->hash_mask;
|
2000-04-30 22:14:31 +00:00
|
|
|
#endif
|
1999-11-10 12:27:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct top_graph *
|
|
|
|
ospf_top_new(struct proto_ospf *p)
|
|
|
|
{
|
|
|
|
struct top_graph *f;
|
|
|
|
|
|
|
|
f = mb_allocz(p->proto.pool, sizeof(struct top_graph));
|
|
|
|
f->pool = p->proto.pool;
|
|
|
|
f->hash_slab = sl_new(f->pool, sizeof(struct top_hash_entry));
|
|
|
|
f->hash_order = HASH_DEF_ORDER;
|
|
|
|
ospf_top_ht_alloc(f);
|
|
|
|
f->hash_entries = 0;
|
|
|
|
f->hash_entries_min = 0;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ospf_top_free(struct top_graph *f)
|
|
|
|
{
|
|
|
|
rfree(f->hash_slab);
|
|
|
|
ospf_top_ht_free(f->hash_table);
|
|
|
|
mb_free(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ospf_top_rehash(struct top_graph *f, int step)
|
|
|
|
{
|
|
|
|
unsigned int oldn, oldh;
|
|
|
|
struct top_hash_entry **n, **oldt, **newt, *e, *x;
|
|
|
|
|
|
|
|
oldn = f->hash_size;
|
|
|
|
oldt = f->hash_table;
|
|
|
|
DBG("Re-hashing topology hash from order %d to %d\n", f->hash_order, f->hash_order+step);
|
|
|
|
f->hash_order += step;
|
|
|
|
ospf_top_ht_alloc(f);
|
|
|
|
newt = f->hash_table;
|
|
|
|
|
|
|
|
for(oldh=0; oldh < oldn; oldh++)
|
|
|
|
{
|
|
|
|
e = oldt[oldh];
|
|
|
|
while (e)
|
|
|
|
{
|
|
|
|
x = e->next;
|
2000-03-09 22:38:05 +00:00
|
|
|
n = newt + ospf_top_hash(f, e->lsa.id, e->lsa.rt, e->lsa.type);
|
1999-11-10 12:27:01 +00:00
|
|
|
e->next = *n;
|
|
|
|
*n = e;
|
|
|
|
e = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ospf_top_ht_free(oldt);
|
|
|
|
}
|
|
|
|
|
2000-04-04 00:32:17 +00:00
|
|
|
struct top_hash_entry *
|
|
|
|
ospf_hash_find_header(struct top_graph *f, struct ospf_lsa_header *h)
|
|
|
|
{
|
|
|
|
return ospf_hash_find(f,h->id,h->rt,h->type);
|
|
|
|
}
|
2000-04-04 15:55:55 +00:00
|
|
|
|
|
|
|
struct top_hash_entry *
|
|
|
|
ospf_hash_get_header(struct top_graph *f, struct ospf_lsa_header *h)
|
|
|
|
{
|
|
|
|
return ospf_hash_get(f,h->id,h->rt,h->type);
|
|
|
|
}
|
|
|
|
|
1999-11-10 12:27:01 +00:00
|
|
|
struct top_hash_entry *
|
|
|
|
ospf_hash_find(struct top_graph *f, u32 lsa, u32 rtr, u32 type)
|
|
|
|
{
|
|
|
|
struct top_hash_entry *e = f->hash_table[ospf_top_hash(f, lsa, rtr, type)];
|
|
|
|
|
2000-04-30 22:14:31 +00:00
|
|
|
#if 1
|
|
|
|
if(type==2 && lsa==rtr)
|
|
|
|
{
|
|
|
|
while (e && (e->lsa.id != lsa || e->lsa.type != 2 ))
|
|
|
|
e = e->next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (e && (e->lsa.id != lsa || e->lsa.type != type || e->lsa.rt != rtr))
|
|
|
|
e = e->next;
|
|
|
|
}
|
|
|
|
#else
|
2000-03-09 22:38:05 +00:00
|
|
|
while (e && (e->lsa.id != lsa || e->lsa.rt != rtr || e->lsa.type != type))
|
1999-11-10 12:27:01 +00:00
|
|
|
e = e->next;
|
2000-04-30 22:14:31 +00:00
|
|
|
#endif
|
1999-11-10 12:27:01 +00:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct top_hash_entry *
|
|
|
|
ospf_hash_get(struct top_graph *f, u32 lsa, u32 rtr, u32 type)
|
|
|
|
{
|
|
|
|
struct top_hash_entry **ee = f->hash_table + ospf_top_hash(f, lsa, rtr, type);
|
|
|
|
struct top_hash_entry *e = *ee;
|
|
|
|
|
2000-03-09 22:38:05 +00:00
|
|
|
while (e && (e->lsa.id != lsa || e->lsa.rt != rtr || e->lsa.type != type))
|
1999-11-10 12:27:01 +00:00
|
|
|
e = e->next;
|
|
|
|
if (e)
|
|
|
|
return e;
|
|
|
|
e = sl_alloc(f->hash_slab);
|
2000-03-09 22:38:05 +00:00
|
|
|
e->lsa.id = lsa;
|
|
|
|
e->lsa.rt = rtr;
|
|
|
|
e->lsa.type = type;
|
|
|
|
e->lsa_body = NULL;
|
2000-04-30 11:31:05 +00:00
|
|
|
e->nhi=NULL;
|
2000-02-25 19:19:41 +00:00
|
|
|
e->next=*ee; /* MJ you forgot this :-) */
|
|
|
|
*ee=e;
|
1999-11-10 12:27:01 +00:00
|
|
|
if (f->hash_entries++ > f->hash_entries_max)
|
|
|
|
ospf_top_rehash(f, HASH_HI_STEP);
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ospf_hash_delete(struct top_graph *f, struct top_hash_entry *e)
|
|
|
|
{
|
2000-03-09 22:38:05 +00:00
|
|
|
unsigned int h = ospf_top_hash(f, e->lsa.id, e->lsa.rt, e->lsa.type);
|
1999-11-10 12:27:01 +00:00
|
|
|
struct top_hash_entry **ee = f->hash_table + h;
|
|
|
|
|
|
|
|
while (*ee)
|
|
|
|
{
|
|
|
|
if (*ee == e)
|
|
|
|
{
|
|
|
|
*ee = e->next;
|
|
|
|
sl_free(f->hash_slab, e);
|
|
|
|
if (f->hash_entries-- < f->hash_entries_min)
|
|
|
|
ospf_top_rehash(f, -HASH_LO_STEP);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ee = &((*ee)->next);
|
|
|
|
}
|
|
|
|
bug("ospf_hash_delete() called for invalid node");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ospf_top_dump(struct top_graph *f)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
2000-02-25 19:19:41 +00:00
|
|
|
debug("Hash entries: %d\n", f->hash_entries);
|
1999-11-10 12:27:01 +00:00
|
|
|
|
|
|
|
for(i=0; i<f->hash_size; i++)
|
|
|
|
{
|
|
|
|
struct top_hash_entry *e = f->hash_table[i];
|
|
|
|
while (e)
|
|
|
|
{
|
2000-05-09 19:38:34 +00:00
|
|
|
debug("\t%1x %8I %8I %4u 0x%08x\n", e->lsa.type, e->lsa.id,
|
|
|
|
e->lsa.rt, e->lsa.age, e->lsa.sn);
|
1999-11-10 12:27:01 +00:00
|
|
|
e = e->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-25 19:19:41 +00:00
|
|
|
|
2000-05-03 22:12:33 +00:00
|
|
|
/* This is very uneficient, please don't call it often */
|
|
|
|
|
|
|
|
/* I should also test for every LSA if it's in some link state
|
|
|
|
* retransmision list for every neighbor. I will not test it.
|
|
|
|
* It can happen that I'll receive some strange ls ack's.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
can_flush_lsa(struct ospf_area *oa)
|
|
|
|
{
|
|
|
|
struct ospf_iface *ifa;
|
|
|
|
struct ospf_neighbor *n;
|
|
|
|
struct proto_ospf *po=oa->po;
|
|
|
|
|
|
|
|
WALK_LIST(ifa, iface_list)
|
|
|
|
{
|
|
|
|
if(ifa->oa==oa)
|
|
|
|
{
|
|
|
|
WALK_LIST(n, ifa->neigh_list)
|
|
|
|
{
|
2000-05-03 22:36:12 +00:00
|
|
|
if((n->state==NEIGHBOR_EXCHANGE)||(n->state==NEIGHBOR_LOADING))
|
2000-05-03 22:12:33 +00:00
|
|
|
{
|
2000-05-03 22:36:12 +00:00
|
|
|
return 0;
|
2000-05-03 22:12:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-03 22:36:12 +00:00
|
|
|
return 1;
|
2000-05-03 22:12:33 +00:00
|
|
|
}
|