zebra: Add vty_socket cli option to override the compiled-in location for the VTY Socket

Signed-off-by: Martin Winter <mwinter@opensourcerouting.org>
This commit is contained in:
Martin Winter 2017-01-24 22:44:28 +07:00
parent 950765ba10
commit 48f8480d4c

View File

@ -59,6 +59,9 @@ struct zebra_t zebrad =
/* process id. */ /* process id. */
pid_t pid; pid_t pid;
/* VTY Socket prefix */
char vty_sock_path[MAXPATHLEN] = ZEBRA_VTYSH_PATH;
/* Pacify zclient.o in libzebra, which expects this variable. */ /* Pacify zclient.o in libzebra, which expects this variable. */
struct thread_master *master; struct thread_master *master;
@ -77,6 +80,7 @@ u_int32_t nl_rcvbufsize = 4194304;
#endif /* HAVE_NETLINK */ #endif /* HAVE_NETLINK */
/* Command line options. */ /* Command line options. */
#define OPTION_VTYSOCK 1000
struct option longopts[] = struct option longopts[] =
{ {
{ "batch", no_argument, NULL, 'b'}, { "batch", no_argument, NULL, 'b'},
@ -90,6 +94,7 @@ struct option longopts[] =
{ "help", no_argument, NULL, 'h'}, { "help", no_argument, NULL, 'h'},
{ "vty_addr", required_argument, NULL, 'A'}, { "vty_addr", required_argument, NULL, 'A'},
{ "vty_port", required_argument, NULL, 'P'}, { "vty_port", required_argument, NULL, 'P'},
{ "vty_socket", required_argument, NULL, OPTION_VTYSOCK },
{ "retain", no_argument, NULL, 'r'}, { "retain", no_argument, NULL, 'r'},
{ "dryrun", no_argument, NULL, 'C'}, { "dryrun", no_argument, NULL, 'C'},
#ifdef HAVE_NETLINK #ifdef HAVE_NETLINK
@ -152,6 +157,7 @@ usage (char *progname, int status)
"-C, --dryrun Check configuration for validity and exit\n"\ "-C, --dryrun Check configuration for validity and exit\n"\
"-A, --vty_addr Set vty's bind address\n"\ "-A, --vty_addr Set vty's bind address\n"\
"-P, --vty_port Set vty's port number\n"\ "-P, --vty_port Set vty's port number\n"\
" --vty_socket Override vty socket path\n"\
"-r, --retain When program terminates, retain added route "\ "-r, --retain When program terminates, retain added route "\
"by zebra.\n"\ "by zebra.\n"\
"-u, --user User to run as\n"\ "-u, --user User to run as\n"\
@ -259,6 +265,7 @@ main (int argc, char **argv)
char *p; char *p;
char *vty_addr = NULL; char *vty_addr = NULL;
int vty_port = ZEBRA_VTY_PORT; int vty_port = ZEBRA_VTY_PORT;
char *vty_sock_name;
int dryrun = 0; int dryrun = 0;
int batch_mode = 0; int batch_mode = 0;
int daemon_mode = 0; int daemon_mode = 0;
@ -339,6 +346,9 @@ main (int argc, char **argv)
if (vty_port <= 0 || vty_port > 0xffff) if (vty_port <= 0 || vty_port > 0xffff)
vty_port = ZEBRA_VTY_PORT; vty_port = ZEBRA_VTY_PORT;
break; break;
case OPTION_VTYSOCK:
set_socket_path(vty_sock_path, ZEBRA_VTYSH_PATH, optarg, sizeof (vty_sock_path));
break;
case 'r': case 'r':
retain_mode = 1; retain_mode = 1;
break; break;
@ -463,7 +473,7 @@ main (int argc, char **argv)
zebra_zserv_socket_init (zserv_path); zebra_zserv_socket_init (zserv_path);
/* Make vty server socket. */ /* Make vty server socket. */
vty_serv_sock (vty_addr, vty_port, ZEBRA_VTYSH_PATH); vty_serv_sock (vty_addr, vty_port, vty_sock_path);
/* Print banner. */ /* Print banner. */
zlog_notice ("Zebra %s starting: vty@%d", FRR_VERSION, vty_port); zlog_notice ("Zebra %s starting: vty@%d", FRR_VERSION, vty_port);