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,
33 #include "memory_vty.h"
44 #include "pim_version.h"
45 #include "pim_signals.h"
46 #include "pim_zebra.h"
48 #ifdef PIM_ZCLIENT_DEBUG
49 extern int zclient_debug
;
52 extern struct host host
;
54 char config_default
[] = SYSCONFDIR PIMD_DEFAULT_CONFIG
;
57 #define OPTION_VTYSOCK 1000
58 struct option longopts
[] = {
59 { "daemon", no_argument
, NULL
, 'd'},
60 { "config_file", required_argument
, NULL
, 'f'},
61 { "pid_file", required_argument
, NULL
, 'i'},
62 { "socket", required_argument
, NULL
, 'z'},
63 { "vty_addr", required_argument
, NULL
, 'A'},
64 { "vty_port", required_argument
, NULL
, 'P'},
65 { "vty_socket", required_argument
, NULL
, OPTION_VTYSOCK
},
66 { "version", no_argument
, NULL
, 'v'},
67 { "debug_zclient", no_argument
, NULL
, 'Z'},
68 { "help", no_argument
, NULL
, 'h'},
72 /* VTY Socket prefix */
73 char vty_sock_path
[MAXPATHLEN
] = PIM_VTYSH_PATH
;
76 zebra_capabilities_t _caps_p
[] =
83 /* pimd privileges to run with */
84 struct zebra_privs_t pimd_privs
=
86 #if defined(FRR_USER) && defined(FRR_GROUP)
91 .vty_group
= VTY_GROUP
,
94 .cap_num_p
= sizeof(_caps_p
)/sizeof(_caps_p
[0]),
99 const char *pid_file
= PATH_PIMD_PID
;
101 static void usage(int status
)
104 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
106 printf ("Usage : %s [OPTION...]\n\
107 Daemon which manages PIM.\n\n\
108 -d, --daemon Run in daemon mode\n\
109 -f, --config_file Set configuration file name\n\
110 -i, --pid_file Set process identifier file name\n\
111 -z, --socket Set path of zebra socket\n\
112 -A, --vty_addr Set vty's bind address\n\
113 -P, --vty_port Set vty's port number\n\
114 --vty_socket Override vty socket path\n\
115 -v, --version Print program version\n\
118 #ifdef PIM_ZCLIENT_DEBUG
120 -Z, --debug_zclient Enable zclient debugging\n\
125 -h, --help Display this help and exit\n\
127 Report bugs to %s\n", progname
, PIMD_BUG_ADDRESS
);
134 int main(int argc
, char** argv
, char** envp
) {
136 char *vty_addr
= NULL
;
139 char *config_file
= NULL
;
140 char *zebra_sock_path
= NULL
;
141 struct thread thread
;
145 progname
= ((p
= strrchr(argv
[0], '/')) ? ++p
: argv
[0]);
147 zlog_default
= openzlog(progname
, ZLOG_PIM
, 0,
148 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
149 zprivs_init (&pimd_privs
);
150 #if defined(HAVE_CUMULUS)
151 zlog_set_level (NULL
, ZLOG_DEST_SYSLOG
, zlog_default
->default_lvl
);
154 /* this while just reads the options */
158 opt
= getopt_long (argc
, argv
, "df:i:z:A:P:vZh", longopts
, 0);
170 config_file
= optarg
;
176 zebra_sock_path
= optarg
;
182 vty_port
= atoi (optarg
);
185 set_socket_path(vty_sock_path
, PIM_VTYSH_PATH
, optarg
, sizeof (vty_sock_path
));
188 printf(PIMD_PROGNAME
" version %s\n", PIMD_VERSION
);
189 print_version(progname
);
192 #ifdef PIM_ZCLIENT_DEBUG
206 master
= thread_master_create();
208 zlog_notice("Quagga %s " PIMD_PROGNAME
" %s starting",
209 FRR_VERSION
, PIMD_VERSION
);
221 pim_route_map_init ();
225 * Initialize zclient "update" and "lookup" sockets
227 pim_zebra_init(zebra_sock_path
);
229 zlog_notice("Loading configuration - begin");
231 /* Get configuration file. */
232 vty_read_config(config_file
, config_default
);
235 Starting from here zlog_* functions will log according configuration
238 zlog_notice("Loading configuration - end");
240 /* Change to the daemon program. */
243 zlog_warn("failed to daemonize");
247 /* Process ID file creation. */
248 pid_output(pid_file
);
250 /* Create pimd VTY socket */
252 vty_port
= PIMD_VTY_PORT
;
253 vty_serv_sock(vty_addr
, vty_port
, vty_sock_path
);
255 zlog_notice("Quagga %s " PIMD_PROGNAME
" %s starting, VTY interface at port TCP %d",
256 FRR_VERSION
, PIMD_VERSION
, vty_port
);
258 #ifdef PIM_DEBUG_BYDEFAULT
259 zlog_notice("PIM_DEBUG_BYDEFAULT: Enabling all debug commands");
260 PIM_DO_DEBUG_PIM_EVENTS
;
261 PIM_DO_DEBUG_PIM_PACKETS
;
262 PIM_DO_DEBUG_PIM_TRACE
;
263 PIM_DO_DEBUG_IGMP_EVENTS
;
264 PIM_DO_DEBUG_IGMP_PACKETS
;
265 PIM_DO_DEBUG_IGMP_TRACE
;
269 #ifdef PIM_ZCLIENT_DEBUG
270 zlog_notice("PIM_ZCLIENT_DEBUG: zclient debugging is supported, mode is %s (see option -Z)",
271 zclient_debug
? "ON" : "OFF");
274 #ifdef PIM_CHECK_RECV_IFINDEX_SANITY
275 zlog_notice("PIM_CHECK_RECV_IFINDEX_SANITY: will match sock/recv ifindex");
276 #ifdef PIM_REPORT_RECV_IFINDEX_MISMATCH
277 zlog_notice("PIM_REPORT_RECV_IFINDEX_MISMATCH: will report sock/recv ifindex mismatch");
281 #ifdef PIM_UNEXPECTED_KERNEL_UPCALL
282 zlog_notice("PIM_UNEXPECTED_KERNEL_UPCALL: report unexpected kernel upcall");
285 #ifdef HAVE_CLOCK_MONOTONIC
286 zlog_notice("HAVE_CLOCK_MONOTONIC");
288 zlog_notice("!HAVE_CLOCK_MONOTONIC");
291 while (thread_fetch(master
, &thread
))
292 thread_call(&thread
);
294 zlog_err("%s %s: thread_fetch() returned NULL, exiting",
295 __FILE__
, __PRETTY_FUNCTION__
);