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>
38 #include "ripngd/ripngd.h"
40 /* Configuration filename and directory. */
41 char config_default
[] = SYSCONFDIR RIPNG_DEFAULT_CONFIG
;
42 char *config_file
= NULL
;
45 struct option longopts
[] =
47 { "daemon", no_argument
, NULL
, 'd'},
48 { "config_file", required_argument
, NULL
, 'f'},
49 { "pid_file", required_argument
, NULL
, 'i'},
50 { "log_mode", no_argument
, NULL
, 'l'},
51 { "dryrun", no_argument
, NULL
, 'C'},
52 { "help", no_argument
, NULL
, 'h'},
53 { "vty_addr", required_argument
, NULL
, 'A'},
54 { "vty_port", required_argument
, NULL
, 'P'},
55 { "retain", no_argument
, NULL
, 'r'},
56 { "user", required_argument
, NULL
, 'u'},
57 { "group", required_argument
, NULL
, 'g'},
58 { "version", no_argument
, NULL
, 'v'},
62 /* ripngd privileges */
63 zebra_capabilities_t _caps_p
[] =
69 struct zebra_privs_t ripngd_privs
=
71 #if defined(QUAGGA_USER)
74 #if defined QUAGGA_GROUP
75 .group
= QUAGGA_GROUP
,
78 .vty_group
= VTY_GROUP
,
86 /* RIPngd program name */
88 /* Route retain mode flag. */
91 /* RIPng VTY bind address. */
92 char *vty_addr
= NULL
;
94 /* RIPng VTY connection port. */
95 int vty_port
= RIPNG_VTY_PORT
;
97 /* Master of threads. */
98 struct thread_master
*master
;
100 /* Process ID saved for use by init system */
101 const char *pid_file
= PATH_RIPNGD_PID
;
103 /* Help information display. */
105 usage (char *progname
, int status
)
108 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
111 printf ("Usage : %s [OPTION...]\n\
112 Daemon which manages RIPng.\n\n\
113 -d, --daemon Runs in daemon mode\n\
114 -f, --config_file Set configuration file name\n\
115 -i, --pid_file Set process identifier file name\n\
116 -l. --log_mode Set verbose log mode flag\n\
117 -A, --vty_addr Set vty's bind address\n\
118 -P, --vty_port Set vty's port number\n\
119 -r, --retain When program terminates, retain added route by ripngd.\n\
120 -u, --user User to run as\n\
121 -g, --group Group to run as\n\
122 -v, --version Print program version\n\
123 -C, --dryrun Check configuration for validity and exit\n\
124 -h, --help Display this help and exit\n\
126 Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
131 /* SIGHUP handler. */
135 zlog_info ("SIGHUP received");
139 /* Reload config file. */
140 vty_read_config (config_file
, config_default
);
141 /* Create VTY's socket */
142 vty_serv_sock (vty_addr
, vty_port
, RIPNG_VTYSH_PATH
);
144 /* Try to return to normal operation. */
147 /* SIGINT handler. */
151 zlog_notice ("Terminating on signal");
159 /* SIGUSR1 handler. */
166 struct quagga_signal_t ripng_signals
[] =
186 /* RIPngd main routine. */
188 main (int argc
, char **argv
)
191 int vty_port
= RIPNG_VTY_PORT
;
194 struct thread thread
;
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
, "dlf:i:hA:P:u:g:vC", longopts
, 0);
226 config_file
= 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 vty_port
= (vty_port
? vty_port
: RIPNG_VTY_PORT
);
249 ripngd_privs
.user
= optarg
;
252 ripngd_privs
.group
= optarg
;
255 print_version (progname
);
270 master
= thread_master_create ();
273 zprivs_init (&ripngd_privs
);
274 signal_init (master
, Q_SIGC(ripng_signals
), ripng_signals
);
284 /* Sort all installed commands. */
287 /* Get configuration file. */
288 vty_read_config (config_file
, config_default
);
290 /* Start execution only if not in dry-run mode */
294 /* Change to the daemon program. */
298 /* Create VTY socket */
299 vty_serv_sock (vty_addr
, vty_port
, RIPNG_VTYSH_PATH
);
301 /* Process id file create. */
302 pid_output (pid_file
);
305 zlog_notice ("RIPNGd %s starting: vty@%d", QUAGGA_VERSION
, vty_port
);
307 /* Fetch next active thread. */
308 while (thread_fetch (master
, &thread
))
309 thread_call (&thread
);