From d597533a9dcabc298a53112c22e94c0264cd3f39 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 24 Sep 2021 16:36:27 -0400 Subject: [PATCH] zebra: Start carrying safi for rnh processing PIM is going to need to be able to send down the address it is trying to resolve in the multicast rib. We need a way to signal this to the end developer. Start the conversion by adding the ability to have a safi. But only allow SAFI_UNICAST at the moment. Signed-off-by: Donald Sharp --- zebra/rib.h | 1 + zebra/zapi_msg.c | 5 +++-- zebra/zebra_rib.c | 3 ++- zebra/zebra_rnh.c | 32 ++++++++++++++++++++------------ zebra/zebra_rnh.h | 5 +++-- zebra/zebra_routemap.c | 14 ++++++++------ zebra/zebra_srte.c | 2 +- zebra/zebra_vty.c | 8 ++++---- 8 files changed, 42 insertions(+), 28 deletions(-) diff --git a/zebra/rib.h b/zebra/rib.h index 92e1b3635..076608bb0 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -61,6 +61,7 @@ struct rnh { vrf_id_t vrf_id; afi_t afi; + safi_t safi; uint32_t seqno; diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index 4c0a0c82b..c5f29b8fe 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -1240,7 +1240,8 @@ static void zread_rnh_register(ZAPI_HANDLER_ARGS) /* Anything not AF_INET/INET6 has been filtered out above */ if (!exist || flag_changed) - zebra_evaluate_rnh(zvrf, family2afi(p.family), 1, &p); + zebra_evaluate_rnh(zvrf, family2afi(p.family), 1, &p, + SAFI_UNICAST); zebra_add_rnh_client(rnh, client, zvrf_id(zvrf)); } @@ -1305,7 +1306,7 @@ static void zread_rnh_unregister(ZAPI_HANDLER_ARGS) p.family); return; } - rnh = zebra_lookup_rnh(&p, zvrf_id(zvrf)); + rnh = zebra_lookup_rnh(&p, zvrf_id(zvrf), SAFI_UNICAST); if (rnh) { client->nh_dereg_time = monotime(NULL); zebra_remove_rnh_client(rnh, client); diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 5230f0a4d..12e82dde9 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -754,7 +754,8 @@ void zebra_rib_evaluate_rn_nexthops(struct route_node *rn, uint32_t seq) } rnh->seqno = seq; - zebra_evaluate_rnh(zvrf, family2afi(p->family), 0, p); + zebra_evaluate_rnh(zvrf, family2afi(p->family), 0, p, + rnh->safi); } rn = rn->parent; diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index c58debb6a..e782839d1 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -70,14 +70,17 @@ void zebra_rnh_init(void) hook_register(zserv_client_close, zebra_client_cleanup_rnh); } -static inline struct route_table *get_rnh_table(vrf_id_t vrfid, afi_t afi) +static inline struct route_table *get_rnh_table(vrf_id_t vrfid, afi_t afi, + safi_t safi) { struct zebra_vrf *zvrf; struct route_table *t = NULL; zvrf = zebra_vrf_lookup_by_id(vrfid); - if (zvrf) - t = zvrf->rnh_table[afi]; + if (zvrf) { + if (safi == SAFI_UNICAST) + t = zvrf->rnh_table[afi]; + } return t; } @@ -133,13 +136,16 @@ struct rnh *zebra_add_rnh(struct prefix *p, vrf_id_t vrfid, bool *exists) struct route_node *rn; struct rnh *rnh = NULL; afi_t afi = family2afi(p->family); + safi_t safi = SAFI_UNICAST; if (IS_ZEBRA_DEBUG_NHT) { struct vrf *vrf = vrf_lookup_by_id(vrfid); - zlog_debug("%s(%u): Add RNH %pFX", VRF_LOGNAME(vrf), vrfid, p); + zlog_debug("%s(%u): Add RNH %pFX for safi: %u", + VRF_LOGNAME(vrf), vrfid, p, safi); } - table = get_rnh_table(vrfid, afi); + + table = get_rnh_table(vrfid, afi, safi); if (!table) { struct vrf *vrf = vrf_lookup_by_id(vrfid); @@ -170,6 +176,7 @@ struct rnh *zebra_add_rnh(struct prefix *p, vrf_id_t vrfid, bool *exists) rnh->vrf_id = vrfid; rnh->seqno = 0; rnh->afi = afi; + rnh->safi = safi; rnh->zebra_pseudowire_list = list_new(); route_lock_node(rn); rn->info = rnh; @@ -184,12 +191,12 @@ struct rnh *zebra_add_rnh(struct prefix *p, vrf_id_t vrfid, bool *exists) return (rn->info); } -struct rnh *zebra_lookup_rnh(struct prefix *p, vrf_id_t vrfid) +struct rnh *zebra_lookup_rnh(struct prefix *p, vrf_id_t vrfid, safi_t safi) { struct route_table *table; struct route_node *rn; - table = get_rnh_table(vrfid, family2afi(PREFIX_FAMILY(p))); + table = get_rnh_table(vrfid, family2afi(PREFIX_FAMILY(p)), safi); if (!table) return NULL; @@ -343,7 +350,8 @@ void zebra_register_rnh_pseudowire(vrf_id_t vrf_id, struct zebra_pw *pw, if (!listnode_lookup(rnh->zebra_pseudowire_list, pw)) { listnode_add(rnh->zebra_pseudowire_list, pw); pw->rnh = rnh; - zebra_evaluate_rnh(zvrf, family2afi(pw->af), 1, &nh); + zebra_evaluate_rnh(zvrf, family2afi(pw->af), 1, &nh, + SAFI_UNICAST); } else *nht_exists = true; } @@ -762,12 +770,12 @@ static void zebra_rnh_clear_nhc_flag(struct zebra_vrf *zvrf, afi_t afi, * of a particular VRF and address-family or a specific prefix. */ void zebra_evaluate_rnh(struct zebra_vrf *zvrf, afi_t afi, int force, - struct prefix *p) + struct prefix *p, safi_t safi) { struct route_table *rnh_table; struct route_node *nrn; - rnh_table = get_rnh_table(zvrf->vrf->vrf_id, afi); + rnh_table = get_rnh_table(zvrf->vrf->vrf_id, afi, safi); if (!rnh_table) // unexpected return; @@ -802,7 +810,7 @@ void zebra_print_rnh_table(vrf_id_t vrfid, afi_t afi, struct vty *vty, struct route_table *table; struct route_node *rn; - table = get_rnh_table(vrfid, afi); + table = get_rnh_table(vrfid, afi, SAFI_UNICAST); if (!table) { if (IS_ZEBRA_DEBUG_NHT) zlog_debug("print_rnhs: rnh table not found"); @@ -1323,7 +1331,7 @@ static int zebra_cleanup_rnh_client(vrf_id_t vrf_id, afi_t afi, zebra_route_string(client->proto), afi2str(afi)); } - ntable = get_rnh_table(vrf_id, afi); + ntable = get_rnh_table(vrf_id, afi, SAFI_UNICAST); if (!ntable) { zlog_debug("cleanup_rnh_client: rnh table not found"); return -1; diff --git a/zebra/zebra_rnh.h b/zebra/zebra_rnh.h index 01ad7215b..27c016ebe 100644 --- a/zebra/zebra_rnh.h +++ b/zebra/zebra_rnh.h @@ -33,7 +33,8 @@ extern void zebra_rnh_init(void); extern struct rnh *zebra_add_rnh(struct prefix *p, vrf_id_t vrfid, bool *exists); -extern struct rnh *zebra_lookup_rnh(struct prefix *p, vrf_id_t vrfid); +extern struct rnh *zebra_lookup_rnh(struct prefix *p, vrf_id_t vrfid, + safi_t safi); extern void zebra_free_rnh(struct rnh *rnh); extern void zebra_add_rnh_client(struct rnh *rnh, struct zserv *client, vrf_id_t vrfid); @@ -43,7 +44,7 @@ extern void zebra_register_rnh_pseudowire(vrf_id_t, struct zebra_pw *, bool *); extern void zebra_deregister_rnh_pseudowire(vrf_id_t, struct zebra_pw *); extern void zebra_remove_rnh_client(struct rnh *rnh, struct zserv *client); extern void zebra_evaluate_rnh(struct zebra_vrf *zvrf, afi_t afi, int force, - struct prefix *p); + struct prefix *p, safi_t safi); extern void zebra_print_rnh_table(vrf_id_t vrfid, afi_t afi, struct vty *vty, struct prefix *p); diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 0887ce1f0..908c13f3d 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -319,7 +319,7 @@ static int ip_nht_rm_add(struct zebra_vrf *zvrf, const char *rmap, int rtype, route_map_counter_increment(NHT_RM_MAP(zvrf, afi, rtype)); if (NHT_RM_MAP(zvrf, afi, rtype)) - zebra_evaluate_rnh(zvrf, AFI_IP, 1, NULL); + zebra_evaluate_rnh(zvrf, AFI_IP, 1, NULL, SAFI_UNICAST); return CMD_SUCCESS; } @@ -340,7 +340,7 @@ static int ip_nht_rm_del(struct zebra_vrf *zvrf, const char *rmap, int rtype, zvrf->vrf->vrf_id, rtype); NHT_RM_MAP(zvrf, afi, rtype) = NULL; - zebra_evaluate_rnh(zvrf, AFI_IP, 1, NULL); + zebra_evaluate_rnh(zvrf, AFI_IP, 1, NULL, SAFI_UNICAST); } XFREE(MTYPE_ROUTE_MAP_NAME, NHT_RM_NAME(zvrf, afi, rtype)); } @@ -1587,8 +1587,9 @@ static void zebra_nht_rm_update(const char *rmap) afi_ip = 1; - zebra_evaluate_rnh(zvrf, AFI_IP, - 1, NULL); + zebra_evaluate_rnh( + zvrf, AFI_IP, 1, NULL, + SAFI_UNICAST); } } } @@ -1617,8 +1618,9 @@ static void zebra_nht_rm_update(const char *rmap) afi_ipv6 = 1; - zebra_evaluate_rnh(zvrf, AFI_IP, - 1, NULL); + zebra_evaluate_rnh( + zvrf, AFI_IP, 1, NULL, + SAFI_UNICAST); } } } diff --git a/zebra/zebra_srte.c b/zebra/zebra_srte.c index 0fa054105..d87b3149a 100644 --- a/zebra/zebra_srte.c +++ b/zebra/zebra_srte.c @@ -196,7 +196,7 @@ static void zebra_sr_policy_notify_update(struct zebra_sr_policy *policy) exit(1); } - rnh = zebra_lookup_rnh(&p, zvrf_id(zvrf)); + rnh = zebra_lookup_rnh(&p, zvrf_id(zvrf), SAFI_UNICAST); if (!rnh) return; diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 779996a80..fe2ffdfea 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -1374,7 +1374,7 @@ DEFUN (ip_nht_default_route, zvrf->zebra_rnh_ip_default_route = true; - zebra_evaluate_rnh(zvrf, AFI_IP, 0, NULL); + zebra_evaluate_rnh(zvrf, AFI_IP, 0, NULL, SAFI_UNICAST); return CMD_SUCCESS; } @@ -1712,7 +1712,7 @@ DEFUN (no_ip_nht_default_route, return CMD_SUCCESS; zvrf->zebra_rnh_ip_default_route = false; - zebra_evaluate_rnh(zvrf, AFI_IP, 0, NULL); + zebra_evaluate_rnh(zvrf, AFI_IP, 0, NULL, SAFI_UNICAST); return CMD_SUCCESS; } @@ -1732,7 +1732,7 @@ DEFUN (ipv6_nht_default_route, return CMD_SUCCESS; zvrf->zebra_rnh_ipv6_default_route = true; - zebra_evaluate_rnh(zvrf, AFI_IP6, 0, NULL); + zebra_evaluate_rnh(zvrf, AFI_IP6, 0, NULL, SAFI_UNICAST); return CMD_SUCCESS; } @@ -1753,7 +1753,7 @@ DEFUN (no_ipv6_nht_default_route, return CMD_SUCCESS; zvrf->zebra_rnh_ipv6_default_route = false; - zebra_evaluate_rnh(zvrf, AFI_IP6, 0, NULL); + zebra_evaluate_rnh(zvrf, AFI_IP6, 0, NULL, SAFI_UNICAST); return CMD_SUCCESS; } -- 2.39.2