1999-11-10 20:27:01 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- OSPF Topological Database
|
|
|
|
*
|
2004-06-26 00:39:53 +08:00
|
|
|
* (c) 1999 Martin Mares <mj@ucw.cz>
|
|
|
|
* (c) 1999--2004 Ondrej Filip <feela@network.cz>
|
1999-11-10 20:27:01 +08:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nest/bird.h"
|
2000-04-01 07:30:21 +08:00
|
|
|
#include "lib/string.h"
|
1999-11-10 20:27:01 +08:00
|
|
|
|
|
|
|
#include "ospf.h"
|
|
|
|
|
2000-06-08 20:04:57 +08:00
|
|
|
#define HASH_DEF_ORDER 6
|
1999-11-10 20:27:01 +08:00
|
|
|
#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
|
|
|
|
|
2008-10-27 06:43:13 +08:00
|
|
|
int ptp_unnumbered_stub_lsa = 0;
|
|
|
|
|
2009-06-11 05:45:08 +08:00
|
|
|
static void *
|
|
|
|
lsab_alloc(struct proto_ospf *po, unsigned size)
|
|
|
|
{
|
|
|
|
unsigned offset = po->lsab_used;
|
|
|
|
po->lsab_used += size;
|
|
|
|
if (po->lsab_used > po->lsab_size)
|
|
|
|
{
|
|
|
|
po->lsab_size = MAX(po->lsab_used, 2 * po->lsab_size);
|
|
|
|
po->lsab = mb_realloc(po->proto.pool, po->lsab, po->lsab_size);
|
|
|
|
}
|
|
|
|
return ((byte *) po->lsab) + offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *
|
|
|
|
lsab_allocz(struct proto_ospf *po, unsigned size)
|
|
|
|
{
|
|
|
|
void *r = lsab_alloc(po, size);
|
|
|
|
bzero(r, size);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *
|
|
|
|
lsab_flush(struct proto_ospf *po)
|
|
|
|
{
|
|
|
|
void *r = mb_alloc(po->proto.pool, po->lsab_size);
|
|
|
|
memcpy(r, po->lsab, po->lsab_used);
|
|
|
|
po->lsab_used = 0;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2009-06-11 23:25:38 +08:00
|
|
|
static int
|
|
|
|
configured_stubnet(struct ospf_area *oa, struct ifa *a)
|
|
|
|
{
|
|
|
|
struct ospf_stubnet_config *sn;
|
|
|
|
WALK_LIST(sn, oa->ac->stubnet_list)
|
|
|
|
{
|
|
|
|
if (sn->summary)
|
|
|
|
{
|
|
|
|
if (ipa_in_net(a->prefix, sn->px.addr, sn->px.len) && (a->pxlen >= sn->px.len))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ipa_equal(a->prefix, sn->px.addr) && (a->pxlen == sn->px.len))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2009-06-11 05:45:08 +08:00
|
|
|
|
2004-06-05 17:58:23 +08:00
|
|
|
static void *
|
2004-06-06 16:55:33 +08:00
|
|
|
originate_rt_lsa_body(struct ospf_area *oa, u16 * length)
|
2000-03-10 06:38:05 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
struct proto_ospf *po = oa->po;
|
2000-03-10 06:38:05 +08:00
|
|
|
struct ospf_iface *ifa;
|
2009-06-11 05:45:08 +08:00
|
|
|
int i = 0, j = 0, k = 0, bitv = 0;
|
2000-03-10 06:38:05 +08:00
|
|
|
struct ospf_lsa_rt *rt;
|
2009-06-11 05:45:08 +08:00
|
|
|
struct ospf_lsa_rt_link *ln;
|
2000-03-10 06:38:05 +08:00
|
|
|
struct ospf_neighbor *neigh;
|
|
|
|
|
2000-05-10 02:17:34 +08:00
|
|
|
DBG("%s: Originating RT_lsa body for area \"%I\".\n", po->proto.name,
|
2004-06-06 16:55:33 +08:00
|
|
|
oa->areaid);
|
2009-06-11 05:45:08 +08:00
|
|
|
|
|
|
|
ASSERT(po->lsab_used == 0);
|
|
|
|
rt = lsab_allocz(po, sizeof(struct ospf_lsa_rt));
|
2004-06-06 16:55:33 +08:00
|
|
|
if (po->areano > 1)
|
|
|
|
rt->veb.bit.b = 1;
|
|
|
|
if ((po->ebit) && (!oa->stub))
|
|
|
|
rt->veb.bit.e = 1;
|
2009-06-11 05:45:08 +08:00
|
|
|
rt = NULL; /* buffer might be reallocated later */
|
2004-06-06 16:55:33 +08:00
|
|
|
|
|
|
|
WALK_LIST(ifa, po->iface_list)
|
2000-03-10 06:38:05 +08:00
|
|
|
{
|
2009-06-11 05:45:08 +08:00
|
|
|
int master = 0;
|
|
|
|
|
|
|
|
if ((ifa->type == OSPF_IT_VLINK) && (ifa->voa == oa) &&
|
|
|
|
(!EMPTY_LIST(ifa->neigh_list)))
|
2005-02-14 07:36:31 +08:00
|
|
|
{
|
|
|
|
neigh = (struct ospf_neighbor *) HEAD(ifa->neigh_list);
|
|
|
|
if ((neigh->state == NEIGHBOR_FULL) && (ifa->cost <= 0xffff))
|
2009-06-11 05:45:08 +08:00
|
|
|
bitv = 1;
|
2005-02-14 07:36:31 +08:00
|
|
|
}
|
2004-07-15 05:46:20 +08:00
|
|
|
|
|
|
|
if ((ifa->oa != oa) || (ifa->state == OSPF_IS_DOWN))
|
2004-06-06 16:55:33 +08:00
|
|
|
continue;
|
2000-06-06 04:57:53 +08:00
|
|
|
|
2009-06-11 05:45:08 +08:00
|
|
|
/* BIRD does not support interface loops */
|
|
|
|
ASSERT(ifa->state != OSPF_IS_LOOP);
|
2008-10-27 06:43:13 +08:00
|
|
|
|
2009-06-11 05:45:08 +08:00
|
|
|
switch (ifa->type)
|
2000-03-10 06:38:05 +08:00
|
|
|
{
|
2009-06-11 05:45:08 +08:00
|
|
|
case OSPF_IT_PTP: /* RFC2328 - 12.4.1.1 */
|
2004-06-06 16:55:33 +08:00
|
|
|
neigh = (struct ospf_neighbor *) HEAD(ifa->neigh_list);
|
|
|
|
if ((!EMPTY_LIST(ifa->neigh_list)) && (neigh->state == NEIGHBOR_FULL))
|
|
|
|
{
|
2009-06-11 05:45:08 +08:00
|
|
|
ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
|
2004-06-06 16:55:33 +08:00
|
|
|
ln->type = LSART_PTP;
|
|
|
|
ln->id = neigh->rid;
|
2009-06-11 05:45:08 +08:00
|
|
|
ln->data = (ifa->iface->addr->flags & IA_UNNUMBERED) ?
|
|
|
|
ifa->iface->index : ipa_to_u32(ifa->iface->addr->ip);
|
2004-06-06 16:55:33 +08:00
|
|
|
ln->metric = ifa->cost;
|
|
|
|
ln->notos = 0;
|
2009-06-11 05:45:08 +08:00
|
|
|
i++;
|
|
|
|
master = 1;
|
2004-06-06 16:55:33 +08:00
|
|
|
}
|
|
|
|
break;
|
2009-06-11 05:45:08 +08:00
|
|
|
|
|
|
|
case OSPF_IT_BCAST: /* RFC2328 - 12.4.1.2 */
|
2004-06-06 16:55:33 +08:00
|
|
|
case OSPF_IT_NBMA:
|
|
|
|
if (ifa->state == OSPF_IS_WAITING)
|
2009-06-11 05:45:08 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
j = 0, k = 0;
|
|
|
|
WALK_LIST(neigh, ifa->neigh_list)
|
2004-06-06 16:55:33 +08:00
|
|
|
{
|
|
|
|
if ((neigh->rid == ifa->drid) && (neigh->state == NEIGHBOR_FULL))
|
|
|
|
k = 1;
|
|
|
|
if (neigh->state == NEIGHBOR_FULL)
|
|
|
|
j = 1;
|
|
|
|
}
|
2009-06-11 05:45:08 +08:00
|
|
|
|
|
|
|
if (((ifa->state == OSPF_IS_DR) && (j == 1)) || (k == 1))
|
2004-06-06 16:55:33 +08:00
|
|
|
{
|
2009-06-11 05:45:08 +08:00
|
|
|
ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
|
2004-06-06 16:55:33 +08: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;
|
2009-06-11 05:45:08 +08:00
|
|
|
i++;
|
|
|
|
master = 1;
|
2004-06-06 16:55:33 +08:00
|
|
|
}
|
|
|
|
break;
|
2009-06-11 05:45:08 +08:00
|
|
|
|
|
|
|
case OSPF_IT_VLINK: /* RFC2328 - 12.4.1.3 */
|
2004-06-26 00:39:53 +08:00
|
|
|
neigh = (struct ospf_neighbor *) HEAD(ifa->neigh_list);
|
|
|
|
if ((!EMPTY_LIST(ifa->neigh_list)) && (neigh->state == NEIGHBOR_FULL) && (ifa->cost <= 0xffff))
|
|
|
|
{
|
2009-06-11 05:45:08 +08:00
|
|
|
ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
|
2004-06-26 00:39:53 +08:00
|
|
|
ln->type = LSART_VLNK;
|
|
|
|
ln->id = neigh->rid;
|
2009-06-11 05:45:08 +08:00
|
|
|
ln->data = ipa_to_u32(ifa->iface->addr->ip);
|
2004-06-26 00:39:53 +08:00
|
|
|
ln->metric = ifa->cost;
|
|
|
|
ln->notos = 0;
|
2009-06-11 05:45:08 +08:00
|
|
|
i++;
|
|
|
|
master = 1;
|
2004-07-13 20:21:24 +08:00
|
|
|
}
|
|
|
|
break;
|
2009-06-11 05:45:08 +08:00
|
|
|
|
2004-07-13 20:21:24 +08:00
|
|
|
default:
|
2004-07-16 00:37:52 +08:00
|
|
|
log("Unknown interface type %s", ifa->iface->name);
|
2004-06-26 00:39:53 +08:00
|
|
|
break;
|
2000-03-10 06:38:05 +08:00
|
|
|
}
|
2009-06-11 05:45:08 +08:00
|
|
|
|
|
|
|
/* Now we will originate stub areas for interfaces addresses */
|
|
|
|
struct ifa *a;
|
|
|
|
WALK_LIST(a, ifa->iface->addrs)
|
|
|
|
{
|
|
|
|
if (((a == ifa->iface->addr) && master) ||
|
|
|
|
(a->flags & IA_SECONDARY) ||
|
2009-06-11 23:25:38 +08:00
|
|
|
(a->flags & IA_UNNUMBERED) ||
|
|
|
|
configured_stubnet(oa, a))
|
2009-06-11 05:45:08 +08:00
|
|
|
continue;
|
|
|
|
|
2009-06-11 23:25:38 +08:00
|
|
|
|
2009-06-11 05:45:08 +08:00
|
|
|
ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
|
|
|
|
ln->type = LSART_STUB;
|
|
|
|
ln->id = ipa_to_u32(a->prefix);
|
|
|
|
ln->data = ipa_to_u32(ipa_mkmask(a->pxlen));
|
|
|
|
ln->metric = ifa->cost;
|
|
|
|
ln->notos = 0;
|
|
|
|
i++;
|
|
|
|
}
|
2000-03-10 06:38:05 +08:00
|
|
|
}
|
2009-06-11 05:45:08 +08:00
|
|
|
|
2009-06-11 23:25:38 +08:00
|
|
|
struct ospf_stubnet_config *sn;
|
|
|
|
WALK_LIST(sn, oa->ac->stubnet_list)
|
|
|
|
if (!sn->hidden)
|
|
|
|
{
|
|
|
|
ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
|
|
|
|
ln->type = LSART_STUB;
|
|
|
|
ln->id = ipa_to_u32(sn->px.addr);
|
|
|
|
ln->data = ipa_to_u32(ipa_mkmask(sn->px.len));
|
|
|
|
ln->metric = sn->cost;
|
|
|
|
ln->notos = 0;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2009-06-11 05:45:08 +08:00
|
|
|
rt = po->lsab;
|
2004-06-06 16:55:33 +08:00
|
|
|
rt->links = i;
|
2009-06-11 05:45:08 +08:00
|
|
|
rt->veb.bit.v = bitv;
|
|
|
|
*length = po->lsab_used + sizeof(struct ospf_lsa_header);
|
|
|
|
return lsab_flush(po);
|
2000-03-10 06:38:05 +08:00
|
|
|
}
|
2000-05-03 06:19:41 +08:00
|
|
|
|
2000-06-08 05:46:22 +08:00
|
|
|
/**
|
|
|
|
* originate_rt_lsa - build new instance of router LSA
|
|
|
|
* @oa: ospf_area which is LSA built to
|
|
|
|
*
|
|
|
|
* It builds router LSA walking through all OSPF interfaces in
|
|
|
|
* specified OSPF area. This function is mostly called from
|
|
|
|
* area_disp(). Builds new LSA, increases sequence number (if old
|
|
|
|
* instance exists) and sets age of LSA to zero.
|
|
|
|
*/
|
2000-05-03 08:08:48 +08:00
|
|
|
void
|
2000-05-31 22:06:33 +08:00
|
|
|
originate_rt_lsa(struct ospf_area *oa)
|
2000-04-04 23:55:55 +08:00
|
|
|
{
|
|
|
|
struct ospf_lsa_header lsa;
|
2004-06-06 16:55:33 +08:00
|
|
|
struct proto_ospf *po = oa->po;
|
|
|
|
struct proto *p = &po->proto;
|
|
|
|
u32 rtid = po->proto.cf->global->router_id;
|
2000-04-04 23:55:55 +08:00
|
|
|
struct top_hash_entry *en;
|
|
|
|
void *body;
|
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
if ((oa->rt) && ((oa->rt->inst_t + MINLSINTERVAL)) > now)
|
|
|
|
return;
|
|
|
|
/*
|
|
|
|
* Tick is probably set to very low value. We cannot
|
|
|
|
* originate new LSA before MINLSINTERVAL. We will
|
|
|
|
* try to do it next tick.
|
|
|
|
*/
|
|
|
|
|
|
|
|
OSPF_TRACE(D_EVENTS, "Originating RT_lsa for area \"%I\".", oa->areaid);
|
|
|
|
|
|
|
|
lsa.age = 0;
|
|
|
|
lsa.id = rtid;
|
|
|
|
lsa.type = LSA_T_RT;
|
|
|
|
lsa.rt = rtid;
|
2004-07-13 19:58:50 +08:00
|
|
|
lsa.options = oa->opt.byte;
|
2004-06-06 16:55:33 +08:00
|
|
|
if (oa->rt == NULL)
|
2000-04-04 23:55:55 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
lsa.sn = LSA_INITSEQNO;
|
2000-04-04 23:55:55 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
lsa.sn = oa->rt->lsa.sn + 1;
|
2000-04-04 23:55:55 +08:00
|
|
|
}
|
2004-06-06 16:55:33 +08:00
|
|
|
body = originate_rt_lsa_body(oa, &lsa.length);
|
2004-06-07 02:45:08 +08:00
|
|
|
lsasum_calculate(&lsa, body);
|
2004-06-06 16:55:33 +08:00
|
|
|
en = lsa_install_new(&lsa, body, oa);
|
|
|
|
oa->rt = en;
|
|
|
|
ospf_lsupd_flood(NULL, NULL, &oa->rt->lsa, NULL, oa, 1);
|
2004-06-07 00:00:09 +08:00
|
|
|
schedule_rtcalc(po);
|
2004-06-06 16:55:33 +08:00
|
|
|
oa->origrt = 0;
|
2000-02-24 08:26:10 +08:00
|
|
|
}
|
|
|
|
|
2004-06-05 17:58:23 +08:00
|
|
|
static void *
|
2004-06-06 16:55:33 +08:00
|
|
|
originate_net_lsa_body(struct ospf_iface *ifa, u16 * length,
|
|
|
|
struct proto_ospf *po)
|
2000-05-03 07:09:44 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
u16 i = 1;
|
2000-05-03 07:09:44 +08:00
|
|
|
struct ospf_neighbor *n;
|
|
|
|
u32 *body;
|
2000-05-04 09:23:03 +08:00
|
|
|
struct ospf_lsa_net *net;
|
2000-05-03 07:09:44 +08:00
|
|
|
|
2004-06-06 16:55:33 +08: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);
|
2000-05-04 09:23:03 +08:00
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
body = (u32 *) (net + 1);
|
|
|
|
i = 1;
|
|
|
|
*body = po->proto.cf->global->router_id;
|
|
|
|
WALK_LIST(n, ifa->neigh_list)
|
2000-05-03 07:09:44 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
if (n->state == NEIGHBOR_FULL)
|
2000-05-03 07:09:44 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
*(body + i) = n->rid;
|
2000-05-03 07:09:44 +08:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2004-06-06 16:55:33 +08:00
|
|
|
*length = i * sizeof(u32) + sizeof(struct ospf_lsa_header) +
|
2000-05-04 09:23:03 +08:00
|
|
|
sizeof(struct ospf_lsa_net);
|
|
|
|
return net;
|
2000-05-03 07:09:44 +08:00
|
|
|
}
|
|
|
|
|
2000-06-08 05:46:22 +08:00
|
|
|
/**
|
|
|
|
* originate_net_lsa - originates of deletes network LSA
|
|
|
|
* @ifa: interface which is LSA originated for
|
|
|
|
*
|
2003-08-23 18:42:41 +08:00
|
|
|
* Interface counts number of adjacent neighbors. If this number is
|
|
|
|
* lower than one or interface is not in state %OSPF_IS_DR it deletes
|
2000-06-08 05:46:22 +08:00
|
|
|
* and premature ages instance of network LSA for specified interface.
|
|
|
|
* In other case, new instance of network LSA is originated.
|
|
|
|
*/
|
2000-05-03 08:08:48 +08:00
|
|
|
void
|
2000-06-08 05:46:22 +08:00
|
|
|
originate_net_lsa(struct ospf_iface *ifa)
|
2000-05-03 07:09:44 +08:00
|
|
|
{
|
2004-07-16 00:37:52 +08:00
|
|
|
struct proto_ospf *po = ifa->oa->po;
|
2000-05-03 07:09:44 +08:00
|
|
|
struct ospf_lsa_header lsa;
|
2004-06-06 16:55:33 +08:00
|
|
|
u32 rtid = po->proto.cf->global->router_id;
|
|
|
|
struct proto *p = &po->proto;
|
2000-05-03 07:09:44 +08:00
|
|
|
void *body;
|
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
if (ifa->nlsa && ((ifa->nlsa->inst_t + MINLSINTERVAL) > now))
|
|
|
|
return;
|
2001-08-11 22:01:54 +08:00
|
|
|
/*
|
|
|
|
* It's too early to originate new network LSA. We will
|
|
|
|
* try to do it next tick
|
|
|
|
*/
|
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
if ((ifa->state != OSPF_IS_DR) || (ifa->fadj == 0))
|
2000-05-03 08:08:48 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
if (ifa->nlsa == NULL)
|
|
|
|
return;
|
2000-05-03 08:08:48 +08:00
|
|
|
|
2000-06-08 05:46:22 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Deleting Net lsa for iface \"%s\".",
|
2004-06-06 16:55:33 +08:00
|
|
|
ifa->iface->name);
|
|
|
|
ifa->nlsa->lsa.sn += 1;
|
|
|
|
ifa->nlsa->lsa.age = LSA_MAXAGE;
|
2009-01-11 17:47:41 +08:00
|
|
|
lsasum_calculate(&ifa->nlsa->lsa, ifa->nlsa->lsa_body);
|
2004-06-06 16:55:33 +08:00
|
|
|
ospf_lsupd_flood(NULL, NULL, &ifa->nlsa->lsa, NULL, ifa->oa, 0);
|
2000-05-31 22:43:42 +08:00
|
|
|
s_rem_node(SNODE ifa->nlsa);
|
2004-06-06 16:55:33 +08:00
|
|
|
if (ifa->nlsa->lsa_body != NULL)
|
|
|
|
mb_free(ifa->nlsa->lsa_body);
|
|
|
|
ifa->nlsa->lsa_body = NULL;
|
2004-07-16 00:37:52 +08:00
|
|
|
ospf_hash_delete(po->gr, ifa->nlsa);
|
2004-06-07 00:00:09 +08:00
|
|
|
schedule_rtcalc(po);
|
2004-06-06 16:55:33 +08:00
|
|
|
ifa->nlsa = NULL;
|
|
|
|
return;
|
2000-05-03 08:08:48 +08:00
|
|
|
}
|
|
|
|
|
2000-06-08 05:46:22 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Originating Net lsa for iface \"%s\".",
|
2004-06-06 16:55:33 +08:00
|
|
|
ifa->iface->name);
|
|
|
|
|
|
|
|
lsa.age = 0;
|
|
|
|
lsa.id = ipa_to_u32(ifa->iface->addr->ip);
|
|
|
|
lsa.type = LSA_T_NET;
|
|
|
|
lsa.rt = rtid;
|
2004-07-13 19:58:50 +08:00
|
|
|
lsa.options = ifa->oa->opt.byte;
|
2004-06-06 16:55:33 +08:00
|
|
|
if (ifa->nlsa == NULL)
|
2000-05-03 07:09:44 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
lsa.sn = LSA_INITSEQNO;
|
2000-05-03 07:09:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
lsa.sn = ifa->nlsa->lsa.sn + 1;
|
2000-05-03 07:09:44 +08:00
|
|
|
}
|
2000-05-31 01:51:22 +08:00
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
body = originate_net_lsa_body(ifa, &lsa.length, po);
|
2004-06-07 02:45:08 +08:00
|
|
|
lsasum_calculate(&lsa, body);
|
2004-06-06 16:55:33 +08:00
|
|
|
ifa->nlsa = lsa_install_new(&lsa, body, ifa->oa);
|
|
|
|
ospf_lsupd_flood(NULL, NULL, &ifa->nlsa->lsa, NULL, ifa->oa, 1);
|
|
|
|
ifa->orignet = 0;
|
2000-05-03 07:09:44 +08:00
|
|
|
}
|
|
|
|
|
2004-06-26 00:39:53 +08:00
|
|
|
|
2000-05-31 05:25:32 +08:00
|
|
|
static void *
|
2004-06-06 16:55:33 +08:00
|
|
|
originate_ext_lsa_body(net * n, rte * e, struct proto_ospf *po,
|
|
|
|
struct ea_list *attrs)
|
2000-05-27 22:17:35 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
struct proto *p = &po->proto;
|
2000-05-27 22:17:35 +08:00
|
|
|
struct ospf_lsa_ext *ext;
|
|
|
|
struct ospf_lsa_ext_tos *et;
|
2000-06-06 02:40:25 +08:00
|
|
|
u32 m1 = ea_get_int(attrs, EA_OSPF_METRIC1, LSINFINITY);
|
|
|
|
u32 m2 = ea_get_int(attrs, EA_OSPF_METRIC2, 10000);
|
2000-05-31 05:25:32 +08:00
|
|
|
u32 tag = ea_get_int(attrs, EA_OSPF_TAG, 0);
|
2004-06-06 16:55:33 +08:00
|
|
|
int inas = 0;
|
2000-05-27 22:17:35 +08:00
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
ext = mb_alloc(p->pool, sizeof(struct ospf_lsa_ext) +
|
|
|
|
sizeof(struct ospf_lsa_ext_tos));
|
|
|
|
ext->netmask = ipa_mkmask(n->n.pxlen);
|
2000-05-27 22:17:35 +08:00
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
et = (struct ospf_lsa_ext_tos *) (ext + 1);
|
2000-05-31 05:25:32 +08:00
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
if (m1 != LSINFINITY)
|
2000-08-28 21:51:13 +08:00
|
|
|
{
|
2004-06-26 00:39:53 +08:00
|
|
|
et->etm.metric = m1;
|
|
|
|
et->etm.etos.tos = 0;
|
|
|
|
et->etm.etos.ebit = 0;
|
2000-08-28 21:51:13 +08:00
|
|
|
}
|
2000-05-27 22:17:35 +08:00
|
|
|
else
|
2000-08-28 21:51:13 +08:00
|
|
|
{
|
2004-06-26 00:39:53 +08:00
|
|
|
et->etm.metric = m2;
|
|
|
|
et->etm.etos.tos = 0;
|
|
|
|
et->etm.etos.ebit = 1;
|
2000-08-28 21:51:13 +08:00
|
|
|
}
|
2004-06-06 16:55:33 +08:00
|
|
|
et->tag = tag;
|
2004-07-15 05:46:20 +08:00
|
|
|
if (!ipa_equal(e->attrs->gw, IPA_NONE))
|
2000-05-31 21:20:25 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
if (ospf_iface_find((struct proto_ospf *) p, e->attrs->iface) != NULL)
|
|
|
|
inas = 1;
|
2000-05-31 21:20:25 +08:00
|
|
|
}
|
2004-06-06 16:55:33 +08:00
|
|
|
|
|
|
|
if (!inas)
|
2004-07-15 05:46:20 +08:00
|
|
|
et->fwaddr = IPA_NONE;
|
2004-06-06 16:55:33 +08:00
|
|
|
else
|
|
|
|
et->fwaddr = e->attrs->gw;
|
2000-05-27 22:17:35 +08:00
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
2004-06-01 02:16:42 +08:00
|
|
|
/**
|
|
|
|
* max_ext_lsa - calculate the maximum amount of external networks
|
|
|
|
* possible for the given prefix length.
|
2004-06-01 06:22:21 +08:00
|
|
|
* @pxlen: network prefix length
|
2004-06-01 02:16:42 +08:00
|
|
|
*
|
|
|
|
* This is a fix for the previous static use of MAXNETS which did
|
|
|
|
* only work correct if MAXNETS < possible IPs for given prefix.
|
|
|
|
* This solution is kind of a hack as there can now only be one
|
|
|
|
* route for /32 type entries but this is better than the crashes
|
|
|
|
* I did experience whith close together /32 routes originating
|
|
|
|
* on different hosts.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
max_ext_lsa(unsigned pxlen)
|
|
|
|
{
|
|
|
|
int i;
|
2004-06-06 16:55:33 +08:00
|
|
|
for (i = 1; pxlen < BITS_PER_IP_ADDRESS; pxlen++, i <<= 1)
|
|
|
|
if (i >= MAXNETS)
|
2004-06-01 02:16:42 +08:00
|
|
|
return MAXNETS;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2004-06-26 00:39:53 +08:00
|
|
|
void
|
|
|
|
flush_sum_lsa(struct ospf_area *oa, struct fib_node *fn, int type)
|
|
|
|
{
|
|
|
|
struct proto_ospf *po = oa->po;
|
|
|
|
struct proto *p = &po->proto;
|
|
|
|
struct top_hash_entry *en;
|
|
|
|
u32 rtid = po->proto.cf->global->router_id;
|
|
|
|
struct ospf_lsa_header lsa;
|
|
|
|
int max, i;
|
|
|
|
struct ospf_lsa_sum *sum = NULL;
|
|
|
|
|
|
|
|
lsa.rt = rtid;
|
|
|
|
lsa.type = LSA_T_SUM_NET;
|
|
|
|
if (type == ORT_ROUTER)
|
|
|
|
lsa.type = LSA_T_SUM_RT;
|
|
|
|
|
|
|
|
max = max_ext_lsa(fn->pxlen);
|
|
|
|
|
|
|
|
for (i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
lsa.id = ipa_to_u32(fn->prefix) + i;
|
2004-07-16 00:37:52 +08:00
|
|
|
if ((en = ospf_hash_find_header(po->gr, oa->areaid, &lsa)) != NULL)
|
2004-06-26 00:39:53 +08:00
|
|
|
{
|
|
|
|
sum = en->lsa_body;
|
2005-02-14 07:36:31 +08:00
|
|
|
if ((type == ORT_ROUTER) || (fn->pxlen == ipa_mklen(sum->netmask)))
|
2004-06-26 00:39:53 +08:00
|
|
|
{
|
|
|
|
en->lsa.age = LSA_MAXAGE;
|
|
|
|
en->lsa.sn = LSA_MAXSEQNO;
|
2004-07-15 05:46:20 +08:00
|
|
|
lsasum_calculate(&en->lsa, sum);
|
|
|
|
OSPF_TRACE(D_EVENTS, "Flushing summary lsa. (id=%I, type=%d)", en->lsa.id, en->lsa.type);
|
2004-06-26 00:39:53 +08:00
|
|
|
ospf_lsupd_flood(NULL, NULL, &en->lsa, NULL, oa, 1);
|
2004-07-16 00:37:52 +08:00
|
|
|
if (can_flush_lsa(po)) flush_lsa(en, po);
|
2004-06-26 00:39:53 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
originate_sum_lsa(struct ospf_area *oa, struct fib_node *fn, int type, int metric)
|
|
|
|
{
|
|
|
|
struct proto_ospf *po = oa->po;
|
|
|
|
struct proto *p = &po->proto;
|
|
|
|
struct top_hash_entry *en;
|
|
|
|
u32 rtid = po->proto.cf->global->router_id;
|
|
|
|
struct ospf_lsa_header lsa;
|
2004-07-15 05:46:20 +08:00
|
|
|
int i, max, mlen = fn->pxlen, free = 0;
|
2005-02-21 00:53:06 +08:00
|
|
|
u32 freeid = 0xFFFF;
|
2004-06-26 00:39:53 +08:00
|
|
|
struct ospf_lsa_sum *sum = NULL;
|
|
|
|
union ospf_lsa_sum_tm *tm;
|
|
|
|
lsa.type = LSA_T_SUM_NET;
|
|
|
|
|
|
|
|
if (type == ORT_ROUTER)
|
|
|
|
{
|
|
|
|
lsa.type = LSA_T_SUM_RT;
|
|
|
|
mlen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
lsa.age = 0;
|
|
|
|
lsa.rt = rtid;
|
|
|
|
lsa.sn = LSA_INITSEQNO;
|
|
|
|
lsa.length = sizeof(struct ospf_lsa_sum) + sizeof(union ospf_lsa_sum_tm) +
|
|
|
|
sizeof(struct ospf_lsa_header);
|
2004-07-14 06:10:14 +08:00
|
|
|
lsa.options = oa->opt.byte;
|
2004-06-26 00:39:53 +08:00
|
|
|
|
|
|
|
max = max_ext_lsa(fn->pxlen);
|
|
|
|
for (i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
lsa.id = ipa_to_u32(fn->prefix) + i;
|
2004-07-16 00:37:52 +08:00
|
|
|
if ((en = ospf_hash_find_header(po->gr, oa->areaid, &lsa)) == NULL)
|
2004-06-26 00:39:53 +08:00
|
|
|
{
|
2005-02-21 00:53:06 +08:00
|
|
|
if (!free)
|
|
|
|
{
|
|
|
|
freeid = lsa.id;
|
|
|
|
free = 1;
|
|
|
|
}
|
2004-06-26 00:39:53 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sum = en->lsa_body;
|
|
|
|
if (mlen == ipa_mklen(sum->netmask))
|
|
|
|
{
|
|
|
|
tm = (union ospf_lsa_sum_tm *) (sum + 1);
|
2005-02-21 00:53:06 +08:00
|
|
|
if (tm->metric == (unsigned) metric) return; /* No reason for origination */
|
2004-06-26 00:39:53 +08:00
|
|
|
lsa.sn = en->lsa.sn + 1;
|
2005-02-21 00:53:06 +08:00
|
|
|
freeid = en->lsa.id;
|
|
|
|
free = 1;
|
2004-06-26 00:39:53 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-15 05:46:20 +08:00
|
|
|
if(!free)
|
2004-06-26 00:39:53 +08:00
|
|
|
{
|
|
|
|
log("%s: got more routes for one /%d network then %d, ignoring", p->name,
|
|
|
|
fn->pxlen, max);
|
|
|
|
return;
|
|
|
|
}
|
2005-02-21 00:53:06 +08:00
|
|
|
lsa.id = freeid;
|
2004-06-26 00:39:53 +08:00
|
|
|
|
2005-02-13 06:22:18 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Originating summary (type %d) lsa for %I/%d (met %d).", lsa.type, fn->prefix,
|
|
|
|
fn->pxlen, metric);
|
2004-06-26 00:39:53 +08:00
|
|
|
|
|
|
|
sum = mb_alloc(p->pool, sizeof(struct ospf_lsa_sum) + sizeof(union ospf_lsa_sum_tm));
|
|
|
|
sum->netmask = ipa_mkmask(mlen);
|
|
|
|
tm = (union ospf_lsa_sum_tm *) (sum + 1);
|
|
|
|
tm->metric = metric;
|
|
|
|
tm->tos.tos = 0;
|
|
|
|
|
2004-07-15 05:46:20 +08:00
|
|
|
lsasum_calculate(&lsa, sum);
|
|
|
|
en = lsa_install_new(&lsa, sum, oa);
|
2004-06-26 00:39:53 +08:00
|
|
|
ospf_lsupd_flood(NULL, NULL, &en->lsa, NULL, oa, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
check_sum_lsa(struct proto_ospf *po, ort *nf, int dest)
|
|
|
|
{
|
|
|
|
struct ospf_area *oa;
|
|
|
|
int flush, mlen;
|
|
|
|
ip_addr ip;
|
|
|
|
|
|
|
|
if (po->areano < 2) return;
|
|
|
|
|
|
|
|
if ((nf->n.type > RTS_OSPF_IA) && (nf->o.type > RTS_OSPF_IA)) return;
|
|
|
|
|
2004-07-15 05:46:20 +08:00
|
|
|
#ifdef LOCAL_DEBUG
|
2009-01-11 19:14:27 +08:00
|
|
|
DBG("Checking...dest = %d, %I/%d\n", dest, nf->fn.prefix, nf->fn.pxlen);
|
|
|
|
if (nf->n.oa) DBG("New: met=%d, oa=%d\n", nf->n.metric1, nf->n.oa->areaid);
|
|
|
|
if (nf->o.oa) DBG("Old: met=%d, oa=%d\n", nf->o.metric1, nf->o.oa->areaid);
|
2004-07-15 05:46:20 +08:00
|
|
|
#endif
|
|
|
|
|
2004-06-26 00:39:53 +08:00
|
|
|
WALK_LIST(oa, po->area_list)
|
|
|
|
{
|
|
|
|
flush = 0;
|
|
|
|
if ((nf->n.metric1 >= LSINFINITY) || (nf->n.type > RTS_OSPF_IA))
|
|
|
|
flush = 1;
|
2005-02-14 07:36:31 +08:00
|
|
|
if ((dest == ORT_ROUTER) && (!(nf->n.capa & ORTA_ASBR)))
|
2004-06-26 00:39:53 +08:00
|
|
|
flush = 1;
|
2004-07-15 05:46:20 +08:00
|
|
|
if ((!nf->n.oa) || (nf->n.oa->areaid == oa->areaid))
|
2004-06-26 00:39:53 +08:00
|
|
|
flush = 1;
|
2005-02-14 07:36:31 +08:00
|
|
|
|
|
|
|
if (nf->n.ifa) {
|
|
|
|
if (nf->n.ifa->oa->areaid == oa->areaid)
|
|
|
|
flush = 1;
|
|
|
|
}
|
|
|
|
else flush = 1;
|
|
|
|
|
2005-02-21 00:53:06 +08:00
|
|
|
/* Don't send summary into stub areas
|
|
|
|
* We send just default route (and later) */
|
|
|
|
if (oa->stub)
|
2004-06-26 00:39:53 +08:00
|
|
|
flush = 1;
|
2005-02-21 00:53:06 +08:00
|
|
|
|
2004-06-26 00:39:53 +08:00
|
|
|
mlen = nf->fn.pxlen;
|
|
|
|
ip = ipa_and(nf->fn.prefix, ipa_mkmask(mlen));
|
|
|
|
|
2005-02-14 07:36:31 +08:00
|
|
|
if ((oa == po->backbone) && (nf->n.type == RTS_OSPF_IA)) flush = 1; /* Only intra-area can go to the backbone */
|
|
|
|
|
|
|
|
if ((!flush) && (dest == ORT_NET) && fib_route(&nf->n.oa->net_fib, ip, mlen)) /* The route fits into area networks */
|
2004-06-26 00:39:53 +08:00
|
|
|
{
|
2005-02-14 07:36:31 +08:00
|
|
|
flush = 1;
|
|
|
|
if ((nf->n.oa == po->backbone) && (oa->trcap)) flush = 0;
|
2004-06-26 00:39:53 +08:00
|
|
|
}
|
2005-02-14 07:36:31 +08:00
|
|
|
|
|
|
|
if(flush)
|
|
|
|
flush_sum_lsa(oa, &nf->fn, dest);
|
|
|
|
else
|
|
|
|
originate_sum_lsa(oa, &nf->fn, dest, nf->n.metric1);
|
2004-06-26 00:39:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-08 05:46:22 +08:00
|
|
|
/**
|
2003-08-23 18:42:41 +08:00
|
|
|
* originate_ext_lsa - new route received from nest and filters
|
2000-06-08 05:46:22 +08:00
|
|
|
* @n: network prefix and mask
|
|
|
|
* @e: rte
|
|
|
|
* @po: current instance of OSPF
|
|
|
|
* @attrs: list of extended attributes
|
|
|
|
*
|
2003-08-23 18:42:41 +08:00
|
|
|
* If I receive a message that new route is installed, I try to originate an
|
|
|
|
* external LSA. The LSA header of such LSA does not contain information about
|
|
|
|
* prefix length, so if I have to originate multiple LSAs for route with
|
2000-06-08 05:46:22 +08:00
|
|
|
* different prefixes I try to increment prefix id to find a "free" one.
|
2000-09-04 06:18:40 +08:00
|
|
|
*
|
2003-08-23 18:42:41 +08:00
|
|
|
* The function also sets flag ebit. If it's the first time, the new router lsa
|
2000-09-04 06:18:40 +08:00
|
|
|
* origination is necessary.
|
2000-06-08 05:46:22 +08:00
|
|
|
*/
|
2000-05-27 22:17:35 +08:00
|
|
|
void
|
2004-06-06 16:55:33 +08:00
|
|
|
originate_ext_lsa(net * n, rte * e, struct proto_ospf *po,
|
|
|
|
struct ea_list *attrs)
|
2000-05-27 22:17:35 +08:00
|
|
|
{
|
|
|
|
struct ospf_lsa_header lsa;
|
2004-06-06 16:55:33 +08:00
|
|
|
u32 rtid = po->proto.cf->global->router_id;
|
|
|
|
struct top_hash_entry *en = NULL;
|
|
|
|
void *body = NULL;
|
|
|
|
struct proto *p = &po->proto;
|
2000-06-05 03:20:28 +08:00
|
|
|
struct ospf_area *oa;
|
2004-06-06 16:55:33 +08:00
|
|
|
struct ospf_lsa_ext *ext1, *ext2;
|
2004-06-26 00:39:53 +08:00
|
|
|
int i, max;
|
2000-05-27 22:17:35 +08:00
|
|
|
|
2000-06-06 10:27:08 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Originating Ext lsa for %I/%d.", n->n.prefix,
|
2004-06-06 16:55:33 +08:00
|
|
|
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;
|
2004-07-14 06:10:14 +08:00
|
|
|
lsa.options = 0;
|
2004-06-26 00:39:53 +08:00
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
body = originate_ext_lsa_body(n, e, po, attrs);
|
|
|
|
lsa.length = sizeof(struct ospf_lsa_ext) + sizeof(struct ospf_lsa_ext_tos) +
|
2000-05-27 22:17:35 +08:00
|
|
|
sizeof(struct ospf_lsa_header);
|
2004-06-06 16:55:33 +08:00
|
|
|
ext1 = body;
|
|
|
|
max = max_ext_lsa(n->n.pxlen);
|
2000-06-05 10:23:20 +08:00
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
for (i = 0; i < max; i++)
|
2000-06-05 10:23:20 +08:00
|
|
|
{
|
2004-07-16 00:37:52 +08:00
|
|
|
if ((en = ospf_hash_find_header(po->gr, 0 , &lsa)) != NULL)
|
2000-06-05 10:23:20 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
ext2 = en->lsa_body;
|
|
|
|
if (ipa_compare(ext1->netmask, ext2->netmask) != 0)
|
|
|
|
lsa.id++;
|
|
|
|
else
|
|
|
|
break;
|
2000-06-05 10:23:20 +08:00
|
|
|
}
|
2004-06-06 16:55:33 +08:00
|
|
|
else
|
|
|
|
break;
|
2000-06-05 10:23:20 +08:00
|
|
|
}
|
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
if (i == max)
|
2000-06-05 10:23:20 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
log("%s: got more routes for one /%d network then %d, ignoring", p->name,
|
|
|
|
n->n.pxlen, max);
|
2000-06-05 10:23:20 +08:00
|
|
|
mb_free(body);
|
|
|
|
return;
|
|
|
|
}
|
2004-06-07 02:45:08 +08:00
|
|
|
lsasum_calculate(&lsa, body);
|
2000-06-05 03:20:28 +08:00
|
|
|
WALK_LIST(oa, po->area_list)
|
2000-05-27 22:17:35 +08:00
|
|
|
{
|
2004-06-26 00:39:53 +08:00
|
|
|
if (!oa->stub)
|
|
|
|
{
|
|
|
|
en = lsa_install_new(&lsa, body, oa);
|
|
|
|
ospf_lsupd_flood(NULL, NULL, &en->lsa, NULL, oa, 1);
|
|
|
|
body = originate_ext_lsa_body(n, e, po, attrs);
|
|
|
|
}
|
2000-05-27 22:17:35 +08:00
|
|
|
}
|
2000-06-05 03:20:28 +08:00
|
|
|
mb_free(body);
|
2000-09-04 06:18:40 +08:00
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
if (po->ebit == 0)
|
2000-09-04 06:18:40 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
po->ebit = 1;
|
2000-09-04 06:18:40 +08:00
|
|
|
WALK_LIST(oa, po->area_list)
|
|
|
|
{
|
|
|
|
schedule_rt_lsa(oa);
|
|
|
|
}
|
|
|
|
}
|
2000-05-27 22:17:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-10 20:27:01 +08: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);
|
2004-06-06 16:55:33 +08:00
|
|
|
f->hash_table =
|
|
|
|
mb_alloc(f->pool, f->hash_size * sizeof(struct top_hash_entry *));
|
1999-11-10 20:27:01 +08:00
|
|
|
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
|
2004-07-16 00:37:52 +08:00
|
|
|
ospf_top_hash(struct top_graph *f, u32 areaid, u32 lsaid, u32 rtrid, u32 type)
|
1999-11-10 20:27:01 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
#if 1 /* Dirty patch to make rt table calculation work. */
|
|
|
|
return (ospf_top_hash_u32(lsaid) +
|
|
|
|
ospf_top_hash_u32((type ==
|
2004-07-16 00:37:52 +08:00
|
|
|
LSA_T_NET) ? lsaid : rtrid) + type +
|
|
|
|
(type == LSA_T_EXT ? 0 : areaid)) & f->hash_mask;
|
2000-06-05 11:46:19 +08:00
|
|
|
#else
|
2004-06-06 16:55:33 +08:00
|
|
|
return (ospf_top_hash_u32(lsaid) + ospf_top_hash_u32(rtrid) +
|
2004-07-16 00:37:52 +08:00
|
|
|
type + areaid) & f->hash_mask;
|
2000-06-05 11:46:19 +08:00
|
|
|
#endif
|
1999-11-10 20:27:01 +08:00
|
|
|
}
|
|
|
|
|
2000-06-08 05:46:22 +08:00
|
|
|
/**
|
|
|
|
* ospf_top_new - allocated new topology database
|
|
|
|
* @p: current instance of OSPF
|
|
|
|
*
|
|
|
|
* This dynamically hashed structure is often used for keeping LSAs. Mainly
|
2003-08-23 18:42:41 +08:00
|
|
|
* its used in @ospf_area structure.
|
2000-06-08 05:46:22 +08:00
|
|
|
*/
|
1999-11-10 20:27:01 +08:00
|
|
|
struct top_graph *
|
2004-06-07 02:45:08 +08:00
|
|
|
ospf_top_new(pool *pool)
|
1999-11-10 20:27:01 +08:00
|
|
|
{
|
|
|
|
struct top_graph *f;
|
|
|
|
|
2004-06-01 21:12:10 +08:00
|
|
|
f = mb_allocz(pool, sizeof(struct top_graph));
|
|
|
|
f->pool = pool;
|
1999-11-10 20:27:01 +08:00
|
|
|
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;
|
2004-06-06 16:55:33 +08:00
|
|
|
DBG("Re-hashing topology hash from order %d to %d\n", f->hash_order,
|
|
|
|
f->hash_order + step);
|
1999-11-10 20:27:01 +08:00
|
|
|
f->hash_order += step;
|
|
|
|
ospf_top_ht_alloc(f);
|
|
|
|
newt = f->hash_table;
|
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
for (oldh = 0; oldh < oldn; oldh++)
|
|
|
|
{
|
|
|
|
e = oldt[oldh];
|
|
|
|
while (e)
|
1999-11-10 20:27:01 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
x = e->next;
|
2004-07-16 00:37:52 +08:00
|
|
|
n = newt + ospf_top_hash(f, e->oa->areaid, e->lsa.id, e->lsa.rt, e->lsa.type);
|
2004-06-06 16:55:33 +08:00
|
|
|
e->next = *n;
|
|
|
|
*n = e;
|
|
|
|
e = x;
|
1999-11-10 20:27:01 +08:00
|
|
|
}
|
2004-06-06 16:55:33 +08:00
|
|
|
}
|
1999-11-10 20:27:01 +08:00
|
|
|
ospf_top_ht_free(oldt);
|
|
|
|
}
|
|
|
|
|
2000-04-04 08:32:17 +08:00
|
|
|
struct top_hash_entry *
|
2004-07-16 00:37:52 +08:00
|
|
|
ospf_hash_find_header(struct top_graph *f, u32 areaid, struct ospf_lsa_header *h)
|
2000-04-04 08:32:17 +08:00
|
|
|
{
|
2004-07-16 00:37:52 +08:00
|
|
|
return ospf_hash_find(f, areaid, h->id, h->rt, h->type);
|
2000-04-04 08:32:17 +08:00
|
|
|
}
|
2000-04-04 23:55:55 +08:00
|
|
|
|
|
|
|
struct top_hash_entry *
|
2004-07-16 00:37:52 +08:00
|
|
|
ospf_hash_get_header(struct top_graph *f, struct ospf_area *oa, struct ospf_lsa_header *h)
|
2000-04-04 23:55:55 +08:00
|
|
|
{
|
2004-07-16 00:37:52 +08:00
|
|
|
return ospf_hash_get(f, oa, h->id, h->rt, h->type);
|
2000-04-04 23:55:55 +08:00
|
|
|
}
|
|
|
|
|
1999-11-10 20:27:01 +08:00
|
|
|
struct top_hash_entry *
|
2004-07-16 00:37:52 +08:00
|
|
|
ospf_hash_find(struct top_graph *f, u32 areaid, u32 lsa, u32 rtr, u32 type)
|
1999-11-10 20:27:01 +08:00
|
|
|
{
|
2004-07-16 00:37:52 +08:00
|
|
|
struct top_hash_entry *e;
|
1999-11-10 20:27:01 +08:00
|
|
|
|
2004-07-16 00:37:52 +08:00
|
|
|
e = f->hash_table[ospf_top_hash(f, areaid, lsa, rtr, type)];
|
|
|
|
|
|
|
|
/* Dirty patch to make rt table calculation work. */
|
2004-06-06 16:55:33 +08:00
|
|
|
if (type == LSA_T_NET)
|
2000-06-05 11:46:19 +08:00
|
|
|
{
|
2004-07-16 00:37:52 +08:00
|
|
|
while (e && (e->lsa.id != lsa || e->lsa.type != LSA_T_NET || e->oa->areaid != areaid))
|
2004-06-06 16:55:33 +08:00
|
|
|
e = e->next;
|
2000-06-05 11:46:19 +08:00
|
|
|
}
|
2004-07-16 00:37:52 +08:00
|
|
|
else if (type == LSA_T_EXT)
|
2000-06-05 11:46:19 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
while (e && (e->lsa.id != lsa || e->lsa.type != type || e->lsa.rt != rtr))
|
|
|
|
e = e->next;
|
2000-06-05 11:46:19 +08:00
|
|
|
}
|
2004-07-16 00:37:52 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
while (e && (e->lsa.id != lsa || e->lsa.type != type || e->lsa.rt != rtr || e->oa->areaid != areaid))
|
|
|
|
e = e->next;
|
|
|
|
}
|
|
|
|
|
1999-11-10 20:27:01 +08:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct top_hash_entry *
|
2004-07-16 00:37:52 +08:00
|
|
|
ospf_hash_get(struct top_graph *f, struct ospf_area *oa, u32 lsa, u32 rtr, u32 type)
|
1999-11-10 20:27:01 +08:00
|
|
|
{
|
2004-07-16 00:37:52 +08:00
|
|
|
struct top_hash_entry **ee;
|
|
|
|
struct top_hash_entry *e;
|
|
|
|
u32 nareaid = (type == LSA_T_EXT ? 0 : oa->areaid);
|
|
|
|
|
|
|
|
ee = f->hash_table + ospf_top_hash(f, nareaid, lsa, rtr, type);
|
|
|
|
e = *ee;
|
|
|
|
|
|
|
|
if (type == LSA_T_EXT)
|
|
|
|
{
|
|
|
|
while (e && (e->lsa.id != lsa || e->lsa.rt != rtr || e->lsa.type != type))
|
|
|
|
e = e->next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (e && (e->lsa.id != lsa || e->lsa.rt != rtr || e->lsa.type != type || e->oa->areaid != nareaid))
|
|
|
|
e = e->next;
|
|
|
|
}
|
1999-11-10 20:27:01 +08:00
|
|
|
|
|
|
|
if (e)
|
|
|
|
return e;
|
2004-06-07 00:14:57 +08:00
|
|
|
|
1999-11-10 20:27:01 +08:00
|
|
|
e = sl_alloc(f->hash_slab);
|
2004-06-07 00:14:57 +08:00
|
|
|
e->color = OUTSPF;
|
|
|
|
e->dist = LSINFINITY;
|
|
|
|
e->nhi = NULL;
|
2004-07-15 05:46:20 +08:00
|
|
|
e->nh = IPA_NONE;
|
|
|
|
e->lb = IPA_NONE;
|
2000-03-10 06:38:05 +08:00
|
|
|
e->lsa.id = lsa;
|
|
|
|
e->lsa.rt = rtr;
|
|
|
|
e->lsa.type = type;
|
|
|
|
e->lsa_body = NULL;
|
2004-06-06 16:55:33 +08:00
|
|
|
e->nhi = NULL;
|
2004-07-16 00:37:52 +08:00
|
|
|
e->oa = oa;
|
2004-06-07 00:14:57 +08:00
|
|
|
e->next = *ee;
|
2004-06-06 16:55:33 +08:00
|
|
|
*ee = e;
|
1999-11-10 20:27:01 +08: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)
|
|
|
|
{
|
2004-07-16 00:37:52 +08:00
|
|
|
struct top_hash_entry **ee = f->hash_table +
|
|
|
|
ospf_top_hash(f, e->oa->areaid, e->lsa.id, e->lsa.rt, e->lsa.type);
|
1999-11-10 20:27:01 +08:00
|
|
|
|
|
|
|
while (*ee)
|
2004-06-06 16:55:33 +08:00
|
|
|
{
|
|
|
|
if (*ee == e)
|
1999-11-10 20:27:01 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
*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;
|
1999-11-10 20:27:01 +08:00
|
|
|
}
|
2004-06-06 16:55:33 +08:00
|
|
|
ee = &((*ee)->next);
|
|
|
|
}
|
1999-11-10 20:27:01 +08:00
|
|
|
bug("ospf_hash_delete() called for invalid node");
|
|
|
|
}
|
|
|
|
|
2008-08-25 20:51:06 +08:00
|
|
|
static void
|
|
|
|
ospf_dump_lsa(struct top_hash_entry *he, struct proto *p)
|
|
|
|
{
|
|
|
|
struct ospf_lsa_rt *rt = NULL;
|
|
|
|
struct ospf_lsa_rt_link *rr = NULL;
|
|
|
|
struct ospf_lsa_net *ln = NULL;
|
|
|
|
u32 *rts = NULL;
|
|
|
|
u32 i, max;
|
|
|
|
|
|
|
|
OSPF_TRACE(D_EVENTS, "- %1x %-1I %-1I %4u 0x%08x 0x%04x %-1I",
|
|
|
|
he->lsa.type, he->lsa.id, he->lsa.rt, he->lsa.age,
|
|
|
|
he->lsa.sn, he->lsa.checksum, he->oa ? he->oa->areaid : 0 );
|
|
|
|
|
|
|
|
switch (he->lsa.type)
|
|
|
|
{
|
|
|
|
case LSA_T_RT:
|
|
|
|
rt = he->lsa_body;
|
|
|
|
rr = (struct ospf_lsa_rt_link *) (rt + 1);
|
|
|
|
|
|
|
|
for (i = 0; i < rt->links; i++)
|
|
|
|
OSPF_TRACE(D_EVENTS, " - %1x %-1I %-1I %5u", rr[i].type, rr[i].id, rr[i].data, rr[i].metric);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LSA_T_NET:
|
|
|
|
ln = he->lsa_body;
|
|
|
|
rts = (u32 *) (ln + 1);
|
2009-01-14 02:15:49 +08:00
|
|
|
max = (he->lsa.length - sizeof(struct ospf_lsa_header) -
|
2008-08-25 20:51:06 +08:00
|
|
|
sizeof(struct ospf_lsa_net)) / sizeof(u32);
|
|
|
|
|
|
|
|
for (i = 0; i < max; i++)
|
|
|
|
OSPF_TRACE(D_EVENTS, " - %-1I", rts[i]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-10 20:27:01 +08:00
|
|
|
void
|
2000-06-06 10:27:08 +08:00
|
|
|
ospf_top_dump(struct top_graph *f, struct proto *p)
|
1999-11-10 20:27:01 +08:00
|
|
|
{
|
2005-02-13 06:22:18 +08:00
|
|
|
unsigned int i;
|
2000-06-06 10:27:08 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Hash entries: %d", f->hash_entries);
|
1999-11-10 20:27:01 +08:00
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
for (i = 0; i < f->hash_size; i++)
|
|
|
|
{
|
2008-08-25 20:51:06 +08:00
|
|
|
struct top_hash_entry *e;
|
|
|
|
for (e = f->hash_table[i]; e != NULL; e = e->next)
|
|
|
|
ospf_dump_lsa(e, p);
|
2004-06-06 16:55:33 +08:00
|
|
|
}
|
1999-11-10 20:27:01 +08:00
|
|
|
}
|
2000-02-26 03:19:41 +08:00
|
|
|
|
2003-08-23 18:42:41 +08:00
|
|
|
/* This is very inefficient, please don't call it often */
|
2000-05-04 06:12:33 +08:00
|
|
|
|
|
|
|
/* I should also test for every LSA if it's in some link state
|
2003-08-23 18:42:41 +08:00
|
|
|
* retransmission list for every neighbor. I will not test it.
|
|
|
|
* It could happen that I'll receive some strange ls ack's.
|
2000-05-04 06:12:33 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2004-07-16 00:37:52 +08:00
|
|
|
can_flush_lsa(struct proto_ospf *po)
|
2000-05-04 06:12:33 +08:00
|
|
|
{
|
|
|
|
struct ospf_iface *ifa;
|
|
|
|
struct ospf_neighbor *n;
|
|
|
|
|
2004-07-16 00:37:52 +08:00
|
|
|
WALK_LIST(ifa, po->iface_list)
|
2000-05-04 06:12:33 +08:00
|
|
|
{
|
2004-07-16 00:37:52 +08:00
|
|
|
WALK_LIST(n, ifa->neigh_list)
|
2000-05-04 06:12:33 +08:00
|
|
|
{
|
2004-07-16 00:37:52 +08:00
|
|
|
if ((n->state == NEIGHBOR_EXCHANGE) || (n->state == NEIGHBOR_LOADING))
|
|
|
|
return 0;
|
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
break;
|
2000-05-04 06:12:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-04 06:36:12 +08:00
|
|
|
return 1;
|
2000-05-04 06:12:33 +08:00
|
|
|
}
|