diff options
| -rw-r--r-- | ldpd/.gitignore | 1 | ||||
| -rw-r--r-- | ldpd/Makefile.am | 4 | ||||
| -rw-r--r-- | ldpd/lde.c | 6 | ||||
| -rw-r--r-- | ldpd/ldp_debug.c | 18 | ||||
| -rw-r--r-- | ldpd/ldp_vty.h | 78 | ||||
| -rw-r--r-- | ldpd/ldp_vty_cmds.c | 733 | ||||
| -rw-r--r-- | ldpd/ldp_vty_conf.c | 215 | ||||
| -rw-r--r-- | ldpd/ldp_vty_exec.c | 34 | ||||
| -rw-r--r-- | lib/command.c | 111 | ||||
| -rw-r--r-- | lib/command.h | 6 | ||||
| -rw-r--r-- | ospf6d/ospf6_intra.c | 2 | ||||
| -rw-r--r-- | ospf6d/ospf6_lsa.c | 2 | ||||
| -rw-r--r-- | ospf6d/ospf6_neighbor.c | 6 | ||||
| -rw-r--r-- | ospf6d/ospf6_route.c | 4 | ||||
| -rw-r--r-- | vtysh/vtysh.c | 79 | ||||
| -rw-r--r-- | zebra/.gitignore | 1 | ||||
| -rw-r--r-- | zebra/Makefile.am | 2 | ||||
| -rw-r--r-- | zebra/zebra_mpls_vty.c | 599 | ||||
| -rw-r--r-- | zebra/zebra_static.c | 27 | ||||
| -rw-r--r-- | zebra/zebra_static.h | 18 | ||||
| -rw-r--r-- | zebra/zebra_vty.c | 994 |
21 files changed, 670 insertions, 2270 deletions
diff --git a/ldpd/.gitignore b/ldpd/.gitignore index 35f7740d11..f52b227cb1 100644 --- a/ldpd/.gitignore +++ b/ldpd/.gitignore @@ -15,3 +15,4 @@ TAGS .arch-ids *~ *.loT +ldp_vty_cmds_clippy.c diff --git a/ldpd/Makefile.am b/ldpd/Makefile.am index 6074b53a33..de9b07ed4c 100644 --- a/ldpd/Makefile.am +++ b/ldpd/Makefile.am @@ -1,5 +1,7 @@ ## Process this file with automake to produce Makefile.in. +include ../common.am + AM_CPPFLAGS = -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" INSTALL_SDATA=@INSTALL@ -m 600 @@ -16,6 +18,8 @@ libldp_a_SOURCES = \ socket.c util.c ldp_vty_cmds.c ldp_vty_conf.c ldp_vty_exec.c \ ldp_debug.c ldp_zebra.c +ldp_vty_cmds.o: ldp_vty_cmds_clippy.c + noinst_HEADERS = \ control.h lde.h ldpd.h ldpe.h ldp.h log.h ldp_debug.h ldp_vty.h diff --git a/ldpd/lde.c b/ldpd/lde.c index 602dc8805e..77643ff48b 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -1328,7 +1328,6 @@ lde_nbr_addr_update(struct lde_nbr *ln, struct lde_addr *lde_addr, int removed) struct lde_map *me; RB_FOREACH(fec, fec_tree, &ln->recv_map) { - fn = (struct fec_node *)fec_find(&ft, fec); switch (fec->type) { case FEC_TYPE_IPV4: if (lde_addr->af != AF_INET) @@ -1342,6 +1341,11 @@ lde_nbr_addr_update(struct lde_nbr *ln, struct lde_addr *lde_addr, int removed) continue; } + fn = (struct fec_node *)fec_find(&ft, fec); + if (fn == NULL) + /* shouldn't happen */ + continue; + LIST_FOREACH(fnh, &fn->nexthops, entry) { if (ldp_addrcmp(fnh->af, &fnh->nexthop, &lde_addr->addr)) diff --git a/ldpd/ldp_debug.c b/ldpd/ldp_debug.c index c9c7160aed..d80ec8dfbc 100644 --- a/ldpd/ldp_debug.c +++ b/ldpd/ldp_debug.c @@ -38,31 +38,31 @@ struct cmd_node ldp_debug_node = }; int -ldp_vty_debug(struct vty *vty, int disable, const char *type_str, - const char *dir_str, int all) +ldp_vty_debug(struct vty *vty, const char *negate, const char *type_str, + const char *dir_str, const char *all) { if (strcmp(type_str, "discovery") == 0) { if (dir_str == NULL) return (CMD_WARNING_CONFIG_FAILED); if (dir_str[0] == 'r') { - if (disable) + if (negate) DEBUG_OFF(hello, HELLO_RECV); else DEBUG_ON(hello, HELLO_RECV); } else { - if (disable) + if (negate) DEBUG_OFF(hello, HELLO_SEND); else DEBUG_ON(hello, HELLO_SEND); } } else if (strcmp(type_str, "errors") == 0) { - if (disable) + if (negate) DEBUG_OFF(errors, ERRORS); else DEBUG_ON(errors, ERRORS); } else if (strcmp(type_str, "event") == 0) { - if (disable) + if (negate) DEBUG_OFF(event, EVENT); else DEBUG_ON(event, EVENT); @@ -71,7 +71,7 @@ ldp_vty_debug(struct vty *vty, int disable, const char *type_str, return (CMD_WARNING_CONFIG_FAILED); if (dir_str[0] == 'r') { - if (disable) { + if (negate) { DEBUG_OFF(msg, MSG_RECV); DEBUG_OFF(msg, MSG_RECV_ALL); } else { @@ -80,7 +80,7 @@ ldp_vty_debug(struct vty *vty, int disable, const char *type_str, DEBUG_ON(msg, MSG_RECV_ALL); } } else { - if (disable) { + if (negate) { DEBUG_OFF(msg, MSG_SEND); DEBUG_OFF(msg, MSG_SEND_ALL); } else { @@ -90,7 +90,7 @@ ldp_vty_debug(struct vty *vty, int disable, const char *type_str, } } } else if (strcmp(type_str, "zebra") == 0) { - if (disable) + if (negate) DEBUG_OFF(zebra, ZEBRA); else DEBUG_ON(zebra, ZEBRA); diff --git a/ldpd/ldp_vty.h b/ldpd/ldp_vty.h index 93713166f4..3d2072f1e5 100644 --- a/ldpd/ldp_vty.h +++ b/ldpd/ldp_vty.h @@ -36,46 +36,46 @@ int ldp_get_address(const char *, int *, union ldpd_addr *); int ldp_config_write(struct vty *); int ldp_l2vpn_config_write(struct vty *); int ldp_debug_config_write(struct vty *); -int ldp_vty_mpls_ldp (struct vty *, int); -int ldp_vty_address_family (struct vty *, int, const char *); -int ldp_vty_disc_holdtime(struct vty *, int, const char *, const char *); -int ldp_vty_disc_interval(struct vty *, int, const char *, const char *); -int ldp_vty_targeted_hello_accept(struct vty *, int, const char *); -int ldp_vty_nbr_session_holdtime(struct vty *, int, const char *, const char *); -int ldp_vty_af_session_holdtime(struct vty *, int, const char *); -int ldp_vty_interface(struct vty *, int, const char *); -int ldp_vty_trans_addr(struct vty *, int, const char *); -int ldp_vty_neighbor_targeted(struct vty *, int, const char *); -int ldp_vty_label_advertise(struct vty *, int, const char *, const char *); -int ldp_vty_label_allocate(struct vty *, int, int, const char *); -int ldp_vty_label_expnull(struct vty *, int, const char *); -int ldp_vty_label_accept(struct vty *, int, const char *, const char *); -int ldp_vty_ttl_security(struct vty *, int); -int ldp_vty_router_id(struct vty *, int, const char *); -int ldp_vty_ds_cisco_interop(struct vty *, int); -int ldp_vty_trans_pref_ipv4(struct vty *, int); -int ldp_vty_neighbor_password(struct vty *, int, const char *, const char *); -int ldp_vty_neighbor_ttl_security(struct vty *, int, const char *, const char *); -int ldp_vty_l2vpn(struct vty *, int, const char *); -int ldp_vty_l2vpn_bridge(struct vty *, int, const char *); -int ldp_vty_l2vpn_mtu(struct vty *, int, const char *); -int ldp_vty_l2vpn_pwtype(struct vty *, int, const char *); -int ldp_vty_l2vpn_interface(struct vty *, int, const char *); -int ldp_vty_l2vpn_pseudowire(struct vty *, int, const char *); -int ldp_vty_l2vpn_pw_cword(struct vty *, int, const char *); -int ldp_vty_l2vpn_pw_nbr_addr(struct vty *, int, const char *); -int ldp_vty_l2vpn_pw_nbr_id(struct vty *, int, const char *); -int ldp_vty_l2vpn_pw_pwid(struct vty *, int, const char *); -int ldp_vty_l2vpn_pw_pwstatus(struct vty *, int); +int ldp_vty_mpls_ldp (struct vty *, const char *); +int ldp_vty_address_family (struct vty *, const char *, const char *); +int ldp_vty_disc_holdtime(struct vty *, const char *, const char *, long); +int ldp_vty_disc_interval(struct vty *, const char *, const char *, long); +int ldp_vty_targeted_hello_accept(struct vty *, const char *, const char *); +int ldp_vty_nbr_session_holdtime(struct vty *, const char *, struct in_addr, long); +int ldp_vty_af_session_holdtime(struct vty *, const char *, long); +int ldp_vty_interface(struct vty *, const char *, const char *); +int ldp_vty_trans_addr(struct vty *, const char *, const char *); +int ldp_vty_neighbor_targeted(struct vty *, const char *, const char *); +int ldp_vty_label_advertise(struct vty *, const char *, const char *, const char *); +int ldp_vty_label_allocate(struct vty *, const char *, const char *, const char *); +int ldp_vty_label_expnull(struct vty *, const char *, const char *); +int ldp_vty_label_accept(struct vty *, const char *, const char *, const char *); +int ldp_vty_ttl_security(struct vty *, const char *); +int ldp_vty_router_id(struct vty *, const char *, struct in_addr); +int ldp_vty_ds_cisco_interop(struct vty *, const char *); +int ldp_vty_trans_pref_ipv4(struct vty *, const char *); +int ldp_vty_neighbor_password(struct vty *, const char *, struct in_addr, const char *); +int ldp_vty_neighbor_ttl_security(struct vty *, const char *, struct in_addr, const char *); +int ldp_vty_l2vpn(struct vty *, const char *, const char *); +int ldp_vty_l2vpn_bridge(struct vty *, const char *, const char *); +int ldp_vty_l2vpn_mtu(struct vty *, const char *, long); +int ldp_vty_l2vpn_pwtype(struct vty *, const char *, const char *); +int ldp_vty_l2vpn_interface(struct vty *, const char *, const char *); +int ldp_vty_l2vpn_pseudowire(struct vty *, const char *, const char *); +int ldp_vty_l2vpn_pw_cword(struct vty *, const char *, const char *); +int ldp_vty_l2vpn_pw_nbr_addr(struct vty *, const char *, const char *); +int ldp_vty_l2vpn_pw_nbr_id(struct vty *, const char *, struct in_addr); +int ldp_vty_l2vpn_pw_pwid(struct vty *, const char *, long); +int ldp_vty_l2vpn_pw_pwstatus(struct vty *, const char *); int ldp_vty_clear_nbr(struct vty *, const char *); -int ldp_vty_debug(struct vty *, int, const char *, const char *, int); -int ldp_vty_show_binding(struct vty *, const char *, int, int); -int ldp_vty_show_discovery(struct vty *, const char *, int, int); -int ldp_vty_show_interface(struct vty *, const char *, int); -int ldp_vty_show_capabilities(struct vty *, int); -int ldp_vty_show_neighbor(struct vty *, int, int, int); -int ldp_vty_show_atom_binding(struct vty *, int); -int ldp_vty_show_atom_vc(struct vty *, int); +int ldp_vty_debug(struct vty *, const char *, const char *, const char *, const char *); +int ldp_vty_show_binding(struct vty *, const char *, const char *, const char *); +int ldp_vty_show_discovery(struct vty *, const char *, const char *, const char *); +int ldp_vty_show_interface(struct vty *, const char *, const char *); +int ldp_vty_show_capabilities(struct vty *, const char *); +int ldp_vty_show_neighbor(struct vty *, int, const char *, const char *); +int ldp_vty_show_atom_binding(struct vty *, const char *); +int ldp_vty_show_atom_vc(struct vty *, const char *); int ldp_vty_show_debugging(struct vty *); void ldp_vty_init(void); diff --git a/ldpd/ldp_vty_cmds.c b/ldpd/ldp_vty_cmds.c index 871905aa8f..7da76185c6 100644 --- a/ldpd/ldp_vty_cmds.c +++ b/ldpd/ldp_vty_cmds.c @@ -21,63 +21,83 @@ #include "command.h" #include "vty.h" +#include "ldpd/ldpd.h" #include "ldpd/ldp_vty.h" +#include "ldpd/ldp_vty_cmds_clippy.c" DEFUN_NOSH(ldp_mpls_ldp, ldp_mpls_ldp_cmd, - "[no] mpls ldp", - "Negate a command or set its defaults\n" + "mpls ldp", "Global MPLS configuration subcommands\n" "Label Distribution Protocol\n") { - int idx = 0; - int negate = 0; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; + return (ldp_vty_mpls_ldp(vty, NULL)); +} - return (ldp_vty_mpls_ldp(vty, negate)); +DEFPY (no_ldp_mpls_ldp, + no_ldp_mpls_ldp_cmd, + "no mpls ldp", + "Negate a command or set its defaults\n" + "Global MPLS configuration subcommands\n" + "Label Distribution Protocol\n") +{ + return (ldp_vty_mpls_ldp(vty, "no")); } DEFUN_NOSH(ldp_l2vpn, ldp_l2vpn_cmd, - "[no] l2vpn WORD type vpls", - "Negate a command or set its defaults\n" + "l2vpn WORD type vpls", "Configure l2vpn commands\n" "L2VPN name\n" "L2VPN type\n" "Virtual Private LAN Service\n") { int idx = 0; - int negate = 0; const char *name; - if (argv_find(argv, argc, "no", &idx)) - negate = 1; argv_find(argv, argc, "WORD", &idx); name = argv[idx]->arg; - return (ldp_vty_l2vpn(vty, negate, name)); + return (ldp_vty_l2vpn(vty, 0, name)); +} + +DEFPY (no_ldp_l2vpn, + no_ldp_l2vpn_cmd, + "no l2vpn WORD$l2vpn_name type vpls", + "Negate a command or set its defaults\n" + "Configure l2vpn commands\n" + "L2VPN name\n" + "L2VPN type\n" + "Virtual Private LAN Service\n") +{ + return (ldp_vty_l2vpn(vty, "no", l2vpn_name)); } DEFUN_NOSH(ldp_address_family, ldp_address_family_cmd, - "[no] address-family <ipv4|ipv6>", - "Negate a command or set its defaults\n" + "address-family <ipv4|ipv6>", "Configure Address Family and its parameters\n" "IPv4\n" "IPv6\n") { int idx = 0; - int negate = 0; const char *af; - if (argv_find(argv, argc, "no", &idx)) - negate = 1; argv_find(argv, argc, "address-family", &idx); af = argv[idx + 1]->text; - return (ldp_vty_address_family(vty, negate, af)); + return (ldp_vty_address_family(vty, 0, af)); +} + +DEFPY (no_ldp_address_family, + no_ldp_address_family_cmd, + "no address-family <ipv4|ipv6>$af", + "Negate a command or set its defaults\n" + "Configure Address Family and its parameters\n" + "IPv4\n" + "IPv6\n") +{ + return (ldp_vty_address_family(vty, "no", af)); } DEFUN_NOSH(ldp_exit_address_family, @@ -90,9 +110,9 @@ DEFUN_NOSH(ldp_exit_address_family, return CMD_SUCCESS; } -DEFUN (ldp_discovery_holdtime, +DEFPY (ldp_discovery_holdtime, ldp_discovery_holdtime_cmd, - "[no] discovery <hello|targeted-hello> holdtime (1-65535)", + "[no] discovery <hello|targeted-hello>$hello_type holdtime (1-65535)$holdtime", "Negate a command or set its defaults\n" "Configure discovery parameters\n" "LDP Link Hellos\n" @@ -100,24 +120,12 @@ DEFUN (ldp_discovery_holdtime, "Hello holdtime\n" "Time (seconds) - 65535 implies infinite\n") { - int idx = 0; - int negate = 0; - const char *hello_type; - const char *holdtime; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "discovery", &idx); - hello_type = argv[idx + 1]->text; - argv_find(argv, argc, "(1-65535)", &idx); - holdtime = argv[idx]->arg; - - return (ldp_vty_disc_holdtime(vty, negate, hello_type, holdtime)); + return (ldp_vty_disc_holdtime(vty, no, hello_type, holdtime)); } -DEFUN (ldp_discovery_interval, +DEFPY (ldp_discovery_interval, ldp_discovery_interval_cmd, - "[no] discovery <hello|targeted-hello> interval (1-65535)", + "[no] discovery <hello|targeted-hello>$hello_type interval (1-65535)$interval", "Negate a command or set its defaults\n" "Configure discovery parameters\n" "LDP Link Hellos\n" @@ -125,22 +133,10 @@ DEFUN (ldp_discovery_interval, "Hello interval\n" "Time (seconds)\n") { - int idx = 0; - int negate = 0; - const char *hello_type; - const char *interval; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "discovery", &idx); - hello_type = argv[idx + 1]->text; - argv_find(argv, argc, "(1-65535)", &idx); - interval = argv[idx]->arg; - - return (ldp_vty_disc_interval(vty, negate, hello_type, interval)); + return (ldp_vty_disc_interval(vty, no, hello_type, interval)); } -DEFUN (ldp_dual_stack_transport_connection_prefer_ipv4, +DEFPY (ldp_dual_stack_transport_connection_prefer_ipv4, ldp_dual_stack_transport_connection_prefer_ipv4_cmd, "[no] dual-stack transport-connection prefer ipv4", "Negate a command or set its defaults\n" @@ -149,58 +145,34 @@ DEFUN (ldp_dual_stack_transport_connection_prefer_ipv4, "Configure prefered address family for TCP transport connection with neighbor\n" "IPv4\n") { - int idx = 0; - int negate = 0; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - - return (ldp_vty_trans_pref_ipv4(vty, negate)); + return (ldp_vty_trans_pref_ipv4(vty, no)); } -DEFUN (ldp_dual_stack_cisco_interop, +DEFPY (ldp_dual_stack_cisco_interop, ldp_dual_stack_cisco_interop_cmd, "[no] dual-stack cisco-interop", "Negate a command or set its defaults\n" "Configure dual stack parameters\n" "Use Cisco non-compliant format to send and interpret the Dual-Stack capability TLV\n") { - int idx = 0; - int negate = 0; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - - return (ldp_vty_ds_cisco_interop(vty, negate)); + return (ldp_vty_ds_cisco_interop(vty, no)); } -DEFUN (ldp_neighbor_password, +DEFPY (ldp_neighbor_password, ldp_neighbor_password_cmd, - "[no] neighbor A.B.C.D password WORD", + "[no] neighbor A.B.C.D$neighbor password WORD$password", "Negate a command or set its defaults\n" "Configure neighbor parameters\n" "LDP Id of neighbor\n" "Configure password for MD5 authentication\n" "The password\n") { - int idx = 0; - int negate = 0; - const char *neighbor; - const char *password; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "A.B.C.D", &idx); - neighbor = argv[idx]->arg; - argv_find(argv, argc, "WORD", &idx); - password = argv[idx]->arg; - - return (ldp_vty_neighbor_password(vty, negate, neighbor, password)); + return (ldp_vty_neighbor_password(vty, no, neighbor, password)); } -DEFUN (ldp_neighbor_session_holdtime, +DEFPY (ldp_neighbor_session_holdtime, ldp_neighbor_session_holdtime_cmd, - "[no] neighbor A.B.C.D session holdtime (15-65535)", + "[no] neighbor A.B.C.D$neighbor session holdtime (15-65535)$holdtime", "Negate a command or set its defaults\n" "Configure neighbor parameters\n" "LDP Id of neighbor\n" @@ -208,24 +180,12 @@ DEFUN (ldp_neighbor_session_holdtime, "Configure session holdtime\n" "Time (seconds)\n") { - int idx = 0; - int negate = 0; - const char *neighbor; - const char *holdtime; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "A.B.C.D", &idx); - neighbor = argv[idx]->arg; - argv_find(argv, argc, "(15-65535)", &idx); - holdtime = argv[idx]->arg; - - return (ldp_vty_nbr_session_holdtime(vty, negate, neighbor, holdtime)); + return (ldp_vty_nbr_session_holdtime(vty, no, neighbor, holdtime)); } -DEFUN (ldp_neighbor_ttl_security, +DEFPY (ldp_neighbor_ttl_security, ldp_neighbor_ttl_security_cmd, - "[no] neighbor A.B.C.D ttl-security <disable|hops (1-254)>", + "[no] neighbor A.B.C.D$neighbor ttl-security <disable|hops (1-254)$hops>", "Negate a command or set its defaults\n" "Configure neighbor parameters\n" "LDP Id of neighbor\n" @@ -234,43 +194,22 @@ DEFUN (ldp_neighbor_ttl_security, "IP hops\n" "maximum number of hops\n") { - int idx = 0; - int negate = 0; - const char *neighbor; - const char *hops = NULL; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "A.B.C.D", &idx); - neighbor = argv[idx]->arg; - if (argv_find(argv, argc, "(1-254)", &idx)) - hops = argv[idx]->arg; - - return (ldp_vty_neighbor_ttl_security(vty, negate, neighbor, hops)); + return (ldp_vty_neighbor_ttl_security(vty, no, neighbor, hops_str)); } -DEFUN (ldp_router_id, +DEFPY (ldp_router_id, ldp_router_id_cmd, - "[no] router-id A.B.C.D", + "[no] router-id A.B.C.D$address", "Negate a command or set its defaults\n" "Configure router Id\n" "LSR Id (in form of an IPv4 address)\n") { - int idx = 0; - int negate = 0; - const char *address; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "A.B.C.D", &idx); - address = argv[idx]->arg; - - return (ldp_vty_router_id(vty, negate, address)); + return (ldp_vty_router_id(vty, no, address)); } -DEFUN (ldp_discovery_targeted_hello_accept, +DEFPY (ldp_discovery_targeted_hello_accept, ldp_discovery_targeted_hello_accept_cmd, - "[no] discovery targeted-hello accept [from <(1-199)|(1300-2699)|WORD>]", + "[no] discovery targeted-hello accept [from <(1-199)|(1300-2699)|WORD>$from_acl]", "Negate a command or set its defaults\n" "Configure discovery parameters\n" "LDP Targeted Hellos\n" @@ -280,61 +219,34 @@ DEFUN (ldp_discovery_targeted_hello_accept, "IP access-list number (expanded range)\n" "IP access-list name\n") { - int idx = 0; - int negate = 0; - const char *from_acl = NULL; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - if (argv_find(argv, argc, "from", &idx)) - from_acl = argv[idx + 1]->arg; - - return (ldp_vty_targeted_hello_accept(vty, negate, from_acl)); + return (ldp_vty_targeted_hello_accept(vty, no, from_acl)); } -DEFUN (ldp_discovery_transport_address_ipv4, +DEFPY (ldp_discovery_transport_address_ipv4, ldp_discovery_transport_address_ipv4_cmd, - "[no] discovery transport-address A.B.C.D", + "[no] discovery transport-address A.B.C.D$address", "Negate a command or set its defaults\n" "Configure discovery parameters\n" "Specify transport address for TCP connection\n" "IP address to be used as transport address\n") { - int idx = 0; - int negate = 0; - const char *address; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "A.B.C.D", &idx); - address = argv[idx]->arg; - - return (ldp_vty_trans_addr(vty, negate, address)); + return (ldp_vty_trans_addr(vty, no, address_str)); } -DEFUN (ldp_discovery_transport_address_ipv6, +DEFPY (ldp_discovery_transport_address_ipv6, ldp_discovery_transport_address_ipv6_cmd, - "[no] discovery transport-address X:X::X:X", + "[no] discovery transport-address X:X::X:X$address", "Negate a command or set its defaults\n" "Configure discovery parameters\n" "Specify transport address for TCP connection\n" "IPv6 address to be used as transport address\n") { - int idx = 0; - int negate = 0; - const char *address; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "X:X::X:X", &idx); - address = argv[idx]->arg; - - return (ldp_vty_trans_addr(vty, negate, address)); + return (ldp_vty_trans_addr(vty, no, address_str)); } -DEFUN (ldp_label_local_advertise, +DEFPY (ldp_label_local_advertise, ldp_label_local_advertise_cmd, - "[no] label local advertise [{to <(1-199)|(1300-2699)|WORD>|for <(1-199)|(1300-2699)|WORD>}]", + "[no] label local advertise [{to <(1-199)|(1300-2699)|WORD>$to_acl|for <(1-199)|(1300-2699)|WORD>$for_acl}]", "Negate a command or set its defaults\n" "Configure label control and policies\n" "Configure local label control and policies\n" @@ -348,27 +260,12 @@ DEFUN (ldp_label_local_advertise, "IP access-list number (expanded range)\n" "IP access-list name\n") { - int idx = 0; - int negate = 0; - const char *to_acl = NULL; - const char *for_acl = NULL; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - - /* arguments within curly braces may be provided in any order */ - if (argv_find(argv, argc, "to", &idx)) - to_acl = argv[idx + 1]->arg; - idx = 0; - if (argv_find(argv, argc, "for", &idx)) - for_acl = argv[idx + 1]->arg; - - return (ldp_vty_label_advertise(vty, negate, to_acl, for_acl)); + return (ldp_vty_label_advertise(vty, no, to_acl, for_acl)); } -DEFUN (ldp_label_local_advertise_explicit_null, +DEFPY (ldp_label_local_advertise_explicit_null, ldp_label_local_advertise_explicit_null_cmd, - "[no] label local advertise explicit-null [for <(1-199)|(1300-2699)|WORD>]", + "[no] label local advertise explicit-null [for <(1-199)|(1300-2699)|WORD>$for_acl]", "Negate a command or set its defaults\n" "Configure label control and policies\n" "Configure local label control and policies\n" @@ -379,21 +276,12 @@ DEFUN (ldp_label_local_advertise_explicit_null, "IP access-list number (expanded range)\n" "IP access-list name\n") { - int idx = 0; - int negate = 0; - const char *for_acl = NULL; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - if (argv_find(argv, argc, "for", &idx)) - for_acl = argv[idx + 1]->arg; - - return (ldp_vty_label_expnull(vty, negate, for_acl)); + return (ldp_vty_label_expnull(vty, no, for_acl)); } -DEFUN (ldp_label_local_allocate, +DEFPY (ldp_label_local_allocate, ldp_label_local_allocate_cmd, - "[no] label local allocate <host-routes|for <(1-199)|(1300-2699)|WORD>>", + "[no] label local allocate <host-routes$host_routes|for <(1-199)|(1300-2699)|WORD>$for_acl>", "Negate a command or set its defaults\n" "Configure label control and policies\n" "Configure local label control and policies\n" @@ -404,27 +292,12 @@ DEFUN (ldp_label_local_allocate, "IP access-list number (expanded range)\n" "IP access-list name\n") { - int idx = 0; - int negate = 0; - int host_routes = 0; - const char *for_acl = NULL; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - - /* arguments within curly braces may be provided in any order */ - if (argv_find(argv, argc, "host-routes", &idx)) - host_routes = 1; - idx = 0; - if (argv_find(argv, argc, "for", &idx)) - for_acl = argv[idx + 1]->arg; - - return (ldp_vty_label_allocate(vty, negate, host_routes, for_acl)); + return (ldp_vty_label_allocate(vty, no, host_routes, for_acl)); } -DEFUN (ldp_label_remote_accept, +DEFPY (ldp_label_remote_accept, ldp_label_remote_accept_cmd, - "[no] label remote accept {from <(1-199)|(1300-2699)|WORD>|for <(1-199)|(1300-2699)|WORD>}", + "[no] label remote accept {from <(1-199)|(1300-2699)|WORD>$from_acl|for <(1-199)|(1300-2699)|WORD>$for_acl}", "Negate a command or set its defaults\n" "Configure label control and policies\n" "Configure remote/peer label control and policies\n" @@ -438,317 +311,204 @@ DEFUN (ldp_label_remote_accept, "IP access-list number (expanded range)\n" "IP access-list name\n") { - int idx = 0; - int negate = 0; - const char *from_acl = NULL; - const char *for_acl = NULL; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - - /* arguments within curly braces may be provided in any order */ - if (argv_find(argv, argc, "from", &idx)) - from_acl = argv[idx + 1]->arg; - idx = 0; - if (argv_find(argv, argc, "for", &idx)) - for_acl = argv[idx + 1]->arg; - - return (ldp_vty_label_accept(vty, negate, from_acl, for_acl)); + return (ldp_vty_label_accept(vty, no, from_acl, for_acl)); } -DEFUN (ldp_ttl_security_disable, +DEFPY (ldp_ttl_security_disable, ldp_ttl_security_disable_cmd, "[no] ttl-security disable", "Negate a command or set its defaults\n" "LDP ttl security check\n" "Disable ttl security\n") { - int idx = 0; - int negate = 0; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - - return (ldp_vty_ttl_security(vty, negate)); + return (ldp_vty_ttl_security(vty, no)); } -DEFUN (ldp_session_holdtime, +DEFPY (ldp_session_holdtime, ldp_session_holdtime_cmd, - "[no] session holdtime (15-65535)", + "[no] session holdtime (15-65535)$holdtime", "Negate a command or set its defaults\n" "Configure session parameters\n" "Configure session holdtime\n" "Time (seconds)\n") { - int idx = 0; - int negate = 0; - const char *holdtime; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "(15-65535)", &idx); - holdtime = argv[idx]->arg; - - return (ldp_vty_af_session_holdtime(vty, negate, holdtime)); + return (ldp_vty_af_session_holdtime(vty, no, holdtime)); } DEFUN_NOSH(ldp_interface, ldp_interface_cmd, - "[no] interface IFNAME", - "Negate a command or set its defaults\n" + "interface IFNAME", "Enable LDP on an interface and enter interface submode\n" "Interface's name\n") { int idx = 0; - int negate = 0; const char *ifname; - if (argv_find(argv, argc, "no", &idx)) - negate = 1; argv_find(argv, argc, "IFNAME", &idx); ifname = argv[idx]->arg; - return (ldp_vty_interface(vty, negate, ifname)); + return (ldp_vty_interface(vty, 0, ifname)); } -DEFUN (ldp_neighbor_ipv4_targeted, +DEFPY (no_ldp_interface, + no_ldp_interface_cmd, + "no interface IFNAME$ifname", + "Negate a command or set its defaults\n" + "Enable LDP on an interface and enter interface submode\n" + "Interface's name\n") +{ + return (ldp_vty_interface(vty, "no", ifname)); +} + +DEFPY (ldp_neighbor_ipv4_targeted, ldp_neighbor_ipv4_targeted_cmd, - "[no] neighbor A.B.C.D targeted", + "[no] neighbor A.B.C.D$address targeted", "Negate a command or set its defaults\n" "Configure neighbor parameters\n" "IP address of neighbor\n" "Establish targeted session\n") { - int idx = 0; - int negate = 0; - const char *address; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "A.B.C.D", &idx); - address = argv[idx]->arg; - - return (ldp_vty_neighbor_targeted(vty, negate, address)); + return (ldp_vty_neighbor_targeted(vty, no, address_str)); } -DEFUN (ldp_neighbor_ipv6_targeted, +DEFPY (ldp_neighbor_ipv6_targeted, ldp_neighbor_ipv6_targeted_cmd, - "[no] neighbor X:X::X:X targeted", + "[no] neighbor X:X::X:X$address targeted", "Negate a command or set its defaults\n" "Configure neighbor parameters\n" "IPv6 address of neighbor\n" "Establish targeted session\n") { - int idx = 0; - int negate = 0; - const char *address; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "X:X::X:X", &idx); - address = argv[idx]->arg; - - return (ldp_vty_neighbor_targeted(vty, negate, address)); + return (ldp_vty_neighbor_targeted(vty, no, address_str)); } -DEFUN (ldp_bridge, +DEFPY (ldp_bridge, ldp_bridge_cmd, - "[no] bridge IFNAME", + "[no] bridge IFNAME$ifname", "Negate a command or set its defaults\n" "Bridge interface\n" "Interface's name\n") { - int idx = 0; - int negate = 0; - const char *ifname; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "IFNAME", &idx); - ifname = argv[idx]->arg; - - return (ldp_vty_l2vpn_bridge(vty, negate, ifname)); + return (ldp_vty_l2vpn_bridge(vty, no, ifname)); } -DEFUN (ldp_mtu, +DEFPY (ldp_mtu, ldp_mtu_cmd, - "[no] mtu (1500-9180)", + "[no] mtu (1500-9180)$mtu", "Negate a command or set its defaults\n" "Set Maximum Transmission Unit\n" "Maximum Transmission Unit value\n") { - int idx = 0; - int negate = 0; - const char *mtu; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "(1500-9180)", &idx); - mtu = argv[idx]->arg; - - return (ldp_vty_l2vpn_mtu(vty, negate, mtu)); + return (ldp_vty_l2vpn_mtu(vty, no, mtu)); } -DEFUN (ldp_member_interface, +DEFPY (ldp_member_interface, ldp_member_interface_cmd, - "[no] member interface IFNAME", + "[no] member interface IFNAME$ifname", "Negate a command or set its defaults\n" "L2VPN member configuration\n" "Local interface\n" "Interface's name\n") { - int idx = 0; - int negate = 0; - const char *ifname; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "IFNAME", &idx); - ifname = argv[idx]->arg; - - return (ldp_vty_l2vpn_interface(vty, negate, ifname)); + return (ldp_vty_l2vpn_interface(vty, no, ifname)); } DEFUN_NOSH(ldp_member_pseudowire, ldp_member_pseudowire_cmd, - "[no] member pseudowire IFNAME", - "Negate a command or set its defaults\n" + "member pseudowire IFNAME", "L2VPN member configuration\n" "Pseudowire interface\n" "Interface's name\n") { int idx = 0; - int negate = 0; const char *ifname; - if (argv_find(argv, argc, "no", &idx)) - negate = 1; argv_find(argv, argc, "IFNAME", &idx); ifname = argv[idx]->arg; - return (ldp_vty_l2vpn_pseudowire(vty, negate, ifname)); + return (ldp_vty_l2vpn_pseudowire(vty, 0, ifname)); +} + +DEFPY (no_ldp_member_pseudowire, + no_ldp_member_pseudowire_cmd, + "no member pseudowire IFNAME$ifname", + "Negate a command or set its defaults\n" + "L2VPN member configuration\n" + "Pseudowire interface\n" + "Interface's name\n") +{ + return (ldp_vty_l2vpn_pseudowire(vty, "no", ifname)); } -DEFUN (ldp_vc_type, +DEFPY (ldp_vc_type, ldp_vc_type_cmd, - "[no] vc type <ethernet|ethernet-tagged>", + "[no] vc type <ethernet|ethernet-tagged>$vc_type", "Negate a command or set its defaults\n" "Virtual Circuit options\n" "Virtual Circuit type to use\n" "Ethernet (type 5)\n" "Ethernet-tagged (type 4)\n") { - int idx = 0; - int negate = 0; - const char *vc_type; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "type", &idx); - vc_type = argv[idx + 1]->text; - - return (ldp_vty_l2vpn_pwtype(vty, negate, vc_type)); + return (ldp_vty_l2vpn_pwtype(vty, no, vc_type)); } -DEFUN (ldp_control_word, +DEFPY (ldp_control_word, ldp_control_word_cmd, - "[no] control-word <exclude|include>", + "[no] control-word <exclude|include>$preference", "Negate a command or set its defaults\n" "Control-word options\n" "Exclude control-word in pseudowire packets\n" "Include control-word in pseudowire packets\n") { - int idx = 0; - int negate = 0; - const char *preference; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "control-word", &idx); - preference = argv[idx + 1]->text; - - return (ldp_vty_l2vpn_pw_cword(vty, negate, preference)); + return (ldp_vty_l2vpn_pw_cword(vty, no, preference)); } -DEFUN (ldp_neighbor_address, +DEFPY (ldp_neighbor_address, ldp_neighbor_address_cmd, - "[no] neighbor address <A.B.C.D|X:X::X:X>", + "[no] neighbor address <A.B.C.D|X:X::X:X>$pw_address", "Negate a command or set its defaults\n" "Remote endpoint configuration\n" "Specify the IPv4 or IPv6 address of the remote endpoint\n" "IPv4 address\n" "IPv6 address\n") { - int idx = 0; - int negate = 0; - const char *address; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "address", &idx); - address = argv[idx + 1]->arg; - - return (ldp_vty_l2vpn_pw_nbr_addr(vty, negate, address)); + return (ldp_vty_l2vpn_pw_nbr_addr(vty, no, pw_address_str)); } -DEFUN (ldp_neighbor_lsr_id, +DEFPY (ldp_neighbor_lsr_id, ldp_neighbor_lsr_id_cmd, - "[no] neighbor lsr-id A.B.C.D", + "[no] neighbor lsr-id A.B.C.D$address", "Negate a command or set its defaults\n" "Remote endpoint configuration\n" "Specify the LSR-ID of the remote endpoint\n" "IPv4 address\n") { - int idx = 0; - int negate = 0; - const char *address; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "A.B.C.D", &idx); - address = argv[idx]->arg; - - return (ldp_vty_l2vpn_pw_nbr_id(vty, negate, address)); + return (ldp_vty_l2vpn_pw_nbr_id(vty, no, address)); } -DEFUN (ldp_pw_id, +DEFPY (ldp_pw_id, ldp_pw_id_cmd, - "[no] pw-id (1-4294967295)", + "[no] pw-id (1-4294967295)$pwid", "Negate a command or set its defaults\n" "Set the Virtual Circuit ID\n" "Virtual Circuit ID value\n") { - int idx = 0; - int negate = 0; - const char *pwid; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "(1-4294967295)", &idx); - pwid = argv[idx]->arg; - - return (ldp_vty_l2vpn_pw_pwid(vty, negate, pwid)); + return (ldp_vty_l2vpn_pw_pwid(vty, no, pwid)); } -DEFUN (ldp_pw_status_disable, +DEFPY (ldp_pw_status_disable, ldp_pw_status_disable_cmd, "[no] pw-status disable", "Negate a command or set its defaults\n" "Configure PW status\n" "Disable PW status\n") { - int idx = 0; - int negate = 0; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - - return (ldp_vty_l2vpn_pw_pwstatus(vty, negate)); + return (ldp_vty_l2vpn_pw_pwstatus(vty, no)); } -DEFUN (ldp_clear_mpls_ldp_neighbor, +DEFPY (ldp_clear_mpls_ldp_neighbor, ldp_clear_mpls_ldp_neighbor_cmd, - "clear mpls ldp neighbor [<A.B.C.D|X:X::X:X>]", + "clear mpls ldp neighbor [<A.B.C.D|X:X::X:X>]$address", "Reset functions\n" "Reset MPLS statistical information\n" "Clear LDP state\n" @@ -756,18 +516,12 @@ DEFUN (ldp_clear_mpls_ldp_neighbor, "IPv4 address\n" "IPv6 address\n") { - int idx = 0; - const char *address = NULL; - - if (argv_find(argv, argc, "neighbor", &idx)) - address = argv[idx + 1]->arg; - - return (ldp_vty_clear_nbr(vty, address)); + return (ldp_vty_clear_nbr(vty, address_str)); } -DEFUN (ldp_debug_mpls_ldp_discovery_hello, +DEFPY (ldp_debug_mpls_ldp_discovery_hello, ldp_debug_mpls_ldp_discovery_hello_cmd, - "[no] debug mpls ldp discovery hello <recv|sent>", + "[no] debug mpls ldp discovery hello <recv|sent>$dir", "Negate a command or set its defaults\n" "Debugging functions\n" "MPLS information\n" @@ -777,21 +531,12 @@ DEFUN (ldp_debug_mpls_ldp_discovery_hello, "Received messages\n" "Sent messages\n") { - int idx = 0; - int negate = 0; - const char *dir; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "hello", &idx); - dir = argv[idx + 1]->text; - - return (ldp_vty_debug(vty, negate, "discovery", dir, 0)); + return (ldp_vty_debug(vty, no, "discovery", dir, NULL)); } -DEFUN (ldp_debug_mpls_ldp_type, +DEFPY (ldp_debug_mpls_ldp_type, ldp_debug_mpls_ldp_type_cmd, - "[no] debug mpls ldp <errors|event|zebra>", + "[no] debug mpls ldp <errors|event|zebra>$type", "Negate a command or set its defaults\n" "Debugging functions\n" "MPLS information\n" @@ -800,21 +545,12 @@ DEFUN (ldp_debug_mpls_ldp_type, "LDP event information\n" "LDP zebra information\n") { - int idx = 0; - int negate = 0; - const char *type; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "ldp", &idx); - type = argv[idx + 1]->text; - - return (ldp_vty_debug(vty, negate, type, NULL, 0)); + return (ldp_vty_debug(vty, no, type, NULL, NULL)); } -DEFUN (ldp_debug_mpls_ldp_messages_recv, +DEFPY (ldp_debug_mpls_ldp_messages_recv, ldp_debug_mpls_ldp_messages_recv_cmd, - "[no] debug mpls ldp messages recv [all]", + "[no] debug mpls ldp messages recv [all]$all", "Negate a command or set its defaults\n" "Debugging functions\n" "MPLS information\n" @@ -823,21 +559,12 @@ DEFUN (ldp_debug_mpls_ldp_messages_recv, "Received messages, excluding periodic Keep Alives\n" "Received messages, including periodic Keep Alives\n") { - int idx = 0; - int negate = 0; - int all = 0; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - if (argv_find(argv, argc, "all", &idx)) - all = 1; - - return (ldp_vty_debug(vty, negate, "messages", "recv", all)); + return (ldp_vty_debug(vty, no, "messages", "recv", all)); } -DEFUN (ldp_debug_mpls_ldp_messages_sent, +DEFPY (ldp_debug_mpls_ldp_messages_sent, ldp_debug_mpls_ldp_messages_sent_cmd, - "[no] debug mpls ldp messages sent [all]", + "[no] debug mpls ldp messages sent [all]$all", "Negate a command or set its defaults\n" "Debugging functions\n" "MPLS information\n" @@ -846,21 +573,12 @@ DEFUN (ldp_debug_mpls_ldp_messages_sent, "Sent messages, excluding periodic Keep Alives\n" "Sent messages, including periodic Keep Alives\n") { - int idx = 0; - int negate = 0; - int all = 0; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - if (argv_find(argv, argc, "all", &idx)) - all = 1; - - return (ldp_vty_debug(vty, negate, "messages", "sent", all)); + return (ldp_vty_debug(vty, no, "messages", "sent", all)); } -DEFUN (ldp_show_mpls_ldp_binding, +DEFPY (ldp_show_mpls_ldp_binding, ldp_show_mpls_ldp_binding_cmd, - "show mpls ldp [<ipv4|ipv6>] binding [detail] [json]", + "show mpls ldp [<ipv4|ipv6>]$af binding [detail]$detail [json]$json", "Show running system information\n" "MPLS information\n" "Label Distribution Protocol\n" @@ -870,25 +588,12 @@ DEFUN (ldp_show_mpls_ldp_binding, "Show detailed information\n" "JavaScript Object Notation\n") { - int idx = 0; - const char *af = NULL; - int detail = 0; - int json = 0; - - if (argv_find(argv, argc, "ipv4", &idx) || - argv_find(argv, argc, "ipv6", &idx)) - af = argv[idx]->text; - if (argv_find(argv, argc, "detail", &idx)) - detail = 1; - if (argv_find(argv, argc, "json", &idx)) - json = 1; - return (ldp_vty_show_binding(vty, af, detail, json)); } -DEFUN (ldp_show_mpls_ldp_discovery, +DEFPY (ldp_show_mpls_ldp_discovery, ldp_show_mpls_ldp_discovery_cmd, - "show mpls ldp [<ipv4|ipv6>] discovery [detail] [json]", + "show mpls ldp [<ipv4|ipv6>]$af discovery [detail]$detail [json]$json", "Show running system information\n" "MPLS information\n" "Label Distribution Protocol\n" @@ -898,25 +603,12 @@ DEFUN (ldp_show_mpls_ldp_discovery, "Show detailed information\n" "JavaScript Object Notation\n") { - int idx = 0; - const char *af = NULL; - int detail = 0; - int json = 0; - - if (argv_find(argv, argc, "ipv4", &idx) || - argv_find(argv, argc, "ipv6", &idx)) - af = argv[idx]->text; - if (argv_find(argv, argc, "detail", &idx)) - detail = 1; - if (argv_find(argv, argc, "json", &idx)) - json = 1; - return (ldp_vty_show_discovery(vty, af, detail, json)); } -DEFUN (ldp_show_mpls_ldp_interface, +DEFPY (ldp_show_mpls_ldp_interface, ldp_show_mpls_ldp_interface_cmd, - "show mpls ldp [<ipv4|ipv6>] interface [json]", + "show mpls ldp [<ipv4|ipv6>]$af interface [json]$json", "Show running system information\n" "MPLS information\n" "Label Distribution Protocol\n" @@ -925,40 +617,24 @@ DEFUN (ldp_show_mpls_ldp_interface, "interface information\n" "JavaScript Object Notation\n") { - int idx = 0; - const char *af = NULL; - int json = 0; - - if (argv_find(argv, argc, "ipv4", &idx) || - argv_find(argv, argc, "ipv6", &idx)) - af = argv[idx]->text; - if (argv_find(argv, argc, "json", &idx)) - json = 1; - return (ldp_vty_show_interface(vty, af, json)); } -DEFUN (ldp_show_mpls_ldp_capabilities, +DEFPY (ldp_show_mpls_ldp_capabilities, ldp_show_mpls_ldp_capabilities_cmd, - "show mpls ldp capabilities [json]", + "show mpls ldp capabilities [json]$json", "Show running system information\n" "MPLS information\n" "Label Distribution Protocol\n" "Display LDP Capabilities information\n" "JavaScript Object Notation\n") { - int idx = 0; - int json = 0; - - if (argv_find(argv, argc, "json", &idx)) - json = 1; - return (ldp_vty_show_capabilities(vty, json)); } -DEFUN (ldp_show_mpls_ldp_neighbor, +DEFPY (ldp_show_mpls_ldp_neighbor, ldp_show_mpls_ldp_neighbor_cmd, - "show mpls ldp neighbor [detail] [json]", + "show mpls ldp neighbor [detail]$detail [json]$json", "Show running system information\n" "MPLS information\n" "Label Distribution Protocol\n" @@ -966,21 +642,12 @@ DEFUN (ldp_show_mpls_ldp_neighbor, "Show detailed information\n" "JavaScript Object Notation\n") { - int idx = 0; - int detail = 0; - int json = 0; - - if (argv_find(argv, argc, "detail", &idx)) - detail = 1; - if (argv_find(argv, argc, "json", &idx)) - json = 1; - return (ldp_vty_show_neighbor(vty, 0, detail, json)); } -DEFUN (ldp_show_mpls_ldp_neighbor_capabilities, +DEFPY (ldp_show_mpls_ldp_neighbor_capabilities, ldp_show_mpls_ldp_neighbor_capabilities_cmd, - "show mpls ldp neighbor capabilities [json]", + "show mpls ldp neighbor capabilities [json]$json", "Show running system information\n" "MPLS information\n" "Label Distribution Protocol\n" @@ -988,52 +655,34 @@ DEFUN (ldp_show_mpls_ldp_neighbor_capabilities, "Display neighbor capability information\n" "JavaScript Object Notation\n") { - int idx = 0; - int json = 0; - - if (argv_find(argv, argc, "json", &idx)) - json = 1; - - return (ldp_vty_show_neighbor(vty, 1, 0, json)); + return (ldp_vty_show_neighbor(vty, 1, NULL, json)); } -DEFUN (ldp_show_l2vpn_atom_binding, +DEFPY (ldp_show_l2vpn_atom_binding, ldp_show_l2vpn_atom_binding_cmd, - "show l2vpn atom binding [json]", + "show l2vpn atom binding [json]$json", "Show running system information\n" "Show information about Layer2 VPN\n" "Show Any Transport over MPLS information\n" "Show AToM label binding information\n" "JavaScript Object Notation\n") { - int idx = 0; - int json = 0; - - if (argv_find(argv, argc, "json", &idx)) - json = 1; - return (ldp_vty_show_atom_binding(vty, json)); } -DEFUN (ldp_show_l2vpn_atom_vc, +DEFPY (ldp_show_l2vpn_atom_vc, ldp_show_l2vpn_atom_vc_cmd, - "show l2vpn atom vc [json]", + "show l2vpn atom vc [json]$json", "Show running system information\n" "Show information about Layer2 VPN\n" "Show Any Transport over MPLS information\n" "Show AToM virtual circuit information\n" "JavaScript Object Notation\n") { - int idx = 0; - int json = 0; - - if (argv_find(argv, argc, "json", &idx)) - json = 1; - return (ldp_vty_show_atom_vc(vty, json)); } -DEFUN (ldp_show_debugging_mpls_ldp, +DEFPY (ldp_show_debugging_mpls_ldp, ldp_show_debugging_mpls_ldp_cmd, "show debugging mpls ldp", "Show running system information\n" @@ -1044,9 +693,30 @@ DEFUN (ldp_show_debugging_mpls_ldp, return (ldp_vty_show_debugging(vty)); } +static void +l2vpn_autocomplete(vector comps, struct cmd_token *token) +{ + struct l2vpn *l2vpn; + + RB_FOREACH(l2vpn, l2vpn_head, &vty_conf->l2vpn_tree) + vector_set(comps, XSTRDUP(MTYPE_COMPLETION, l2vpn->name)); +} + +static const struct cmd_variable_handler l2vpn_var_handlers[] = { + { + .varname = "l2vpn_name", + .completions = l2vpn_autocomplete + }, + { + .completions = NULL + } +}; + void ldp_vty_init (void) { + cmd_variable_handler_register(l2vpn_var_handlers); + install_node(&ldp_node, ldp_config_write); install_node(&ldp_ipv4_node, NULL); install_node(&ldp_ipv6_node, NULL); @@ -1064,13 +734,16 @@ ldp_vty_init (void) install_default(LDP_PSEUDOWIRE_NODE); install_element(CONFIG_NODE, &ldp_mpls_ldp_cmd); + install_element(CONFIG_NODE, &no_ldp_mpls_ldp_cmd); install_element(CONFIG_NODE, &ldp_l2vpn_cmd); + install_element(CONFIG_NODE, &no_ldp_l2vpn_cmd); install_element(CONFIG_NODE, &ldp_debug_mpls_ldp_discovery_hello_cmd); install_element(CONFIG_NODE, &ldp_debug_mpls_ldp_type_cmd); install_element(CONFIG_NODE, &ldp_debug_mpls_ldp_messages_recv_cmd); install_element(CONFIG_NODE, &ldp_debug_mpls_ldp_messages_sent_cmd); install_element(LDP_NODE, &ldp_address_family_cmd); + install_element(LDP_NODE, &no_ldp_address_family_cmd); install_element(LDP_NODE, &ldp_discovery_holdtime_cmd); install_element(LDP_NODE, &ldp_discovery_interval_cmd); install_element(LDP_NODE, &ldp_dual_stack_transport_connection_prefer_ipv4_cmd); @@ -1090,6 +763,7 @@ ldp_vty_init (void) install_element(LDP_IPV4_NODE, &ldp_label_remote_accept_cmd); install_element(LDP_IPV4_NODE, &ldp_ttl_security_disable_cmd); install_element(LDP_IPV4_NODE, &ldp_interface_cmd); + install_element(LDP_IPV4_NODE, &no_ldp_interface_cmd); install_element(LDP_IPV4_NODE, &ldp_session_holdtime_cmd); install_element(LDP_IPV4_NODE, &ldp_neighbor_ipv4_targeted_cmd); install_element(LDP_IPV4_NODE, &ldp_exit_address_family_cmd); @@ -1118,6 +792,7 @@ ldp_vty_init (void) install_element(LDP_L2VPN_NODE, &ldp_mtu_cmd); install_element(LDP_L2VPN_NODE, &ldp_member_interface_cmd); install_element(LDP_L2VPN_NODE, &ldp_member_pseudowire_cmd); + install_element(LDP_L2VPN_NODE, &no_ldp_member_pseudowire_cmd); install_element(LDP_L2VPN_NODE, &ldp_vc_type_cmd); install_element(LDP_PSEUDOWIRE_NODE, &ldp_control_word_cmd); diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index 09eb6a7c55..e938582d0d 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -407,9 +407,9 @@ ldp_iface_is_configured(struct ldpd_conf *xconf, const char *ifname) } int -ldp_vty_mpls_ldp(struct vty *vty, int disable) +ldp_vty_mpls_ldp(struct vty *vty, const char *negate) { - if (disable) + if (negate) vty_conf->flags &= ~F_LDPD_ENABLED; else { vty->node = LDP_NODE; @@ -422,7 +422,7 @@ ldp_vty_mpls_ldp(struct vty *vty, int disable) } int -ldp_vty_address_family(struct vty *vty, int disable, const char *af_str) +ldp_vty_address_family(struct vty *vty, const char *negate, const char *af_str) { struct ldpd_af_conf *af_conf; int af; @@ -436,7 +436,7 @@ ldp_vty_address_family(struct vty *vty, int disable, const char *af_str) } else return (CMD_WARNING_CONFIG_FAILED); - if (disable) { + if (negate) { af_conf->flags &= ~F_LDPD_AF_ENABLED; ldp_config_apply(vty, vty_conf); return (CMD_SUCCESS); @@ -460,23 +460,15 @@ ldp_vty_address_family(struct vty *vty, int disable, const char *af_str) } int -ldp_vty_disc_holdtime(struct vty *vty, int disable, const char *hello_type_str, - const char *seconds_str) +ldp_vty_disc_holdtime(struct vty *vty, const char *negate, + const char *hello_type_str, long secs) { struct ldpd_af_conf *af_conf; struct iface *iface; struct iface_af *ia; int af; - char *ep; - long int secs; enum hello_type hello_type; - secs = strtol(seconds_str, &ep, 10); - if (*ep != '\0' || secs < MIN_HOLDTIME || secs > MAX_HOLDTIME) { - vty_out (vty, "%% Invalid holdtime\n"); - return (CMD_WARNING_CONFIG_FAILED); - } - if (hello_type_str[0] == 'h') hello_type = HELLO_LINK; else @@ -484,7 +476,7 @@ ldp_vty_disc_holdtime(struct vty *vty, int disable, const char *hello_type_str, switch (vty->node) { case LDP_NODE: - if (disable) { + if (negate) { switch (hello_type) { case HELLO_LINK: vty_conf->lhello_holdtime = LINK_DFLT_HOLDTIME; @@ -511,7 +503,7 @@ ldp_vty_disc_holdtime(struct vty *vty, int disable, const char *hello_type_str, af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) { + if (negate) { switch (hello_type) { case HELLO_LINK: af_conf->lhello_holdtime = 0; @@ -539,7 +531,7 @@ ldp_vty_disc_holdtime(struct vty *vty, int disable, const char *hello_type_str, VTY_CHECK_CONTEXT(iface); ia = iface_af_get(iface, af); - if (disable) + if (negate) ia->hello_holdtime = 0; else ia->hello_holdtime = secs; @@ -554,24 +546,15 @@ ldp_vty_disc_holdtime(struct vty *vty, int disable, const char *hello_type_str, } int -ldp_vty_disc_interval(struct vty *vty, int disable, const char *hello_type_str, - const char *seconds_str) +ldp_vty_disc_interval(struct vty *vty, const char *negate, + const char *hello_type_str, long secs) { struct ldpd_af_conf *af_conf; struct iface *iface; struct iface_af *ia; int af; - char *ep; - long int secs; enum hello_type hello_type; - secs = strtol(seconds_str, &ep, 10); - if (*ep != '\0' || secs < MIN_HELLO_INTERVAL || - secs > MAX_HELLO_INTERVAL) { - vty_out (vty, "%% Invalid interval\n"); - return (CMD_WARNING_CONFIG_FAILED); - } - if (hello_type_str[0] == 'h') hello_type = HELLO_LINK; else @@ -579,14 +562,15 @@ ldp_vty_disc_interval(struct vty *vty, int disable, const char *hello_type_str, switch (vty->node) { case LDP_NODE: - if (disable) { + if (negate) { switch (hello_type) { case HELLO_LINK: - vty_conf->lhello_interval = LINK_DFLT_HOLDTIME; + vty_conf->lhello_interval = + DEFAULT_HELLO_INTERVAL; break; case HELLO_TARGETED: vty_conf->thello_interval = - TARGETED_DFLT_HOLDTIME; + DEFAULT_HELLO_INTERVAL; break; } } else { @@ -606,7 +590,7 @@ ldp_vty_disc_interval(struct vty *vty, int disable, const char *hello_type_str, af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) { + if (negate) { switch (hello_type) { case HELLO_LINK: af_conf->lhello_interval = 0; @@ -634,7 +618,7 @@ ldp_vty_disc_interval(struct vty *vty, int disable, const char *hello_type_str, VTY_CHECK_CONTEXT(iface); ia = iface_af_get(iface, af); - if (disable) + if (negate) ia->hello_interval = 0; else ia->hello_interval = secs; @@ -649,7 +633,7 @@ ldp_vty_disc_interval(struct vty *vty, int disable, const char *hello_type_str, } int -ldp_vty_targeted_hello_accept(struct vty *vty, int disable, +ldp_vty_targeted_hello_accept(struct vty *vty, const char *negate, const char *acl_from_str) { struct ldpd_af_conf *af_conf; @@ -658,7 +642,7 @@ ldp_vty_targeted_hello_accept(struct vty *vty, int disable, af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) { + if (negate) { af_conf->flags &= ~F_LDPD_AF_THELLO_ACCEPT; af_conf->acl_thello_accept_from[0] = '\0'; } else { @@ -676,29 +660,19 @@ ldp_vty_targeted_hello_accept(struct vty *vty, int disable, } int -ldp_vty_nbr_session_holdtime(struct vty *vty, int disable, - const char *lsr_id_str, const char *seconds_str) +ldp_vty_nbr_session_holdtime(struct vty *vty, const char *negate, + struct in_addr lsr_id, long secs) { - char *ep; - long int secs; - struct in_addr lsr_id; struct nbr_params *nbrp; - if (inet_pton(AF_INET, lsr_id_str, &lsr_id) != 1 || - bad_addr_v4(lsr_id)) { + if (bad_addr_v4(lsr_id)) { vty_out (vty, "%% Malformed address\n"); return (CMD_WARNING_CONFIG_FAILED); } - secs = strtol(seconds_str, &ep, 10); - if (*ep != '\0' || secs < MIN_KEEPALIVE || secs > MAX_KEEPALIVE) { - vty_out (vty, "%% Invalid holdtime\n"); - return (CMD_SUCCESS); - } - nbrp = nbr_params_find(vty_conf, lsr_id); - if (disable) { + if (negate) { if (nbrp == NULL) return (CMD_SUCCESS); @@ -722,24 +696,15 @@ ldp_vty_nbr_session_holdtime(struct vty *vty, int disable, } int -ldp_vty_af_session_holdtime(struct vty *vty, int disable, - const char *seconds_str) +ldp_vty_af_session_holdtime(struct vty *vty, const char *negate, long secs) { struct ldpd_af_conf *af_conf; int af; - char *ep; - long int secs; - - secs = strtol(seconds_str, &ep, 10); - if (*ep != '\0' || secs < MIN_KEEPALIVE || secs > MAX_KEEPALIVE) { - vty_out (vty, "%% Invalid holdtime\n"); - return (CMD_SUCCESS); - } af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) + if (negate) af_conf->keepalive = DEFAULT_KEEPALIVE; else af_conf->keepalive = secs; @@ -750,7 +715,7 @@ ldp_vty_af_session_holdtime(struct vty *vty, int disable, } int -ldp_vty_interface(struct vty *vty, int disable, const char *ifname) +ldp_vty_interface(struct vty *vty, const char *negate, const char *ifname) { int af; struct iface *iface; @@ -759,7 +724,7 @@ ldp_vty_interface(struct vty *vty, int disable, const char *ifname) af = ldp_vty_get_af(vty); iface = if_lookup_name(vty_conf, ifname); - if (disable) { + if (negate) { if (iface == NULL) return (CMD_SUCCESS); @@ -812,7 +777,7 @@ ldp_vty_interface(struct vty *vty, int disable, const char *ifname) } int -ldp_vty_trans_addr(struct vty *vty, int disable, const char *addr_str) +ldp_vty_trans_addr(struct vty *vty, const char *negate, const char *addr_str) { struct ldpd_af_conf *af_conf; int af; @@ -820,7 +785,7 @@ ldp_vty_trans_addr(struct vty *vty, int disable, const char *addr_str) af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) + if (negate) memset(&af_conf->trans_addr, 0, sizeof(af_conf->trans_addr)); else { if (inet_pton(af, addr_str, &af_conf->trans_addr) != 1 || @@ -836,7 +801,7 @@ ldp_vty_trans_addr(struct vty *vty, int disable, const char *addr_str) } int -ldp_vty_neighbor_targeted(struct vty *vty, int disable, const char *addr_str) +ldp_vty_neighbor_targeted(struct vty *vty, const char *negate, const char *addr_str) { int af; union ldpd_addr addr; @@ -856,7 +821,7 @@ ldp_vty_neighbor_targeted(struct vty *vty, int disable, const char *addr_str) tnbr = tnbr_find(vty_conf, af, &addr); - if (disable) { + if (negate) { if (tnbr == NULL) return (CMD_SUCCESS); @@ -883,7 +848,7 @@ ldp_vty_neighbor_targeted(struct vty *vty, int disable, const char *addr_str) } int -ldp_vty_label_advertise(struct vty *vty, int disable, const char *acl_to_str, +ldp_vty_label_advertise(struct vty *vty, const char *negate, const char *acl_to_str, const char *acl_for_str) { struct ldpd_af_conf *af_conf; @@ -892,7 +857,7 @@ ldp_vty_label_advertise(struct vty *vty, int disable, const char *acl_to_str, af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) { + if (negate) { af_conf->acl_label_advertise_to[0] = '\0'; af_conf->acl_label_advertise_for[0] = '\0'; } else { @@ -914,7 +879,7 @@ ldp_vty_label_advertise(struct vty *vty, int disable, const char *acl_to_str, } int -ldp_vty_label_allocate(struct vty *vty, int disable, int host_routes, +ldp_vty_label_allocate(struct vty *vty, const char *negate, const char *host_routes, const char *acl_for_str) { struct ldpd_af_conf *af_conf; @@ -925,7 +890,7 @@ ldp_vty_label_allocate(struct vty *vty, int disable, int host_routes, af_conf->flags &= ~F_LDPD_AF_ALLOCHOSTONLY; af_conf->acl_label_allocate_for[0] = '\0'; - if (!disable) { + if (!negate) { if (host_routes) af_conf->flags |= F_LDPD_AF_ALLOCHOSTONLY; else @@ -939,7 +904,7 @@ ldp_vty_label_allocate(struct vty *vty, int disable, int host_routes, } int -ldp_vty_label_expnull(struct vty *vty, int disable, const char *acl_for_str) +ldp_vty_label_expnull(struct vty *vty, const char *negate, const char *acl_for_str) { struct ldpd_af_conf *af_conf; int af; @@ -947,7 +912,7 @@ ldp_vty_label_expnull(struct vty *vty, int disable, const char *acl_for_str) af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) { + if (negate) { af_conf->flags &= ~F_LDPD_AF_EXPNULL; af_conf->acl_label_expnull_for[0] = '\0'; } else { @@ -965,7 +930,7 @@ ldp_vty_label_expnull(struct vty *vty, int disable, const char *acl_for_str) } int -ldp_vty_label_accept(struct vty *vty, int disable, const char *acl_from_str, +ldp_vty_label_accept(struct vty *vty, const char *negate, const char *acl_from_str, const char *acl_for_str) { struct ldpd_af_conf *af_conf; @@ -974,7 +939,7 @@ ldp_vty_label_accept(struct vty *vty, int disable, const char *acl_from_str, af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) { + if (negate) { af_conf->acl_label_accept_from[0] = '\0'; af_conf->acl_label_accept_for[0] = '\0'; } else { @@ -996,7 +961,7 @@ ldp_vty_label_accept(struct vty *vty, int disable, const char *acl_from_str, } int -ldp_vty_ttl_security(struct vty *vty, int disable) +ldp_vty_ttl_security(struct vty *vty, const char *negate) { struct ldpd_af_conf *af_conf; int af; @@ -1004,7 +969,7 @@ ldp_vty_ttl_security(struct vty *vty, int disable) af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) + if (negate) af_conf->flags &= ~F_LDPD_AF_NO_GTSM; else af_conf->flags |= F_LDPD_AF_NO_GTSM; @@ -1015,16 +980,16 @@ ldp_vty_ttl_security(struct vty *vty, int disable) } int -ldp_vty_router_id(struct vty *vty, int disable, const char *addr_str) +ldp_vty_router_id(struct vty *vty, const char *negate, struct in_addr address) { - if (disable) + if (negate) vty_conf->rtr_id.s_addr = INADDR_ANY; else { - if (inet_pton(AF_INET, addr_str, &vty_conf->rtr_id) != 1 || - bad_addr_v4(vty_conf->rtr_id)) { + if (bad_addr_v4(address)) { vty_out (vty, "%% Malformed address\n"); return (CMD_SUCCESS); } + vty_conf->rtr_id = address; } ldp_config_apply(vty, vty_conf); @@ -1033,9 +998,9 @@ ldp_vty_router_id(struct vty *vty, int disable, const char *addr_str) } int -ldp_vty_ds_cisco_interop(struct vty *vty, int disable) +ldp_vty_ds_cisco_interop(struct vty *vty, const char * negate) { - if (disable) + if (negate) vty_conf->flags &= ~F_LDPD_DS_CISCO_INTEROP; else vty_conf->flags |= F_LDPD_DS_CISCO_INTEROP; @@ -1046,9 +1011,9 @@ ldp_vty_ds_cisco_interop(struct vty *vty, int disable) } int -ldp_vty_trans_pref_ipv4(struct vty *vty, int disable) +ldp_vty_trans_pref_ipv4(struct vty *vty, const char *negate) { - if (disable) + if (negate) vty_conf->trans_pref = DUAL_STACK_LDPOV6; else vty_conf->trans_pref = DUAL_STACK_LDPOV4; @@ -1059,22 +1024,20 @@ ldp_vty_trans_pref_ipv4(struct vty *vty, int disable) } int -ldp_vty_neighbor_password(struct vty *vty, int disable, const char *lsr_id_str, +ldp_vty_neighbor_password(struct vty *vty, const char *negate, struct in_addr lsr_id, const char *password_str) { - struct in_addr lsr_id; size_t password_len; struct nbr_params *nbrp; - if (inet_pton(AF_INET, lsr_id_str, &lsr_id) != 1 || - bad_addr_v4(lsr_id)) { + if (bad_addr_v4(lsr_id)) { vty_out (vty, "%% Malformed address\n"); return (CMD_WARNING_CONFIG_FAILED); } nbrp = nbr_params_find(vty_conf, lsr_id); - if (disable) { + if (negate) { if (nbrp == NULL) return (CMD_SUCCESS); @@ -1104,16 +1067,14 @@ ldp_vty_neighbor_password(struct vty *vty, int disable, const char *lsr_id_str, } int -ldp_vty_neighbor_ttl_security(struct vty *vty, int disable, - const char *lsr_id_str, const char *hops_str) +ldp_vty_neighbor_ttl_security(struct vty *vty, const char *negate, + struct in_addr lsr_id, const char *hops_str) { - struct in_addr lsr_id; struct nbr_params *nbrp; long int hops = 0; char *ep; - if (inet_pton(AF_INET, lsr_id_str, &lsr_id) != 1 || - bad_addr_v4(lsr_id)) { + if (bad_addr_v4(lsr_id)) { vty_out (vty, "%% Malformed address\n"); return (CMD_WARNING_CONFIG_FAILED); } @@ -1128,7 +1089,7 @@ ldp_vty_neighbor_ttl_security(struct vty *vty, int disable, nbrp = nbr_params_find(vty_conf, lsr_id); - if (disable) { + if (negate) { if (nbrp == NULL) return (CMD_SUCCESS); @@ -1158,7 +1119,7 @@ ldp_vty_neighbor_ttl_security(struct vty *vty, int disable, } int -ldp_vty_l2vpn(struct vty *vty, int disable, const char *name_str) +ldp_vty_l2vpn(struct vty *vty, const char *negate, const char *name_str) { struct l2vpn *l2vpn; struct l2vpn_if *lif; @@ -1166,7 +1127,7 @@ ldp_vty_l2vpn(struct vty *vty, int disable, const char *name_str) l2vpn = l2vpn_find(vty_conf, name_str); - if (disable) { + if (negate) { if (l2vpn == NULL) return (CMD_SUCCESS); @@ -1203,11 +1164,11 @@ ldp_vty_l2vpn(struct vty *vty, int disable, const char *name_str) } int -ldp_vty_l2vpn_bridge(struct vty *vty, int disable, const char *ifname) +ldp_vty_l2vpn_bridge(struct vty *vty, const char *negate, const char *ifname) { VTY_DECLVAR_CONTEXT(l2vpn, l2vpn); - if (disable) + if (negate) memset(l2vpn->br_ifname, 0, sizeof(l2vpn->br_ifname)); else strlcpy(l2vpn->br_ifname, ifname, sizeof(l2vpn->br_ifname)); @@ -1218,19 +1179,11 @@ ldp_vty_l2vpn_bridge(struct vty *vty, int disable, const char *ifname) } int -ldp_vty_l2vpn_mtu(struct vty *vty, int disable, const char *mtu_str) +ldp_vty_l2vpn_mtu(struct vty *vty, const char *negate, long mtu) { VTY_DECLVAR_CONTEXT(l2vpn, l2vpn); - char *ep; - int mtu; - - mtu = strtol(mtu_str, &ep, 10); - if (*ep != '\0' || mtu < MIN_L2VPN_MTU || mtu > MAX_L2VPN_MTU) { - vty_out (vty, "%% Invalid MTU\n"); - return (CMD_WARNING_CONFIG_FAILED); - } - if (disable) + if (negate) l2vpn->mtu = DEFAULT_L2VPN_MTU; else l2vpn->mtu = mtu; @@ -1241,7 +1194,7 @@ ldp_vty_l2vpn_mtu(struct vty *vty, int disable, const char *mtu_str) } int -ldp_vty_l2vpn_pwtype(struct vty *vty, int disable, const char *type_str) +ldp_vty_l2vpn_pwtype(struct vty *vty, const char *negate, const char *type_str) { VTY_DECLVAR_CONTEXT(l2vpn, l2vpn); int pw_type; @@ -1251,7 +1204,7 @@ ldp_vty_l2vpn_pwtype(struct vty *vty, int disable, const char *type_str) else pw_type = PW_TYPE_ETHERNET_TAGGED; - if (disable) + if (negate) l2vpn->pw_type = DEFAULT_PW_TYPE; else l2vpn->pw_type = pw_type; @@ -1262,14 +1215,14 @@ ldp_vty_l2vpn_pwtype(struct vty *vty, int disable, const char *type_str) } int -ldp_vty_l2vpn_interface(struct vty *vty, int disable, const char *ifname) +ldp_vty_l2vpn_interface(struct vty *vty, const char *negate, const char *ifname) { VTY_DECLVAR_CONTEXT(l2vpn, l2vpn); struct l2vpn_if *lif; lif = l2vpn_if_find(l2vpn, ifname); - if (disable) { + if (negate) { if (lif == NULL) return (CMD_SUCCESS); @@ -1300,14 +1253,14 @@ ldp_vty_l2vpn_interface(struct vty *vty, int disable, const char *ifname) } int -ldp_vty_l2vpn_pseudowire(struct vty *vty, int disable, const char *ifname) +ldp_vty_l2vpn_pseudowire(struct vty *vty, const char *negate, const char *ifname) { VTY_DECLVAR_CONTEXT(l2vpn, l2vpn); struct l2vpn_pw *pw; pw = l2vpn_pw_find(l2vpn, ifname); - if (disable) { + if (negate) { if (pw == NULL) return (CMD_SUCCESS); @@ -1346,11 +1299,11 @@ ldp_vty_l2vpn_pseudowire(struct vty *vty, int disable, const char *ifname) } int -ldp_vty_l2vpn_pw_cword(struct vty *vty, int disable, const char *preference_str) +ldp_vty_l2vpn_pw_cword(struct vty *vty, const char *negate, const char *preference_str) { VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw, pw); - if (disable) + if (negate) pw->flags |= F_PW_CWORD_CONF; else { if (preference_str[0] == 'e') @@ -1365,7 +1318,7 @@ ldp_vty_l2vpn_pw_cword(struct vty *vty, int disable, const char *preference_str) } int -ldp_vty_l2vpn_pw_nbr_addr(struct vty *vty, int disable, const char *addr_str) +ldp_vty_l2vpn_pw_nbr_addr(struct vty *vty, const char *negate, const char *addr_str) { VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw, pw); int af; @@ -1377,7 +1330,7 @@ ldp_vty_l2vpn_pw_nbr_addr(struct vty *vty, int disable, const char *addr_str) return (CMD_WARNING_CONFIG_FAILED); } - if (disable) { + if (negate) { pw->af = AF_UNSPEC; memset(&pw->addr, 0, sizeof(pw->addr)); pw->flags &= ~F_PW_STATIC_NBR_ADDR; @@ -1393,18 +1346,16 @@ ldp_vty_l2vpn_pw_nbr_addr(struct vty *vty, int disable, const char *addr_str) } int -ldp_vty_l2vpn_pw_nbr_id(struct vty *vty, int disable, const char *lsr_id_str) +ldp_vty_l2vpn_pw_nbr_id(struct vty *vty, const char *negate, struct in_addr lsr_id) { VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw, pw); - struct in_addr lsr_id; - if (inet_pton(AF_INET, lsr_id_str, &lsr_id) != 1 || - bad_addr_v4(lsr_id)) { + if (bad_addr_v4(lsr_id)) { vty_out (vty, "%% Malformed address\n"); return (CMD_WARNING_CONFIG_FAILED); } - if (disable) + if (negate) pw->lsr_id.s_addr = INADDR_ANY; else pw->lsr_id = lsr_id; @@ -1415,19 +1366,11 @@ ldp_vty_l2vpn_pw_nbr_id(struct vty *vty, int disable, const char *lsr_id_str) } int -ldp_vty_l2vpn_pw_pwid(struct vty *vty, int disable, const char *pwid_str) +ldp_vty_l2vpn_pw_pwid(struct vty *vty, const char *negate, long pwid) { VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw, pw); - char *ep; - uint32_t pwid; - - pwid = strtol(pwid_str, &ep, 10); - if (*ep != '\0' || pwid < MIN_PWID_ID || pwid > MAX_PWID_ID) { - vty_out (vty, "%% Invalid pw-id\n"); - return (CMD_WARNING_CONFIG_FAILED); - } - if (disable) + if (negate) pw->pwid = 0; else pw->pwid = pwid; @@ -1438,11 +1381,11 @@ ldp_vty_l2vpn_pw_pwid(struct vty *vty, int disable, const char *pwid_str) } int -ldp_vty_l2vpn_pw_pwstatus(struct vty *vty, int disable) +ldp_vty_l2vpn_pw_pwstatus(struct vty *vty, const char *negate) { VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw, pw); - if (disable) + if (negate) pw->flags |= F_PW_STATUSTLV_CONF; else pw->flags &= ~F_PW_STATUSTLV_CONF; diff --git a/ldpd/ldp_vty_exec.c b/ldpd/ldp_vty_exec.c index bec1375bd2..ad5e79c721 100644 --- a/ldpd/ldp_vty_exec.c +++ b/ldpd/ldp_vty_exec.c @@ -1565,7 +1565,7 @@ ldp_vty_get_af(const char *str, int *af) } int -ldp_vty_show_binding(struct vty *vty, const char *af_str, int detail, int json) +ldp_vty_show_binding(struct vty *vty, const char *af_str, const char *detail, const char *json) { struct imsgbuf ibuf; struct show_params params; @@ -1579,8 +1579,8 @@ ldp_vty_show_binding(struct vty *vty, const char *af_str, int detail, int json) memset(¶ms, 0, sizeof(params)); params.family = af; - params.detail = detail; - params.json = json; + params.detail = (detail) ? 1 : 0; + params.json = (json) ? 1 : 0; if (!params.detail && !params.json) vty_out (vty, "%-4s %-20s %-15s %-11s %-13s %6s\n", "AF", @@ -1592,8 +1592,8 @@ ldp_vty_show_binding(struct vty *vty, const char *af_str, int detail, int json) } int -ldp_vty_show_discovery(struct vty *vty, const char *af_str, int detail, - int json) +ldp_vty_show_discovery(struct vty *vty, const char *af_str, const char *detail, + const char *json) { struct imsgbuf ibuf; struct show_params params; @@ -1607,8 +1607,8 @@ ldp_vty_show_discovery(struct vty *vty, const char *af_str, int detail, memset(¶ms, 0, sizeof(params)); params.family = af; - params.detail = detail; - params.json = json; + params.detail = (detail) ? 1 : 0; + params.json = (json) ? 1 : 0; if (!params.detail && !params.json) vty_out (vty, "%-4s %-15s %-8s %-15s %9s\n", @@ -1623,7 +1623,7 @@ ldp_vty_show_discovery(struct vty *vty, const char *af_str, int detail, } int -ldp_vty_show_interface(struct vty *vty, const char *af_str, int json) +ldp_vty_show_interface(struct vty *vty, const char *af_str, const char *json) { struct imsgbuf ibuf; struct show_params params; @@ -1638,7 +1638,7 @@ ldp_vty_show_interface(struct vty *vty, const char *af_str, int json) memset(¶ms, 0, sizeof(params)); params.family = af; - params.json = json; + params.json = (json) ? 1 : 0; /* header */ if (!params.json) { @@ -1652,7 +1652,7 @@ ldp_vty_show_interface(struct vty *vty, const char *af_str, int json) } int -ldp_vty_show_capabilities(struct vty *vty, int json) +ldp_vty_show_capabilities(struct vty *vty, const char *json) { if (json) { json_object *json; @@ -1703,7 +1703,7 @@ ldp_vty_show_capabilities(struct vty *vty, int json) } int -ldp_vty_show_neighbor(struct vty *vty, int capabilities, int detail, int json) +ldp_vty_show_neighbor(struct vty *vty, int capabilities, const char *detail, const char *json) { struct imsgbuf ibuf; struct show_params params; @@ -1713,8 +1713,8 @@ ldp_vty_show_neighbor(struct vty *vty, int capabilities, int detail, int json) memset(¶ms, 0, sizeof(params)); params.capabilities = capabilities; - params.detail = detail; - params.json = json; + params.detail = (detail) ? 1 : 0; + params.json = (json) ? 1 : 0; if (params.capabilities) params.detail = 1; @@ -1728,7 +1728,7 @@ ldp_vty_show_neighbor(struct vty *vty, int capabilities, int detail, int json) } int -ldp_vty_show_atom_binding(struct vty *vty, int json) +ldp_vty_show_atom_binding(struct vty *vty, const char *json) { struct imsgbuf ibuf; struct show_params params; @@ -1737,14 +1737,14 @@ ldp_vty_show_atom_binding(struct vty *vty, int json) return (CMD_WARNING); memset(¶ms, 0, sizeof(params)); - params.json = json; + params.json = (json) ? 1 : 0; imsg_compose(&ibuf, IMSG_CTL_SHOW_L2VPN_BINDING, 0, 0, -1, NULL, 0); return (ldp_vty_dispatch(vty, &ibuf, SHOW_L2VPN_BINDING, ¶ms)); } int -ldp_vty_show_atom_vc(struct vty *vty, int json) +ldp_vty_show_atom_vc(struct vty *vty, const char *json) { struct imsgbuf ibuf; struct show_params params; @@ -1753,7 +1753,7 @@ ldp_vty_show_atom_vc(struct vty *vty, int json) return (CMD_WARNING); memset(¶ms, 0, sizeof(params)); - params.json = json; + params.json = (json) ? 1 : 0; if (!params.json) { /* header */ diff --git a/lib/command.c b/lib/command.c index d97ad9db3c..f28a55ec6d 100644 --- a/lib/command.c +++ b/lib/command.c @@ -47,6 +47,74 @@ DEFINE_MTYPE(LIB, HOST, "Host config") DEFINE_MTYPE(LIB, STRVEC, "String vector") DEFINE_MTYPE(LIB, COMPLETION, "Completion item") +const char *node_names[] = { + "auth", // AUTH_NODE, + "view", // VIEW_NODE, + "auth enable", // AUTH_ENABLE_NODE, + "enable", // ENABLE_NODE, + "config", // CONFIG_NODE, + "service", // SERVICE_NODE, + "debug", // DEBUG_NODE, + "vrf debug", // VRF_DEBUG_NODE, + "vnc debug", // DEBUG_VNC_NODE, + "aaa", // AAA_NODE, + "keychain", // KEYCHAIN_NODE, + "keychain key", // KEYCHAIN_KEY_NODE, + "logical-router", // NS_NODE, + "vrf", // VRF_NODE, + "interface", // INTERFACE_NODE, + "zebra", // ZEBRA_NODE, + "table", // TABLE_NODE, + "rip", // RIP_NODE, + "ripng", // RIPNG_NODE, + "babel", // BABEL_NODE, + "eigrp", // EIGRP_NODE, + "bgp", // BGP_NODE, + "bgp vpnv4", // BGP_VPNV4_NODE, + "bgp vpnv6", // BGP_VPNV6_NODE, + "bgp ipv4 unicast", // BGP_IPV4_NODE, + "bgp ipv4 multicast", // BGP_IPV4M_NODE, + "bgp ipv4 labeled unicast", // BGP_IPV4L_NODE, + "bgp ipv6", // BGP_IPV6_NODE, + "bgp ipv6 multicast", // BGP_IPV6M_NODE, + "bgp ipv6 labeled unicast", // BGP_IPV6L_NODE, + "bgp vrf policy", // BGP_VRF_POLICY_NODE, + "bgp vnc defaults", // BGP_VNC_DEFAULTS_NODE, + "bgp vnc nve", // BGP_VNC_NVE_GROUP_NODE, + "bgp vnc l2", // BGP_VNC_L2_GROUP_NODE, + "rfp defaults", // RFP_DEFAULTS_NODE, + "bgp evpn", // BGP_EVPN_NODE, + "ospf", // OSPF_NODE, + "ospf6", // OSPF6_NODE, + "ldp", // LDP_NODE, + "ldp ipv4", // LDP_IPV4_NODE, + "ldp ipv6", // LDP_IPV6_NODE, + "ldp ipv4 interface", // LDP_IPV4_IFACE_NODE, + "ldp ipv6 interface", // LDP_IPV6_IFACE_NODE, + "ldp l2vpn", // LDP_L2VPN_NODE, + "ldp", // LDP_PSEUDOWIRE_NODE, + "isis", // ISIS_NODE, + "pim", // PIM_NODE, + "masc", // MASC_NODE, + "irdp", // IRDP_NODE, + "static ip", // IP_NODE, + "ipv4 access list", // ACCESS_NODE, + "ipv4 prefix list", // PREFIX_NODE, + "ipv6 access list", // ACCESS_IPV6_NODE, + "ipv6 prefix list", // PREFIX_IPV6_NODE, + "as list", // AS_LIST_NODE, + "community list", // COMMUNITY_LIST_NODE, + "routemap", // RMAP_NODE, + "smux", // SMUX_NODE, + "dump", // DUMP_NODE, + "forwarding", // FORWARDING_NODE, + "protocol", // PROTOCOL_NODE, + "mpls", // MPLS_NODE, + "vty", // VTY_NODE, + "link-params", // LINK_PARAMS_NODE, + "bgp evpn vni", // BGP_EVPN_VNI_NODE, +}; + /* Command vector which includes some level of command lists. Normally each daemon maintains each own cmdvec. */ vector cmdvec = NULL; @@ -2355,6 +2423,35 @@ DEFUN (no_banner_motd, return CMD_SUCCESS; } +DEFUN(find, + find_cmd, + "find COMMAND...", + "Find CLI command containing text\n" + "Text to search for\n") +{ + char *text = argv_concat(argv, argc, 1); + const struct cmd_node *node; + const struct cmd_element *cli; + vector clis; + + for (unsigned int i = 0; i < vector_active(cmdvec); i++) { + node = vector_slot(cmdvec, i); + if (!node) + continue; + clis = node->cmd_vector; + for (unsigned int j = 0; j < vector_active(clis); j++) { + cli = vector_slot(clis, j); + if (strcasestr(cli->string, text)) + vty_out(vty, " (%s) %s\n", + node_names[node->node], cli->string); + } + } + + XFREE(MTYPE_TMP, text); + + return CMD_SUCCESS; +} + /* Set config filename. Called from vty.c */ void host_config_set(const char *filename) { @@ -2375,6 +2472,7 @@ void install_default(enum node_type node) install_element(node, &config_end_cmd); install_element(node, &config_help_cmd); install_element(node, &config_list_cmd); + install_element(node, &find_cmd); install_element(node, &config_write_cmd); install_element(node, &show_running_config_cmd); @@ -2389,6 +2487,9 @@ void install_default(enum node_type node) * terminal = -1 -- watchfrr / no logging, but minimal config control */ void cmd_init(int terminal) { + if (array_size(node_names) != NODE_TYPE_MAX) + assert(!"Update the CLI node description array!"); + qobj_init(); varhandlers = list_new(); @@ -2416,6 +2517,8 @@ void cmd_init(int terminal) /* Each node's basic commands. */ install_element(VIEW_NODE, &show_version_cmd); + install_element(ENABLE_NODE, &show_startup_config_cmd); + if (terminal) { install_element(VIEW_NODE, &config_list_cmd); install_element(VIEW_NODE, &config_exit_cmd); @@ -2428,20 +2531,16 @@ void cmd_init(int terminal) install_element(VIEW_NODE, &show_commandtree_cmd); install_element(VIEW_NODE, &echo_cmd); install_element(VIEW_NODE, &autocomplete_cmd); - } + install_element(VIEW_NODE, &find_cmd); - if (terminal) { install_element(ENABLE_NODE, &config_end_cmd); install_element(ENABLE_NODE, &config_disable_cmd); install_element(ENABLE_NODE, &config_terminal_cmd); install_element(ENABLE_NODE, ©_runningconf_startupconf_cmd); install_element(ENABLE_NODE, &config_write_cmd); install_element(ENABLE_NODE, &show_running_config_cmd); - } - install_element(ENABLE_NODE, &show_startup_config_cmd); - - if (terminal) { install_element(ENABLE_NODE, &config_logmsg_cmd); + install_default(CONFIG_NODE); thread_cmd_init(); diff --git a/lib/command.h b/lib/command.h index 5d52fe3fc3..533b4b3289 100644 --- a/lib/command.h +++ b/lib/command.h @@ -68,7 +68,7 @@ struct host { char *motdfile; }; -/* There are some command levels which called from command node. */ +/* List of CLI nodes. Please remember to update the name array in command.c. */ enum node_type { AUTH_NODE, /* Authentication mode of vty interface. */ VIEW_NODE, /* View node. Default mode of vty interface. */ @@ -135,8 +135,12 @@ enum node_type { VTY_NODE, /* Vty node. */ LINK_PARAMS_NODE, /* Link-parameters node */ BGP_EVPN_VNI_NODE, /* BGP EVPN VNI */ + NODE_TYPE_MAX, /* maximum */ }; +extern vector cmdvec; +extern const char *node_names[]; + /* Node which has some commands and prompt string and configuration function pointer . */ struct cmd_node { diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index 7c5c44fca7..015776a174 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -1437,7 +1437,7 @@ static void ospf6_brouter_debug_print(struct ospf6_route *brouter) char brouter_name[16]; char area_name[16]; char destination[64]; - char installed[16], changed[16]; + char installed[64], changed[64]; struct timeval now, res; char id[16], adv_router[16]; char capa[16], options[16]; diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index 329060a16f..e1a431ea07 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -467,7 +467,7 @@ void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa) char adv_router[64], id[64]; struct ospf6_lsa_handler *handler; struct timeval now, res; - char duration[16]; + char duration[64]; assert(lsa && lsa->header); diff --git a/ospf6d/ospf6_neighbor.c b/ospf6d/ospf6_neighbor.c index a21da07483..bde89f54a6 100644 --- a/ospf6d/ospf6_neighbor.c +++ b/ospf6d/ospf6_neighbor.c @@ -582,10 +582,10 @@ int inactivity_timer(struct thread *thread) static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on) { char router_id[16]; - char duration[16]; + char duration[64]; struct timeval res; char nstate[16]; - char deadtime[16]; + char deadtime[64]; long h, m, s; /* Router-ID (Name) */ @@ -640,7 +640,7 @@ static void ospf6_neighbor_show_drchoice(struct vty *vty, { char router_id[16]; char drouter[16], bdrouter[16]; - char duration[16]; + char duration[64]; struct timeval now, res; /* diff --git a/ospf6d/ospf6_route.c b/ospf6d/ospf6_route.c index 5e8fd0e15d..e0e9fc9449 100644 --- a/ospf6d/ospf6_route.c +++ b/ospf6d/ospf6_route.c @@ -945,7 +945,7 @@ void ospf6_route_show(struct vty *vty, struct ospf6_route *route) { int i; char destination[PREFIX2STR_BUFFER], nexthop[64]; - char duration[16]; + char duration[64]; const char *ifname; struct timeval now, res; struct listnode *node; @@ -991,7 +991,7 @@ void ospf6_route_show_detail(struct vty *vty, struct ospf6_route *route) char destination[PREFIX2STR_BUFFER], nexthop[64]; char area_id[16], id[16], adv_router[16], capa[16], options[16]; struct timeval now, res; - char duration[16]; + char duration[64]; struct listnode *node; struct ospf6_nexthop *nh; diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 7476a2b897..f6a2c92586 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -2621,9 +2621,39 @@ DEFUN (config_list, return cmd_list_cmds(vty, argc == 2); } +DEFUN(find, + find_cmd, + "find COMMAND...", + "Find CLI command containing text\n" + "Text to search for\n") +{ + char *text = argv_concat(argv, argc, 1); + const struct cmd_node *node; + const struct cmd_element *cli; + vector clis; + + for (unsigned int i = 0; i < vector_active(cmdvec); i++) { + node = vector_slot(cmdvec, i); + if (!node) + continue; + clis = node->cmd_vector; + for (unsigned int j = 0; j < vector_active(clis); j++) { + cli = vector_slot(clis, j); + if (strcasestr(cli->string, text)) + fprintf(stdout, " (%s) %s\n", + node_names[node->node], cli->string); + } + } + + XFREE(MTYPE_TMP, text); + + return CMD_SUCCESS; +} + static void vtysh_install_default(enum node_type node) { install_element(node, &config_list_cmd); + install_element(node, &find_cmd); } /* Making connection to protocol daemon. */ @@ -2915,48 +2945,13 @@ void vtysh_init_vty(void) install_node(&isis_node, NULL); install_node(&vty_node, NULL); - vtysh_install_default(VIEW_NODE); - vtysh_install_default(CONFIG_NODE); - vtysh_install_default(BGP_NODE); - vtysh_install_default(RIP_NODE); - vtysh_install_default(INTERFACE_NODE); - vtysh_install_default(LINK_PARAMS_NODE); - vtysh_install_default(NS_NODE); - vtysh_install_default(VRF_NODE); - vtysh_install_default(RMAP_NODE); - vtysh_install_default(ZEBRA_NODE); - vtysh_install_default(BGP_VPNV4_NODE); - vtysh_install_default(BGP_VPNV6_NODE); - vtysh_install_default(BGP_IPV4_NODE); - vtysh_install_default(BGP_IPV4M_NODE); - vtysh_install_default(BGP_IPV4L_NODE); - vtysh_install_default(BGP_IPV6_NODE); - vtysh_install_default(BGP_IPV6M_NODE); - vtysh_install_default(BGP_EVPN_NODE); - vtysh_install_default(BGP_EVPN_VNI_NODE); - vtysh_install_default(BGP_IPV6L_NODE); -#if ENABLE_BGP_VNC - vtysh_install_default(BGP_VRF_POLICY_NODE); - vtysh_install_default(BGP_VNC_DEFAULTS_NODE); - vtysh_install_default(BGP_VNC_NVE_GROUP_NODE); - vtysh_install_default(BGP_VNC_L2_GROUP_NODE); -#endif - vtysh_install_default(OSPF_NODE); - vtysh_install_default(EIGRP_NODE); - vtysh_install_default(BABEL_NODE); - vtysh_install_default(RIPNG_NODE); - vtysh_install_default(OSPF6_NODE); - vtysh_install_default(LDP_NODE); - vtysh_install_default(LDP_IPV4_NODE); - vtysh_install_default(LDP_IPV6_NODE); - vtysh_install_default(LDP_IPV4_IFACE_NODE); - vtysh_install_default(LDP_IPV6_IFACE_NODE); - vtysh_install_default(LDP_L2VPN_NODE); - vtysh_install_default(LDP_PSEUDOWIRE_NODE); - vtysh_install_default(ISIS_NODE); - vtysh_install_default(KEYCHAIN_NODE); - vtysh_install_default(KEYCHAIN_KEY_NODE); - vtysh_install_default(VTY_NODE); + struct cmd_node *node; + for (unsigned int i = 0; i < vector_active(cmdvec); i++) { + node = vector_slot(cmdvec, i); + if (!node || node->node == VIEW_NODE) + continue; + vtysh_install_default(node->node); + } install_element(VIEW_NODE, &vtysh_enable_cmd); install_element(ENABLE_NODE, &vtysh_config_terminal_cmd); diff --git a/zebra/.gitignore b/zebra/.gitignore index 145df05689..d0a7528539 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 46ecad5e4c..67031ea361 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_mpls_vty.c b/zebra/zebra_mpls_vty.c index ed34831f8f..9d100bb7d0 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 <A.B.C.D|INTERFACE|null0> 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 <A.B.C.D|INTERFACE|null0> 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 <A.B.C.D|INTERFACE|null0> 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 <A.B.C.D|INTERFACE|null0> 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 <A.B.C.D|INTERFACE|null0> (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 <A.B.C.D|INTERFACE|null0> 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 <A.B.C.D|INTERFACE|null0> (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 <A.B.C.D|INTERFACE|null0> 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 <A.B.C.D|INTERFACE|null0> 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 <A.B.C.D|INTERFACE|null0> 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 <A.B.C.D|INTERFACE|null0> 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 <A.B.C.D|INTERFACE|null0> 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 <A.B.C.D|INTERFACE|null0> (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 <A.B.C.D|INTERFACE|null0> 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 <A.B.C.D|INTERFACE|null0> (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 <A.B.C.D|INTERFACE|null0> 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 <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, 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 <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, 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 <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, 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 <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, 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 <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, 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 <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, 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 <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, 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 <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, 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.c b/zebra/zebra_static.c index ae32395161..6cebae997c 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 91ac0a33c2..885774895f 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; @@ -100,16 +96,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 50fa69d224..e8b82ecf90 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; @@ -61,40 +62,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. */ -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_route(struct vty *vty, afi_t afi, safi_t safi, + 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, + 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 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; - 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)); 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); + } + 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; } - p.prefixlen = ip_masklen(mask); + break; + default: + break; } /* Apply mask for given prefix. */ @@ -119,6 +139,7 @@ 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, @@ -149,22 +170,15 @@ 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,70 +198,56 @@ 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(afi2family(afi), 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) { + 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, - ifindex ? NULL : (union g_addr *)&gate, - ifindex, ifname, flag, tag, distance, zvrf, - &snh_label); + if (!negate) + 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, - ifindex ? NULL : (union g_addr *)&gate, - 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; } /* 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 <A.B.C.D|INTERFACE> [(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 *nexthop = argv[3]->arg; - char *distance = (argc == 5) ? argv[4]->arg : NULL; - - return zebra_static_ipv4(vty, SAFI_MULTICAST, 1, destprefix, NULL, - nexthop, NULL, NULL, distance, NULL, NULL); -} - -DEFUN (no_ip_mroute_dist, - no_ip_mroute_dist_cmd, - "no ip mroute A.B.C.D/M <A.B.C.D|INTERFACE> [(1-255)]", + "[no] ip mroute A.B.C.D/M$prefix <A.B.C.D$gate|INTERFACE$ifname> [(1-255)$distance]", NO_STR IP_STR "Configure static unicast route into MRIB for multicast RPF lookup\n" @@ -256,12 +256,9 @@ DEFUN (no_ip_mroute_dist, "Nexthop interface name\n" "Distance\n") { - char *destprefix = argv[3]->arg; - char *nexthop = argv[4]->arg; - char *distance = (argc == 6) ? argv[5]->arg : NULL; - - return zebra_static_ipv4(vty, SAFI_MULTICAST, 0, destprefix, NULL, - nexthop, 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, @@ -357,270 +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) -{ - *distance = 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 <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]", - 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" - VRF_CMD_HELP_STR) -{ - int idx_ipv4_prefixlen = 2; - int idx_ipv4_ifname_null = 3; - 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); - - 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); -} - -DEFUN (ip_route_flags, - ip_route_flags_cmd, - "ip route A.B.C.D/M <reject|blackhole> [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; - - tag = distance = vrf = NULL; - 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, - argv[idx_reject_blackhole]->arg, tag, distance, vrf, NULL); -} - -/* 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 <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]", - 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) -{ - int idx_ipv4 = 2; - int idx_ipv4_2 = 3; - int idx_ipv4_ifname_null = 4; - 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); - - 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); -} - -DEFUN_HIDDEN (ip_route_mask_flags, - ip_route_mask_flags_cmd, - "ip route A.B.C.D A.B.C.D <reject|blackhole> [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; - - tag = distance = vrf = NULL; - 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, - 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 <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "[no] ip route\ + <A.B.C.D/M$prefix|A.B.C.D$prefix A.B.C.D$mask>\ + <\ + {A.B.C.D$gate|INTERFACE$ifname}\ + |null0$ifname\ + |<reject|blackhole>$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" - "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_ipv4_ifname_null = 4; - 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); - - 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); -} - -DEFUN (no_ip_route_flags, - no_ip_route_flags_cmd, - "no ip route A.B.C.D/M <reject|blackhole> [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" + "Set tag for 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; - - tag = distance = vrf = NULL; - 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, 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 <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]", - 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) -{ - int idx_ipv4 = 3; - int idx_ipv4_2 = 4; - int idx_ipv4_ifname_null = 5; - 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); - - 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); -} - -DEFUN_HIDDEN (no_ip_route_mask_flags, - no_ip_route_mask_flags_cmd, - "no ip route A.B.C.D A.B.C.D <reject|blackhole> [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) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { - int idx_ipv4 = 3; - int idx_ipv4_2 = 4; - 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); - - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, 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. */ @@ -1944,6 +1714,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, @@ -1996,360 +1774,22 @@ static int static_config(struct vty *vty, afi_t afi, safi_t safi, return write; } -/* 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) -{ - 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 = STATIC_BLACKHOLE; - 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; - - 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); - - /* 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); - - 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 ((gate_str != NULL) - && (strncasecmp(gate_str, "Null0", strlen(gate_str)) == 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; - } - - /* 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 (ifname) { - /* When ifname is specified. It must be come with gateway - address. */ - if (ret != 1) { - vty_out(vty, "%% Malformed address\n"); - return CMD_WARNING_CONFIG_FAILED; - } - type = STATIC_IPV6_GATEWAY_IFINDEX; - gate = &gate_addr; - ifp = if_lookup_by_name(ifname, zvrf_id(zvrf)); - if (!ifp) { - vty_out(vty, "%% Malformed Interface name %s\n", - ifname); - return CMD_WARNING_CONFIG_FAILED; - } - 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 (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, +DEFPY (ipv6_route, ipv6_route_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] <X:X::X:X|INTERFACE|null0> [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" - "Null interface\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_ifname; - int idx_curr; - char *src, *tag, *distance, *vrf; - - 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; - } - - 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_ifname]->arg, NULL, NULL, tag, - distance, vrf, NULL); -} - -DEFUN (ipv6_route_flags, - ipv6_route_flags_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] <X:X::X:X|INTERFACE> <reject|blackhole> [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_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; - } else { - src = NULL; - idx_ipv6_ifname = 3; - idx_reject_blackhole = 4; - idx_curr = 5; - } - - 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_ifname]->arg, 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]", - 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) -{ - int idx_ipv6_prefixlen = 2; - int idx_ipv6 = 3; - int idx_interface = 4; - int idx_curr = 5; - char *src, *tag, *distance, *vrf; - - 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; - } - - 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, - 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 <reject|blackhole> [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] <X:X::X:X|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "[no] ipv6 route X:X::X:X/M$prefix [from X:X::X:X/M]\ + <\ + {X:X::X:X$gate|INTERFACE$ifname}\ + |null0$ifname\ + |<reject|blackhole>$flag\ + >\ + [{\ + tag (1-4294967295)\ + |(1-255)$distance\ + |vrf NAME\ + |label WORD\ + }]", NO_STR - IP_STR + IPV6_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" "IPv6 source-dest route\n" @@ -2357,171 +1797,17 @@ DEFUN (no_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) -{ - int idx_ipv6_prefixlen = 3; - int idx_ipv6_ifname; - int idx_curr; - char *src, *tag, *distance, *vrf; - - 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; - } - - 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_ifname]->arg, NULL, NULL, tag, - distance, vrf, NULL); -} - -DEFUN (no_ipv6_route_flags, - no_ipv6_route_flags_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] <X:X::X:X|INTERFACE> <reject|blackhole> [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_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; - } else { - src = NULL; - idx_ipv6_ifname = 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, 0, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6_ifname]->arg, 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]", - 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) -{ - int idx_ipv6_prefixlen = 3; - int idx_ipv6; - int idx_interface; - 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_curr = 8; - } else { - src = NULL; - idx_ipv6 = 4; - idx_interface = 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, 0, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6]->arg, argv[idx_interface]->arg, - 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 <reject|blackhole> [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) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { - 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); + 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, @@ -3374,15 +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_flags_cmd); - install_element(CONFIG_NODE, &ip_route_mask_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_mask_cmd); install_element(CONFIG_NODE, &ip_zebra_import_table_distance_cmd); install_element(CONFIG_NODE, &no_ip_zebra_import_table_cmd); @@ -3400,24 +2680,12 @@ 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); 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, &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); |
