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