[PATCH] OSPF: fix next-hop inheriting condition

Soha Jin soha at jin.sh
Tue Mar 19 11:51:24 CET 2024


Signed-off-by: Soha Jin <soha at jin.sh>
Co-developed-by: Wende Tan <twd2.me at gmail.com>
---
 proto/ospf/rt.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/proto/ospf/rt.c b/proto/ospf/rt.c
index efcd4e17..7636e9a2 100644
--- a/proto/ospf/rt.c
+++ b/proto/ospf/rt.c
@@ -1726,10 +1726,24 @@ ospf_rt_spf(struct ospf_proto *p)
 
 
 static inline int
-inherit_nexthops(struct nexthop *pn)
+inherit_nexthops(struct top_hash_entry *par)
 {
-  /* Proper nexthops (with defined GW) or dummy vlink nexthops (without iface) */
-  return pn && (ipa_nonzero(pn->gw) || !pn->iface);
+  struct nexthop *pn = par->nhs;
+  /* no next-hop to inherit, or the parent is root */
+  if (!pn)
+    return 0;
+  /* 16.1.1, there is at least one intervening router, can directly inherit */
+  if (par->lsa_type == LSA_T_RT)
+    return 1;
+  /*
+   * Now, the parent is a LSA_T_NET, and cannot know whether this net is
+   * directly connected or not. We can only decide with the next-hop.
+   * Note: A next-hop to PtP iface may only have no gw. In this condition, the
+   * next-hop can also be inherited.
+   */
+  return ipa_nonzero(pn->gw) || /* proper next-hops (with defined GW) */
+    !pn->iface || /* dummy vlink next-hops (without iface) */
+    !(pn->iface->flags & IF_MULTIACCESS); /* iface is PtP */
 }
 
 static inline ip_addr
@@ -1760,7 +1774,7 @@ calc_next_hop(struct ospf_area *oa, struct top_hash_entry *en,
       en->lsa.id, en->lsa.rt, en->lsa_type);
 
   /* Usually, we inherit parent nexthops */
-  if (inherit_nexthops(pn))
+  if (inherit_nexthops(par))
     return pn;
 
   /*
-- 
2.39.2



More information about the Bird-users mailing list