]>
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 | |
b58ed1f8 | 19 | <<<<<<< HEAD |
7e0cff2f | 20 | |
b58ed1f8 DS |
21 | ======= |
22 | >>>>>>> origin/master | |
12e41d03 DL |
23 | */ |
24 | ||
25 | #include <zebra.h> | |
26 | ||
27 | #include "log.h" | |
28 | #include "privs.h" | |
29 | #include "version.h" | |
30 | #include <getopt.h> | |
31 | #include "command.h" | |
32 | #include "thread.h" | |
33 | #include <signal.h> | |
34 | ||
35 | #include "memory.h" | |
fc7948fa DL |
36 | #include "vrf.h" |
37 | #include "memory_vty.h" | |
12e41d03 DL |
38 | #include "filter.h" |
39 | #include "vty.h" | |
40 | #include "sigevent.h" | |
41 | #include "version.h" | |
0e8ce7e6 DS |
42 | #include "prefix.h" |
43 | #include "plist.h" | |
48e8451b | 44 | #include "vrf.h" |
12e41d03 DL |
45 | |
46 | #include "pimd.h" | |
47 | #include "pim_version.h" | |
48 | #include "pim_signals.h" | |
49 | #include "pim_zebra.h" | |
11128587 | 50 | #include "pim_msdp.h" |
7176984f | 51 | #include "pim_iface.h" |
dfe43e25 | 52 | #include "pim_rp.h" |
12e41d03 | 53 | |
12e41d03 DL |
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 | { | |
b2f36157 DL |
82 | #if defined(FRR_USER) && defined(FRR_GROUP) |
83 | .user = FRR_USER, | |
84 | .group = FRR_GROUP, | |
12e41d03 DL |
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\ | |
12e41d03 DL |
111 | -h, --help Display this help and exit\n\ |
112 | \n\ | |
0252d82d | 113 | Report bugs to %s\n", progname, PACKAGE_BUGREPORT); |
12e41d03 DL |
114 | } |
115 | ||
116 | exit (status); | |
117 | } | |
118 | ||
119 | ||
120 | int main(int argc, char** argv, char** envp) { | |
121 | char *p; | |
122 | char *vty_addr = NULL; | |
123 | int vty_port = -1; | |
124 | int daemon_mode = 0; | |
125 | char *config_file = NULL; | |
126 | char *zebra_sock_path = NULL; | |
127 | struct thread thread; | |
128 | ||
129 | umask(0027); | |
130 | ||
131 | progname = ((p = strrchr(argv[0], '/')) ? ++p : argv[0]); | |
f28692a4 | 132 | |
469351b3 | 133 | zlog_default = openzlog(progname, ZLOG_PIM, 0, |
12e41d03 | 134 | LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); |
2caa9b39 | 135 | zprivs_init (&pimd_privs); |
c05795b1 SK |
136 | #if defined(HAVE_CUMULUS) |
137 | zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl); | |
138 | #endif | |
f28692a4 | 139 | |
12e41d03 DL |
140 | /* this while just reads the options */ |
141 | while (1) { | |
142 | int opt; | |
143 | ||
144 | opt = getopt_long (argc, argv, "df:i:z:A:P:vZh", longopts, 0); | |
145 | ||
146 | if (opt == EOF) | |
147 | break; | |
148 | ||
149 | switch (opt) { | |
150 | case 0: | |
151 | break; | |
152 | case 'd': | |
153 | daemon_mode = 1; | |
154 | break; | |
155 | case 'f': | |
156 | config_file = optarg; | |
157 | break; | |
158 | case 'i': | |
159 | pid_file = optarg; | |
160 | break; | |
161 | case 'z': | |
162 | zebra_sock_path = optarg; | |
163 | break; | |
164 | case 'A': | |
165 | vty_addr = optarg; | |
166 | break; | |
167 | case 'P': | |
168 | vty_port = atoi (optarg); | |
169 | break; | |
170 | case 'v': | |
171 | printf(PIMD_PROGNAME " version %s\n", PIMD_VERSION); | |
b2f36157 | 172 | print_version(progname); |
12e41d03 DL |
173 | exit (0); |
174 | break; | |
12e41d03 DL |
175 | case 'h': |
176 | usage (0); | |
177 | break; | |
178 | default: | |
179 | usage (1); | |
180 | break; | |
181 | } | |
182 | } | |
183 | ||
184 | master = thread_master_create(); | |
185 | ||
12e41d03 | 186 | zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting", |
b2f36157 | 187 | FRR_VERSION, PIMD_VERSION); |
12e41d03 DL |
188 | |
189 | /* | |
190 | * Initializations | |
191 | */ | |
12e41d03 DL |
192 | pim_signals_init(); |
193 | cmd_init(1); | |
194 | vty_init(master); | |
195 | memory_init(); | |
48e8451b | 196 | vrf_init (); |
12e41d03 | 197 | access_list_init(); |
0e8ce7e6 | 198 | prefix_list_init (); |
dfe43e25 DW |
199 | prefix_list_add_hook (pim_rp_prefix_list_update); |
200 | prefix_list_delete_hook (pim_rp_prefix_list_update); | |
201 | ||
0e8ce7e6 | 202 | pim_route_map_init (); |
12e41d03 | 203 | pim_init(); |
2a333e0f | 204 | pim_msdp_init (master); |
12e41d03 DL |
205 | |
206 | /* | |
18a23295 | 207 | * Initialize zclient "update" and "lookup" sockets |
12e41d03 DL |
208 | */ |
209 | pim_zebra_init(zebra_sock_path); | |
210 | ||
211 | zlog_notice("Loading configuration - begin"); | |
212 | ||
213 | /* Get configuration file. */ | |
214 | vty_read_config(config_file, config_default); | |
215 | ||
216 | /* | |
217 | Starting from here zlog_* functions will log according configuration | |
218 | */ | |
219 | ||
220 | zlog_notice("Loading configuration - end"); | |
221 | ||
222 | /* Change to the daemon program. */ | |
223 | if (daemon_mode) { | |
224 | if (daemon(0, 0)) { | |
225 | zlog_warn("failed to daemonize"); | |
226 | } | |
227 | } | |
228 | ||
229 | /* Process ID file creation. */ | |
230 | pid_output(pid_file); | |
231 | ||
232 | /* Create pimd VTY socket */ | |
233 | if (vty_port < 0) | |
234 | vty_port = PIMD_VTY_PORT; | |
235 | vty_serv_sock(vty_addr, vty_port, PIM_VTYSH_PATH); | |
236 | ||
237 | zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting, VTY interface at port TCP %d", | |
b2f36157 | 238 | FRR_VERSION, PIMD_VERSION, vty_port); |
12e41d03 DL |
239 | |
240 | #ifdef PIM_DEBUG_BYDEFAULT | |
241 | zlog_notice("PIM_DEBUG_BYDEFAULT: Enabling all debug commands"); | |
242 | PIM_DO_DEBUG_PIM_EVENTS; | |
243 | PIM_DO_DEBUG_PIM_PACKETS; | |
244 | PIM_DO_DEBUG_PIM_TRACE; | |
245 | PIM_DO_DEBUG_IGMP_EVENTS; | |
246 | PIM_DO_DEBUG_IGMP_PACKETS; | |
247 | PIM_DO_DEBUG_IGMP_TRACE; | |
248 | PIM_DO_DEBUG_ZEBRA; | |
249 | #endif | |
250 | ||
12e41d03 DL |
251 | #ifdef PIM_CHECK_RECV_IFINDEX_SANITY |
252 | zlog_notice("PIM_CHECK_RECV_IFINDEX_SANITY: will match sock/recv ifindex"); | |
253 | #ifdef PIM_REPORT_RECV_IFINDEX_MISMATCH | |
254 | zlog_notice("PIM_REPORT_RECV_IFINDEX_MISMATCH: will report sock/recv ifindex mismatch"); | |
255 | #endif | |
256 | #endif | |
257 | ||
258 | #ifdef PIM_UNEXPECTED_KERNEL_UPCALL | |
259 | zlog_notice("PIM_UNEXPECTED_KERNEL_UPCALL: report unexpected kernel upcall"); | |
260 | #endif | |
261 | ||
12e41d03 DL |
262 | while (thread_fetch(master, &thread)) |
263 | thread_call(&thread); | |
264 | ||
265 | zlog_err("%s %s: thread_fetch() returned NULL, exiting", | |
266 | __FILE__, __PRETTY_FUNCTION__); | |
267 | ||
268 | /* never reached */ | |
269 | return 0; | |
270 | } |