diff options
author | Renato Westphal <renato@opensourcerouting.org> | 2019-01-21 15:30:36 +0100 |
---|---|---|
committer | Renato Westphal <renato@opensourcerouting.org> | 2019-01-21 16:26:36 +0100 |
commit | 73bf60a06b2d798a06e408fb37ffa2e8e574f611 (patch) | |
tree | ec418411179b57f57de88a6c8c59294f904ba361 /zebra/zebra_rnh.c | |
parent | zebra: fix the "show ip import-check" command (diff) | |
download | frr-73bf60a06b2d798a06e408fb37ffa2e8e574f611.tar.xz frr-73bf60a06b2d798a06e408fb37ffa2e8e574f611.zip |
zebra: consolidate how we indentify address-families in the NHT code
Favor usage of the afi_t enumeration to identify address-families
over using the classic AF_INET[6] constants for that. The choice to
use either of the two seems to be mostly arbitrary throughout our
code base, which leads to confusion and bugs like the one fixed by
commit 6f95d11a1. To address this problem, favor usage of the afi_t
enumeration whenever possible, since 1) it's an enumeration (helps
the compilers to catch some bugs), 2) has a safi_t sibling and 3)
can be used to index static arrays. AF_INET[6] should then be used
only when interfacing with the kernel or external libraries like
libc. The family2afi() and afi2family() functions can be used to
convert between the two different representations back and forth.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'zebra/zebra_rnh.c')
-rw-r--r-- | zebra/zebra_rnh.c | 113 |
1 files changed, 52 insertions, 61 deletions
diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index c3781888b..ee76df4db 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -78,7 +78,7 @@ 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, int family, +static inline struct route_table *get_rnh_table(vrf_id_t vrfid, afi_t afi, rnh_type_t type) { struct zebra_vrf *zvrf; @@ -88,10 +88,10 @@ static inline struct route_table *get_rnh_table(vrf_id_t vrfid, int family, if (zvrf) switch (type) { case RNH_NEXTHOP_TYPE: - t = zvrf->rnh_table[family2afi(family)]; + t = zvrf->rnh_table[afi]; break; case RNH_IMPORT_CHECK_TYPE: - t = zvrf->import_check_table[family2afi(family)]; + t = zvrf->import_check_table[afi]; break; } @@ -116,7 +116,7 @@ struct rnh *zebra_add_rnh(struct prefix *p, vrf_id_t vrfid, rnh_type_t type, prefix2str(p, buf, sizeof(buf)); zlog_debug("%u: Add RNH %s type %d", vrfid, buf, type); } - table = get_rnh_table(vrfid, PREFIX_FAMILY(p), type); + table = get_rnh_table(vrfid, family2afi(PREFIX_FAMILY(p)), type); if (!table) { prefix2str(p, buf, sizeof(buf)); flog_warn(EC_ZEBRA_RNH_NO_TABLE, @@ -153,7 +153,7 @@ struct rnh *zebra_lookup_rnh(struct prefix *p, vrf_id_t vrfid, rnh_type_t type) struct route_table *table; struct route_node *rn; - table = get_rnh_table(vrfid, PREFIX_FAMILY(p), type); + table = get_rnh_table(vrfid, family2afi(PREFIX_FAMILY(p)), type); if (!table) return NULL; @@ -278,7 +278,8 @@ void zebra_register_rnh_pseudowire(vrf_id_t vrf_id, struct zebra_pw *pw) if (rnh && !listnode_lookup(rnh->zebra_pseudowire_list, pw)) { listnode_add(rnh->zebra_pseudowire_list, pw); pw->rnh = rnh; - zebra_evaluate_rnh(zvrf, pw->af, 1, RNH_NEXTHOP_TYPE, &nh); + zebra_evaluate_rnh(zvrf, family2afi(pw->af), 1, + RNH_NEXTHOP_TYPE, &nh); } } @@ -299,22 +300,19 @@ void zebra_deregister_rnh_pseudowire(vrf_id_t vrf_id, struct zebra_pw *pw) /* Apply the NHT route-map for a client to the route (and nexthops) * resolving a NH. */ -static int zebra_rnh_apply_nht_rmap(int family, struct zebra_vrf *zvrf, +static int zebra_rnh_apply_nht_rmap(afi_t afi, struct zebra_vrf *zvrf, struct route_node *prn, struct route_entry *re, int proto) { int at_least_one = 0; - int rmap_family; /* Route map has diff AF family enum */ struct nexthop *nexthop; int ret; - rmap_family = (family == AF_INET) ? AFI_IP : AFI_IP6; - if (prn && re) { for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next) { ret = zebra_nht_route_map_check( - rmap_family, proto, &prn->p, zvrf, re, nexthop); + afi, proto, &prn->p, zvrf, re, nexthop); if (ret != RMAP_DENYMATCH) { SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); at_least_one++; /* at least one valid NH */ @@ -331,7 +329,7 @@ static int zebra_rnh_apply_nht_rmap(int family, struct zebra_vrf *zvrf, * for BGP route for import. */ static struct route_entry * -zebra_rnh_resolve_import_entry(struct zebra_vrf *zvrf, int family, +zebra_rnh_resolve_import_entry(struct zebra_vrf *zvrf, afi_t afi, struct route_node *nrn, struct rnh *rnh, struct route_node **prn) { @@ -341,7 +339,7 @@ zebra_rnh_resolve_import_entry(struct zebra_vrf *zvrf, int family, *prn = NULL; - route_table = zvrf->table[family2afi(family)][SAFI_UNICAST]; + route_table = zvrf->table[afi][SAFI_UNICAST]; if (!route_table) // unexpected return NULL; @@ -373,7 +371,7 @@ zebra_rnh_resolve_import_entry(struct zebra_vrf *zvrf, int family, * See if a tracked route entry for import (by BGP) has undergone any * change, and if so, notify the client. */ -static void zebra_rnh_eval_import_check_entry(vrf_id_t vrfid, int family, +static void zebra_rnh_eval_import_check_entry(vrf_id_t vrfid, afi_t afi, int force, struct route_node *nrn, struct rnh *rnh, struct route_entry *re) @@ -413,9 +411,11 @@ static void zebra_rnh_eval_import_check_entry(vrf_id_t vrfid, int family, /* * Notify clients registered for this nexthop about a change. */ -static void zebra_rnh_notify_protocol_clients( - struct zebra_vrf *zvrf, int family, struct route_node *nrn, - struct rnh *rnh, struct route_node *prn, struct route_entry *re) +static void zebra_rnh_notify_protocol_clients(struct zebra_vrf *zvrf, afi_t afi, + struct route_node *nrn, + struct rnh *rnh, + struct route_node *prn, + struct route_entry *re) { struct listnode *node; struct zserv *client; @@ -441,7 +441,7 @@ static void zebra_rnh_notify_protocol_clients( * nexthop to see if it is filtered or not. */ num_resolving_nh = zebra_rnh_apply_nht_rmap( - family, zvrf, prn, re, client->proto); + afi, zvrf, prn, re, client->proto); if (num_resolving_nh) rnh->filtered[client->proto] = 0; else @@ -468,8 +468,7 @@ static void zebra_rnh_notify_protocol_clients( } } -static void zebra_rnh_process_pbr_tables(int family, - struct route_node *nrn, +static void zebra_rnh_process_pbr_tables(afi_t afi, struct route_node *nrn, struct rnh *rnh, struct route_node *prn, struct route_entry *re) @@ -479,10 +478,6 @@ static void zebra_rnh_process_pbr_tables(int family, struct route_node *o_rn; struct listnode *node; struct zserv *client; - afi_t afi = AFI_IP; - - if (family == AF_INET6) - afi = AFI_IP6; /* * We are only concerned about nexthops that change for @@ -537,7 +532,7 @@ static bool rnh_nexthop_valid(const struct nexthop *nh) * nexthop. */ static struct route_entry * -zebra_rnh_resolve_nexthop_entry(struct zebra_vrf *zvrf, int family, +zebra_rnh_resolve_nexthop_entry(struct zebra_vrf *zvrf, afi_t afi, struct route_node *nrn, struct rnh *rnh, struct route_node **prn) { @@ -548,7 +543,7 @@ zebra_rnh_resolve_nexthop_entry(struct zebra_vrf *zvrf, int family, *prn = NULL; - route_table = zvrf->table[family2afi(family)][SAFI_UNICAST]; + route_table = zvrf->table[afi][SAFI_UNICAST]; if (!route_table) return NULL; @@ -635,7 +630,7 @@ static void zebra_rnh_process_pseudowires(vrf_id_t vrfid, struct rnh *rnh) * take appropriate action; this involves notifying any clients and/or * scheduling dependent static routes for processing. */ -static void zebra_rnh_eval_nexthop_entry(struct zebra_vrf *zvrf, int family, +static void zebra_rnh_eval_nexthop_entry(struct zebra_vrf *zvrf, afi_t afi, int force, struct route_node *nrn, struct rnh *rnh, struct route_node *prn, @@ -665,10 +660,10 @@ static void zebra_rnh_eval_nexthop_entry(struct zebra_vrf *zvrf, int family, * rnh->state. */ /* Notify registered protocol clients. */ - zebra_rnh_notify_protocol_clients(zvrf, family, nrn, rnh, prn, + zebra_rnh_notify_protocol_clients(zvrf, afi, nrn, rnh, prn, rnh->state); - zebra_rnh_process_pbr_tables(family, nrn, rnh, prn, rnh->state); + zebra_rnh_process_pbr_tables(afi, nrn, rnh, prn, rnh->state); /* Process pseudowires attached to this nexthop */ zebra_rnh_process_pseudowires(zvrf->vrf->vrf_id, rnh); @@ -676,7 +671,7 @@ static void zebra_rnh_eval_nexthop_entry(struct zebra_vrf *zvrf, int family, } /* Evaluate one tracked entry */ -static void zebra_rnh_evaluate_entry(struct zebra_vrf *zvrf, int family, +static void zebra_rnh_evaluate_entry(struct zebra_vrf *zvrf, afi_t afi, int force, rnh_type_t type, struct route_node *nrn) { @@ -695,11 +690,9 @@ static void zebra_rnh_evaluate_entry(struct zebra_vrf *zvrf, int family, /* Identify route entry (RE) resolving this tracked entry. */ if (type == RNH_IMPORT_CHECK_TYPE) - re = zebra_rnh_resolve_import_entry(zvrf, family, nrn, rnh, - &prn); + re = zebra_rnh_resolve_import_entry(zvrf, afi, nrn, rnh, &prn); else - re = zebra_rnh_resolve_nexthop_entry(zvrf, family, nrn, rnh, - &prn); + re = zebra_rnh_resolve_nexthop_entry(zvrf, afi, nrn, rnh, &prn); /* If the entry cannot be resolved and that is also the existing state, * there is nothing further to do. @@ -709,10 +702,10 @@ static void zebra_rnh_evaluate_entry(struct zebra_vrf *zvrf, int family, /* Process based on type of entry. */ if (type == RNH_IMPORT_CHECK_TYPE) - zebra_rnh_eval_import_check_entry(zvrf->vrf->vrf_id, family, - force, nrn, rnh, re); + zebra_rnh_eval_import_check_entry(zvrf->vrf->vrf_id, afi, force, + nrn, rnh, re); else - zebra_rnh_eval_nexthop_entry(zvrf, family, force, nrn, rnh, prn, + zebra_rnh_eval_nexthop_entry(zvrf, afi, force, nrn, rnh, prn, re); } @@ -725,7 +718,7 @@ static void zebra_rnh_evaluate_entry(struct zebra_vrf *zvrf, int family, * we can have a situation where one re entry * covers multiple nexthops we are interested in. */ -static void zebra_rnh_clear_nhc_flag(struct zebra_vrf *zvrf, int family, +static void zebra_rnh_clear_nhc_flag(struct zebra_vrf *zvrf, afi_t afi, rnh_type_t type, struct route_node *nrn) { struct rnh *rnh; @@ -736,10 +729,10 @@ static void zebra_rnh_clear_nhc_flag(struct zebra_vrf *zvrf, int family, /* Identify route entry (RIB) resolving this tracked entry. */ if (type == RNH_IMPORT_CHECK_TYPE) - re = zebra_rnh_resolve_import_entry(zvrf, family, nrn, rnh, + re = zebra_rnh_resolve_import_entry(zvrf, afi, nrn, rnh, &prn); else - re = zebra_rnh_resolve_nexthop_entry(zvrf, family, nrn, rnh, + re = zebra_rnh_resolve_nexthop_entry(zvrf, afi, nrn, rnh, &prn); if (re) { @@ -751,13 +744,13 @@ static void zebra_rnh_clear_nhc_flag(struct zebra_vrf *zvrf, int family, /* Evaluate all tracked entries (nexthops or routes for import into BGP) * of a particular VRF and address-family or a specific prefix. */ -void zebra_evaluate_rnh(struct zebra_vrf *zvrf, int family, int force, +void zebra_evaluate_rnh(struct zebra_vrf *zvrf, afi_t afi, int force, rnh_type_t type, struct prefix *p) { struct route_table *rnh_table; struct route_node *nrn; - rnh_table = get_rnh_table(zvrf->vrf->vrf_id, family, type); + rnh_table = get_rnh_table(zvrf->vrf->vrf_id, afi, type); if (!rnh_table) // unexpected return; @@ -765,8 +758,7 @@ void zebra_evaluate_rnh(struct zebra_vrf *zvrf, int family, int force, /* Evaluating a specific entry, make sure it exists. */ nrn = route_node_lookup(rnh_table, p); if (nrn && nrn->info) - zebra_rnh_evaluate_entry(zvrf, family, force, type, - nrn); + zebra_rnh_evaluate_entry(zvrf, afi, force, type, nrn); if (nrn) route_unlock_node(nrn); @@ -775,27 +767,26 @@ void zebra_evaluate_rnh(struct zebra_vrf *zvrf, int family, int force, nrn = route_top(rnh_table); while (nrn) { if (nrn->info) - zebra_rnh_evaluate_entry(zvrf, family, force, - type, nrn); + zebra_rnh_evaluate_entry(zvrf, afi, force, type, + nrn); nrn = route_next(nrn); /* this will also unlock nrn */ } nrn = route_top(rnh_table); while (nrn) { if (nrn->info) - zebra_rnh_clear_nhc_flag(zvrf, family, type, - nrn); + zebra_rnh_clear_nhc_flag(zvrf, afi, type, nrn); nrn = route_next(nrn); /* this will also unlock nrn */ } } } -void zebra_print_rnh_table(vrf_id_t vrfid, int af, struct vty *vty, +void zebra_print_rnh_table(vrf_id_t vrfid, afi_t afi, struct vty *vty, rnh_type_t type) { struct route_table *table; struct route_node *rn; - table = get_rnh_table(vrfid, af, type); + table = get_rnh_table(vrfid, afi, type); if (!table) { zlog_debug("print_rnhs: rnh table not found\n"); return; @@ -1032,7 +1023,7 @@ static void print_rnh(struct route_node *rn, struct vty *vty) vty_out(vty, "\n"); } -static int zebra_cleanup_rnh_client(vrf_id_t vrf_id, int family, +static int zebra_cleanup_rnh_client(vrf_id_t vrf_id, afi_t afi, struct zserv *client, rnh_type_t type) { struct route_table *ntable; @@ -1040,11 +1031,11 @@ static int zebra_cleanup_rnh_client(vrf_id_t vrf_id, int family, struct rnh *rnh; if (IS_ZEBRA_DEBUG_NHT) - zlog_debug("%u: Client %s RNH cleanup for family %d type %d", - vrf_id, zebra_route_string(client->proto), family, - type); + zlog_debug("%u: Client %s RNH cleanup for family %s type %d", + vrf_id, zebra_route_string(client->proto), + afi2str(afi), type); - ntable = get_rnh_table(vrf_id, family, type); + ntable = get_rnh_table(vrf_id, afi, type); if (!ntable) { zlog_debug("cleanup_rnh_client: rnh table not found\n"); return -1; @@ -1069,14 +1060,14 @@ static int zebra_client_cleanup_rnh(struct zserv *client) RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) { zvrf = vrf->info; if (zvrf) { - zebra_cleanup_rnh_client(zvrf_id(zvrf), AF_INET, client, + zebra_cleanup_rnh_client(zvrf_id(zvrf), AFI_IP, client, RNH_NEXTHOP_TYPE); - zebra_cleanup_rnh_client(zvrf_id(zvrf), AF_INET6, - client, RNH_NEXTHOP_TYPE); - zebra_cleanup_rnh_client(zvrf_id(zvrf), AF_INET, client, + zebra_cleanup_rnh_client(zvrf_id(zvrf), AFI_IP6, client, + RNH_NEXTHOP_TYPE); + zebra_cleanup_rnh_client(zvrf_id(zvrf), AFI_IP, client, + RNH_IMPORT_CHECK_TYPE); + zebra_cleanup_rnh_client(zvrf_id(zvrf), AFI_IP6, client, RNH_IMPORT_CHECK_TYPE); - zebra_cleanup_rnh_client(zvrf_id(zvrf), AF_INET6, - client, RNH_IMPORT_CHECK_TYPE); if (client->proto == ZEBRA_ROUTE_LDP) { hash_iterate(zvrf->lsp_table, mpls_ldp_lsp_uninstall_all, |