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