]>
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 | |
12e41d03 DL |
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" | |
fc7948fa DL |
32 | #include "vrf.h" |
33 | #include "memory_vty.h" | |
12e41d03 DL |
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" |
ff1c42fb | 41 | #include "sockopt.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" |
7176984f | 48 | #include "pim_iface.h" |
dfe43e25 | 49 | #include "pim_rp.h" |
12e41d03 | 50 | |
12e41d03 DL |
51 | extern struct host host; |
52 | ||
53 | char config_default[] = SYSCONFDIR PIMD_DEFAULT_CONFIG; | |
54 | ||
a8cdea56 MW |
55 | /* pimd options */ |
56 | #define OPTION_VTYSOCK 1000 | |
12e41d03 DL |
57 | struct option longopts[] = { |
58 | { "daemon", no_argument, NULL, 'd'}, | |
59 | { "config_file", required_argument, NULL, 'f'}, | |
60 | { "pid_file", required_argument, NULL, 'i'}, | |
780cff2f | 61 | { "socket", required_argument, NULL, 'z'}, |
12e41d03 DL |
62 | { "vty_addr", required_argument, NULL, 'A'}, |
63 | { "vty_port", required_argument, NULL, 'P'}, | |
a8cdea56 | 64 | { "vty_socket", required_argument, NULL, OPTION_VTYSOCK}, |
12e41d03 DL |
65 | { "version", no_argument, NULL, 'v'}, |
66 | { "debug_zclient", no_argument, NULL, 'Z'}, | |
67 | { "help", no_argument, NULL, 'h'}, | |
68 | { 0 } | |
69 | }; | |
70 | ||
a8cdea56 MW |
71 | /* VTY Socket prefix */ |
72 | char vty_sock_path[MAXPATHLEN] = PIM_VTYSH_PATH; | |
73 | ||
12e41d03 DL |
74 | /* pimd privileges */ |
75 | zebra_capabilities_t _caps_p [] = | |
76 | { | |
77 | ZCAP_NET_ADMIN, | |
78 | ZCAP_SYS_ADMIN, | |
79 | ZCAP_NET_RAW, | |
2a333e0f | 80 | ZCAP_BIND, |
12e41d03 DL |
81 | }; |
82 | ||
83 | /* pimd privileges to run with */ | |
84 | struct zebra_privs_t pimd_privs = | |
85 | { | |
b2f36157 DL |
86 | #if defined(FRR_USER) && defined(FRR_GROUP) |
87 | .user = FRR_USER, | |
88 | .group = FRR_GROUP, | |
12e41d03 DL |
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\ | |
a8cdea56 | 114 | --vty_socket Override vty socket path\n\ |
12e41d03 | 115 | -v, --version Print program version\n\ |
12e41d03 DL |
116 | -h, --help Display this help and exit\n\ |
117 | \n\ | |
0252d82d | 118 | Report bugs to %s\n", progname, PACKAGE_BUGREPORT); |
12e41d03 DL |
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; | |
a8cdea56 MW |
175 | case OPTION_VTYSOCK: |
176 | set_socket_path(vty_sock_path, PIM_VTYSH_PATH, optarg, sizeof (vty_sock_path)); | |
177 | break; | |
12e41d03 DL |
178 | case 'v': |
179 | printf(PIMD_PROGNAME " version %s\n", PIMD_VERSION); | |
b2f36157 | 180 | print_version(progname); |
12e41d03 DL |
181 | exit (0); |
182 | break; | |
12e41d03 DL |
183 | case 'h': |
184 | usage (0); | |
185 | break; | |
186 | default: | |
187 | usage (1); | |
188 | break; | |
189 | } | |
190 | } | |
191 | ||
192 | master = thread_master_create(); | |
193 | ||
12e41d03 | 194 | zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting", |
b2f36157 | 195 | FRR_VERSION, PIMD_VERSION); |
12e41d03 DL |
196 | |
197 | /* | |
198 | * Initializations | |
199 | */ | |
12e41d03 DL |
200 | pim_signals_init(); |
201 | cmd_init(1); | |
202 | vty_init(master); | |
203 | memory_init(); | |
48e8451b | 204 | vrf_init (); |
12e41d03 | 205 | access_list_init(); |
0e8ce7e6 | 206 | prefix_list_init (); |
dfe43e25 DW |
207 | prefix_list_add_hook (pim_rp_prefix_list_update); |
208 | prefix_list_delete_hook (pim_rp_prefix_list_update); | |
209 | ||
0e8ce7e6 | 210 | pim_route_map_init (); |
12e41d03 | 211 | pim_init(); |
2a333e0f | 212 | pim_msdp_init (master); |
12e41d03 DL |
213 | |
214 | /* | |
18a23295 | 215 | * Initialize zclient "update" and "lookup" sockets |
12e41d03 DL |
216 | */ |
217 | pim_zebra_init(zebra_sock_path); | |
218 | ||
219 | zlog_notice("Loading configuration - begin"); | |
220 | ||
221 | /* Get configuration file. */ | |
222 | vty_read_config(config_file, config_default); | |
223 | ||
224 | /* | |
225 | Starting from here zlog_* functions will log according configuration | |
226 | */ | |
227 | ||
228 | zlog_notice("Loading configuration - end"); | |
229 | ||
230 | /* Change to the daemon program. */ | |
231 | if (daemon_mode) { | |
232 | if (daemon(0, 0)) { | |
233 | zlog_warn("failed to daemonize"); | |
234 | } | |
235 | } | |
236 | ||
237 | /* Process ID file creation. */ | |
238 | pid_output(pid_file); | |
239 | ||
240 | /* Create pimd VTY socket */ | |
241 | if (vty_port < 0) | |
242 | vty_port = PIMD_VTY_PORT; | |
a8cdea56 | 243 | vty_serv_sock(vty_addr, vty_port, vty_sock_path); |
12e41d03 DL |
244 | |
245 | zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting, VTY interface at port TCP %d", | |
b2f36157 | 246 | FRR_VERSION, PIMD_VERSION, vty_port); |
12e41d03 DL |
247 | |
248 | #ifdef PIM_DEBUG_BYDEFAULT | |
249 | zlog_notice("PIM_DEBUG_BYDEFAULT: Enabling all debug commands"); | |
250 | PIM_DO_DEBUG_PIM_EVENTS; | |
251 | PIM_DO_DEBUG_PIM_PACKETS; | |
252 | PIM_DO_DEBUG_PIM_TRACE; | |
253 | PIM_DO_DEBUG_IGMP_EVENTS; | |
254 | PIM_DO_DEBUG_IGMP_PACKETS; | |
255 | PIM_DO_DEBUG_IGMP_TRACE; | |
256 | PIM_DO_DEBUG_ZEBRA; | |
257 | #endif | |
258 | ||
12e41d03 DL |
259 | #ifdef PIM_CHECK_RECV_IFINDEX_SANITY |
260 | zlog_notice("PIM_CHECK_RECV_IFINDEX_SANITY: will match sock/recv ifindex"); | |
261 | #ifdef PIM_REPORT_RECV_IFINDEX_MISMATCH | |
262 | zlog_notice("PIM_REPORT_RECV_IFINDEX_MISMATCH: will report sock/recv ifindex mismatch"); | |
263 | #endif | |
264 | #endif | |
265 | ||
266 | #ifdef PIM_UNEXPECTED_KERNEL_UPCALL | |
267 | zlog_notice("PIM_UNEXPECTED_KERNEL_UPCALL: report unexpected kernel upcall"); | |
268 | #endif | |
269 | ||
12e41d03 DL |
270 | while (thread_fetch(master, &thread)) |
271 | thread_call(&thread); | |
272 | ||
273 | zlog_err("%s %s: thread_fetch() returned NULL, exiting", | |
274 | __FILE__, __PRETTY_FUNCTION__); | |
275 | ||
276 | /* never reached */ | |
277 | return 0; | |
278 | } |