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