diff options
Diffstat (limited to 'ospfd/ospf_main.c')
| -rw-r--r-- | ospfd/ospf_main.c | 211 |
1 files changed, 25 insertions, 186 deletions
diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c index edb1ca470e..5705dad5d4 100644 --- a/ospfd/ospf_main.c +++ b/ospfd/ospf_main.c @@ -41,7 +41,7 @@ #include "sigevent.h" #include "zclient.h" #include "vrf.h" -#include "sockopt.h" +#include "libfrr.h" #include "ospfd/ospfd.h" #include "ospfd/ospf_interface.h" @@ -76,41 +76,19 @@ struct zebra_privs_t ospfd_privs = .cap_num_i = 0 }; -/* Configuration filename and directory. */ -char config_default[100]; - /* OSPFd options. */ -#define OPTION_VTYSOCK 1000 struct option longopts[] = { - { "daemon", no_argument, NULL, 'd'}, { "instance", required_argument, NULL, 'n'}, - { "config_file", required_argument, NULL, 'f'}, - { "pid_file", required_argument, NULL, 'i'}, - { "socket", required_argument, NULL, 'z'}, - { "dryrun", no_argument, NULL, 'C'}, - { "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'}, - { "version", no_argument, NULL, 'v'}, { 0 } }; /* OSPFd program name */ -/* VTY Socket prefix */ -char vty_sock_path[MAXPATHLEN] = OSPF_VTYSH_PATH; - /* Master of threads. */ struct thread_master *master; -/* Process ID saved for use by init system */ -char pid_file[100]; - #ifdef SUPPORT_OSPF_API extern int ospf_apiserver_enable; #endif /* SUPPORT_OSPF_API */ @@ -124,21 +102,6 @@ usage (char *progname, int status) else { printf ("Usage : %s [OPTION...]\n\ -Daemon which manages OSPF.\n\n\ --d, --daemon Runs in daemon mode\n\ --n, --instance Set the instance id\n\ --f, --config_file Set configuration file name\n\ --i, --pid_file Set process identifier file name\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\ --v, --version Print program version\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, FRR_BUG_ADDRESS); } @@ -149,7 +112,7 @@ Report bugs to %s\n", progname, FRR_BUG_ADDRESS); static void sighup (void) { - zlog (NULL, LOG_INFO, "SIGHUP received"); + zlog_info("SIGHUP received"); } /* SIGINT / SIGTERM handler. */ @@ -164,7 +127,7 @@ sigint (void) static void sigusr1 (void) { - zlog_rotate (NULL); + zlog_rotate(); } struct quagga_signal_t ospf_signals[] = @@ -187,39 +150,38 @@ struct quagga_signal_t ospf_signals[] = }, }; +FRR_DAEMON_INFO(ospfd, OSPF, + .vty_port = OSPF_VTY_PORT, + + .proghelp = "Implementation of the OSPFv2 routing protocol.", + + .signals = ospf_signals, + .n_signals = array_size(ospf_signals), + + .privs = &ospfd_privs, +) + /* OSPFd main routine. */ int main (int argc, char **argv) { - char *p; - char *vty_addr = NULL; - int vty_port = OSPF_VTY_PORT; - char vty_path[100]; - int daemon_mode = 0; - char *config_file = NULL; - char *progname; u_short instance = 0; - struct thread thread; - int dryrun = 0; - - /* Set umask before anything for security */ - umask (0027); #ifdef SUPPORT_OSPF_API /* OSPF apiserver is disabled by default. */ 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]); + frr_preinit (&ospfd_di, argc, argv); + frr_opt_add ("n:a", longopts, + " -n, --instance Set the instance id\n" + " -a, --apiserver Enable OSPF apiserver\n"); while (1) { int opt; - opt = getopt_long (argc, argv, "df:i:n:z:hA:P:u:g:avC", longopts, 0); + opt = frr_getopt (argc, argv, NULL); if (opt == EOF) break; @@ -227,65 +189,19 @@ main (int argc, char **argv) switch (opt) { case 'n': - instance = atoi(optarg); + ospfd_di.instance = instance = atoi(optarg); if (instance < 1) exit(0); break; case 0: break; - case 'd': - daemon_mode = 1; - break; - case 'f': - config_file = optarg; - break; - case 'A': - vty_addr = optarg; - break; - case 'i': - strcpy(pid_file,optarg); - break; - case 'z': - zclient_serv_path_set (optarg); - break; - case 'P': - /* Deal with atoi() returning 0 on failure, and ospfd not - listening on ospfd port... */ - if (strcmp(optarg, "0") == 0) - { - vty_port = 0; - break; - } - vty_port = atoi (optarg); - 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; - case 'g': - ospfd_privs.group = optarg; - break; #ifdef SUPPORT_OSPF_API case 'a': ospf_apiserver_enable = 1; break; #endif /* SUPPORT_OSPF_API */ - case 'v': - print_version (progname); - exit (0); - break; - case 'C': - dryrun = 1; - break; - case 'h': - usage (progname, 0); - break; default: - usage (progname, 1); + frr_help_exit (1); break; } } @@ -294,29 +210,18 @@ main (int argc, char **argv) if (geteuid () != 0) { errno = EPERM; - perror (progname); + perror (ospfd_di.progname); exit (1); } - zlog_default = openzlog (progname, ZLOG_OSPF, instance, - LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); - zprivs_init (&ospfd_privs); -#if defined(HAVE_CUMULUS) - zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl); -#endif - /* OSPF master init. */ - ospf_master_init (); + ospf_master_init (frr_init ()); /* Initializations. */ master = om->master; /* Library inits. */ - signal_init (master, array_size(ospf_signals), ospf_signals); - cmd_init (1); debug_init (); - vty_init (master); - memory_init (); vrf_init (); access_list_init (); @@ -349,74 +254,8 @@ main (int argc, char **argv) exit (1); } - /* Get configuration file. */ - if (instance) - sprintf(config_default, "%sospfd-%d.conf", SYSCONFDIR, instance); - else - sprintf(config_default, "%s%s", SYSCONFDIR, OSPF_DEFAULT_CONFIG); - vty_read_config (config_file, config_default); - - /* Start execution only if not in dry-run mode */ - if (dryrun) - return(0); - - /* Change to the daemon program. */ - if (daemon_mode && daemon (0, 0) < 0) - { - zlog_err("OSPFd daemon failed: %s", strerror(errno)); - 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) - { - /* 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 - { - strlcpy(vty_path, vty_sock_path, sizeof(vty_path)); - } - vty_serv_sock (vty_addr, vty_port, vty_path); - - /* Print banner. */ - zlog_notice ("OSPFd %s starting: vty@%d, %s", FRR_VERSION, vty_port, vty_path); - - /* Fetch next active thread. */ - while (thread_fetch (master, &thread)) - thread_call (&thread); + frr_config_fork(); + frr_run (master); /* Not reached. */ return (0); |
