From 0032dd59cda8215e7ccf4297cd78ee6100de7499 Mon Sep 17 00:00:00 2001 From: Feng Lu Date: Fri, 22 May 2015 11:40:04 +0200 Subject: [PATCH] zebra: let the route-map rule "match interface" work for VRFs Introduce a new "struct nexthop_vrfid" to specify a nexthop together with the VRF ID it belongs to. Thus in route_match_interface(), we can lookup the interface from the correct VRF. Signed-off-by: Feng Lu Reviewed-by: Alain Ritoux Signed-off-by: Nicolas Dichtel Acked-by: Vincent JARDIN Signed-off-by: David Lamparter Conflicts: zebra/zebra_rib.c zebra/zebra_routemap.c --- zebra/zebra_rib.c | 3 ++- zebra/zebra_routemap.c | 22 +++++++++++++--------- zebra/zserv.h | 1 + 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 79aa989814..0f25c76858 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -1213,7 +1213,8 @@ nexthop_active_check (struct route_node *rn, struct rib *rib, memset(&nexthop->rmap_src.ipv6, 0, sizeof(union g_addr)); /* It'll get set if required inside */ - ret = zebra_route_map_check(family, rib->type, &rn->p, nexthop, rib->tag); + ret = zebra_route_map_check(family, rib->type, &rn->p, nexthop, rib->vrf_id, + rib->tag); if (ret == RMAP_DENYMATCH) { if (IS_ZEBRA_DEBUG_RIB) diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 1c7b63e757..a8e87dd09c 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -29,6 +29,7 @@ #include "filter.h" #include "plist.h" #include "nexthop.h" +#include "vrf.h" #include "zebra/zserv.h" #include "zebra/debug.h" @@ -45,6 +46,7 @@ extern struct zebra_t zebrad; struct nh_rmap_obj { struct nexthop *nexthop; + vrf_id_t vrf_id; u_int32_t source_protocol; int metric; u_short tag; @@ -255,12 +257,12 @@ route_match_interface (void *rule, struct prefix *prefix, { if (strcasecmp(ifname, "any") == 0) return RMAP_MATCH; - ifindex = ifname2ifindex(ifname); - if (ifindex == 0) - return RMAP_NOMATCH; nh_data = object; if (!nh_data || !nh_data->nexthop) return RMAP_NOMATCH; + ifindex = ifname2ifindex_vrf (ifname, nh_data->vrf_id); + if (ifindex == 0) + return RMAP_NOMATCH; if (nh_data->nexthop->ifindex == ifindex) return RMAP_MATCH; } @@ -767,7 +769,7 @@ DEFUN (ip_protocol, if (IS_ZEBRA_DEBUG_RIB) zlog_debug ("%s: calling rib_update", __func__); - rib_update(); + rib_update(VRF_DEFAULT); return CMD_SUCCESS; } @@ -804,7 +806,7 @@ DEFUN (no_ip_protocol, if (IS_ZEBRA_DEBUG_RIB) zlog_debug ("%s: calling rib_update", __func__); - rib_update(); + rib_update(VRF_DEFAULT); } return CMD_SUCCESS; } @@ -879,7 +881,7 @@ DEFUN (ipv6_protocol, if (IS_ZEBRA_DEBUG_RIB) zlog_debug ("%s: calling rib_update", __func__); - rib_update(); + rib_update(VRF_DEFAULT); return CMD_SUCCESS; } @@ -916,7 +918,7 @@ DEFUN (no_ipv6_protocol, if (IS_ZEBRA_DEBUG_RIB) zlog_debug ("%s: calling rib_update", __func__); - rib_update(); + rib_update(VRF_DEFAULT); } return CMD_SUCCESS; } @@ -1590,7 +1592,7 @@ zebra_route_map_update_timer (struct thread *thread) if (IS_ZEBRA_DEBUG_RIB) zlog_debug ("%s: calling rib_update", __func__); - rib_update(); + rib_update(VRF_DEFAULT); zebra_evaluate_rnh(0, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL); zebra_evaluate_rnh(0, AF_INET6, 1, RNH_NEXTHOP_TYPE, NULL); @@ -1621,13 +1623,14 @@ zebra_route_map_write_delay_timer (struct vty *vty) route_map_result_t zebra_route_map_check (int family, int rib_type, struct prefix *p, - struct nexthop *nexthop, u_short tag) + struct nexthop *nexthop, vrf_id_t vrf_id, u_short tag) { struct route_map *rmap = NULL; route_map_result_t ret = RMAP_MATCH; struct nh_rmap_obj nh_obj; nh_obj.nexthop = nexthop; + nh_obj.vrf_id = vrf_id; nh_obj.source_protocol = rib_type; nh_obj.metric = 0; nh_obj.tag = tag; @@ -1652,6 +1655,7 @@ zebra_nht_route_map_check (int family, int client_proto, struct prefix *p, struct nh_rmap_obj nh_obj; nh_obj.nexthop = nexthop; + nh_obj.vrf_id = rib->vrf_id; nh_obj.source_protocol = rib->type; nh_obj.metric = rib->metric; nh_obj.tag = rib->tag; diff --git a/zebra/zserv.h b/zebra/zserv.h index 41a4b9ea9f..ace3715247 100644 --- a/zebra/zserv.h +++ b/zebra/zserv.h @@ -162,6 +162,7 @@ extern void zebra_route_map_write_delay_timer(struct vty *); extern route_map_result_t zebra_route_map_check (int family, int rib_type, struct prefix *p, struct nexthop *nexthop, + vrf_id_t vrf_id, u_short tag); extern route_map_result_t zebra_nht_route_map_check (int family, int client_proto, -- 2.39.5