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 <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2021-09-24 16:36:27 -04:00
parent 6cd9a93ddd
commit d597533a9d
8 changed files with 42 additions and 28 deletions

View File

@ -61,6 +61,7 @@ struct rnh {
vrf_id_t vrf_id; vrf_id_t vrf_id;
afi_t afi; afi_t afi;
safi_t safi;
uint32_t seqno; uint32_t seqno;

View File

@ -1240,7 +1240,8 @@ static void zread_rnh_register(ZAPI_HANDLER_ARGS)
/* Anything not AF_INET/INET6 has been filtered out above */ /* Anything not AF_INET/INET6 has been filtered out above */
if (!exist || flag_changed) 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)); zebra_add_rnh_client(rnh, client, zvrf_id(zvrf));
} }
@ -1305,7 +1306,7 @@ static void zread_rnh_unregister(ZAPI_HANDLER_ARGS)
p.family); p.family);
return; return;
} }
rnh = zebra_lookup_rnh(&p, zvrf_id(zvrf)); rnh = zebra_lookup_rnh(&p, zvrf_id(zvrf), SAFI_UNICAST);
if (rnh) { if (rnh) {
client->nh_dereg_time = monotime(NULL); client->nh_dereg_time = monotime(NULL);
zebra_remove_rnh_client(rnh, client); zebra_remove_rnh_client(rnh, client);

View File

@ -754,7 +754,8 @@ void zebra_rib_evaluate_rn_nexthops(struct route_node *rn, uint32_t seq)
} }
rnh->seqno = 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; rn = rn->parent;

View File

@ -70,14 +70,17 @@ void zebra_rnh_init(void)
hook_register(zserv_client_close, zebra_client_cleanup_rnh); 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 zebra_vrf *zvrf;
struct route_table *t = NULL; struct route_table *t = NULL;
zvrf = zebra_vrf_lookup_by_id(vrfid); zvrf = zebra_vrf_lookup_by_id(vrfid);
if (zvrf) if (zvrf) {
if (safi == SAFI_UNICAST)
t = zvrf->rnh_table[afi]; t = zvrf->rnh_table[afi];
}
return t; 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 route_node *rn;
struct rnh *rnh = NULL; struct rnh *rnh = NULL;
afi_t afi = family2afi(p->family); afi_t afi = family2afi(p->family);
safi_t safi = SAFI_UNICAST;
if (IS_ZEBRA_DEBUG_NHT) { if (IS_ZEBRA_DEBUG_NHT) {
struct vrf *vrf = vrf_lookup_by_id(vrfid); 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) { if (!table) {
struct vrf *vrf = vrf_lookup_by_id(vrfid); 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->vrf_id = vrfid;
rnh->seqno = 0; rnh->seqno = 0;
rnh->afi = afi; rnh->afi = afi;
rnh->safi = safi;
rnh->zebra_pseudowire_list = list_new(); rnh->zebra_pseudowire_list = list_new();
route_lock_node(rn); route_lock_node(rn);
rn->info = rnh; rn->info = rnh;
@ -184,12 +191,12 @@ struct rnh *zebra_add_rnh(struct prefix *p, vrf_id_t vrfid, bool *exists)
return (rn->info); 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_table *table;
struct route_node *rn; 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) if (!table)
return NULL; 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)) { if (!listnode_lookup(rnh->zebra_pseudowire_list, pw)) {
listnode_add(rnh->zebra_pseudowire_list, pw); listnode_add(rnh->zebra_pseudowire_list, pw);
pw->rnh = rnh; pw->rnh = rnh;
zebra_evaluate_rnh(zvrf, family2afi(pw->af), 1, &nh); zebra_evaluate_rnh(zvrf, family2afi(pw->af), 1, &nh,
SAFI_UNICAST);
} else } else
*nht_exists = true; *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. * of a particular VRF and address-family or a specific prefix.
*/ */
void zebra_evaluate_rnh(struct zebra_vrf *zvrf, afi_t afi, int force, 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_table *rnh_table;
struct route_node *nrn; 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 if (!rnh_table) // unexpected
return; 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_table *table;
struct route_node *rn; struct route_node *rn;
table = get_rnh_table(vrfid, afi); table = get_rnh_table(vrfid, afi, SAFI_UNICAST);
if (!table) { if (!table) {
if (IS_ZEBRA_DEBUG_NHT) if (IS_ZEBRA_DEBUG_NHT)
zlog_debug("print_rnhs: rnh table not found"); 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)); 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) { if (!ntable) {
zlog_debug("cleanup_rnh_client: rnh table not found"); zlog_debug("cleanup_rnh_client: rnh table not found");
return -1; return -1;

View File

@ -33,7 +33,8 @@ extern void zebra_rnh_init(void);
extern struct rnh *zebra_add_rnh(struct prefix *p, vrf_id_t vrfid, extern struct rnh *zebra_add_rnh(struct prefix *p, vrf_id_t vrfid,
bool *exists); 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_free_rnh(struct rnh *rnh);
extern void zebra_add_rnh_client(struct rnh *rnh, struct zserv *client, extern void zebra_add_rnh_client(struct rnh *rnh, struct zserv *client,
vrf_id_t vrfid); 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_deregister_rnh_pseudowire(vrf_id_t, struct zebra_pw *);
extern void zebra_remove_rnh_client(struct rnh *rnh, struct zserv *client); 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, 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, extern void zebra_print_rnh_table(vrf_id_t vrfid, afi_t afi, struct vty *vty,
struct prefix *p); struct prefix *p);

View File

@ -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)); route_map_counter_increment(NHT_RM_MAP(zvrf, afi, rtype));
if (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; 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); zvrf->vrf->vrf_id, rtype);
NHT_RM_MAP(zvrf, afi, rtype) = NULL; 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)); 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; afi_ip = 1;
zebra_evaluate_rnh(zvrf, AFI_IP, zebra_evaluate_rnh(
1, NULL); zvrf, AFI_IP, 1, NULL,
SAFI_UNICAST);
} }
} }
} }
@ -1617,8 +1618,9 @@ static void zebra_nht_rm_update(const char *rmap)
afi_ipv6 = 1; afi_ipv6 = 1;
zebra_evaluate_rnh(zvrf, AFI_IP, zebra_evaluate_rnh(
1, NULL); zvrf, AFI_IP, 1, NULL,
SAFI_UNICAST);
} }
} }
} }

View File

@ -196,7 +196,7 @@ static void zebra_sr_policy_notify_update(struct zebra_sr_policy *policy)
exit(1); exit(1);
} }
rnh = zebra_lookup_rnh(&p, zvrf_id(zvrf)); rnh = zebra_lookup_rnh(&p, zvrf_id(zvrf), SAFI_UNICAST);
if (!rnh) if (!rnh)
return; return;

View File

@ -1374,7 +1374,7 @@ DEFUN (ip_nht_default_route,
zvrf->zebra_rnh_ip_default_route = true; 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; return CMD_SUCCESS;
} }
@ -1712,7 +1712,7 @@ DEFUN (no_ip_nht_default_route,
return CMD_SUCCESS; return CMD_SUCCESS;
zvrf->zebra_rnh_ip_default_route = false; 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; return CMD_SUCCESS;
} }
@ -1732,7 +1732,7 @@ DEFUN (ipv6_nht_default_route,
return CMD_SUCCESS; return CMD_SUCCESS;
zvrf->zebra_rnh_ipv6_default_route = true; 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; return CMD_SUCCESS;
} }
@ -1753,7 +1753,7 @@ DEFUN (no_ipv6_nht_default_route,
return CMD_SUCCESS; return CMD_SUCCESS;
zvrf->zebra_rnh_ipv6_default_route = false; 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; return CMD_SUCCESS;
} }