Deleted Added
full compact
trace.c (19880) trace.c (20339)
1/*
2 * Copyright (c) 1983, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 22 unchanged lines hidden (view full) ---

31 * SUCH DAMAGE.
32 */
33
34#if !defined(lint) && !defined(sgi) && !defined(__NetBSD__)
35static char sccsid[] = "@(#)trace.c 8.1 (Berkeley) 6/5/93";
36#elif defined(__NetBSD__)
37static char rcsid[] = "$NetBSD$";
38#endif
1/*
2 * Copyright (c) 1983, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 22 unchanged lines hidden (view full) ---

31 * SUCH DAMAGE.
32 */
33
34#if !defined(lint) && !defined(sgi) && !defined(__NetBSD__)
35static char sccsid[] = "@(#)trace.c 8.1 (Berkeley) 6/5/93";
36#elif defined(__NetBSD__)
37static char rcsid[] = "$NetBSD$";
38#endif
39#ident "$Revision: 1.14 $"
39#ident "$Revision: 1.16 $"
40
41#define RIPCMDS
42#include "defs.h"
43#include "pathnames.h"
44#include <sys/stat.h>
45#include <sys/signal.h>
46#include <fcntl.h>
47
48
49#ifdef sgi
50/* use *stat64 for files on large filesystems */
51#define stat stat64
52#endif
53
54#define NRECORDS 50 /* size of circular trace buffer */
55
40
41#define RIPCMDS
42#include "defs.h"
43#include "pathnames.h"
44#include <sys/stat.h>
45#include <sys/signal.h>
46#include <fcntl.h>
47
48
49#ifdef sgi
50/* use *stat64 for files on large filesystems */
51#define stat stat64
52#endif
53
54#define NRECORDS 50 /* size of circular trace buffer */
55
56u_int tracelevel, new_tracelevel;
56int tracelevel, new_tracelevel;
57FILE *ftrace = stdout; /* output trace file */
57FILE *ftrace = stdout; /* output trace file */
58static char *tracelevel_pat = "%s\n";
58static char *sigtrace_pat = "%s\n";
59static char savetracename[MAXPATHLEN+1];
60char inittracename[MAXPATHLEN+1];
61int file_trace; /* 1=tracing to file, not stdout */
59
62
60char savetracename[MAXPATHLEN+1];
61
62static void trace_dump(void);
63
64
65/* convert string to printable characters
66 */
67static char *
68qstring(u_char *s, int len)
69{

--- 87 unchanged lines hidden (view full) ---

157 return s;
158}
159
160
161/* On each event, display a time stamp.
162 * This assumes that 'now' is update once for each event, and
163 * that at least now.tv_usec changes.
164 */
63static void trace_dump(void);
64
65
66/* convert string to printable characters
67 */
68static char *
69qstring(u_char *s, int len)
70{

--- 87 unchanged lines hidden (view full) ---

158 return s;
159}
160
161
162/* On each event, display a time stamp.
163 * This assumes that 'now' is update once for each event, and
164 * that at least now.tv_usec changes.
165 */
166static struct timeval lastlog_time;
167
165void
166lastlog(void)
167{
168void
169lastlog(void)
170{
168 static struct timeval last;
169
170 if (last.tv_sec != now.tv_sec
171 || last.tv_usec != now.tv_usec) {
171 if (lastlog_time.tv_sec != now.tv_sec
172 || lastlog_time.tv_usec != now.tv_usec) {
172 (void)fprintf(ftrace, "-- %s --\n", ts(now.tv_sec));
173 (void)fprintf(ftrace, "-- %s --\n", ts(now.tv_sec));
173 last = now;
174 lastlog_time = now;
174 }
175}
176
177
178static void
179tmsg(char *p, ...)
180{
181 va_list args;

--- 11 unchanged lines hidden (view full) ---

193trace_close(void)
194{
195 int fd;
196
197
198 fflush(stdout);
199 fflush(stderr);
200
175 }
176}
177
178
179static void
180tmsg(char *p, ...)
181{
182 va_list args;

--- 11 unchanged lines hidden (view full) ---

194trace_close(void)
195{
196 int fd;
197
198
199 fflush(stdout);
200 fflush(stderr);
201
201 if (ftrace != 0
202 && savetracename[0] != '\0') {
202 if (ftrace != 0 && file_trace) {
203 if (ftrace != stdout)
204 fclose(ftrace);
205 ftrace = 0;
203 fd = open(_PATH_DEVNULL, O_RDWR);
206 fd = open(_PATH_DEVNULL, O_RDWR);
207 (void)dup2(fd, STDIN_FILENO);
204 (void)dup2(fd, STDOUT_FILENO);
205 (void)dup2(fd, STDERR_FILENO);
206 (void)close(fd);
208 (void)dup2(fd, STDOUT_FILENO);
209 (void)dup2(fd, STDERR_FILENO);
210 (void)close(fd);
207 fclose(ftrace);
208 ftrace = 0;
209 }
211 }
212 lastlog_time.tv_sec = 0;
210}
211
212
213void
214trace_flush(void)
215{
216 if (ftrace != 0) {
217 fflush(ftrace);

--- 8 unchanged lines hidden (view full) ---

226{
227 va_list args;
228
229
230 if (ftrace != 0) {
231 lastlog();
232 va_start(args, p);
233 vfprintf(ftrace, p, args);
213}
214
215
216void
217trace_flush(void)
218{
219 if (ftrace != 0) {
220 fflush(ftrace);

--- 8 unchanged lines hidden (view full) ---

229{
230 va_list args;
231
232
233 if (ftrace != 0) {
234 lastlog();
235 va_start(args, p);
236 vfprintf(ftrace, p, args);
234 fflush(ftrace);
235 }
236 trace_close();
237
238 new_tracelevel = tracelevel = 0;
239}
240
241
237 }
238 trace_close();
239
240 new_tracelevel = tracelevel = 0;
241}
242
243
244/* log a change in tracing
245 */
242void
246void
243trace_on(char *filename,
244 int initial) /* 1=setting from command line */
247tracelevel_msg(char *pat,
248 int dump) /* -1=no dump, 0=default, 1=force */
245{
249{
250 static char *off_msgs[MAX_TRACELEVEL] = {
251 "Tracing actions stopped",
252 "Tracing packets stopped",
253 "Tracing packet contents stopped",
254 "Tracing kernel changes stopped",
255 };
256 static char *on_msgs[MAX_TRACELEVEL] = {
257 "Tracing actions started",
258 "Tracing packets started",
259 "Tracing packet contents started",
260 "Tracing kernel changes started",
261 };
262 u_int old_tracelevel = tracelevel;
263
264
265 if (new_tracelevel < 0)
266 new_tracelevel = 0;
267 else if (new_tracelevel > MAX_TRACELEVEL)
268 new_tracelevel = MAX_TRACELEVEL;
269
270 if (new_tracelevel < tracelevel) {
271 if (new_tracelevel <= 0) {
272 trace_off(pat, off_msgs[0]);
273 } else do {
274 tmsg(pat, off_msgs[tracelevel]);
275 }
276 while (--tracelevel != new_tracelevel);
277
278 } else if (new_tracelevel > tracelevel) {
279 do {
280 tmsg(pat, on_msgs[tracelevel++]);
281 } while (tracelevel != new_tracelevel);
282 }
283
284 if (dump > 0
285 || (dump == 0 && old_tracelevel == 0 && tracelevel != 0))
286 trace_dump();
287}
288
289
290void
291set_tracefile(char *filename,
292 char *pat,
293 int dump) /* -1=no dump, 0=default, 1=force */
294{
246 struct stat stbuf;
247 FILE *n_ftrace;
295 struct stat stbuf;
296 FILE *n_ftrace;
248 u_int old_tracelevel;
297 char *fn;
249
250
298
299
251 /* Given a null filename when tracing is already on, increase the
252 * debugging level and re-open the file in case it has been unlinked.
300 /* Allow a null filename to increase the level if the trace file
301 * is already open or if coming from a trusted source, such as
302 * a signal or the command line.
253 */
303 */
254 if (filename[0] == '\0') {
255 if (tracelevel != 0) {
256 new_tracelevel++;
257 tracelevel_pat = "trace command: %s\n";
258 } else if (savetracename[0] == '\0') {
259 msglog("missing trace file name");
260 return;
304 if (filename == 0 || filename[0] == '\0') {
305 filename = 0;
306 if (ftrace == 0) {
307 if (inittracename[0] == '\0') {
308 msglog("missing trace file name");
309 return;
310 }
311 fn = inittracename;
312 } else {
313 fn = 0;
261 }
314 }
262 filename = savetracename;
263
264 } else if (!strcmp(filename,"dump/../table")) {
265 trace_dump();
266 return;
267
268 } else {
315
316 } else if (!strcmp(filename,"dump/../table")) {
317 trace_dump();
318 return;
319
320 } else {
321 /* Allow the file specified with "-T file" to be reopened,
322 * but require all other names specified over the net to
323 * match the official path. The path can specify a directory
324 * in which the file is to be created.
325 */
326 if (strcmp(filename, inittracename)
327#ifdef _PATH_TRACE
328 && (strncmp(filename, _PATH_TRACE, sizeof(_PATH_TRACE)-1)
329 || strstr(filename,"../")
330 || 0 > stat(_PATH_TRACE, &stbuf))
331#endif
332 ) {
333 msglog("wrong trace file \"%s\"", filename);
334 return;
335 }
336
337 /* If the new tracefile exists, it must be a regular file.
338 */
269 if (stat(filename, &stbuf) >= 0
270 && (stbuf.st_mode & S_IFMT) != S_IFREG) {
271 msglog("wrong type (%#x) of trace file \"%s\"",
272 stbuf.st_mode, filename);
273 return;
274 }
275
339 if (stat(filename, &stbuf) >= 0
340 && (stbuf.st_mode & S_IFMT) != S_IFREG) {
341 msglog("wrong type (%#x) of trace file \"%s\"",
342 stbuf.st_mode, filename);
343 return;
344 }
345
276 if (!initial
277#ifdef _PATH_TRACE
278 && (strncmp(filename, _PATH_TRACE, sizeof(_PATH_TRACE)-1)
279 || strstr(filename,"../")
280 || 0 > stat(_PATH_TRACE, &stbuf))
281#endif
282 && strcmp(filename, savetracename)) {
283 msglog("wrong directory for trace file \"%s\"",
284 filename);
346 fn = filename;
347 }
348
349 if (fn != 0) {
350 n_ftrace = fopen(fn, "a");
351 if (n_ftrace == 0) {
352 msglog("failed to open trace file \"%s\" %s",
353 fn, strerror(errno));
354 if (fn == inittracename)
355 inittracename[0] = '\0';
285 return;
286 }
356 return;
357 }
287 }
288
358
289 n_ftrace = fopen(filename, "a");
290 if (n_ftrace == 0) {
291 msglog("failed to open trace file \"%s\" %s",
292 filename, strerror(errno));
293 return;
294 }
359 tmsg("switch to trace file %s\n", fn);
295
360
296 tmsg("switch to trace file %s\n", filename);
297 trace_close();
298 if (filename != savetracename)
299 strncpy(savetracename, filename, sizeof(savetracename)-1);
300 ftrace = n_ftrace;
361 file_trace = 1;
362 trace_close();
301
363
302 fflush(stdout);
303 fflush(stderr);
304 dup2(fileno(ftrace), STDOUT_FILENO);
305 dup2(fileno(ftrace), STDERR_FILENO);
364 if (fn != savetracename)
365 strncpy(savetracename, fn, sizeof(savetracename)-1);
366 ftrace = n_ftrace;
306
367
307 if (new_tracelevel == 0)
308 new_tracelevel = 1;
309 old_tracelevel = tracelevel;
310 set_tracelevel(initial);
368 fflush(stdout);
369 fflush(stderr);
370 dup2(fileno(ftrace), STDOUT_FILENO);
371 dup2(fileno(ftrace), STDERR_FILENO);
372 }
311
373
312 if (!initial && old_tracelevel == 0)
313 trace_dump();
374 if (new_tracelevel == 0 || filename == 0)
375 new_tracelevel++;
376 tracelevel_msg(pat, dump != 0 ? dump : (filename != 0));
314}
315
316
317/* ARGSUSED */
318void
319sigtrace_on(int s)
320{
321 new_tracelevel++;
377}
378
379
380/* ARGSUSED */
381void
382sigtrace_on(int s)
383{
384 new_tracelevel++;
322 tracelevel_pat = "SIGUSR1: %s\n";
385 sigtrace_pat = "SIGUSR1: %s\n";
323}
324
325
326/* ARGSUSED */
327void
328sigtrace_off(int s)
329{
330 new_tracelevel--;
386}
387
388
389/* ARGSUSED */
390void
391sigtrace_off(int s)
392{
393 new_tracelevel--;
331 tracelevel_pat = "SIGUSR2: %s\n";
394 sigtrace_pat = "SIGUSR2: %s\n";
332}
333
334
395}
396
397
335/* Move to next higher level of tracing when -t option processed or
336 * SIGUSR1 is received. Successive levels are:
337 * actions
338 * actions + packets
339 * actions + packets + contents
398/* Set tracing after a signal.
340 */
341void
399 */
400void
342set_tracelevel(int initial)
401set_tracelevel(void)
343{
402{
344 static char *off_msgs[MAX_TRACELEVEL] = {
345 "Tracing actions stopped",
346 "Tracing packets stopped",
347 "Tracing packet contents stopped",
348 "Tracing kernel changes stopped",
349 };
350 static char *on_msgs[MAX_TRACELEVEL] = {
351 "Tracing actions started",
352 "Tracing packets started",
353 "Tracing packet contents started",
354 "Tracing kernel changes started",
355 };
403 if (new_tracelevel == tracelevel)
404 return;
356
405
357
358 if (new_tracelevel > MAX_TRACELEVEL) {
359 new_tracelevel = MAX_TRACELEVEL;
360 if (new_tracelevel == tracelevel) {
361 tmsg(tracelevel_pat, on_msgs[tracelevel-1]);
406 /* If tracing entirely off, and there was no tracefile specified
407 * on the command line, then leave it off.
408 */
409 if (new_tracelevel > tracelevel && ftrace == 0) {
410 if (savetracename[0] != '\0') {
411 set_tracefile(savetracename,sigtrace_pat,0);
412 } else if (inittracename[0] != '\0') {
413 set_tracefile(inittracename,sigtrace_pat,0);
414 } else {
415 new_tracelevel = 0;
362 return;
363 }
416 return;
417 }
418 } else {
419 tracelevel_msg(sigtrace_pat, 0);
364 }
420 }
365
366 for (; new_tracelevel != tracelevel; tracelevel++) {
367 if (new_tracelevel < tracelevel) {
368 if (--tracelevel == 0)
369 trace_off(tracelevel_pat, off_msgs[0]);
370 else
371 tmsg(tracelevel_pat, off_msgs[tracelevel]);
372 } else {
373 if (ftrace == 0) {
374 if (savetracename[0] != '\0')
375 trace_on(savetracename, 1);
376 else
377 ftrace = stdout;
378 }
379 if (!initial || tracelevel+1 == new_tracelevel)
380 tmsg(tracelevel_pat, on_msgs[tracelevel]);
381 }
382 }
383 tracelevel_pat = "%s\n";
384}
385
386
387/* display an address
388 */
389char *
390addrname(naddr addr, /* in network byte order */
391 naddr mask,

--- 57 unchanged lines hidden (view full) ---

449 { IS_EXTERNAL, 0, "EXTERNAL" },
450 { IS_CHECKED, 0, "" },
451 { IS_ALL_HOSTS, 0, "" },
452 { IS_ALL_ROUTERS, 0, "" },
453 { IS_DISTRUST, 0, "DISTRUST" },
454 { IS_BROKE, IS_SICK, "BROKEN" },
455 { IS_SICK, 0, "SICK" },
456 { IS_DUP, 0, "DUPLICATE" },
421}
422
423
424/* display an address
425 */
426char *
427addrname(naddr addr, /* in network byte order */
428 naddr mask,

--- 57 unchanged lines hidden (view full) ---

486 { IS_EXTERNAL, 0, "EXTERNAL" },
487 { IS_CHECKED, 0, "" },
488 { IS_ALL_HOSTS, 0, "" },
489 { IS_ALL_ROUTERS, 0, "" },
490 { IS_DISTRUST, 0, "DISTRUST" },
491 { IS_BROKE, IS_SICK, "BROKEN" },
492 { IS_SICK, 0, "SICK" },
493 { IS_DUP, 0, "DUPLICATE" },
494 { IS_REDIRECT_OK, 0, "REDIRECT_OK" },
457 { IS_NEED_NET_SYN, 0, "" },
458 { IS_NO_AG, IS_NO_SUPER_AG, "NO_AG" },
459 { IS_NO_SUPER_AG, 0, "NO_SUPER_AG" },
460 { (IS_NO_RIPV1_IN
461 | IS_NO_RIPV2_IN
462 | IS_NO_RIPV1_OUT
463 | IS_NO_RIPV2_OUT), 0, "NO_RIP" },
464 { (IS_NO_RIPV1_IN

--- 78 unchanged lines hidden (view full) ---

543 int i;
544
545 i = sprintf(buf, "%-16s-->", addrname(dst, mask, 0));
546 (void)sprintf(&buf[i], "%-*s", 15+20-MAX(20,i), gate);
547 return buf;
548}
549
550
495 { IS_NEED_NET_SYN, 0, "" },
496 { IS_NO_AG, IS_NO_SUPER_AG, "NO_AG" },
497 { IS_NO_SUPER_AG, 0, "NO_SUPER_AG" },
498 { (IS_NO_RIPV1_IN
499 | IS_NO_RIPV2_IN
500 | IS_NO_RIPV1_OUT
501 | IS_NO_RIPV2_OUT), 0, "NO_RIP" },
502 { (IS_NO_RIPV1_IN

--- 78 unchanged lines hidden (view full) ---

581 int i;
582
583 i = sprintf(buf, "%-16s-->", addrname(dst, mask, 0));
584 (void)sprintf(&buf[i], "%-*s", 15+20-MAX(20,i), gate);
585 return buf;
586}
587
588
589static void
590print_rts(struct rt_spare *rts,
591 int force_metric, /* -1=suppress, 0=default */
592 int force_ifp, /* -1=suppress, 0=default */
593 int force_router, /* -1=suppress, 0=default, 1=display */
594 int force_tag, /* -1=suppress, 0=default, 1=display */
595 int force_time) /* 0=suppress, 1=display */
596{
597 if (force_metric >= 0)
598 (void)fprintf(ftrace, "metric=%-2d ", rts->rts_metric);
599 if (force_ifp >= 0)
600 (void)fprintf(ftrace, "%s ", (rts->rts_ifp == 0 ?
601 "if?" : rts->rts_ifp->int_name));
602 if (force_router > 0
603 || (force_router == 0 && rts->rts_router != rts->rts_gate))
604 (void)fprintf(ftrace, "router=%s ",
605 naddr_ntoa(rts->rts_router));
606 if (force_time > 0)
607 (void)fprintf(ftrace, "%s ", ts(rts->rts_time));
608 if (force_tag > 0
609 || (force_tag == 0 && rts->rts_tag != 0))
610 (void)fprintf(ftrace, "tag=%#x ",
611 ntohs(rts->rts_tag));
612}
613
614
551void
552trace_if(char *act,
553 struct interface *ifp)
554{
555 if (!TRACEACTIONS || ftrace == 0)
556 return;
557
558 lastlog();

--- 20 unchanged lines hidden (view full) ---

579 struct rt_spare *rts,
580 naddr gate,
581 naddr router,
582 struct interface *ifp,
583 int metric,
584 u_short tag,
585 time_t new_time)
586{
615void
616trace_if(char *act,
617 struct interface *ifp)
618{
619 if (!TRACEACTIONS || ftrace == 0)
620 return;
621
622 lastlog();

--- 20 unchanged lines hidden (view full) ---

643 struct rt_spare *rts,
644 naddr gate,
645 naddr router,
646 struct interface *ifp,
647 int metric,
648 u_short tag,
649 time_t new_time)
650{
651 struct rt_spare new;
652
587 if (!TRACEACTIONS || ftrace == 0)
588 return;
653 if (!TRACEACTIONS || ftrace == 0)
654 return;
655
589 if (rts->rts_gate == gate
590 && rts->rts_router == router
591 && rts->rts_metric == metric
592 && rts->rts_tag == tag)
593 return;
656 if (rts->rts_gate == gate
657 && rts->rts_router == router
658 && rts->rts_metric == metric
659 && rts->rts_tag == tag)
660 return;
661 new.rts_ifp = ifp;
662 new.rts_gate = gate;
663 new.rts_router = router;
664 new.rts_metric = metric;
665 new.rts_time = new_time;
666 new.rts_tag = tag;
594
595 lastlog();
596 if (rts->rts_gate != RIP_DEFAULT) {
597 (void)fprintf(ftrace, "Chg #%d %-35s ",
598 rts - rt->rt_spares,
599 trace_pair(rt->rt_dst, rt->rt_mask,
600 naddr_ntoa(rts->rts_gate)));
667
668 lastlog();
669 if (rts->rts_gate != RIP_DEFAULT) {
670 (void)fprintf(ftrace, "Chg #%d %-35s ",
671 rts - rt->rt_spares,
672 trace_pair(rt->rt_dst, rt->rt_mask,
673 naddr_ntoa(rts->rts_gate)));
601 if (rts->rts_gate != rts->rts_gate)
602 (void)fprintf(ftrace, "router=%s ",
603 naddr_ntoa(rts->rts_gate));
604 if (rts->rts_tag != 0)
605 (void)fprintf(ftrace, "tag=%#x ", ntohs(rts->rts_tag));
606 (void)fprintf(ftrace, "metric=%-2d ", rts->rts_metric);
607 if (rts->rts_ifp != 0)
608 (void)fprintf(ftrace, "%s ",
609 rts->rts_ifp->int_name);
610 (void)fprintf(ftrace, "%s\n", ts(rts->rts_time));
674 print_rts(rts, 0,0,
675 rts->rts_gate != gate,
676 rts->rts_tag != tag,
677 rts != rt->rt_spares || AGE_RT(rt->rt_state,
678 rt->rt_ifp));
611
679
612 (void)fprintf(ftrace, " %19s%-16s ",
613 "",
680 (void)fprintf(ftrace, "\n %19s%-16s ", "",
614 gate != rts->rts_gate ? naddr_ntoa(gate) : "");
681 gate != rts->rts_gate ? naddr_ntoa(gate) : "");
615 if (gate != router)
616 (void)fprintf(ftrace,"router=%s ",naddr_ntoa(router));
617 if (tag != rts->rts_tag)
618 (void)fprintf(ftrace, "tag=%#x ", ntohs(tag));
619 if (metric != rts->rts_metric)
620 (void)fprintf(ftrace, "metric=%-2d ", metric);
621 if (ifp != rts->rts_ifp && ifp != 0 )
622 (void)fprintf(ftrace, "%s ", ifp->int_name);
623 (void)fprintf(ftrace, "%s\n",
624 new_time != rts->rts_time ? ts(new_time) : "");
682 print_rts(&new,
683 -(metric == rts->rts_metric),
684 -(ifp == rts->rts_ifp),
685 0,
686 rts->rts_tag != tag,
687 new_time != rts->rts_time && (rts != rt->rt_spares
688 || AGE_RT(rt->rt_state,
689 ifp)));
625
626 } else {
627 (void)fprintf(ftrace, "Add #%d %-35s ",
628 rts - rt->rt_spares,
629 trace_pair(rt->rt_dst, rt->rt_mask,
630 naddr_ntoa(gate)));
690
691 } else {
692 (void)fprintf(ftrace, "Add #%d %-35s ",
693 rts - rt->rt_spares,
694 trace_pair(rt->rt_dst, rt->rt_mask,
695 naddr_ntoa(gate)));
631 if (gate != router)
632 (void)fprintf(ftrace, "router=%s ", naddr_ntoa(gate));
633 if (tag != 0)
634 (void)fprintf(ftrace, "tag=%#x ", ntohs(tag));
635 (void)fprintf(ftrace, "metric=%-2d ", metric);
636 if (ifp != 0)
637 (void)fprintf(ftrace, "%s ", ifp->int_name);
638 (void)fprintf(ftrace, "%s\n", ts(new_time));
696 print_rts(&new, 0,0,0,0,
697 rts != rt->rt_spares || AGE_RT(rt->rt_state,ifp));
639 }
698 }
699 (void)fputc('\n',ftrace);
640}
641
642
643/* talk about a change made to the kernel table
644 */
645void
646trace_kernel(char *p, ...)
647{

--- 48 unchanged lines hidden (view full) ---

696 naddr gate, /* forward packets here */
697 naddr router, /* on the authority of this router */
698 int metric,
699 u_short tag,
700 struct interface *ifp,
701 time_t new_time,
702 char *label)
703{
700}
701
702
703/* talk about a change made to the kernel table
704 */
705void
706trace_kernel(char *p, ...)
707{

--- 48 unchanged lines hidden (view full) ---

756 naddr gate, /* forward packets here */
757 naddr router, /* on the authority of this router */
758 int metric,
759 u_short tag,
760 struct interface *ifp,
761 time_t new_time,
762 char *label)
763{
764 struct rt_spare new;
765
704 if (ftrace == 0)
705 return;
706
707 if (rt->rt_metric == metric
708 && rt->rt_gate == gate
709 && rt->rt_router == router
710 && rt->rt_state == state
711 && rt->rt_tag == tag)
712 return;
766 if (ftrace == 0)
767 return;
768
769 if (rt->rt_metric == metric
770 && rt->rt_gate == gate
771 && rt->rt_router == router
772 && rt->rt_state == state
773 && rt->rt_tag == tag)
774 return;
775 new.rts_ifp = ifp;
776 new.rts_gate = gate;
777 new.rts_router = router;
778 new.rts_metric = metric;
779 new.rts_time = new_time;
780 new.rts_tag = tag;
713
714 lastlog();
781
782 lastlog();
715 (void)fprintf(ftrace, "%s %-35s metric=%-2d ",
783 (void)fprintf(ftrace, "%s %-35s ",
716 label,
717 trace_pair(rt->rt_dst, rt->rt_mask,
784 label,
785 trace_pair(rt->rt_dst, rt->rt_mask,
718 naddr_ntoa(rt->rt_gate)),
719 rt->rt_metric);
720 if (rt->rt_router != rt->rt_gate)
721 (void)fprintf(ftrace, "router=%s ",
722 naddr_ntoa(rt->rt_router));
723 if (rt->rt_tag != 0)
724 (void)fprintf(ftrace, "tag=%#x ", ntohs(rt->rt_tag));
786 naddr_ntoa(rt->rt_gate)));
787 print_rts(rt->rt_spares,
788 0,0,0,0, AGE_RT(rt->rt_state, rt->rt_ifp));
725 trace_bits(rs_bits, rt->rt_state, rt->rt_state != state);
789 trace_bits(rs_bits, rt->rt_state, rt->rt_state != state);
726 (void)fprintf(ftrace, "%s ",
727 rt->rt_ifp == 0 ? "?" : rt->rt_ifp->int_name);
728 (void)fprintf(ftrace, "%s\n",
729 AGE_RT(rt->rt_state, rt->rt_ifp) ? ts(rt->rt_time) : "");
730
790
731 (void)fprintf(ftrace, "%*s %19s%-16s ",
791 (void)fprintf(ftrace, "\n%*s %19s%-16s ",
732 strlen(label), "", "",
733 rt->rt_gate != gate ? naddr_ntoa(gate) : "");
792 strlen(label), "", "",
793 rt->rt_gate != gate ? naddr_ntoa(gate) : "");
734 if (rt->rt_metric != metric)
735 (void)fprintf(ftrace, "metric=%-2d ", metric);
736 if (router != gate)
737 (void)fprintf(ftrace, "router=%s ", naddr_ntoa(router));
738 if (rt->rt_tag != tag)
739 (void)fprintf(ftrace, "tag=%#x ", ntohs(tag));
794 print_rts(&new,
795 -(metric == rt->rt_metric),
796 -(ifp == rt->rt_ifp),
797 0,
798 rt->rt_tag != tag,
799 rt->rt_time != new_time && AGE_RT(rt->rt_state,ifp));
740 if (rt->rt_state != state)
741 trace_bits(rs_bits, state, 1);
800 if (rt->rt_state != state)
801 trace_bits(rs_bits, state, 1);
742 if (rt->rt_ifp != ifp)
743 (void)fprintf(ftrace, "%s ",
744 ifp != 0 ? ifp->int_name : "?");
745 (void)fprintf(ftrace, "%s\n",
746 ((rt->rt_time == new_time || !AGE_RT(rt->rt_state, ifp))
747 ? "" : ts(new_time)));
802 (void)fputc('\n',ftrace);
748}
749
750
751void
752trace_add_del(char * action, struct rt_entry *rt)
753{
803}
804
805
806void
807trace_add_del(char * action, struct rt_entry *rt)
808{
754 u_int state = rt->rt_state;
755
756 if (ftrace == 0)
757 return;
758
759 lastlog();
809 if (ftrace == 0)
810 return;
811
812 lastlog();
760 (void)fprintf(ftrace, "%s %-35s metric=%-2d ",
813 (void)fprintf(ftrace, "%s %-35s ",
761 action,
762 trace_pair(rt->rt_dst, rt->rt_mask,
814 action,
815 trace_pair(rt->rt_dst, rt->rt_mask,
763 naddr_ntoa(rt->rt_gate)),
764 rt->rt_metric);
765 if (rt->rt_router != rt->rt_gate)
766 (void)fprintf(ftrace, "router=%s ",
767 naddr_ntoa(rt->rt_router));
768 if (rt->rt_tag != 0)
769 (void)fprintf(ftrace, "tag=%#x ", ntohs(rt->rt_tag));
770 trace_bits(rs_bits, state, 0);
771 (void)fprintf(ftrace, "%s ",
772 rt->rt_ifp != 0 ? rt->rt_ifp->int_name : "?");
773 (void)fprintf(ftrace, "%s\n", ts(rt->rt_time));
816 naddr_ntoa(rt->rt_gate)));
817 print_rts(rt->rt_spares, 0,0,0,0,AGE_RT(rt->rt_state,rt->rt_ifp));
818 trace_bits(rs_bits, rt->rt_state, 0);
819 (void)fputc('\n',ftrace);
774}
775
776
777/* ARGSUSED */
778static int
779walk_trace(struct radix_node *rn,
780 struct walkarg *w)
781{
782#define RT ((struct rt_entry *)rn)
783 struct rt_spare *rts;
820}
821
822
823/* ARGSUSED */
824static int
825walk_trace(struct radix_node *rn,
826 struct walkarg *w)
827{
828#define RT ((struct rt_entry *)rn)
829 struct rt_spare *rts;
784 int i, age;
830 int i, age = AGE_RT(RT->rt_state, RT->rt_ifp);
785
831
786 (void)fprintf(ftrace, " %-35s metric=%-2d ",
787 trace_pair(RT->rt_dst, RT->rt_mask,
788 naddr_ntoa(RT->rt_gate)),
789 RT->rt_metric);
790 if (RT->rt_router != RT->rt_gate)
791 (void)fprintf(ftrace, "router=%s ",
792 naddr_ntoa(RT->rt_router));
793 if (RT->rt_tag != 0)
794 (void)fprintf(ftrace, "tag=%#x ",
795 ntohs(RT->rt_tag));
832 (void)fprintf(ftrace, " %-35s ", trace_pair(RT->rt_dst, RT->rt_mask,
833 naddr_ntoa(RT->rt_gate)));
834 print_rts(&RT->rt_spares[0], 0,0,0,0,age);
796 trace_bits(rs_bits, RT->rt_state, 0);
835 trace_bits(rs_bits, RT->rt_state, 0);
797 (void)fprintf(ftrace, "%s ",
798 RT->rt_ifp == 0 ? "?" : RT->rt_ifp->int_name);
799 age = AGE_RT(RT->rt_state, RT->rt_ifp);
800 if (age)
801 (void)fprintf(ftrace, "%s", ts(RT->rt_time));
836 if (RT->rt_poison_time >= now_garbage
837 && RT->rt_poison_metric < RT->rt_metric)
838 (void)fprintf(ftrace, "pm=%d@%s",
839 RT->rt_poison_metric,
840 ts(RT->rt_poison_time));
802
803 rts = &RT->rt_spares[1];
804 for (i = 1; i < NUM_SPARES; i++, rts++) {
841
842 rts = &RT->rt_spares[1];
843 for (i = 1; i < NUM_SPARES; i++, rts++) {
805 if (rts->rts_metric != HOPCNT_INFINITY) {
806 (void)fprintf(ftrace,"\n #%d%15s%-16s metric=%-2d ",
807 i, "", naddr_ntoa(rts->rts_gate),
808 rts->rts_metric);
809 if (rts->rts_router != rts->rts_gate)
810 (void)fprintf(ftrace, "router=%s ",
811 naddr_ntoa(rts->rts_router));
812 if (rts->rts_tag != 0)
813 (void)fprintf(ftrace, "tag=%#x ",
814 ntohs(rts->rts_tag));
815 (void)fprintf(ftrace, "%s ",
816 (rts->rts_ifp == 0
817 ? "?" : rts->rts_ifp->int_name));
818 if (age)
819 (void)fprintf(ftrace, "%s", ts(rts->rts_time));
844 if (rts->rts_gate != RIP_DEFAULT) {
845 (void)fprintf(ftrace,"\n #%d%15s%-16s ",
846 i, "", naddr_ntoa(rts->rts_gate));
847 print_rts(rts, 0,0,0,0,1);
820 }
821 }
822 (void)fputc('\n',ftrace);
823
824 return 0;
825}
826
827
828static void
829trace_dump(void)
830{
831 struct interface *ifp;
832
833 if (ftrace == 0)
834 return;
835 lastlog();
836
848 }
849 }
850 (void)fputc('\n',ftrace);
851
852 return 0;
853}
854
855
856static void
857trace_dump(void)
858{
859 struct interface *ifp;
860
861 if (ftrace == 0)
862 return;
863 lastlog();
864
865 (void)fputs("current daemon state:\n", ftrace);
837 for (ifp = ifnet; ifp != 0; ifp = ifp->int_next)
838 trace_if("", ifp);
839 (void)rn_walktree(rhead, walk_trace, 0);
840}
841
842
843void
844trace_rip(char *dir1, char *dir2,

--- 126 unchanged lines hidden (view full) ---

971 (void)fputc('\n',ftrace);
972 }
973 if (size != (char *)n - (char *)msg)
974 (void)fprintf(ftrace, "truncated record, len %d\n",
975 size);
976 break;
977
978 case RIPCMD_TRACEON:
866 for (ifp = ifnet; ifp != 0; ifp = ifp->int_next)
867 trace_if("", ifp);
868 (void)rn_walktree(rhead, walk_trace, 0);
869}
870
871
872void
873trace_rip(char *dir1, char *dir2,

--- 126 unchanged lines hidden (view full) ---

1000 (void)fputc('\n',ftrace);
1001 }
1002 if (size != (char *)n - (char *)msg)
1003 (void)fprintf(ftrace, "truncated record, len %d\n",
1004 size);
1005 break;
1006
1007 case RIPCMD_TRACEON:
979 fprintf(ftrace, "\tfile=%*s\n", size-4, msg->rip_tracefile);
1008 fprintf(ftrace, "\tfile=\"%.*s\"\n", size-4,
1009 msg->rip_tracefile);
980 break;
981
982 case RIPCMD_TRACEOFF:
983 break;
984 }
985}
1010 break;
1011
1012 case RIPCMD_TRACEOFF:
1013 break;
1014 }
1015}