OSPF: most of summary LSA orig./flush logic rewritten.

Fixes many bugs in the old code and makes it much cleaner.
This commit is contained in:
Ondrej Zajicek 2010-05-02 19:58:34 +02:00
parent ba32170657
commit 6384c7d7aa
8 changed files with 471 additions and 422 deletions

View file

@ -95,7 +95,7 @@ ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
} }
tmp = !(ps->options & OPT_E); tmp = !(ps->options & OPT_E);
if (tmp != ifa->oa->stub) if (tmp != !!ifa->oa->stub)
{ {
log(L_ERR "%s%I - stub area flag mismatch (%d)", beg, faddr, tmp); log(L_ERR "%s%I - stub area flag mismatch (%d)", beg, faddr, tmp);
return; return;

View file

@ -236,11 +236,11 @@ ospf_iface_down(struct ospf_iface *ifa)
struct proto *p = &po->proto; struct proto *p = &po->proto;
struct ospf_iface *iff; struct ospf_iface *iff;
if (ifa->type != OSPF_IT_VLINK)
{
OSPF_TRACE(D_EVENTS, "Removing interface %s", ifa->iface->name); OSPF_TRACE(D_EVENTS, "Removing interface %s", ifa->iface->name);
/* First of all kill all the related vlinks */ /* First of all kill all the related vlinks */
if (ifa->type != OSPF_IT_VLINK)
{
WALK_LIST(iff, po->iface_list) WALK_LIST(iff, po->iface_list)
{ {
if ((iff->type == OSPF_IT_VLINK) && (iff->vifa == ifa)) if ((iff->type == OSPF_IT_VLINK) && (iff->vifa == ifa))

View file

@ -47,15 +47,6 @@ ospf_age(struct proto_ospf *po)
WALK_SLIST_DELSAFE(en, nxt, po->lsal) WALK_SLIST_DELSAFE(en, nxt, po->lsal)
{ {
if (po->calcrt)
{
/* Cleanup before ospf_rt_spf() */
en->color = OUTSPF;
en->dist = LSINFINITY;
en->nhi = NULL;
en->nh = IPA_NONE;
en->lb = IPA_NONE;
}
if (en->lsa.age == LSA_MAXAGE) if (en->lsa.age == LSA_MAXAGE)
{ {
if (flush) if (flush)

View file

@ -142,6 +142,7 @@ ospf_start(struct proto *p)
struct ospf_config *c = (struct ospf_config *) (p->cf); struct ospf_config *c = (struct ospf_config *) (p->cf);
struct ospf_area_config *ac; struct ospf_area_config *ac;
struct ospf_area *oa; struct ospf_area *oa;
int vlinks = 0;
po->router_id = proto_get_router_id(p->cf); po->router_id = proto_get_router_id(p->cf);
po->rfc1583 = c->rfc1583; po->rfc1583 = c->rfc1583;
@ -188,6 +189,9 @@ ospf_start(struct proto *p)
oa->stub = 0; oa->stub = 0;
} }
if (!EMPTY_LIST(ac->vlink_list))
vlinks = 1;
#ifdef OSPFv2 #ifdef OSPFv2
oa->options = (oa->stub ? 0 : OPT_E); oa->options = (oa->stub ? 0 : OPT_E);
#else /* OSPFv3 */ #else /* OSPFv3 */
@ -195,14 +199,8 @@ ospf_start(struct proto *p)
#endif #endif
} }
/* Add all virtual links as interfaces */ /* ABR is always in the backbone */
{ if (((po->areano > 1) || vlinks) && !po->backbone)
struct ospf_iface_patt *ipatt;
WALK_LIST(ac, c->area_list)
{
WALK_LIST(ipatt, ac->vlink_list)
{
if(!po->backbone)
{ {
oa = mb_allocz(p->pool, sizeof(struct ospf_area)); oa = mb_allocz(p->pool, sizeof(struct ospf_area));
add_tail(&po->area_list, NODE oa); add_tail(&po->area_list, NODE oa);
@ -220,10 +218,13 @@ ospf_start(struct proto *p)
oa->options = OPT_R | OPT_E | OPT_V6; oa->options = OPT_R | OPT_E | OPT_V6;
#endif #endif
} }
/* Add all virtual links as interfaces */
struct ospf_iface_patt *ipatt;
WALK_LIST(ac, c->area_list)
WALK_LIST(ipatt, ac->vlink_list)
ospf_iface_new(po, NULL, NULL, ac, ipatt); ospf_iface_new(po, NULL, NULL, ac, ipatt);
}
}
}
return PS_UP; return PS_UP;
} }
@ -635,8 +636,6 @@ ospf_reconfigure(struct proto *p, struct proto_config *c)
struct nbma_node *nb1, *nb2, *nbnx; struct nbma_node *nb1, *nb2, *nbnx;
struct ospf_area *oa = NULL; struct ospf_area *oa = NULL;
int found, olddead, newdead; int found, olddead, newdead;
struct area_net_config *anc;
struct area_net *an;
if (po->rfc1583 != new->rfc1583) if (po->rfc1583 != new->rfc1583)
return 0; return 0;
@ -690,26 +689,8 @@ ospf_reconfigure(struct proto *p, struct proto_config *c)
schedule_rt_lsa(oa); schedule_rt_lsa(oa);
/* Change net_list */ /* Change net_list */
FIB_WALK(&oa->net_fib, nf) /* First check if some networks are deleted */ fib_free(&oa->net_fib);
{ add_area_nets(oa, newac);
found = 0;
WALK_LIST(anc, newac->net_list)
{
if (ipa_equal(anc->px.addr, nf->prefix) && (anc->px.len == nf->pxlen))
{
found = 1;
break;
}
if (!found) flush_sum_lsa(oa, nf, ORT_NET); /* And flush them */
}
}
FIB_WALK_END;
WALK_LIST(anc, newac->net_list) /* Second add new networks */
{
an = fib_get(&oa->net_fib, &anc->px.addr, anc->px.len);
an->hidden = anc->hidden;
}
if (!iface_patts_equal(&oldac->patt_list, &newac->patt_list, if (!iface_patts_equal(&oldac->patt_list, &newac->patt_list,
(void *) ospf_patt_compare)) (void *) ospf_patt_compare))

View file

@ -25,35 +25,20 @@ static void rt_sync(struct proto_ospf *po);
#endif #endif
static void static inline void reset_ri(orta * orta)
fill_ri(orta * orta)
{ {
orta->type = RTS_DUMMY; bzero(orta, sizeof(orta));
orta->options = 0;
orta->metric1 = LSINFINITY;
orta->metric2 = LSINFINITY;
orta->tag = 0;
orta->rid = 0;
orta->oa = NULL;
orta->ifa = NULL;
orta->nh = IPA_NONE;
} }
void void
ospf_rt_initort(struct fib_node *fn) ospf_rt_initort(struct fib_node *fn)
{ {
ort *ri = (ort *) fn; ort *ri = (ort *) fn;
fill_ri(&ri->n); reset_ri(&ri->n);
memcpy(&ri->o, &ri->n, sizeof(orta)); reset_ri(&ri->o);
ri->fn.x0 = 0;
} }
/* Whether the ASBR or the forward address destination is preferred in AS external route selection
according to 16.4.1. */
static inline int
epath_preferred(orta *ep)
{
return (ep->type == RTS_OSPF) && (ep->oa->areaid != 0);
}
/* If new is better return 1 */ /* If new is better return 1 */
static int static int
@ -62,9 +47,6 @@ ri_better(struct proto_ospf *po, orta *new, orta *old)
if (old->type == RTS_DUMMY) if (old->type == RTS_DUMMY)
return 1; return 1;
if (old->metric1 == LSINFINITY)
return 1;
if (new->type < old->type) if (new->type < old->type)
return 1; return 1;
@ -81,11 +63,20 @@ ri_better(struct proto_ospf *po, orta *new, orta *old)
} }
/* Whether the ASBR or the forward address destination is preferred
in AS external route selection according to 16.4.1. */
static inline int
epath_preferred(orta *ep)
{
return (ep->type == RTS_OSPF) && (ep->oa->areaid != 0);
}
/* 16.4. (3), return 1 if new is better */ /* 16.4. (3), return 1 if new is better */
static int static int
ri_better_asbr(struct proto_ospf *po, orta *new, orta *old) ri_better_asbr(struct proto_ospf *po, orta *new, orta *old)
{ {
/* We know that the old ASBB is valid */ if (old->type == RTS_DUMMY)
return 1;
if (!po->rfc1583) if (!po->rfc1583)
{ {
@ -119,9 +110,6 @@ ri_better_ext(struct proto_ospf *po, orta *new, orta *old)
if (old->type == RTS_DUMMY) if (old->type == RTS_DUMMY)
return 1; return 1;
if (old->metric1 == LSINFINITY)
return 1;
/* 16.4. (6a) */ /* 16.4. (6a) */
if (new->type < old->type) if (new->type < old->type)
return 1; return 1;
@ -179,6 +167,14 @@ ri_install_rt(struct ospf_area *oa, u32 rid, orta *new)
memcpy(&old->n, new, sizeof(orta)); memcpy(&old->n, new, sizeof(orta));
} }
static inline void
ri_install_asbr(struct proto_ospf *po, ip_addr *addr, orta *new)
{
ort *old = (ort *) fib_get(&po->backbone->rtr, addr, MAX_PREFIX_LENGTH);
if (ri_better_asbr(po, new, &old->n))
memcpy(&old->n, new, sizeof(orta));
}
static inline void static inline void
ri_install_ext(struct proto_ospf *po, ip_addr prefix, int pxlen, orta *new) ri_install_ext(struct proto_ospf *po, ip_addr prefix, int pxlen, orta *new)
{ {
@ -187,18 +183,6 @@ ri_install_ext(struct proto_ospf *po, ip_addr prefix, int pxlen, orta *new)
memcpy(&old->n, new, sizeof(orta)); memcpy(&old->n, new, sizeof(orta));
} }
static inline void
update_anet(struct ospf_area *oa, ip_addr prefix, int pxlen, u32 metric)
{
struct area_net *anet = (struct area_net *) fib_route(&oa->net_fib, prefix, pxlen);
if (!anet)
return;
anet->active = 1;
if (metric > anet->metric)
anet->metric = metric;
}
#ifdef OSPFv2 #ifdef OSPFv2
@ -271,7 +255,6 @@ add_network(struct ospf_area *oa, ip_addr px, int pxlen, int metric, struct top_
} }
ri_install_net(oa->po, px, pxlen, &nf); ri_install_net(oa->po, px, pxlen, &nf);
update_anet(oa, px, pxlen, metric);
} }
#ifdef OSPFv3 #ifdef OSPFv3
@ -315,9 +298,6 @@ process_prefixes(struct ospf_area *oa)
if (src->color != INSPF) if (src->color != INSPF)
continue; continue;
if (src->lsa.age == LSA_MAXAGE)
continue;
if ((src->lsa.type != LSA_T_RT) && (src->lsa.type != LSA_T_NET)) if ((src->lsa.type != LSA_T_RT) && (src->lsa.type != LSA_T_NET))
continue; continue;
@ -410,9 +390,6 @@ ospf_rt_spfa(struct ospf_area *oa)
OSPF_TRACE(D_EVENTS, "Starting routing table calculation for area %R", oa->areaid); OSPF_TRACE(D_EVENTS, "Starting routing table calculation for area %R", oa->areaid);
if (oa->rt->dist != LSINFINITY)
bug("Aging was not processed.");
/* 16.1. (1) */ /* 16.1. (1) */
init_list(&oa->cand); /* Empty list of candidates */ init_list(&oa->cand); /* Empty list of candidates */
oa->trcap = 0; oa->trcap = 0;
@ -448,7 +425,8 @@ ospf_rt_spfa(struct ospf_area *oa)
* purpose of the last step in SPF - prefix-LSA processing in * purpose of the last step in SPF - prefix-LSA processing in
* process_prefixes(), we use information stored in LSA db. * process_prefixes(), we use information stored in LSA db.
*/ */
if ((rt->options & OPT_RT_E) || (rt->options & OPT_RT_B)) if (((rt->options & OPT_RT_E) || (rt->options & OPT_RT_B))
&& (act->lsa.rt != po->router_id))
{ {
orta nf = { orta nf = {
.type = RTS_OSPF, .type = RTS_OSPF,
@ -590,7 +568,6 @@ ospf_rt_sum(struct ospf_area *oa)
ip_addr ip = IPA_NONE; ip_addr ip = IPA_NONE;
u32 dst_rid = 0; u32 dst_rid = 0;
u32 metric, options; u32 metric, options;
struct area_net *anet;
ort *abr; ort *abr;
int pxlen = -1, type = -1; int pxlen = -1, type = -1;
@ -612,12 +589,10 @@ ospf_rt_sum(struct ospf_area *oa)
if (en->lsa.rt == po->router_id) if (en->lsa.rt == po->router_id)
continue; continue;
/* 16.2. (3) is handled later in ospf_rt_abr() by resetting such rt entry */
if (en->lsa.type == LSA_T_SUM_NET) if (en->lsa.type == LSA_T_SUM_NET)
{ {
struct ospf_area *oaa;
int skip = 0;
#ifdef OSPFv2 #ifdef OSPFv2
struct ospf_lsa_sum *ls = en->lsa_body; struct ospf_lsa_sum *ls = en->lsa_body;
pxlen = ipa_mklen(ls->netmask); pxlen = ipa_mklen(ls->netmask);
@ -635,18 +610,6 @@ ospf_rt_sum(struct ospf_area *oa)
metric = ls->metric & METRIC_MASK; metric = ls->metric & METRIC_MASK;
options = 0; options = 0;
type = ORT_NET; type = ORT_NET;
/* 16.2. (3) */
WALK_LIST(oaa, po->area_list)
{
if ((anet = fib_find(&oaa->net_fib, &ip, pxlen)) && anet->active)
{
skip = 1;
break;
}
}
if (skip)
continue;
} }
else /* LSA_T_SUM_RT */ else /* LSA_T_SUM_RT */
{ {
@ -660,6 +623,10 @@ ospf_rt_sum(struct ospf_area *oa)
options = ls->options & OPTIONS_MASK; options = ls->options & OPTIONS_MASK;
#endif #endif
/* We don't want local router in ASBR routing table */
if (dst_rid == po->router_id)
continue;
metric = ls->metric & METRIC_MASK; metric = ls->metric & METRIC_MASK;
options |= ORTA_ASBR; options |= ORTA_ASBR;
type = ORT_ROUTER; type = ORT_ROUTER;
@ -675,9 +642,6 @@ ospf_rt_sum(struct ospf_area *oa)
if (!abr || !abr->n.type) if (!abr || !abr->n.type)
continue; continue;
if (abr->n.metric1 == LSINFINITY)
continue;
if (!(abr->n.options & ORTA_ABR)) if (!(abr->n.options & ORTA_ABR))
continue; continue;
@ -712,10 +676,9 @@ ospf_rt_sum_tr(struct ospf_area *oa)
// struct proto *p = &oa->po->proto; // struct proto *p = &oa->po->proto;
struct proto_ospf *po = oa->po; struct proto_ospf *po = oa->po;
struct ospf_area *bb = po->backbone; struct ospf_area *bb = po->backbone;
ip_addr ip, abrip; ip_addr abrip;
struct top_hash_entry *en; struct top_hash_entry *en;
u32 dst_rid, metric, options; u32 dst_rid, metric;
int pxlen = -1, type = -1;
ort *re = NULL, *abr; ort *re = NULL, *abr;
@ -739,6 +702,8 @@ ospf_rt_sum_tr(struct ospf_area *oa)
if (en->lsa.type == LSA_T_SUM_NET) if (en->lsa.type == LSA_T_SUM_NET)
{ {
ip_addr ip;
int pxlen;
#ifdef OSPFv2 #ifdef OSPFv2
struct ospf_lsa_sum *ls = en->lsa_body; struct ospf_lsa_sum *ls = en->lsa_body;
pxlen = ipa_mklen(ls->netmask); pxlen = ipa_mklen(ls->netmask);
@ -754,8 +719,6 @@ ospf_rt_sum_tr(struct ospf_area *oa)
#endif #endif
metric = ls->metric & METRIC_MASK; metric = ls->metric & METRIC_MASK;
options = 0;
type = ORT_NET;
re = fib_find(&po->rtf, &ip, pxlen); re = fib_find(&po->rtf, &ip, pxlen);
} }
else // en->lsa.type == LSA_T_SUM_RT else // en->lsa.type == LSA_T_SUM_RT
@ -763,19 +726,14 @@ ospf_rt_sum_tr(struct ospf_area *oa)
#ifdef OSPFv2 #ifdef OSPFv2
struct ospf_lsa_sum *ls = en->lsa_body; struct ospf_lsa_sum *ls = en->lsa_body;
dst_rid = en->lsa.id; dst_rid = en->lsa.id;
options = 0;
#else /* OSPFv3 */ #else /* OSPFv3 */
struct ospf_lsa_sum_rt *ls = en->lsa_body; struct ospf_lsa_sum_rt *ls = en->lsa_body;
dst_rid = ls->drid; dst_rid = ls->drid;
options = ls->options & OPTIONS_MASK;
#endif #endif
ip = ipa_from_rid(dst_rid);
pxlen = MAX_PREFIX_LENGTH;
metric = ls->metric & METRIC_MASK; metric = ls->metric & METRIC_MASK;
options |= ORTA_ASBR; ip_addr ip = ipa_from_rid(dst_rid);
type = ORT_ROUTER; re = fib_find(&bb->rtr, &ip, MAX_PREFIX_LENGTH);
re = fib_find(&bb->rtr, &ip, pxlen);
} }
/* 16.3 (1b) */ /* 16.3 (1b) */
@ -812,27 +770,262 @@ ospf_rt_sum_tr(struct ospf_area *oa)
} }
} }
/* RFC 2328 G.3 - incomplete resolution of virtual next hops */ /* Decide about originating or flushing summary LSAs for condended area networks */
static void static int
ospf_cleanup_vlinks(struct proto_ospf *po) decide_anet_lsa(struct ospf_area *oa, struct area_net *anet, struct ospf_area *anet_oa)
{ {
if (oa->stub)
return 0;
if (oa == anet_oa)
return 0;
/* Do not condense routing info when exporting from backbone to the transit area */
if ((anet_oa == oa->po->backbone) && oa->trcap)
return 0;
return (anet->active && !anet->hidden);
}
/* Decide about originating or flushing summary LSAs (12.4.3) */
static int
decide_sum_lsa(struct ospf_area *oa, ort *nf, int dest)
{
/* 12.4.3.1. - do not send summary into stub areas, we send just default route */
if (oa->stub)
return 0;
/* Invalid field - no route */
if (!nf->n.type)
return 0;
/* 12.4.3 p2 */
if (nf->n.type > RTS_OSPF_IA)
return 0;
/* 12.4.3 p3 */
if ((nf->n.oa->areaid == oa->areaid))
return 0;
/* 12.4.3 p4 */
if (nf->n.ifa->oa->areaid == oa->areaid)
return 0;
/* 12.4.3 p5 */
if (nf->n.metric1 >= LSINFINITY)
return 0;
/* 12.4.3 p6 - AS boundary router */
if (dest == ORT_ROUTER)
{
/* We call decide_sum_lsa() on preferred ASBR entries, no need for 16.4. (3) */
/* 12.4.3 p1 */
return (nf->n.options & ORTA_ASBR);
}
/* 12.4.3 p7 - inter-area route */
if (nf->n.type == RTS_OSPF_IA)
{
/* Inter-area routes are not repropagated into the backbone */
return (oa != oa->po->backbone);
}
/* 12.4.3 p8 - intra-area route */
/* Do not condense routing info when exporting from backbone to the transit area */
if ((nf->n.oa == oa->po->backbone) && oa->trcap)
return 1;
struct area_net *anet = (struct area_net *)
fib_route(&nf->n.oa->net_fib, nf->fn.prefix, nf->fn.pxlen);
/* Condensed area network found */
if (anet)
return 0;
return 1;
}
/* RFC 2328 16.7. p1 - originate or flush summary LSAs */
static inline void
check_sum_net_lsa(struct proto_ospf *po, ort *nf)
{
struct area_net *anet = NULL;
struct ospf_area *anet_oa;
/* RT entry marked as area network */
if (nf->fn.x0)
{
/* It is a default route for stub areas, handled entirely in ospf_rt_abr() */
if (nf->fn.pxlen == 0)
return;
/* Find that area network */
WALK_LIST(anet_oa, po->area_list)
{
anet = (struct area_net *) fib_find(&anet_oa->net_fib, &nf->fn.prefix, nf->fn.pxlen);
if (anet)
break;
}
}
struct ospf_area *oa;
WALK_LIST(oa, po->area_list)
{
if (anet && decide_anet_lsa(oa, anet, anet_oa))
originate_sum_net_lsa(oa, &nf->fn, anet->metric);
else if (decide_sum_lsa(oa, nf, ORT_NET))
originate_sum_net_lsa(oa, &nf->fn, nf->n.metric1);
else
flush_sum_lsa(oa, &nf->fn, ORT_NET);
}
}
static inline void
check_sum_rt_lsa(struct proto_ospf *po, ort *nf)
{
struct ospf_area *oa;
WALK_LIST(oa, po->area_list)
{
if (decide_sum_lsa(oa, nf, ORT_ROUTER))
originate_sum_rt_lsa(oa, &nf->fn, nf->n.metric1, nf->n.options);
else
flush_sum_lsa(oa, &nf->fn, ORT_ROUTER);
}
}
/* RFC 2328 16.7. p2 - find new/lost vlink endpoints */
static void
ospf_check_vlinks(struct proto_ospf *po)
{
struct proto *p = &po->proto;
struct ospf_iface *iface;
WALK_LIST(iface, po->iface_list)
{
if (iface->type == OSPF_IT_VLINK)
{
struct top_hash_entry *tmp;
tmp = ospf_hash_find_rt(po->gr, iface->voa->areaid, iface->vid);
if (tmp && (tmp->color == INSPF) && ipa_nonzero(tmp->lb))
{
if ((iface->state != OSPF_IS_PTP)
|| (iface->vifa != tmp->nhi)
|| !ipa_equal(iface->vip, tmp->lb))
{
OSPF_TRACE(D_EVENTS, "Vlink peer %R found", tmp->lsa.id);
ospf_iface_sm(iface, ISM_DOWN);
iface->vifa = tmp->nhi;
iface->iface = tmp->nhi->iface;
iface->addr = tmp->nhi->addr;
iface->sk = tmp->nhi->sk;
iface->cost = tmp->dist;
iface->vip = tmp->lb;
ospf_iface_sm(iface, ISM_UP);
}
else if ((iface->state == OSPF_IS_PTP) && (iface->cost != tmp->dist))
{
iface->cost = tmp->dist;
schedule_rt_lsa(po->backbone);
}
}
else
{
if (iface->state > OSPF_IS_DOWN)
{
OSPF_TRACE(D_EVENTS, "Vlink peer %R lost", iface->vid);
ospf_iface_sm(iface, ISM_DOWN);
}
}
}
}
}
/* Miscellaneous route processing that needs to be done by ABRs */
static void
ospf_rt_abr(struct proto_ospf *po)
{
struct area_net *anet;
ort *nf, *default_nf;
FIB_WALK(&po->rtf, nftmp) FIB_WALK(&po->rtf, nftmp)
{ {
ort *nf = (ort *) nftmp; nf = (ort *) nftmp;
/* RFC 2328 G.3 - incomplete resolution of virtual next hops */
if (nf->n.type && (nf->n.ifa->type == OSPF_IT_VLINK)) if (nf->n.type && (nf->n.ifa->type == OSPF_IT_VLINK))
fill_ri(&nf->n); reset_ri(&nf->n);
/* Compute condensed area networks */
if (nf->n.type == RTS_OSPF)
{
anet = (struct area_net *) fib_route(&nf->n.oa->net_fib, nf->fn.prefix, nf->fn.pxlen);
if (anet)
{
if (!anet->active)
{
anet->active = 1;
/* Get a RT entry and mark it to know that it is an area network */
ort *nfi = (ort *) fib_get(&po->rtf, &anet->fn.prefix, anet->fn.pxlen);
nfi->fn.x0 = 1; /* mark and keep persistent, to have stable UID */
/* 16.2. (3) */
if (nfi->n.type == RTS_OSPF_IA)
reset_ri(&nfi->n);
}
if (anet->metric < nf->n.metric1)
anet->metric = nf->n.metric1;
}
}
}
FIB_WALK_END;
ip_addr addr = IPA_NONE;
default_nf = (ort *) fib_get(&po->rtf, &addr, 0);
default_nf->fn.x0 = 1; /* keep persistent */
struct ospf_area *oa;
WALK_LIST(oa, po->area_list)
{
/* 12.4.3.1. - originate or flush default summary LSA for stub areas */
if (oa->stub)
originate_sum_net_lsa(oa, &default_nf->fn, oa->stub);
else
flush_sum_lsa(oa, &default_nf->fn, ORT_NET);
/* RFC 2328 16.4. (3) - precompute preferred ASBR entries */
FIB_WALK(&oa->rtr, nftmp)
{
nf = (ort *) nftmp;
if (nf->n.options & ORTA_ASBR)
ri_install_asbr(po, &nf->fn.prefix, &nf->n);
} }
FIB_WALK_END; FIB_WALK_END;
} }
/**
* ospf_ext_spf - calculate external paths /* Originate or flush ASBR summary LSAs */
* @po: protocol FIB_WALK(&po->backbone->rtr, nftmp)
* {
* After routing table for any area is calculated, calculation of external check_sum_rt_lsa(po, (ort *) nftmp);
* path is invoked. This process is described in 16.4 of RFC 2328. }
* Inter- and Intra-area paths are always prefered over externals. FIB_WALK_END;
*/
/* RFC 2328 16.7. p2 - find new/lost vlink endpoints */
ospf_check_vlinks(po);
}
/* RFC 2328 16.4. calculating external routes */
static void static void
ospf_ext_spf(struct proto_ospf *po) ospf_ext_spf(struct proto_ospf *po)
{ {
@ -910,22 +1103,13 @@ ospf_ext_spf(struct proto_ospf *po)
nh = IPA_NONE; nh = IPA_NONE;
/* 16.4. (3) */ /* 16.4. (3) */
/* If there are more areas, we already precomputed preferred ASBR entries
in ospf_asbr_spf() and stored them in the backbone table */
atmp = (po->areano > 1) ? po->backbone : HEAD(po->area_list);
rtid = ipa_from_rid(en->lsa.rt); rtid = ipa_from_rid(en->lsa.rt);
nf1 = NULL; nf1 = fib_find(&atmp->rtr, &rtid, MAX_PREFIX_LENGTH);
WALK_LIST(atmp, po->area_list)
{
ort *nfh = fib_find(&atmp->rtr, &rtid, MAX_PREFIX_LENGTH);
if (!nfh || !nfh->n.type)
continue;
if (nfh->n.metric1 == LSINFINITY) if (!nf1 || !nf1->n.type)
continue;
if (!nf1 || ri_better_asbr(po, &nfh->n, &nf1->n))
nf1 = nfh;
}
if (!nf1)
continue; /* No AS boundary router found */ continue; /* No AS boundary router found */
if (!(nf1->n.options & ORTA_ASBR)) if (!(nf1->n.options & ORTA_ASBR))
@ -945,9 +1129,6 @@ ospf_ext_spf(struct proto_ospf *po)
if (!nf2) /* nf2->n.type is checked later */ if (!nf2) /* nf2->n.type is checked later */
continue; continue;
if (nf2->n.metric1 == LSINFINITY)
continue;
if ((nf2->n.type != RTS_OSPF) && (nf2->n.type != RTS_OSPF_IA)) if ((nf2->n.type != RTS_OSPF) && (nf2->n.type != RTS_OSPF_IA))
continue; continue;
@ -986,55 +1167,60 @@ ospf_ext_spf(struct proto_ospf *po)
} }
} }
/* RFC 2328 16.7. p2 - find new/lost vlink endpoints */ /* Cleanup of routing tables and data Cleanup */
static void void
ospf_check_vlinks(struct proto_ospf *po) ospf_rt_reset(struct proto_ospf *po)
{ {
struct proto *p = &po->proto; struct ospf_area *oa;
struct top_hash_entry *en;
struct area_net *anet;
ort *ri;
struct ospf_iface *iface; /* Reset old routing table */
WALK_LIST(iface, po->iface_list) FIB_WALK(&po->rtf, nftmp)
{ {
if (iface->type == OSPF_IT_VLINK) ri = (ort *) nftmp;
{ memcpy(&ri->o, &ri->n, sizeof(orta)); /* Backup old data */
struct top_hash_entry *tmp; ri->fn.x0 = 0;
tmp = ospf_hash_find_rt(po->gr, iface->voa->areaid, iface->vid); reset_ri(&ri->n);
}
FIB_WALK_END;
if (tmp && (tmp->color == INSPF) /* Reset SPF data in LSA db */
&& (tmp->dist < LSINFINITY) WALK_SLIST(en, po->lsal)
&& ipa_nonzero(tmp->lb))
{ {
if ((iface->state != OSPF_IS_PTP) en->color = OUTSPF;
|| (iface->vifa != tmp->nhi) en->dist = LSINFINITY;
|| !ipa_equal(iface->vip, tmp->lb)) en->nhi = NULL;
en->nh = IPA_NONE;
en->lb = IPA_NONE;
}
WALK_LIST(oa, po->area_list)
{ {
OSPF_TRACE(D_EVENTS, "Vlink peer %R found", tmp->lsa.id); /* Reset ASBR routing tables */
ospf_iface_sm(iface, ISM_DOWN); FIB_WALK(&oa->rtr, nftmp)
iface->vifa = tmp->nhi;
iface->iface = tmp->nhi->iface;
iface->addr = tmp->nhi->addr;
iface->sk = tmp->nhi->sk;
iface->cost = tmp->dist;
iface->vip = tmp->lb;
ospf_iface_sm(iface, ISM_UP);
}
else if ((iface->state == OSPF_IS_PTP) && (iface->cost != tmp->dist))
{ {
iface->cost = tmp->dist; ri = (ort *) nftmp;
schedule_rt_lsa(po->backbone); memcpy(&ri->o, &ri->n, sizeof(orta)); /* Backup old data */
reset_ri(&ri->n);
} }
} FIB_WALK_END;
else
/* Reset condensed area networks */
if (po->areano > 1)
{ {
if (iface->state > OSPF_IS_DOWN) FIB_WALK(&oa->net_fib, nftmp)
{ {
OSPF_TRACE(D_EVENTS, "Vlink peer %R lost", iface->vid); anet = (struct area_net *) nftmp;
ospf_iface_sm(iface, ISM_DOWN); anet->active = 0;
} anet->metric = 0;
} }
FIB_WALK_END;
} }
} }
} }
/** /**
* ospf_rt_spf - calculate internal routes * ospf_rt_spf - calculate internal routes
* @po: OSPF protocol * @po: OSPF protocol
@ -1048,47 +1234,21 @@ ospf_rt_spf(struct proto_ospf *po)
{ {
struct proto *p = &po->proto; struct proto *p = &po->proto;
struct ospf_area *oa; struct ospf_area *oa;
ort *ri;
struct area_net *anet;
if (po->areano == 0) return; if (po->areano == 0)
return;
OSPF_TRACE(D_EVENTS, "Starting routing table calculation"); OSPF_TRACE(D_EVENTS, "Starting routing table calculation");
/* 16. (1) - Invalidate old routing table */ /* 16. (1) */
FIB_WALK(&po->rtf, nftmp) ospf_rt_reset(po);
{
ri = (ort *) nftmp;
memcpy(&ri->o, &ri->n, sizeof(orta)); /* Backup old data */
fill_ri(&ri->n);
}
FIB_WALK_END;
WALK_LIST(oa, po->area_list)
{
FIB_WALK(&oa->rtr, nftmp)
{
ri = (ort *) nftmp;
memcpy(&ri->o, &ri->n, sizeof(orta)); /* Backup old data */
fill_ri(&ri->n);
}
FIB_WALK_END;
FIB_WALK(&oa->net_fib, nftmp)
{
anet = (struct area_net *) nftmp;
anet->active = 0;
anet->metric = 1;
}
FIB_WALK_END;
/* 16. (2) */ /* 16. (2) */
WALK_LIST(oa, po->area_list)
ospf_rt_spfa(oa); ospf_rt_spfa(oa);
}
/* 16. (3) */ /* 16. (3) */
if ((po->areano == 1) || (!po->backbone)) if (po->areano == 1)
ospf_rt_sum(HEAD(po->area_list)); ospf_rt_sum(HEAD(po->area_list));
else else
ospf_rt_sum(po->backbone); ospf_rt_sum(po->backbone);
@ -1098,10 +1258,8 @@ ospf_rt_spf(struct proto_ospf *po)
if (oa->trcap && (oa->areaid != 0)) if (oa->trcap && (oa->areaid != 0))
ospf_rt_sum_tr(oa); ospf_rt_sum_tr(oa);
/* G.3 */ if (po->areano > 1)
if (po->backbone && po->backbone->rt && ospf_rt_abr(po);
(((struct ospf_lsa_rt *) po->backbone->rt->lsa_body)->options & OPT_RT_V))
ospf_cleanup_vlinks(po);
/* 16. (5) */ /* 16. (5) */
ospf_ext_spf(po); ospf_ext_spf(po);
@ -1139,7 +1297,7 @@ add_cand(list * l, struct top_hash_entry *en, struct top_hash_entry *par,
if (en->color == INSPF) if (en->color == INSPF)
return; return;
/* 16.1. (2d) */ /* 16.1. (2d), also checks that dist < LSINFINITY */
if (dist >= en->dist) if (dist >= en->dist)
return; return;
/* /*
@ -1335,9 +1493,7 @@ rt_sync(struct proto_ospf *po)
struct fib_iterator fit; struct fib_iterator fit;
struct fib *fib = &po->rtf; struct fib *fib = &po->rtf;
ort *nf; ort *nf;
struct ospf_area *oa, *oaa; struct ospf_area *oa;
struct area_net *anet;
int flush;
/* This is used for forced reload of routes */ /* This is used for forced reload of routes */
int reload = (po->calcrt == 2); int reload = (po->calcrt == 2);
@ -1350,40 +1506,40 @@ again1:
FIB_ITERATE_START(fib, &fit, nftmp) FIB_ITERATE_START(fib, &fit, nftmp)
{ {
nf = (ort *) nftmp; nf = (ort *) nftmp;
check_sum_lsa(po, nf, ORT_NET);
/* Sanity check of next-hop address */
if (nf->n.type && ipa_nonzero(nf->n.nh))
{
neighbor *ng = neigh_find2(p, &nf->n.nh, nf->n.ifa->iface, 0);
if (!ng || (ng->scope == SCOPE_HOST))
reset_ri(&nf->n);
}
if (po->areano > 1)
check_sum_net_lsa(po, nf);
if (reload || memcmp(&nf->n, &nf->o, sizeof(orta))) if (reload || memcmp(&nf->n, &nf->o, sizeof(orta)))
{ /* Some difference */ {
net *ne = net_get(p->table, nf->fn.prefix, nf->fn.pxlen); net *ne = net_get(p->table, nf->fn.prefix, nf->fn.pxlen);
if (nf->n.type) /* Add the route */
{
rta a0 = { rta a0 = {
.proto = p, .proto = p,
.source = nf->n.type, .source = nf->n.type,
.scope = SCOPE_UNIVERSE, .scope = SCOPE_UNIVERSE,
.cast = RTC_UNICAST .cast = RTC_UNICAST,
.iface = nf->n.ifa->iface
}; };
if (!nf->n.type)
goto remove1;
/* The distance is unreachable (or farther) */
if (nf->n.metric1 >= LSINFINITY)
goto remove1;
a0.iface = nf->n.ifa->iface;
if (ipa_nonzero(nf->n.nh)) if (ipa_nonzero(nf->n.nh))
{ {
neighbor *ng;
a0.dest = RTD_ROUTER; a0.dest = RTD_ROUTER;
a0.gw = nf->n.nh; a0.gw = nf->n.nh;
ng = neigh_find2(p, &a0.gw, a0.iface, 0);
if (!ng || (ng->scope == SCOPE_HOST))
goto remove1;
} }
else else
a0.dest = RTD_DEVICE; a0.dest = RTD_DEVICE;
/* Add the route */
rte *e = rte_get_temp(&a0); rte *e = rte_get_temp(&a0);
e->u.ospf.metric1 = nf->n.metric1; e->u.ospf.metric1 = nf->n.metric1;
e->u.ospf.metric2 = nf->n.metric2; e->u.ospf.metric2 = nf->n.metric2;
@ -1395,76 +1551,38 @@ again1:
DBG("Mod rte type %d - %I/%d via %I on iface %s, met %d\n", DBG("Mod rte type %d - %I/%d via %I on iface %s, met %d\n",
a0.source, nf->fn.prefix, nf->fn.pxlen, a0.gw, a0.iface ? a0.iface->name : "(none)", nf->n.metric1); a0.source, nf->fn.prefix, nf->fn.pxlen, a0.gw, a0.iface ? a0.iface->name : "(none)", nf->n.metric1);
rte_update(p->table, ne, p, p, e); rte_update(p->table, ne, p, p, e);
goto cont1; }
else /* Remove the route */
remove1:
/* Remove the route */
rte_update(p->table, ne, p, p, NULL); rte_update(p->table, ne, p, p, NULL);
}
/* Remove unused rt entry. Entries with fn.x0 == 1 are persistent. */
if (!nf->n.type && !nf->fn.x0)
{
FIB_ITERATE_PUT(&fit, nftmp); FIB_ITERATE_PUT(&fit, nftmp);
fib_delete(fib, nftmp); fib_delete(fib, nftmp);
goto again1; goto again1;
} }
} }
cont1:
FIB_ITERATE_END(nftmp); FIB_ITERATE_END(nftmp);
ospf_check_vlinks(po);
WALK_LIST(oa, po->area_list) WALK_LIST(oa, po->area_list)
{ {
/* Cleanup ASBR hash tables */
FIB_ITERATE_INIT(&fit, &oa->rtr); FIB_ITERATE_INIT(&fit, &oa->rtr);
again2: again2:
FIB_ITERATE_START(&oa->rtr, &fit, nftmp) FIB_ITERATE_START(&oa->rtr, &fit, nftmp)
{ {
nf = (ort *) nftmp; nf = (ort *) nftmp;
if (memcmp(&nf->n, &nf->o, sizeof(orta)))
{ /* Some difference */ if (!nf->n.type)
check_sum_lsa(po, nf, ORT_ROUTER);
if (nf->n.metric1 >= LSINFINITY)
{ {
FIB_ITERATE_PUT(&fit, nftmp); FIB_ITERATE_PUT(&fit, nftmp);
fib_delete(&oa->rtr, nftmp); fib_delete(&oa->rtr, nftmp);
goto again2; goto again2;
} }
} }
}
FIB_ITERATE_END(nftmp); FIB_ITERATE_END(nftmp);
/* Check condensed summary LSAs */
FIB_WALK(&oa->net_fib, nftmp)
{
flush = 1;
anet = (struct area_net *) nftmp;
if ((!anet->hidden) && anet->active)
flush = 0;
WALK_LIST(oaa, po->area_list)
{
int fl = flush;
if (oaa == oa)
continue;
if ((oa == po->backbone) && oaa->trcap) fl = 1;
if (oaa->stub) fl = 1;
if (fl) flush_sum_lsa(oaa, &anet->fn, ORT_NET);
else originate_sum_lsa(oaa, &anet->fn, ORT_NET, anet->metric, 0);
}
}
FIB_WALK_END;
/* Check default summary LSA for stub areas
* just for router connected to backbone */
if (po->backbone)
{
struct fib_node fnn;
fnn.prefix = IPA_NONE;
fnn.pxlen = 0;
if (oa->stub) originate_sum_lsa(oa, &fnn, ORT_NET, oa->stub, 0);
else flush_sum_lsa(oa, &fnn, ORT_NET);
}
} }
} }

View file

@ -47,12 +47,35 @@ orta;
typedef struct ort typedef struct ort
{ {
/*
* We use fn.x0 to mark persistent rt entries, that are needed for summary
* LSAs that don't have 'proper' rt entry (area networks + default to stubs)
* to keep uid stable (used for LSA ID in OSPFv3 - see fibnode_to_lsaid()).
*/
struct fib_node fn; struct fib_node fn;
orta n; orta n;
orta o; orta o;
} }
ort; ort;
/*
* Invariants for structs top_hash_entry (nodes of LSA db)
* enforced by SPF calculation for final nodes (color == INSPF):
* - only router, network and AS-external LSAs
* - lsa.age < LSA_MAXAGE
* - dist < LSINFINITY (or 2*LSINFINITY for ext-LSAs)
* - nhi are non-NULL unless the node is oa->rt (calculating router itself)
* - beware, nhi is not valid after SPF calculation
* - nh is IFA_NONE iff the node is a local network
*
* Invariants for structs orta nodes of fib tables po->rtf, oa->rtr:
* - nodes may be invalid (fn.type == 0), in that case other invariants don't hold
* - n.metric1 may be at most a small multiple of LSINFINITY,
* therefore sums do not overflow
* - n.oa and n.ifa are always non-NULL
* - oa->rtr does not contain calculating router itself
*/
void ospf_rt_spf(struct proto_ospf *po); void ospf_rt_spf(struct proto_ospf *po);
void ospf_rt_initort(struct fib_node *fn); void ospf_rt_initort(struct fib_node *fn);

View file

@ -81,10 +81,14 @@ fibnode_to_lsaid(struct proto_ospf *po, struct fib_node *fn)
static inline u32 static inline u32
fibnode_to_lsaid(struct proto_ospf *po, struct fib_node *fn) fibnode_to_lsaid(struct proto_ospf *po, struct fib_node *fn)
{ {
/* In OSPFv3, it is simpler. There is not a requirement /*
for membership of the result in input network, so we * In OSPFv3, it is simpler. There is not a requirement for
just use hash-based unique ID. */ * membership of the result in the input network, so we just use a
* hash-based unique ID of a routing table entry for a route that
* originated given LSA. For ext-LSA, it is an imported route in the
* nest's routing table (p->table). For summary-LSA, it is a
* 'source' route in the protocol internal routing table (po->rtf).
*/
return fn->uid; return fn->uid;
} }
@ -769,17 +773,6 @@ originate_sum_rt_lsa(struct ospf_area *oa, struct fib_node *fn, int metric, u32
ospf_lsupd_flood(po, NULL, NULL, &lsa, dom, 1); ospf_lsupd_flood(po, NULL, NULL, &lsa, dom, 1);
} }
void
originate_sum_lsa(struct ospf_area *oa, struct fib_node *fn, int type, int metric, u32 options)
{
if (type == ORT_NET)
originate_sum_net_lsa(oa, fn, metric);
else
originate_sum_rt_lsa(oa, fn, metric, options);
}
void void
flush_sum_lsa(struct ospf_area *oa, struct fib_node *fn, int type) flush_sum_lsa(struct ospf_area *oa, struct fib_node *fn, int type)
{ {
@ -823,65 +816,6 @@ flush_sum_lsa(struct ospf_area *oa, struct fib_node *fn, int type)
} }
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;
#ifdef LOCAL_DEBUG
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);
#endif
WALK_LIST(oa, po->area_list)
{
flush = 0;
if ((nf->n.metric1 >= LSINFINITY) || (nf->n.type > RTS_OSPF_IA))
flush = 1;
if ((dest == ORT_ROUTER) && (!(nf->n.options & ORTA_ASBR)))
flush = 1;
if ((!nf->n.oa) || (nf->n.oa->areaid == oa->areaid))
flush = 1;
if (nf->n.ifa) {
if (nf->n.ifa->oa->areaid == oa->areaid)
flush = 1;
}
else flush = 1;
/* Don't send summary into stub areas
* We send just default route (and later) */
if (oa->stub)
flush = 1;
mlen = nf->fn.pxlen;
ip = ipa_and(nf->fn.prefix, ipa_mkmask(mlen));
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 */
flush = 1;
if ((nf->n.oa == po->backbone) && (oa->trcap)) flush = 0;
}
if (flush)
flush_sum_lsa(oa, &nf->fn, dest);
else
originate_sum_lsa(oa, &nf->fn, dest, nf->n.metric1, nf->n.options);
}
}
static void * static void *
originate_ext_lsa_body(net *n, rte *e, u16 *length, struct proto_ospf *po, originate_ext_lsa_body(net *n, rte *e, u16 *length, struct proto_ospf *po,
struct ea_list *attrs) struct ea_list *attrs)

View file

@ -67,13 +67,15 @@ void originate_net_lsa(struct ospf_iface *ifa);
void update_net_lsa(struct ospf_iface *ifa); void update_net_lsa(struct ospf_iface *ifa);
void update_link_lsa(struct ospf_iface *ifa); void update_link_lsa(struct ospf_iface *ifa);
int can_flush_lsa(struct proto_ospf *po); int can_flush_lsa(struct proto_ospf *po);
int max_ext_lsa(unsigned pxlen);
void originate_sum_net_lsa(struct ospf_area *oa, struct fib_node *fn, int metric);
void originate_sum_rt_lsa(struct ospf_area *oa, struct fib_node *fn, int metric, u32 options UNUSED);
void flush_sum_lsa(struct ospf_area *oa, struct fib_node *fn, int type);
void originate_ext_lsa(net * n, rte * e, struct proto_ospf *po, void originate_ext_lsa(net * n, rte * e, struct proto_ospf *po,
struct ea_list *attrs); struct ea_list *attrs);
void flush_ext_lsa(net *n, struct proto_ospf *po); void flush_ext_lsa(net *n, struct proto_ospf *po);
void check_sum_lsa(struct proto_ospf *po, ort *nf, int);
void originate_sum_lsa(struct ospf_area *oa, struct fib_node *fn, int type, int metric, u32 options);
void flush_sum_lsa(struct ospf_area *oa, struct fib_node *fn, int type);
#ifdef OSPFv2 #ifdef OSPFv2
struct top_hash_entry * ospf_hash_find_net(struct top_graph *f, u32 domain, u32 lsa); struct top_hash_entry * ospf_hash_find_net(struct top_graph *f, u32 domain, u32 lsa);