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