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 { "dryrun", no_argument
, NULL
, 'C'},
51 { "help", no_argument
, NULL
, 'h'},
52 { "vty_addr", required_argument
, NULL
, 'A'},
53 { "vty_port", required_argument
, NULL
, 'P'},
54 { "retain", no_argument
, NULL
, 'r'},
55 { "user", required_argument
, NULL
, 'u'},
56 { "group", required_argument
, NULL
, 'g'},
57 { "version", no_argument
, NULL
, 'v'},
61 /* ripngd privileges */
62 zebra_capabilities_t _caps_p
[] =
68 struct zebra_privs_t ripngd_privs
=
70 #if defined(QUAGGA_USER)
73 #if defined QUAGGA_GROUP
74 .group
= QUAGGA_GROUP
,
77 .vty_group
= VTY_GROUP
,
85 /* RIPngd program name */
87 /* Route retain mode flag. */
90 /* RIPng VTY bind address. */
91 char *vty_addr
= NULL
;
93 /* RIPng VTY connection port. */
94 int vty_port
= RIPNG_VTY_PORT
;
96 /* Master of threads. */
97 struct thread_master
*master
;
99 /* Process ID saved for use by init system */
100 const char *pid_file
= PATH_RIPNGD_PID
;
102 /* Help information display. */
104 usage (char *progname
, int status
)
107 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
110 printf ("Usage : %s [OPTION...]\n\
111 Daemon which manages RIPng.\n\n\
112 -d, --daemon Runs in daemon mode\n\
113 -f, --config_file Set configuration file name\n\
114 -i, --pid_file Set process identifier file name\n\
115 -A, --vty_addr Set vty's bind address\n\
116 -P, --vty_port Set vty's port number\n\
117 -r, --retain When program terminates, retain added route by ripngd.\n\
118 -u, --user User to run as\n\
119 -g, --group Group to run as\n\
120 -v, --version Print program version\n\
121 -C, --dryrun Check configuration for validity and exit\n\
122 -h, --help Display this help and exit\n\
124 Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
129 /* SIGHUP handler. */
133 zlog_info ("SIGHUP received");
137 /* Reload config file. */
138 vty_read_config (config_file
, config_default
);
139 /* Create VTY's socket */
140 vty_serv_sock (vty_addr
, vty_port
, RIPNG_VTYSH_PATH
);
142 /* Try to return to normal operation. */
145 /* SIGINT handler. */
149 zlog_notice ("Terminating on signal");
157 /* SIGUSR1 handler. */
164 struct quagga_signal_t ripng_signals
[] =
184 /* RIPngd main routine. */
186 main (int argc
, char **argv
)
189 int vty_port
= RIPNG_VTY_PORT
;
192 struct thread thread
;
195 /* Set umask before anything for security */
198 /* get program name */
199 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
201 zlog_default
= openzlog(progname
, ZLOG_RIPNG
,
202 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
208 opt
= getopt_long (argc
, argv
, "df:i:hA:P:u:g:vC", longopts
, 0);
221 config_file
= optarg
;
230 /* Deal with atoi() returning 0 on failure, and ripngd not
231 listening on ripngd port... */
232 if (strcmp(optarg
, "0") == 0)
237 vty_port
= atoi (optarg
);
238 if (vty_port
<= 0 || vty_port
> 0xffff)
239 vty_port
= RIPNG_VTY_PORT
;
245 ripngd_privs
.user
= optarg
;
248 ripngd_privs
.group
= optarg
;
251 print_version (progname
);
266 master
= thread_master_create ();
269 zprivs_init (&ripngd_privs
);
270 signal_init (master
, Q_SIGC(ripng_signals
), ripng_signals
);
280 /* Sort all installed commands. */
283 /* Get configuration file. */
284 vty_read_config (config_file
, config_default
);
286 /* Start execution only if not in dry-run mode */
290 /* Change to the daemon program. */
291 if (daemon_mode
&& daemon (0, 0) < 0)
293 zlog_err("RIPNGd daemon failed: %s", strerror(errno
));
297 /* Create VTY socket */
298 vty_serv_sock (vty_addr
, vty_port
, RIPNG_VTYSH_PATH
);
300 /* Process id file create. */
301 pid_output (pid_file
);
304 zlog_notice ("RIPNGd %s starting: vty@%d", QUAGGA_VERSION
, vty_port
);
306 /* Fetch next active thread. */
307 while (thread_fetch (master
, &thread
))
308 thread_call (&thread
);