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