]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_main.c
*: fix warning fallout from set_socket_path
[mirror_frr.git] / pimd / pim_main.c
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
19 */
20
21 #include <zebra.h>
22
23 #include "log.h"
24 #include "privs.h"
25 #include "version.h"
26 #include <getopt.h>
27 #include "command.h"
28 #include "thread.h"
29 #include <signal.h>
30
31 #include "memory.h"
32 #include "vrf.h"
33 #include "memory_vty.h"
34 #include "filter.h"
35 #include "vty.h"
36 #include "sigevent.h"
37 #include "version.h"
38 #include "prefix.h"
39 #include "plist.h"
40 #include "vrf.h"
41 #include "sockopt.h"
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
49 extern int zclient_debug;
50 #endif
51
52 extern struct host host;
53
54 char config_default[] = SYSCONFDIR PIMD_DEFAULT_CONFIG;
55
56 /* pimd options */
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'},
69 { 0 }
70 };
71
72 /* VTY Socket prefix */
73 char vty_sock_path[MAXPATHLEN] = PIM_VTYSH_PATH;
74
75 /* pimd privileges */
76 zebra_capabilities_t _caps_p [] =
77 {
78 ZCAP_NET_ADMIN,
79 ZCAP_SYS_ADMIN,
80 ZCAP_NET_RAW,
81 };
82
83 /* pimd privileges to run with */
84 struct zebra_privs_t pimd_privs =
85 {
86 #if defined(FRR_USER) && defined(FRR_GROUP)
87 .user = FRR_USER,
88 .group = FRR_GROUP,
89 #endif
90 #ifdef VTY_GROUP
91 .vty_group = VTY_GROUP,
92 #endif
93 .caps_p = _caps_p,
94 .cap_num_p = sizeof(_caps_p)/sizeof(_caps_p[0]),
95 .cap_num_i = 0
96 };
97
98 char* progname;
99 const char *pid_file = PATH_PIMD_PID;
100
101 static void usage(int status)
102 {
103 if (status != 0)
104 fprintf (stderr, "Try `%s --help' for more information.\n", progname);
105 else {
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\
116 "
117
118 #ifdef PIM_ZCLIENT_DEBUG
119 "\
120 -Z, --debug_zclient Enable zclient debugging\n\
121 "
122 #endif
123
124 "\
125 -h, --help Display this help and exit\n\
126 \n\
127 Report bugs to %s\n", progname, PIMD_BUG_ADDRESS);
128 }
129
130 exit (status);
131 }
132
133
134 int main(int argc, char** argv, char** envp) {
135 char *p;
136 char *vty_addr = NULL;
137 int vty_port = -1;
138 int daemon_mode = 0;
139 char *config_file = NULL;
140 char *zebra_sock_path = NULL;
141 struct thread thread;
142
143 umask(0027);
144
145 progname = ((p = strrchr(argv[0], '/')) ? ++p : argv[0]);
146
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);
152 #endif
153
154 /* this while just reads the options */
155 while (1) {
156 int opt;
157
158 opt = getopt_long (argc, argv, "df:i:z:A:P:vZh", longopts, 0);
159
160 if (opt == EOF)
161 break;
162
163 switch (opt) {
164 case 0:
165 break;
166 case 'd':
167 daemon_mode = 1;
168 break;
169 case 'f':
170 config_file = optarg;
171 break;
172 case 'i':
173 pid_file = optarg;
174 break;
175 case 'z':
176 zebra_sock_path = optarg;
177 break;
178 case 'A':
179 vty_addr = optarg;
180 break;
181 case 'P':
182 vty_port = atoi (optarg);
183 break;
184 case OPTION_VTYSOCK:
185 set_socket_path(vty_sock_path, PIM_VTYSH_PATH, optarg, sizeof (vty_sock_path));
186 break;
187 case 'v':
188 printf(PIMD_PROGNAME " version %s\n", PIMD_VERSION);
189 print_version(progname);
190 exit (0);
191 break;
192 #ifdef PIM_ZCLIENT_DEBUG
193 case 'Z':
194 zclient_debug = 1;
195 break;
196 #endif
197 case 'h':
198 usage (0);
199 break;
200 default:
201 usage (1);
202 break;
203 }
204 }
205
206 master = thread_master_create();
207
208 zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting",
209 FRR_VERSION, PIMD_VERSION);
210
211 /*
212 * Initializations
213 */
214 pim_signals_init();
215 cmd_init(1);
216 vty_init(master);
217 memory_init();
218 vrf_init ();
219 access_list_init();
220 prefix_list_init ();
221 pim_route_map_init ();
222 pim_init();
223
224 /*
225 * Initialize zclient "update" and "lookup" sockets
226 */
227 pim_zebra_init(zebra_sock_path);
228
229 zlog_notice("Loading configuration - begin");
230
231 /* Get configuration file. */
232 vty_read_config(config_file, config_default);
233
234 /*
235 Starting from here zlog_* functions will log according configuration
236 */
237
238 zlog_notice("Loading configuration - end");
239
240 /* Change to the daemon program. */
241 if (daemon_mode) {
242 if (daemon(0, 0)) {
243 zlog_warn("failed to daemonize");
244 }
245 }
246
247 /* Process ID file creation. */
248 pid_output(pid_file);
249
250 /* Create pimd VTY socket */
251 if (vty_port < 0)
252 vty_port = PIMD_VTY_PORT;
253 vty_serv_sock(vty_addr, vty_port, vty_sock_path);
254
255 zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting, VTY interface at port TCP %d",
256 FRR_VERSION, PIMD_VERSION, vty_port);
257
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;
266 PIM_DO_DEBUG_ZEBRA;
267 #endif
268
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");
272 #endif
273
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");
278 #endif
279 #endif
280
281 #ifdef PIM_UNEXPECTED_KERNEL_UPCALL
282 zlog_notice("PIM_UNEXPECTED_KERNEL_UPCALL: report unexpected kernel upcall");
283 #endif
284
285 #ifdef HAVE_CLOCK_MONOTONIC
286 zlog_notice("HAVE_CLOCK_MONOTONIC");
287 #else
288 zlog_notice("!HAVE_CLOCK_MONOTONIC");
289 #endif
290
291 while (thread_fetch(master, &thread))
292 thread_call(&thread);
293
294 zlog_err("%s %s: thread_fetch() returned NULL, exiting",
295 __FILE__, __PRETTY_FUNCTION__);
296
297 /* never reached */
298 return 0;
299 }