]> git.proxmox.com Git - mirror_frr.git/blame - pimd/pim_main.c
pimd: Fix unguarded log message
[mirror_frr.git] / pimd / pim_main.c
CommitLineData
12e41d03
DL
1/*
2 PIM for Quagga
3 Copyright (C) 2008 Everton da Silva Marques
4
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.
9
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.
14
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,
18 MA 02110-1301 USA
7e0cff2f 19
12e41d03
DL
20*/
21
22#include <zebra.h>
23
24#include "log.h"
25#include "privs.h"
26#include "version.h"
27#include <getopt.h>
28#include "command.h"
29#include "thread.h"
30#include <signal.h>
31
32#include "memory.h"
fc7948fa
DL
33#include "vrf.h"
34#include "memory_vty.h"
12e41d03
DL
35#include "filter.h"
36#include "vty.h"
37#include "sigevent.h"
38#include "version.h"
0e8ce7e6
DS
39#include "prefix.h"
40#include "plist.h"
48e8451b 41#include "vrf.h"
12e41d03
DL
42
43#include "pimd.h"
44#include "pim_version.h"
45#include "pim_signals.h"
46#include "pim_zebra.h"
47
48#ifdef PIM_ZCLIENT_DEBUG
49extern int zclient_debug;
50#endif
51
52extern struct host host;
53
54char config_default[] = SYSCONFDIR PIMD_DEFAULT_CONFIG;
55
56struct option longopts[] = {
57 { "daemon", no_argument, NULL, 'd'},
58 { "config_file", required_argument, NULL, 'f'},
59 { "pid_file", required_argument, NULL, 'i'},
60 { "vty_addr", required_argument, NULL, 'A'},
61 { "vty_port", required_argument, NULL, 'P'},
62 { "version", no_argument, NULL, 'v'},
63 { "debug_zclient", no_argument, NULL, 'Z'},
64 { "help", no_argument, NULL, 'h'},
65 { 0 }
66};
67
68/* pimd privileges */
69zebra_capabilities_t _caps_p [] =
70{
71 ZCAP_NET_ADMIN,
72 ZCAP_SYS_ADMIN,
73 ZCAP_NET_RAW,
74};
75
76/* pimd privileges to run with */
77struct zebra_privs_t pimd_privs =
78{
79#if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
80 .user = QUAGGA_USER,
81 .group = QUAGGA_GROUP,
82#endif
83#ifdef VTY_GROUP
84 .vty_group = VTY_GROUP,
85#endif
86 .caps_p = _caps_p,
87 .cap_num_p = sizeof(_caps_p)/sizeof(_caps_p[0]),
88 .cap_num_i = 0
89};
90
91char* progname;
92const char *pid_file = PATH_PIMD_PID;
93
94static void usage(int status)
95{
96 if (status != 0)
97 fprintf (stderr, "Try `%s --help' for more information.\n", progname);
98 else {
99 printf ("Usage : %s [OPTION...]\n\
100Daemon which manages PIM.\n\n\
101-d, --daemon Run in daemon mode\n\
102-f, --config_file Set configuration file name\n\
103-i, --pid_file Set process identifier file name\n\
104-z, --socket Set path of zebra socket\n\
105-A, --vty_addr Set vty's bind address\n\
106-P, --vty_port Set vty's port number\n\
107-v, --version Print program version\n\
108"
109
110#ifdef PIM_ZCLIENT_DEBUG
111"\
112-Z, --debug_zclient Enable zclient debugging\n\
113"
114#endif
115
116"\
117-h, --help Display this help and exit\n\
118\n\
0252d82d 119Report bugs to %s\n", progname, PACKAGE_BUGREPORT);
12e41d03
DL
120 }
121
122 exit (status);
123}
124
125
126int main(int argc, char** argv, char** envp) {
127 char *p;
128 char *vty_addr = NULL;
129 int vty_port = -1;
130 int daemon_mode = 0;
131 char *config_file = NULL;
132 char *zebra_sock_path = NULL;
133 struct thread thread;
134
135 umask(0027);
136
137 progname = ((p = strrchr(argv[0], '/')) ? ++p : argv[0]);
f28692a4 138
469351b3 139 zlog_default = openzlog(progname, ZLOG_PIM, 0,
12e41d03 140 LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
2caa9b39 141 zprivs_init (&pimd_privs);
c05795b1
SK
142#if defined(HAVE_CUMULUS)
143 zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl);
144#endif
f28692a4 145
12e41d03
DL
146 /* this while just reads the options */
147 while (1) {
148 int opt;
149
150 opt = getopt_long (argc, argv, "df:i:z:A:P:vZh", longopts, 0);
151
152 if (opt == EOF)
153 break;
154
155 switch (opt) {
156 case 0:
157 break;
158 case 'd':
159 daemon_mode = 1;
160 break;
161 case 'f':
162 config_file = optarg;
163 break;
164 case 'i':
165 pid_file = optarg;
166 break;
167 case 'z':
168 zebra_sock_path = optarg;
169 break;
170 case 'A':
171 vty_addr = optarg;
172 break;
173 case 'P':
174 vty_port = atoi (optarg);
175 break;
176 case 'v':
177 printf(PIMD_PROGNAME " version %s\n", PIMD_VERSION);
178 print_version(QUAGGA_PROGNAME);
179 exit (0);
180 break;
181#ifdef PIM_ZCLIENT_DEBUG
182 case 'Z':
183 zclient_debug = 1;
184 break;
185#endif
186 case 'h':
187 usage (0);
188 break;
189 default:
190 usage (1);
191 break;
192 }
193 }
194
195 master = thread_master_create();
196
12e41d03
DL
197 zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting",
198 QUAGGA_VERSION, PIMD_VERSION);
199
200 /*
201 * Initializations
202 */
12e41d03
DL
203 pim_signals_init();
204 cmd_init(1);
205 vty_init(master);
206 memory_init();
48e8451b 207 vrf_init ();
12e41d03 208 access_list_init();
0e8ce7e6
DS
209 prefix_list_init ();
210 pim_route_map_init ();
12e41d03
DL
211 pim_init();
212
213 /*
18a23295 214 * Initialize zclient "update" and "lookup" sockets
12e41d03
DL
215 */
216 pim_zebra_init(zebra_sock_path);
217
218 zlog_notice("Loading configuration - begin");
219
220 /* Get configuration file. */
221 vty_read_config(config_file, config_default);
222
223 /*
224 Starting from here zlog_* functions will log according configuration
225 */
226
227 zlog_notice("Loading configuration - end");
228
229 /* Change to the daemon program. */
230 if (daemon_mode) {
231 if (daemon(0, 0)) {
232 zlog_warn("failed to daemonize");
233 }
234 }
235
236 /* Process ID file creation. */
237 pid_output(pid_file);
238
239 /* Create pimd VTY socket */
240 if (vty_port < 0)
241 vty_port = PIMD_VTY_PORT;
242 vty_serv_sock(vty_addr, vty_port, PIM_VTYSH_PATH);
243
244 zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting, VTY interface at port TCP %d",
245 QUAGGA_VERSION, PIMD_VERSION, vty_port);
246
247#ifdef PIM_DEBUG_BYDEFAULT
248 zlog_notice("PIM_DEBUG_BYDEFAULT: Enabling all debug commands");
249 PIM_DO_DEBUG_PIM_EVENTS;
250 PIM_DO_DEBUG_PIM_PACKETS;
251 PIM_DO_DEBUG_PIM_TRACE;
252 PIM_DO_DEBUG_IGMP_EVENTS;
253 PIM_DO_DEBUG_IGMP_PACKETS;
254 PIM_DO_DEBUG_IGMP_TRACE;
255 PIM_DO_DEBUG_ZEBRA;
256#endif
257
258#ifdef PIM_ZCLIENT_DEBUG
259 zlog_notice("PIM_ZCLIENT_DEBUG: zclient debugging is supported, mode is %s (see option -Z)",
260 zclient_debug ? "ON" : "OFF");
261#endif
262
263#ifdef PIM_CHECK_RECV_IFINDEX_SANITY
264 zlog_notice("PIM_CHECK_RECV_IFINDEX_SANITY: will match sock/recv ifindex");
265#ifdef PIM_REPORT_RECV_IFINDEX_MISMATCH
266 zlog_notice("PIM_REPORT_RECV_IFINDEX_MISMATCH: will report sock/recv ifindex mismatch");
267#endif
268#endif
269
270#ifdef PIM_UNEXPECTED_KERNEL_UPCALL
271 zlog_notice("PIM_UNEXPECTED_KERNEL_UPCALL: report unexpected kernel upcall");
272#endif
273
274#ifdef HAVE_CLOCK_MONOTONIC
275 zlog_notice("HAVE_CLOCK_MONOTONIC");
276#else
277 zlog_notice("!HAVE_CLOCK_MONOTONIC");
278#endif
279
280 while (thread_fetch(master, &thread))
281 thread_call(&thread);
282
283 zlog_err("%s %s: thread_fetch() returned NULL, exiting",
284 __FILE__, __PRETTY_FUNCTION__);
285
286 /* never reached */
287 return 0;
288}