From 80db5ac1783458e29effd2eddff2e936302fe923 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sat, 22 Nov 2014 10:43:29 -0800 Subject: build: track config args Record the ./configure arguments used and make them user-visible. Signed-off-by: David Lamparter Acked-by: Paul Jakma --- lib/command.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index a71cb5ddd2..85506adefe 100644 --- a/lib/command.c +++ b/lib/command.c @@ -182,6 +182,7 @@ print_version (const char *progname) { printf ("%s version %s\n", progname, QUAGGA_VERSION); printf ("%s\n", QUAGGA_COPYRIGHT); + printf ("configured with:\n\t%s\n", QUAGGA_CONFIG_ARGS); } @@ -3022,6 +3023,8 @@ DEFUN (show_version, vty_out (vty, "Quagga %s (%s).%s", QUAGGA_VERSION, host.name?host.name:"", VTY_NEWLINE); vty_out (vty, "%s%s%s", QUAGGA_COPYRIGHT, GIT_INFO, VTY_NEWLINE); + vty_out (vty, "configured with:%s %s%s", VTY_NEWLINE, + QUAGGA_CONFIG_ARGS, VTY_NEWLINE); return CMD_SUCCESS; } -- cgit v1.2.3 From b06fd12526849dd65836a1899a4cabca4525a96d Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 19 Jun 2015 19:26:19 -0400 Subject: Quagga: Fix code to use srandom/random Quagga was using a mix of srand/rand and srandom/random. Consolidate to use srandom/random which are the POSIX versions of random number generators Signed-off-by: Donald Sharp --- bgpd/bgp_main.c | 2 +- bgpd/bgp_routemap.c | 13 +------------ isisd/isis_main.c | 2 +- isisd/isis_misc.c | 2 +- lib/command.c | 2 +- ospf6d/ospf6_main.c | 2 +- ripd/ripd.c | 4 ++-- ripngd/ripngd.c | 4 ++-- 8 files changed, 10 insertions(+), 21 deletions(-) (limited to 'lib/command.c') diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c index 7fa80cc9c9..f873aba493 100644 --- a/bgpd/bgp_main.c +++ b/bgpd/bgp_main.c @@ -490,7 +490,7 @@ main (int argc, char **argv) /* Initializations. */ - srand (time (NULL)); + srandom (time (NULL)); signal_init (bm->master, array_size(bgp_signals), bgp_signals); zprivs_init (&bgpd_privs); cmd_init (1); diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index ab22a455d2..a7d62a6b37 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -892,12 +892,7 @@ static route_map_result_t route_match_probability (void *rule, struct prefix *prefix, route_map_object_t type, void *object) { - unsigned long r; -#if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500 - r = random(); -#else - r = (unsigned long) rand(); -#endif + long r = random(); switch (*(long *) rule) { @@ -919,12 +914,6 @@ route_match_probability_compile (const char *arg) long *lobule; unsigned perc; -#if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500 - srandom (time (NULL)); -#else - srand (time (NULL)); -#endif - perc = atoi (arg); lobule = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (long)); diff --git a/isisd/isis_main.c b/isisd/isis_main.c index f2fe4ef71f..343c683f48 100644 --- a/isisd/isis_main.c +++ b/isisd/isis_main.c @@ -327,7 +327,7 @@ main (int argc, char **argv, char **envp) master = thread_master_create (); /* random seed from time */ - srand (time (NULL)); + srandom (time (NULL)); /* * initializations diff --git a/isisd/isis_misc.c b/isisd/isis_misc.c index 230fe24387..f19b44155a 100644 --- a/isisd/isis_misc.c +++ b/isisd/isis_misc.c @@ -510,7 +510,7 @@ isis_jitter (unsigned long timer, unsigned long jitter) * most IS-IS timers are no longer than 16 bit */ - j = 1 + (int) ((RANDOM_SPREAD * rand ()) / (RAND_MAX + 1.0)); + j = 1 + (int) ((RANDOM_SPREAD * random ()) / (RAND_MAX + 1.0)); k = timer - (timer * (100 - jitter)) / 100; diff --git a/lib/command.c b/lib/command.c index 85506adefe..d080d6cc0b 100644 --- a/lib/command.c +++ b/lib/command.c @@ -4209,7 +4209,7 @@ cmd_init (int terminal) vrf_install_commands (); } - srand(time(NULL)); + srandom(time(NULL)); } static void diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c index 52dc6677f0..84c98b885f 100644 --- a/ospf6d/ospf6_main.c +++ b/ospf6d/ospf6_main.c @@ -243,7 +243,7 @@ main (int argc, char *argv[], char *envp[]) progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); /* Seed random number for LSA ID */ - srand (time(NULL)); + srandom (time(NULL)); /* Command line argument treatment. */ while (1) diff --git a/ripd/ripd.c b/ripd/ripd.c index fc3ad3adb3..42f1015453 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -2867,7 +2867,7 @@ rip_update_jitter (unsigned long time) if (jitter_input < JITTER_BOUND) jitter_input = JITTER_BOUND; - jitter = (((rand () % ((jitter_input * 2) + 1)) - jitter_input)); + jitter = (((random () % ((jitter_input * 2) + 1)) - jitter_input)); return jitter/JITTER_BOUND; } @@ -4140,7 +4140,7 @@ void rip_init (void) { /* Randomize for triggered update random(). */ - srand (time (NULL)); + srandom (time (NULL)); /* Install top nodes. */ install_node (&rip_node, config_write_rip); diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index 4eed40b94a..13884ff3b3 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -1874,7 +1874,7 @@ ripng_request (struct interface *ifp) static int ripng_update_jitter (int time) { - return ((rand () % (time + 1)) - (time / 2)); + return ((random () % (time + 1)) - (time / 2)); } void @@ -2928,7 +2928,7 @@ void ripng_init () { /* Randomize. */ - srand (time (NULL)); + srandom (time (NULL)); /* Install RIPNG_NODE. */ install_node (&cmd_ripng_node, ripng_config_write); -- cgit v1.2.3 From cde9f1011728e6b4f141fa7d5d4656cfa6d46293 Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Tue, 12 Jan 2016 13:41:46 -0500 Subject: lib: fix bookkeeping for libreadline malloc()s When libreadline is used, we mistakenly mix in strdup() done in libreadline with Quagga's lib/memory bookkeeping/counting, leading to counter underflows on MTYPE_TMP. Signed-off-by: Lou Berger Signed-off-by: David Lamparter (cherry picked from commit 672900382d47137638086bd8351b2678f589a546) Conflicts: lib/command.c --- lib/command.c | 45 +++++++++++++++++++++++++++++---------------- lib/command.h | 1 + lib/vty.c | 2 +- 3 files changed, 31 insertions(+), 17 deletions(-) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index d080d6cc0b..dd98eb2de5 100644 --- a/lib/command.c +++ b/lib/command.c @@ -2349,7 +2349,7 @@ cmd_complete_sort(vector matchvec) /* Command line completion support. */ static char ** -cmd_complete_command_real (vector vline, struct vty *vty, int *status) +cmd_complete_command_real (vector vline, struct vty *vty, int *status, int islib) { unsigned int i; vector cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node)); @@ -2434,13 +2434,14 @@ cmd_complete_command_real (vector vline, struct vty *vty, int *status) for (j = 0; j < vector_active (match_vector); j++) if ((token = vector_slot (match_vector, j))) - { - if ((string = - cmd_entry_function (vector_slot (vline, index), - token->cmd))) - if (cmd_unique_string (matchvec, string)) - vector_set (matchvec, XSTRDUP (MTYPE_TMP, string)); - } + { + string = cmd_entry_function (vector_slot (vline, index), + token->cmd); + if (string && cmd_unique_string (matchvec, string)) + vector_set (matchvec, (islib != 0 ? + XSTRDUP (MTYPE_TMP, string) : + strdup (string) /* rl freed */)); + } } /* We don't need cmd_vector any more. */ @@ -2485,7 +2486,9 @@ cmd_complete_command_real (vector vline, struct vty *vty, int *status) { char *lcdstr; - lcdstr = XMALLOC (MTYPE_TMP, lcd + 1); + lcdstr = (islib != 0 ? + XMALLOC (MTYPE_TMP, lcd + 1) : + malloc(lcd + 1)); memcpy (lcdstr, matchvec->index[0], lcd); lcdstr[lcd] = '\0'; @@ -2493,10 +2496,15 @@ cmd_complete_command_real (vector vline, struct vty *vty, int *status) /* Free matchvec. */ for (i = 0; i < vector_active (matchvec); i++) - { - if (vector_slot (matchvec, i)) - XFREE (MTYPE_TMP, vector_slot (matchvec, i)); - } + { + if (vector_slot (matchvec, i)) + { + if (islib != 0) + XFREE (MTYPE_TMP, vector_slot (matchvec, i)); + else + free (vector_slot (matchvec, i)); + } + } vector_free (matchvec); /* Make new matchvec. */ @@ -2519,7 +2527,7 @@ cmd_complete_command_real (vector vline, struct vty *vty, int *status) } char ** -cmd_complete_command (vector vline, struct vty *vty, int *status) +cmd_complete_command_lib (vector vline, struct vty *vty, int *status, int islib) { char **ret; @@ -2540,15 +2548,20 @@ cmd_complete_command (vector vline, struct vty *vty, int *status) vector_set_index (shifted_vline, index-1, vector_lookup(vline, index)); } - ret = cmd_complete_command_real (shifted_vline, vty, status); + ret = cmd_complete_command_real (shifted_vline, vty, status, islib); vector_free(shifted_vline); vty->node = onode; return ret; } + return cmd_complete_command_real (vline, vty, status, islib); +} - return cmd_complete_command_real (vline, vty, status); +char ** +cmd_complete_command (vector vline, struct vty *vty, int *status) +{ + return cmd_complete_command_lib (vline, vty, status, 0); } /* return parent node */ diff --git a/lib/command.h b/lib/command.h index 7051e1ca5c..4be9514e85 100644 --- a/lib/command.h +++ b/lib/command.h @@ -550,6 +550,7 @@ extern vector cmd_make_strvec (const char *); extern void cmd_free_strvec (vector); extern vector cmd_describe_command (vector, struct vty *, int *status); extern char **cmd_complete_command (vector, struct vty *, int *status); +extern char **cmd_complete_command_lib (vector, struct vty *, int *status, int islib); extern const char *cmd_prompt (enum node_type); extern int command_config_read_one_line (struct vty *vty, struct cmd_element **, int use_config_node); extern int config_from_file (struct vty *, FILE *, unsigned int *line_num); diff --git a/lib/vty.c b/lib/vty.c index 0de075ccbf..53c9a2aba0 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -873,7 +873,7 @@ vty_complete_command (struct vty *vty) if (isspace ((int) vty->buf[vty->length - 1])) vector_set (vline, NULL); - matched = cmd_complete_command (vline, vty, &ret); + matched = cmd_complete_command_lib (vline, vty, &ret, 1); cmd_free_strvec (vline); -- cgit v1.2.3 From bcd9fa7ff2c6547cde8441ba8ec179458b1d9e28 Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Tue, 12 Jan 2016 13:41:48 -0500 Subject: lib: add "show commandtree" CLI command Signed-off-by: Lou Berger Signed-off-by: David Lamparter (cherry picked from commit f9ec4190f1eaf2dba355a9808bca8d7148bc8a55) --- lib/command.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index dd98eb2de5..99aa669530 100644 --- a/lib/command.c +++ b/lib/command.c @@ -4070,6 +4070,37 @@ DEFUN (no_banner_motd, return CMD_SUCCESS; } +DEFUN (show_commandtree, + show_commandtree_cmd, + "show commandtree", + NO_STR + "Show command tree\n") +{ + /* TBD */ + vector cmd_vector; + unsigned int i; + + vty_out (vty, "Current node id: %d%s", vty->node, VTY_NEWLINE); + + /* vector of all commands installed at this node */ + cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node)); + + /* loop over all commands at this node */ + for (i = 0; i < vector_active(cmd_vector); ++i) + { + struct cmd_element *cmd_element; + + /* A cmd_element (seems to be) is an individual command */ + if ((cmd_element = vector_slot (cmd_vector, i)) == NULL) + continue; + + vty_out (vty, " %s%s", cmd_element->string, VTY_NEWLINE); + } + + vector_free (cmd_vector); + return CMD_SUCCESS; +} + /* Set config filename. Called from vty.c */ void host_config_set (const char *filename) @@ -4137,6 +4168,7 @@ cmd_init (int terminal) install_element (VIEW_NODE, &config_terminal_length_cmd); install_element (VIEW_NODE, &config_terminal_no_length_cmd); install_element (VIEW_NODE, &show_logging_cmd); + install_element (VIEW_NODE, &show_commandtree_cmd); install_element (VIEW_NODE, &echo_cmd); install_element (RESTRICTED_NODE, &config_list_cmd); @@ -4146,6 +4178,7 @@ cmd_init (int terminal) install_element (RESTRICTED_NODE, &config_enable_cmd); install_element (RESTRICTED_NODE, &config_terminal_length_cmd); install_element (RESTRICTED_NODE, &config_terminal_no_length_cmd); + install_element (RESTRICTED_NODE, &show_commandtree_cmd); install_element (RESTRICTED_NODE, &echo_cmd); } @@ -4158,6 +4191,7 @@ cmd_init (int terminal) } install_element (ENABLE_NODE, &show_startup_config_cmd); install_element (ENABLE_NODE, &show_version_cmd); + install_element (ENABLE_NODE, &show_commandtree_cmd); if (terminal) { @@ -4222,6 +4256,7 @@ cmd_init (int terminal) vrf_install_commands (); } + install_element (CONFIG_NODE, &show_commandtree_cmd); srandom(time(NULL)); } -- cgit v1.2.3 From 8ecd32669320500e6d144d079a42183035b0ee4f Mon Sep 17 00:00:00 2001 From: vivek Date: Mon, 6 Jun 2016 19:29:05 -0700 Subject: bgpd, lib, vtysh: hook up bgp VPNv6 CLI node Signed-off-by: Lou Berger Signed-off-by: David Lamparter (cherry picked from commit 13c378d96a57017f5995b2e0df46cfc31123f0e8) Conflicts: bgpd/bgp_vty.c bgpd/bgpd.c vtysh/vtysh_config.c --- bgpd/bgp_vty.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- bgpd/bgpd.c | 5 +++ lib/command.c | 5 ++- lib/command.h | 1 + lib/vty.c | 1 + vtysh/vtysh.c | 42 +++++++++++++++++++- 6 files changed, 168 insertions(+), 4 deletions(-) (limited to 'lib/command.c') diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 5fc0b75122..17588eb3a4 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -62,7 +62,9 @@ listen_range_exists (struct bgp *bgp, struct prefix *range, int exact); afi_t bgp_node_afi (struct vty *vty) { - if (vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE) + if (vty->node == BGP_IPV6_NODE || + vty->node == BGP_IPV6M_NODE || + vty->node == BGP_VPNV6_NODE) return AFI_IP6; return AFI_IP; } @@ -74,6 +76,8 @@ bgp_node_safi (struct vty *vty) { if (vty->node == BGP_VPNV4_NODE) return SAFI_MPLS_VPN; + if (vty->node == BGP_VPNV6_NODE) + return SAFI_MPLS_VPN; if (vty->node == BGP_IPV4M_NODE || vty->node == BGP_IPV6M_NODE) return SAFI_MULTICAST; return SAFI_UNICAST; @@ -5864,6 +5868,23 @@ ALIAS (address_family_vpnv4, "Address family\n" "Address Family Modifier\n") +DEFUN (address_family_vpnv6, + address_family_vpnv6_cmd, + "address-family vpnv6", + "Enter Address Family command mode\n" + "Address family\n") +{ + vty->node = BGP_VPNV6_NODE; + return CMD_SUCCESS; +} + +ALIAS (address_family_vpnv6, + address_family_vpnv6_unicast_cmd, + "address-family vpnv6 unicast", + "Enter Address Family command mode\n" + "Address family\n" + "Address Family Modifier\n") + DEFUN (exit_address_family, exit_address_family_cmd, "exit-address-family", @@ -5873,7 +5894,8 @@ DEFUN (exit_address_family, || vty->node == BGP_IPV4M_NODE || vty->node == BGP_VPNV4_NODE || vty->node == BGP_IPV6_NODE - || vty->node == BGP_IPV6M_NODE) + || vty->node == BGP_IPV6M_NODE + || vty->node == BGP_VPNV6_NODE) vty->node = BGP_NODE; return CMD_SUCCESS; } @@ -13905,6 +13927,13 @@ static struct cmd_node bgp_vpnv4_node = 1 }; +static struct cmd_node bgp_vpnv6_node = +{ + BGP_VPNV6_NODE, + "%s(config-router-af-vpnv6)# ", + 1 +}; + static void community_list_vty (void); void @@ -13917,6 +13946,7 @@ bgp_vty_init (void) install_node (&bgp_ipv6_unicast_node, NULL); install_node (&bgp_ipv6_multicast_node, NULL); install_node (&bgp_vpnv4_node, NULL); + install_node (&bgp_vpnv6_node, NULL); /* Install default VTY commands to new nodes. */ install_default (BGP_NODE); @@ -13925,6 +13955,7 @@ bgp_vty_init (void) install_default (BGP_IPV6_NODE); install_default (BGP_IPV6M_NODE); install_default (BGP_VPNV4_NODE); + install_default (BGP_VPNV6_NODE); /* "bgp multiple-instance" commands. */ install_element (CONFIG_NODE, &bgp_multiple_instance_cmd); @@ -14170,6 +14201,7 @@ bgp_vty_init (void) install_element (BGP_IPV6_NODE, &neighbor_activate_cmd); install_element (BGP_IPV6M_NODE, &neighbor_activate_cmd); install_element (BGP_VPNV4_NODE, &neighbor_activate_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_activate_cmd); /* "no neighbor activate" commands. */ install_element (BGP_NODE, &no_neighbor_activate_cmd); @@ -14178,6 +14210,7 @@ bgp_vty_init (void) install_element (BGP_IPV6_NODE, &no_neighbor_activate_cmd); install_element (BGP_IPV6M_NODE, &no_neighbor_activate_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_activate_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_activate_cmd); /* "neighbor peer-group" set commands. * Long term we should only accept this command under BGP_NODE and not all of @@ -14191,6 +14224,7 @@ bgp_vty_init (void) install_element (BGP_IPV6_NODE, &neighbor_set_peer_group_cmd); install_element (BGP_IPV6M_NODE, &neighbor_set_peer_group_cmd); install_element (BGP_VPNV4_NODE, &neighbor_set_peer_group_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_set_peer_group_cmd); /* "no neighbor peer-group unset" commands. */ install_element (BGP_NODE, &no_neighbor_set_peer_group_cmd); @@ -14199,6 +14233,7 @@ bgp_vty_init (void) install_element (BGP_IPV6_NODE, &no_neighbor_set_peer_group_cmd); install_element (BGP_IPV6M_NODE, &no_neighbor_set_peer_group_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_set_peer_group_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_set_peer_group_cmd); /* "neighbor softreconfiguration inbound" commands.*/ install_element (BGP_NODE, &neighbor_soft_reconfiguration_cmd); @@ -14213,6 +14248,8 @@ bgp_vty_init (void) install_element (BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd); install_element (BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd); /* "neighbor attribute-unchanged" commands. */ install_element (BGP_NODE, &neighbor_attr_unchanged_cmd); @@ -14347,6 +14384,29 @@ bgp_vty_init (void) install_element (BGP_VPNV4_NODE, &no_neighbor_attr_unchanged8_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_attr_unchanged9_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_attr_unchanged10_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged1_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged2_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged3_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged4_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged5_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged6_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged7_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged8_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged9_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged10_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged1_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged2_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged3_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged4_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged5_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged6_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged7_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged8_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged9_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged10_cmd); + /* "nexthop-local unchanged" commands */ install_element (BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd); @@ -14365,6 +14425,8 @@ bgp_vty_init (void) install_element (BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd); install_element (BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd); /* "neighbor next-hop-self force" commands. */ install_element (BGP_NODE, &neighbor_nexthop_self_force_cmd); @@ -14379,6 +14441,8 @@ bgp_vty_init (void) install_element (BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd); install_element (BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd); /* "neighbor as-override" commands. */ install_element (BGP_NODE, &neighbor_as_override_cmd); @@ -14393,6 +14457,8 @@ bgp_vty_init (void) install_element (BGP_IPV6M_NODE, &no_neighbor_as_override_cmd); install_element (BGP_VPNV4_NODE, &neighbor_as_override_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_as_override_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_as_override_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_as_override_cmd); /* "neighbor remove-private-AS" commands. */ install_element (BGP_NODE, &neighbor_remove_private_as_cmd); @@ -14443,6 +14509,14 @@ bgp_vty_init (void) install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_replace_as_cmd); install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_all_replace_as_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_replace_as_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_replace_as_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_all_replace_as_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd); /* "neighbor send-community" commands.*/ install_element (BGP_NODE, &neighbor_send_community_cmd); @@ -14469,6 +14543,10 @@ bgp_vty_init (void) install_element (BGP_VPNV4_NODE, &neighbor_send_community_type_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_send_community_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_send_community_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_send_community_type_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_send_community_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd); /* "neighbor route-reflector" commands.*/ install_element (BGP_NODE, &neighbor_route_reflector_client_cmd); @@ -14483,6 +14561,8 @@ bgp_vty_init (void) install_element (BGP_IPV6M_NODE, &no_neighbor_route_reflector_client_cmd); install_element (BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_route_reflector_client_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_route_reflector_client_cmd); /* "neighbor route-server" commands.*/ install_element (BGP_NODE, &neighbor_route_server_client_cmd); @@ -14497,6 +14577,8 @@ bgp_vty_init (void) install_element (BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd); install_element (BGP_VPNV4_NODE, &neighbor_route_server_client_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_route_server_client_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd); /* "neighbor addpath-tx-all-paths" commands.*/ install_element (BGP_NODE, &neighbor_addpath_tx_all_paths_cmd); @@ -14511,6 +14593,8 @@ bgp_vty_init (void) install_element (BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd); install_element (BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd); /* "neighbor addpath-tx-bestpath-per-AS" commands.*/ install_element (BGP_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd); @@ -14525,6 +14609,8 @@ bgp_vty_init (void) install_element (BGP_IPV6M_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd); install_element (BGP_VPNV4_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd); /* "neighbor passive" commands. */ install_element (BGP_NODE, &neighbor_passive_cmd); @@ -14652,6 +14738,8 @@ bgp_vty_init (void) install_element (BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd); install_element (BGP_VPNV4_NODE, &neighbor_distribute_list_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_distribute_list_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd); /* "neighbor prefix-list" commands. */ install_element (BGP_NODE, &neighbor_prefix_list_cmd); @@ -14666,6 +14754,8 @@ bgp_vty_init (void) install_element (BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd); install_element (BGP_VPNV4_NODE, &neighbor_prefix_list_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_prefix_list_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd); /* "neighbor filter-list" commands. */ install_element (BGP_NODE, &neighbor_filter_list_cmd); @@ -14680,6 +14770,8 @@ bgp_vty_init (void) install_element (BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd); install_element (BGP_VPNV4_NODE, &neighbor_filter_list_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_filter_list_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd); /* "neighbor route-map" commands. */ install_element (BGP_NODE, &neighbor_route_map_cmd); @@ -14694,6 +14786,8 @@ bgp_vty_init (void) install_element (BGP_IPV6M_NODE, &no_neighbor_route_map_cmd); install_element (BGP_VPNV4_NODE, &neighbor_route_map_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_route_map_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_route_map_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_route_map_cmd); /* "neighbor unsuppress-map" commands. */ install_element (BGP_NODE, &neighbor_unsuppress_map_cmd); @@ -14708,6 +14802,8 @@ bgp_vty_init (void) install_element (BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd); install_element (BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd); /* "neighbor maximum-prefix" commands. */ install_element (BGP_NODE, &neighbor_maximum_prefix_cmd); @@ -14788,6 +14884,19 @@ bgp_vty_init (void) install_element (BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_threshold_warning_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_restart_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_threshold_restart_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_warning_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_restart_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_val_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_threshold_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_warning_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_threshold_warning_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_restart_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_threshold_restart_cmd); /* "neighbor allowas-in" */ install_element (BGP_NODE, &neighbor_allowas_in_cmd); @@ -14814,6 +14923,10 @@ bgp_vty_init (void) install_element (BGP_VPNV4_NODE, &neighbor_allowas_in_arg_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd); install_element (BGP_VPNV4_NODE, &no_neighbor_allowas_in_val_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_allowas_in_cmd); + install_element (BGP_VPNV6_NODE, &neighbor_allowas_in_arg_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd); + install_element (BGP_VPNV6_NODE, &no_neighbor_allowas_in_val_cmd); /* address-family commands. */ install_element (BGP_NODE, &address_family_ipv4_cmd); @@ -14831,6 +14944,7 @@ bgp_vty_init (void) install_element (BGP_IPV6_NODE, &exit_address_family_cmd); install_element (BGP_IPV6M_NODE, &exit_address_family_cmd); install_element (BGP_VPNV4_NODE, &exit_address_family_cmd); + install_element (BGP_VPNV6_NODE, &exit_address_family_cmd); /* "clear ip bgp commands" */ install_element (ENABLE_NODE, &clear_ip_bgp_all_cmd); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 8c2c61f4cb..06956b0ad6 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -6904,6 +6904,8 @@ bgp_config_write_family_header (struct vty *vty, afi_t afi, safi_t safi, vty_out (vty, "ipv6 unicast"); else if (safi == SAFI_MULTICAST) vty_out (vty, "ipv6 multicast"); + else if (safi == SAFI_MPLS_VPN) + vty_out (vty, "vpnv6"); } vty_out (vty, "%s", VTY_NEWLINE); @@ -7191,6 +7193,9 @@ bgp_config_write (struct vty *vty) /* IPv6 multicast configuration. */ write += bgp_config_write_family (vty, bgp, AFI_IP6, SAFI_MULTICAST); + /* IPv6 VPN configuration. */ + write += bgp_config_write_family (vty, bgp, AFI_IP6, SAFI_MPLS_VPN); + write++; } return write; diff --git a/lib/command.c b/lib/command.c index 99aa669530..17e0f8d3b9 100644 --- a/lib/command.c +++ b/lib/command.c @@ -2576,6 +2576,7 @@ node_parent ( enum node_type node ) switch (node) { case BGP_VPNV4_NODE: + case BGP_VPNV6_NODE: case BGP_IPV4_NODE: case BGP_IPV4M_NODE: case BGP_IPV6_NODE: @@ -2961,9 +2962,10 @@ DEFUN (config_exit, case VTY_NODE: vty->node = CONFIG_NODE; break; - case BGP_VPNV4_NODE: case BGP_IPV4_NODE: case BGP_IPV4M_NODE: + case BGP_VPNV4_NODE: + case BGP_VPNV6_NODE: case BGP_IPV6_NODE: case BGP_IPV6M_NODE: vty->node = BGP_NODE; @@ -3004,6 +3006,7 @@ DEFUN (config_end, case RIPNG_NODE: case BGP_NODE: case BGP_VPNV4_NODE: + case BGP_VPNV6_NODE: case BGP_IPV4_NODE: case BGP_IPV4M_NODE: case BGP_IPV6_NODE: diff --git a/lib/command.h b/lib/command.h index 4be9514e85..50c07b1460 100644 --- a/lib/command.h +++ b/lib/command.h @@ -82,6 +82,7 @@ enum node_type RIPNG_NODE, /* RIPng protocol mode node. */ BGP_NODE, /* BGP protocol mode which includes BGP4+ */ BGP_VPNV4_NODE, /* BGP MPLS-VPN PE exchange. */ + BGP_VPNV6_NODE, /* BGP MPLS-VPN PE exchange. */ BGP_IPV4_NODE, /* BGP IPv4 unicast address family. */ BGP_IPV4M_NODE, /* BGP IPv4 multicast address family. */ BGP_IPV6_NODE, /* BGP IPv6 address family */ diff --git a/lib/vty.c b/lib/vty.c index 53c9a2aba0..97ce245b33 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -703,6 +703,7 @@ vty_end_config (struct vty *vty) case RIPNG_NODE: case BGP_NODE: case BGP_VPNV4_NODE: + case BGP_VPNV6_NODE: case BGP_IPV4_NODE: case BGP_IPV4M_NODE: case BGP_IPV6_NODE: diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 8e39e9349e..bdfbeb9143 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -383,7 +383,8 @@ vtysh_execute_func (const char *line, int pager) * to move into node in the vtysh where it succeeded. */ if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING) { - if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_IPV4_NODE + if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_VPNV6_NODE + || saved_node == BGP_IPV4_NODE || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE || saved_node == BGP_IPV6M_NODE) && (tried == 1)) @@ -941,6 +942,12 @@ static struct cmd_node bgp_vpnv4_node = "%s(config-router-af)# " }; +static struct cmd_node bgp_vpnv6_node = +{ + BGP_VPNV6_NODE, + "%s(config-router-af)# " +}; + static struct cmd_node bgp_ipv4_node = { BGP_IPV4_NODE, @@ -1076,6 +1083,29 @@ DEFUNSH (VTYSH_BGPD, return CMD_SUCCESS; } +DEFUNSH (VTYSH_BGPD, + address_family_vpnv6, + address_family_vpnv6_cmd, + "address-family vpnv6", + "Enter Address Family command mode\n" + "Address family\n") +{ + vty->node = BGP_VPNV6_NODE; + return CMD_SUCCESS; +} + +DEFUNSH (VTYSH_BGPD, + address_family_vpnv6_unicast, + address_family_vpnv6_unicast_cmd, + "address-family vpnv6 unicast", + "Enter Address Family command mode\n" + "Address family\n" + "Address Family Modifier\n") +{ + vty->node = BGP_VPNV6_NODE; + return CMD_SUCCESS; +} + DEFUNSH (VTYSH_BGPD, address_family_ipv4_unicast, address_family_ipv4_unicast_cmd, @@ -1309,6 +1339,7 @@ vtysh_exit (struct vty *vty) vty->node = CONFIG_NODE; break; case BGP_VPNV4_NODE: + case BGP_VPNV6_NODE: case BGP_IPV4_NODE: case BGP_IPV4M_NODE: case BGP_IPV6_NODE: @@ -1347,6 +1378,7 @@ DEFUNSH (VTYSH_BGPD, if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE || vty->node == BGP_VPNV4_NODE + || vty->node == BGP_VPNV6_NODE || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE) vty->node = BGP_NODE; @@ -2750,6 +2782,7 @@ vtysh_init_vty (void) install_node (&rmap_node, NULL); install_node (&zebra_node, NULL); install_node (&bgp_vpnv4_node, NULL); + install_node (&bgp_vpnv6_node, NULL); install_node (&bgp_ipv4_node, NULL); install_node (&bgp_ipv4m_node, NULL); /* #ifdef HAVE_IPV6 */ @@ -2776,6 +2809,7 @@ vtysh_init_vty (void) 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_IPV6_NODE); @@ -2811,6 +2845,8 @@ vtysh_init_vty (void) install_element (BGP_NODE, &vtysh_quit_bgpd_cmd); install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd); install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd); + install_element (BGP_VPNV6_NODE, &vtysh_exit_bgpd_cmd); + install_element (BGP_VPNV6_NODE, &vtysh_quit_bgpd_cmd); install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd); install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd); install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd); @@ -2841,6 +2877,7 @@ vtysh_init_vty (void) install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd); install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd); install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd); + install_element (BGP_VPNV6_NODE, &vtysh_end_all_cmd); install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd); install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd); install_element (ISIS_NODE, &vtysh_end_all_cmd); @@ -2874,6 +2911,8 @@ vtysh_init_vty (void) install_element (CONFIG_NODE, &router_bgp_view_cmd); install_element (BGP_NODE, &address_family_vpnv4_cmd); install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd); + install_element (BGP_NODE, &address_family_vpnv6_cmd); + install_element (BGP_NODE, &address_family_vpnv6_unicast_cmd); install_element (BGP_NODE, &address_family_ipv4_unicast_cmd); install_element (BGP_NODE, &address_family_ipv4_multicast_cmd); #ifdef HAVE_IPV6 @@ -2882,6 +2921,7 @@ vtysh_init_vty (void) install_element (BGP_NODE, &address_family_ipv6_multicast_cmd); #endif install_element (BGP_VPNV4_NODE, &exit_address_family_cmd); + install_element (BGP_VPNV6_NODE, &exit_address_family_cmd); install_element (BGP_IPV4_NODE, &exit_address_family_cmd); install_element (BGP_IPV4M_NODE, &exit_address_family_cmd); install_element (BGP_IPV6_NODE, &exit_address_family_cmd); -- cgit v1.2.3 From c5e0075f8b0ed11c81333bbe6970ebc9479e3a70 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 3 Mar 2015 09:07:25 +0100 Subject: *: add/cleanup initialisers There were some (inconsequential) warnings about uninitialised use of variables. Also, in one case, sub-structs were mixed in initialisation, which doesn't quite work as intended. Signed-off-by: David Lamparter --- lib/command.c | 2 +- ospfd/ospf_spf.c | 3 +-- ripngd/ripngd.c | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index 17e0f8d3b9..958d0eb244 100644 --- a/lib/command.c +++ b/lib/command.c @@ -1355,7 +1355,7 @@ cmd_matcher_match_multiple(struct cmd_matcher *matcher, enum match_type multiple_match; unsigned int multiple_index; const char *word; - const char *arg; + const char *arg = NULL; struct cmd_token *word_token; enum match_type word_match; diff --git a/ospfd/ospf_spf.c b/ospfd/ospf_spf.c index 9f6c6f471b..5f8ef6f993 100644 --- a/ospfd/ospf_spf.c +++ b/ospfd/ospf_spf.c @@ -590,8 +590,7 @@ ospf_nexthop_calculation (struct ospf_area *area, struct vertex *v, if (l->m[0].type == LSA_LINK_TYPE_POINTOPOINT) { - struct in_addr nexthop; - nexthop.s_addr = 0; + struct in_addr nexthop = { .s_addr = 0 }; /* If the destination is a router which connects to the calculating router via a Point-to-MultiPoint diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index 13884ff3b3..e026d4748e 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -236,7 +236,7 @@ ripng_recv_packet (int sock, u_char *buf, int bufsize, struct msghdr msg; struct iovec iov; struct cmsghdr *cmsgptr; - struct in6_addr dst; + struct in6_addr dst = { .s6_addr = { 0 } }; memset(&dst, 0, sizeof(struct in6_addr)); -- cgit v1.2.3 From c117e02796a8c1d32379b9eb2e7c444fdeeb60d6 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 5 May 2015 11:10:20 +0200 Subject: lib/cli: reduce strcmp in CLI hot paths Er, no idea how anyone could ever have thought that it would be a good idea to have a zillion of strcmp() calls in the CLI's active paths, just to compare against things like "A.B.C.D". Reduces 40k prefix list load time from 1.65s to 1.23s (1.34:1). Acked-by: Paul Jakma [v2: killed CMDS_* macros] Signed-off-by: David Lamparter (cherry picked from commit 10bac80195cf5a781da6e4415e6580fd7080f734) --- lib/command.c | 284 ++++++++++++++++++++++++++++++++-------------------------- lib/command.h | 25 +++--- 2 files changed, 174 insertions(+), 135 deletions(-) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index 958d0eb244..1e18e25026 100644 --- a/lib/command.c +++ b/lib/command.c @@ -507,6 +507,25 @@ format_parser_read_word(struct format_parser_state *state) token = XCALLOC(MTYPE_CMD_TOKENS, sizeof(*token)); token->type = TOKEN_TERMINAL; + if (cmd[0] == '[') + token->terminal = TERMINAL_OPTION; + else if ((cmd[0] >= 'A' && cmd[0] <= 'Z') || (cmd[0] == '<')) + token->terminal = TERMINAL_VARIABLE; + else if (cmd[0] == '.') + token->terminal = TERMINAL_VARARG; + else if (cmd[0] == '<') + token->terminal = TERMINAL_RANGE; + else if (strcmp (cmd, "A.B.C.D") == 0) + token->terminal = TERMINAL_IPV4; + else if (strcmp (cmd, "A.B.C.D/M") == 0) + token->terminal = TERMINAL_IPV4_PREFIX; + else if (strcmp (cmd, "X:X::X:X") == 0) + token->terminal = TERMINAL_IPV6; + else if (strcmp (cmd, "X:X::X:X/M") == 0) + token->terminal = TERMINAL_IPV6_PREFIX; + else + token->terminal = TERMINAL_LITERAL; + token->cmd = cmd; token->desc = format_parser_desc_str(state); vector_set(state->curvect, token); @@ -1173,59 +1192,61 @@ cmd_word_match(struct cmd_token *token, if (!word) return no_match; - if (CMD_VARARG(str)) - { - return vararg_match; - } - else if (CMD_RANGE(str)) - { - if (cmd_range_match(str, word)) - return range_match; - } -#ifdef HAVE_IPV6 - else if (CMD_IPV6(str)) - { - match_type = cmd_ipv6_match(word); - if ((filter == FILTER_RELAXED && match_type != no_match) - || (filter == FILTER_STRICT && match_type == exact_match)) - return ipv6_match; - } - else if (CMD_IPV6_PREFIX(str)) - { - match_type = cmd_ipv6_prefix_match(word); - if ((filter == FILTER_RELAXED && match_type != no_match) - || (filter == FILTER_STRICT && match_type == exact_match)) - return ipv6_prefix_match; - } -#endif /* HAVE_IPV6 */ - else if (CMD_IPV4(str)) - { - match_type = cmd_ipv4_match(word); - if ((filter == FILTER_RELAXED && match_type != no_match) - || (filter == FILTER_STRICT && match_type == exact_match)) - return ipv4_match; - } - else if (CMD_IPV4_PREFIX(str)) + switch (token->terminal) { - match_type = cmd_ipv4_prefix_match(word); - if ((filter == FILTER_RELAXED && match_type != no_match) + case TERMINAL_VARARG: + return vararg_match; + + case TERMINAL_RANGE: + if (cmd_range_match(str, word)) + return range_match; + break; + + case TERMINAL_IPV6: + match_type = cmd_ipv6_match(word); + if ((filter == FILTER_RELAXED && match_type != no_match) || (filter == FILTER_STRICT && match_type == exact_match)) - return ipv4_prefix_match; - } - else if (CMD_OPTION(str) || CMD_VARIABLE(str)) - { - return extend_match; - } - else - { - if (filter == FILTER_RELAXED && !strncmp(str, word, strlen(word))) - { - if (!strcmp(str, word)) - return exact_match; - return partly_match; - } - if (filter == FILTER_STRICT && !strcmp(str, word)) - return exact_match; + return ipv6_match; + break; + + case TERMINAL_IPV6_PREFIX: + match_type = cmd_ipv6_prefix_match(word); + if ((filter == FILTER_RELAXED && match_type != no_match) + || (filter == FILTER_STRICT && match_type == exact_match)) + return ipv6_prefix_match; + break; + + case TERMINAL_IPV4: + match_type = cmd_ipv4_match(word); + if ((filter == FILTER_RELAXED && match_type != no_match) + || (filter == FILTER_STRICT && match_type == exact_match)) + return ipv4_match; + break; + + case TERMINAL_IPV4_PREFIX: + match_type = cmd_ipv4_prefix_match(word); + if ((filter == FILTER_RELAXED && match_type != no_match) + || (filter == FILTER_STRICT && match_type == exact_match)) + return ipv4_prefix_match; + break; + + case TERMINAL_OPTION: + case TERMINAL_VARIABLE: + return extend_match; + + case TERMINAL_LITERAL: + if (filter == FILTER_RELAXED && !strncmp(str, word, strlen(word))) + { + if (!strcmp(str, word)) + return exact_match; + return partly_match; + } + if (filter == FILTER_STRICT && !strcmp(str, word)) + return exact_match; + break; + + default: + assert (0); } return no_match; @@ -1309,7 +1330,7 @@ cmd_matcher_match_terminal(struct cmd_matcher *matcher, if (!cmd_matcher_words_left(matcher)) { - if (CMD_OPTION(token->cmd)) + if (token->terminal == TERMINAL_OPTION) return MATCHER_OK; /* missing optional args are NOT pushed as NULL */ else return MATCHER_INCOMPLETE; @@ -1322,9 +1343,9 @@ cmd_matcher_match_terminal(struct cmd_matcher *matcher, /* We have to record the input word as argument if it matched * against a variable. */ - if (CMD_VARARG(token->cmd) - || CMD_VARIABLE(token->cmd) - || CMD_OPTION(token->cmd)) + if (token->terminal == TERMINAL_VARARG + || token->terminal == TERMINAL_VARIABLE + || token->terminal == TERMINAL_OPTION) { if (push_argument(argc, argv, word)) return MATCHER_EXCEED_ARGC_MAX; @@ -1335,7 +1356,7 @@ cmd_matcher_match_terminal(struct cmd_matcher *matcher, matcher->word_index++; /* A vararg token should consume all left over words as arguments */ - if (CMD_VARARG(token->cmd)) + if (token->terminal == TERMINAL_VARARG) while (cmd_matcher_words_left(matcher)) { word = cmd_matcher_get_word(matcher); @@ -1566,9 +1587,9 @@ cmd_matcher_build_keyword_args(struct cmd_matcher *matcher, { word_token = vector_slot(keyword_vector, j); if ((word_token->type == TOKEN_TERMINAL - && (CMD_VARARG(word_token->cmd) - || CMD_VARIABLE(word_token->cmd) - || CMD_OPTION(word_token->cmd))) + && (word_token->terminal == TERMINAL_VARARG + || word_token->terminal == TERMINAL_VARIABLE + || word_token->terminal == TERMINAL_OPTION)) || word_token->type == TOKEN_MULTIPLE) { if (push_argument(argc, argv, NULL)) @@ -1854,12 +1875,14 @@ is_cmd_ambiguous (vector cmd_vector, switch (type) { case exact_match: - if (!(CMD_OPTION (str) || CMD_VARIABLE (str)) + if (!(cmd_token->terminal == TERMINAL_OPTION + || cmd_token->terminal == TERMINAL_VARIABLE) && strcmp (command, str) == 0) match++; break; case partly_match: - if (!(CMD_OPTION (str) || CMD_VARIABLE (str)) + if (!(cmd_token->terminal == TERMINAL_OPTION + || cmd_token->terminal == TERMINAL_VARIABLE) && strncmp (command, str, strlen (command)) == 0) { if (matched && strcmp (matched, str) != 0) @@ -1881,7 +1904,7 @@ is_cmd_ambiguous (vector cmd_vector, break; #ifdef HAVE_IPV6 case ipv6_match: - if (CMD_IPV6 (str)) + if (cmd_token->terminal == TERMINAL_IPV6) match++; break; case ipv6_prefix_match: @@ -1895,7 +1918,7 @@ is_cmd_ambiguous (vector cmd_vector, break; #endif /* HAVE_IPV6 */ case ipv4_match: - if (CMD_IPV4 (str)) + if (cmd_token->terminal == TERMINAL_IPV4) match++; break; case ipv4_prefix_match: @@ -1908,7 +1931,8 @@ is_cmd_ambiguous (vector cmd_vector, } break; case extend_match: - if (CMD_OPTION (str) || CMD_VARIABLE (str)) + if (cmd_token->terminal == TERMINAL_OPTION + || cmd_token->terminal == TERMINAL_VARIABLE) match++; break; case no_match: @@ -1924,12 +1948,23 @@ is_cmd_ambiguous (vector cmd_vector, /* If src matches dst return dst string, otherwise return NULL */ static const char * -cmd_entry_function (const char *src, const char *dst) +cmd_entry_function (const char *src, struct cmd_token *token) { + const char *dst = token->cmd; + /* Skip variable arguments. */ - if (CMD_OPTION (dst) || CMD_VARIABLE (dst) || CMD_VARARG (dst) || - CMD_IPV4 (dst) || CMD_IPV4_PREFIX (dst) || CMD_RANGE (dst)) - return NULL; + switch (token->terminal) + { + case TERMINAL_OPTION: + case TERMINAL_VARIABLE: + case TERMINAL_VARARG: + case TERMINAL_IPV4: + case TERMINAL_IPV4_PREFIX: + case TERMINAL_RANGE: + return NULL; + default: + break; + } /* In case of 'command \t', given src is NULL string. */ if (src == NULL) @@ -1946,65 +1981,63 @@ cmd_entry_function (const char *src, const char *dst) /* This version will return the dst string always if it is CMD_VARIABLE for '?' key processing */ static const char * -cmd_entry_function_desc (const char *src, const char *dst) +cmd_entry_function_desc (const char *src, struct cmd_token *token) { - if (CMD_VARARG (dst)) - return dst; - - if (CMD_RANGE (dst)) - { - if (cmd_range_match (dst, src)) - return dst; - else - return NULL; - } - -#ifdef HAVE_IPV6 - if (CMD_IPV6 (dst)) - { - if (cmd_ipv6_match (src)) - return dst; - else - return NULL; - } - - if (CMD_IPV6_PREFIX (dst)) - { - if (cmd_ipv6_prefix_match (src)) - return dst; - else - return NULL; - } -#endif /* HAVE_IPV6 */ + const char *dst = token->cmd; - if (CMD_IPV4 (dst)) + switch (token->terminal) { - if (cmd_ipv4_match (src)) - return dst; - else - return NULL; - } - - if (CMD_IPV4_PREFIX (dst)) - { - if (cmd_ipv4_prefix_match (src)) - return dst; - else - return NULL; + case TERMINAL_VARARG: + return dst; + + case TERMINAL_RANGE: + if (cmd_range_match (dst, src)) + return dst; + else + return NULL; + + case TERMINAL_IPV6: + if (cmd_ipv6_match (src)) + return dst; + else + return NULL; + + case TERMINAL_IPV6_PREFIX: + if (cmd_ipv6_prefix_match (src)) + return dst; + else + return NULL; + + case TERMINAL_IPV4: + if (cmd_ipv4_match (src)) + return dst; + else + return NULL; + + case TERMINAL_IPV4_PREFIX: + if (cmd_ipv4_prefix_match (src)) + return dst; + else + return NULL; + + /* Optional or variable commands always match on '?' */ + case TERMINAL_OPTION: + case TERMINAL_VARIABLE: + return dst; + + case TERMINAL_LITERAL: + /* In case of 'command \t', given src is NULL string. */ + if (src == NULL) + return dst; + + if (strncmp (src, dst, strlen (src)) == 0) + return dst; + else + return NULL; + + default: + assert(0); } - - /* Optional or variable commands always match on '?' */ - if (CMD_OPTION (dst) || CMD_VARIABLE (dst)) - return dst; - - /* In case of 'command \t', given src is NULL string. */ - if (src == NULL) - return dst; - - if (strncmp (src, dst, strlen (src)) == 0) - return dst; - else - return NULL; } /** @@ -2223,7 +2256,7 @@ cmd_describe_command_real (vector vline, struct vty *vty, int *status) struct cmd_token *token = vector_slot(match_vector, j); const char *string; - string = cmd_entry_function_desc(command, token->cmd); + string = cmd_entry_function_desc(command, token); if (string && desc_unique_string(matchvec, string)) vector_set(matchvec, token); } @@ -2436,7 +2469,7 @@ cmd_complete_command_real (vector vline, struct vty *vty, int *status, int islib if ((token = vector_slot (match_vector, j))) { string = cmd_entry_function (vector_slot (vline, index), - token->cmd); + token); if (string && cmd_unique_string (matchvec, string)) vector_set (matchvec, (islib != 0 ? XSTRDUP (MTYPE_TMP, string) : @@ -4135,6 +4168,7 @@ cmd_init (int terminal) { command_cr = XSTRDUP(MTYPE_CMD_TOKENS, ""); token_cr.type = TOKEN_TERMINAL; + token_cr.terminal = TERMINAL_LITERAL; token_cr.cmd = command_cr; token_cr.desc = XSTRDUP(MTYPE_CMD_TOKENS, ""); diff --git a/lib/command.h b/lib/command.h index 50c07b1460..56c1caceb2 100644 --- a/lib/command.h +++ b/lib/command.h @@ -153,10 +153,25 @@ enum cmd_token_type TOKEN_KEYWORD, }; +enum cmd_terminal_type +{ + _TERMINAL_BUG = 0, + TERMINAL_LITERAL, + TERMINAL_OPTION, + TERMINAL_VARIABLE, + TERMINAL_VARARG, + TERMINAL_RANGE, + TERMINAL_IPV4, + TERMINAL_IPV4_PREFIX, + TERMINAL_IPV6, + TERMINAL_IPV6_PREFIX, +}; + /* Command description structure. */ struct cmd_token { enum cmd_token_type type; + enum cmd_terminal_type terminal; /* Used for type == MULTIPLE */ vector multiple; /* vector of cmd_token, type == FINAL */ @@ -455,16 +470,6 @@ struct cmd_token #define CMD_CREATE_STR_HELPER(s) #s #define CMD_RANGE_STR(a,s) "<" CMD_CREATE_STR(a) "-" CMD_CREATE_STR(s) ">" -#define CMD_OPTION(S) ((S[0]) == '[') -#define CMD_VARIABLE(S) (((S[0]) >= 'A' && (S[0]) <= 'Z') || ((S[0]) == '<')) -#define CMD_VARARG(S) ((S[0]) == '.') -#define CMD_RANGE(S) ((S[0] == '<')) - -#define CMD_IPV4(S) ((strcmp ((S), "A.B.C.D") == 0)) -#define CMD_IPV4_PREFIX(S) ((strcmp ((S), "A.B.C.D/M") == 0)) -#define CMD_IPV6(S) ((strcmp ((S), "X:X::X:X") == 0)) -#define CMD_IPV6_PREFIX(S) ((strcmp ((S), "X:X::X:X/M") == 0)) - /* Common descriptions. */ #define SHOW_STR "Show running system information\n" #define IP_STR "IP information\n" -- cgit v1.2.3 From 27e7f290292b7789d750758e5feea18ee6ca2a14 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 12 May 2015 17:18:04 +0200 Subject: lib: fix "reduce strcmp in CLI" fallout (10bac801) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In "lib/cli: reduce strcmp in CLI hot paths", I failed to notice that CMD_VARIABLE as a boolean test covers a superset of the other types of variables. Thus, the patch broke processing of IP/IPv6/Integer range parameters in the CLI. Fix by some reordering and introducing TERMINAL_RECORD macro (which marks whether a given terminal type is a parameter) to be used in places where the check is really for all kinds of variables. Reported-by: Timo Teräs Tested-by: Martin Winter Signed-off-by: David Lamparter --- lib/command.c | 49 ++++++++++++++++--------------------------------- lib/command.h | 3 +++ 2 files changed, 19 insertions(+), 33 deletions(-) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index 1e18e25026..37603c46f8 100644 --- a/lib/command.c +++ b/lib/command.c @@ -507,15 +507,7 @@ format_parser_read_word(struct format_parser_state *state) token = XCALLOC(MTYPE_CMD_TOKENS, sizeof(*token)); token->type = TOKEN_TERMINAL; - if (cmd[0] == '[') - token->terminal = TERMINAL_OPTION; - else if ((cmd[0] >= 'A' && cmd[0] <= 'Z') || (cmd[0] == '<')) - token->terminal = TERMINAL_VARIABLE; - else if (cmd[0] == '.') - token->terminal = TERMINAL_VARARG; - else if (cmd[0] == '<') - token->terminal = TERMINAL_RANGE; - else if (strcmp (cmd, "A.B.C.D") == 0) + if (strcmp (cmd, "A.B.C.D") == 0) token->terminal = TERMINAL_IPV4; else if (strcmp (cmd, "A.B.C.D/M") == 0) token->terminal = TERMINAL_IPV4_PREFIX; @@ -523,6 +515,14 @@ format_parser_read_word(struct format_parser_state *state) token->terminal = TERMINAL_IPV6; else if (strcmp (cmd, "X:X::X:X/M") == 0) token->terminal = TERMINAL_IPV6_PREFIX; + else if (cmd[0] == '[') + token->terminal = TERMINAL_OPTION; + else if (cmd[0] == '.') + token->terminal = TERMINAL_VARARG; + else if (cmd[0] == '<') + token->terminal = TERMINAL_RANGE; + else if (cmd[0] >= 'A' && cmd[0] <= 'Z') + token->terminal = TERMINAL_VARIABLE; else token->terminal = TERMINAL_LITERAL; @@ -1343,9 +1343,7 @@ cmd_matcher_match_terminal(struct cmd_matcher *matcher, /* We have to record the input word as argument if it matched * against a variable. */ - if (token->terminal == TERMINAL_VARARG - || token->terminal == TERMINAL_VARIABLE - || token->terminal == TERMINAL_OPTION) + if (TERMINAL_RECORD (token->terminal)) { if (push_argument(argc, argv, word)) return MATCHER_EXCEED_ARGC_MAX; @@ -1587,9 +1585,7 @@ cmd_matcher_build_keyword_args(struct cmd_matcher *matcher, { word_token = vector_slot(keyword_vector, j); if ((word_token->type == TOKEN_TERMINAL - && (word_token->terminal == TERMINAL_VARARG - || word_token->terminal == TERMINAL_VARIABLE - || word_token->terminal == TERMINAL_OPTION)) + && TERMINAL_RECORD (word_token->terminal)) || word_token->type == TOKEN_MULTIPLE) { if (push_argument(argc, argv, NULL)) @@ -1875,14 +1871,12 @@ is_cmd_ambiguous (vector cmd_vector, switch (type) { case exact_match: - if (!(cmd_token->terminal == TERMINAL_OPTION - || cmd_token->terminal == TERMINAL_VARIABLE) + if (!TERMINAL_RECORD (cmd_token->terminal) && strcmp (command, str) == 0) match++; break; case partly_match: - if (!(cmd_token->terminal == TERMINAL_OPTION - || cmd_token->terminal == TERMINAL_VARIABLE) + if (!TERMINAL_RECORD (cmd_token->terminal) && strncmp (command, str, strlen (command)) == 0) { if (matched && strcmp (matched, str) != 0) @@ -1931,8 +1925,7 @@ is_cmd_ambiguous (vector cmd_vector, } break; case extend_match: - if (cmd_token->terminal == TERMINAL_OPTION - || cmd_token->terminal == TERMINAL_VARIABLE) + if (TERMINAL_RECORD (cmd_token->terminal)) match++; break; case no_match: @@ -1953,18 +1946,8 @@ cmd_entry_function (const char *src, struct cmd_token *token) const char *dst = token->cmd; /* Skip variable arguments. */ - switch (token->terminal) - { - case TERMINAL_OPTION: - case TERMINAL_VARIABLE: - case TERMINAL_VARARG: - case TERMINAL_IPV4: - case TERMINAL_IPV4_PREFIX: - case TERMINAL_RANGE: - return NULL; - default: - break; - } + if (TERMINAL_RECORD (token->terminal)) + return NULL; /* In case of 'command \t', given src is NULL string. */ if (src == NULL) diff --git a/lib/command.h b/lib/command.h index 56c1caceb2..523d1a2e4c 100644 --- a/lib/command.h +++ b/lib/command.h @@ -167,6 +167,9 @@ enum cmd_terminal_type TERMINAL_IPV6_PREFIX, }; +/* argument to be recorded on argv[] if it's not a literal */ +#define TERMINAL_RECORD(t) ((t) >= TERMINAL_OPTION) + /* Command description structure. */ struct cmd_token { -- cgit v1.2.3 From dc1b72dca39ffa190c9cbc853a5d899f57386f0a Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Wed, 13 May 2015 12:44:50 +0200 Subject: lib: assert(0) still needs a return assert(0) is not guaranteed to not return since assert() in general can be optimised out when building without debug / with optimisation. This breaks the build in clang, which warns/errors about the missing return. Signed-off-by: David Lamparter (cherry picked from commit f1fc327c7eb00634d2c2b08c2a6f6e44a626ef04) --- lib/command.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index 37603c46f8..015d97266d 100644 --- a/lib/command.c +++ b/lib/command.c @@ -2020,6 +2020,7 @@ cmd_entry_function_desc (const char *src, struct cmd_token *token) default: assert(0); + return NULL; } } -- cgit v1.2.3 From c5e69a025f7d1c15cd1c49d1b8cf7a0c18bbc377 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Thu, 30 May 2013 16:31:49 +0200 Subject: lib/vty: add separate output fd support to VTYs to be used with stdin/stdout terminals, this adds support for writing to a different FD than we're reading from. Also fixes error messages from config load being written to stdin. [v2: fixed config write] Signed-off-by: David Lamparter (cherry picked from commit 4715a53b4d390e72a06c864a6a505971841e3dc9) --- lib/command.c | 2 +- lib/vty.c | 27 +++++++++++++++------------ lib/vty.h | 3 +++ 3 files changed, 19 insertions(+), 13 deletions(-) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index 015d97266d..72a2739895 100644 --- a/lib/command.c +++ b/lib/command.c @@ -3153,7 +3153,7 @@ DEFUN (config_write_file, /* Make vty for configuration file. */ file_vty = vty_new (); - file_vty->fd = fd; + file_vty->wfd = fd; file_vty->type = VTY_FILE; /* Config file header print. */ diff --git a/lib/vty.c b/lib/vty.c index 97ce245b33..21f6f0da6f 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -184,7 +184,7 @@ vty_log_out (struct vty *vty, const char *level, const char *proto_str, buf[len++] = '\r'; buf[len++] = '\n'; - if (write(vty->fd, buf, len) < 0) + if (write(vty->wfd, buf, len) < 0) { if (ERRNO_IO_RETRY(errno)) /* Kernel buffer is full, probably too much debugging output, so just @@ -1543,7 +1543,7 @@ vty_read (struct thread *thread) vty_close (vty); else { - vty_event (VTY_WRITE, vty_sock, vty); + vty_event (VTY_WRITE, vty->wfd, vty); vty_event (VTY_READ, vty_sock, vty); } return 0; @@ -1572,12 +1572,12 @@ vty_flush (struct thread *thread) /* N.B. if width is 0, that means we don't know the window size. */ if ((vty->lines == 0) || (vty->width == 0)) - flushrc = buffer_flush_available(vty->obuf, vty->fd); + flushrc = buffer_flush_available(vty->obuf, vty_sock); else if (vty->status == VTY_MORELINE) - flushrc = buffer_flush_window(vty->obuf, vty->fd, vty->width, + flushrc = buffer_flush_window(vty->obuf, vty_sock, vty->width, 1, erase, 0); else - flushrc = buffer_flush_window(vty->obuf, vty->fd, vty->width, + flushrc = buffer_flush_window(vty->obuf, vty_sock, vty->width, vty->lines >= 0 ? vty->lines : vty->height, erase, 0); @@ -1623,6 +1623,7 @@ vty_create (int vty_sock, union sockunion *su) /* Allocate new vty structure and set up default values. */ vty = vty_new (); vty->fd = vty_sock; + vty->wfd = vty_sock; vty->type = VTY_TERM; strcpy (vty->address, buf); if (no_password_check) @@ -2023,6 +2024,7 @@ vtysh_accept (struct thread *thread) vty = vty_new (); vty->fd = sock; + vty->wfd = sock; vty->type = VTY_SHELL_SERV; vty->node = VIEW_NODE; @@ -2034,10 +2036,10 @@ vtysh_accept (struct thread *thread) static int vtysh_flush(struct vty *vty) { - switch (buffer_flush_available(vty->obuf, vty->fd)) + switch (buffer_flush_available(vty->obuf, vty->wfd)) { case BUFFER_PENDING: - vty_event(VTYSH_WRITE, vty->fd, vty); + vty_event(VTYSH_WRITE, vty->wfd, vty); break; case BUFFER_ERROR: vty->monitor = 0; /* disable monitoring to avoid infinite recursion */ @@ -2173,7 +2175,7 @@ vty_close (struct vty *vty) thread_cancel (vty->t_timeout); /* Flush buffer. */ - buffer_flush_all (vty->obuf, vty->fd); + buffer_flush_all (vty->obuf, vty->wfd); /* Free input buffer. */ buffer_free (vty->obuf); @@ -2233,12 +2235,13 @@ vty_read_file (FILE *confp) unsigned int line_num = 0; vty = vty_new (); - vty->fd = dup(STDERR_FILENO); /* vty_close() will close this */ - if (vty->fd < 0) + vty->wfd = dup(STDERR_FILENO); /* vty_close() will close this */ + if (vty->wfd < 0) { /* Fine, we couldn't make a new fd. vty_close doesn't close stdout. */ - vty->fd = STDOUT_FILENO; + vty->wfd = STDOUT_FILENO; } + vty->fd = STDIN_FILENO; vty->type = VTY_FILE; vty->node = CONFIG_NODE; @@ -2493,7 +2496,7 @@ vty_log_fixed (char *buf, size_t len) if (((vty = vector_slot (vtyvec, i)) != NULL) && vty->monitor) /* N.B. We don't care about the return code, since process is most likely just about to die anyway. */ - if (writev(vty->fd, iov, 2) == -1) + if (writev(vty->wfd, iov, 2) == -1) { fprintf(stderr, "Failure to writev: %d\n", errno); exit(-1); diff --git a/lib/vty.h b/lib/vty.h index f0286202bd..7968e92fd5 100644 --- a/lib/vty.h +++ b/lib/vty.h @@ -34,6 +34,9 @@ struct vty /* File descripter of this vty. */ int fd; + /* output FD, to support stdin/stdout combination */ + int wfd; + /* Is this vty connect to file or not */ enum {VTY_TERM, VTY_FILE, VTY_SHELL, VTY_SHELL_SERV} type; -- cgit v1.2.3