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;
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;
}
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,
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;
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);
}
}
/* 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 */
* 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)
{
*prn = NULL;
- route_table = zvrf->table[family2afi(family)][SAFI_UNICAST];
+ route_table = zvrf->table[afi][SAFI_UNICAST];
if (!route_table) // unexpected
return NULL;
* 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)
/*
* 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;
* 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
}
}
-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)
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
* 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)
{
*prn = NULL;
- route_table = zvrf->table[family2afi(family)][SAFI_UNICAST];
+ route_table = zvrf->table[afi][SAFI_UNICAST];
if (!route_table)
return NULL;
* 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,
* 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);
}
/* 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)
{
/* 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.
/* 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);
}
* 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;
/* 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) {
/* 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;
/* 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);
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;
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;
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;
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,
if (argc == 5)
VRF_GET_ID(vrf_id, argv[idx_vrf]->arg, false);
- zebra_print_rnh_table(vrf_id, AF_INET, vty, RNH_NEXTHOP_TYPE);
+ zebra_print_rnh_table(vrf_id, AFI_IP, vty, RNH_NEXTHOP_TYPE);
return CMD_SUCCESS;
}
VRF_CMD_HELP_STR
VRF_ALL_CMD_HELP_STR)
{
- int family = ipv4 ? AF_INET : AF_INET6;
+ afi_t afi = ipv4 ? AFI_IP : AFI_IP6;
vrf_id_t vrf_id = VRF_DEFAULT;
if (vrf_all) {
if ((zvrf = vrf->info) != NULL) {
vty_out(vty, "\nVRF %s:\n",
zvrf_name(zvrf));
- zebra_print_rnh_table(zvrf_id(zvrf),
- family, vty,
+ zebra_print_rnh_table(zvrf_id(zvrf), afi, vty,
RNH_IMPORT_CHECK_TYPE);
}
return CMD_SUCCESS;
if (vrf_name)
VRF_GET_ID(vrf_id, vrf_name, false);
- zebra_print_rnh_table(vrf_id, family, vty, RNH_IMPORT_CHECK_TYPE);
+ zebra_print_rnh_table(vrf_id, afi, vty, RNH_IMPORT_CHECK_TYPE);
return CMD_SUCCESS;
}
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
if ((zvrf = vrf->info) != NULL) {
vty_out(vty, "\nVRF %s:\n", zvrf_name(zvrf));
- zebra_print_rnh_table(zvrf_id(zvrf), AF_INET, vty,
+ zebra_print_rnh_table(zvrf_id(zvrf), AFI_IP, vty,
RNH_NEXTHOP_TYPE);
}
if (argc == 5)
VRF_GET_ID(vrf_id, argv[idx_vrf]->arg, false);
- zebra_print_rnh_table(vrf_id, AF_INET6, vty, RNH_NEXTHOP_TYPE);
+ zebra_print_rnh_table(vrf_id, AFI_IP6, vty, RNH_NEXTHOP_TYPE);
return CMD_SUCCESS;
}
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
if ((zvrf = vrf->info) != NULL) {
vty_out(vty, "\nVRF %s:\n", zvrf_name(zvrf));
- zebra_print_rnh_table(zvrf_id(zvrf), AF_INET6, vty,
+ zebra_print_rnh_table(zvrf_id(zvrf), AFI_IP6, vty,
RNH_NEXTHOP_TYPE);
}
zebra_rnh_ip_default_route = 1;
- zebra_evaluate_rnh(zvrf, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL);
+ zebra_evaluate_rnh(zvrf, AFI_IP, 1, RNH_NEXTHOP_TYPE, NULL);
return CMD_SUCCESS;
}
return CMD_SUCCESS;
zebra_rnh_ip_default_route = 0;
- zebra_evaluate_rnh(zvrf, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL);
+ zebra_evaluate_rnh(zvrf, AFI_IP, 1, RNH_NEXTHOP_TYPE, NULL);
return CMD_SUCCESS;
}
return CMD_SUCCESS;
zebra_rnh_ipv6_default_route = 1;
- zebra_evaluate_rnh(zvrf, AF_INET6, 1, RNH_NEXTHOP_TYPE, NULL);
+ zebra_evaluate_rnh(zvrf, AFI_IP6, 1, RNH_NEXTHOP_TYPE, NULL);
return CMD_SUCCESS;
}
return CMD_SUCCESS;
zebra_rnh_ipv6_default_route = 0;
- zebra_evaluate_rnh(zvrf, AF_INET6, 1, RNH_NEXTHOP_TYPE, NULL);
+ zebra_evaluate_rnh(zvrf, AFI_IP6, 1, RNH_NEXTHOP_TYPE, NULL);
return CMD_SUCCESS;
}