From 2f8aa457e0a30e20a1af84257892006e24490d85 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 27 Jul 2017 10:44:55 -0300 Subject: [PATCH 1/8] zebra: use curly braces for optional arguments of static routes This way the optional arguments can be provided in any order. Signed-off-by: Renato Westphal --- zebra/zebra_vty.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 50fa69d22..5cbb55ebd 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -389,7 +389,7 @@ static void zebra_vty_ip_route_tdv_helper(int argc, struct cmd_token *argv[], /* Static route configuration. */ DEFUN (ip_route, ip_route_cmd, - "ip route A.B.C.D/M [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IP destination prefix (e.g. 10.0.0.0/8)\n" @@ -418,7 +418,7 @@ DEFUN (ip_route, DEFUN (ip_route_flags, ip_route_flags_cmd, - "ip route A.B.C.D/M [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IP destination prefix (e.g. 10.0.0.0/8)\n" @@ -446,7 +446,7 @@ DEFUN (ip_route_flags, /* Mask as A.B.C.D format. */ DEFUN_HIDDEN (ip_route_mask, ip_route_mask_cmd, - "ip route A.B.C.D A.B.C.D [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IP destination prefix\n" @@ -477,7 +477,7 @@ DEFUN_HIDDEN (ip_route_mask, DEFUN_HIDDEN (ip_route_mask_flags, ip_route_mask_flags_cmd, - "ip route A.B.C.D A.B.C.D [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IP destination prefix\n" @@ -507,7 +507,7 @@ DEFUN_HIDDEN (ip_route_mask_flags, DEFUN (no_ip_route, no_ip_route_cmd, - "no ip route A.B.C.D/M [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "no ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" @@ -537,7 +537,7 @@ DEFUN (no_ip_route, DEFUN (no_ip_route_flags, no_ip_route_flags_cmd, - "no ip route A.B.C.D/M [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "no ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" @@ -564,7 +564,7 @@ DEFUN (no_ip_route_flags, DEFUN_HIDDEN (no_ip_route_mask, no_ip_route_mask_cmd, - "no ip route A.B.C.D A.B.C.D [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "no ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" @@ -596,7 +596,7 @@ DEFUN_HIDDEN (no_ip_route_mask, DEFUN_HIDDEN (no_ip_route_mask_flags, no_ip_route_mask_flags_cmd, - "no ip route A.B.C.D A.B.C.D [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "no ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" @@ -2172,7 +2172,7 @@ int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, DEFUN (ipv6_route, ipv6_route_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" @@ -2212,7 +2212,7 @@ DEFUN (ipv6_route, DEFUN (ipv6_route_flags, ipv6_route_flags_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" @@ -2257,7 +2257,7 @@ DEFUN (ipv6_route_flags, DEFUN (ipv6_route_ifname, ipv6_route_ifname_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" @@ -2299,7 +2299,7 @@ DEFUN (ipv6_route_ifname, DEFUN (ipv6_route_ifname_flags, ipv6_route_ifname_flags_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" @@ -2347,7 +2347,7 @@ DEFUN (ipv6_route_ifname_flags, DEFUN (no_ipv6_route, no_ipv6_route_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" @@ -2388,7 +2388,7 @@ DEFUN (no_ipv6_route, DEFUN (no_ipv6_route_flags, no_ipv6_route_flags_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" @@ -2434,7 +2434,7 @@ DEFUN (no_ipv6_route_flags, DEFUN (no_ipv6_route_ifname, no_ipv6_route_ifname_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" @@ -2477,7 +2477,7 @@ DEFUN (no_ipv6_route_ifname, DEFUN (no_ipv6_route_ifname_flags, no_ipv6_route_ifname_flags_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" From 8bcbf3b0d705b532c17670ad508930414213e953 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 27 Jul 2017 11:05:15 -0300 Subject: [PATCH 2/8] zebra: remove weird blackhole/reject ipv6 static routes This is the v6 counterpart of commit 74d263466b9. Signed-off-by: Renato Westphal --- zebra/zebra_vty.c | 160 +++++++++------------------------------------- 1 file changed, 31 insertions(+), 129 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 5cbb55ebd..7e492ad6b 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -2045,10 +2045,6 @@ int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, if (tag_str) tag = strtoul(tag_str, NULL, 10); - /* When gateway is valid IPv6 addrees, then gate is treated as - nexthop address other case gate is treated as interface name. */ - ret = inet_pton(AF_INET6, gate_str, &gate_addr); - /* VRF id */ zvrf = zebra_vrf_lookup_by_name(vrf_id_str); @@ -2125,6 +2121,23 @@ int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, } } + if (gate_str == NULL) { + if (add_cmd) + static_add_route(AFI_IP6, SAFI_UNICAST, type, &p, src_p, + NULL, ifindex, ifname, flag, tag, + distance, zvrf, &snh_label); + else + static_delete_route(AFI_IP6, SAFI_UNICAST, type, &p, + src_p, NULL, ifindex, tag, distance, + zvrf, &snh_label); + + return CMD_SUCCESS; + } + + /* When gateway is valid IPv6 addrees, then gate is treated as + nexthop address other case gate is treated as interface name. */ + ret = inet_pton(AF_INET6, gate_str, &gate_addr); + if (ifname) { /* When ifname is specified. It must be come with gateway address. */ @@ -2212,14 +2225,12 @@ DEFUN (ipv6_route, DEFUN (ipv6_route_flags, ipv6_route_flags_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" "IPv6 source-dest route\n" "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" "Emit an ICMP unreachable when matched\n" "Silently discard pkts when matched\n" "Set tag for this route\n" @@ -2228,21 +2239,18 @@ DEFUN (ipv6_route_flags, VRF_CMD_HELP_STR) { int idx_ipv6_prefixlen = 2; - int idx_ipv6_ifname; int idx_reject_blackhole; int idx_curr; char *src, *tag, *distance, *vrf; if (strmatch(argv[3]->text, "from")) { src = argv[4]->arg; - idx_ipv6_ifname = 5; - idx_reject_blackhole = 6; - idx_curr = 7; + idx_reject_blackhole = 5; + idx_curr = 6; } else { src = NULL; - idx_ipv6_ifname = 3; - idx_reject_blackhole = 4; - idx_curr = 5; + idx_reject_blackhole = 3; + idx_curr = 4; } tag = distance = vrf = NULL; @@ -2250,9 +2258,8 @@ DEFUN (ipv6_route_flags, &vrf, NULL); return static_ipv6_func(vty, 1, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6_ifname]->arg, NULL, - argv[idx_reject_blackhole]->arg, tag, distance, - vrf, NULL); + NULL, NULL, argv[idx_reject_blackhole]->arg, + tag, distance, vrf, NULL); } DEFUN (ipv6_route_ifname, @@ -2297,54 +2304,6 @@ DEFUN (ipv6_route_ifname, NULL, tag, distance, vrf, NULL); } -DEFUN (ipv6_route_ifname_flags, - ipv6_route_ifname_flags_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME}]", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Emit an ICMP unreachable when matched\n" - "Silently discard pkts when matched\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - VRF_CMD_HELP_STR) -{ - int idx_ipv6_prefixlen = 2; - int idx_ipv6; - int idx_interface; - int idx_reject_blackhole; - int idx_curr; - char *src, *tag, *distance, *vrf; - - if (strmatch(argv[3]->text, "from")) { - src = argv[4]->arg; - idx_ipv6 = 5; - idx_interface = 6; - idx_reject_blackhole = 7; - idx_curr = 8; - } else { - src = NULL; - idx_ipv6 = 3; - idx_interface = 4; - idx_reject_blackhole = 5; - idx_curr = 6; - } - - tag = distance = vrf = NULL; - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); - - return static_ipv6_func(vty, 1, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6]->arg, argv[idx_interface]->arg, - argv[idx_reject_blackhole]->arg, tag, distance, - vrf, NULL); -} - DEFUN (no_ipv6_route, no_ipv6_route_cmd, "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", @@ -2388,15 +2347,13 @@ DEFUN (no_ipv6_route, DEFUN (no_ipv6_route_flags, no_ipv6_route_flags_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" "IPv6 source-dest route\n" "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" "Emit an ICMP unreachable when matched\n" "Silently discard pkts when matched\n" "Set tag for this route\n" @@ -2405,21 +2362,18 @@ DEFUN (no_ipv6_route_flags, VRF_CMD_HELP_STR) { int idx_ipv6_prefixlen = 3; - int idx_ipv6_ifname; int idx_reject_blackhole; int idx_curr; char *src, *tag, *distance, *vrf; if (strmatch(argv[4]->text, "from")) { src = argv[5]->arg; - idx_ipv6_ifname = 6; - idx_reject_blackhole = 7; - idx_curr = 8; + idx_reject_blackhole = 6; + idx_curr = 7; } else { src = NULL; - idx_ipv6_ifname = 4; - idx_reject_blackhole = 5; - idx_curr = 6; + idx_reject_blackhole = 4; + idx_curr = 5; } tag = distance = vrf = NULL; @@ -2427,9 +2381,8 @@ DEFUN (no_ipv6_route_flags, &vrf, NULL); return static_ipv6_func(vty, 0, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6_ifname]->arg, NULL, - argv[idx_reject_blackhole]->arg, tag, distance, - vrf, NULL); + NULL, NULL, argv[idx_reject_blackhole]->arg, + tag, distance, vrf, NULL); } DEFUN (no_ipv6_route_ifname, @@ -2475,55 +2428,6 @@ DEFUN (no_ipv6_route_ifname, NULL, tag, distance, vrf, NULL); } -DEFUN (no_ipv6_route_ifname_flags, - no_ipv6_route_ifname_flags_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME}]", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Emit an ICMP unreachable when matched\n" - "Silently discard pkts when matched\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - VRF_CMD_HELP_STR) -{ - int idx_ipv6_prefixlen = 3; - int idx_ipv6; - int idx_interface; - int idx_reject_blackhole; - int idx_curr; - char *src, *tag, *distance, *vrf; - - if (strmatch(argv[4]->text, "from")) { - src = argv[5]->arg; - idx_ipv6 = 6; - idx_interface = 7; - idx_reject_blackhole = 8; - idx_curr = 9; - } else { - src = NULL; - idx_ipv6 = 4; - idx_interface = 5; - idx_reject_blackhole = 6; - idx_curr = 7; - } - - tag = distance = vrf = NULL; - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); - - return static_ipv6_func(vty, 0, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6]->arg, argv[idx_interface]->arg, - argv[idx_reject_blackhole]->arg, tag, distance, - vrf, NULL); -} - DEFUN (show_ipv6_route, show_ipv6_route_cmd, "show ipv6 [vrf NAME] [tag (1-4294967295)|X:X::X:X/M longer-prefixes|" FRR_IP6_REDIST_STR_ZEBRA "] [json]", @@ -3413,11 +3317,9 @@ void zebra_vty_init(void) install_element(CONFIG_NODE, &ipv6_route_cmd); install_element(CONFIG_NODE, &ipv6_route_flags_cmd); install_element(CONFIG_NODE, &ipv6_route_ifname_cmd); - install_element(CONFIG_NODE, &ipv6_route_ifname_flags_cmd); install_element(CONFIG_NODE, &no_ipv6_route_cmd); install_element(CONFIG_NODE, &no_ipv6_route_flags_cmd); install_element(CONFIG_NODE, &no_ipv6_route_ifname_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd); install_element(CONFIG_NODE, &ip_nht_default_route_cmd); install_element(CONFIG_NODE, &no_ip_nht_default_route_cmd); install_element(CONFIG_NODE, &ipv6_nht_default_route_cmd); From d97c792e9f525e360d3f39fd5c73e3ab4bd908c3 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 27 Jul 2017 12:16:41 -0300 Subject: [PATCH 3/8] zebra: remove redundant DEFUNs for labeled static routes Signed-off-by: Renato Westphal --- zebra/zebra_mpls_vty.c | 599 +---------------------------------------- zebra/zebra_static.h | 12 - zebra/zebra_vty.c | 126 +++++---- 3 files changed, 63 insertions(+), 674 deletions(-) diff --git a/zebra/zebra_mpls_vty.c b/zebra/zebra_mpls_vty.c index ed34831f8..9d100bb7d 100644 --- a/zebra/zebra_mpls_vty.c +++ b/zebra/zebra_mpls_vty.c @@ -283,570 +283,6 @@ DEFUN (no_mpls_label_bind, return zebra_mpls_bind(vty, 0, argv[4]->arg, NULL); } -/* Static route configuration. */ -DEFUN (ip_route_label, - ip_route_label_cmd, - "ip route A.B.C.D/M label WORD", - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, NULL, - argv[3]->arg, NULL, NULL, NULL, NULL, - argv[5]->arg); -} - -DEFUN (ip_route_tag_label, - ip_route_tag_label_cmd, - "ip route A.B.C.D/M tag (1-4294967295) label WORD", - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, NULL, - argv[3]->arg, NULL, argv[5]->arg, NULL, NULL, - argv[7]->arg); -} - -/* Mask as A.B.C.D format. */ -DEFUN (ip_route_mask_label, - ip_route_mask_label_cmd, - "ip route A.B.C.D A.B.C.D label WORD", - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, - argv[3]->arg, argv[4]->arg, NULL, NULL, NULL, - NULL, argv[6]->arg); -} - -DEFUN (ip_route_mask_tag_label, - ip_route_mask_tag_label_cmd, - "ip route A.B.C.D A.B.C.D tag (1-4294967295) label WORD", - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, - argv[3]->arg, argv[4]->arg, NULL, argv[6]->arg, - NULL, NULL, argv[8]->arg); -} - -/* Distance option value. */ -DEFUN (ip_route_distance_label, - ip_route_distance_label_cmd, - "ip route A.B.C.D/M (1-255) label WORD", - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Distance value for this route\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, NULL, - argv[3]->arg, NULL, NULL, argv[4]->arg, NULL, - argv[6]->arg); -} - -DEFUN (ip_route_tag_distance_label, - ip_route_tag_distance_label_cmd, - "ip route A.B.C.D/M tag (1-4294967295) (1-255) label WORD", - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this route\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, NULL, - argv[3]->arg, NULL, argv[5]->arg, argv[6]->arg, - NULL, argv[8]->arg); -} - -DEFUN (ip_route_mask_distance_label, - ip_route_mask_distance_label_cmd, - "ip route A.B.C.D A.B.C.D (1-255) label WORD", - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Distance value for this route\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, - argv[3]->arg, argv[4]->arg, NULL, NULL, - argv[5]->arg, NULL, argv[7]->arg); -} - -DEFUN (ip_route_mask_tag_distance_label, - ip_route_mask_tag_distance_label_cmd, - "ip route A.B.C.D A.B.C.D tag (1-4294967295) (1-255) label WORD", - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this route\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, - argv[3]->arg, argv[4]->arg, NULL, argv[6]->arg, - argv[7]->arg, NULL, argv[9]->arg); -} - -DEFUN (no_ip_route_label, - no_ip_route_label_cmd, - "no ip route A.B.C.D/M label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, NULL, - argv[4]->arg, NULL, NULL, NULL, NULL, - argv[6]->arg); -} - -DEFUN (no_ip_route_tag_label, - no_ip_route_tag_label_cmd, - "no ip route A.B.C.D/M tag (1-4294967295) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Tag of this route\n" - "Tag value\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, NULL, - argv[4]->arg, NULL, argv[6]->arg, NULL, NULL, - argv[8]->arg); -} - -DEFUN (no_ip_route_mask_label, - no_ip_route_mask_label_cmd, - "no ip route A.B.C.D A.B.C.D label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, - argv[4]->arg, argv[5]->arg, NULL, NULL, NULL, - NULL, argv[7]->arg); -} - -DEFUN (no_ip_route_mask_tag_label, - no_ip_route_mask_tag_label_cmd, - "no ip route A.B.C.D A.B.C.D tag (1-4294967295) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Tag of this route\n" - "Tag value\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, - argv[4]->arg, argv[5]->arg, NULL, argv[7]->arg, - NULL, NULL, argv[9]->arg); -} - -DEFUN (no_ip_route_distance_label, - no_ip_route_distance_label_cmd, - "no ip route A.B.C.D/M (1-255) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Distance value for this route\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, NULL, - argv[4]->arg, NULL, NULL, argv[5]->arg, NULL, - argv[7]->arg); -} - -DEFUN (no_ip_route_tag_distance_label, - no_ip_route_tag_distance_label_cmd, - "no ip route A.B.C.D/M tag (1-4294967295) (1-255) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, NULL, - argv[4]->arg, NULL, argv[6]->arg, argv[7]->arg, - NULL, argv[9]->arg); -} - -DEFUN (no_ip_route_mask_distance_label, - no_ip_route_mask_distance_label_cmd, - "no ip route A.B.C.D A.B.C.D (1-255) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Distance value for this route\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, - argv[4]->arg, argv[5]->arg, NULL, NULL, - argv[6]->arg, NULL, argv[8]->arg); -} - -DEFUN (no_ip_route_mask_tag_distance_label, - no_ip_route_mask_tag_distance_label_cmd, - "no ip route A.B.C.D A.B.C.D tag (1-4294967295) (1-255) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, - argv[4]->arg, argv[5]->arg, NULL, argv[7]->arg, - argv[8]->arg, NULL, argv[10]->arg); -} - -DEFUN (ipv6_route_label, - ipv6_route_label_cmd, - "ipv6 route X:X::X:X/M label WORD", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, NULL, - NULL, NULL, NULL, NULL, argv[5]->arg); -} - -DEFUN (ipv6_route_tag_label, - ipv6_route_tag_label_cmd, - "ipv6 route X:X::X:X/M tag (1-4294967295) label WORD", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, NULL, - NULL, argv[5]->arg, NULL, NULL, argv[7]->arg); -} - -DEFUN (ipv6_route_ifname_label, - ipv6_route_ifname_label_cmd, - "ipv6 route X:X::X:X/M X:X::X:X INTERFACE label WORD", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, - argv[4]->arg, NULL, NULL, NULL, NULL, - argv[6]->arg); -} -DEFUN (ipv6_route_ifname_tag_label, - ipv6_route_ifname_tag_label_cmd, - "ipv6 route X:X::X:X/M X:X::X:X INTERFACE tag (1-4294967295) label WORD", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, - argv[4]->arg, NULL, argv[6]->arg, NULL, NULL, - argv[8]->arg); -} - -DEFUN (ipv6_route_pref_label, - ipv6_route_pref_label_cmd, - "ipv6 route X:X::X:X/M (1-255) label WORD", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, NULL, - NULL, NULL, argv[4]->arg, NULL, argv[6]->arg); -} - -DEFUN (ipv6_route_pref_tag_label, - ipv6_route_pref_tag_label_cmd, - "ipv6 route X:X::X:X/M tag (1-4294967295) (1-255) label WORD", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, NULL, - NULL, argv[5]->arg, argv[6]->arg, NULL, - argv[8]->arg); -} - -DEFUN (ipv6_route_ifname_pref_label, - ipv6_route_ifname_pref_label_cmd, - "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (1-255) label WORD", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, - argv[4]->arg, NULL, NULL, argv[5]->arg, NULL, - argv[7]->arg); -} - -DEFUN (ipv6_route_ifname_pref_tag_label, - ipv6_route_ifname_pref_tag_label_cmd, - "ipv6 route X:X::X:X/M X:X::X:X INTERFACE tag (1-4294967295) (1-255) label WORD", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, - argv[4]->arg, NULL, argv[6]->arg, argv[7]->arg, - NULL, argv[9]->arg); -} - -DEFUN (no_ipv6_route_label, - no_ipv6_route_label_cmd, - "no ipv6 route X:X::X:X/M label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, NULL, - NULL, NULL, NULL, NULL, argv[6]->arg); -} - -DEFUN (no_ipv6_route_tag_label, - no_ipv6_route_tag_label_cmd, - "no ipv6 route X:X::X:X/M tag (1-4294967295) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, NULL, - NULL, argv[6]->arg, NULL, NULL, argv[8]->arg); -} - -DEFUN (no_ipv6_route_ifname_label, - no_ipv6_route_ifname_label_cmd, - "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, - argv[5]->arg, NULL, NULL, NULL, NULL, - argv[7]->arg); -} - -DEFUN (no_ipv6_route_ifname_tag_label, - no_ipv6_route_ifname_tag_label_cmd, - "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE tag (1-4294967295) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, - argv[5]->arg, NULL, argv[7]->arg, NULL, NULL, - argv[9]->arg); -} - -DEFUN (no_ipv6_route_pref_label, - no_ipv6_route_pref_label_cmd, - "no ipv6 route X:X::X:X/M (1-255) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, NULL, - NULL, NULL, argv[5]->arg, NULL, argv[7]->arg); -} - -DEFUN (no_ipv6_route_pref_tag_label, - no_ipv6_route_pref_tag_label_cmd, - "no ipv6 route X:X::X:X/M tag (1-4294967295) (1-255) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, NULL, - NULL, argv[6]->arg, argv[7]->arg, NULL, - argv[9]->arg); -} - -DEFUN (no_ipv6_route_ifname_pref_label, - no_ipv6_route_ifname_pref_label_cmd, - "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (1-255) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, - argv[5]->arg, NULL, NULL, argv[6]->arg, NULL, - argv[8]->arg); -} - -DEFUN (no_ipv6_route_ifname_pref_tag_label, - no_ipv6_route_ifname_pref_tag_label_cmd, - "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE tag (1-4294967295) (1-255) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, - argv[5]->arg, NULL, argv[7]->arg, argv[8]->arg, - NULL, argv[10]->arg); -} - /* MPLS LSP configuration write function. */ static int zebra_mpls_config(struct vty *vty) { @@ -1024,44 +460,11 @@ void zebra_mpls_vty_init(void) install_node(&mpls_node, zebra_mpls_config); - install_element(CONFIG_NODE, &ip_route_label_cmd); - install_element(CONFIG_NODE, &ip_route_tag_label_cmd); - install_element(CONFIG_NODE, &ip_route_mask_label_cmd); - install_element(CONFIG_NODE, &ip_route_mask_tag_label_cmd); - install_element(CONFIG_NODE, &no_ip_route_label_cmd); - install_element(CONFIG_NODE, &no_ip_route_tag_label_cmd); - install_element(CONFIG_NODE, &no_ip_route_mask_label_cmd); - install_element(CONFIG_NODE, &no_ip_route_mask_tag_label_cmd); - install_element(CONFIG_NODE, &ip_route_distance_label_cmd); - install_element(CONFIG_NODE, &ip_route_tag_distance_label_cmd); - install_element(CONFIG_NODE, &ip_route_mask_distance_label_cmd); - install_element(CONFIG_NODE, &ip_route_mask_tag_distance_label_cmd); - install_element(CONFIG_NODE, &no_ip_route_distance_label_cmd); - install_element(CONFIG_NODE, &no_ip_route_tag_distance_label_cmd); - install_element(CONFIG_NODE, &no_ip_route_mask_distance_label_cmd); - install_element(CONFIG_NODE, &no_ip_route_mask_tag_distance_label_cmd); - - install_element(CONFIG_NODE, &ipv6_route_label_cmd); - install_element(CONFIG_NODE, &ipv6_route_ifname_label_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_label_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_ifname_label_cmd); - install_element(CONFIG_NODE, &ipv6_route_pref_label_cmd); - install_element(CONFIG_NODE, &ipv6_route_ifname_pref_label_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_pref_label_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_ifname_pref_label_cmd); - install_element(CONFIG_NODE, &ipv6_route_tag_label_cmd); - install_element(CONFIG_NODE, &ipv6_route_ifname_tag_label_cmd); - install_element(CONFIG_NODE, &ipv6_route_pref_tag_label_cmd); - install_element(CONFIG_NODE, &ipv6_route_ifname_pref_tag_label_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_tag_label_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_ifname_tag_label_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_pref_tag_label_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_ifname_pref_tag_label_cmd); - install_element(CONFIG_NODE, &mpls_transit_lsp_cmd); install_element(CONFIG_NODE, &no_mpls_transit_lsp_cmd); install_element(CONFIG_NODE, &no_mpls_transit_lsp_out_label_cmd); install_element(CONFIG_NODE, &no_mpls_transit_lsp_all_cmd); + install_element(CONFIG_NODE, &mpls_label_bind_cmd); install_element(CONFIG_NODE, &no_mpls_label_bind_cmd); diff --git a/zebra/zebra_static.h b/zebra/zebra_static.h index 91ac0a33c..dff799a9a 100644 --- a/zebra/zebra_static.h +++ b/zebra/zebra_static.h @@ -100,16 +100,4 @@ extern int static_delete_route(afi_t, safi_t safi, u_char type, struct zebra_vrf *zvrf, struct static_nh_label *snh_label); -int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, - const char *dest_str, const char *mask_str, - const char *gate_str, const char *flag_str, - const char *tag_str, const char *distance_str, - const char *vrf_id_str, const char *label_str); - -int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, - const char *src_str, const char *gate_str, - const char *ifname, const char *flag_str, - const char *tag_str, const char *distance_str, - const char *vrf_id_str, const char *label_str); - #endif diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 7e492ad6b..941090171 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -61,11 +61,11 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, #define CMD_VNI_RANGE "(1-16777215)" /* General function for static route. */ -int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, - const char *dest_str, const char *mask_str, - const char *gate_str, const char *flag_str, - const char *tag_str, const char *distance_str, - const char *vrf_id_str, const char *label_str) +static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, + const char *dest_str, const char *mask_str, + const char *gate_str, const char *flag_str, + const char *tag_str, const char *distance_str, + const char *vrf_id_str, const char *label_str) { int ret; u_char distance; @@ -362,7 +362,11 @@ static void zebra_vty_ip_route_tdv_helper(int argc, struct cmd_token *argv[], char **distance, char **vrf, char **labels) { + *tag = NULL; *distance = NULL; + *vrf = NULL; + if (labels) + *labels = NULL; while (idx_curr < argc) { if (strmatch(argv[idx_curr]->text, "tag")) { if (tag) @@ -389,7 +393,7 @@ static void zebra_vty_ip_route_tdv_helper(int argc, struct cmd_token *argv[], /* Static route configuration. */ DEFUN (ip_route, ip_route_cmd, - "ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", IP_STR "Establish static routes\n" "IP destination prefix (e.g. 10.0.0.0/8)\n" @@ -399,21 +403,21 @@ DEFUN (ip_route, "Set tag for this route\n" "Tag value\n" "Distance value for this route\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { int idx_ipv4_prefixlen = 2; int idx_ipv4_ifname_null = 3; int idx_curr = 4; - char *tag, *distance, *vrf; + char *tag, *distance, *vrf, *label; - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); + &vrf, &label); return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[idx_ipv4_prefixlen]->arg, NULL, argv[idx_ipv4_ifname_null]->arg, NULL, tag, - distance, vrf, NULL); + distance, vrf, label); } DEFUN (ip_route_flags, @@ -434,7 +438,6 @@ DEFUN (ip_route_flags, int idx_curr = 4; char *tag, *distance, *vrf; - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); @@ -446,7 +449,7 @@ DEFUN (ip_route_flags, /* Mask as A.B.C.D format. */ DEFUN_HIDDEN (ip_route_mask, ip_route_mask_cmd, - "ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", IP_STR "Establish static routes\n" "IP destination prefix\n" @@ -457,22 +460,22 @@ DEFUN_HIDDEN (ip_route_mask, "Set tag for this route\n" "Tag value\n" "Distance value for this route\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { int idx_ipv4 = 2; int idx_ipv4_2 = 3; int idx_ipv4_ifname_null = 4; int idx_curr = 5; - char *tag, *distance, *vrf; + char *tag, *distance, *vrf, *label; - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); + &vrf, &label); return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, argv[idx_ipv4_ifname_null]->arg, NULL, tag, - distance, vrf, NULL); + distance, vrf, label); } DEFUN_HIDDEN (ip_route_mask_flags, @@ -495,7 +498,6 @@ DEFUN_HIDDEN (ip_route_mask_flags, int idx_curr = 5; char *tag, *distance, *vrf; - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); @@ -507,7 +509,7 @@ DEFUN_HIDDEN (ip_route_mask_flags, DEFUN (no_ip_route, no_ip_route_cmd, - "no ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "no ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", NO_STR IP_STR "Establish static routes\n" @@ -518,21 +520,21 @@ DEFUN (no_ip_route, "Tag of this route\n" "Tag value\n" "Distance value for this route\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { int idx_ipv4_prefixlen = 3; int idx_ipv4_ifname_null = 4; int idx_curr = 5; - char *tag, *distance, *vrf; + char *tag, *distance, *vrf, *label; - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); + &vrf, &label); return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4_prefixlen]->arg, NULL, argv[idx_ipv4_ifname_null]->arg, NULL, tag, - distance, vrf, NULL); + distance, vrf, label); } DEFUN (no_ip_route_flags, @@ -553,7 +555,6 @@ DEFUN (no_ip_route_flags, int idx_curr = 5; char *tag, *distance, *vrf; - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); @@ -564,7 +565,7 @@ DEFUN (no_ip_route_flags, DEFUN_HIDDEN (no_ip_route_mask, no_ip_route_mask_cmd, - "no ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "no ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", NO_STR IP_STR "Establish static routes\n" @@ -576,22 +577,22 @@ DEFUN_HIDDEN (no_ip_route_mask, "Tag of this route\n" "Tag value\n" "Distance value for this route\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { int idx_ipv4 = 3; int idx_ipv4_2 = 4; int idx_ipv4_ifname_null = 5; int idx_curr = 6; - char *tag, *distance, *vrf; + char *tag, *distance, *vrf, *label; - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); + &vrf, &label); return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, argv[idx_ipv4_ifname_null]->arg, NULL, tag, - distance, vrf, NULL); + distance, vrf, label); } DEFUN_HIDDEN (no_ip_route_mask_flags, @@ -614,7 +615,6 @@ DEFUN_HIDDEN (no_ip_route_mask_flags, int idx_curr = 6; char *tag, *distance, *vrf; - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); @@ -1997,11 +1997,11 @@ static int static_config(struct vty *vty, afi_t afi, safi_t safi, } /* General fucntion for IPv6 static route. */ -int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, - const char *src_str, const char *gate_str, - const char *ifname, const char *flag_str, - const char *tag_str, const char *distance_str, - const char *vrf_id_str, const char *label_str) +static int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, + const char *src_str, const char *gate_str, + const char *ifname, const char *flag_str, + const char *tag_str, const char *distance_str, + const char *vrf_id_str, const char *label_str) { int ret; u_char distance; @@ -2185,7 +2185,7 @@ int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, DEFUN (ipv6_route, ipv6_route_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", IP_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" @@ -2197,12 +2197,13 @@ DEFUN (ipv6_route, "Set tag for this route\n" "Tag value\n" "Distance value for this prefix\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { int idx_ipv6_prefixlen = 2; int idx_ipv6_ifname; int idx_curr; - char *src, *tag, *distance, *vrf; + char *src, *tag, *distance, *vrf, *label; if (strmatch(argv[3]->text, "from")) { src = argv[4]->arg; @@ -2214,13 +2215,12 @@ DEFUN (ipv6_route, idx_curr = 4; } - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); + &vrf, &label); return static_ipv6_func(vty, 1, argv[idx_ipv6_prefixlen]->arg, src, argv[idx_ipv6_ifname]->arg, NULL, NULL, tag, - distance, vrf, NULL); + distance, vrf, label); } DEFUN (ipv6_route_flags, @@ -2253,7 +2253,6 @@ DEFUN (ipv6_route_flags, idx_curr = 4; } - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); @@ -2264,7 +2263,7 @@ DEFUN (ipv6_route_flags, DEFUN (ipv6_route_ifname, ipv6_route_ifname_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", IP_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" @@ -2275,13 +2274,14 @@ DEFUN (ipv6_route_ifname, "Set tag for this route\n" "Tag value\n" "Distance value for this prefix\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { int idx_ipv6_prefixlen = 2; int idx_ipv6 = 3; int idx_interface = 4; int idx_curr = 5; - char *src, *tag, *distance, *vrf; + char *src, *tag, *distance, *vrf, *label; if (strmatch(argv[3]->text, "from")) { src = argv[4]->arg; @@ -2295,18 +2295,17 @@ DEFUN (ipv6_route_ifname, idx_curr = 5; } - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); + &vrf, &label); return static_ipv6_func(vty, 1, argv[idx_ipv6_prefixlen]->arg, src, argv[idx_ipv6]->arg, argv[idx_interface]->arg, - NULL, tag, distance, vrf, NULL); + NULL, tag, distance, vrf, label); } DEFUN (no_ipv6_route, no_ipv6_route_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", NO_STR IP_STR "Establish static routes\n" @@ -2319,12 +2318,13 @@ DEFUN (no_ipv6_route, "Set tag for this route\n" "Tag value\n" "Distance value for this prefix\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { int idx_ipv6_prefixlen = 3; int idx_ipv6_ifname; int idx_curr; - char *src, *tag, *distance, *vrf; + char *src, *tag, *distance, *vrf, *label; if (strmatch(argv[4]->text, "from")) { src = argv[5]->arg; @@ -2336,13 +2336,12 @@ DEFUN (no_ipv6_route, idx_curr = 5; } - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); + &vrf, &label); return static_ipv6_func(vty, 0, argv[idx_ipv6_prefixlen]->arg, src, argv[idx_ipv6_ifname]->arg, NULL, NULL, tag, - distance, vrf, NULL); + distance, vrf, label); } DEFUN (no_ipv6_route_flags, @@ -2376,7 +2375,6 @@ DEFUN (no_ipv6_route_flags, idx_curr = 5; } - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); @@ -2387,7 +2385,7 @@ DEFUN (no_ipv6_route_flags, DEFUN (no_ipv6_route_ifname, no_ipv6_route_ifname_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", NO_STR IP_STR "Establish static routes\n" @@ -2399,13 +2397,14 @@ DEFUN (no_ipv6_route_ifname, "Set tag for this route\n" "Tag value\n" "Distance value for this prefix\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { int idx_ipv6_prefixlen = 3; int idx_ipv6; int idx_interface; int idx_curr; - char *src, *tag, *distance, *vrf; + char *src, *tag, *distance, *vrf, *label; if (strmatch(argv[4]->text, "from")) { src = argv[5]->arg; @@ -2419,13 +2418,12 @@ DEFUN (no_ipv6_route_ifname, idx_curr = 6; } - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); + &vrf, &label); return static_ipv6_func(vty, 0, argv[idx_ipv6_prefixlen]->arg, src, argv[idx_ipv6]->arg, argv[idx_interface]->arg, - NULL, tag, distance, vrf, NULL); + NULL, tag, distance, vrf, label); } DEFUN (show_ipv6_route, From 33df4bb219d6c5b972877434c57fa85543dc8a5e Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 27 Jul 2017 18:01:12 -0300 Subject: [PATCH 4/8] zebra: accept static v6 routes with non-existent nexthop interfaces We don't need to enforce that the interface exists because the route can be activated later once the interface becomes available. We already do this for IPv4 routes and IPv6 routes with both a nexthop address and a nexthop interface. Signed-off-by: Renato Westphal --- zebra/zebra_vty.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 941090171..a79d8d71b 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -2151,9 +2151,9 @@ static int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, if (!ifp) { vty_out(vty, "%% Malformed Interface name %s\n", ifname); - return CMD_WARNING_CONFIG_FAILED; - } - ifindex = ifp->ifindex; + ifindex = IFINDEX_DELETED; + } else + ifindex = ifp->ifindex; } else { if (ret == 1) { type = STATIC_IPV6_GATEWAY; From c6cef20ba9d317792a9742c3efb728f4aa766dad Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 27 Jul 2017 15:52:52 -0300 Subject: [PATCH 5/8] zebra: refactor zebra_static_ipv4() and static_ipv6_func() This is a preliminary step to join both functions into one later. The main idea here is to make these functions have separate arguments for the nexthop address and the nexthop interface, and adjust the call sites appropriately. Having an argument that could be a nexthop address OR a nexthop interface was making the code very hard to follow. With this simplification, a lot of code duplication was removed and now both functions look very similar. Signed-off-by: Renato Westphal --- zebra/zebra_vty.c | 244 ++++++++++++++++++++++++---------------------- 1 file changed, 126 insertions(+), 118 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index a79d8d71b..c5cdad890 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -63,21 +63,22 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, /* General function for static route. */ static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, const char *dest_str, const char *mask_str, - const char *gate_str, const char *flag_str, - const char *tag_str, const char *distance_str, - const char *vrf_id_str, const char *label_str) + const char *gate_str, const char *ifname, + const char *flag_str, const char *tag_str, + const char *distance_str, const char *vrf_id_str, + const char *label_str) { int ret; u_char distance; struct prefix p; struct in_addr gate; + struct in_addr *gatep = NULL; struct in_addr mask; u_char flag = 0; route_tag_t tag = 0; struct zebra_vrf *zvrf = NULL; unsigned int ifindex = 0; - const char *ifname = NULL; - u_char type = STATIC_BLACKHOLE; + u_char type; struct static_nh_label snh_label; memset(&snh_label, 0, sizeof(struct static_nh_label)); @@ -149,22 +150,15 @@ static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, } /* Null0 static route. */ - if ((gate_str != NULL) - && (strncasecmp(gate_str, "Null0", strlen(gate_str)) == 0)) { + if ((ifname != NULL) + && (strncasecmp(ifname, "Null0", strlen(ifname)) == 0)) { if (flag_str) { vty_out(vty, "%% can not have flag %s with Null0\n", flag_str); return CMD_WARNING_CONFIG_FAILED; } - if (add_cmd) - static_add_route(AFI_IP, safi, type, &p, NULL, NULL, - ifindex, ifname, ZEBRA_FLAG_BLACKHOLE, - tag, distance, zvrf, &snh_label); - else - static_delete_route(AFI_IP, safi, type, &p, NULL, NULL, - ifindex, tag, distance, zvrf, - &snh_label); - return CMD_SUCCESS; + SET_FLAG(flag, ZEBRA_FLAG_BLACKHOLE); + ifname = NULL; } /* Route flags */ @@ -184,44 +178,44 @@ static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, } } - if (gate_str == NULL) { - if (add_cmd) - static_add_route(AFI_IP, safi, type, &p, NULL, NULL, - ifindex, ifname, flag, tag, distance, - zvrf, &snh_label); - else - static_delete_route(AFI_IP, safi, type, &p, NULL, NULL, - ifindex, tag, distance, zvrf, - &snh_label); - - return CMD_SUCCESS; + if (gate_str) { + if (inet_pton(AF_INET, gate_str, &gate) != 1) { + vty_out(vty, "%% Malformed nexthop address %s\n", + gate_str); + return CMD_WARNING_CONFIG_FAILED; + } + gatep = &gate; } - /* When gateway is A.B.C.D format, gate is treated as nexthop - address other case gate is treated as interface name. */ - ret = inet_aton(gate_str, &gate); - if (!ret) { - struct interface *ifp = - if_lookup_by_name(gate_str, zvrf_id(zvrf)); + if (ifname) { + struct interface *ifp; + ifp = if_lookup_by_name(ifname, zvrf_id(zvrf)); if (!ifp) { - vty_out(vty, "%% Unknown interface: %s\n", gate_str); + vty_out(vty, "%% Malformed Interface name %s\n", + ifname); ifindex = IFINDEX_DELETED; } else ifindex = ifp->ifindex; - ifname = gate_str; + } + + if (gate_str == NULL && ifname == NULL) + type = STATIC_BLACKHOLE; + else if (gate_str && ifname) + /* TODO: not implemented yet */ + return CMD_WARNING_CONFIG_FAILED; + else if (ifname) type = STATIC_IFINDEX; - } else + else type = STATIC_IPV4_GATEWAY; if (add_cmd) static_add_route(AFI_IP, safi, type, &p, NULL, - ifindex ? NULL : (union g_addr *)&gate, - ifindex, ifname, flag, tag, distance, zvrf, - &snh_label); + (union g_addr *)gatep, ifindex, ifname, flag, + tag, distance, zvrf, &snh_label); else static_delete_route(AFI_IP, safi, type, &p, NULL, - ifindex ? NULL : (union g_addr *)&gate, - ifindex, tag, distance, zvrf, &snh_label); + (union g_addr *)gatep, ifindex, tag, + distance, zvrf, &snh_label); return CMD_SUCCESS; } @@ -238,11 +232,17 @@ DEFUN (ip_mroute_dist, "Distance\n") { char *destprefix = argv[2]->arg; - char *nexthop = argv[3]->arg; + char *gate = NULL; + char *ifname = NULL; char *distance = (argc == 5) ? argv[4]->arg : NULL; + if (argv[3]->type == IPV4_TKN) + gate = argv[3]->arg; + else + ifname = argv[3]->arg; + return zebra_static_ipv4(vty, SAFI_MULTICAST, 1, destprefix, NULL, - nexthop, NULL, NULL, distance, NULL, NULL); + gate, ifname, NULL, NULL, distance, NULL, NULL); } DEFUN (no_ip_mroute_dist, @@ -257,11 +257,17 @@ DEFUN (no_ip_mroute_dist, "Distance\n") { char *destprefix = argv[3]->arg; - char *nexthop = argv[4]->arg; + char *gate = NULL; + char *ifname = NULL; char *distance = (argc == 6) ? argv[5]->arg : NULL; + if (argv[4]->type == IPV4_TKN) + gate = argv[4]->arg; + else + ifname = argv[4]->arg; + return zebra_static_ipv4(vty, SAFI_MULTICAST, 0, destprefix, NULL, - nexthop, NULL, NULL, distance, NULL, NULL); + gate, ifname, NULL, NULL, distance, NULL, NULL); } DEFUN (ip_multicast_mode, @@ -407,17 +413,22 @@ DEFUN (ip_route, MPLS_LABEL_HELPSTR) { int idx_ipv4_prefixlen = 2; - int idx_ipv4_ifname_null = 3; int idx_curr = 4; + char *gate = NULL; + char *ifname = NULL; char *tag, *distance, *vrf, *label; + if (argv[3]->type == IPV4_TKN) + gate = argv[3]->arg; + else + ifname = argv[3]->arg; + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); return zebra_static_ipv4(vty, SAFI_UNICAST, 1, - argv[idx_ipv4_prefixlen]->arg, NULL, - argv[idx_ipv4_ifname_null]->arg, NULL, tag, - distance, vrf, label); + argv[idx_ipv4_prefixlen]->arg, NULL, gate, + ifname, NULL, tag, distance, vrf, label); } DEFUN (ip_route_flags, @@ -443,7 +454,7 @@ DEFUN (ip_route_flags, return zebra_static_ipv4( vty, SAFI_UNICAST, 1, argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - argv[idx_reject_blackhole]->arg, tag, distance, vrf, NULL); + NULL, argv[idx_reject_blackhole]->arg, tag, distance, vrf, NULL); } /* Mask as A.B.C.D format. */ @@ -465,17 +476,22 @@ DEFUN_HIDDEN (ip_route_mask, { int idx_ipv4 = 2; int idx_ipv4_2 = 3; - int idx_ipv4_ifname_null = 4; int idx_curr = 5; + char *gate = NULL; + char *ifname = NULL; char *tag, *distance, *vrf, *label; + if (argv[4]->type == IPV4_TKN) + gate = argv[4]->arg; + else + ifname = argv[4]->arg; + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, - argv[idx_ipv4_ifname_null]->arg, NULL, tag, - distance, vrf, label); + gate, ifname, NULL, tag, distance, vrf, label); } DEFUN_HIDDEN (ip_route_mask_flags, @@ -502,7 +518,7 @@ DEFUN_HIDDEN (ip_route_mask_flags, &vrf, NULL); return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, NULL, + argv[idx_ipv4_2]->arg, NULL, NULL, argv[idx_reject_blackhole]->arg, tag, distance, vrf, NULL); } @@ -524,17 +540,22 @@ DEFUN (no_ip_route, MPLS_LABEL_HELPSTR) { int idx_ipv4_prefixlen = 3; - int idx_ipv4_ifname_null = 4; int idx_curr = 5; + char *gate = NULL; + char *ifname = NULL; char *tag, *distance, *vrf, *label; + if (argv[4]->type == IPV4_TKN) + gate = argv[4]->arg; + else + ifname = argv[4]->arg; + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4_prefixlen]->arg, NULL, - argv[idx_ipv4_ifname_null]->arg, NULL, tag, - distance, vrf, label); + gate, ifname, NULL, tag, distance, vrf, label); } DEFUN (no_ip_route_flags, @@ -560,7 +581,7 @@ DEFUN (no_ip_route_flags, return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - NULL, tag, distance, vrf, NULL); + NULL, NULL, tag, distance, vrf, NULL); } DEFUN_HIDDEN (no_ip_route_mask, @@ -582,17 +603,22 @@ DEFUN_HIDDEN (no_ip_route_mask, { int idx_ipv4 = 3; int idx_ipv4_2 = 4; - int idx_ipv4_ifname_null = 5; int idx_curr = 6; + char *gate = NULL; + char *ifname = NULL; char *tag, *distance, *vrf, *label; + if (argv[5]->type == IPV4_TKN) + gate = argv[5]->arg; + else + ifname = argv[5]->arg; + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, - argv[idx_ipv4_ifname_null]->arg, NULL, tag, - distance, vrf, label); + gate, ifname, NULL, tag, distance, vrf, label); } DEFUN_HIDDEN (no_ip_route_mask_flags, @@ -619,7 +645,7 @@ DEFUN_HIDDEN (no_ip_route_mask_flags, &vrf, NULL); return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, NULL, NULL, tag, + argv[idx_ipv4_2]->arg, NULL, NULL, NULL, tag, distance, vrf, NULL); } @@ -2009,11 +2035,10 @@ static int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, struct prefix_ipv6 *src_p = NULL; struct in6_addr *gate = NULL; struct in6_addr gate_addr; - u_char type = STATIC_BLACKHOLE; + u_char type; u_char flag = 0; route_tag_t tag = 0; unsigned int ifindex = 0; - struct interface *ifp = NULL; struct zebra_vrf *zvrf; struct static_nh_label snh_label; @@ -2085,23 +2110,15 @@ static int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, } /* Null0 static route. */ - if ((gate_str != NULL) - && (strncasecmp(gate_str, "Null0", strlen(gate_str)) == 0)) { + if ((ifname != NULL) + && (strncasecmp(ifname, "Null0", strlen(ifname)) == 0)) { if (flag_str) { vty_out(vty, "%% can not have flag %s with Null0\n", flag_str); return CMD_WARNING_CONFIG_FAILED; } - if (add_cmd) - static_add_route(AFI_IP6, SAFI_UNICAST, type, &p, src_p, - NULL, ifindex, ifname, - ZEBRA_FLAG_BLACKHOLE, tag, distance, - zvrf, &snh_label); - else - static_delete_route(AFI_IP6, SAFI_UNICAST, type, &p, - src_p, NULL, ifindex, tag, distance, - zvrf, &snh_label); - return CMD_SUCCESS; + SET_FLAG(flag, ZEBRA_FLAG_BLACKHOLE); + ifname = NULL; } /* Route flags */ @@ -2121,32 +2138,17 @@ static int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, } } - if (gate_str == NULL) { - if (add_cmd) - static_add_route(AFI_IP6, SAFI_UNICAST, type, &p, src_p, - NULL, ifindex, ifname, flag, tag, - distance, zvrf, &snh_label); - else - static_delete_route(AFI_IP6, SAFI_UNICAST, type, &p, - src_p, NULL, ifindex, tag, distance, - zvrf, &snh_label); - - return CMD_SUCCESS; - } - - /* When gateway is valid IPv6 addrees, then gate is treated as - nexthop address other case gate is treated as interface name. */ - ret = inet_pton(AF_INET6, gate_str, &gate_addr); - - if (ifname) { - /* When ifname is specified. It must be come with gateway - address. */ - if (ret != 1) { - vty_out(vty, "%% Malformed address\n"); + if (gate_str) { + if (inet_pton(AF_INET6, gate_str, &gate_addr) != 1) { + vty_out(vty, "%% Malformed nexthop address %s\n", + gate_str); return CMD_WARNING_CONFIG_FAILED; } - type = STATIC_IPV6_GATEWAY_IFINDEX; gate = &gate_addr; + } + + if (ifname) { + struct interface *ifp; ifp = if_lookup_by_name(ifname, zvrf_id(zvrf)); if (!ifp) { vty_out(vty, "%% Malformed Interface name %s\n", @@ -2154,23 +2156,17 @@ static int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, ifindex = IFINDEX_DELETED; } else ifindex = ifp->ifindex; - } else { - if (ret == 1) { - type = STATIC_IPV6_GATEWAY; - gate = &gate_addr; - } else { - type = STATIC_IFINDEX; - ifp = if_lookup_by_name(gate_str, zvrf_id(zvrf)); - if (!ifp) { - vty_out(vty, "%% Malformed Interface name %s\n", - gate_str); - ifindex = IFINDEX_DELETED; - } else - ifindex = ifp->ifindex; - ifname = gate_str; - } } + if (gate_str == NULL && ifname == NULL) + type = STATIC_BLACKHOLE; + else if (gate_str && ifname) + type = STATIC_IPV6_GATEWAY_IFINDEX; + else if (ifname) + type = STATIC_IFINDEX; + else + type = STATIC_IPV6_GATEWAY; + if (add_cmd) static_add_route(AFI_IP6, SAFI_UNICAST, type, &p, src_p, (union g_addr *)gate, ifindex, ifname, flag, @@ -2203,6 +2199,8 @@ DEFUN (ipv6_route, int idx_ipv6_prefixlen = 2; int idx_ipv6_ifname; int idx_curr; + char *gate = NULL; + char *ifname = NULL; char *src, *tag, *distance, *vrf, *label; if (strmatch(argv[3]->text, "from")) { @@ -2215,12 +2213,16 @@ DEFUN (ipv6_route, idx_curr = 4; } + if (argv[idx_ipv6_ifname]->type == IPV6_TKN) + gate = argv[idx_ipv6_ifname]->arg; + else + ifname = argv[idx_ipv6_ifname]->arg; + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); return static_ipv6_func(vty, 1, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6_ifname]->arg, NULL, NULL, tag, - distance, vrf, label); + gate, ifname, NULL, tag, distance, vrf, label); } DEFUN (ipv6_route_flags, @@ -2324,6 +2326,8 @@ DEFUN (no_ipv6_route, int idx_ipv6_prefixlen = 3; int idx_ipv6_ifname; int idx_curr; + char *gate = NULL; + char *ifname = NULL; char *src, *tag, *distance, *vrf, *label; if (strmatch(argv[4]->text, "from")) { @@ -2336,12 +2340,16 @@ DEFUN (no_ipv6_route, idx_curr = 5; } + if (argv[idx_ipv6_ifname]->type == IPV6_TKN) + gate = argv[idx_ipv6_ifname]->arg; + else + ifname = argv[idx_ipv6_ifname]->arg; + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); return static_ipv6_func(vty, 0, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6_ifname]->arg, NULL, NULL, tag, - distance, vrf, label); + gate, ifname, NULL, tag, distance, vrf, label); } DEFUN (no_ipv6_route_flags, From 599186ad970b50d689f719dbb8cf527df0089d01 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 27 Jul 2017 18:57:37 -0300 Subject: [PATCH 6/8] zebra: allow fully specified static ipv4 routes Fully specified routes are useful when you need to ensure that the nexthop address is reachable through the specified interface. Addresses Issue #641. Signed-off-by: Renato Westphal --- zebra/zebra_static.c | 27 +++++++-- zebra/zebra_static.h | 6 +- zebra/zebra_vty.c | 140 ++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 156 insertions(+), 17 deletions(-) diff --git a/zebra/zebra_static.c b/zebra/zebra_static.c index ae3239516..6cebae997 100644 --- a/zebra/zebra_static.c +++ b/zebra/zebra_static.c @@ -81,6 +81,10 @@ void static_install_route(afi_t afi, safi_t safi, struct prefix *p, nh_p.u.prefix4 = si->addr.ipv4; zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn); break; + case STATIC_IPV4_GATEWAY_IFINDEX: + nexthop = route_entry_nexthop_ipv4_ifindex_add( + re, &si->addr.ipv4, NULL, si->ifindex); + break; case STATIC_IFINDEX: nexthop = route_entry_nexthop_ifindex_add(re, si->ifindex); @@ -152,6 +156,10 @@ void static_install_route(afi_t afi, safi_t safi, struct prefix *p, nh_p.u.prefix4 = si->addr.ipv4; zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn); break; + case STATIC_IPV4_GATEWAY_IFINDEX: + nexthop = route_entry_nexthop_ipv4_ifindex_add( + re, &si->addr.ipv4, NULL, si->ifindex); + break; case STATIC_IFINDEX: nexthop = route_entry_nexthop_ifindex_add(re, si->ifindex); @@ -216,6 +224,11 @@ static int static_nexthop_same(struct nexthop *nexthop, struct static_route *si) && si->type == STATIC_IPV4_GATEWAY && IPV4_ADDR_SAME(&nexthop->gate.ipv4, &si->addr.ipv4)) return 1; + else if (nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX + && si->type == STATIC_IPV4_GATEWAY_IFINDEX + && IPV4_ADDR_SAME(&nexthop->gate.ipv4, &si->addr.ipv4) + && nexthop->ifindex == si->ifindex) + return 1; else if (nexthop->type == NEXTHOP_TYPE_IFINDEX && si->type == STATIC_IFINDEX && nexthop->ifindex == si->ifindex) @@ -361,12 +374,17 @@ int static_add_route(afi_t afi, safi_t safi, u_char type, struct prefix *p, if (!stable) return -1; - if (!gate && (type == STATIC_IPV4_GATEWAY || type == STATIC_IPV6_GATEWAY - || type == STATIC_IPV6_GATEWAY_IFINDEX)) + if (!gate + && (type == STATIC_IPV4_GATEWAY + || type == STATIC_IPV4_GATEWAY_IFINDEX + || type == STATIC_IPV6_GATEWAY + || type == STATIC_IPV6_GATEWAY_IFINDEX)) return -1; if (!ifindex - && (type == STATIC_IFINDEX || type == STATIC_IPV6_GATEWAY_IFINDEX)) + && (type == STATIC_IFINDEX + || type == STATIC_IPV4_GATEWAY_IFINDEX + || type == STATIC_IPV6_GATEWAY_IFINDEX)) return -1; /* Lookup static route prefix. */ @@ -411,11 +429,10 @@ int static_add_route(afi_t afi, safi_t safi, u_char type, struct prefix *p, switch (type) { case STATIC_IPV4_GATEWAY: + case STATIC_IPV4_GATEWAY_IFINDEX: si->addr.ipv4 = gate->ipv4; break; case STATIC_IPV6_GATEWAY: - si->addr.ipv6 = gate->ipv6; - break; case STATIC_IPV6_GATEWAY_IFINDEX: si->addr.ipv6 = gate->ipv6; break; diff --git a/zebra/zebra_static.h b/zebra/zebra_static.h index dff799a9a..885774895 100644 --- a/zebra/zebra_static.h +++ b/zebra/zebra_static.h @@ -32,6 +32,7 @@ struct static_nh_label { typedef enum { STATIC_IFINDEX, STATIC_IPV4_GATEWAY, + STATIC_IPV4_GATEWAY_IFINDEX, STATIC_BLACKHOLE, STATIC_IPV6_GATEWAY, STATIC_IPV6_GATEWAY_IFINDEX, @@ -57,11 +58,6 @@ struct static_route { /* * Nexthop value. - * - * Under IPv4 addr and ifindex are - * used independentyly. - * STATIC_IPV4_GATEWAY uses addr - * STATIC_IFINDEX uses ifindex */ union g_addr addr; ifindex_t ifindex; diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index c5cdad890..96f922169 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -201,8 +201,7 @@ static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, if (gate_str == NULL && ifname == NULL) type = STATIC_BLACKHOLE; else if (gate_str && ifname) - /* TODO: not implemented yet */ - return CMD_WARNING_CONFIG_FAILED; + type = STATIC_IPV4_GATEWAY_IFINDEX; else if (ifname) type = STATIC_IFINDEX; else @@ -457,6 +456,34 @@ DEFUN (ip_route_flags, NULL, argv[idx_reject_blackhole]->arg, tag, distance, vrf, NULL); } +DEFUN (ip_route_ifname, + ip_route_ifname_cmd, + "ip route A.B.C.D/M A.B.C.D INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", + IP_STR + "Establish static routes\n" + "IP destination prefix (e.g. 10.0.0.0/8)\n" + "IP gateway address\n" + "IP gateway interface name\n" + "Set tag for this route\n" + "Tag value\n" + "Distance value for this route\n" + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) +{ + int idx_ipv4_prefixlen = 2; + int idx_curr = 5; + char *gate = argv[3]->arg; + char *ifname = argv[4]->arg; + char *tag, *distance, *vrf, *label; + + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, + &vrf, &label); + + return zebra_static_ipv4(vty, SAFI_UNICAST, 1, + argv[idx_ipv4_prefixlen]->arg, NULL, gate, + ifname, NULL, tag, distance, vrf, label); +} + /* Mask as A.B.C.D format. */ DEFUN_HIDDEN (ip_route_mask, ip_route_mask_cmd, @@ -494,6 +521,36 @@ DEFUN_HIDDEN (ip_route_mask, gate, ifname, NULL, tag, distance, vrf, label); } +DEFUN_HIDDEN (ip_route_mask_ifname, + ip_route_mask_ifname_cmd, + "ip route A.B.C.D A.B.C.D A.B.C.D INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", + IP_STR + "Establish static routes\n" + "IP destination prefix\n" + "IP destination prefix mask\n" + "IP gateway address\n" + "IP gateway interface name\n" + "Set tag for this route\n" + "Tag value\n" + "Distance value for this route\n" + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) +{ + int idx_ipv4 = 2; + int idx_ipv4_2 = 3; + int idx_curr = 6; + char *gate = argv[4]->arg; + char *ifname = argv[5]->arg; + char *tag, *distance, *vrf, *label; + + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, + &vrf, &label); + + return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[idx_ipv4]->arg, + argv[idx_ipv4_2]->arg, + gate, ifname, NULL, tag, distance, vrf, label); +} + DEFUN_HIDDEN (ip_route_mask_flags, ip_route_mask_flags_cmd, "ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", @@ -558,6 +615,35 @@ DEFUN (no_ip_route, gate, ifname, NULL, tag, distance, vrf, label); } +DEFUN (no_ip_route_ifname, + no_ip_route_ifname_cmd, + "no ip route A.B.C.D/M A.B.C.D INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", + NO_STR + IP_STR + "Establish static routes\n" + "IP destination prefix (e.g. 10.0.0.0/8)\n" + "IP gateway address\n" + "IP gateway interface name\n" + "Tag of this route\n" + "Tag value\n" + "Distance value for this route\n" + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) +{ + int idx_ipv4_prefixlen = 3; + int idx_curr = 6; + char *gate = argv[4]->arg; + char *ifname = argv[5]->arg; + char *tag, *distance, *vrf, *label; + + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, + &vrf, &label); + + return zebra_static_ipv4(vty, SAFI_UNICAST, 0, + argv[idx_ipv4_prefixlen]->arg, NULL, + gate, ifname, NULL, tag, distance, vrf, label); +} + DEFUN (no_ip_route_flags, no_ip_route_flags_cmd, "no ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", @@ -621,6 +707,37 @@ DEFUN_HIDDEN (no_ip_route_mask, gate, ifname, NULL, tag, distance, vrf, label); } +DEFUN_HIDDEN (no_ip_route_mask_ifname, + no_ip_route_mask_ifname_cmd, + "no ip route A.B.C.D A.B.C.D A.B.C.D INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", + NO_STR + IP_STR + "Establish static routes\n" + "IP destination prefix\n" + "IP destination prefix mask\n" + "IP gateway address\n" + "IP gateway interface name\n" + "Tag of this route\n" + "Tag value\n" + "Distance value for this route\n" + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) +{ + int idx_ipv4 = 3; + int idx_ipv4_2 = 4; + int idx_curr = 7; + char *gate = argv[5]->arg; + char *ifname = argv[6]->arg; + char *tag, *distance, *vrf, *label; + + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, + &vrf, &label); + + return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4]->arg, + argv[idx_ipv4_2]->arg, + gate, ifname, NULL, tag, distance, vrf, label); +} + DEFUN_HIDDEN (no_ip_route_mask_flags, no_ip_route_mask_flags_cmd, "no ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", @@ -1970,6 +2087,14 @@ static int static_config(struct vty *vty, afi_t afi, safi_t safi, else vty_out(vty, " Null0"); break; + case STATIC_IPV4_GATEWAY_IFINDEX: + vty_out(vty, " %s %s", + inet_ntop(AF_INET, + &si->addr.ipv4, buf, + sizeof buf), + ifindex2ifname(si->ifindex, + si->vrf_id)); + break; case STATIC_IPV6_GATEWAY_IFINDEX: vty_out(vty, " %s %s", inet_ntop(AF_INET6, @@ -3288,11 +3413,17 @@ void zebra_vty_init(void) install_element(CONFIG_NODE, &ip_multicast_mode_cmd); install_element(CONFIG_NODE, &no_ip_multicast_mode_cmd); install_element(CONFIG_NODE, &ip_route_cmd); + install_element(CONFIG_NODE, &ip_route_ifname_cmd); install_element(CONFIG_NODE, &ip_route_flags_cmd); install_element(CONFIG_NODE, &ip_route_mask_cmd); + install_element(CONFIG_NODE, &ip_route_mask_ifname_cmd); install_element(CONFIG_NODE, &ip_route_mask_flags_cmd); install_element(CONFIG_NODE, &no_ip_route_cmd); + install_element(CONFIG_NODE, &no_ip_route_flags_cmd); + install_element(CONFIG_NODE, &no_ip_route_ifname_cmd); install_element(CONFIG_NODE, &no_ip_route_mask_cmd); + install_element(CONFIG_NODE, &no_ip_route_mask_flags_cmd); + install_element(CONFIG_NODE, &no_ip_route_mask_ifname_cmd); install_element(CONFIG_NODE, &ip_zebra_import_table_distance_cmd); install_element(CONFIG_NODE, &no_ip_zebra_import_table_cmd); @@ -3310,11 +3441,6 @@ void zebra_vty_init(void) install_element(VIEW_NODE, &show_ip_rpf_cmd); install_element(VIEW_NODE, &show_ip_rpf_addr_cmd); - /* Commands for VRF */ - - install_element(CONFIG_NODE, &no_ip_route_flags_cmd); - install_element(CONFIG_NODE, &no_ip_route_mask_flags_cmd); - install_element(VIEW_NODE, &show_ip_route_vrf_all_addr_cmd); install_element(VIEW_NODE, &show_ip_route_vrf_all_prefix_cmd); install_element(VIEW_NODE, &show_ip_route_vrf_all_summary_cmd); From 1d3f0eff598c4798ecf2efd486596e2ade78f6b3 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 27 Jul 2017 19:58:45 -0300 Subject: [PATCH 7/8] zebra: unify the ipv4/ipv6 static route functions Addresses Issue #655. Signed-off-by: Renato Westphal --- zebra/zebra_vty.c | 373 ++++++++++++++++------------------------------ 1 file changed, 129 insertions(+), 244 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 96f922169..446bcc49e 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -61,41 +61,59 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, #define CMD_VNI_RANGE "(1-16777215)" /* General function for static route. */ -static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, - const char *dest_str, const char *mask_str, - const char *gate_str, const char *ifname, - const char *flag_str, const char *tag_str, - const char *distance_str, const char *vrf_id_str, - const char *label_str) +static int zebra_static_route(struct vty *vty, afi_t afi, safi_t safi, + int add_cmd, const char *dest_str, + const char *mask_str, const char *src_str, + const char *gate_str, const char *ifname, + const char *flag_str, const char *tag_str, + const char *distance_str, const char *vrf_id_str, + const char *label_str) { int ret; u_char distance; - struct prefix p; - struct in_addr gate; - struct in_addr *gatep = NULL; + struct prefix p, src; + struct prefix_ipv6 *src_p = NULL; + union g_addr gate; + union g_addr *gatep = NULL; struct in_addr mask; u_char flag = 0; route_tag_t tag = 0; - struct zebra_vrf *zvrf = NULL; + struct zebra_vrf *zvrf; unsigned int ifindex = 0; u_char type; struct static_nh_label snh_label; - memset(&snh_label, 0, sizeof(struct static_nh_label)); ret = str2prefix(dest_str, &p); if (ret <= 0) { vty_out(vty, "%% Malformed address\n"); return CMD_WARNING_CONFIG_FAILED; } - /* Cisco like mask notation. */ - if (mask_str) { - ret = inet_aton(mask_str, &mask); - if (ret == 0) { - vty_out(vty, "%% Malformed address\n"); - return CMD_WARNING_CONFIG_FAILED; + switch (afi) { + case AFI_IP: + /* Cisco like mask notation. */ + if (mask_str) { + ret = inet_aton(mask_str, &mask); + if (ret == 0) { + vty_out(vty, "%% Malformed address\n"); + return CMD_WARNING_CONFIG_FAILED; + } + p.prefixlen = ip_masklen(mask); } - p.prefixlen = ip_masklen(mask); + break; + case AFI_IP6: + /* srcdest routing */ + if (src_str) { + ret = str2prefix(src_str, &src); + if (ret <= 0 || src.family != AF_INET6) { + vty_out(vty, "%% Malformed source address\n"); + return CMD_WARNING_CONFIG_FAILED; + } + src_p = (struct prefix_ipv6 *)&src; + } + break; + default: + break; } /* Apply mask for given prefix. */ @@ -120,6 +138,7 @@ static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, } /* Labels */ + memset(&snh_label, 0, sizeof(struct static_nh_label)); if (label_str) { if (!mpls_enabled) { vty_out(vty, @@ -179,7 +198,7 @@ static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, } if (gate_str) { - if (inet_pton(AF_INET, gate_str, &gate) != 1) { + if (inet_pton(afi2family(afi), gate_str, &gate) != 1) { vty_out(vty, "%% Malformed nexthop address %s\n", gate_str); return CMD_WARNING_CONFIG_FAILED; @@ -200,21 +219,26 @@ static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, if (gate_str == NULL && ifname == NULL) type = STATIC_BLACKHOLE; - else if (gate_str && ifname) - type = STATIC_IPV4_GATEWAY_IFINDEX; - else if (ifname) + else if (gate_str && ifname) { + if (afi == AFI_IP) + type = STATIC_IPV4_GATEWAY_IFINDEX; + else + type = STATIC_IPV6_GATEWAY_IFINDEX; + } else if (ifname) type = STATIC_IFINDEX; - else - type = STATIC_IPV4_GATEWAY; + else { + if (afi == AFI_IP) + type = STATIC_IPV4_GATEWAY; + else + type = STATIC_IPV6_GATEWAY; + } if (add_cmd) - static_add_route(AFI_IP, safi, type, &p, NULL, - (union g_addr *)gatep, ifindex, ifname, flag, - tag, distance, zvrf, &snh_label); + static_add_route(afi, safi, type, &p, src_p, gatep, ifindex, + ifname, flag, tag, distance, zvrf, &snh_label); else - static_delete_route(AFI_IP, safi, type, &p, NULL, - (union g_addr *)gatep, ifindex, tag, - distance, zvrf, &snh_label); + static_delete_route(afi, safi, type, &p, src_p, gatep, ifindex, + tag, distance, zvrf, &snh_label); return CMD_SUCCESS; } @@ -240,8 +264,9 @@ DEFUN (ip_mroute_dist, else ifname = argv[3]->arg; - return zebra_static_ipv4(vty, SAFI_MULTICAST, 1, destprefix, NULL, - gate, ifname, NULL, NULL, distance, NULL, NULL); + return zebra_static_route(vty, AFI_IP, SAFI_MULTICAST, 1, destprefix, + NULL, NULL, gate, ifname, NULL, NULL, distance, + NULL, NULL); } DEFUN (no_ip_mroute_dist, @@ -265,8 +290,9 @@ DEFUN (no_ip_mroute_dist, else ifname = argv[4]->arg; - return zebra_static_ipv4(vty, SAFI_MULTICAST, 0, destprefix, NULL, - gate, ifname, NULL, NULL, distance, NULL, NULL); + return zebra_static_route(vty, AFI_IP, SAFI_MULTICAST, 0, destprefix, + NULL, NULL, gate, ifname, NULL, NULL, distance, + NULL, NULL); } DEFUN (ip_multicast_mode, @@ -425,9 +451,9 @@ DEFUN (ip_route, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, - argv[idx_ipv4_prefixlen]->arg, NULL, gate, - ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, + argv[idx_ipv4_prefixlen]->arg, NULL, NULL, + gate, ifname, NULL, tag, distance, vrf, label); } DEFUN (ip_route_flags, @@ -451,9 +477,10 @@ DEFUN (ip_route_flags, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); - return zebra_static_ipv4( - vty, SAFI_UNICAST, 1, argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - NULL, argv[idx_reject_blackhole]->arg, tag, distance, vrf, NULL); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, + argv[idx_ipv4_prefixlen]->arg, NULL, NULL, + NULL, NULL, argv[idx_reject_blackhole]->arg, + tag, distance, vrf, NULL); } DEFUN (ip_route_ifname, @@ -479,9 +506,9 @@ DEFUN (ip_route_ifname, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, - argv[idx_ipv4_prefixlen]->arg, NULL, gate, - ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, + argv[idx_ipv4_prefixlen]->arg, NULL, NULL, + gate, ifname, NULL, tag, distance, vrf, label); } /* Mask as A.B.C.D format. */ @@ -516,9 +543,10 @@ DEFUN_HIDDEN (ip_route_mask, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, - gate, ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, + argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, + NULL, gate, ifname, NULL, tag, distance, vrf, + label); } DEFUN_HIDDEN (ip_route_mask_ifname, @@ -546,9 +574,10 @@ DEFUN_HIDDEN (ip_route_mask_ifname, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, - gate, ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, + argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, + NULL, gate, ifname, NULL, tag, distance, vrf, + label); } DEFUN_HIDDEN (ip_route_mask_flags, @@ -574,10 +603,11 @@ DEFUN_HIDDEN (ip_route_mask_flags, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, NULL, NULL, - argv[idx_reject_blackhole]->arg, tag, distance, - vrf, NULL); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, + argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, + NULL, NULL, NULL, + argv[idx_reject_blackhole]->arg, tag, + distance, vrf, NULL); } DEFUN (no_ip_route, @@ -610,9 +640,10 @@ DEFUN (no_ip_route, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, - argv[idx_ipv4_prefixlen]->arg, NULL, - gate, ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, + argv[idx_ipv4_prefixlen]->arg, NULL, NULL, + gate, ifname, NULL, tag, distance, vrf, + label); } DEFUN (no_ip_route_ifname, @@ -639,9 +670,10 @@ DEFUN (no_ip_route_ifname, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, - argv[idx_ipv4_prefixlen]->arg, NULL, - gate, ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, + argv[idx_ipv4_prefixlen]->arg, NULL, NULL, + gate, ifname, NULL, tag, distance, vrf, + label); } DEFUN (no_ip_route_flags, @@ -665,9 +697,9 @@ DEFUN (no_ip_route_flags, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, - argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - NULL, NULL, tag, distance, vrf, NULL); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, + argv[idx_ipv4_prefixlen]->arg, NULL, NULL, + NULL, NULL, NULL, tag, distance, vrf, NULL); } DEFUN_HIDDEN (no_ip_route_mask, @@ -702,9 +734,10 @@ DEFUN_HIDDEN (no_ip_route_mask, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, - gate, ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, + argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, + NULL, gate, ifname, NULL, tag, distance, vrf, + label); } DEFUN_HIDDEN (no_ip_route_mask_ifname, @@ -733,9 +766,10 @@ DEFUN_HIDDEN (no_ip_route_mask_ifname, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, - gate, ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, + argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, + NULL, gate, ifname, NULL, tag, distance, vrf, + label); } DEFUN_HIDDEN (no_ip_route_mask_flags, @@ -761,9 +795,10 @@ DEFUN_HIDDEN (no_ip_route_mask_flags, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, NULL, NULL, NULL, tag, - distance, vrf, NULL); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, + argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, + NULL, NULL, NULL, NULL, tag, distance, vrf, + NULL); } /* New RIB. Detailed information for IPv4 route. */ @@ -2147,163 +2182,6 @@ static int static_config(struct vty *vty, afi_t afi, safi_t safi, return write; } -/* General fucntion for IPv6 static route. */ -static int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, - const char *src_str, const char *gate_str, - const char *ifname, const char *flag_str, - const char *tag_str, const char *distance_str, - const char *vrf_id_str, const char *label_str) -{ - int ret; - u_char distance; - struct prefix p, src; - struct prefix_ipv6 *src_p = NULL; - struct in6_addr *gate = NULL; - struct in6_addr gate_addr; - u_char type; - u_char flag = 0; - route_tag_t tag = 0; - unsigned int ifindex = 0; - struct zebra_vrf *zvrf; - struct static_nh_label snh_label; - - ret = str2prefix(dest_str, &p); - if (ret <= 0) { - vty_out(vty, "%% Malformed address\n"); - return CMD_WARNING_CONFIG_FAILED; - } - - if (src_str) { - ret = str2prefix(src_str, &src); - if (ret <= 0 || src.family != AF_INET6) { - vty_out(vty, "%% Malformed source address\n"); - return CMD_WARNING_CONFIG_FAILED; - } - src_p = (struct prefix_ipv6 *)&src; - } - - /* Apply mask for given prefix. */ - apply_mask(&p); - - /* Administrative distance. */ - if (distance_str) - distance = atoi(distance_str); - else - distance = ZEBRA_STATIC_DISTANCE_DEFAULT; - - /* tag */ - if (tag_str) - tag = strtoul(tag_str, NULL, 10); - - /* VRF id */ - zvrf = zebra_vrf_lookup_by_name(vrf_id_str); - - if (!zvrf) { - vty_out(vty, "%% vrf %s is not defined\n", vrf_id_str); - return CMD_WARNING_CONFIG_FAILED; - } - - /* Labels */ - memset(&snh_label, 0, sizeof(struct static_nh_label)); - if (label_str) { - if (!mpls_enabled) { - vty_out(vty, - "%% MPLS not turned on in kernel, ignoring command\n"); - return CMD_WARNING_CONFIG_FAILED; - } - int rc = mpls_str2label(label_str, &snh_label.num_labels, - snh_label.label); - if (rc < 0) { - switch (rc) { - case -1: - vty_out(vty, "%% Malformed label(s)\n"); - break; - case -2: - vty_out(vty, - "%% Cannot use reserved label(s) (%d-%d)\n", - MPLS_MIN_RESERVED_LABEL, - MPLS_MAX_RESERVED_LABEL); - break; - case -3: - vty_out(vty, - "%% Too many labels. Enter %d or fewer\n", - MPLS_MAX_LABELS); - break; - } - return CMD_WARNING_CONFIG_FAILED; - } - } - - /* Null0 static route. */ - if ((ifname != NULL) - && (strncasecmp(ifname, "Null0", strlen(ifname)) == 0)) { - if (flag_str) { - vty_out(vty, "%% can not have flag %s with Null0\n", - flag_str); - return CMD_WARNING_CONFIG_FAILED; - } - SET_FLAG(flag, ZEBRA_FLAG_BLACKHOLE); - ifname = NULL; - } - - /* Route flags */ - if (flag_str) { - switch (flag_str[0]) { - case 'r': - case 'R': /* XXX */ - SET_FLAG(flag, ZEBRA_FLAG_REJECT); - break; - case 'b': - case 'B': /* XXX */ - SET_FLAG(flag, ZEBRA_FLAG_BLACKHOLE); - break; - default: - vty_out(vty, "%% Malformed flag %s \n", flag_str); - return CMD_WARNING_CONFIG_FAILED; - } - } - - if (gate_str) { - if (inet_pton(AF_INET6, gate_str, &gate_addr) != 1) { - vty_out(vty, "%% Malformed nexthop address %s\n", - gate_str); - return CMD_WARNING_CONFIG_FAILED; - } - gate = &gate_addr; - } - - if (ifname) { - struct interface *ifp; - ifp = if_lookup_by_name(ifname, zvrf_id(zvrf)); - if (!ifp) { - vty_out(vty, "%% Malformed Interface name %s\n", - ifname); - ifindex = IFINDEX_DELETED; - } else - ifindex = ifp->ifindex; - } - - if (gate_str == NULL && ifname == NULL) - type = STATIC_BLACKHOLE; - else if (gate_str && ifname) - type = STATIC_IPV6_GATEWAY_IFINDEX; - else if (ifname) - type = STATIC_IFINDEX; - else - type = STATIC_IPV6_GATEWAY; - - if (add_cmd) - static_add_route(AFI_IP6, SAFI_UNICAST, type, &p, src_p, - (union g_addr *)gate, ifindex, ifname, flag, - tag, distance, zvrf, &snh_label); - else - static_delete_route(AFI_IP6, SAFI_UNICAST, type, &p, src_p, - (union g_addr *)gate, ifindex, tag, - distance, zvrf, &snh_label); - - return CMD_SUCCESS; -} - DEFUN (ipv6_route, ipv6_route_cmd, "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", @@ -2346,8 +2224,10 @@ DEFUN (ipv6_route, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return static_ipv6_func(vty, 1, argv[idx_ipv6_prefixlen]->arg, src, - gate, ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 1, + argv[idx_ipv6_prefixlen]->arg, NULL, src, + gate, ifname, NULL, tag, distance, vrf, + label); } DEFUN (ipv6_route_flags, @@ -2383,9 +2263,10 @@ DEFUN (ipv6_route_flags, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); - return static_ipv6_func(vty, 1, argv[idx_ipv6_prefixlen]->arg, src, - NULL, NULL, argv[idx_reject_blackhole]->arg, - tag, distance, vrf, NULL); + return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 1, + argv[idx_ipv6_prefixlen]->arg, NULL, src, + NULL, NULL, argv[idx_reject_blackhole]->arg, + tag, distance, vrf, NULL); } DEFUN (ipv6_route_ifname, @@ -2425,9 +2306,10 @@ DEFUN (ipv6_route_ifname, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return static_ipv6_func(vty, 1, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6]->arg, argv[idx_interface]->arg, - NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 1, + argv[idx_ipv6_prefixlen]->arg, NULL, src, + argv[idx_ipv6]->arg, argv[idx_interface]->arg, + NULL, tag, distance, vrf, label); } DEFUN (no_ipv6_route, @@ -2473,8 +2355,9 @@ DEFUN (no_ipv6_route, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return static_ipv6_func(vty, 0, argv[idx_ipv6_prefixlen]->arg, src, - gate, ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 0, + argv[idx_ipv6_prefixlen]->arg, NULL, src, + gate, ifname, NULL, tag, distance, vrf, label); } DEFUN (no_ipv6_route_flags, @@ -2511,9 +2394,10 @@ DEFUN (no_ipv6_route_flags, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); - return static_ipv6_func(vty, 0, argv[idx_ipv6_prefixlen]->arg, src, - NULL, NULL, argv[idx_reject_blackhole]->arg, - tag, distance, vrf, NULL); + return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 0, + argv[idx_ipv6_prefixlen]->arg, NULL, src, + NULL, NULL, argv[idx_reject_blackhole]->arg, + tag, distance, vrf, NULL); } DEFUN (no_ipv6_route_ifname, @@ -2554,9 +2438,10 @@ DEFUN (no_ipv6_route_ifname, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return static_ipv6_func(vty, 0, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6]->arg, argv[idx_interface]->arg, - NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 0, + argv[idx_ipv6_prefixlen]->arg, NULL, src, + argv[idx_ipv6]->arg, argv[idx_interface]->arg, + NULL, tag, distance, vrf, label); } DEFUN (show_ipv6_route, From 00685a85e25f3817b2a972019ac047914f019caa Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 27 Jul 2017 21:27:56 -0300 Subject: [PATCH 8/8] zebra: use DEFPY for static routes Now we have a single command for IPv4 static routes and another one for IPv6 static routes (+ one command for IPv4 multicast static routes). Signed-off-by: Renato Westphal --- zebra/.gitignore | 1 + zebra/Makefile.am | 2 + zebra/zebra_vty.c | 745 +++------------------------------------------- 3 files changed, 50 insertions(+), 698 deletions(-) diff --git a/zebra/.gitignore b/zebra/.gitignore index 145df0568..d0a752853 100644 --- a/zebra/.gitignore +++ b/zebra/.gitignore @@ -13,3 +13,4 @@ TAGS .arch-ids *~ *.loT +zebra_vty_clippy.c diff --git a/zebra/Makefile.am b/zebra/Makefile.am index 46ecad5e4..67031ea36 100644 --- a/zebra/Makefile.am +++ b/zebra/Makefile.am @@ -37,6 +37,8 @@ zebra_SOURCES = \ zebra_vxlan.c \ # end +zebra_vty.o: zebra_vty_clippy.c + noinst_HEADERS = \ zebra_memory.h \ connected.h ioctl.h rib.h rt.h zserv.h redistribute.h debug.h rtadv.h \ diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 446bcc49e..e8b82ecf9 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -43,6 +43,7 @@ #include "zebra/zebra_static.h" #include "lib/json.h" #include "zebra/zebra_vxlan.h" +#include "zebra/zebra_vty_clippy.c" extern int allow_delete; @@ -62,7 +63,7 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, /* General function for static route. */ static int zebra_static_route(struct vty *vty, afi_t afi, safi_t safi, - int add_cmd, const char *dest_str, + const char *negate, const char *dest_str, const char *mask_str, const char *src_str, const char *gate_str, const char *ifname, const char *flag_str, const char *tag_str, @@ -233,7 +234,7 @@ static int zebra_static_route(struct vty *vty, afi_t afi, safi_t safi, type = STATIC_IPV6_GATEWAY; } - if (add_cmd) + if (!negate) static_add_route(afi, safi, type, &p, src_p, gatep, ifindex, ifname, flag, tag, distance, zvrf, &snh_label); else @@ -244,34 +245,9 @@ static int zebra_static_route(struct vty *vty, afi_t afi, safi_t safi, } /* Static unicast routes for multicast RPF lookup. */ -DEFUN (ip_mroute_dist, +DEFPY (ip_mroute_dist, ip_mroute_dist_cmd, - "ip mroute A.B.C.D/M [(1-255)]", - IP_STR - "Configure static unicast route into MRIB for multicast RPF lookup\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "Nexthop address\n" - "Nexthop interface name\n" - "Distance\n") -{ - char *destprefix = argv[2]->arg; - char *gate = NULL; - char *ifname = NULL; - char *distance = (argc == 5) ? argv[4]->arg : NULL; - - if (argv[3]->type == IPV4_TKN) - gate = argv[3]->arg; - else - ifname = argv[3]->arg; - - return zebra_static_route(vty, AFI_IP, SAFI_MULTICAST, 1, destprefix, - NULL, NULL, gate, ifname, NULL, NULL, distance, - NULL, NULL); -} - -DEFUN (no_ip_mroute_dist, - no_ip_mroute_dist_cmd, - "no ip mroute A.B.C.D/M [(1-255)]", + "[no] ip mroute A.B.C.D/M$prefix [(1-255)$distance]", NO_STR IP_STR "Configure static unicast route into MRIB for multicast RPF lookup\n" @@ -280,19 +256,9 @@ DEFUN (no_ip_mroute_dist, "Nexthop interface name\n" "Distance\n") { - char *destprefix = argv[3]->arg; - char *gate = NULL; - char *ifname = NULL; - char *distance = (argc == 6) ? argv[5]->arg : NULL; - - if (argv[4]->type == IPV4_TKN) - gate = argv[4]->arg; - else - ifname = argv[4]->arg; - - return zebra_static_route(vty, AFI_IP, SAFI_MULTICAST, 0, destprefix, - NULL, NULL, gate, ifname, NULL, NULL, distance, - NULL, NULL); + return zebra_static_route(vty, AFI_IP, SAFI_MULTICAST, no, prefix_str, + NULL, NULL, gate_str, ifname, NULL, NULL, + distance_str, NULL, NULL); } DEFUN (ip_multicast_mode, @@ -388,417 +354,43 @@ DEFUN (show_ip_rpf_addr, return CMD_SUCCESS; } -static void zebra_vty_ip_route_tdv_helper(int argc, struct cmd_token *argv[], - int idx_curr, char **tag, - char **distance, char **vrf, - char **labels) -{ - *tag = NULL; - *distance = NULL; - *vrf = NULL; - if (labels) - *labels = NULL; - while (idx_curr < argc) { - if (strmatch(argv[idx_curr]->text, "tag")) { - if (tag) - *tag = argv[idx_curr + 1]->arg; - idx_curr += 2; - } else if (strmatch(argv[idx_curr]->text, "vrf")) { - if (vrf) - *vrf = argv[idx_curr + 1]->arg; - idx_curr += 2; - } else if (strmatch(argv[idx_curr]->text, "label")) { - if (labels) - *labels = argv[idx_curr + 1]->arg; - idx_curr += 2; - } else { - if (distance) - *distance = argv[idx_curr]->arg; - idx_curr++; - } - } - - return; -} - /* Static route configuration. */ -DEFUN (ip_route, +DEFPY (ip_route, ip_route_cmd, - "ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", + "[no] ip route\ + \ + <\ + {A.B.C.D$gate|INTERFACE$ifname}\ + |null0$ifname\ + |$flag\ + >\ + [{\ + tag (1-4294967295)\ + |(1-255)$distance\ + |vrf NAME\ + |label WORD\ + }]", + NO_STR IP_STR "Establish static routes\n" "IP destination prefix (e.g. 10.0.0.0/8)\n" + "IP destination prefix\n" + "IP destination prefix mask\n" "IP gateway address\n" "IP gateway interface name\n" "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv4_prefixlen = 2; - int idx_curr = 4; - char *gate = NULL; - char *ifname = NULL; - char *tag, *distance, *vrf, *label; - - if (argv[3]->type == IPV4_TKN) - gate = argv[3]->arg; - else - ifname = argv[3]->arg; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, - argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - gate, ifname, NULL, tag, distance, vrf, label); -} - -DEFUN (ip_route_flags, - ip_route_flags_cmd, - "ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" "Emit an ICMP unreachable when matched\n" "Silently discard pkts when matched\n" "Set tag for this route\n" "Tag value\n" "Distance value for this route\n" - VRF_CMD_HELP_STR) -{ - int idx_ipv4_prefixlen = 2; - int idx_reject_blackhole = 3; - int idx_curr = 4; - char *tag, *distance, *vrf; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, - argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - NULL, NULL, argv[idx_reject_blackhole]->arg, - tag, distance, vrf, NULL); -} - -DEFUN (ip_route_ifname, - ip_route_ifname_cmd, - "ip route A.B.C.D/M A.B.C.D INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this route\n" VRF_CMD_HELP_STR MPLS_LABEL_HELPSTR) { - int idx_ipv4_prefixlen = 2; - int idx_curr = 5; - char *gate = argv[3]->arg; - char *ifname = argv[4]->arg; - char *tag, *distance, *vrf, *label; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, - argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - gate, ifname, NULL, tag, distance, vrf, label); -} - -/* Mask as A.B.C.D format. */ -DEFUN_HIDDEN (ip_route_mask, - ip_route_mask_cmd, - "ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv4 = 2; - int idx_ipv4_2 = 3; - int idx_curr = 5; - char *gate = NULL; - char *ifname = NULL; - char *tag, *distance, *vrf, *label; - - if (argv[4]->type == IPV4_TKN) - gate = argv[4]->arg; - else - ifname = argv[4]->arg; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, - argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, - NULL, gate, ifname, NULL, tag, distance, vrf, - label); -} - -DEFUN_HIDDEN (ip_route_mask_ifname, - ip_route_mask_ifname_cmd, - "ip route A.B.C.D A.B.C.D A.B.C.D INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv4 = 2; - int idx_ipv4_2 = 3; - int idx_curr = 6; - char *gate = argv[4]->arg; - char *ifname = argv[5]->arg; - char *tag, *distance, *vrf, *label; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, - argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, - NULL, gate, ifname, NULL, tag, distance, vrf, - label); -} - -DEFUN_HIDDEN (ip_route_mask_flags, - ip_route_mask_flags_cmd, - "ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "Emit an ICMP unreachable when matched\n" - "Silently discard pkts when matched\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR) -{ - int idx_ipv4 = 2; - int idx_ipv4_2 = 3; - int idx_reject_blackhole = 4; - int idx_curr = 5; - char *tag, *distance, *vrf; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, - argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, - NULL, NULL, NULL, - argv[idx_reject_blackhole]->arg, tag, - distance, vrf, NULL); -} - -DEFUN (no_ip_route, - no_ip_route_cmd, - "no ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv4_prefixlen = 3; - int idx_curr = 5; - char *gate = NULL; - char *ifname = NULL; - char *tag, *distance, *vrf, *label; - - if (argv[4]->type == IPV4_TKN) - gate = argv[4]->arg; - else - ifname = argv[4]->arg; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, - argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - gate, ifname, NULL, tag, distance, vrf, - label); -} - -DEFUN (no_ip_route_ifname, - no_ip_route_ifname_cmd, - "no ip route A.B.C.D/M A.B.C.D INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv4_prefixlen = 3; - int idx_curr = 6; - char *gate = argv[4]->arg; - char *ifname = argv[5]->arg; - char *tag, *distance, *vrf, *label; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, - argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - gate, ifname, NULL, tag, distance, vrf, - label); -} - -DEFUN (no_ip_route_flags, - no_ip_route_flags_cmd, - "no ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "Emit an ICMP unreachable when matched\n" - "Silently discard pkts when matched\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR) -{ - int idx_ipv4_prefixlen = 3; - int idx_curr = 5; - char *tag, *distance, *vrf; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, - argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - NULL, NULL, NULL, tag, distance, vrf, NULL); -} - -DEFUN_HIDDEN (no_ip_route_mask, - no_ip_route_mask_cmd, - "no ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv4 = 3; - int idx_ipv4_2 = 4; - int idx_curr = 6; - char *gate = NULL; - char *ifname = NULL; - char *tag, *distance, *vrf, *label; - - if (argv[5]->type == IPV4_TKN) - gate = argv[5]->arg; - else - ifname = argv[5]->arg; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, - argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, - NULL, gate, ifname, NULL, tag, distance, vrf, - label); -} - -DEFUN_HIDDEN (no_ip_route_mask_ifname, - no_ip_route_mask_ifname_cmd, - "no ip route A.B.C.D A.B.C.D A.B.C.D INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv4 = 3; - int idx_ipv4_2 = 4; - int idx_curr = 7; - char *gate = argv[5]->arg; - char *ifname = argv[6]->arg; - char *tag, *distance, *vrf, *label; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, - argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, - NULL, gate, ifname, NULL, tag, distance, vrf, - label); -} - -DEFUN_HIDDEN (no_ip_route_mask_flags, - no_ip_route_mask_flags_cmd, - "no ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "Emit an ICMP unreachable when matched\n" - "Silently discard pkts when matched\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR) -{ - int idx_ipv4 = 3; - int idx_ipv4_2 = 4; - int idx_curr = 6; - char *tag, *distance, *vrf; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, - argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, - NULL, NULL, NULL, NULL, tag, distance, vrf, - NULL); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, no, prefix, + mask_str, NULL, gate_str, ifname, flag, + tag_str, distance_str, vrf, label); + return 0; } /* New RIB. Detailed information for IPv4 route. */ @@ -2182,10 +1774,22 @@ static int static_config(struct vty *vty, afi_t afi, safi_t safi, return write; } -DEFUN (ipv6_route, +DEFPY (ipv6_route, ipv6_route_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - IP_STR + "[no] ipv6 route X:X::X:X/M$prefix [from X:X::X:X/M]\ + <\ + {X:X::X:X$gate|INTERFACE$ifname}\ + |null0$ifname\ + |$flag\ + >\ + [{\ + tag (1-4294967295)\ + |(1-255)$distance\ + |vrf NAME\ + |label WORD\ + }]", + NO_STR + IPV6_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" "IPv6 source-dest route\n" @@ -2193,255 +1797,17 @@ DEFUN (ipv6_route, "IPv6 gateway address\n" "IPv6 gateway interface name\n" "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv6_prefixlen = 2; - int idx_ipv6_ifname; - int idx_curr; - char *gate = NULL; - char *ifname = NULL; - char *src, *tag, *distance, *vrf, *label; - - if (strmatch(argv[3]->text, "from")) { - src = argv[4]->arg; - idx_ipv6_ifname = 5; - idx_curr = 6; - } else { - src = NULL; - idx_ipv6_ifname = 3; - idx_curr = 4; - } - - if (argv[idx_ipv6_ifname]->type == IPV6_TKN) - gate = argv[idx_ipv6_ifname]->arg; - else - ifname = argv[idx_ipv6_ifname]->arg; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 1, - argv[idx_ipv6_prefixlen]->arg, NULL, src, - gate, ifname, NULL, tag, distance, vrf, - label); -} - -DEFUN (ipv6_route_flags, - ipv6_route_flags_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" "Emit an ICMP unreachable when matched\n" "Silently discard pkts when matched\n" "Set tag for this route\n" "Tag value\n" "Distance value for this prefix\n" - VRF_CMD_HELP_STR) -{ - int idx_ipv6_prefixlen = 2; - int idx_reject_blackhole; - int idx_curr; - char *src, *tag, *distance, *vrf; - - if (strmatch(argv[3]->text, "from")) { - src = argv[4]->arg; - idx_reject_blackhole = 5; - idx_curr = 6; - } else { - src = NULL; - idx_reject_blackhole = 3; - idx_curr = 4; - } - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); - - return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 1, - argv[idx_ipv6_prefixlen]->arg, NULL, src, - NULL, NULL, argv[idx_reject_blackhole]->arg, - tag, distance, vrf, NULL); -} - -DEFUN (ipv6_route_ifname, - ipv6_route_ifname_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" VRF_CMD_HELP_STR MPLS_LABEL_HELPSTR) { - int idx_ipv6_prefixlen = 2; - int idx_ipv6 = 3; - int idx_interface = 4; - int idx_curr = 5; - char *src, *tag, *distance, *vrf, *label; - - if (strmatch(argv[3]->text, "from")) { - src = argv[4]->arg; - idx_ipv6 = 5; - idx_interface = 6; - idx_curr = 7; - } else { - src = NULL; - idx_ipv6 = 3; - idx_interface = 4; - idx_curr = 5; - } - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 1, - argv[idx_ipv6_prefixlen]->arg, NULL, src, - argv[idx_ipv6]->arg, argv[idx_interface]->arg, - NULL, tag, distance, vrf, label); -} - -DEFUN (no_ipv6_route, - no_ipv6_route_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv6_prefixlen = 3; - int idx_ipv6_ifname; - int idx_curr; - char *gate = NULL; - char *ifname = NULL; - char *src, *tag, *distance, *vrf, *label; - - if (strmatch(argv[4]->text, "from")) { - src = argv[5]->arg; - idx_ipv6_ifname = 6; - idx_curr = 7; - } else { - src = NULL; - idx_ipv6_ifname = 4; - idx_curr = 5; - } - - if (argv[idx_ipv6_ifname]->type == IPV6_TKN) - gate = argv[idx_ipv6_ifname]->arg; - else - ifname = argv[idx_ipv6_ifname]->arg; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 0, - argv[idx_ipv6_prefixlen]->arg, NULL, src, - gate, ifname, NULL, tag, distance, vrf, label); -} - -DEFUN (no_ipv6_route_flags, - no_ipv6_route_flags_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" - "Emit an ICMP unreachable when matched\n" - "Silently discard pkts when matched\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - VRF_CMD_HELP_STR) -{ - int idx_ipv6_prefixlen = 3; - int idx_reject_blackhole; - int idx_curr; - char *src, *tag, *distance, *vrf; - - if (strmatch(argv[4]->text, "from")) { - src = argv[5]->arg; - idx_reject_blackhole = 6; - idx_curr = 7; - } else { - src = NULL; - idx_reject_blackhole = 4; - idx_curr = 5; - } - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); - - return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 0, - argv[idx_ipv6_prefixlen]->arg, NULL, src, - NULL, NULL, argv[idx_reject_blackhole]->arg, - tag, distance, vrf, NULL); -} - -DEFUN (no_ipv6_route_ifname, - no_ipv6_route_ifname_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv6_prefixlen = 3; - int idx_ipv6; - int idx_interface; - int idx_curr; - char *src, *tag, *distance, *vrf, *label; - - if (strmatch(argv[4]->text, "from")) { - src = argv[5]->arg; - idx_ipv6 = 6; - idx_interface = 7; - idx_curr = 8; - } else { - src = NULL; - idx_ipv6 = 4; - idx_interface = 5; - idx_curr = 6; - } - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 0, - argv[idx_ipv6_prefixlen]->arg, NULL, src, - argv[idx_ipv6]->arg, argv[idx_interface]->arg, - NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, no, prefix_str, + NULL, from_str, gate_str, ifname, flag, + tag_str, distance_str, vrf, label); } DEFUN (show_ipv6_route, @@ -3294,21 +2660,9 @@ void zebra_vty_init(void) install_element(CONFIG_NODE, &allow_external_route_update_cmd); install_element(CONFIG_NODE, &no_allow_external_route_update_cmd); install_element(CONFIG_NODE, &ip_mroute_dist_cmd); - install_element(CONFIG_NODE, &no_ip_mroute_dist_cmd); install_element(CONFIG_NODE, &ip_multicast_mode_cmd); install_element(CONFIG_NODE, &no_ip_multicast_mode_cmd); install_element(CONFIG_NODE, &ip_route_cmd); - install_element(CONFIG_NODE, &ip_route_ifname_cmd); - install_element(CONFIG_NODE, &ip_route_flags_cmd); - install_element(CONFIG_NODE, &ip_route_mask_cmd); - install_element(CONFIG_NODE, &ip_route_mask_ifname_cmd); - install_element(CONFIG_NODE, &ip_route_mask_flags_cmd); - install_element(CONFIG_NODE, &no_ip_route_cmd); - install_element(CONFIG_NODE, &no_ip_route_flags_cmd); - install_element(CONFIG_NODE, &no_ip_route_ifname_cmd); - install_element(CONFIG_NODE, &no_ip_route_mask_cmd); - install_element(CONFIG_NODE, &no_ip_route_mask_flags_cmd); - install_element(CONFIG_NODE, &no_ip_route_mask_ifname_cmd); install_element(CONFIG_NODE, &ip_zebra_import_table_distance_cmd); install_element(CONFIG_NODE, &no_ip_zebra_import_table_cmd); @@ -3332,11 +2686,6 @@ void zebra_vty_init(void) install_element(VIEW_NODE, &show_ip_route_vrf_all_summary_prefix_cmd); install_element(CONFIG_NODE, &ipv6_route_cmd); - install_element(CONFIG_NODE, &ipv6_route_flags_cmd); - install_element(CONFIG_NODE, &ipv6_route_ifname_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_flags_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_ifname_cmd); install_element(CONFIG_NODE, &ip_nht_default_route_cmd); install_element(CONFIG_NODE, &no_ip_nht_default_route_cmd); install_element(CONFIG_NODE, &ipv6_nht_default_route_cmd);