3 Copyright (C) 2008 Everton da Silva Marques
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20 $QuaggaId: $Format:%an, %ai, %h$ $
43 #include "pim_version.h"
44 #include "pim_signals.h"
45 #include "pim_zebra.h"
47 #ifdef PIM_ZCLIENT_DEBUG
48 extern int zclient_debug;
51 extern struct host host;
53 char config_default[] = SYSCONFDIR PIMD_DEFAULT_CONFIG;
55 struct option longopts[] = {
56 { "daemon", no_argument, NULL, 'd'},
57 { "config_file", required_argument, NULL, 'f'},
58 { "pid_file", required_argument, NULL, 'i'},
59 { "vty_addr", required_argument, NULL, 'A'},
60 { "vty_port", required_argument, NULL, 'P'},
61 { "version", no_argument, NULL, 'v'},
62 { "debug_zclient", no_argument, NULL, 'Z'},
63 { "help", no_argument, NULL, 'h'},
68 zebra_capabilities_t _caps_p [] =
75 /* pimd privileges to run with */
76 struct zebra_privs_t pimd_privs =
78 #if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
80 .group = QUAGGA_GROUP,
83 .vty_group = VTY_GROUP,
86 .cap_num_p = sizeof(_caps_p)/sizeof(_caps_p[0]),
91 const char *pid_file = PATH_PIMD_PID;
93 static void usage(int status)
96 fprintf (stderr, "Try `%s --help' for more information.\n", progname);
98 printf ("Usage : %s [OPTION...]\n\
99 Daemon which manages PIM.\n\n\
100 -d, --daemon Run in daemon mode\n\
101 -f, --config_file Set configuration file name\n\
102 -i, --pid_file Set process identifier file name\n\
103 -z, --socket Set path of zebra socket\n\
104 -A, --vty_addr Set vty's bind address\n\
105 -P, --vty_port Set vty's port number\n\
106 -v, --version Print program version\n\
109 #ifdef PIM_ZCLIENT_DEBUG
111 -Z, --debug_zclient Enable zclient debugging\n\
116 -h, --help Display this help and exit\n\
118 Report bugs to %s\n", progname, PIMD_BUG_ADDRESS);
125 int main(int argc, char** argv, char** envp) {
127 char *vty_addr = NULL;
130 char *config_file = NULL;
131 char *zebra_sock_path = NULL;
135 progname = ((p = strrchr(argv[0], '/')) ? ++p : argv[0]);
137 zlog_default = openzlog(progname, ZLOG_PIM,
138 LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
140 /* this while just reads the options */
144 opt = getopt_long (argc, argv, "df:i:z:A:P:vZh", longopts, 0);
156 config_file = optarg;
162 zebra_sock_path = optarg;
168 vty_port = atoi (optarg);
171 printf(PIMD_PROGNAME " version %s\n", PIMD_VERSION);
172 print_version(QUAGGA_PROGNAME);
175 #ifdef PIM_ZCLIENT_DEBUG
189 master = thread_master_create();
191 zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting",
192 QUAGGA_VERSION, PIMD_VERSION);
197 zprivs_init (&pimd_privs);
205 pim_route_map_init ();
209 * Initialize zclient "update" and "lookup" sockets
211 pim_zebra_init (master, zebra_sock_path);
213 zlog_notice("Loading configuration - begin");
215 /* Get configuration file. */
216 vty_read_config(config_file, config_default);
219 Starting from here zlog_* functions will log according configuration
222 zlog_notice("Loading configuration - end");
224 /* Change to the daemon program. */
227 zlog_warn("failed to daemonize");
231 /* Process ID file creation. */
232 pid_output(pid_file);
234 /* Create pimd VTY socket */
236 vty_port = PIMD_VTY_PORT;
237 vty_serv_sock(vty_addr, vty_port, PIM_VTYSH_PATH);
239 zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting, VTY interface at port TCP %d",
240 QUAGGA_VERSION, PIMD_VERSION, vty_port);
242 #ifdef PIM_DEBUG_BYDEFAULT
243 zlog_notice("PIM_DEBUG_BYDEFAULT: Enabling all debug commands");
244 PIM_DO_DEBUG_PIM_EVENTS;
245 PIM_DO_DEBUG_PIM_PACKETS;
246 PIM_DO_DEBUG_PIM_TRACE;
247 PIM_DO_DEBUG_IGMP_EVENTS;
248 PIM_DO_DEBUG_IGMP_PACKETS;
249 PIM_DO_DEBUG_IGMP_TRACE;
253 #ifdef PIM_ZCLIENT_DEBUG
254 zlog_notice("PIM_ZCLIENT_DEBUG: zclient debugging is supported, mode is %s (see option -Z)",
255 zclient_debug ? "ON" : "OFF");
258 #ifdef PIM_CHECK_RECV_IFINDEX_SANITY
259 zlog_notice("PIM_CHECK_RECV_IFINDEX_SANITY: will match sock/recv ifindex");
260 #ifdef PIM_REPORT_RECV_IFINDEX_MISMATCH
261 zlog_notice("PIM_REPORT_RECV_IFINDEX_MISMATCH: will report sock/recv ifindex mismatch");
265 #ifdef PIM_UNEXPECTED_KERNEL_UPCALL
266 zlog_notice("PIM_UNEXPECTED_KERNEL_UPCALL: report unexpected kernel upcall");
269 #ifdef HAVE_CLOCK_MONOTONIC
270 zlog_notice("HAVE_CLOCK_MONOTONIC");
272 zlog_notice("!HAVE_CLOCK_MONOTONIC");
275 thread_main (master);
277 zlog_err("%s %s: thread_fetch() returned NULL, exiting",
278 __FILE__, __PRETTY_FUNCTION__);