summaryrefslogtreecommitdiffstats
path: root/ospfd
diff options
context:
space:
mode:
authorMartin Winter <mwinter@opensourcerouting.org>2017-01-24 16:57:15 +0100
committerMartin Winter <mwinter@opensourcerouting.org>2017-01-25 18:41:40 +0100
commit9cbb96304cf0c4967c033378c09a121df86106ea (patch)
tree229ef445fab11f2546025aa2a77afa27de775891 /ospfd
parentospf6d: Add vty_socket cli option to override the compiled-in location for th... (diff)
downloadfrr-9cbb96304cf0c4967c033378c09a121df86106ea.tar.xz
frr-9cbb96304cf0c4967c033378c09a121df86106ea.zip
ospfd: Add vty_socket cli option to override the compiled-in location for the VTY Socket and add instance number for multi-instance ospf
Signed-off-by: Martin Winter <mwinter@opensourcerouting.org>
Diffstat (limited to 'ospfd')
-rw-r--r--ospfd/ospf_main.c51
1 files changed, 45 insertions, 6 deletions
diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c
index e0719b397..6719eb249 100644
--- a/ospfd/ospf_main.c
+++ b/ospfd/ospf_main.c
@@ -79,6 +79,7 @@ struct zebra_privs_t ospfd_privs =
char config_default[100];
/* OSPFd options. */
+#define OPTION_VTYSOCK 1000
struct option longopts[] =
{
{ "daemon", no_argument, NULL, 'd'},
@@ -90,6 +91,7 @@ struct option longopts[] =
{ "help", no_argument, NULL, 'h'},
{ "vty_addr", required_argument, NULL, 'A'},
{ "vty_port", required_argument, NULL, 'P'},
+ { "vty_socket", required_argument, NULL, OPTION_VTYSOCK},
{ "user", required_argument, NULL, 'u'},
{ "group", required_argument, NULL, 'g'},
{ "apiserver", no_argument, NULL, 'a'},
@@ -99,6 +101,9 @@ struct option longopts[] =
/* OSPFd program name */
+/* VTY Socket prefix */
+char vty_sock_path[MAXPATHLEN] = OSPF_VTYSH_PATH;
+
/* Master of threads. */
struct thread_master *master;
@@ -126,6 +131,7 @@ Daemon which manages OSPF.\n\n\
-z, --socket Set path of zebra socket\n\
-A, --vty_addr Set vty's bind address\n\
-P, --vty_port Set vty's port number\n\
+ --vty_socket Override vty socket path\n\
-u, --user User to run as\n\
-g, --group Group to run as\n\
-a. --apiserver Enable OSPF apiserver\n\
@@ -188,6 +194,7 @@ main (int argc, char **argv)
char *vty_addr = NULL;
int vty_port = OSPF_VTY_PORT;
char vty_path[100];
+ char *vty_sock_name;
int daemon_mode = 0;
char *config_file = NULL;
char *progname;
@@ -253,6 +260,9 @@ main (int argc, char **argv)
if (vty_port <= 0 || vty_port > 0xffff)
vty_port = OSPF_VTY_PORT;
break;
+ case OPTION_VTYSOCK:
+ set_socket_path(vty_sock_path, OSPF_VTYSH_PATH, optarg, sizeof (vty_sock_path));
+ break;
case 'u':
ospfd_privs.user = optarg;
break;
@@ -357,19 +367,48 @@ main (int argc, char **argv)
exit (1);
}
+ /* Create PID file */
+ if (instance)
+ {
+ char pidfile_temp[100];
+
+ /* Override the single file with file including instance
+ number in case of multi-instance */
+ if (strrchr(pid_file, '/') != NULL)
+ /* cut of pid_file at last / char * to get directory */
+ *strrchr(pid_file, '/') = '\0';
+ else
+ /* pid_file contains no directory - should never happen, but deal with it anyway */
+ /* throw-away all pid_file and assume it's only the filename */
+ pid_file[0] = '\0';
+
+ snprintf(pidfile_temp, sizeof(pidfile_temp), "%s/ospfd-%d.pid", pid_file, instance );
+ strncpy(pid_file, pidfile_temp, sizeof(pid_file));
+ }
+ /* Process id file create. */
+ pid_output (pid_file);
+
/* Create VTY socket */
if (instance)
{
- sprintf(pid_file, "%s/ospfd-%d.pid", DAEMON_VTY_DIR, instance);
- sprintf(vty_path, "%s/ospfd-%d.vty", DAEMON_VTY_DIR, instance);
+ /* Multi-Instance. Use only path section of vty_sock_path with new file incl instance */
+ if (strrchr(vty_sock_path, '/') != NULL)
+ {
+ /* cut of pid_file at last / char * to get directory */
+ *strrchr(vty_sock_path, '/') = '\0';
+ }
+ else
+ {
+ /* pid_file contains no directory - should never happen, but deal with it anyway */
+ /* throw-away all pid_file and assume it's only the filename */
+ vty_sock_path[0] = '\0';
+ }
+ snprintf(vty_path, sizeof(vty_path), "%s/ospfd-%d.vty", vty_sock_path, instance );
}
else
{
- strcpy(vty_path, OSPF_VTYSH_PATH);
+ strcpy(vty_path, vty_sock_path);
}
- /* Process id file create. */
- pid_output (pid_file);
-
vty_serv_sock (vty_addr, vty_port, vty_path);
/* Print banner. */