[PATCH] ospf: Improve calc_next_hop()
Joakim Tjernlund
Joakim.Tjernlund at transmode.se
Mon Dec 27 19:26:15 CET 2010
Using the new ospf_pos_to_ifa(), calc_next_hop() can be cleaned up
and improved further.
Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund at transmode.se>
---
proto/ospf/rt.c | 49 +++++++++++++++++++++++++------------------------
1 files changed, 25 insertions(+), 24 deletions(-)
diff --git a/proto/ospf/rt.c b/proto/ospf/rt.c
index 84fea16..d851616 100644
--- a/proto/ospf/rt.c
+++ b/proto/ospf/rt.c
@@ -1350,37 +1350,38 @@ calc_next_hop(struct ospf_area *oa, struct top_hash_entry *en,
if (inherit_nexthops(pn))
return pn;
- /*
+ /*
* There are three cases:
* 1) en is a local network (and par is root)
* 2) en is a ptp or ptmp neighbor (and par is root)
* 3) en is a bcast or nbma neighbor (and par is local network)
*/
- /* The first case - local network */
- if ((en->lsa.type == LSA_T_NET) && (par == oa->rt))
- {
- ifa = ospf_pos_to_ifa(oa, pos);
- if (!ifa)
- return NULL;
+ if (par == oa->rt) { /* par is root ? */
+ if (rtl->type == LSART_VLNK) /* en->lsa.type == LSA_T_RT needed ? */
+ return new_nexthop(po, IPA_NONE, NULL, 0); /* No iface ? */
- return new_nexthop(po, IPA_NONE, ifa->iface, ifa->ecmp_weight);
- }
+ ifa = ospf_pos_to_ifa(oa, pos);
+ if (!ifa)
+ goto bad;
- /* The second case - ptp or ptmp neighbor */
- if ((en->lsa.type == LSA_T_RT) && (par == oa->rt))
- {
- if (rtl->type == LSART_VLNK)
- return new_nexthop(po, IPA_NONE, NULL, 0);
- ifa = ospf_pos_to_ifa(oa, pos);
- if (!ifa)
- return NULL;
- {
- struct ospf_neighbor *m = find_neigh(ifa, rid);
- if (m && (m->state == NEIGHBOR_FULL))
- return new_nexthop(po, m->ip, ifa->iface, ifa->ecmp_weight);
- }
- return NULL;
+ /* The first case - local network */
+ if (en->lsa.type == LSA_T_NET)
+ return new_nexthop(po, IPA_NONE, ifa->iface, ifa->ecmp_weight);
+
+ /* The second case - ptp or ptmp neighbor */
+ if (en->lsa.type == LSA_T_RT)
+ {
+ if (ifa->type == OSPF_IT_PTP)
+ return new_nexthop(po, ifa->addr->opposite, ifa->iface,
+ ifa->ecmp_weight);
+ else { /* must be PTMP */
+ struct ospf_neighbor *m = find_neigh(ifa, rid);
+ if (m && (m->state == NEIGHBOR_FULL))
+ return new_nexthop(po, m->ip, ifa->iface, ifa->ecmp_weight);
+ }
+ }
+ goto bad;
}
/* The third case - bcast or nbma neighbor */
@@ -1396,7 +1397,7 @@ calc_next_hop(struct ospf_area *oa, struct top_hash_entry *en,
* already computed in link_back().
*/
if (ipa_zero(en->lb))
- goto bad;
+ return NULL; /* This is not "bad", may happen intermittent. */
return new_nexthop(po, en->lb, pn->iface, pn->weight);
--
1.7.2.5
More information about the Bird-users
mailing list