diff options
Diffstat (limited to 'zebra/zebra_routemap.c')
| -rw-r--r-- | zebra/zebra_routemap.c | 832 |
1 files changed, 86 insertions, 746 deletions
diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 142501b149..95da789108 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -14,7 +14,6 @@ #include "filter.h" #include "plist.h" #include "nexthop.h" -#include "northbound_cli.h" #include "lib/route_types.h" #include "vrf.h" #include "frrstr.h" @@ -24,6 +23,7 @@ #include "zebra/debug.h" #include "zebra/zebra_rnh.h" #include "zebra/zebra_routemap.h" +#include "zebra/zebra_vrf.h" #include "zebra/zebra_routemap_clippy.c" @@ -31,17 +31,11 @@ static uint32_t zebra_rmap_update_timer = ZEBRA_RMAP_DEFAULT_UPDATE_TIMER; static struct event *zebra_t_rmap_update = NULL; char *zebra_import_table_routemap[AFI_MAX][ZEBRA_KERNEL_TABLE_MAX]; -struct nh_rmap_obj { +struct zebra_rmap_obj { struct nexthop *nexthop; - vrf_id_t vrf_id; - uint32_t source_protocol; - uint8_t instance; - int metric; - route_tag_t tag; + struct route_entry *re; }; -static void zebra_route_map_set_delay_timer(uint32_t value); - /* 'match tag TAG' * Match function return 1 if match is success else return 0 */ @@ -49,12 +43,12 @@ static enum route_map_cmd_result_t route_match_tag(void *rule, const struct prefix *prefix, void *object) { route_tag_t *tag; - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; tag = rule; - nh_data = object; + rm_data = object; - if (nh_data->tag == *tag) + if (rm_data->re->tag == *tag) return RMAP_MATCH; return RMAP_NOMATCH; @@ -74,19 +68,19 @@ static const struct route_map_rule_cmd route_match_tag_cmd = { static enum route_map_cmd_result_t route_match_interface(void *rule, const struct prefix *prefix, void *object) { - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; char *ifname = rule; ifindex_t ifindex; if (strcasecmp(ifname, "any") == 0) return RMAP_MATCH; - nh_data = object; - if (!nh_data || !nh_data->nexthop) + rm_data = object; + if (!rm_data || !rm_data->nexthop) return RMAP_NOMATCH; - ifindex = ifname2ifindex(ifname, nh_data->vrf_id); + ifindex = ifname2ifindex(ifname, rm_data->nexthop->vrf_id); if (ifindex == 0) return RMAP_NOMATCH; - if (nh_data->nexthop->ifindex == ifindex) + if (rm_data->nexthop->ifindex == ifindex) return RMAP_MATCH; return RMAP_NOMATCH; @@ -288,8 +282,8 @@ static const struct route_map_rule_cmd route_match_interface_cmd = { route_match_interface_free }; -static int ip_protocol_rm_add(struct zebra_vrf *zvrf, const char *rmap, - int rtype, afi_t afi, safi_t safi) +int ip_protocol_rm_add(struct zebra_vrf *zvrf, const char *rmap, int rtype, + afi_t afi, safi_t safi) { struct route_table *table; @@ -321,8 +315,8 @@ static int ip_protocol_rm_add(struct zebra_vrf *zvrf, const char *rmap, return CMD_SUCCESS; } -static int ip_protocol_rm_del(struct zebra_vrf *zvrf, const char *rmap, - int rtype, afi_t afi, safi_t safi) +int ip_protocol_rm_del(struct zebra_vrf *zvrf, const char *rmap, int rtype, + afi_t afi, safi_t safi) { struct route_table *table; @@ -350,8 +344,7 @@ static int ip_protocol_rm_del(struct zebra_vrf *zvrf, const char *rmap, return CMD_SUCCESS; } -static int ip_nht_rm_add(struct zebra_vrf *zvrf, const char *rmap, int rtype, - int afi) +int ip_nht_rm_add(struct zebra_vrf *zvrf, const char *rmap, int rtype, int afi) { if (NHT_RM_NAME(zvrf, afi, rtype)) { @@ -367,13 +360,12 @@ static int ip_nht_rm_add(struct zebra_vrf *zvrf, const char *rmap, int rtype, route_map_counter_increment(NHT_RM_MAP(zvrf, afi, rtype)); if (NHT_RM_MAP(zvrf, afi, rtype)) - zebra_evaluate_rnh(zvrf, AFI_IP, 1, NULL, SAFI_UNICAST); + zebra_evaluate_rnh(zvrf, afi, 1, NULL, SAFI_UNICAST); return CMD_SUCCESS; } -static int ip_nht_rm_del(struct zebra_vrf *zvrf, const char *rmap, int rtype, - int afi) +int ip_nht_rm_del(struct zebra_vrf *zvrf, const char *rmap, int rtype, int afi) { if (!NHT_RM_NAME(zvrf, afi, rtype)) @@ -388,358 +380,14 @@ static int ip_nht_rm_del(struct zebra_vrf *zvrf, const char *rmap, int rtype, zvrf->vrf->vrf_id, rtype); NHT_RM_MAP(zvrf, afi, rtype) = NULL; - zebra_evaluate_rnh(zvrf, AFI_IP, 1, NULL, SAFI_UNICAST); + zebra_evaluate_rnh(zvrf, afi, 1, NULL, SAFI_UNICAST); } XFREE(MTYPE_ROUTE_MAP_NAME, NHT_RM_NAME(zvrf, afi, rtype)); } return CMD_SUCCESS; } -DEFPY_YANG( - match_ip_address_prefix_len, match_ip_address_prefix_len_cmd, - "match ip address prefix-len (0-32)$length", - MATCH_STR - IP_STR - "Match prefix length of IP address\n" - "Match prefix length of IP address\n" - "Prefix length\n") -{ - const char *xpath = - "./match-condition[condition='frr-zebra-route-map:ipv4-prefix-length']"; - char xpath_value[XPATH_MAXLEN]; - - nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); - snprintf( - xpath_value, sizeof(xpath_value), - "%s/rmap-match-condition/frr-zebra-route-map:ipv4-prefix-length", - xpath); - nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, length_str); - - return nb_cli_apply_changes(vty, NULL); -} - -DEFPY_YANG( - no_match_ip_address_prefix_len, no_match_ip_address_prefix_len_cmd, - "no match ip address prefix-len [(0-32)]", - NO_STR - MATCH_STR - IP_STR - "Match prefix length of IP address\n" - "Match prefix length of IP address\n" - "Prefix length\n") -{ - const char *xpath = - "./match-condition[condition='frr-zebra-route-map:ipv4-prefix-length']"; - - nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); - - return nb_cli_apply_changes(vty, NULL); -} - -DEFPY_YANG( - match_ipv6_address_prefix_len, match_ipv6_address_prefix_len_cmd, - "match ipv6 address prefix-len (0-128)$length", - MATCH_STR - IPV6_STR - "Match prefix length of IPv6 address\n" - "Match prefix length of IPv6 address\n" - "Prefix length\n") -{ - const char *xpath = - "./match-condition[condition='frr-zebra-route-map:ipv6-prefix-length']"; - char xpath_value[XPATH_MAXLEN]; - - nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); - snprintf( - xpath_value, sizeof(xpath_value), - "%s/rmap-match-condition/frr-zebra-route-map:ipv6-prefix-length", - xpath); - nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, length_str); - - return nb_cli_apply_changes(vty, NULL); -} - -DEFPY_YANG( - no_match_ipv6_address_prefix_len, no_match_ipv6_address_prefix_len_cmd, - "no match ipv6 address prefix-len [(0-128)]", - NO_STR - MATCH_STR - IPV6_STR - "Match prefix length of IPv6 address\n" - "Match prefix length of IPv6 address\n" - "Prefix length\n") -{ - const char *xpath = - "./match-condition[condition='frr-zebra-route-map:ipv6-prefix-length']"; - - nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); - - return nb_cli_apply_changes(vty, NULL); -} - -DEFPY_YANG( - match_ip_nexthop_prefix_len, match_ip_nexthop_prefix_len_cmd, - "match ip next-hop prefix-len (0-32)$length", - MATCH_STR - IP_STR - "Match prefixlen of nexthop IP address\n" - "Match prefixlen of given nexthop\n" - "Prefix length\n") -{ - const char *xpath = - "./match-condition[condition='frr-zebra-route-map:ipv4-next-hop-prefix-length']"; - char xpath_value[XPATH_MAXLEN]; - - nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); - snprintf( - xpath_value, sizeof(xpath_value), - "%s/rmap-match-condition/frr-zebra-route-map:ipv4-prefix-length", - xpath); - nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, length_str); - - return nb_cli_apply_changes(vty, NULL); -} - -DEFPY_YANG( - no_match_ip_nexthop_prefix_len, no_match_ip_nexthop_prefix_len_cmd, - "no match ip next-hop prefix-len [(0-32)]", - NO_STR - MATCH_STR - IP_STR - "Match prefixlen of nexthop IP address\n" - "Match prefix length of nexthop\n" - "Prefix length\n") -{ - const char *xpath = - "./match-condition[condition='frr-zebra-route-map:ipv4-next-hop-prefix-length']"; - - nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); - - return nb_cli_apply_changes(vty, NULL); -} - -DEFPY_YANG( - match_source_protocol, match_source_protocol_cmd, - "match source-protocol " FRR_REDIST_STR_ZEBRA "$proto", - MATCH_STR - "Match protocol via which the route was learnt\n" - FRR_REDIST_HELP_STR_ZEBRA) -{ - const char *xpath = - "./match-condition[condition='frr-zebra-route-map:source-protocol']"; - char xpath_value[XPATH_MAXLEN]; - - nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); - snprintf(xpath_value, sizeof(xpath_value), - "%s/rmap-match-condition/frr-zebra-route-map:source-protocol", - xpath); - nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, proto); - - return nb_cli_apply_changes(vty, NULL); -} - -DEFPY_YANG( - no_match_source_protocol, no_match_source_protocol_cmd, - "no match source-protocol [" FRR_REDIST_STR_ZEBRA "]", - NO_STR - MATCH_STR - "Match protocol via which the route was learnt\n" - FRR_REDIST_HELP_STR_ZEBRA) -{ - const char *xpath = - "./match-condition[condition='frr-zebra-route-map:source-protocol']"; - - nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); - - return nb_cli_apply_changes(vty, NULL); -} - -DEFPY_YANG( - match_source_instance, match_source_instance_cmd, - "match source-instance (0-255)$instance", - MATCH_STR - "Match the protocol's instance number\n" - "The instance number\n") -{ - const char *xpath = - "./match-condition[condition='frr-zebra-route-map:source-instance']"; - char xpath_value[XPATH_MAXLEN]; - - nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); - snprintf(xpath_value, sizeof(xpath_value), - "%s/rmap-match-condition/frr-zebra-route-map:source-instance", - xpath); - nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, instance_str); - - return nb_cli_apply_changes(vty, NULL); -} - -DEFPY_YANG( - no_match_source_instance, no_match_source_instance_cmd, - "no match source-instance [(0-255)]", - NO_STR MATCH_STR - "Match the protocol's instance number\n" - "The instance number\n") -{ - const char *xpath = - "./match-condition[condition='frr-zebra-route-map:source-instance']"; - - nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); - - return nb_cli_apply_changes(vty, NULL); -} - -/* set functions */ - -DEFPY_YANG( - set_src, set_src_cmd, - "set src <A.B.C.D$addrv4|X:X::X:X$addrv6>", - SET_STR - "src address for route\n" - "IPv4 src address\n" - "IPv6 src address\n") -{ - const char *xpath = - "./set-action[action='frr-zebra-route-map:src-address']"; - char xpath_value[XPATH_MAXLEN]; - - nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); - if (addrv4_str) { - snprintf( - xpath_value, sizeof(xpath_value), - "%s/rmap-set-action/frr-zebra-route-map:ipv4-src-address", - xpath); - nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, - addrv4_str); - } else { - snprintf( - xpath_value, sizeof(xpath_value), - "%s/rmap-set-action/frr-zebra-route-map:ipv6-src-address", - xpath); - nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, - addrv6_str); - } - - return nb_cli_apply_changes(vty, NULL); -} - -DEFPY_YANG( - no_set_src, no_set_src_cmd, - "no set src [<A.B.C.D|X:X::X:X>]", - NO_STR - SET_STR - "Source address for route\n" - "IPv4 address\n" - "IPv6 address\n") -{ - const char *xpath = - "./set-action[action='frr-zebra-route-map:src-address']"; - - nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); - - return nb_cli_apply_changes(vty, NULL); -} - -DEFUN_YANG (zebra_route_map_timer, - zebra_route_map_timer_cmd, - "zebra route-map delay-timer (0-600)", - ZEBRA_STR - "Set route-map parameters\n" - "Time to wait before route-map updates are processed\n" - "0 means route-map changes are run immediately instead of delaying\n") -{ - int idx_number = 3; - uint32_t rmap_delay_timer; - - rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10); - zebra_route_map_set_delay_timer(rmap_delay_timer); - - return (CMD_SUCCESS); -} - -DEFUN_YANG (no_zebra_route_map_timer, - no_zebra_route_map_timer_cmd, - "no zebra route-map delay-timer [(0-600)]", - NO_STR - ZEBRA_STR - "Set route-map parameters\n" - "Reset delay-timer to default value, 30 secs\n" - "0 means route-map changes are run immediately instead of delaying\n") -{ - zebra_route_map_set_delay_timer(ZEBRA_RMAP_DEFAULT_UPDATE_TIMER); - - return (CMD_SUCCESS); -} - -DEFPY_YANG (ip_protocol, - ip_protocol_cmd, - "ip protocol " FRR_IP_PROTOCOL_MAP_STR_ZEBRA - " $proto route-map ROUTE-MAP$rmap", - IP_STR - "Filter routing info exchanged between zebra and protocol\n" - FRR_IP_PROTOCOL_MAP_HELP_STR_ZEBRA - "Specify route-map\n" - "Route map name\n") -{ - int ret, rtype; - - assert(proto); - assert(rmap); - - ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf); - - if (!zvrf) - return CMD_WARNING; - - if (strcasecmp(proto, "any") == 0) - rtype = ZEBRA_ROUTE_MAX; - else - rtype = proto_name2num(proto); - if (rtype < 0) { - vty_out(vty, "invalid protocol name \"%s\"\n", proto); - return CMD_WARNING_CONFIG_FAILED; - } - - ret = ip_protocol_rm_add(zvrf, rmap, rtype, AFI_IP, SAFI_UNICAST); - - return ret; -} - -DEFPY_YANG (no_ip_protocol, - no_ip_protocol_cmd, - "no ip protocol " FRR_IP_PROTOCOL_MAP_STR_ZEBRA - " $proto [route-map ROUTE-MAP$rmap]", - NO_STR - IP_STR - "Stop filtering routing info between zebra and protocol\n" - FRR_IP_PROTOCOL_MAP_HELP_STR_ZEBRA - "Specify route-map\n" - "Route map name\n") -{ - int ret, rtype; - - assert(proto); - - ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf); - - if (!zvrf) - return CMD_WARNING; - - if (strcasecmp(proto, "any") == 0) - rtype = ZEBRA_ROUTE_MAX; - else - rtype = proto_name2num(proto); - if (rtype < 0) { - vty_out(vty, "invalid protocol name \"%s\"\n", proto); - return CMD_WARNING_CONFIG_FAILED; - } - - ret = ip_protocol_rm_del(zvrf, rmap, rtype, AFI_IP, SAFI_UNICAST); - - return ret; -} - -DEFPY_YANG (show_ip_protocol, +DEFPY (show_ip_protocol, show_ip_protocol_cmd, "show ip protocol [vrf <NAME$vrf_name|all$vrf_all>]", SHOW_STR @@ -752,75 +400,7 @@ DEFPY_YANG (show_ip_protocol, return ret; } -DEFPY_YANG (ipv6_protocol, - ipv6_protocol_cmd, - "ipv6 protocol " FRR_IP6_PROTOCOL_MAP_STR_ZEBRA - " $proto route-map ROUTE-MAP$rmap", - IP6_STR - "Filter IPv6 routing info exchanged between zebra and protocol\n" - FRR_IP6_PROTOCOL_MAP_HELP_STR_ZEBRA - "Specify route-map\n" - "Route map name\n") -{ - int ret, rtype; - - assert(rmap); - assert(proto); - - ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf); - - if (!zvrf) - return CMD_WARNING; - - if (strcasecmp(proto, "any") == 0) - rtype = ZEBRA_ROUTE_MAX; - else - rtype = proto_name2num(proto); - if (rtype < 0) { - vty_out(vty, "invalid protocol name \"%s\"\n", proto); - return CMD_WARNING_CONFIG_FAILED; - } - - ret = ip_protocol_rm_add(zvrf, rmap, rtype, AFI_IP6, SAFI_UNICAST); - - return ret; -} - -DEFPY_YANG (no_ipv6_protocol, - no_ipv6_protocol_cmd, - "no ipv6 protocol " FRR_IP6_PROTOCOL_MAP_STR_ZEBRA - " $proto [route-map ROUTE-MAP$rmap]", - NO_STR - IP6_STR - "Stop filtering IPv6 routing info between zebra and protocol\n" - FRR_IP6_PROTOCOL_MAP_HELP_STR_ZEBRA - "Specify route-map\n" - "Route map name\n") -{ - int ret, rtype; - - assert(proto); - - ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf); - - if (!zvrf) - return CMD_WARNING; - - if (strcasecmp(proto, "any") == 0) - rtype = ZEBRA_ROUTE_MAX; - else - rtype = proto_name2num(proto); - if (rtype < 0) { - vty_out(vty, "invalid protocol name \"%s\"\n", proto); - return CMD_WARNING_CONFIG_FAILED; - } - - ret = ip_protocol_rm_del(zvrf, rmap, rtype, AFI_IP6, SAFI_UNICAST); - - return ret; -} - -DEFPY_YANG (show_ipv6_protocol, +DEFPY (show_ipv6_protocol, show_ipv6_protocol_cmd, "show ipv6 protocol [vrf <NAME$vrf_name|all$vrf_all>]", SHOW_STR @@ -833,76 +413,7 @@ DEFPY_YANG (show_ipv6_protocol, return ret; } -DEFPY_YANG (ip_protocol_nht_rmap, - ip_protocol_nht_rmap_cmd, - "ip nht " FRR_IP_PROTOCOL_MAP_STR_ZEBRA - " $proto route-map ROUTE-MAP$rmap", - IP_STR - "Filter Next Hop tracking route resolution\n" - FRR_IP_PROTOCOL_MAP_HELP_STR_ZEBRA - "Specify route map\n" - "Route map name\n") -{ - - int ret, rtype; - - assert(proto); - assert(rmap); - - ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf); - - if (!zvrf) - return CMD_WARNING; - - if (strcasecmp(proto, "any") == 0) - rtype = ZEBRA_ROUTE_MAX; - else - rtype = proto_name2num(proto); - if (rtype < 0) { - vty_out(vty, "invalid protocol name \"%s\"\n", proto); - return CMD_WARNING_CONFIG_FAILED; - } - - ret = ip_nht_rm_add(zvrf, rmap, rtype, AFI_IP); - - return ret; -} - -DEFPY_YANG (no_ip_protocol_nht_rmap, - no_ip_protocol_nht_rmap_cmd, - "no ip nht " FRR_IP_PROTOCOL_MAP_STR_ZEBRA - " $proto route-map [ROUTE-MAP$rmap]", - NO_STR - IP_STR - "Filter Next Hop tracking route resolution\n" - FRR_IP_PROTOCOL_MAP_HELP_STR_ZEBRA - "Specify route map\n" - "Route map name\n") -{ - int ret, rtype; - - assert(proto); - - ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf); - - if (!zvrf) - return CMD_WARNING; - - if (strcasecmp(proto, "any") == 0) - rtype = ZEBRA_ROUTE_MAX; - else - rtype = proto_name2num(proto); - if (rtype < 0) { - vty_out(vty, "invalid protocol name \"%s\"\n", proto); - return CMD_WARNING_CONFIG_FAILED; - } - - ret = ip_nht_rm_del(zvrf, rmap, rtype, AFI_IP); - - return ret; -} - -DEFPY_YANG (show_ip_protocol_nht, +DEFPY (show_ip_protocol_nht, show_ip_protocol_nht_cmd, "show ip nht route-map [vrf <NAME$vrf_name|all$vrf_all>] [json]", SHOW_STR @@ -921,75 +432,7 @@ DEFPY_YANG (show_ip_protocol_nht, return ret; } -DEFPY_YANG (ipv6_protocol_nht_rmap, - ipv6_protocol_nht_rmap_cmd, - "ipv6 nht " FRR_IP6_PROTOCOL_MAP_STR_ZEBRA - " $proto route-map ROUTE-MAP$rmap", - IP6_STR - "Filter Next Hop tracking route resolution\n" - FRR_IP6_PROTOCOL_MAP_HELP_STR_ZEBRA - "Specify route map\n" - "Route map name\n") -{ - int ret, rtype; - - assert(rmap); - assert(proto); - - ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf); - - if (!zvrf) - return CMD_WARNING; - - if (strcasecmp(proto, "any") == 0) - rtype = ZEBRA_ROUTE_MAX; - else - rtype = proto_name2num(proto); - if (rtype < 0) { - vty_out(vty, "invalid protocol name \"%s\"\n", proto); - return CMD_WARNING_CONFIG_FAILED; - } - - ret = ip_nht_rm_add(zvrf, rmap, rtype, AFI_IP6); - - return ret; -} - -DEFPY_YANG (no_ipv6_protocol_nht_rmap, - no_ipv6_protocol_nht_rmap_cmd, - "no ipv6 nht " FRR_IP6_PROTOCOL_MAP_STR_ZEBRA - " $proto [route-map ROUTE-MAP$rmap]", - NO_STR - IP6_STR - "Filter Next Hop tracking route resolution\n" - FRR_IP6_PROTOCOL_MAP_HELP_STR_ZEBRA - "Specify route map\n" - "Route map name\n") -{ - int ret, rtype; - - assert(proto); - - ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf); - - if (!zvrf) - return CMD_WARNING; - - if (strcasecmp(proto, "any") == 0) - rtype = ZEBRA_ROUTE_MAX; - else - rtype = proto_name2num(proto); - if (rtype < 0) { - vty_out(vty, "invalid protocol name \"%s\"\n", proto); - return CMD_WARNING_CONFIG_FAILED; - } - - ret = ip_nht_rm_del(zvrf, rmap, rtype, AFI_IP6); - - return ret; -} - -DEFPY_YANG (show_ipv6_protocol_nht, +DEFPY (show_ipv6_protocol_nht, show_ipv6_protocol_nht_cmd, "show ipv6 nht route-map [vrf <NAME$vrf_name|all$vrf_all>] [json]", SHOW_STR @@ -1017,21 +460,21 @@ static enum route_map_cmd_result_t route_match_ip_next_hop(void *rule, const struct prefix *prefix, void *object) { struct access_list *alist; - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; struct prefix_ipv4 p; - nh_data = object; - if (!nh_data) + rm_data = object; + if (!rm_data) return RMAP_NOMATCH; - switch (nh_data->nexthop->type) { + switch (rm_data->nexthop->type) { case NEXTHOP_TYPE_IFINDEX: /* Interface routes can't match ip next-hop */ return RMAP_NOMATCH; case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4: p.family = AF_INET; - p.prefix = nh_data->nexthop->gate.ipv4; + p.prefix = rm_data->nexthop->gate.ipv4; p.prefixlen = IPV4_MAX_BITLEN; break; case NEXTHOP_TYPE_IPV6: @@ -1080,21 +523,21 @@ route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix, void *object) { struct prefix_list *plist; - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; struct prefix_ipv4 p; - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data) + rm_data = (struct zebra_rmap_obj *)object; + if (!rm_data) return RMAP_NOMATCH; - switch (nh_data->nexthop->type) { + switch (rm_data->nexthop->type) { case NEXTHOP_TYPE_IFINDEX: /* Interface routes can't match ip next-hop */ return RMAP_NOMATCH; case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4: p.family = AF_INET; - p.prefix = nh_data->nexthop->gate.ipv4; + p.prefix = rm_data->nexthop->gate.ipv4; p.prefixlen = IPV4_MAX_BITLEN; break; case NEXTHOP_TYPE_IPV6: @@ -1264,14 +707,14 @@ static enum route_map_cmd_result_t route_match_ipv6_next_hop_type(void *rule, const struct prefix *prefix, void *object) { - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; if (prefix->family == AF_INET6) { - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data) + rm_data = (struct zebra_rmap_obj *)object; + if (!rm_data) return RMAP_NOMATCH; - if (nh_data->nexthop->type == NEXTHOP_TYPE_BLACKHOLE) + if (rm_data->nexthop->type == NEXTHOP_TYPE_BLACKHOLE) return RMAP_MATCH; } @@ -1356,21 +799,21 @@ route_match_ip_nexthop_prefix_len(void *rule, const struct prefix *prefix, void *object) { uint32_t *prefixlen = (uint32_t *)rule; - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; struct prefix_ipv4 p; - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data || !nh_data->nexthop) + rm_data = (struct zebra_rmap_obj *)object; + if (!rm_data || !rm_data->nexthop) return RMAP_NOMATCH; - switch (nh_data->nexthop->type) { + switch (rm_data->nexthop->type) { case NEXTHOP_TYPE_IFINDEX: /* Interface routes can't match ip next-hop */ return RMAP_NOMATCH; case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4: p.family = AF_INET; - p.prefix = nh_data->nexthop->gate.ipv4; + p.prefix = rm_data->nexthop->gate.ipv4; p.prefixlen = IPV4_MAX_BITLEN; break; case NEXTHOP_TYPE_IPV6: @@ -1395,14 +838,14 @@ static enum route_map_cmd_result_t route_match_ip_next_hop_type(void *rule, const struct prefix *prefix, void *object) { - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; if (prefix->family == AF_INET) { - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data) + rm_data = (struct zebra_rmap_obj *)object; + if (!rm_data) return RMAP_NOMATCH; - if (nh_data->nexthop->type == NEXTHOP_TYPE_BLACKHOLE) + if (rm_data->nexthop->type == NEXTHOP_TYPE_BLACKHOLE) return RMAP_MATCH; } @@ -1432,15 +875,14 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t route_match_source_protocol(void *rule, const struct prefix *p, void *object) { - uint32_t *rib_type = (uint32_t *)rule; - struct nh_rmap_obj *nh_data; + int32_t *rib_type = (int32_t *)rule; + struct zebra_rmap_obj *rm_data; - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data) + rm_data = (struct zebra_rmap_obj *)object; + if (!rm_data) return RMAP_NOMATCH; - return ((nh_data->source_protocol == *rib_type) ? RMAP_MATCH - : RMAP_NOMATCH); + return ((rm_data->re->type == *rib_type) ? RMAP_MATCH : RMAP_NOMATCH); } static void *route_match_source_protocol_compile(const char *arg) @@ -1473,13 +915,13 @@ static enum route_map_cmd_result_t route_match_source_instance(void *rule, const struct prefix *p, void *object) { uint8_t *instance = (uint8_t *)rule; - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data) + rm_data = (struct zebra_rmap_obj *)object; + if (!rm_data) return RMAP_NOMATCH; - return (nh_data->instance == *instance) ? RMAP_MATCH : RMAP_NOMATCH; + return (rm_data->re->instance == *instance) ? RMAP_MATCH : RMAP_NOMATCH; } static void *route_match_source_instance_compile(const char *arg) @@ -1513,10 +955,10 @@ static const struct route_map_rule_cmd route_match_source_instance_cmd = { static enum route_map_cmd_result_t route_set_src(void *rule, const struct prefix *prefix, void *object) { - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; - nh_data = (struct nh_rmap_obj *)object; - nh_data->nexthop->rmap_src = *(union g_addr *)rule; + rm_data = (struct zebra_rmap_obj *)object; + rm_data->nexthop->rmap_src = *(union g_addr *)rule; return RMAP_OKAY; } @@ -1703,7 +1145,7 @@ static void zebra_nht_rm_update(const char *rmap) afi_ipv6 = 1; zebra_evaluate_rnh( - zvrf, AFI_IP, 1, NULL, + zvrf, AFI_IP6, 1, NULL, SAFI_UNICAST); } } @@ -1741,7 +1183,7 @@ static void zebra_route_map_update_timer(struct event *thread) */ } -static void zebra_route_map_set_delay_timer(uint32_t value) +void zebra_route_map_set_delay_timer(uint32_t value) { zebra_rmap_update_timer = value; if (!value && zebra_t_rmap_update) { @@ -1761,26 +1203,22 @@ void zebra_routemap_finish(void) route_map_finish(); } -route_map_result_t -zebra_route_map_check(afi_t family, int rib_type, uint8_t instance, - const struct prefix *p, struct nexthop *nexthop, - struct zebra_vrf *zvrf, route_tag_t tag) +route_map_result_t zebra_route_map_check(afi_t family, struct route_entry *re, + const struct prefix *p, + struct nexthop *nexthop, + struct zebra_vrf *zvrf) { struct route_map *rmap = NULL; char *rm_name; route_map_result_t ret = RMAP_PERMITMATCH; - struct nh_rmap_obj nh_obj; + struct zebra_rmap_obj rm_obj; - nh_obj.nexthop = nexthop; - nh_obj.vrf_id = nexthop->vrf_id; - nh_obj.source_protocol = rib_type; - nh_obj.instance = instance; - nh_obj.metric = 0; - nh_obj.tag = tag; + rm_obj.nexthop = nexthop; + rm_obj.re = re; - if (rib_type >= 0 && rib_type < ZEBRA_ROUTE_MAX) { - rm_name = PROTO_RM_NAME(zvrf, family, rib_type); - rmap = PROTO_RM_MAP(zvrf, family, rib_type); + if (re->type >= 0 && re->type < ZEBRA_ROUTE_MAX) { + rm_name = PROTO_RM_NAME(zvrf, family, re->type); + rmap = PROTO_RM_MAP(zvrf, family, re->type); if (rm_name && !rmap) return RMAP_DENYMATCH; @@ -1793,7 +1231,7 @@ zebra_route_map_check(afi_t family, int rib_type, uint8_t instance, return RMAP_DENYMATCH; } if (rmap) { - ret = route_map_apply(rmap, p, &nh_obj); + ret = route_map_apply(rmap, p, &rm_obj); } return (ret); @@ -1816,28 +1254,23 @@ void zebra_del_import_table_route_map(afi_t afi, uint32_t table) XFREE(MTYPE_ROUTE_MAP_NAME, zebra_import_table_routemap[afi][table]); } -route_map_result_t -zebra_import_table_route_map_check(int family, int re_type, uint8_t instance, - const struct prefix *p, - struct nexthop *nexthop, - vrf_id_t vrf_id, route_tag_t tag, - const char *rmap_name) +route_map_result_t zebra_import_table_route_map_check(int family, + struct route_entry *re, + const struct prefix *p, + struct nexthop *nexthop, + const char *rmap_name) { struct route_map *rmap = NULL; route_map_result_t ret = RMAP_DENYMATCH; - struct nh_rmap_obj nh_obj; + struct zebra_rmap_obj rm_obj; - nh_obj.nexthop = nexthop; - nh_obj.vrf_id = vrf_id; - nh_obj.source_protocol = re_type; - nh_obj.instance = instance; - nh_obj.metric = 0; - nh_obj.tag = tag; + rm_obj.nexthop = nexthop; + rm_obj.re = re; - if (re_type >= 0 && re_type < ZEBRA_ROUTE_MAX) + if (re->type >= 0 && re->type < ZEBRA_ROUTE_MAX) rmap = route_map_lookup_by_name(rmap_name); if (rmap) { - ret = route_map_apply(rmap, p, &nh_obj); + ret = route_map_apply(rmap, p, &rm_obj); } return (ret); @@ -1851,21 +1284,17 @@ route_map_result_t zebra_nht_route_map_check(afi_t afi, int client_proto, { struct route_map *rmap = NULL; route_map_result_t ret = RMAP_PERMITMATCH; - struct nh_rmap_obj nh_obj; + struct zebra_rmap_obj rm_obj; - nh_obj.nexthop = nexthop; - nh_obj.vrf_id = nexthop->vrf_id; - nh_obj.source_protocol = re->type; - nh_obj.instance = re->instance; - nh_obj.metric = re->metric; - nh_obj.tag = re->tag; + rm_obj.nexthop = nexthop; + rm_obj.re = re; if (client_proto >= 0 && client_proto < ZEBRA_ROUTE_MAX) rmap = NHT_RM_MAP(zvrf, afi, client_proto); if (!rmap && NHT_RM_MAP(zvrf, afi, ZEBRA_ROUTE_MAX)) rmap = NHT_RM_MAP(zvrf, afi, ZEBRA_ROUTE_MAX); if (rmap) - ret = route_map_apply(rmap, p, &nh_obj); + ret = route_map_apply(rmap, p, &rm_obj); return ret; } @@ -1921,88 +1350,14 @@ void zebra_routemap_vrf_delete(struct zebra_vrf *zvrf) } } -/* ip protocol configuration write function */ -void zebra_routemap_config_write_protocol(struct vty *vty, - struct zebra_vrf *zvrf) -{ - int i; - char space[2]; - - memset(space, 0, sizeof(space)); - - if (zvrf_id(zvrf) != VRF_DEFAULT) - snprintf(space, sizeof(space), "%s", " "); - - for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { - if (PROTO_RM_NAME(zvrf, AFI_IP, i)) - vty_out(vty, "%sip protocol %s route-map %s\n", space, - zebra_route_string(i), - PROTO_RM_NAME(zvrf, AFI_IP, i)); - - if (PROTO_RM_NAME(zvrf, AFI_IP6, i)) - vty_out(vty, "%sipv6 protocol %s route-map %s\n", space, - zebra_route_string(i), - PROTO_RM_NAME(zvrf, AFI_IP6, i)); - - if (NHT_RM_NAME(zvrf, AFI_IP, i)) - vty_out(vty, "%sip nht %s route-map %s\n", space, - zebra_route_string(i), - NHT_RM_NAME(zvrf, AFI_IP, i)); - - if (NHT_RM_NAME(zvrf, AFI_IP6, i)) - vty_out(vty, "%sipv6 nht %s route-map %s\n", space, - zebra_route_string(i), - NHT_RM_NAME(zvrf, AFI_IP6, i)); - } - - if (PROTO_RM_NAME(zvrf, AFI_IP, ZEBRA_ROUTE_MAX)) - vty_out(vty, "%sip protocol %s route-map %s\n", space, "any", - PROTO_RM_NAME(zvrf, AFI_IP, ZEBRA_ROUTE_MAX)); - - if (PROTO_RM_NAME(zvrf, AFI_IP6, ZEBRA_ROUTE_MAX)) - vty_out(vty, "%sipv6 protocol %s route-map %s\n", space, "any", - PROTO_RM_NAME(zvrf, AFI_IP6, ZEBRA_ROUTE_MAX)); - - if (NHT_RM_NAME(zvrf, AFI_IP, ZEBRA_ROUTE_MAX)) - vty_out(vty, "%sip nht %s route-map %s\n", space, "any", - NHT_RM_NAME(zvrf, AFI_IP, ZEBRA_ROUTE_MAX)); - - if (NHT_RM_NAME(zvrf, AFI_IP6, ZEBRA_ROUTE_MAX)) - vty_out(vty, "%sipv6 nht %s route-map %s\n", space, "any", - NHT_RM_NAME(zvrf, AFI_IP6, ZEBRA_ROUTE_MAX)); - - if (zvrf_id(zvrf) == VRF_DEFAULT - && zebra_rmap_update_timer != ZEBRA_RMAP_DEFAULT_UPDATE_TIMER) - vty_out(vty, "zebra route-map delay-timer %d\n", - zebra_rmap_update_timer); -} - void zebra_route_map_init(void) { - install_element(CONFIG_NODE, &ip_protocol_cmd); - install_element(CONFIG_NODE, &no_ip_protocol_cmd); - install_element(VRF_NODE, &ip_protocol_cmd); - install_element(VRF_NODE, &no_ip_protocol_cmd); install_element(VIEW_NODE, &show_ip_protocol_cmd); - install_element(CONFIG_NODE, &ipv6_protocol_cmd); - install_element(CONFIG_NODE, &no_ipv6_protocol_cmd); - install_element(VRF_NODE, &ipv6_protocol_cmd); - install_element(VRF_NODE, &no_ipv6_protocol_cmd); install_element(VIEW_NODE, &show_ipv6_protocol_cmd); - install_element(CONFIG_NODE, &ip_protocol_nht_rmap_cmd); - install_element(CONFIG_NODE, &no_ip_protocol_nht_rmap_cmd); - install_element(VRF_NODE, &ip_protocol_nht_rmap_cmd); - install_element(VRF_NODE, &no_ip_protocol_nht_rmap_cmd); install_element(VIEW_NODE, &show_ip_protocol_nht_cmd); - install_element(CONFIG_NODE, &ipv6_protocol_nht_rmap_cmd); - install_element(CONFIG_NODE, &no_ipv6_protocol_nht_rmap_cmd); - install_element(VRF_NODE, &ipv6_protocol_nht_rmap_cmd); - install_element(VRF_NODE, &no_ipv6_protocol_nht_rmap_cmd); install_element(VIEW_NODE, &show_ipv6_protocol_nht_cmd); - install_element(CONFIG_NODE, &zebra_route_map_timer_cmd); - install_element(CONFIG_NODE, &no_zebra_route_map_timer_cmd); - route_map_init(); + route_map_init_new(true); route_map_add_hook(zebra_route_map_add); route_map_delete_hook(zebra_route_map_delete); @@ -2056,19 +1411,4 @@ void zebra_route_map_init(void) /* */ route_map_install_set(&route_set_src_cmd); - /* */ - install_element(RMAP_NODE, &match_ip_nexthop_prefix_len_cmd); - install_element(RMAP_NODE, &no_match_ip_nexthop_prefix_len_cmd); - install_element(RMAP_NODE, &match_ip_address_prefix_len_cmd); - install_element(RMAP_NODE, &match_ipv6_address_prefix_len_cmd); - install_element(RMAP_NODE, &no_match_ipv6_address_prefix_len_cmd); - install_element(RMAP_NODE, &no_match_ip_address_prefix_len_cmd); - install_element(RMAP_NODE, &match_source_protocol_cmd); - install_element(RMAP_NODE, &no_match_source_protocol_cmd); - install_element(RMAP_NODE, &match_source_instance_cmd); - install_element(RMAP_NODE, &no_match_source_instance_cmd); - - /* */ - install_element(RMAP_NODE, &set_src_cmd); - install_element(RMAP_NODE, &no_set_src_cmd); } |
