]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_main.c
Merge pull request #267 from opensourcerouting/vty-completion-again
[mirror_frr.git] / ospfd / ospf_main.c
index 48f39d009910e372891a07e964538b1dbfb7e5d7..edb1ca470e71fb17ea043dc6e9ac9953f57cf256 100644 (file)
 #include "stream.h"
 #include "log.h"
 #include "memory.h"
+#include "memory_vty.h"
 #include "privs.h"
 #include "sigevent.h"
 #include "zclient.h"
 #include "vrf.h"
+#include "sockopt.h"
 
 #include "ospfd/ospfd.h"
 #include "ospfd/ospf_interface.h"
@@ -62,9 +64,9 @@ zebra_capabilities_t _caps_p [] =
 
 struct zebra_privs_t ospfd_privs =
 {
-#if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
-  .user = QUAGGA_USER,
-  .group = QUAGGA_GROUP,
+#if defined(FRR_USER) && defined(FRR_GROUP)
+  .user = FRR_USER,
+  .group = FRR_GROUP,
 #endif
 #if defined(VTY_GROUP)
   .vty_group = VTY_GROUP,
@@ -78,6 +80,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'},
@@ -89,6 +92,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'},
@@ -98,6 +102,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;
 
@@ -125,6 +132,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\
@@ -132,7 +140,7 @@ Daemon which manages OSPF.\n\n\
 -C, --dryrun       Check configuration for validity and exit\n\
 -h, --help         Display this help and exit\n\
 \n\
-Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
+Report bugs to %s\n", progname, FRR_BUG_ADDRESS);
     }
   exit (status);
 }
@@ -202,6 +210,8 @@ main (int argc, char **argv)
   ospf_apiserver_enable = 0;
 #endif /* SUPPORT_OSPF_API */
 
+  strcpy(pid_file, PATH_OSPFD_PID);
+
   /* get program name */
   progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
 
@@ -250,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;
@@ -325,9 +338,7 @@ main (int argc, char **argv)
 #ifdef HAVE_SNMP
   ospf_snmp_init ();
 #endif /* HAVE_SNMP */
-#ifdef HAVE_OPAQUE_LSA
   ospf_opaque_init ();
-#endif /* HAVE_OPAQUE_LSA */
   
   /* Need to initialize the default ospf structure, so the interface mode
      commands can be duly processed if they are received before 'router ospf',
@@ -356,24 +367,52 @@ 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 );
+      strlcpy(pid_file, pidfile_temp, sizeof(pid_file));
+    }
+  /* Process id file create. */
+  pid_output (pid_file);
+
   /* Create VTY socket */
   if (instance)
     {
-      sprintf(pid_file, "/var/run/quagga/ospfd-%d.pid", instance);
-      sprintf(vty_path, "/var/run/quagga/ospfd-%d.vty", 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(pid_file, PATH_OSPFD_PID);
-      strcpy(vty_path, OSPF_VTYSH_PATH);
+      strlcpy(vty_path, vty_sock_path, sizeof(vty_path));
     }
-  /* Process id file create. */
-  pid_output (pid_file);
-
   vty_serv_sock (vty_addr, vty_port, vty_path);
 
   /* Print banner. */
-  zlog_notice ("OSPFd %s starting: vty@%d, %s", QUAGGA_VERSION, vty_port, vty_path);
+  zlog_notice ("OSPFd %s starting: vty@%d, %s", FRR_VERSION, vty_port, vty_path);
 
   /* Fetch next active thread. */
   while (thread_fetch (master, &thread))