trace.c revision 1.16 1 1.16 christos /* $NetBSD: trace.c,v 1.16 1997/02/03 22:03:10 christos Exp $ */
2 1.10 cgd
3 1.1 cgd /*
4 1.5 mycroft * Copyright (c) 1983, 1988, 1993
5 1.5 mycroft * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.1 cgd * 3. All advertising materials mentioning features or use of this software
16 1.1 cgd * must display the following acknowledgement:
17 1.1 cgd * This product includes software developed by the University of
18 1.1 cgd * California, Berkeley and its contributors.
19 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
20 1.1 cgd * may be used to endorse or promote products derived from this software
21 1.1 cgd * without specific prior written permission.
22 1.1 cgd *
23 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 cgd * SUCH DAMAGE.
34 1.1 cgd */
35 1.1 cgd
36 1.15 christos #if !defined(lint) && !defined(sgi) && !defined(__NetBSD__)
37 1.10 cgd static char sccsid[] = "@(#)trace.c 8.1 (Berkeley) 6/5/93";
38 1.15 christos #elif defined(__NetBSD__)
39 1.16 christos static char rcsid[] = "$NetBSD: trace.c,v 1.16 1997/02/03 22:03:10 christos Exp $";
40 1.10 cgd #endif
41 1.1 cgd
42 1.1 cgd #define RIPCMDS
43 1.1 cgd #include "defs.h"
44 1.14 thorpej #include "pathnames.h"
45 1.1 cgd #include <sys/stat.h>
46 1.14 thorpej #include <sys/signal.h>
47 1.1 cgd #include <fcntl.h>
48 1.14 thorpej
49 1.14 thorpej
50 1.14 thorpej #ifdef sgi
51 1.14 thorpej /* use *stat64 for files on large filesystems */
52 1.14 thorpej #define stat stat64
53 1.14 thorpej #endif
54 1.1 cgd
55 1.1 cgd #define NRECORDS 50 /* size of circular trace buffer */
56 1.14 thorpej
57 1.16 christos int tracelevel, new_tracelevel;
58 1.14 thorpej FILE *ftrace = stdout; /* output trace file */
59 1.16 christos static char *sigtrace_pat = "%s";
60 1.16 christos static char savetracename[MAXPATHLEN+1];
61 1.16 christos char inittracename[MAXPATHLEN+1];
62 1.16 christos int file_trace; /* 1=tracing to file, not stdout */
63 1.14 thorpej
64 1.16 christos static void trace_dump(void);
65 1.16 christos
66 1.16 christos
67 1.16 christos /* convert string to printable characters
68 1.16 christos */
69 1.16 christos static char *
70 1.16 christos qstring(u_char *s, int len)
71 1.16 christos {
72 1.16 christos static char buf[8*20+1];
73 1.16 christos char *p;
74 1.16 christos u_char *s2, c;
75 1.16 christos
76 1.16 christos
77 1.16 christos for (p = buf; len != 0 && p < &buf[sizeof(buf)-1]; len--) {
78 1.16 christos c = *s++;
79 1.16 christos if (c == '\0') {
80 1.16 christos for (s2 = s+1; s2 < &s[len]; s2++) {
81 1.16 christos if (*s2 != '\0')
82 1.16 christos break;
83 1.16 christos }
84 1.16 christos if (s2 >= &s[len])
85 1.16 christos goto exit;
86 1.16 christos }
87 1.14 thorpej
88 1.16 christos if (c >= ' ' && c < 0x7f && c != '\\') {
89 1.16 christos *p++ = c;
90 1.16 christos continue;
91 1.16 christos }
92 1.16 christos *p++ = '\\';
93 1.16 christos switch (c) {
94 1.16 christos case '\\':
95 1.16 christos *p++ = '\\';
96 1.16 christos break;
97 1.16 christos case '\n':
98 1.16 christos *p++= 'n';
99 1.16 christos break;
100 1.16 christos case '\r':
101 1.16 christos *p++= 'r';
102 1.16 christos break;
103 1.16 christos case '\t':
104 1.16 christos *p++ = 't';
105 1.16 christos break;
106 1.16 christos case '\b':
107 1.16 christos *p++ = 'b';
108 1.16 christos break;
109 1.16 christos default:
110 1.16 christos p += sprintf(p,"%o",c);
111 1.16 christos break;
112 1.16 christos }
113 1.16 christos }
114 1.16 christos exit:
115 1.16 christos *p = '\0';
116 1.16 christos return buf;
117 1.16 christos }
118 1.15 christos
119 1.14 thorpej
120 1.14 thorpej /* convert IP address to a string, but not into a single buffer
121 1.14 thorpej */
122 1.14 thorpej char *
123 1.14 thorpej naddr_ntoa(naddr a)
124 1.14 thorpej {
125 1.14 thorpej #define NUM_BUFS 4
126 1.15 christos static int bufno;
127 1.14 thorpej static struct {
128 1.14 thorpej char str[16]; /* xxx.xxx.xxx.xxx\0 */
129 1.14 thorpej } bufs[NUM_BUFS];
130 1.15 christos char *s;
131 1.14 thorpej struct in_addr addr;
132 1.14 thorpej
133 1.14 thorpej addr.s_addr = a;
134 1.15 christos s = strcpy(bufs[bufno].str, inet_ntoa(addr));
135 1.15 christos bufno = (bufno+1) % NUM_BUFS;
136 1.14 thorpej return s;
137 1.15 christos #undef NUM_BUFS
138 1.14 thorpej }
139 1.14 thorpej
140 1.14 thorpej
141 1.14 thorpej char *
142 1.14 thorpej saddr_ntoa(struct sockaddr *sa)
143 1.14 thorpej {
144 1.14 thorpej return (sa == 0) ? "?" : naddr_ntoa(S_ADDR(sa));
145 1.14 thorpej }
146 1.14 thorpej
147 1.14 thorpej
148 1.14 thorpej static char *
149 1.14 thorpej ts(time_t secs) {
150 1.14 thorpej static char s[20];
151 1.14 thorpej
152 1.14 thorpej secs += epoch.tv_sec;
153 1.14 thorpej #ifdef sgi
154 1.14 thorpej (void)cftime(s, "%T", &secs);
155 1.14 thorpej #else
156 1.14 thorpej bcopy(ctime(&secs)+11, s, 8);
157 1.14 thorpej s[8] = '\0';
158 1.1 cgd #endif
159 1.14 thorpej return s;
160 1.14 thorpej }
161 1.1 cgd
162 1.7 cgd
163 1.14 thorpej /* On each event, display a time stamp.
164 1.14 thorpej * This assumes that 'now' is update once for each event, and
165 1.14 thorpej * that at least now.tv_usec changes.
166 1.14 thorpej */
167 1.16 christos static struct timeval lastlog_time;
168 1.16 christos
169 1.7 cgd void
170 1.14 thorpej lastlog(void)
171 1.1 cgd {
172 1.16 christos if (lastlog_time.tv_sec != now.tv_sec
173 1.16 christos || lastlog_time.tv_usec != now.tv_usec) {
174 1.14 thorpej (void)fprintf(ftrace, "-- %s --\n", ts(now.tv_sec));
175 1.16 christos lastlog_time = now;
176 1.14 thorpej }
177 1.1 cgd }
178 1.1 cgd
179 1.14 thorpej
180 1.14 thorpej static void
181 1.14 thorpej tmsg(char *p, ...)
182 1.1 cgd {
183 1.14 thorpej va_list args;
184 1.1 cgd
185 1.14 thorpej if (ftrace != 0) {
186 1.14 thorpej lastlog();
187 1.14 thorpej va_start(args, p);
188 1.14 thorpej vfprintf(ftrace, p, args);
189 1.16 christos (void)fputc('\n',ftrace);
190 1.14 thorpej fflush(ftrace);
191 1.1 cgd }
192 1.1 cgd }
193 1.1 cgd
194 1.14 thorpej
195 1.14 thorpej static void
196 1.14 thorpej trace_close(void)
197 1.1 cgd {
198 1.14 thorpej int fd;
199 1.14 thorpej
200 1.14 thorpej
201 1.14 thorpej fflush(stdout);
202 1.14 thorpej fflush(stderr);
203 1.1 cgd
204 1.16 christos if (ftrace != 0 && file_trace) {
205 1.16 christos if (ftrace != stdout)
206 1.16 christos fclose(ftrace);
207 1.16 christos ftrace = 0;
208 1.14 thorpej fd = open(_PATH_DEVNULL, O_RDWR);
209 1.16 christos (void)dup2(fd, STDIN_FILENO);
210 1.14 thorpej (void)dup2(fd, STDOUT_FILENO);
211 1.14 thorpej (void)dup2(fd, STDERR_FILENO);
212 1.14 thorpej (void)close(fd);
213 1.14 thorpej }
214 1.16 christos lastlog_time.tv_sec = 0;
215 1.1 cgd }
216 1.1 cgd
217 1.14 thorpej
218 1.7 cgd void
219 1.14 thorpej trace_flush(void)
220 1.1 cgd {
221 1.14 thorpej if (ftrace != 0) {
222 1.1 cgd fflush(ftrace);
223 1.14 thorpej if (ferror(ftrace))
224 1.14 thorpej trace_off("tracing off: ", strerror(ferror(ftrace)));
225 1.1 cgd }
226 1.1 cgd }
227 1.1 cgd
228 1.14 thorpej
229 1.1 cgd void
230 1.14 thorpej trace_off(char *p, ...)
231 1.1 cgd {
232 1.14 thorpej va_list args;
233 1.1 cgd
234 1.14 thorpej
235 1.14 thorpej if (ftrace != 0) {
236 1.14 thorpej lastlog();
237 1.14 thorpej va_start(args, p);
238 1.14 thorpej vfprintf(ftrace, p, args);
239 1.16 christos (void)fputc('\n',ftrace);
240 1.14 thorpej }
241 1.14 thorpej trace_close();
242 1.14 thorpej
243 1.14 thorpej new_tracelevel = tracelevel = 0;
244 1.1 cgd }
245 1.1 cgd
246 1.14 thorpej
247 1.16 christos /* log a change in tracing
248 1.16 christos */
249 1.7 cgd void
250 1.16 christos tracelevel_msg(char *pat,
251 1.16 christos int dump) /* -1=no dump, 0=default, 1=force */
252 1.16 christos {
253 1.16 christos static char *off_msgs[MAX_TRACELEVEL] = {
254 1.16 christos "Tracing actions stopped",
255 1.16 christos "Tracing packets stopped",
256 1.16 christos "Tracing packet contents stopped",
257 1.16 christos "Tracing kernel changes stopped",
258 1.16 christos };
259 1.16 christos static char *on_msgs[MAX_TRACELEVEL] = {
260 1.16 christos "Tracing actions started",
261 1.16 christos "Tracing packets started",
262 1.16 christos "Tracing packet contents started",
263 1.16 christos "Tracing kernel changes started",
264 1.16 christos };
265 1.16 christos u_int old_tracelevel = tracelevel;
266 1.16 christos
267 1.16 christos
268 1.16 christos if (new_tracelevel < 0)
269 1.16 christos new_tracelevel = 0;
270 1.16 christos else if (new_tracelevel > MAX_TRACELEVEL)
271 1.16 christos new_tracelevel = MAX_TRACELEVEL;
272 1.16 christos
273 1.16 christos if (new_tracelevel < tracelevel) {
274 1.16 christos if (new_tracelevel <= 0) {
275 1.16 christos trace_off(pat, off_msgs[0]);
276 1.16 christos } else do {
277 1.16 christos tmsg(pat, off_msgs[tracelevel]);
278 1.16 christos }
279 1.16 christos while (--tracelevel != new_tracelevel);
280 1.16 christos
281 1.16 christos } else if (new_tracelevel > tracelevel) {
282 1.16 christos do {
283 1.16 christos tmsg(pat, on_msgs[tracelevel++]);
284 1.16 christos } while (tracelevel != new_tracelevel);
285 1.16 christos }
286 1.16 christos
287 1.16 christos if (dump > 0
288 1.16 christos || (dump == 0 && old_tracelevel == 0 && tracelevel != 0))
289 1.16 christos trace_dump();
290 1.16 christos }
291 1.16 christos
292 1.16 christos
293 1.16 christos void
294 1.16 christos set_tracefile(char *filename,
295 1.16 christos char *pat,
296 1.16 christos int dump) /* -1=no dump, 0=default, 1=force */
297 1.1 cgd {
298 1.14 thorpej struct stat stbuf;
299 1.14 thorpej FILE *n_ftrace;
300 1.16 christos char *fn;
301 1.1 cgd
302 1.14 thorpej
303 1.16 christos /* Allow a null filename to increase the level if the trace file
304 1.16 christos * is already open or if coming from a trusted source, such as
305 1.16 christos * a signal or the command line.
306 1.14 thorpej */
307 1.16 christos if (filename == 0 || filename[0] == '\0') {
308 1.16 christos filename = 0;
309 1.16 christos if (ftrace == 0) {
310 1.16 christos if (inittracename[0] == '\0') {
311 1.16 christos msglog("missing trace file name");
312 1.16 christos return;
313 1.16 christos }
314 1.16 christos fn = inittracename;
315 1.16 christos } else {
316 1.16 christos fn = 0;
317 1.14 thorpej }
318 1.14 thorpej
319 1.15 christos } else if (!strcmp(filename,"dump/../table")) {
320 1.15 christos trace_dump();
321 1.15 christos return;
322 1.15 christos
323 1.15 christos } else {
324 1.16 christos /* Allow the file specified with "-T file" to be reopened,
325 1.16 christos * but require all other names specified over the net to
326 1.16 christos * match the official path. The path can specify a directory
327 1.16 christos * in which the file is to be created.
328 1.16 christos */
329 1.16 christos if (strcmp(filename, inittracename)
330 1.16 christos #ifdef _PATH_TRACE
331 1.16 christos && (strncmp(filename, _PATH_TRACE, sizeof(_PATH_TRACE)-1)
332 1.16 christos || strstr(filename,"../")
333 1.16 christos || 0 > stat(_PATH_TRACE, &stbuf))
334 1.16 christos #endif
335 1.16 christos ) {
336 1.16 christos msglog("wrong trace file \"%s\"", filename);
337 1.16 christos return;
338 1.16 christos }
339 1.16 christos
340 1.16 christos /* If the new tracefile exists, it must be a regular file.
341 1.16 christos */
342 1.15 christos if (stat(filename, &stbuf) >= 0
343 1.15 christos && (stbuf.st_mode & S_IFMT) != S_IFREG) {
344 1.14 thorpej msglog("wrong type (%#x) of trace file \"%s\"",
345 1.14 thorpej stbuf.st_mode, filename);
346 1.14 thorpej return;
347 1.14 thorpej }
348 1.14 thorpej
349 1.16 christos fn = filename;
350 1.16 christos }
351 1.16 christos
352 1.16 christos if (fn != 0) {
353 1.16 christos n_ftrace = fopen(fn, "a");
354 1.16 christos if (n_ftrace == 0) {
355 1.16 christos msglog("failed to open trace file \"%s\" %s",
356 1.16 christos fn, strerror(errno));
357 1.16 christos if (fn == inittracename)
358 1.16 christos inittracename[0] = '\0';
359 1.14 thorpej return;
360 1.14 thorpej }
361 1.14 thorpej
362 1.16 christos tmsg("switch to trace file %s", fn);
363 1.16 christos
364 1.16 christos file_trace = 1;
365 1.16 christos trace_close();
366 1.14 thorpej
367 1.16 christos if (fn != savetracename)
368 1.16 christos strncpy(savetracename, fn, sizeof(savetracename)-1);
369 1.16 christos ftrace = n_ftrace;
370 1.14 thorpej
371 1.16 christos fflush(stdout);
372 1.16 christos fflush(stderr);
373 1.16 christos dup2(fileno(ftrace), STDOUT_FILENO);
374 1.16 christos dup2(fileno(ftrace), STDERR_FILENO);
375 1.16 christos }
376 1.14 thorpej
377 1.16 christos if (new_tracelevel == 0 || filename == 0)
378 1.16 christos new_tracelevel++;
379 1.16 christos tracelevel_msg(pat, dump != 0 ? dump : (filename != 0));
380 1.14 thorpej }
381 1.14 thorpej
382 1.14 thorpej
383 1.14 thorpej /* ARGSUSED */
384 1.14 thorpej void
385 1.14 thorpej sigtrace_on(int s)
386 1.14 thorpej {
387 1.14 thorpej new_tracelevel++;
388 1.16 christos sigtrace_pat = "SIGUSR1: %s";
389 1.1 cgd }
390 1.1 cgd
391 1.14 thorpej
392 1.14 thorpej /* ARGSUSED */
393 1.7 cgd void
394 1.14 thorpej sigtrace_off(int s)
395 1.14 thorpej {
396 1.14 thorpej new_tracelevel--;
397 1.16 christos sigtrace_pat = "SIGUSR2: %s";
398 1.1 cgd }
399 1.1 cgd
400 1.14 thorpej
401 1.16 christos /* Set tracing after a signal.
402 1.14 thorpej */
403 1.7 cgd void
404 1.14 thorpej set_tracelevel(void)
405 1.14 thorpej {
406 1.16 christos if (new_tracelevel == tracelevel)
407 1.16 christos return;
408 1.14 thorpej
409 1.16 christos /* If tracing entirely off, and there was no tracefile specified
410 1.16 christos * on the command line, then leave it off.
411 1.16 christos */
412 1.16 christos if (new_tracelevel > tracelevel && ftrace == 0) {
413 1.16 christos if (savetracename[0] != '\0') {
414 1.16 christos set_tracefile(savetracename,sigtrace_pat,0);
415 1.16 christos } else if (inittracename[0] != '\0') {
416 1.16 christos set_tracefile(inittracename,sigtrace_pat,0);
417 1.16 christos } else {
418 1.16 christos new_tracelevel = 0;
419 1.14 thorpej return;
420 1.1 cgd }
421 1.16 christos } else {
422 1.16 christos tracelevel_msg(sigtrace_pat, 0);
423 1.1 cgd }
424 1.14 thorpej }
425 1.14 thorpej
426 1.14 thorpej
427 1.14 thorpej /* display an address
428 1.14 thorpej */
429 1.14 thorpej char *
430 1.14 thorpej addrname(naddr addr, /* in network byte order */
431 1.14 thorpej naddr mask,
432 1.14 thorpej int force) /* 0=show mask if nonstandard, */
433 1.14 thorpej { /* 1=always show mask, 2=never */
434 1.15 christos #define NUM_BUFS 4
435 1.15 christos static int bufno;
436 1.15 christos static struct {
437 1.15 christos char str[15+20];
438 1.15 christos } bufs[NUM_BUFS];
439 1.15 christos char *s, *sp;
440 1.14 thorpej naddr dmask;
441 1.14 thorpej int i;
442 1.14 thorpej
443 1.15 christos s = strcpy(bufs[bufno].str, naddr_ntoa(addr));
444 1.15 christos bufno = (bufno+1) % NUM_BUFS;
445 1.14 thorpej
446 1.14 thorpej if (force == 1 || (force == 0 && mask != std_mask(addr))) {
447 1.14 thorpej sp = &s[strlen(s)];
448 1.14 thorpej
449 1.14 thorpej dmask = mask & -mask;
450 1.14 thorpej if (mask + dmask == 0) {
451 1.14 thorpej for (i = 0; i != 32 && ((1<<i) & mask) == 0; i++)
452 1.14 thorpej continue;
453 1.14 thorpej (void)sprintf(sp, "/%d", 32-i);
454 1.14 thorpej
455 1.14 thorpej } else {
456 1.15 christos (void)sprintf(sp, " (mask %#x)", (u_int)mask);
457 1.14 thorpej }
458 1.14 thorpej }
459 1.14 thorpej
460 1.14 thorpej return s;
461 1.15 christos #undef NUM_BUFS
462 1.14 thorpej }
463 1.14 thorpej
464 1.14 thorpej
465 1.14 thorpej /* display a bit-field
466 1.14 thorpej */
467 1.14 thorpej struct bits {
468 1.14 thorpej int bits_mask;
469 1.14 thorpej int bits_clear;
470 1.14 thorpej char *bits_name;
471 1.14 thorpej };
472 1.14 thorpej
473 1.14 thorpej static struct bits if_bits[] = {
474 1.14 thorpej { IFF_LOOPBACK, 0, "LOOPBACK" },
475 1.14 thorpej { IFF_POINTOPOINT, 0, "PT-TO-PT" },
476 1.14 thorpej { 0, 0, 0}
477 1.14 thorpej };
478 1.14 thorpej
479 1.14 thorpej static struct bits is_bits[] = {
480 1.16 christos { IS_ALIAS, 0, "ALIAS" },
481 1.14 thorpej { IS_SUBNET, 0, "" },
482 1.16 christos { IS_REMOTE, (IS_NO_RDISC
483 1.16 christos | IS_BCAST_RDISC), "REMOTE" },
484 1.14 thorpej { IS_PASSIVE, (IS_NO_RDISC
485 1.14 thorpej | IS_NO_RIP
486 1.14 thorpej | IS_NO_SUPER_AG
487 1.14 thorpej | IS_PM_RDISC
488 1.14 thorpej | IS_NO_AG), "PASSIVE" },
489 1.14 thorpej { IS_EXTERNAL, 0, "EXTERNAL" },
490 1.14 thorpej { IS_CHECKED, 0, "" },
491 1.14 thorpej { IS_ALL_HOSTS, 0, "" },
492 1.14 thorpej { IS_ALL_ROUTERS, 0, "" },
493 1.16 christos { IS_DISTRUST, 0, "DISTRUST" },
494 1.14 thorpej { IS_BROKE, IS_SICK, "BROKEN" },
495 1.14 thorpej { IS_SICK, 0, "SICK" },
496 1.16 christos { IS_DUP, 0, "DUPLICATE" },
497 1.16 christos { IS_REDIRECT_OK, 0, "REDIRECT_OK" },
498 1.14 thorpej { IS_NEED_NET_SYN, 0, "" },
499 1.14 thorpej { IS_NO_AG, IS_NO_SUPER_AG, "NO_AG" },
500 1.14 thorpej { IS_NO_SUPER_AG, 0, "NO_SUPER_AG" },
501 1.14 thorpej { (IS_NO_RIPV1_IN
502 1.14 thorpej | IS_NO_RIPV2_IN
503 1.14 thorpej | IS_NO_RIPV1_OUT
504 1.14 thorpej | IS_NO_RIPV2_OUT), 0, "NO_RIP" },
505 1.14 thorpej { (IS_NO_RIPV1_IN
506 1.14 thorpej | IS_NO_RIPV1_OUT), 0, "RIPV2" },
507 1.14 thorpej { IS_NO_RIPV1_IN, 0, "NO_RIPV1_IN" },
508 1.14 thorpej { IS_NO_RIPV2_IN, 0, "NO_RIPV2_IN" },
509 1.14 thorpej { IS_NO_RIPV1_OUT, 0, "NO_RIPV1_OUT" },
510 1.14 thorpej { IS_NO_RIPV2_OUT, 0, "NO_RIPV2_OUT" },
511 1.14 thorpej { (IS_NO_ADV_IN
512 1.14 thorpej | IS_NO_SOL_OUT
513 1.14 thorpej | IS_NO_ADV_OUT), IS_BCAST_RDISC, "NO_RDISC" },
514 1.14 thorpej { IS_NO_SOL_OUT, 0, "NO_SOLICIT" },
515 1.14 thorpej { IS_SOL_OUT, 0, "SEND_SOLICIT" },
516 1.14 thorpej { IS_NO_ADV_OUT, IS_BCAST_RDISC, "NO_RDISC_ADV" },
517 1.14 thorpej { IS_ADV_OUT, 0, "RDISC_ADV" },
518 1.14 thorpej { IS_BCAST_RDISC, 0, "BCAST_RDISC" },
519 1.16 christos { IS_PM_RDISC, 0, "" },
520 1.14 thorpej { 0, 0, "%#x"}
521 1.14 thorpej };
522 1.14 thorpej
523 1.14 thorpej static struct bits rs_bits[] = {
524 1.14 thorpej { RS_IF, 0, "IF" },
525 1.14 thorpej { RS_NET_INT, RS_NET_SYN, "NET_INT" },
526 1.14 thorpej { RS_NET_SYN, 0, "NET_SYN" },
527 1.14 thorpej { RS_SUBNET, 0, "" },
528 1.14 thorpej { RS_LOCAL, 0, "LOCAL" },
529 1.14 thorpej { RS_MHOME, 0, "MHOME" },
530 1.14 thorpej { RS_STATIC, 0, "STATIC" },
531 1.14 thorpej { RS_RDISC, 0, "RDISC" },
532 1.14 thorpej { 0, 0, "%#x"}
533 1.14 thorpej };
534 1.14 thorpej
535 1.14 thorpej
536 1.14 thorpej static void
537 1.14 thorpej trace_bits(struct bits *tbl,
538 1.14 thorpej u_int field,
539 1.14 thorpej int force)
540 1.14 thorpej {
541 1.14 thorpej int b;
542 1.14 thorpej char c;
543 1.14 thorpej
544 1.14 thorpej if (force) {
545 1.14 thorpej (void)putc('<', ftrace);
546 1.14 thorpej c = 0;
547 1.14 thorpej } else {
548 1.14 thorpej c = '<';
549 1.14 thorpej }
550 1.14 thorpej
551 1.14 thorpej while (field != 0
552 1.14 thorpej && (b = tbl->bits_mask) != 0) {
553 1.14 thorpej if ((b & field) == b) {
554 1.14 thorpej if (tbl->bits_name[0] != '\0') {
555 1.14 thorpej if (c)
556 1.14 thorpej (void)putc(c, ftrace);
557 1.14 thorpej (void)fprintf(ftrace, "%s", tbl->bits_name);
558 1.14 thorpej c = '|';
559 1.14 thorpej }
560 1.14 thorpej if (0 == (field &= ~(b | tbl->bits_clear)))
561 1.14 thorpej break;
562 1.14 thorpej }
563 1.14 thorpej tbl++;
564 1.14 thorpej }
565 1.14 thorpej if (field != 0 && tbl->bits_name != 0) {
566 1.14 thorpej if (c)
567 1.14 thorpej (void)putc(c, ftrace);
568 1.14 thorpej (void)fprintf(ftrace, tbl->bits_name, field);
569 1.14 thorpej c = '|';
570 1.14 thorpej }
571 1.14 thorpej
572 1.14 thorpej if (c != '<' || force)
573 1.14 thorpej (void)fputs("> ", ftrace);
574 1.14 thorpej }
575 1.14 thorpej
576 1.14 thorpej
577 1.16 christos char *
578 1.16 christos rtname(naddr dst,
579 1.16 christos naddr mask,
580 1.16 christos naddr gate)
581 1.14 thorpej {
582 1.14 thorpej static char buf[3*4+3+1+2+3 /* "xxx.xxx.xxx.xxx/xx-->" */
583 1.14 thorpej +3*4+3+1]; /* "xxx.xxx.xxx.xxx" */
584 1.14 thorpej int i;
585 1.14 thorpej
586 1.14 thorpej i = sprintf(buf, "%-16s-->", addrname(dst, mask, 0));
587 1.16 christos (void)sprintf(&buf[i], "%-*s", 15+20-MAX(20,i), naddr_ntoa(gate));
588 1.14 thorpej return buf;
589 1.14 thorpej }
590 1.14 thorpej
591 1.14 thorpej
592 1.16 christos static void
593 1.16 christos print_rts(struct rt_spare *rts,
594 1.16 christos int force_metric, /* -1=suppress, 0=default */
595 1.16 christos int force_ifp, /* -1=suppress, 0=default */
596 1.16 christos int force_router, /* -1=suppress, 0=default, 1=display */
597 1.16 christos int force_tag, /* -1=suppress, 0=default, 1=display */
598 1.16 christos int force_time) /* 0=suppress, 1=display */
599 1.16 christos {
600 1.16 christos if (force_metric >= 0)
601 1.16 christos (void)fprintf(ftrace, "metric=%-2d ", rts->rts_metric);
602 1.16 christos if (force_ifp >= 0)
603 1.16 christos (void)fprintf(ftrace, "%s ", (rts->rts_ifp == 0 ?
604 1.16 christos "if?" : rts->rts_ifp->int_name));
605 1.16 christos if (force_router > 0
606 1.16 christos || (force_router == 0 && rts->rts_router != rts->rts_gate))
607 1.16 christos (void)fprintf(ftrace, "router=%s ",
608 1.16 christos naddr_ntoa(rts->rts_router));
609 1.16 christos if (force_time > 0)
610 1.16 christos (void)fprintf(ftrace, "%s ", ts(rts->rts_time));
611 1.16 christos if (force_tag > 0
612 1.16 christos || (force_tag == 0 && rts->rts_tag != 0))
613 1.16 christos (void)fprintf(ftrace, "tag=%#x ",
614 1.16 christos ntohs(rts->rts_tag));
615 1.16 christos }
616 1.16 christos
617 1.16 christos
618 1.14 thorpej void
619 1.14 thorpej trace_if(char *act,
620 1.14 thorpej struct interface *ifp)
621 1.14 thorpej {
622 1.14 thorpej if (!TRACEACTIONS || ftrace == 0)
623 1.14 thorpej return;
624 1.14 thorpej
625 1.14 thorpej lastlog();
626 1.16 christos (void)fprintf(ftrace, "%-3s interface %-4s ", act, ifp->int_name);
627 1.15 christos (void)fprintf(ftrace, "%-15s-->%-15s ",
628 1.14 thorpej naddr_ntoa(ifp->int_addr),
629 1.16 christos addrname(((ifp->int_if_flags & IFF_POINTOPOINT)
630 1.16 christos ? ifp->int_dstaddr
631 1.16 christos : htonl(ifp->int_net)),
632 1.15 christos ifp->int_mask, 1));
633 1.15 christos if (ifp->int_metric != 0)
634 1.15 christos (void)fprintf(ftrace, "metric=%d ", ifp->int_metric);
635 1.16 christos if (!IS_RIP_OUT_OFF(ifp->int_state)
636 1.16 christos && ifp->int_d_metric != 0)
637 1.16 christos (void)fprintf(ftrace, "fake_default=%d ", ifp->int_d_metric);
638 1.14 thorpej trace_bits(if_bits, ifp->int_if_flags, 0);
639 1.14 thorpej trace_bits(is_bits, ifp->int_state, 0);
640 1.14 thorpej (void)fputc('\n',ftrace);
641 1.14 thorpej }
642 1.14 thorpej
643 1.14 thorpej
644 1.14 thorpej void
645 1.14 thorpej trace_upslot(struct rt_entry *rt,
646 1.14 thorpej struct rt_spare *rts,
647 1.14 thorpej naddr gate,
648 1.14 thorpej naddr router,
649 1.14 thorpej struct interface *ifp,
650 1.14 thorpej int metric,
651 1.14 thorpej u_short tag,
652 1.14 thorpej time_t new_time)
653 1.14 thorpej {
654 1.16 christos struct rt_spare new;
655 1.16 christos
656 1.14 thorpej if (!TRACEACTIONS || ftrace == 0)
657 1.14 thorpej return;
658 1.16 christos
659 1.14 thorpej if (rts->rts_gate == gate
660 1.14 thorpej && rts->rts_router == router
661 1.14 thorpej && rts->rts_metric == metric
662 1.14 thorpej && rts->rts_tag == tag)
663 1.14 thorpej return;
664 1.16 christos new.rts_ifp = ifp;
665 1.16 christos new.rts_gate = gate;
666 1.16 christos new.rts_router = router;
667 1.16 christos new.rts_metric = metric;
668 1.16 christos new.rts_time = new_time;
669 1.16 christos new.rts_tag = tag;
670 1.14 thorpej
671 1.14 thorpej lastlog();
672 1.16 christos if (gate == 0) {
673 1.16 christos (void)fprintf(ftrace, "Del #%d %-35s ",
674 1.16 christos rts - rt->rt_spares,
675 1.16 christos rtname(rt->rt_dst, rt->rt_mask, rts->rts_gate));
676 1.16 christos print_rts(&new, 0,0,0,0,
677 1.16 christos rts != rt->rt_spares || AGE_RT(rt->rt_state,ifp));
678 1.16 christos
679 1.16 christos } else if (rts->rts_gate != RIP_DEFAULT) {
680 1.14 thorpej (void)fprintf(ftrace, "Chg #%d %-35s ",
681 1.14 thorpej rts - rt->rt_spares,
682 1.16 christos rtname(rt->rt_dst, rt->rt_mask, rts->rts_gate));
683 1.16 christos print_rts(rts, 0,0,
684 1.16 christos rts->rts_gate != gate,
685 1.16 christos rts->rts_tag != tag,
686 1.16 christos rts != rt->rt_spares || AGE_RT(rt->rt_state,
687 1.16 christos rt->rt_ifp));
688 1.14 thorpej
689 1.16 christos (void)fprintf(ftrace, "\n %19s%-16s ", "",
690 1.14 thorpej gate != rts->rts_gate ? naddr_ntoa(gate) : "");
691 1.16 christos print_rts(&new,
692 1.16 christos -(metric == rts->rts_metric),
693 1.16 christos -(ifp == rts->rts_ifp),
694 1.16 christos 0,
695 1.16 christos rts->rts_tag != tag,
696 1.16 christos new_time != rts->rts_time && (rts != rt->rt_spares
697 1.16 christos || AGE_RT(rt->rt_state,
698 1.16 christos ifp)));
699 1.14 thorpej
700 1.14 thorpej } else {
701 1.14 thorpej (void)fprintf(ftrace, "Add #%d %-35s ",
702 1.14 thorpej rts - rt->rt_spares,
703 1.16 christos rtname(rt->rt_dst, rt->rt_mask, gate));
704 1.16 christos print_rts(&new, 0,0,0,0,
705 1.16 christos rts != rt->rt_spares || AGE_RT(rt->rt_state,ifp));
706 1.14 thorpej }
707 1.16 christos (void)fputc('\n',ftrace);
708 1.1 cgd }
709 1.1 cgd
710 1.14 thorpej
711 1.15 christos /* talk about a change made to the kernel table
712 1.15 christos */
713 1.15 christos void
714 1.15 christos trace_kernel(char *p, ...)
715 1.15 christos {
716 1.15 christos va_list args;
717 1.15 christos
718 1.15 christos if (!TRACEKERNEL || ftrace == 0)
719 1.15 christos return;
720 1.15 christos
721 1.15 christos lastlog();
722 1.15 christos va_start(args, p);
723 1.15 christos vfprintf(ftrace, p, args);
724 1.16 christos (void)fputc('\n',ftrace);
725 1.15 christos }
726 1.15 christos
727 1.15 christos
728 1.14 thorpej /* display a message if tracing actions
729 1.14 thorpej */
730 1.14 thorpej void
731 1.14 thorpej trace_act(char *p, ...)
732 1.14 thorpej {
733 1.14 thorpej va_list args;
734 1.14 thorpej
735 1.14 thorpej if (!TRACEACTIONS || ftrace == 0)
736 1.14 thorpej return;
737 1.14 thorpej
738 1.14 thorpej lastlog();
739 1.14 thorpej va_start(args, p);
740 1.14 thorpej vfprintf(ftrace, p, args);
741 1.16 christos (void)fputc('\n',ftrace);
742 1.14 thorpej }
743 1.14 thorpej
744 1.14 thorpej
745 1.14 thorpej /* display a message if tracing packets
746 1.14 thorpej */
747 1.7 cgd void
748 1.14 thorpej trace_pkt(char *p, ...)
749 1.1 cgd {
750 1.14 thorpej va_list args;
751 1.1 cgd
752 1.14 thorpej if (!TRACEPACKETS || ftrace == 0)
753 1.1 cgd return;
754 1.14 thorpej
755 1.14 thorpej lastlog();
756 1.14 thorpej va_start(args, p);
757 1.14 thorpej vfprintf(ftrace, p, args);
758 1.16 christos (void)fputc('\n',ftrace);
759 1.1 cgd }
760 1.1 cgd
761 1.14 thorpej
762 1.7 cgd void
763 1.14 thorpej trace_change(struct rt_entry *rt,
764 1.14 thorpej u_int state,
765 1.14 thorpej naddr gate, /* forward packets here */
766 1.14 thorpej naddr router, /* on the authority of this router */
767 1.14 thorpej int metric,
768 1.14 thorpej u_short tag,
769 1.14 thorpej struct interface *ifp,
770 1.14 thorpej time_t new_time,
771 1.14 thorpej char *label)
772 1.1 cgd {
773 1.16 christos struct rt_spare new;
774 1.16 christos
775 1.14 thorpej if (ftrace == 0)
776 1.14 thorpej return;
777 1.14 thorpej
778 1.14 thorpej if (rt->rt_metric == metric
779 1.14 thorpej && rt->rt_gate == gate
780 1.14 thorpej && rt->rt_router == router
781 1.14 thorpej && rt->rt_state == state
782 1.14 thorpej && rt->rt_tag == tag)
783 1.14 thorpej return;
784 1.16 christos new.rts_ifp = ifp;
785 1.16 christos new.rts_gate = gate;
786 1.16 christos new.rts_router = router;
787 1.16 christos new.rts_metric = metric;
788 1.16 christos new.rts_time = new_time;
789 1.16 christos new.rts_tag = tag;
790 1.14 thorpej
791 1.14 thorpej lastlog();
792 1.16 christos (void)fprintf(ftrace, "%s %-35s ",
793 1.14 thorpej label,
794 1.16 christos rtname(rt->rt_dst, rt->rt_mask, rt->rt_gate));
795 1.16 christos print_rts(rt->rt_spares,
796 1.16 christos 0,0,0,0, AGE_RT(rt->rt_state, rt->rt_ifp));
797 1.14 thorpej trace_bits(rs_bits, rt->rt_state, rt->rt_state != state);
798 1.14 thorpej
799 1.16 christos (void)fprintf(ftrace, "\n%*s %19s%-16s ",
800 1.14 thorpej strlen(label), "", "",
801 1.14 thorpej rt->rt_gate != gate ? naddr_ntoa(gate) : "");
802 1.16 christos print_rts(&new,
803 1.16 christos -(metric == rt->rt_metric),
804 1.16 christos -(ifp == rt->rt_ifp),
805 1.16 christos 0,
806 1.16 christos rt->rt_tag != tag,
807 1.16 christos rt->rt_time != new_time && AGE_RT(rt->rt_state,ifp));
808 1.14 thorpej if (rt->rt_state != state)
809 1.14 thorpej trace_bits(rs_bits, state, 1);
810 1.16 christos (void)fputc('\n',ftrace);
811 1.1 cgd }
812 1.1 cgd
813 1.14 thorpej
814 1.7 cgd void
815 1.14 thorpej trace_add_del(char * action, struct rt_entry *rt)
816 1.1 cgd {
817 1.14 thorpej if (ftrace == 0)
818 1.1 cgd return;
819 1.14 thorpej
820 1.14 thorpej lastlog();
821 1.16 christos (void)fprintf(ftrace, "%s %-35s ",
822 1.14 thorpej action,
823 1.16 christos rtname(rt->rt_dst, rt->rt_mask, rt->rt_gate));
824 1.16 christos print_rts(rt->rt_spares, 0,0,0,0,AGE_RT(rt->rt_state,rt->rt_ifp));
825 1.16 christos trace_bits(rs_bits, rt->rt_state, 0);
826 1.16 christos (void)fputc('\n',ftrace);
827 1.1 cgd }
828 1.1 cgd
829 1.14 thorpej
830 1.15 christos /* ARGSUSED */
831 1.15 christos static int
832 1.15 christos walk_trace(struct radix_node *rn,
833 1.15 christos struct walkarg *w)
834 1.15 christos {
835 1.15 christos #define RT ((struct rt_entry *)rn)
836 1.15 christos struct rt_spare *rts;
837 1.16 christos int i, age = AGE_RT(RT->rt_state, RT->rt_ifp);
838 1.15 christos
839 1.16 christos (void)fprintf(ftrace, " %-35s ",
840 1.16 christos rtname(RT->rt_dst, RT->rt_mask, RT->rt_gate));
841 1.16 christos print_rts(&RT->rt_spares[0], 0,0,0,0,age);
842 1.15 christos trace_bits(rs_bits, RT->rt_state, 0);
843 1.16 christos if (RT->rt_poison_time >= now_garbage
844 1.16 christos && RT->rt_poison_metric < RT->rt_metric)
845 1.16 christos (void)fprintf(ftrace, "pm=%d@%s",
846 1.16 christos RT->rt_poison_metric, ts(RT->rt_poison_time));
847 1.15 christos
848 1.15 christos rts = &RT->rt_spares[1];
849 1.15 christos for (i = 1; i < NUM_SPARES; i++, rts++) {
850 1.16 christos if (rts->rts_gate != RIP_DEFAULT) {
851 1.16 christos (void)fprintf(ftrace,"\n #%d%15s%-16s ",
852 1.16 christos i, "", naddr_ntoa(rts->rts_gate));
853 1.16 christos print_rts(rts, 0,0,0,0,1);
854 1.15 christos }
855 1.15 christos }
856 1.15 christos (void)fputc('\n',ftrace);
857 1.15 christos
858 1.15 christos return 0;
859 1.15 christos }
860 1.15 christos
861 1.15 christos
862 1.15 christos static void
863 1.15 christos trace_dump(void)
864 1.15 christos {
865 1.16 christos struct interface *ifp;
866 1.16 christos
867 1.15 christos if (ftrace == 0)
868 1.15 christos return;
869 1.15 christos lastlog();
870 1.15 christos
871 1.16 christos (void)fputs("current daemon state:\n", ftrace);
872 1.16 christos for (ifp = ifnet; ifp != 0; ifp = ifp->int_next)
873 1.16 christos trace_if("", ifp);
874 1.15 christos (void)rn_walktree(rhead, walk_trace, 0);
875 1.15 christos }
876 1.15 christos
877 1.15 christos
878 1.7 cgd void
879 1.14 thorpej trace_rip(char *dir1, char *dir2,
880 1.14 thorpej struct sockaddr_in *who,
881 1.14 thorpej struct interface *ifp,
882 1.14 thorpej struct rip *msg,
883 1.14 thorpej int size) /* total size of message */
884 1.1 cgd {
885 1.14 thorpej struct netinfo *n, *lim;
886 1.16 christos # define NA (msg->rip_auths)
887 1.16 christos int i, seen_route;
888 1.1 cgd
889 1.14 thorpej if (!TRACEPACKETS || ftrace == 0)
890 1.1 cgd return;
891 1.14 thorpej
892 1.14 thorpej lastlog();
893 1.14 thorpej if (msg->rip_cmd >= RIPCMD_MAX
894 1.14 thorpej || msg->rip_vers == 0) {
895 1.15 christos (void)fprintf(ftrace, "%s bad RIPv%d cmd=%d %s"
896 1.15 christos " %s.%d size=%d\n",
897 1.15 christos dir1, msg->rip_vers, msg->rip_cmd, dir2,
898 1.15 christos naddr_ntoa(who->sin_addr.s_addr),
899 1.15 christos ntohs(who->sin_port),
900 1.15 christos size);
901 1.1 cgd return;
902 1.1 cgd }
903 1.14 thorpej
904 1.14 thorpej (void)fprintf(ftrace, "%s RIPv%d %s %s %s.%d%s%s\n",
905 1.14 thorpej dir1, msg->rip_vers, ripcmds[msg->rip_cmd], dir2,
906 1.14 thorpej naddr_ntoa(who->sin_addr.s_addr), ntohs(who->sin_port),
907 1.14 thorpej ifp ? " via " : "", ifp ? ifp->int_name : "");
908 1.14 thorpej if (!TRACECONTENTS)
909 1.1 cgd return;
910 1.14 thorpej
911 1.16 christos seen_route = 0;
912 1.1 cgd switch (msg->rip_cmd) {
913 1.1 cgd case RIPCMD_REQUEST:
914 1.1 cgd case RIPCMD_RESPONSE:
915 1.1 cgd n = msg->rip_nets;
916 1.14 thorpej lim = (struct netinfo *)((char*)msg + size);
917 1.14 thorpej for (; n < lim; n++) {
918 1.16 christos if (!seen_route
919 1.16 christos && n->n_family == RIP_AF_UNSPEC
920 1.14 thorpej && ntohl(n->n_metric) == HOPCNT_INFINITY
921 1.16 christos && msg->rip_cmd == RIPCMD_REQUEST
922 1.16 christos && (n+1 == lim
923 1.16 christos || (n+2 == lim
924 1.16 christos && (n+1)->n_family == RIP_AF_AUTH))) {
925 1.14 thorpej (void)fputs("\tQUERY ", ftrace);
926 1.14 thorpej if (n->n_dst != 0)
927 1.14 thorpej (void)fprintf(ftrace, "%s ",
928 1.14 thorpej naddr_ntoa(n->n_dst));
929 1.14 thorpej if (n->n_mask != 0)
930 1.14 thorpej (void)fprintf(ftrace, "mask=%#x ",
931 1.15 christos (u_int)ntohl(n->n_mask));
932 1.14 thorpej if (n->n_nhop != 0)
933 1.16 christos (void)fprintf(ftrace, "nhop=%s ",
934 1.14 thorpej naddr_ntoa(n->n_nhop));
935 1.14 thorpej if (n->n_tag != 0)
936 1.16 christos (void)fprintf(ftrace, "tag=%#x ",
937 1.15 christos ntohs(n->n_tag));
938 1.14 thorpej (void)fputc('\n',ftrace);
939 1.14 thorpej continue;
940 1.1 cgd }
941 1.1 cgd
942 1.14 thorpej if (n->n_family == RIP_AF_AUTH) {
943 1.16 christos if (NA->a_type == RIP_AUTH_PW
944 1.16 christos && n == msg->rip_nets) {
945 1.16 christos (void)fprintf(ftrace, "\tPassword"
946 1.16 christos " Authentication:"
947 1.16 christos " \"%s\"\n",
948 1.16 christos qstring(NA->au.au_pw,
949 1.16 christos RIP_AUTH_PW_LEN));
950 1.16 christos continue;
951 1.16 christos }
952 1.16 christos
953 1.16 christos if (NA->a_type == RIP_AUTH_MD5
954 1.16 christos && n == msg->rip_nets) {
955 1.16 christos (void)fprintf(ftrace,
956 1.16 christos "\tMD5 Authentication"
957 1.16 christos " len=%d KeyID=%u"
958 1.16 christos " seqno=%u"
959 1.16 christos " rsvd=%#x,%#x\n",
960 1.16 christos NA->au.a_md5.md5_pkt_len,
961 1.16 christos NA->au.a_md5.md5_keyid,
962 1.16 christos NA->au.a_md5.md5_seqno,
963 1.16 christos NA->au.a_md5.rsvd[0],
964 1.16 christos NA->au.a_md5.rsvd[1]);
965 1.16 christos continue;
966 1.16 christos }
967 1.14 thorpej (void)fprintf(ftrace,
968 1.16 christos "\tAuthentication"
969 1.16 christos " type %d: ",
970 1.16 christos ntohs(NA->a_type));
971 1.14 thorpej for (i = 0;
972 1.16 christos i < sizeof(NA->au.au_pw);
973 1.14 thorpej i++)
974 1.14 thorpej (void)fprintf(ftrace, "%02x ",
975 1.16 christos NA->au.au_pw[i]);
976 1.14 thorpej (void)fputc('\n',ftrace);
977 1.14 thorpej continue;
978 1.14 thorpej }
979 1.1 cgd
980 1.16 christos seen_route = 1;
981 1.14 thorpej if (n->n_family != RIP_AF_INET) {
982 1.14 thorpej (void)fprintf(ftrace,
983 1.16 christos "\t(af %d) %-18s mask=%#x ",
984 1.14 thorpej ntohs(n->n_family),
985 1.14 thorpej naddr_ntoa(n->n_dst),
986 1.15 christos (u_int)ntohl(n->n_mask));
987 1.14 thorpej } else if (msg->rip_vers == RIPv1) {
988 1.14 thorpej (void)fprintf(ftrace, "\t%-18s ",
989 1.14 thorpej addrname(n->n_dst,
990 1.14 thorpej ntohl(n->n_mask),
991 1.14 thorpej n->n_mask==0 ? 2 : 1));
992 1.14 thorpej } else {
993 1.14 thorpej (void)fprintf(ftrace, "\t%-18s ",
994 1.14 thorpej addrname(n->n_dst,
995 1.14 thorpej ntohl(n->n_mask),
996 1.14 thorpej n->n_mask==0 ? 2 : 0));
997 1.1 cgd }
998 1.14 thorpej (void)fprintf(ftrace, "metric=%-2d ",
999 1.15 christos (u_int)ntohl(n->n_metric));
1000 1.14 thorpej if (n->n_nhop != 0)
1001 1.14 thorpej (void)fprintf(ftrace, " nhop=%s ",
1002 1.14 thorpej naddr_ntoa(n->n_nhop));
1003 1.14 thorpej if (n->n_tag != 0)
1004 1.14 thorpej (void)fprintf(ftrace, "tag=%#x",
1005 1.15 christos ntohs(n->n_tag));
1006 1.14 thorpej (void)fputc('\n',ftrace);
1007 1.1 cgd }
1008 1.14 thorpej if (size != (char *)n - (char *)msg)
1009 1.14 thorpej (void)fprintf(ftrace, "truncated record, len %d\n",
1010 1.14 thorpej size);
1011 1.1 cgd break;
1012 1.1 cgd
1013 1.1 cgd case RIPCMD_TRACEON:
1014 1.16 christos fprintf(ftrace, "\tfile=\"%.*s\"\n", size-4,
1015 1.16 christos msg->rip_tracefile);
1016 1.1 cgd break;
1017 1.1 cgd
1018 1.1 cgd case RIPCMD_TRACEOFF:
1019 1.1 cgd break;
1020 1.1 cgd }
1021 1.1 cgd }
1022