--- embedaddon/quagga/zebra/zebra_routemap.c 2012/02/21 17:26:11 1.1 +++ embedaddon/quagga/zebra/zebra_routemap.c 2016/11/02 10:09:10 1.1.1.2 @@ -28,6 +28,7 @@ #include "command.h" #include "filter.h" #include "plist.h" +#include "vrf.h" #include "zebra/zserv.h" @@ -123,25 +124,29 @@ zebra_route_set_delete (struct vty *vty, struct route_ return CMD_SUCCESS; } - + /* `match interface IFNAME' */ /* Match function return 1 if match is success else return zero. */ static route_map_result_t route_match_interface (void *rule, struct prefix *prefix, route_map_object_t type, void *object) { + struct nexthop_vrfid *nh_vrf; struct nexthop *nexthop; char *ifname = rule; - unsigned int ifindex; + ifindex_t ifindex; if (type == RMAP_ZEBRA) { if (strcasecmp(ifname, "any") == 0) return RMAP_MATCH; - ifindex = ifname2ifindex(ifname); + nh_vrf = object; + if (!nh_vrf) + return RMAP_NOMATCH; + ifindex = ifname2ifindex_vrf (ifname, nh_vrf->vrf_id); if (ifindex == 0) return RMAP_NOMATCH; - nexthop = object; + nexthop = nh_vrf->nexthop; if (!nexthop) return RMAP_NOMATCH; if (nexthop->ifindex == ifindex) @@ -365,7 +370,8 @@ DEFUN (set_src, "src address\n") { struct in_addr src; - struct interface *pif; + struct interface *pif = NULL; + vrf_iter_t iter; if (inet_pton(AF_INET, argv[0], &src) <= 0) { @@ -373,12 +379,16 @@ DEFUN (set_src, return CMD_WARNING; } - pif = if_lookup_exact_address (src); - if (!pif) - { - vty_out (vty, "%% not a local address%s", VTY_NEWLINE); - return CMD_WARNING; - } + for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) + if ((pif = if_lookup_exact_address_vrf (src, vrf_iter2id (iter))) != NULL) + break; + + if (!pif) + { + vty_out (vty, "%% not a local address%s", VTY_NEWLINE); + return CMD_WARNING; + } + return zebra_route_set_add (vty, vty->index, "src", argv[0]); } @@ -422,14 +432,10 @@ route_match_ip_next_hop (void *rule, struct prefix *pr switch (nexthop->type) { case NEXTHOP_TYPE_IFINDEX: case NEXTHOP_TYPE_IFNAME: + /* Interface routes can't match ip next-hop */ + return RMAP_NOMATCH; case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4_IFNAME: - if (nexthop->rtype != NEXTHOP_TYPE_IPV4) - return RMAP_NOMATCH; - p.family = AF_INET; - p.prefix = nexthop->rgate.ipv4; - p.prefixlen = IPV4_MAX_BITLEN; - break; case NEXTHOP_TYPE_IPV4: p.family = AF_INET; p.prefix = nexthop->gate.ipv4; @@ -471,7 +477,7 @@ static struct route_map_rule_cmd route_match_ip_next_h route_match_ip_next_hop_compile, route_match_ip_next_hop_free }; - + /* `match ip next-hop prefix-list PREFIX_LIST' */ static route_map_result_t @@ -488,14 +494,10 @@ route_match_ip_next_hop_prefix_list (void *rule, struc switch (nexthop->type) { case NEXTHOP_TYPE_IFINDEX: case NEXTHOP_TYPE_IFNAME: + /* Interface routes can't match ip next-hop */ + return RMAP_NOMATCH; case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4_IFNAME: - if (nexthop->rtype != NEXTHOP_TYPE_IPV4) - return RMAP_NOMATCH; - p.family = AF_INET; - p.prefix = nexthop->rgate.ipv4; - p.prefixlen = IPV4_MAX_BITLEN; - break; case NEXTHOP_TYPE_IPV4: p.family = AF_INET; p.prefix = nexthop->gate.ipv4; @@ -533,7 +535,7 @@ static struct route_map_rule_cmd route_match_ip_next_h route_match_ip_next_hop_prefix_list_compile, route_match_ip_next_hop_prefix_list_free }; - + /* `match ip address IP_ACCESS_LIST' */ /* Match function should return 1 if match is success else return @@ -579,7 +581,7 @@ static struct route_map_rule_cmd route_match_ip_addres route_match_ip_address_compile, route_match_ip_address_free }; - + /* `match ip address prefix-list PREFIX_LIST' */ static route_map_result_t @@ -620,7 +622,7 @@ static struct route_map_rule_cmd route_match_ip_addres route_match_ip_address_prefix_list_free }; - + /* `set src A.B.C.D' */ /* Set src. */