main.c revision 1.1.1.4 1 1.1 cgd /*
2 1.1.1.2 mycroft * Copyright (c) 1983, 1988, 1993
3 1.1.1.2 mycroft * The Regents of the University of California. All rights reserved.
4 1.1 cgd *
5 1.1 cgd * Redistribution and use in source and binary forms, with or without
6 1.1 cgd * modification, are permitted provided that the following conditions
7 1.1 cgd * are met:
8 1.1 cgd * 1. Redistributions of source code must retain the above copyright
9 1.1 cgd * notice, this list of conditions and the following disclaimer.
10 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer in the
12 1.1 cgd * documentation and/or other materials provided with the distribution.
13 1.1 cgd * 3. All advertising materials mentioning features or use of this software
14 1.1 cgd * must display the following acknowledgement:
15 1.1 cgd * This product includes software developed by the University of
16 1.1 cgd * California, Berkeley and its contributors.
17 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
18 1.1 cgd * may be used to endorse or promote products derived from this software
19 1.1 cgd * without specific prior written permission.
20 1.1 cgd *
21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 cgd * SUCH DAMAGE.
32 1.1 cgd */
33 1.1 cgd
34 1.1.1.3 thorpej char copyright[] =
35 1.1.1.2 mycroft "@(#) Copyright (c) 1983, 1988, 1993\n\
36 1.1.1.2 mycroft The Regents of the University of California. All rights reserved.\n";
37 1.1.1.4 christos #if !defined(lint) && !defined(sgi) && !defined(__NetBSD__)
38 1.1.1.2 mycroft static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/5/93";
39 1.1.1.4 christos #elif defined(__NetBSD__)
40 1.1.1.4 christos static char rcsid[] = "$NetBSD: main.c,v 1.1.1.4 1996/09/24 15:11:37 christos Exp $";
41 1.1.1.4 christos #endif
42 1.1.1.4 christos #ident "$Revision: 1.1.1.4 $"
43 1.1.1.3 thorpej
44 1.1 cgd #include "defs.h"
45 1.1.1.3 thorpej #include "pathnames.h"
46 1.1.1.3 thorpej #ifdef sgi
47 1.1.1.3 thorpej #include "math.h"
48 1.1.1.3 thorpej #endif
49 1.1.1.3 thorpej #include <signal.h>
50 1.1.1.3 thorpej #include <fcntl.h>
51 1.1 cgd #include <sys/file.h>
52 1.1 cgd
53 1.1.1.3 thorpej pid_t mypid;
54 1.1 cgd
55 1.1.1.3 thorpej naddr myaddr; /* system address */
56 1.1.1.3 thorpej char myname[MAXHOSTNAMELEN+1];
57 1.1 cgd
58 1.1.1.3 thorpej int supplier; /* supply or broadcast updates */
59 1.1.1.3 thorpej int supplier_set;
60 1.1.1.3 thorpej int ipforwarding = 1; /* kernel forwarding on */
61 1.1.1.3 thorpej
62 1.1.1.3 thorpej int default_gateway; /* 1=advertise default */
63 1.1.1.3 thorpej int background = 1;
64 1.1.1.3 thorpej int ridhosts; /* 1=reduce host routes */
65 1.1.1.3 thorpej int mhome; /* 1=want multi-homed host route */
66 1.1.1.3 thorpej int advertise_mhome; /* 1=must continue adverising it */
67 1.1.1.3 thorpej int auth_ok = 1; /* 1=ignore auth if we do not care */
68 1.1.1.3 thorpej
69 1.1.1.3 thorpej struct timeval epoch; /* when started */
70 1.1.1.3 thorpej struct timeval clk, prev_clk;
71 1.1.1.3 thorpej struct timeval now; /* current idea of time */
72 1.1.1.3 thorpej time_t now_stale;
73 1.1.1.4 christos time_t now_expire;
74 1.1.1.3 thorpej time_t now_garbage;
75 1.1.1.3 thorpej
76 1.1.1.3 thorpej struct timeval next_bcast; /* next general broadcast */
77 1.1.1.3 thorpej struct timeval no_flash = {EPOCH+SUPPLY_INTERVAL}; /* inhibit flash update */
78 1.1.1.3 thorpej
79 1.1.1.3 thorpej fd_set fdbits;
80 1.1.1.3 thorpej int sock_max;
81 1.1.1.3 thorpej int rip_sock = -1; /* RIP socket */
82 1.1.1.3 thorpej struct interface *rip_sock_mcast; /* current multicast interface */
83 1.1.1.3 thorpej int rt_sock; /* routing socket */
84 1.1.1.3 thorpej int rt_sock_seqno;
85 1.1.1.3 thorpej
86 1.1.1.3 thorpej
87 1.1.1.3 thorpej static int get_rip_sock(naddr, int);
88 1.1.1.3 thorpej static void timevalsub(struct timeval *, struct timeval *, struct timeval *);
89 1.1.1.3 thorpej
90 1.1.1.3 thorpej int
91 1.1.1.3 thorpej main(int argc,
92 1.1.1.3 thorpej char *argv[])
93 1.1.1.3 thorpej {
94 1.1.1.3 thorpej int n, mib[4], off;
95 1.1.1.3 thorpej size_t len;
96 1.1.1.3 thorpej char *p, *q;
97 1.1.1.3 thorpej struct timeval wtime, t2;
98 1.1.1.3 thorpej time_t dt;
99 1.1 cgd fd_set ibits;
100 1.1.1.3 thorpej naddr p_addr, p_mask;
101 1.1.1.3 thorpej struct interface *ifp;
102 1.1.1.3 thorpej struct parm parm;
103 1.1.1.3 thorpej char *tracename = 0;
104 1.1.1.3 thorpej
105 1.1.1.3 thorpej
106 1.1 cgd openlog("routed", LOG_PID | LOG_ODELAY, LOG_DAEMON);
107 1.1.1.3 thorpej ftrace = stdout;
108 1.1.1.3 thorpej
109 1.1.1.3 thorpej gettimeofday(&clk, 0);
110 1.1.1.3 thorpej prev_clk = clk;
111 1.1.1.3 thorpej epoch = clk;
112 1.1.1.3 thorpej epoch.tv_sec -= EPOCH;
113 1.1.1.3 thorpej now.tv_sec = EPOCH;
114 1.1.1.3 thorpej now_stale = EPOCH - STALE_TIME;
115 1.1.1.4 christos now_expire = EPOCH - EXPIRE_TIME;
116 1.1.1.3 thorpej now_garbage = EPOCH - GARBAGE_TIME;
117 1.1.1.3 thorpej wtime.tv_sec = 0;
118 1.1.1.3 thorpej
119 1.1.1.3 thorpej (void)gethostname(myname, sizeof(myname)-1);
120 1.1.1.3 thorpej (void)gethost(myname, &myaddr);
121 1.1.1.3 thorpej
122 1.1.1.3 thorpej while ((n = getopt(argc, argv, "sqdghmpAtT:F:P:")) != EOF) {
123 1.1.1.3 thorpej switch (n) {
124 1.1.1.3 thorpej case 's':
125 1.1.1.3 thorpej supplier = 1;
126 1.1.1.3 thorpej supplier_set = 1;
127 1.1.1.3 thorpej break;
128 1.1.1.3 thorpej
129 1.1.1.3 thorpej case 'q':
130 1.1.1.3 thorpej supplier = 0;
131 1.1.1.3 thorpej supplier_set = 1;
132 1.1.1.3 thorpej break;
133 1.1.1.3 thorpej
134 1.1.1.3 thorpej case 'd':
135 1.1.1.3 thorpej background = 0;
136 1.1.1.3 thorpej break;
137 1.1.1.3 thorpej
138 1.1.1.3 thorpej case 'g':
139 1.1.1.3 thorpej bzero(&parm, sizeof(parm));
140 1.1.1.3 thorpej parm.parm_d_metric = 1;
141 1.1.1.3 thorpej p = check_parms(&parm);
142 1.1.1.3 thorpej if (p != 0)
143 1.1.1.3 thorpej msglog("bad -g: %s", p);
144 1.1.1.3 thorpej else
145 1.1.1.3 thorpej default_gateway = 1;
146 1.1.1.3 thorpej break;
147 1.1.1.3 thorpej
148 1.1.1.3 thorpej case 'h': /* suppress extra host routes */
149 1.1.1.3 thorpej ridhosts = 1;
150 1.1.1.3 thorpej break;
151 1.1.1.3 thorpej
152 1.1.1.3 thorpej case 'm': /* advertise host route */
153 1.1.1.3 thorpej mhome = 1; /* on multi-homed hosts */
154 1.1.1.3 thorpej break;
155 1.1.1.3 thorpej
156 1.1.1.3 thorpej case 'A':
157 1.1.1.3 thorpej /* Ignore authentication if we do not care.
158 1.1.1.3 thorpej * Crazy as it is, that is what RFC 1723 requires.
159 1.1.1.3 thorpej */
160 1.1.1.3 thorpej auth_ok = 0;
161 1.1.1.3 thorpej break;
162 1.1.1.3 thorpej
163 1.1.1.3 thorpej case 't':
164 1.1.1.3 thorpej new_tracelevel++;
165 1.1.1.3 thorpej break;
166 1.1.1.3 thorpej
167 1.1.1.3 thorpej case 'T':
168 1.1.1.3 thorpej tracename = optarg;
169 1.1.1.3 thorpej break;
170 1.1.1.3 thorpej
171 1.1.1.3 thorpej case 'F': /* minimal routes for SLIP */
172 1.1.1.3 thorpej n = HOPCNT_INFINITY-2;
173 1.1.1.3 thorpej p = strchr(optarg,',');
174 1.1.1.3 thorpej if (p && *p != '\0') {
175 1.1.1.3 thorpej n = (int)strtoul(p+1, &q, 0);
176 1.1.1.3 thorpej if (*q == '\0'
177 1.1.1.3 thorpej && n <= HOPCNT_INFINITY-1
178 1.1.1.3 thorpej && n >= 1)
179 1.1.1.3 thorpej *p = '\0';
180 1.1.1.3 thorpej }
181 1.1.1.3 thorpej if (!getnet(optarg, &p_addr, &p_mask)) {
182 1.1.1.3 thorpej msglog("bad network; \"-F %s\"",
183 1.1.1.3 thorpej optarg);
184 1.1.1.3 thorpej break;
185 1.1.1.3 thorpej }
186 1.1.1.3 thorpej bzero(&parm, sizeof(parm));
187 1.1.1.3 thorpej parm.parm_addr_h = ntohl(p_addr);
188 1.1.1.3 thorpej parm.parm_mask = p_mask;
189 1.1.1.3 thorpej parm.parm_d_metric = n;
190 1.1.1.3 thorpej p = check_parms(&parm);
191 1.1.1.3 thorpej if (p != 0)
192 1.1.1.3 thorpej msglog("bad -F: %s", p);
193 1.1.1.3 thorpej break;
194 1.1.1.3 thorpej
195 1.1.1.3 thorpej case 'P':
196 1.1.1.3 thorpej /* handle arbirary, (usually) per-interface
197 1.1.1.3 thorpej * parameters.
198 1.1.1.3 thorpej */
199 1.1.1.3 thorpej p = parse_parms(optarg);
200 1.1.1.3 thorpej if (p != 0)
201 1.1.1.3 thorpej msglog("bad \"%s\" in \"%s\"",
202 1.1.1.3 thorpej p, optarg);
203 1.1.1.3 thorpej break;
204 1.1.1.3 thorpej
205 1.1.1.3 thorpej default:
206 1.1.1.3 thorpej goto usage;
207 1.1.1.3 thorpej }
208 1.1.1.3 thorpej }
209 1.1.1.3 thorpej argc -= optind;
210 1.1.1.3 thorpej argv += optind;
211 1.1.1.3 thorpej
212 1.1.1.3 thorpej if (tracename == 0 && argc >= 1) {
213 1.1.1.3 thorpej tracename = *argv++;
214 1.1.1.3 thorpej argc--;
215 1.1.1.3 thorpej }
216 1.1.1.3 thorpej if (argc != 0) {
217 1.1.1.3 thorpej usage:
218 1.1.1.3 thorpej logbad(0, "usage: routed [-sqdghmpAt] [-T /tracefile]"
219 1.1.1.3 thorpej " [-F net[,metric]] [-P parms]");
220 1.1.1.3 thorpej }
221 1.1.1.3 thorpej if (geteuid() != 0)
222 1.1.1.3 thorpej logbad(0, "requires UID 0");
223 1.1.1.3 thorpej
224 1.1.1.3 thorpej mib[0] = CTL_NET;
225 1.1.1.3 thorpej mib[1] = PF_INET;
226 1.1.1.3 thorpej mib[2] = IPPROTO_IP;
227 1.1.1.3 thorpej mib[3] = IPCTL_FORWARDING;
228 1.1.1.3 thorpej len = sizeof(ipforwarding);
229 1.1.1.3 thorpej if (sysctl(mib, 4, &ipforwarding, &len, 0, 0) < 0)
230 1.1.1.3 thorpej LOGERR("sysctl(IPCTL_FORWARDING)");
231 1.1.1.3 thorpej
232 1.1.1.3 thorpej if (!ipforwarding) {
233 1.1.1.3 thorpej if (supplier)
234 1.1.1.3 thorpej msglog("-s incompatible with ipforwarding=0");
235 1.1.1.3 thorpej if (default_gateway) {
236 1.1.1.3 thorpej msglog("-g incompatible with ipforwarding=0");
237 1.1.1.3 thorpej default_gateway = 0;
238 1.1.1.3 thorpej }
239 1.1.1.3 thorpej supplier = 0;
240 1.1.1.3 thorpej supplier_set = 1;
241 1.1.1.3 thorpej }
242 1.1.1.3 thorpej if (default_gateway) {
243 1.1.1.3 thorpej if (supplier_set && !supplier) {
244 1.1.1.3 thorpej msglog("-g and -q incompatible");
245 1.1.1.3 thorpej } else {
246 1.1.1.3 thorpej supplier = 1;
247 1.1.1.3 thorpej supplier_set = 1;
248 1.1.1.3 thorpej }
249 1.1.1.3 thorpej }
250 1.1.1.3 thorpej
251 1.1.1.3 thorpej
252 1.1.1.4 christos signal(SIGALRM, sigalrm);
253 1.1.1.4 christos if (!background)
254 1.1.1.4 christos signal(SIGHUP, sigterm); /* SIGHUP fatal during debugging */
255 1.1.1.4 christos else
256 1.1.1.4 christos signal(SIGHUP, SIG_IGN);
257 1.1.1.4 christos signal(SIGTERM, sigterm);
258 1.1.1.4 christos signal(SIGINT, sigterm);
259 1.1.1.4 christos signal(SIGUSR1, sigtrace_on);
260 1.1.1.4 christos signal(SIGUSR2, sigtrace_off);
261 1.1.1.4 christos
262 1.1.1.3 thorpej /* get into the background */
263 1.1.1.3 thorpej if (background) {
264 1.1.1.3 thorpej #ifdef sgi
265 1.1.1.3 thorpej if (0 > _daemonize(_DF_NOCHDIR,
266 1.1.1.3 thorpej new_tracelevel == 0 ? -1 : STDOUT_FILENO,
267 1.1.1.3 thorpej new_tracelevel == 0 ? -1 : STDERR_FILENO,
268 1.1.1.3 thorpej -1))
269 1.1.1.3 thorpej BADERR(0, "_daemonize()");
270 1.1 cgd #else
271 1.1.1.3 thorpej if (daemon(1, 1) < 0)
272 1.1.1.3 thorpej BADERR(0,"daemon()");
273 1.1 cgd #endif
274 1.1.1.3 thorpej }
275 1.1.1.3 thorpej
276 1.1.1.3 thorpej mypid = getpid();
277 1.1.1.3 thorpej srandom((int)(clk.tv_sec ^ clk.tv_usec ^ mypid));
278 1.1.1.3 thorpej
279 1.1.1.3 thorpej /* prepare socket connected to the kernel.
280 1.1.1.3 thorpej */
281 1.1.1.3 thorpej rt_sock = socket(AF_ROUTE, SOCK_RAW, 0);
282 1.1.1.3 thorpej if (rt_sock < 0)
283 1.1.1.3 thorpej BADERR(1,"rt_sock = socket()");
284 1.1.1.3 thorpej if (fcntl(rt_sock, F_SETFL, O_NONBLOCK) == -1)
285 1.1.1.3 thorpej logbad(1, "fcntl(rt_sock) O_NONBLOCK: %s", strerror(errno));
286 1.1.1.3 thorpej off = 0;
287 1.1.1.3 thorpej if (setsockopt(rt_sock, SOL_SOCKET,SO_USELOOPBACK,
288 1.1.1.3 thorpej &off,sizeof(off)) < 0)
289 1.1.1.3 thorpej LOGERR("setsockopt(SO_USELOOPBACK,0)");
290 1.1.1.3 thorpej
291 1.1.1.3 thorpej fix_select();
292 1.1.1.3 thorpej
293 1.1.1.3 thorpej
294 1.1.1.3 thorpej if (background && new_tracelevel == 0)
295 1.1.1.3 thorpej ftrace = 0;
296 1.1.1.3 thorpej if (tracename != 0) {
297 1.1.1.3 thorpej trace_on(tracename, 1);
298 1.1.1.3 thorpej if (new_tracelevel == 0) /* use stdout if file is bad */
299 1.1.1.3 thorpej new_tracelevel = 1;
300 1.1.1.3 thorpej }
301 1.1.1.3 thorpej set_tracelevel();
302 1.1.1.3 thorpej
303 1.1.1.3 thorpej /* initialize radix tree */
304 1.1.1.3 thorpej rtinit();
305 1.1.1.3 thorpej
306 1.1.1.3 thorpej /* Pick a random part of the second for our output to minimize
307 1.1.1.3 thorpej * collisions.
308 1.1.1.3 thorpej *
309 1.1.1.3 thorpej * Start broadcasting after hearing from other routers, and
310 1.1.1.3 thorpej * at a random time so a bunch of systems do not get synchronized
311 1.1.1.3 thorpej * after a power failure.
312 1.1.1.3 thorpej */
313 1.1.1.3 thorpej intvl_random(&next_bcast, EPOCH+MIN_WAITTIME, EPOCH+SUPPLY_INTERVAL);
314 1.1.1.3 thorpej age_timer.tv_usec = next_bcast.tv_usec;
315 1.1.1.3 thorpej age_timer.tv_sec = EPOCH+MIN_WAITTIME;
316 1.1.1.3 thorpej rdisc_timer = next_bcast;
317 1.1.1.3 thorpej ifinit_timer.tv_usec = next_bcast.tv_usec;
318 1.1.1.3 thorpej
319 1.1.1.3 thorpej /* Collect an initial view of the world by checking the interface
320 1.1.1.3 thorpej * configuration and the kludge file.
321 1.1.1.3 thorpej */
322 1.1.1.3 thorpej gwkludge();
323 1.1.1.3 thorpej ifinit();
324 1.1.1.3 thorpej flush_kern();
325 1.1.1.3 thorpej
326 1.1.1.3 thorpej /* Ask for routes */
327 1.1.1.3 thorpej rip_query();
328 1.1.1.3 thorpej if (!supplier)
329 1.1.1.3 thorpej rdisc_sol();
330 1.1.1.3 thorpej
331 1.1.1.3 thorpej /* Loop forever, listening and broadcasting.
332 1.1.1.3 thorpej */
333 1.1.1.3 thorpej for (;;) {
334 1.1.1.3 thorpej prev_clk = clk;
335 1.1.1.3 thorpej gettimeofday(&clk, 0);
336 1.1.1.3 thorpej timevalsub(&t2, &clk, &prev_clk);
337 1.1.1.3 thorpej if (t2.tv_sec < 0
338 1.1.1.3 thorpej || t2.tv_sec > wtime.tv_sec + 5) {
339 1.1.1.3 thorpej /* Deal with time changes before other housekeeping to
340 1.1.1.3 thorpej * keep everything straight.
341 1.1.1.3 thorpej */
342 1.1.1.3 thorpej dt = t2.tv_sec;
343 1.1.1.3 thorpej if (dt > 0)
344 1.1.1.3 thorpej dt -= wtime.tv_sec;
345 1.1.1.3 thorpej trace_act("time changed by %d sec\n", dt);
346 1.1.1.3 thorpej epoch.tv_sec += dt;
347 1.1.1.3 thorpej }
348 1.1.1.3 thorpej timevalsub(&now, &clk, &epoch);
349 1.1.1.3 thorpej now_stale = now.tv_sec - STALE_TIME;
350 1.1.1.4 christos now_expire = now.tv_sec - EXPIRE_TIME;
351 1.1.1.3 thorpej now_garbage = now.tv_sec - GARBAGE_TIME;
352 1.1.1.3 thorpej
353 1.1.1.3 thorpej /* deal with interrupts that should affect tracing */
354 1.1.1.3 thorpej set_tracelevel();
355 1.1.1.3 thorpej
356 1.1.1.3 thorpej if (stopint != 0) {
357 1.1.1.3 thorpej if (supplier) {
358 1.1.1.3 thorpej rip_bcast(0);
359 1.1.1.3 thorpej rdisc_adv();
360 1.1.1.3 thorpej }
361 1.1.1.3 thorpej trace_off("exiting with signal %d\n", stopint);
362 1.1.1.3 thorpej exit(stopint | 128);
363 1.1.1.3 thorpej }
364 1.1.1.3 thorpej
365 1.1.1.3 thorpej /* look for new or dead interfaces */
366 1.1.1.3 thorpej timevalsub(&wtime, &ifinit_timer, &now);
367 1.1.1.3 thorpej if (wtime.tv_sec <= 0) {
368 1.1.1.3 thorpej wtime.tv_sec = 0;
369 1.1.1.3 thorpej ifinit();
370 1.1.1.3 thorpej rip_query();
371 1.1 cgd continue;
372 1.1 cgd }
373 1.1.1.3 thorpej
374 1.1.1.3 thorpej /* If it is time, then broadcast our routes.
375 1.1.1.3 thorpej */
376 1.1.1.3 thorpej if (supplier || advertise_mhome) {
377 1.1.1.3 thorpej timevalsub(&t2, &next_bcast, &now);
378 1.1.1.3 thorpej if (t2.tv_sec <= 0) {
379 1.1.1.3 thorpej /* Synchronize the aging and broadcast
380 1.1.1.3 thorpej * timers to minimize awakenings
381 1.1.1.3 thorpej */
382 1.1.1.3 thorpej age(0);
383 1.1.1.3 thorpej
384 1.1.1.3 thorpej rip_bcast(0);
385 1.1.1.3 thorpej
386 1.1.1.3 thorpej /* It is desirable to send routing updates
387 1.1.1.3 thorpej * regularly. So schedule the next update
388 1.1.1.3 thorpej * 30 seconds after the previous one was
389 1.1.1.3 thorpej * secheduled, instead of 30 seconds after
390 1.1.1.3 thorpej * the previous update was finished.
391 1.1.1.3 thorpej * Even if we just started after discovering
392 1.1.1.3 thorpej * a 2nd interface or were otherwise delayed,
393 1.1.1.3 thorpej * pick a 30-second aniversary of the
394 1.1.1.3 thorpej * original broadcast time.
395 1.1.1.3 thorpej */
396 1.1.1.3 thorpej n = 1 + (0-t2.tv_sec)/SUPPLY_INTERVAL;
397 1.1.1.3 thorpej next_bcast.tv_sec += n*SUPPLY_INTERVAL;
398 1.1.1.3 thorpej
399 1.1.1.3 thorpej continue;
400 1.1.1.3 thorpej }
401 1.1.1.3 thorpej
402 1.1.1.3 thorpej if (timercmp(&t2, &wtime, <))
403 1.1.1.3 thorpej wtime = t2;
404 1.1.1.3 thorpej }
405 1.1.1.3 thorpej
406 1.1.1.3 thorpej /* If we need a flash update, either do it now or
407 1.1.1.3 thorpej * set the delay to end when it is time.
408 1.1.1.3 thorpej *
409 1.1.1.3 thorpej * If we are within MIN_WAITTIME seconds of a full update,
410 1.1.1.3 thorpej * do not bother.
411 1.1.1.3 thorpej */
412 1.1.1.3 thorpej if (need_flash
413 1.1.1.3 thorpej && supplier
414 1.1.1.3 thorpej && no_flash.tv_sec+MIN_WAITTIME < next_bcast.tv_sec) {
415 1.1.1.3 thorpej /* accurate to the millisecond */
416 1.1.1.3 thorpej if (!timercmp(&no_flash, &now, >))
417 1.1.1.3 thorpej rip_bcast(1);
418 1.1.1.3 thorpej timevalsub(&t2, &no_flash, &now);
419 1.1.1.3 thorpej if (timercmp(&t2, &wtime, <))
420 1.1.1.3 thorpej wtime = t2;
421 1.1.1.3 thorpej }
422 1.1.1.3 thorpej
423 1.1.1.3 thorpej /* trigger the main aging timer.
424 1.1.1.3 thorpej */
425 1.1.1.3 thorpej timevalsub(&t2, &age_timer, &now);
426 1.1.1.3 thorpej if (t2.tv_sec <= 0) {
427 1.1.1.3 thorpej age(0);
428 1.1 cgd continue;
429 1.1 cgd }
430 1.1.1.3 thorpej if (timercmp(&t2, &wtime, <))
431 1.1.1.3 thorpej wtime = t2;
432 1.1.1.3 thorpej
433 1.1.1.3 thorpej /* update the kernel routing table
434 1.1.1.3 thorpej */
435 1.1.1.3 thorpej timevalsub(&t2, &need_kern, &now);
436 1.1.1.3 thorpej if (t2.tv_sec <= 0) {
437 1.1.1.3 thorpej age(0);
438 1.1 cgd continue;
439 1.1 cgd }
440 1.1.1.3 thorpej if (timercmp(&t2, &wtime, <))
441 1.1.1.3 thorpej wtime = t2;
442 1.1.1.3 thorpej
443 1.1.1.3 thorpej /* take care of router discovery,
444 1.1.1.3 thorpej * but do it to the millisecond
445 1.1.1.3 thorpej */
446 1.1.1.3 thorpej if (!timercmp(&rdisc_timer, &now, >)) {
447 1.1.1.3 thorpej rdisc_age(0);
448 1.1 cgd continue;
449 1.1 cgd }
450 1.1.1.3 thorpej timevalsub(&t2, &rdisc_timer, &now);
451 1.1.1.3 thorpej if (timercmp(&t2, &wtime, <))
452 1.1.1.3 thorpej wtime = t2;
453 1.1.1.3 thorpej
454 1.1.1.3 thorpej
455 1.1.1.3 thorpej /* wait for input or a timer to expire.
456 1.1.1.3 thorpej */
457 1.1.1.3 thorpej trace_flush();
458 1.1.1.3 thorpej ibits = fdbits;
459 1.1.1.3 thorpej n = select(sock_max, &ibits, 0, 0, &wtime);
460 1.1.1.3 thorpej if (n <= 0) {
461 1.1.1.3 thorpej if (n < 0 && errno != EINTR && errno != EAGAIN)
462 1.1.1.3 thorpej BADERR(1,"select");
463 1.1 cgd continue;
464 1.1 cgd }
465 1.1.1.3 thorpej
466 1.1.1.3 thorpej if (FD_ISSET(rt_sock, &ibits)) {
467 1.1.1.3 thorpej read_rt();
468 1.1.1.3 thorpej n--;
469 1.1.1.3 thorpej }
470 1.1.1.3 thorpej if (rdisc_sock >= 0 && FD_ISSET(rdisc_sock, &ibits)) {
471 1.1.1.3 thorpej read_d();
472 1.1.1.3 thorpej n--;
473 1.1.1.3 thorpej }
474 1.1.1.3 thorpej if (rip_sock >= 0 && FD_ISSET(rip_sock, &ibits)) {
475 1.1.1.3 thorpej read_rip(rip_sock, 0);
476 1.1.1.3 thorpej n--;
477 1.1.1.3 thorpej }
478 1.1.1.3 thorpej
479 1.1.1.3 thorpej for (ifp = ifnet; n > 0 && 0 != ifp; ifp = ifp->int_next) {
480 1.1.1.3 thorpej if (ifp->int_rip_sock >= 0
481 1.1.1.3 thorpej && FD_ISSET(ifp->int_rip_sock, &ibits)) {
482 1.1.1.3 thorpej read_rip(ifp->int_rip_sock, ifp);
483 1.1.1.3 thorpej n--;
484 1.1.1.3 thorpej }
485 1.1.1.3 thorpej }
486 1.1 cgd }
487 1.1.1.3 thorpej }
488 1.1 cgd
489 1.1.1.3 thorpej
490 1.1.1.3 thorpej /* ARGSUSED */
491 1.1.1.3 thorpej void
492 1.1.1.3 thorpej sigalrm(int sig)
493 1.1.1.3 thorpej {
494 1.1.1.3 thorpej /* Historically, SIGALRM would cause the daemon to check for
495 1.1.1.3 thorpej * new and broken interfaces.
496 1.1 cgd */
497 1.1.1.3 thorpej ifinit_timer.tv_sec = now.tv_sec;
498 1.1.1.3 thorpej trace_act("SIGALRM\n");
499 1.1.1.3 thorpej }
500 1.1 cgd
501 1.1.1.3 thorpej
502 1.1.1.3 thorpej /* watch for fatal signals */
503 1.1.1.3 thorpej void
504 1.1.1.3 thorpej sigterm(int sig)
505 1.1.1.3 thorpej {
506 1.1.1.3 thorpej stopint = sig;
507 1.1.1.3 thorpej (void)signal(sig, SIG_DFL); /* catch it only once */
508 1.1.1.3 thorpej }
509 1.1.1.3 thorpej
510 1.1.1.3 thorpej
511 1.1.1.3 thorpej void
512 1.1.1.3 thorpej fix_select(void)
513 1.1.1.3 thorpej {
514 1.1.1.3 thorpej struct interface *ifp;
515 1.1.1.3 thorpej
516 1.1.1.3 thorpej
517 1.1.1.3 thorpej FD_ZERO(&fdbits);
518 1.1.1.3 thorpej sock_max = 0;
519 1.1.1.3 thorpej
520 1.1.1.3 thorpej FD_SET(rt_sock, &fdbits);
521 1.1.1.3 thorpej if (sock_max <= rt_sock)
522 1.1.1.3 thorpej sock_max = rt_sock+1;
523 1.1.1.3 thorpej if (rip_sock >= 0) {
524 1.1.1.3 thorpej FD_SET(rip_sock, &fdbits);
525 1.1.1.3 thorpej if (sock_max <= rip_sock)
526 1.1.1.3 thorpej sock_max = rip_sock+1;
527 1.1.1.3 thorpej }
528 1.1.1.3 thorpej for (ifp = ifnet; 0 != ifp; ifp = ifp->int_next) {
529 1.1.1.3 thorpej if (ifp->int_rip_sock >= 0) {
530 1.1.1.3 thorpej FD_SET(ifp->int_rip_sock, &fdbits);
531 1.1.1.3 thorpej if (sock_max <= ifp->int_rip_sock)
532 1.1.1.3 thorpej sock_max = ifp->int_rip_sock+1;
533 1.1.1.3 thorpej }
534 1.1.1.3 thorpej }
535 1.1.1.3 thorpej if (rdisc_sock >= 0) {
536 1.1.1.3 thorpej FD_SET(rdisc_sock, &fdbits);
537 1.1.1.3 thorpej if (sock_max <= rdisc_sock)
538 1.1.1.3 thorpej sock_max = rdisc_sock+1;
539 1.1.1.3 thorpej }
540 1.1.1.3 thorpej }
541 1.1.1.3 thorpej
542 1.1.1.3 thorpej
543 1.1.1.3 thorpej void
544 1.1.1.3 thorpej fix_sock(int sock,
545 1.1.1.3 thorpej char *name)
546 1.1.1.3 thorpej {
547 1.1.1.3 thorpej int on;
548 1.1.1.3 thorpej #define MIN_SOCKBUF (4*1024)
549 1.1.1.3 thorpej static int rbuf;
550 1.1.1.3 thorpej
551 1.1.1.3 thorpej if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1)
552 1.1.1.3 thorpej logbad(1, "fcntl(%s) O_NONBLOCK: %s",
553 1.1.1.3 thorpej name, strerror(errno));
554 1.1.1.3 thorpej on = 1;
555 1.1.1.3 thorpej if (setsockopt(sock, SOL_SOCKET,SO_BROADCAST,
556 1.1.1.3 thorpej &on,sizeof(on)) < 0)
557 1.1.1.3 thorpej msglog("setsockopt(%s,SO_BROADCAST): %s",
558 1.1.1.3 thorpej name, strerror(errno));
559 1.1.1.3 thorpej if (rbuf >= MIN_SOCKBUF) {
560 1.1.1.3 thorpej if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
561 1.1.1.3 thorpej &rbuf, sizeof(rbuf)) < 0)
562 1.1.1.3 thorpej msglog("setsockopt(%s,SO_RCVBUF=%d): %s",
563 1.1.1.3 thorpej name, rbuf, strerror(errno));
564 1.1.1.3 thorpej } else {
565 1.1.1.3 thorpej for (rbuf = 60*1024; ; rbuf -= 4096) {
566 1.1.1.3 thorpej if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
567 1.1.1.3 thorpej &rbuf, sizeof(rbuf)) == 0) {
568 1.1.1.3 thorpej trace_act("RCVBUF=%d\n", rbuf);
569 1.1.1.3 thorpej break;
570 1.1 cgd }
571 1.1.1.3 thorpej if (rbuf < MIN_SOCKBUF) {
572 1.1.1.3 thorpej msglog("setsockopt(%s,SO_RCVBUF = %d): %s",
573 1.1.1.3 thorpej name, rbuf, strerror(errno));
574 1.1.1.3 thorpej break;
575 1.1 cgd }
576 1.1.1.3 thorpej }
577 1.1.1.3 thorpej }
578 1.1.1.3 thorpej }
579 1.1.1.3 thorpej
580 1.1.1.3 thorpej
581 1.1.1.3 thorpej /* get a rip socket
582 1.1.1.3 thorpej */
583 1.1.1.3 thorpej static int /* <0 or file descriptor */
584 1.1.1.3 thorpej get_rip_sock(naddr addr,
585 1.1.1.3 thorpej int serious) /* 1=failure to bind is serious */
586 1.1.1.3 thorpej {
587 1.1.1.3 thorpej struct sockaddr_in sin;
588 1.1.1.3 thorpej unsigned char ttl;
589 1.1.1.3 thorpej int s;
590 1.1.1.3 thorpej
591 1.1.1.3 thorpej
592 1.1.1.3 thorpej if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
593 1.1.1.3 thorpej BADERR(1,"rip_sock = socket()");
594 1.1.1.3 thorpej
595 1.1.1.3 thorpej bzero(&sin,sizeof(sin));
596 1.1.1.3 thorpej #ifdef _HAVE_SIN_LEN
597 1.1.1.3 thorpej sin.sin_len = sizeof(sin);
598 1.1.1.3 thorpej #endif
599 1.1.1.3 thorpej sin.sin_family = AF_INET;
600 1.1.1.3 thorpej sin.sin_port = htons(RIP_PORT);
601 1.1.1.3 thorpej sin.sin_addr.s_addr = addr;
602 1.1.1.3 thorpej if (bind(s, (struct sockaddr *)&sin,sizeof(sin)) < 0) {
603 1.1.1.3 thorpej if (serious)
604 1.1.1.3 thorpej BADERR(errno != EADDRINUSE, "bind(rip_sock)");
605 1.1.1.3 thorpej return -1;
606 1.1.1.3 thorpej }
607 1.1.1.3 thorpej fix_sock(s,"rip_sock");
608 1.1.1.3 thorpej
609 1.1.1.3 thorpej ttl = 1;
610 1.1.1.3 thorpej if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL,
611 1.1.1.3 thorpej &ttl, sizeof(ttl)) < 0)
612 1.1.1.3 thorpej DBGERR(1,"rip_sock setsockopt(IP_MULTICAST_TTL)");
613 1.1.1.3 thorpej
614 1.1.1.3 thorpej return s;
615 1.1.1.3 thorpej }
616 1.1.1.3 thorpej
617 1.1.1.3 thorpej
618 1.1.1.3 thorpej /* turn off main RIP socket */
619 1.1.1.3 thorpej void
620 1.1.1.3 thorpej rip_off(void)
621 1.1.1.3 thorpej {
622 1.1.1.3 thorpej struct interface *ifp;
623 1.1.1.3 thorpej register naddr addr;
624 1.1.1.3 thorpej
625 1.1.1.3 thorpej
626 1.1.1.3 thorpej if (rip_sock >= 0 && !mhome) {
627 1.1.1.3 thorpej trace_act("turn off RIP\n");
628 1.1.1.3 thorpej
629 1.1.1.3 thorpej (void)close(rip_sock);
630 1.1.1.3 thorpej rip_sock = -1;
631 1.1.1.3 thorpej
632 1.1.1.3 thorpej /* get non-broadcast sockets to listen to queries.
633 1.1.1.3 thorpej */
634 1.1.1.3 thorpej for (ifp = ifnet; ifp != 0; ifp = ifp->int_next) {
635 1.1.1.3 thorpej if (ifp->int_rip_sock < 0
636 1.1.1.3 thorpej && !(ifp->int_state & IS_ALIAS)) {
637 1.1.1.3 thorpej addr = ((ifp->int_if_flags & IFF_POINTOPOINT)
638 1.1.1.3 thorpej ? ifp->int_dstaddr
639 1.1.1.3 thorpej : ifp->int_addr);
640 1.1.1.3 thorpej ifp->int_rip_sock = get_rip_sock(addr, 0);
641 1.1 cgd }
642 1.1 cgd }
643 1.1.1.3 thorpej
644 1.1.1.3 thorpej fix_select();
645 1.1.1.3 thorpej
646 1.1.1.3 thorpej age(0);
647 1.1.1.3 thorpej }
648 1.1.1.3 thorpej }
649 1.1.1.3 thorpej
650 1.1.1.3 thorpej
651 1.1.1.3 thorpej /* turn on RIP multicast input via an interface
652 1.1.1.3 thorpej */
653 1.1.1.3 thorpej static void
654 1.1.1.3 thorpej rip_mcast_on(struct interface *ifp)
655 1.1.1.3 thorpej {
656 1.1.1.3 thorpej struct ip_mreq m;
657 1.1.1.3 thorpej
658 1.1.1.3 thorpej if (!IS_RIP_IN_OFF(ifp->int_state)
659 1.1.1.3 thorpej && (ifp->int_if_flags & IFF_MULTICAST)
660 1.1.1.3 thorpej #ifdef MCAST_PPP_BUG
661 1.1.1.3 thorpej && !(ifp->int_if_flags & IFF_POINTOPOINT)
662 1.1 cgd #endif
663 1.1.1.3 thorpej && !(ifp->int_state & IS_ALIAS)) {
664 1.1.1.3 thorpej m.imr_multiaddr.s_addr = htonl(INADDR_RIP_GROUP);
665 1.1.1.3 thorpej m.imr_interface.s_addr = ((ifp->int_if_flags & IFF_POINTOPOINT)
666 1.1.1.3 thorpej ? ifp->int_dstaddr
667 1.1.1.3 thorpej : ifp->int_addr);
668 1.1.1.3 thorpej if (setsockopt(rip_sock,IPPROTO_IP, IP_ADD_MEMBERSHIP,
669 1.1.1.3 thorpej &m, sizeof(m)) < 0)
670 1.1.1.3 thorpej LOGERR("setsockopt(IP_ADD_MEMBERSHIP RIP)");
671 1.1.1.3 thorpej }
672 1.1.1.3 thorpej }
673 1.1.1.3 thorpej
674 1.1.1.3 thorpej
675 1.1.1.3 thorpej /* Prepare socket used for RIP.
676 1.1.1.3 thorpej */
677 1.1.1.3 thorpej void
678 1.1.1.3 thorpej rip_on(struct interface *ifp)
679 1.1.1.3 thorpej {
680 1.1.1.3 thorpej /* If the main RIP socket is already alive, only start receiving
681 1.1.1.3 thorpej * multicasts for this interface.
682 1.1.1.3 thorpej */
683 1.1.1.3 thorpej if (rip_sock >= 0) {
684 1.1.1.3 thorpej if (ifp != 0)
685 1.1.1.3 thorpej rip_mcast_on(ifp);
686 1.1.1.3 thorpej return;
687 1.1.1.3 thorpej }
688 1.1.1.3 thorpej
689 1.1.1.3 thorpej /* If the main RIP socket is off, and it makes sense to turn it on,
690 1.1.1.3 thorpej * turn it on for all of the interfaces.
691 1.1.1.3 thorpej */
692 1.1.1.3 thorpej if (rip_interfaces > 0 && !rdisc_ok) {
693 1.1.1.3 thorpej trace_act("turn on RIP\n");
694 1.1.1.3 thorpej
695 1.1.1.3 thorpej /* Close all of the query sockets so that we can open
696 1.1.1.3 thorpej * the main socket. SO_REUSEPORT is not a solution,
697 1.1.1.3 thorpej * since that would let two daemons bind to the broadcast
698 1.1.1.3 thorpej * socket.
699 1.1.1.3 thorpej */
700 1.1.1.3 thorpej for (ifp = ifnet; ifp != 0; ifp = ifp->int_next) {
701 1.1.1.3 thorpej if (ifp->int_rip_sock >= 0) {
702 1.1.1.3 thorpej (void)close(ifp->int_rip_sock);
703 1.1.1.3 thorpej ifp->int_rip_sock = -1;
704 1.1.1.3 thorpej }
705 1.1.1.3 thorpej }
706 1.1.1.3 thorpej
707 1.1.1.3 thorpej rip_sock = get_rip_sock(INADDR_ANY, 1);
708 1.1.1.3 thorpej rip_sock_mcast = 0;
709 1.1.1.3 thorpej
710 1.1.1.3 thorpej /* Do not advertise anything until we have heard something
711 1.1.1.3 thorpej */
712 1.1.1.3 thorpej if (next_bcast.tv_sec < now.tv_sec+MIN_WAITTIME)
713 1.1.1.3 thorpej next_bcast.tv_sec = now.tv_sec+MIN_WAITTIME;
714 1.1.1.3 thorpej
715 1.1.1.3 thorpej for (ifp = ifnet; ifp != 0; ifp = ifp->int_next) {
716 1.1.1.3 thorpej if (!IS_RIP_IN_OFF(ifp->int_state))
717 1.1.1.3 thorpej ifp->int_state &= ~IS_RIP_QUERIED;
718 1.1.1.3 thorpej rip_mcast_on(ifp);
719 1.1.1.3 thorpej }
720 1.1.1.3 thorpej
721 1.1.1.3 thorpej ifinit_timer.tv_sec = now.tv_sec;
722 1.1.1.3 thorpej
723 1.1.1.3 thorpej fix_select();
724 1.1.1.3 thorpej
725 1.1.1.3 thorpej } else if (ifp != 0
726 1.1.1.3 thorpej && ifp->int_rip_sock < 0
727 1.1.1.3 thorpej && !(ifp->int_state & IS_ALIAS)) {
728 1.1.1.3 thorpej /* RIP is off, so ensure there are sockets on which
729 1.1.1.3 thorpej * to listen for queries.
730 1.1.1.3 thorpej */
731 1.1.1.3 thorpej ifp->int_rip_sock = get_rip_sock(ifp->int_addr, 0);
732 1.1.1.3 thorpej
733 1.1.1.3 thorpej fix_select();
734 1.1 cgd }
735 1.1.1.4 christos }
736 1.1.1.4 christos
737 1.1.1.4 christos
738 1.1.1.4 christos /* die if malloc(3) fails
739 1.1.1.4 christos */
740 1.1.1.4 christos void *
741 1.1.1.4 christos rtmalloc(size_t size,
742 1.1.1.4 christos char *msg)
743 1.1.1.4 christos {
744 1.1.1.4 christos void *p = malloc(size);
745 1.1.1.4 christos if (p == 0)
746 1.1.1.4 christos logbad(1,"malloc() failed in %s", msg);
747 1.1.1.4 christos return p;
748 1.1 cgd }
749 1.1 cgd
750 1.1.1.3 thorpej
751 1.1.1.3 thorpej /* get a random instant in an interval
752 1.1.1.3 thorpej */
753 1.1.1.3 thorpej void
754 1.1.1.3 thorpej intvl_random(struct timeval *tp, /* put value here */
755 1.1.1.3 thorpej u_long lo, /* value is after this second */
756 1.1.1.3 thorpej u_long hi) /* and before this */
757 1.1.1.3 thorpej {
758 1.1.1.3 thorpej tp->tv_sec = (time_t)(hi == lo
759 1.1.1.3 thorpej ? lo
760 1.1.1.3 thorpej : (lo + random() % ((hi - lo))));
761 1.1.1.3 thorpej tp->tv_usec = random() % 1000000;
762 1.1.1.3 thorpej }
763 1.1.1.3 thorpej
764 1.1.1.3 thorpej
765 1.1.1.3 thorpej void
766 1.1.1.3 thorpej timevaladd(struct timeval *t1,
767 1.1.1.3 thorpej struct timeval *t2)
768 1.1 cgd {
769 1.1 cgd
770 1.1 cgd t1->tv_sec += t2->tv_sec;
771 1.1 cgd if ((t1->tv_usec += t2->tv_usec) > 1000000) {
772 1.1 cgd t1->tv_sec++;
773 1.1 cgd t1->tv_usec -= 1000000;
774 1.1 cgd }
775 1.1 cgd }
776 1.1 cgd
777 1.1 cgd
778 1.1.1.3 thorpej /* t1 = t2 - t3
779 1.1.1.3 thorpej */
780 1.1.1.3 thorpej static void
781 1.1.1.3 thorpej timevalsub(struct timeval *t1,
782 1.1.1.3 thorpej struct timeval *t2,
783 1.1.1.3 thorpej struct timeval *t3)
784 1.1.1.3 thorpej {
785 1.1.1.3 thorpej t1->tv_sec = t2->tv_sec - t3->tv_sec;
786 1.1.1.3 thorpej if ((t1->tv_usec = t2->tv_usec - t3->tv_usec) < 0) {
787 1.1 cgd t1->tv_sec--;
788 1.1 cgd t1->tv_usec += 1000000;
789 1.1 cgd }
790 1.1 cgd }
791 1.1 cgd
792 1.1.1.3 thorpej
793 1.1.1.3 thorpej void
794 1.1.1.3 thorpej msglog(char *p, ...)
795 1.1 cgd {
796 1.1.1.3 thorpej va_list args;
797 1.1 cgd
798 1.1.1.3 thorpej trace_flush();
799 1.1.1.3 thorpej
800 1.1.1.3 thorpej va_start(args, p);
801 1.1.1.3 thorpej vsyslog(LOG_ERR, p, args);
802 1.1.1.3 thorpej
803 1.1.1.3 thorpej if (ftrace != 0) {
804 1.1.1.3 thorpej if (ftrace == stdout)
805 1.1.1.3 thorpej (void)fputs("routed: ", ftrace);
806 1.1.1.3 thorpej (void)vfprintf(ftrace, p, args);
807 1.1.1.3 thorpej (void)fputc('\n', ftrace);
808 1.1 cgd }
809 1.1 cgd }
810 1.1 cgd
811 1.1.1.3 thorpej
812 1.1.1.3 thorpej void
813 1.1.1.3 thorpej logbad(int dump, char *p, ...)
814 1.1 cgd {
815 1.1.1.3 thorpej va_list args;
816 1.1 cgd
817 1.1.1.3 thorpej trace_flush();
818 1.1.1.3 thorpej
819 1.1.1.3 thorpej va_start(args, p);
820 1.1.1.3 thorpej vsyslog(LOG_ERR, p, args);
821 1.1.1.3 thorpej
822 1.1.1.3 thorpej (void)fputs("routed: ", stderr);
823 1.1.1.3 thorpej (void)vfprintf(stderr, p, args);
824 1.1.1.3 thorpej (void)fputs("; giving up\n",stderr);
825 1.1.1.3 thorpej (void)fflush(stderr);
826 1.1.1.3 thorpej
827 1.1.1.3 thorpej if (dump)
828 1.1.1.3 thorpej abort();
829 1.1.1.3 thorpej exit(1);
830 1.1 cgd }
831