summaryrefslogtreecommitdiffstats
path: root/proto/ospf/topology.c
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2009-06-10 23:45:08 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2009-06-10 23:45:08 +0200
commit3d15dcdb1cc91c694aa9319b86bb37510d7ed12b (patch)
tree96c5dda68741dd75b4b5d0037e782d5d89726d93 /proto/ospf/topology.c
parentb99d378698641b9821e4b708a90761aeb9bf6cc4 (diff)
downloadbird-3d15dcdb1cc91c694aa9319b86bb37510d7ed12b.tar
bird-3d15dcdb1cc91c694aa9319b86bb37510d7ed12b.zip
Changes OSPF to generate stub networks for non-primary addresses.
Also does some reorganization in RT LSA announcement.
Diffstat (limited to 'proto/ospf/topology.c')
-rw-r--r--proto/ospf/topology.c196
1 files changed, 92 insertions, 104 deletions
diff --git a/proto/ospf/topology.c b/proto/ospf/topology.c
index a15d2e3..18100f7 100644
--- a/proto/ospf/topology.c
+++ b/proto/ospf/topology.c
@@ -23,176 +23,164 @@
int ptp_unnumbered_stub_lsa = 0;
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;
+}
+
+
+static void *
originate_rt_lsa_body(struct ospf_area *oa, u16 * length)
{
struct proto_ospf *po = oa->po;
struct ospf_iface *ifa;
- int j = 0, k = 0;
- u16 i = 0;
+ int i = 0, j = 0, k = 0, bitv = 0;
struct ospf_lsa_rt *rt;
- struct ospf_lsa_rt_link *ln, *ln_after;
+ struct ospf_lsa_rt_link *ln;
struct ospf_neighbor *neigh;
DBG("%s: Originating RT_lsa body for area \"%I\".\n", po->proto.name,
oa->areaid);
-
- WALK_LIST(ifa, po->iface_list)
- {
- if ((ifa->oa == oa) && (ifa->state != OSPF_IS_DOWN))
- {
- i++;
- if ((ifa->type == OSPF_IT_PTP) && (ifa->state == OSPF_IS_PTP) &&
- (ptp_unnumbered_stub_lsa || !(ifa->iface->addr->flags & IA_UNNUMBERED)))
- i++;
- }
- }
- rt = mb_allocz(po->proto.pool, sizeof(struct ospf_lsa_rt) +
- i * sizeof(struct ospf_lsa_rt_link));
+
+ ASSERT(po->lsab_used == 0);
+ rt = lsab_allocz(po, sizeof(struct ospf_lsa_rt));
if (po->areano > 1)
rt->veb.bit.b = 1;
if ((po->ebit) && (!oa->stub))
rt->veb.bit.e = 1;
- ln = (struct ospf_lsa_rt_link *) (rt + 1);
- ln_after = ln + i;
+ rt = NULL; /* buffer might be reallocated later */
WALK_LIST(ifa, po->iface_list)
{
- if ((ifa->type == OSPF_IT_VLINK) && (ifa->voa == oa) && (!EMPTY_LIST(ifa->neigh_list)))
+ int master = 0;
+
+ if ((ifa->type == OSPF_IT_VLINK) && (ifa->voa == oa) &&
+ (!EMPTY_LIST(ifa->neigh_list)))
{
neigh = (struct ospf_neighbor *) HEAD(ifa->neigh_list);
if ((neigh->state == NEIGHBOR_FULL) && (ifa->cost <= 0xffff))
- rt->veb.bit.v = 1;
+ bitv = 1;
}
if ((ifa->oa != oa) || (ifa->state == OSPF_IS_DOWN))
continue;
- if (ln == ln_after)
- die("LSA space overflow");
+ /* BIRD does not support interface loops */
+ ASSERT(ifa->state != OSPF_IS_LOOP);
- 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)
+ switch (ifa->type)
{
- case OSPF_IT_PTP: /* rfc2328 - pg126 */
+ case OSPF_IT_PTP: /* RFC2328 - 12.4.1.1 */
neigh = (struct ospf_neighbor *) HEAD(ifa->neigh_list);
if ((!EMPTY_LIST(ifa->neigh_list)) && (neigh->state == NEIGHBOR_FULL))
{
+ ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
ln->type = LSART_PTP;
ln->id = neigh->rid;
+ ln->data = (ifa->iface->addr->flags & IA_UNNUMBERED) ?
+ ifa->iface->index : ipa_to_u32(ifa->iface->addr->ip);
ln->metric = ifa->cost;
ln->notos = 0;
- if (ifa->iface->addr->flags & IA_UNNUMBERED)
- {
- ln->data = ifa->iface->index;
- }
- else
- {
- ln->data = ipa_to_u32(ifa->iface->addr->ip);
- }
- }
- else
- {
- ln--;
- i--; /* No link added */
- }
-
- if ((ifa->state == OSPF_IS_PTP) &&
- (ptp_unnumbered_stub_lsa || !(ifa->iface->addr->flags & IA_UNNUMBERED)))
- {
- ln++;
- if (ln == ln_after)
- die("LSA space overflow");
-
- ln->type = LSART_STUB;
- ln->metric = ifa->cost;
- ln->notos = 0;
- if (ifa->iface->addr->flags & IA_UNNUMBERED)
- {
- ln->id = ipa_to_u32(ifa->iface->addr->opposite);
- ln->data = 0xffffffff;
- }
- else
- {
- ln->data = ipa_to_u32(ipa_mkmask(ifa->iface->addr->pxlen));
- ln->id = ipa_to_u32(ifa->iface->addr->prefix) & ln->data;
- }
+ i++;
+ master = 1;
}
break;
- case OSPF_IT_BCAST:
+
+ case OSPF_IT_BCAST: /* RFC2328 - 12.4.1.2 */
case OSPF_IT_NBMA:
if (ifa->state == OSPF_IS_WAITING)
- {
- ln->type = LSART_STUB;
- ln->data = ipa_to_u32(ipa_mkmask(ifa->iface->addr->pxlen));
- ln->id = ipa_to_u32(ifa->iface->addr->prefix) & ln->data;
- ln->metric = ifa->cost;
- ln->notos = 0;
- }
- else
- {
- j = 0, k = 0;
- WALK_LIST(neigh, ifa->neigh_list)
+ break;
+
+ 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;
}
- if (((ifa->state == OSPF_IS_DR) && (j == 1)) || (k == 1))
+
+ if (((ifa->state == OSPF_IS_DR) && (j == 1)) || (k == 1))
{
+ ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
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;
+ i++;
+ master = 1;
}
- else
- {
- ln->type = LSART_STUB;
- ln->data = ipa_to_u32(ipa_mkmask(ifa->iface->addr->pxlen));
- ln->id = ipa_to_u32(ifa->iface->addr->prefix) & ln->data;
- ln->metric = ifa->cost;
- ln->notos = 0;
- }
- }
break;
- case OSPF_IT_VLINK:
+
+ case OSPF_IT_VLINK: /* RFC2328 - 12.4.1.3 */
neigh = (struct ospf_neighbor *) HEAD(ifa->neigh_list);
if ((!EMPTY_LIST(ifa->neigh_list)) && (neigh->state == NEIGHBOR_FULL) && (ifa->cost <= 0xffff))
{
+ ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
ln->type = LSART_VLNK;
ln->id = neigh->rid;
+ ln->data = ipa_to_u32(ifa->iface->addr->ip);
ln->metric = ifa->cost;
ln->notos = 0;
- }
- else
- {
- ln--;
- i--; /* No link added */
+ i++;
+ master = 1;
}
break;
+
default:
- ln--;
- i--; /* No link added */
log("Unknown interface type %s", ifa->iface->name);
break;
}
- }
- ln++;
+
+ /* 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) ||
+ (a->flags & IA_UNNUMBERED))
+ continue;
+
+ 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++;
+ }
}
+
+ rt = po->lsab;
rt->links = i;
- *length = i * sizeof(struct ospf_lsa_rt_link) + sizeof(struct ospf_lsa_rt) +
- sizeof(struct ospf_lsa_header);
- return rt;
+ rt->veb.bit.v = bitv;
+ *length = po->lsab_used + sizeof(struct ospf_lsa_header);
+ return lsab_flush(po);
}
/**