3  * Copyright (C) 1998, 1999 Kunihiro Ishiguro
 
   5  * This file is part of GNU Zebra.
 
   7  * GNU Zebra is free software; you can redistribute it and/or modify it
 
   8  * under the terms of the GNU General Public License as published by the
 
   9  * Free Software Foundation; either version 2, or (at your option) any
 
  12  * GNU Zebra is distributed in the hope that it will be useful, but
 
  13  * WITHOUT ANY WARRANTY; without even the implied warranty of
 
  14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
  15  * General Public License for more details.
 
  17  * You should have received a copy of the GNU General Public License
 
  18  * along with GNU Zebra; see the file COPYING.  If not, write to the Free
 
  19  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
  25 #include <lib/version.h>
 
  39 #include "ripngd/ripngd.h"
 
  41 /* Configuration filename and directory. */
 
  42 char config_default[] = SYSCONFDIR RIPNG_DEFAULT_CONFIG;
 
  43 char *config_file = NULL;
 
  46 struct option longopts[] = 
 
  48   { "daemon",      no_argument,       NULL, 'd'},
 
  49   { "config_file", required_argument, NULL, 'f'},
 
  50   { "pid_file",    required_argument, NULL, 'i'},
 
  51   { "socket",      required_argument, NULL, 'z'},
 
  52   { "dryrun",      no_argument,       NULL, 'C'},
 
  53   { "help",        no_argument,       NULL, 'h'},
 
  54   { "vty_addr",    required_argument, NULL, 'A'},
 
  55   { "vty_port",    required_argument, NULL, 'P'},
 
  56   { "retain",      no_argument,       NULL, 'r'},
 
  57   { "user",        required_argument, NULL, 'u'},
 
  58   { "group",       required_argument, NULL, 'g'},
 
  59   { "version",     no_argument,       NULL, 'v'},
 
  63 /* ripngd privileges */
 
  64 zebra_capabilities_t _caps_p [] = 
 
  70 struct zebra_privs_t ripngd_privs =
 
  72 #if defined(QUAGGA_USER)
 
  75 #if defined QUAGGA_GROUP
 
  76   .group = QUAGGA_GROUP,
 
  79   .vty_group = VTY_GROUP,
 
  87 /* RIPngd program name */
 
  89 /* Route retain mode flag. */
 
  92 /* RIPng VTY bind address. */
 
  93 char *vty_addr = NULL;
 
  95 /* RIPng VTY connection port. */
 
  96 int vty_port = RIPNG_VTY_PORT;
 
  98 /* Master of threads. */
 
  99 struct thread_master *master;
 
 101 /* Process ID saved for use by init system */
 
 102 const char *pid_file = PATH_RIPNGD_PID;
 
 104 /* Help information display. */
 
 106 usage (char *progname, int status)
 
 109     fprintf (stderr, "Try `%s --help' for more information.\n", progname);
 
 112       printf ("Usage : %s [OPTION...]\n\
 
 113 Daemon which manages RIPng.\n\n\
 
 114 -d, --daemon       Runs in daemon mode\n\
 
 115 -f, --config_file  Set configuration file name\n\
 
 116 -i, --pid_file     Set process identifier file name\n\
 
 117 -z, --socket       Set path of zebra socket\n\
 
 118 -A, --vty_addr     Set vty's bind address\n\
 
 119 -P, --vty_port     Set vty's port number\n\
 
 120 -r, --retain       When program terminates, retain added route by ripngd.\n\
 
 121 -u, --user         User to run as\n\
 
 122 -g, --group        Group to run as\n\
 
 123 -v, --version      Print program version\n\
 
 124 -C, --dryrun       Check configuration for validity and exit\n\
 
 125 -h, --help         Display this help and exit\n\
 
 127 Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
 
 132 /* SIGHUP handler. */
 
 136   zlog_info ("SIGHUP received");
 
 140   /* Reload config file. */
 
 141   vty_read_config (config_file, config_default);
 
 142   /* Create VTY's socket */
 
 143   vty_serv_sock (vty_addr, vty_port, RIPNG_VTYSH_PATH);
 
 145   /* Try to return to normal operation. */
 
 148 /* SIGINT handler. */
 
 152   zlog_notice ("Terminating on signal");
 
 160 /* SIGUSR1 handler. */
 
 167 struct quagga_signal_t ripng_signals[] =
 
 187 /* RIPngd main routine. */
 
 189 main (int argc, char **argv)
 
 192   int vty_port = RIPNG_VTY_PORT;
 
 197   /* Set umask before anything for security */
 
 200   /* get program name */
 
 201   progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
 
 203   zlog_default = openzlog(progname, ZLOG_RIPNG,
 
 204                           LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
 
 210       opt = getopt_long (argc, argv, "df:i:z:hA:P:u:g:vC", longopts, 0);
 
 223           config_file = optarg;
 
 232           zclient_serv_path_set (optarg);
 
 235           /* Deal with atoi() returning 0 on failure, and ripngd not
 
 236              listening on ripngd port... */
 
 237           if (strcmp(optarg, "0") == 0) 
 
 242           vty_port = atoi (optarg);
 
 243           if (vty_port <= 0 || vty_port > 0xffff)
 
 244             vty_port = RIPNG_VTY_PORT;
 
 250           ripngd_privs.user = optarg;
 
 253           ripngd_privs.group = optarg;
 
 256           print_version (progname);
 
 271   master = thread_master_create ();
 
 274   zprivs_init (&ripngd_privs);
 
 275   signal_init (master, array_size(ripng_signals), ripng_signals);
 
 286   /* Get configuration file. */
 
 287   vty_read_config (config_file, config_default);
 
 289   /* Start execution only if not in dry-run mode */
 
 293   /* Change to the daemon program. */
 
 294   if (daemon_mode && daemon (0, 0) < 0)
 
 296       zlog_err("RIPNGd daemon failed: %s", strerror(errno));
 
 300   /* Create VTY socket */
 
 301   vty_serv_sock (vty_addr, vty_port, RIPNG_VTYSH_PATH);
 
 303   /* Process id file create. */
 
 304   pid_output (pid_file);
 
 307   zlog_notice ("RIPNGd %s starting: vty@%d", QUAGGA_VERSION, vty_port);
 
 309   /* Fetch next active thread. */
 
 310   thread_main (master);