]>
Commit | Line | Data |
---|---|---|
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 | <<<<<<< HEAD | |
20 | ||
21 | ======= | |
22 | >>>>>>> origin/master | |
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" | |
36 | #include "vrf.h" | |
37 | #include "memory_vty.h" | |
38 | #include "filter.h" | |
39 | #include "vty.h" | |
40 | #include "sigevent.h" | |
41 | #include "version.h" | |
42 | #include "prefix.h" | |
43 | #include "plist.h" | |
44 | #include "vrf.h" | |
45 | ||
46 | #include "pimd.h" | |
47 | #include "pim_version.h" | |
48 | #include "pim_signals.h" | |
49 | #include "pim_zebra.h" | |
50 | #include "pim_msdp.h" | |
51 | #include "pim_iface.h" | |
52 | #include "pim_rp.h" | |
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, | |
76 | ZCAP_BIND, | |
77 | }; | |
78 | ||
79 | /* pimd privileges to run with */ | |
80 | struct zebra_privs_t pimd_privs = | |
81 | { | |
82 | #if defined(FRR_USER) && defined(FRR_GROUP) | |
83 | .user = FRR_USER, | |
84 | .group = FRR_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 | -h, --help Display this help and exit\n\ | |
112 | \n\ | |
113 | Report bugs to %s\n", progname, PACKAGE_BUGREPORT); | |
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]); | |
132 | ||
133 | zlog_default = openzlog(progname, ZLOG_PIM, 0, | |
134 | LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); | |
135 | zprivs_init (&pimd_privs); | |
136 | #if defined(HAVE_CUMULUS) | |
137 | zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl); | |
138 | #endif | |
139 | ||
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); | |
172 | print_version(progname); | |
173 | exit (0); | |
174 | break; | |
175 | case 'h': | |
176 | usage (0); | |
177 | break; | |
178 | default: | |
179 | usage (1); | |
180 | break; | |
181 | } | |
182 | } | |
183 | ||
184 | master = thread_master_create(); | |
185 | ||
186 | zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting", | |
187 | FRR_VERSION, PIMD_VERSION); | |
188 | ||
189 | /* | |
190 | * Initializations | |
191 | */ | |
192 | pim_signals_init(); | |
193 | cmd_init(1); | |
194 | vty_init(master); | |
195 | memory_init(); | |
196 | vrf_init (); | |
197 | access_list_init(); | |
198 | prefix_list_init (); | |
199 | prefix_list_add_hook (pim_rp_prefix_list_update); | |
200 | prefix_list_delete_hook (pim_rp_prefix_list_update); | |
201 | ||
202 | pim_route_map_init (); | |
203 | pim_init(); | |
204 | pim_msdp_init (master); | |
205 | ||
206 | /* | |
207 | * Initialize zclient "update" and "lookup" sockets | |
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", | |
238 | FRR_VERSION, PIMD_VERSION, vty_port); | |
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 | ||
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 | ||
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 | } |