diff options
author | vishaldhingra <vdhingra@vmware.com> | 2018-10-11 19:46:55 +0200 |
---|---|---|
committer | vishaldhingra <vdhingra@vmware.com> | 2018-10-11 19:46:55 +0200 |
commit | 6d53d7b1af1f45da8ab8c10add5efee81008ff25 (patch) | |
tree | b37ff14de6a1da4e252bbb93f4f2b74b8fcc4115 /zebra | |
parent | zebra: vrf aware routmap is missing in Zebra #2802(Part 1 of 4) (diff) | |
download | frr-6d53d7b1af1f45da8ab8c10add5efee81008ff25.tar.xz frr-6d53d7b1af1f45da8ab8c10add5efee81008ff25.zip |
zebra: vrf aware routmap is missing in Zebra #2802(Part 2 of 4)
Function parameter replacement of using zvrf instead of vrf_id
Signed-off-by: vishaldhingra vdhingra@vmware.com
Diffstat (limited to 'zebra')
-rw-r--r-- | zebra/zapi_msg.c | 3 | ||||
-rw-r--r-- | zebra/zebra_rib.c | 10 | ||||
-rw-r--r-- | zebra/zebra_rnh.c | 94 | ||||
-rw-r--r-- | zebra/zebra_rnh.h | 2 | ||||
-rw-r--r-- | zebra/zebra_routemap.c | 34 | ||||
-rw-r--r-- | zebra/zebra_vty.c | 28 |
6 files changed, 104 insertions, 67 deletions
diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index b9897bea0..c193a0c47 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -1090,8 +1090,7 @@ static void zread_rnh_register(ZAPI_HANDLER_ARGS) zebra_add_rnh_client(rnh, client, type, zvrf_id(zvrf)); /* Anything not AF_INET/INET6 has been filtered out above */ if (!exist) - zebra_evaluate_rnh(zvrf_id(zvrf), p.family, 1, type, - &p); + zebra_evaluate_rnh(zvrf, p.family, 1, type, &p); } stream_failure: diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 53afbdc8f..4c35b1003 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -1901,14 +1901,12 @@ static void meta_queue_process_complete(struct work_queue *dummy) continue; zvrf->flags &= ~ZEBRA_VRF_RIB_SCHEDULED; - zebra_evaluate_rnh(zvrf_id(zvrf), AF_INET, 0, RNH_NEXTHOP_TYPE, + zebra_evaluate_rnh(zvrf, AF_INET, 0, RNH_NEXTHOP_TYPE, NULL); + zebra_evaluate_rnh(zvrf, AF_INET, 0, RNH_IMPORT_CHECK_TYPE, NULL); - zebra_evaluate_rnh(zvrf_id(zvrf), AF_INET, 0, - RNH_IMPORT_CHECK_TYPE, NULL); - zebra_evaluate_rnh(zvrf_id(zvrf), AF_INET6, 0, RNH_NEXTHOP_TYPE, + zebra_evaluate_rnh(zvrf, AF_INET6, 0, RNH_NEXTHOP_TYPE, NULL); + zebra_evaluate_rnh(zvrf, AF_INET6, 0, RNH_IMPORT_CHECK_TYPE, NULL); - zebra_evaluate_rnh(zvrf_id(zvrf), AF_INET6, 0, - RNH_IMPORT_CHECK_TYPE, NULL); } /* Schedule LSPs for processing, if needed. */ diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index e2b286731..0a531990d 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -260,13 +260,18 @@ void zebra_register_rnh_pseudowire(vrf_id_t vrf_id, struct zebra_pw *pw) struct prefix nh; struct rnh *rnh; bool exists; + struct zebra_vrf *zvrf; + + zvrf = vrf_info_lookup(vrf_id); + if (!zvrf) + return; addr2hostprefix(pw->af, &pw->nexthop, &nh); rnh = zebra_add_rnh(&nh, vrf_id, RNH_NEXTHOP_TYPE, &exists); if (rnh && !listnode_lookup(rnh->zebra_pseudowire_list, pw)) { listnode_add(rnh->zebra_pseudowire_list, pw); pw->rnh = rnh; - zebra_evaluate_rnh(vrf_id, pw->af, 1, RNH_NEXTHOP_TYPE, &nh); + zebra_evaluate_rnh(zvrf, pw->af, 1, RNH_NEXTHOP_TYPE, &nh); } } @@ -289,7 +294,8 @@ 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 route_node *prn, +static int zebra_rnh_apply_nht_rmap(int family, struct zebra_vrf *zvrf, + struct route_node *prn, struct route_entry *re, int proto) { int at_least_one = 0; @@ -302,8 +308,6 @@ static int zebra_rnh_apply_nht_rmap(int family, struct route_node *prn, if (prn && re) { for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next) { - struct zebra_vrf *zvrf = - zebra_vrf_lookup_by_id(nexthop->vrf_id); ret = zebra_nht_route_map_check( rmap_family, proto, &prn->p, zvrf, re, nexthop); if (ret != RMAP_DENYMATCH) { @@ -322,7 +326,7 @@ static int zebra_rnh_apply_nht_rmap(int family, struct route_node *prn, * for BGP route for import. */ static struct route_entry * -zebra_rnh_resolve_import_entry(vrf_id_t vrfid, int family, +zebra_rnh_resolve_import_entry(struct zebra_vrf *zvrf, int family, struct route_node *nrn, struct rnh *rnh, struct route_node **prn) { @@ -332,7 +336,7 @@ zebra_rnh_resolve_import_entry(vrf_id_t vrfid, int family, *prn = NULL; - route_table = zebra_vrf_table(family2afi(family), SAFI_UNICAST, vrfid); + route_table = zvrf->table[family2afi(family)][SAFI_UNICAST]; if (!route_table) // unexpected return NULL; @@ -404,11 +408,9 @@ 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(vrf_id_t vrfid, 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, int family, struct route_node *nrn, + struct rnh *rnh, struct route_node *prn, struct route_entry *re) { struct listnode *node; struct zserv *client; @@ -420,11 +422,11 @@ static void zebra_rnh_notify_protocol_clients(vrf_id_t vrfid, int family, prefix2str(&nrn->p, bufn, INET6_ADDRSTRLEN); if (prn && re) { prefix2str(&prn->p, bufp, INET6_ADDRSTRLEN); - zlog_debug("%u:%s: NH resolved over route %s", vrfid, - bufn, bufp); + zlog_debug("%u:%s: NH resolved over route %s", + zvrf->vrf->vrf_id, bufn, bufp); } else - zlog_debug("%u:%s: NH has become unresolved", vrfid, - bufn); + zlog_debug("%u:%s: NH has become unresolved", + zvrf->vrf->vrf_id, bufn); } for (ALL_LIST_ELEMENTS_RO(rnh->client_list, node, client)) { @@ -434,7 +436,7 @@ static void zebra_rnh_notify_protocol_clients(vrf_id_t vrfid, int family, * nexthop to see if it is filtered or not. */ num_resolving_nh = zebra_rnh_apply_nht_rmap( - family, prn, re, client->proto); + family, zvrf, prn, re, client->proto); if (num_resolving_nh) rnh->filtered[client->proto] = 0; else @@ -443,7 +445,7 @@ static void zebra_rnh_notify_protocol_clients(vrf_id_t vrfid, int family, if (IS_ZEBRA_DEBUG_NHT) zlog_debug( "%u:%s: Notifying client %s about NH %s", - vrfid, bufn, + zvrf->vrf->vrf_id, bufn, zebra_route_string(client->proto), num_resolving_nh ? "" @@ -453,11 +455,11 @@ static void zebra_rnh_notify_protocol_clients(vrf_id_t vrfid, int family, if (IS_ZEBRA_DEBUG_NHT) zlog_debug( "%u:%s: Notifying client %s about NH (unreachable)", - vrfid, bufn, + zvrf->vrf->vrf_id, bufn, zebra_route_string(client->proto)); } - send_client(rnh, client, RNH_NEXTHOP_TYPE, vrfid); + send_client(rnh, client, RNH_NEXTHOP_TYPE, zvrf->vrf->vrf_id); } } @@ -521,7 +523,7 @@ static void zebra_rnh_process_pbr_tables(int family, * nexthop. */ static struct route_entry * -zebra_rnh_resolve_nexthop_entry(vrf_id_t vrfid, int family, +zebra_rnh_resolve_nexthop_entry(struct zebra_vrf *zvrf, int family, struct route_node *nrn, struct rnh *rnh, struct route_node **prn) { @@ -531,7 +533,7 @@ zebra_rnh_resolve_nexthop_entry(vrf_id_t vrfid, int family, *prn = NULL; - route_table = zebra_vrf_table(family2afi(family), SAFI_UNICAST, vrfid); + route_table = zvrf->table[family2afi(family)][SAFI_UNICAST]; if (!route_table) return NULL; @@ -608,8 +610,8 @@ 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(vrf_id_t vrfid, int family, int force, - struct route_node *nrn, +static void zebra_rnh_eval_nexthop_entry(struct zebra_vrf *zvrf, int family, + int force, struct route_node *nrn, struct rnh *rnh, struct route_node *prn, struct route_entry *re) @@ -638,20 +640,20 @@ static void zebra_rnh_eval_nexthop_entry(vrf_id_t vrfid, int family, int force, * rnh->state. */ /* Notify registered protocol clients. */ - zebra_rnh_notify_protocol_clients(vrfid, family, nrn, rnh, prn, + zebra_rnh_notify_protocol_clients(zvrf, family, nrn, rnh, prn, rnh->state); - zebra_rnh_process_pbr_tables(family, nrn, rnh, prn, - rnh->state); + zebra_rnh_process_pbr_tables(family, nrn, rnh, prn, rnh->state); /* Process pseudowires attached to this nexthop */ - zebra_rnh_process_pseudowires(vrfid, rnh); + zebra_rnh_process_pseudowires(zvrf->vrf->vrf_id, rnh); } } /* Evaluate one tracked entry */ -static void zebra_rnh_evaluate_entry(vrf_id_t vrfid, int family, int force, - rnh_type_t type, struct route_node *nrn) +static void zebra_rnh_evaluate_entry(struct zebra_vrf *zvrf, int family, + int force, rnh_type_t type, + struct route_node *nrn) { struct rnh *rnh; struct route_entry *re; @@ -660,18 +662,18 @@ static void zebra_rnh_evaluate_entry(vrf_id_t vrfid, int family, int force, if (IS_ZEBRA_DEBUG_NHT) { prefix2str(&nrn->p, bufn, INET6_ADDRSTRLEN); - zlog_debug("%u:%s: Evaluate RNH, type %d %s", vrfid, bufn, type, - force ? "(force)" : ""); + zlog_debug("%u:%s: Evaluate RNH, type %d %s", zvrf->vrf->vrf_id, + bufn, type, force ? "(force)" : ""); } rnh = nrn->info; /* Identify route entry (RE) resolving this tracked entry. */ if (type == RNH_IMPORT_CHECK_TYPE) - re = zebra_rnh_resolve_import_entry(vrfid, family, nrn, rnh, + re = zebra_rnh_resolve_import_entry(zvrf, family, nrn, rnh, &prn); else - re = zebra_rnh_resolve_nexthop_entry(vrfid, family, nrn, rnh, + re = zebra_rnh_resolve_nexthop_entry(zvrf, family, nrn, rnh, &prn); /* If the entry cannot be resolved and that is also the existing state, @@ -682,11 +684,11 @@ static void zebra_rnh_evaluate_entry(vrf_id_t vrfid, int family, int force, /* Process based on type of entry. */ if (type == RNH_IMPORT_CHECK_TYPE) - zebra_rnh_eval_import_check_entry(vrfid, family, force, nrn, - rnh, re); + zebra_rnh_eval_import_check_entry(zvrf->vrf->vrf_id, family, + force, nrn, rnh, re); else - zebra_rnh_eval_nexthop_entry(vrfid, family, force, nrn, rnh, - prn, re); + zebra_rnh_eval_nexthop_entry(zvrf, family, force, nrn, rnh, prn, + re); } /* @@ -698,7 +700,7 @@ static void zebra_rnh_evaluate_entry(vrf_id_t vrfid, int family, int force, * we can have a situation where one re entry * covers multiple nexthops we are interested in. */ -static void zebra_rnh_clear_nhc_flag(vrf_id_t vrfid, int family, +static void zebra_rnh_clear_nhc_flag(struct zebra_vrf *zvrf, int family, rnh_type_t type, struct route_node *nrn) { struct rnh *rnh; @@ -709,10 +711,10 @@ static void zebra_rnh_clear_nhc_flag(vrf_id_t vrfid, int family, /* Identify route entry (RIB) resolving this tracked entry. */ if (type == RNH_IMPORT_CHECK_TYPE) - re = zebra_rnh_resolve_import_entry(vrfid, family, nrn, rnh, + re = zebra_rnh_resolve_import_entry(zvrf, family, nrn, rnh, &prn); else - re = zebra_rnh_resolve_nexthop_entry(vrfid, family, nrn, rnh, + re = zebra_rnh_resolve_nexthop_entry(zvrf, family, nrn, rnh, &prn); if (re) { @@ -724,13 +726,13 @@ static void zebra_rnh_clear_nhc_flag(vrf_id_t vrfid, 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(vrf_id_t vrfid, int family, int force, rnh_type_t type, - struct prefix *p) +void zebra_evaluate_rnh(struct zebra_vrf *zvrf, int family, int force, + rnh_type_t type, struct prefix *p) { struct route_table *rnh_table; struct route_node *nrn; - rnh_table = get_rnh_table(vrfid, family, type); + rnh_table = get_rnh_table(zvrf->vrf->vrf_id, family, type); if (!rnh_table) // unexpected return; @@ -738,7 +740,7 @@ void zebra_evaluate_rnh(vrf_id_t vrfid, int family, int force, rnh_type_t type, /* Evaluating a specific entry, make sure it exists. */ nrn = route_node_lookup(rnh_table, p); if (nrn && nrn->info) - zebra_rnh_evaluate_entry(vrfid, family, force, type, + zebra_rnh_evaluate_entry(zvrf, family, force, type, nrn); if (nrn) @@ -748,14 +750,14 @@ void zebra_evaluate_rnh(vrf_id_t vrfid, int family, int force, rnh_type_t type, nrn = route_top(rnh_table); while (nrn) { if (nrn->info) - zebra_rnh_evaluate_entry(vrfid, family, force, + zebra_rnh_evaluate_entry(zvrf, family, 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(vrfid, family, type, + zebra_rnh_clear_nhc_flag(zvrf, family, type, nrn); nrn = route_next(nrn); /* this will also unlock nrn */ } diff --git a/zebra/zebra_rnh.h b/zebra/zebra_rnh.h index f4b4b5639..33302f0ee 100644 --- a/zebra/zebra_rnh.h +++ b/zebra/zebra_rnh.h @@ -79,7 +79,7 @@ extern void zebra_register_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, rnh_type_t type); -extern void zebra_evaluate_rnh(vrf_id_t vrfid, int family, int force, +extern void zebra_evaluate_rnh(struct zebra_vrf *zvrf, int family, int force, rnh_type_t type, struct prefix *p); extern void zebra_print_rnh_table(vrf_id_t vrfid, int family, struct vty *vty, rnh_type_t); diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 1318c09b5..598d51fd2 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -713,8 +713,13 @@ DEFUN (ip_protocol_nht_rmap, XFREE(MTYPE_ROUTE_MAP_NAME, nht_rm[AFI_IP][i]); } + struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); + + if (!zvrf) + return CMD_WARNING; + nht_rm[AFI_IP][i] = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap); - zebra_evaluate_rnh(0, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL); + zebra_evaluate_rnh(zvrf, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL); return CMD_SUCCESS; } @@ -745,10 +750,15 @@ DEFUN (no_ip_protocol_nht_rmap, if (!nht_rm[AFI_IP][i]) return CMD_SUCCESS; + struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); + + if (!zvrf) + return CMD_WARNING; + if (!rmap || strcmp(rmap, nht_rm[AFI_IP][i]) == 0) { XFREE(MTYPE_ROUTE_MAP_NAME, nht_rm[AFI_IP][i]); nht_rm[AFI_IP][i] = NULL; - zebra_evaluate_rnh(0, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL); + zebra_evaluate_rnh(zvrf, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL); } return CMD_SUCCESS; } @@ -801,10 +811,16 @@ DEFUN (ipv6_protocol_nht_rmap, vty_out(vty, "invalid protocol name \"%s\"\n", proto); return CMD_WARNING_CONFIG_FAILED; } + + struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); + + if (!zvrf) + return CMD_WARNING; + if (nht_rm[AFI_IP6][i]) XFREE(MTYPE_ROUTE_MAP_NAME, nht_rm[AFI_IP6][i]); nht_rm[AFI_IP6][i] = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap); - zebra_evaluate_rnh(0, AF_INET6, 1, RNH_NEXTHOP_TYPE, NULL); + zebra_evaluate_rnh(zvrf, AF_INET6, 1, RNH_NEXTHOP_TYPE, NULL); return CMD_SUCCESS; } @@ -841,8 +857,12 @@ DEFUN (no_ipv6_protocol_nht_rmap, XFREE(MTYPE_ROUTE_MAP_NAME, nht_rm[AFI_IP6][i]); nht_rm[AFI_IP6][i] = NULL; } + struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); + + if (!zvrf) + return CMD_WARNING; - zebra_evaluate_rnh(0, AF_INET6, 1, RNH_NEXTHOP_TYPE, NULL); + zebra_evaluate_rnh(zvrf, AF_INET6, 1, RNH_NEXTHOP_TYPE, NULL); return CMD_SUCCESS; } @@ -1411,8 +1431,7 @@ static void zebra_nht_rm_update(const char *rmap) afi_ip = 1; zebra_evaluate_rnh( - zvrf->vrf->vrf_id, - AF_INET, 1, + zvrf, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL); } } @@ -1438,8 +1457,7 @@ static void zebra_nht_rm_update(const char *rmap) afi_ipv6 = 1; zebra_evaluate_rnh( - zvrf->vrf->vrf_id, - AF_INET, 1, + zvrf, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL); } } diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 86792fdd8..d79d77c66 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -1030,8 +1030,13 @@ DEFUN (ip_nht_default_route, if (zebra_rnh_ip_default_route) return CMD_SUCCESS; + struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); + + if (!zvrf) + return CMD_WARNING; + zebra_rnh_ip_default_route = 1; - zebra_evaluate_rnh(VRF_DEFAULT, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL); + zebra_evaluate_rnh(zvrf, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL); return CMD_SUCCESS; } @@ -1046,8 +1051,13 @@ DEFUN (no_ip_nht_default_route, if (!zebra_rnh_ip_default_route) return CMD_SUCCESS; + struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); + + if (!zvrf) + return CMD_WARNING; + zebra_rnh_ip_default_route = 0; - zebra_evaluate_rnh(VRF_DEFAULT, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL); + zebra_evaluate_rnh(zvrf, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL); return CMD_SUCCESS; } @@ -1061,8 +1071,13 @@ DEFUN (ipv6_nht_default_route, if (zebra_rnh_ipv6_default_route) return CMD_SUCCESS; + struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); + + if (!zvrf) + return CMD_WARNING; + zebra_rnh_ipv6_default_route = 1; - zebra_evaluate_rnh(VRF_DEFAULT, AF_INET6, 1, RNH_NEXTHOP_TYPE, NULL); + zebra_evaluate_rnh(zvrf, AF_INET6, 1, RNH_NEXTHOP_TYPE, NULL); return CMD_SUCCESS; } @@ -1077,8 +1092,13 @@ DEFUN (no_ipv6_nht_default_route, if (!zebra_rnh_ipv6_default_route) return CMD_SUCCESS; + struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); + + if (!zvrf) + return CMD_WARNING; + zebra_rnh_ipv6_default_route = 0; - zebra_evaluate_rnh(VRF_DEFAULT, AF_INET6, 1, RNH_NEXTHOP_TYPE, NULL); + zebra_evaluate_rnh(zvrf, AF_INET6, 1, RNH_NEXTHOP_TYPE, NULL); return CMD_SUCCESS; } |