1 /* $NetBSD: trace.c,v 1.31 2006/03/22 02:23:11 christos Exp $ */
4 * Copyright (c) 1983, 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgment:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include "pathnames.h"
40 #include <sys/signal.h>
44 __RCSID("$NetBSD: trace.c,v 1.31 2006/03/22 02:23:11 christos Exp $");
45 #elif defined(__FreeBSD__)
48 __RCSID("Revision: 2.27 ");
49 #ident "Revision: 2.27 "
54 /* use *stat64 for files on large filesystems */
58 #define NRECORDS 50 /* size of circular trace buffer */
60 int tracelevel
, new_tracelevel
;
61 FILE *ftrace
= stdout
; /* output trace file */
62 static const char *sigtrace_pat
= "%s";
63 static char savetracename
[MAXPATHLEN
+1];
64 char inittracename
[MAXPATHLEN
+1];
65 int file_trace
; /* 1=tracing to file, not stdout */
67 static void trace_dump(void);
68 static void tmsg(const char *, ...) PATTRIB(1,2);
71 /* convert string to printable characters
74 qstring(u_char
*s
, int len
)
76 static char buf
[8*20+1];
81 for (p
= buf
; len
!= 0 && p
< &buf
[sizeof(buf
)-1]; len
--) {
84 for (s2
= s
+1; s2
< &s
[len
]; s2
++) {
92 if (c
>= ' ' && c
< 0x7f && c
!= '\\') {
114 n
= snprintf(p
, sizeof(buf
) - (p
- buf
), "%o", c
);
127 /* convert IP address to a string, but not into a single buffer
135 char str
[16]; /* xxx.xxx.xxx.xxx\0 */
141 strlcpy(bufs
[bufno
].str
, inet_ntoa(addr
), sizeof(bufs
[bufno
].str
));
143 bufno
= (bufno
+1) % NUM_BUFS
;
150 saddr_ntoa(const struct sockaddr
*sa
)
152 return (sa
== 0) ? "?" : naddr_ntoa(S_ADDR(sa
));
160 secs
+= epoch
.tv_sec
;
162 (void)cftime(s
, "%T", &secs
);
164 memcpy(s
, ctime(&secs
)+11, 8);
171 /* On each event, display a time stamp.
172 * This assumes that 'now' is update once for each event, and
173 * that at least now.tv_usec changes.
175 static struct timeval lastlog_time
;
180 if (lastlog_time
.tv_sec
!= now
.tv_sec
181 || lastlog_time
.tv_usec
!= now
.tv_usec
) {
182 (void)fprintf(ftrace
, "-- %s --\n", ts(now
.tv_sec
));
189 tmsg(const char *p
, ...)
196 vfprintf(ftrace
, p
, args
);
198 (void)fputc('\n',ftrace
);
205 trace_close(int zap_stdio
)
213 if (ftrace
!= 0 && zap_stdio
) {
214 if (ftrace
!= stdout
)
217 fd
= open(_PATH_DEVNULL
, O_RDWR
);
220 if (isatty(STDIN_FILENO
))
221 (void)dup2(fd
, STDIN_FILENO
);
222 if (isatty(STDOUT_FILENO
))
223 (void)dup2(fd
, STDOUT_FILENO
);
224 if (isatty(STDERR_FILENO
))
225 (void)dup2(fd
, STDERR_FILENO
);
228 lastlog_time
.tv_sec
= 0;
238 trace_off("tracing off: %s", strerror(ferror(ftrace
)));
244 trace_off(const char *p
, ...)
252 vfprintf(ftrace
, p
, args
);
254 (void)fputc('\n',ftrace
);
256 trace_close(file_trace
);
258 new_tracelevel
= tracelevel
= 0;
262 /* log a change in tracing
265 tracelevel_msg(const char *pat
,
266 int dump
) /* -1=no dump, 0=default, 1=force */
268 static const char *off_msgs
[MAX_TRACELEVEL
] = {
269 "Tracing actions stopped",
270 "Tracing packets stopped",
271 "Tracing packet contents stopped",
272 "Tracing kernel changes stopped",
274 static const char *on_msgs
[MAX_TRACELEVEL
] = {
275 "Tracing actions started",
276 "Tracing packets started",
277 "Tracing packet contents started",
278 "Tracing kernel changes started",
280 u_int old_tracelevel
= tracelevel
;
283 if (new_tracelevel
< 0)
285 else if (new_tracelevel
> MAX_TRACELEVEL
)
286 new_tracelevel
= MAX_TRACELEVEL
;
288 if (new_tracelevel
< tracelevel
) {
289 if (new_tracelevel
<= 0) {
290 trace_off(pat
, off_msgs
[0]);
292 tmsg(pat
, off_msgs
[tracelevel
]);
294 while (--tracelevel
!= new_tracelevel
);
296 } else if (new_tracelevel
> tracelevel
) {
298 tmsg(pat
, on_msgs
[tracelevel
++]);
299 } while (tracelevel
!= new_tracelevel
);
303 || (dump
== 0 && old_tracelevel
== 0 && tracelevel
!= 0))
309 set_tracefile(const char *filename
,
311 int dump
) /* -1=no dump, 0=default, 1=force */
318 /* Allow a null filename to increase the level if the trace file
319 * is already open or if coming from a trusted source, such as
320 * a signal or the command line.
322 if (filename
== 0 || filename
[0] == '\0') {
325 if (inittracename
[0] == '\0') {
326 msglog("missing trace file name");
334 } else if (!strcmp(filename
,"dump/../table")) {
339 /* Allow the file specified with "-T file" to be reopened,
340 * but require all other names specified over the net to
341 * match the official path. The path can specify a directory
342 * in which the file is to be created.
344 if (strcmp(filename
, inittracename
)
346 && (strncmp(filename
, _PATH_TRACE
, sizeof(_PATH_TRACE
)-1)
347 || strstr(filename
,"../")
348 || 0 > stat(_PATH_TRACE
, &stbuf
))
351 msglog("wrong trace file \"%s\"", filename
);
355 /* If the new tracefile exists, it must be a regular file.
357 if (stat(filename
, &stbuf
) >= 0 && !S_ISREG(stbuf
.st_mode
)) {
358 msglog("wrong type (%#x) of trace file \"%s\"",
359 stbuf
.st_mode
, filename
);
367 n_ftrace
= fopen(fn
, "a");
369 msglog("failed to open trace file \"%s\" %s",
370 fn
, strerror(errno
));
371 if (fn
== inittracename
)
372 inittracename
[0] = '\0';
376 tmsg("switch to trace file %s", fn
);
378 trace_close(file_trace
= 1);
380 if (fn
!= savetracename
)
381 strlcpy(savetracename
, fn
, sizeof(savetracename
));
386 dup2(fileno(ftrace
), STDOUT_FILENO
);
387 dup2(fileno(ftrace
), STDERR_FILENO
);
390 if (new_tracelevel
== 0 || filename
== 0)
392 tracelevel_msg(pat
, dump
!= 0 ? dump
: (filename
!= 0));
398 sigtrace_on(int s UNUSED
)
401 sigtrace_pat
= "SIGUSR1: %s";
407 sigtrace_off(int s UNUSED
)
410 sigtrace_pat
= "SIGUSR2: %s";
414 /* Set tracing after a signal.
419 if (new_tracelevel
== tracelevel
)
422 /* If tracing entirely off, and there was no tracefile specified
423 * on the command line, then leave it off.
425 if (new_tracelevel
> tracelevel
&& ftrace
== 0) {
426 if (savetracename
[0] != '\0') {
427 set_tracefile(savetracename
,sigtrace_pat
,0);
428 } else if (inittracename
[0] != '\0') {
429 set_tracefile(inittracename
,sigtrace_pat
,0);
435 tracelevel_msg(sigtrace_pat
, 0);
440 /* display an address
443 addrname(naddr addr
, /* in network byte order */
445 int force
) /* 0=show mask if nonstandard, */
446 { /* 1=always show mask, 2=never */
457 strlcpy(bufs
[bufno
].str
, naddr_ntoa(addr
), sizeof(bufs
[bufno
].str
));
459 l
= sizeof(bufs
[bufno
].str
);
460 bufno
= (bufno
+1) % NUM_BUFS
;
462 if (force
== 1 || (force
== 0 && mask
!= std_mask(addr
))) {
465 dmask
= mask
& -mask
;
466 if (mask
+ dmask
== 0) {
467 for (i
= 0; i
!= 32 && ((1<<i
) & mask
) == 0; i
++)
469 (void)snprintf(sp
, s
+ l
- sp
, "/%d", 32-i
);
472 (void)snprintf(sp
, s
+ l
- sp
, " (mask %#x)",
482 /* display a bit-field
487 const char *bits_name
;
490 static struct bits if_bits
[] = {
491 { IFF_LOOPBACK
, 0, "LOOPBACK" },
492 { IFF_POINTOPOINT
, 0, "PT-TO-PT" },
496 static struct bits is_bits
[] = {
497 { IS_ALIAS
, 0, "ALIAS" },
498 { IS_SUBNET
, 0, "" },
499 { IS_REMOTE
, (IS_NO_RDISC
500 | IS_BCAST_RDISC
), "REMOTE" },
501 { IS_PASSIVE
, (IS_NO_RDISC
505 | IS_NO_AG
), "PASSIVE" },
506 { IS_EXTERNAL
, 0, "EXTERNAL" },
507 { IS_CHECKED
, 0, "" },
508 { IS_ALL_HOSTS
, 0, "" },
509 { IS_ALL_ROUTERS
, 0, "" },
510 { IS_DISTRUST
, 0, "DISTRUST" },
511 { IS_BROKE
, IS_SICK
, "BROKEN" },
512 { IS_SICK
, 0, "SICK" },
513 { IS_DUP
, 0, "DUPLICATE" },
514 { IS_REDIRECT_OK
, 0, "REDIRECT_OK" },
515 { IS_NEED_NET_SYN
, 0, "" },
516 { IS_NO_AG
, IS_NO_SUPER_AG
, "NO_AG" },
517 { IS_NO_SUPER_AG
, 0, "NO_SUPER_AG" },
521 | IS_NO_RIPV2_OUT
), 0, "NO_RIP" },
523 | IS_NO_RIPV1_OUT
), 0, "RIPV2" },
524 { IS_NO_RIPV1_IN
, 0, "NO_RIPV1_IN" },
525 { IS_NO_RIPV2_IN
, 0, "NO_RIPV2_IN" },
526 { IS_NO_RIPV1_OUT
, 0, "NO_RIPV1_OUT" },
527 { IS_NO_RIPV2_OUT
, 0, "NO_RIPV2_OUT" },
530 | IS_NO_ADV_OUT
), IS_BCAST_RDISC
, "NO_RDISC" },
531 { IS_NO_SOL_OUT
, 0, "NO_SOLICIT" },
532 { IS_SOL_OUT
, 0, "SEND_SOLICIT" },
533 { IS_NO_ADV_OUT
, IS_BCAST_RDISC
, "NO_RDISC_ADV" },
534 { IS_ADV_OUT
, 0, "RDISC_ADV" },
535 { IS_BCAST_RDISC
, 0, "BCAST_RDISC" },
536 { IS_PM_RDISC
, 0, "" },
540 static struct bits rs_bits
[] = {
542 { RS_NET_INT
, RS_NET_SYN
, "NET_INT" },
543 { RS_NET_SYN
, 0, "NET_SYN" },
544 { RS_SUBNET
, 0, "" },
545 { RS_LOCAL
, 0, "LOCAL" },
546 { RS_MHOME
, 0, "MHOME" },
547 { RS_STATIC
, 0, "STATIC" },
548 { RS_RDISC
, 0, "RDISC" },
554 trace_bits(const struct bits
*tbl
,
562 (void)putc('<', ftrace
);
569 && (b
= tbl
->bits_mask
) != 0) {
570 if ((b
& field
) == b
) {
571 if (tbl
->bits_name
[0] != '\0') {
573 (void)putc(c
, ftrace
);
574 (void)fprintf(ftrace
, "%s", tbl
->bits_name
);
577 if (0 == (field
&= ~(b
| tbl
->bits_clear
)))
582 if (field
!= 0 && tbl
->bits_name
!= 0) {
584 (void)putc(c
, ftrace
);
585 (void)fprintf(ftrace
, tbl
->bits_name
, field
);
589 if (c
!= '<' || force
)
590 (void)fputs("> ", ftrace
);
599 static char buf
[3*4+3+1+2+3 /* "xxx.xxx.xxx.xxx/xx-->" */
600 +3*4+3+1]; /* "xxx.xxx.xxx.xxx" */
603 i
= snprintf(buf
, sizeof(buf
), "%-16s-->", addrname(dst
, mask
, 0));
604 if (i
< 0 || (size_t)i
>= sizeof(buf
))
606 (void)snprintf(&buf
[i
], sizeof(buf
) - i
, "%-*s", 15+20-MAX(20, i
),
613 print_rts(struct rt_spare
*rts
,
614 int force_metric
, /* -1=suppress, 0=default */
615 int force_ifp
, /* -1=suppress, 0=default */
616 int force_router
, /* -1=suppress, 0=default, 1=display */
617 int force_tag
, /* -1=suppress, 0=default, 1=display */
618 int force_time
) /* 0=suppress, 1=display */
623 if (force_metric
>= 0)
624 (void)fprintf(ftrace
, "metric=%-2d ", rts
->rts_metric
);
626 (void)fprintf(ftrace
, "%s ", (rts
->rts_ifp
== 0 ?
627 "if?" : rts
->rts_ifp
->int_name
));
629 || (force_router
== 0 && rts
->rts_router
!= rts
->rts_gate
))
630 (void)fprintf(ftrace
, "router=%s ",
631 naddr_ntoa(rts
->rts_router
));
633 (void)fprintf(ftrace
, "%s ", ts(rts
->rts_time
));
635 || (force_tag
== 0 && rts
->rts_tag
!= 0))
636 (void)fprintf(ftrace
, "tag=%#x ", ntohs(rts
->rts_tag
));
637 if (rts
->rts_de_ag
!= 0) {
638 for (i
= 1; (u_int
)(1 << i
) <= rts
->rts_de_ag
; i
++)
640 (void)fprintf(ftrace
, "de_ag=%d ", i
);
647 trace_if(const char *act
,
648 struct interface
*ifp
)
650 if (!TRACEACTIONS
|| ftrace
== 0)
654 (void)fprintf(ftrace
, "%-3s interface %-4s ", act
, ifp
->int_name
);
655 (void)fprintf(ftrace
, "%-15s-->%-15s ",
656 naddr_ntoa(ifp
->int_addr
),
657 addrname(((ifp
->int_if_flags
& IFF_POINTOPOINT
)
659 : htonl(ifp
->int_net
)),
661 if (ifp
->int_metric
!= 0)
662 (void)fprintf(ftrace
, "metric=%d ", ifp
->int_metric
);
663 if (ifp
->int_adj_inmetric
!= 0)
664 (void)fprintf(ftrace
, "adj_inmetric=%u ",
665 ifp
->int_adj_inmetric
);
666 if (ifp
->int_adj_outmetric
!= 0)
667 (void)fprintf(ftrace
, "adj_outmetric=%u ",
668 ifp
->int_adj_outmetric
);
669 if (!IS_RIP_OUT_OFF(ifp
->int_state
)
670 && ifp
->int_d_metric
!= 0)
671 (void)fprintf(ftrace
, "fake_default=%u ", ifp
->int_d_metric
);
672 trace_bits(if_bits
, ifp
->int_if_flags
, 0);
673 trace_bits(is_bits
, ifp
->int_state
, 0);
674 (void)fputc('\n',ftrace
);
679 trace_upslot(struct rt_entry
*rt
,
680 struct rt_spare
*rts
,
681 struct rt_spare
*new)
683 if (!TRACEACTIONS
|| ftrace
== 0)
686 if (rts
->rts_gate
== new->rts_gate
687 && rts
->rts_router
== new->rts_router
688 && rts
->rts_metric
== new->rts_metric
689 && rts
->rts_tag
== new->rts_tag
690 && rts
->rts_de_ag
== new->rts_de_ag
)
694 if (new->rts_gate
== 0) {
695 (void)fprintf(ftrace
, "Del #%d %-35s ",
696 (int)(rts
- rt
->rt_spares
),
697 rtname(rt
->rt_dst
, rt
->rt_mask
, rts
->rts_gate
));
698 print_rts(rts
, 0,0,0,0,
699 (rts
!= rt
->rt_spares
700 || AGE_RT(rt
->rt_state
,new->rts_ifp
)));
702 } else if (rts
->rts_gate
!= RIP_DEFAULT
) {
703 (void)fprintf(ftrace
, "Chg #%d %-35s ",
704 (int)(rts
- rt
->rt_spares
),
705 rtname(rt
->rt_dst
, rt
->rt_mask
, rts
->rts_gate
));
707 rts
->rts_gate
!= new->rts_gate
,
708 rts
->rts_tag
!= new->rts_tag
,
709 rts
!= rt
->rt_spares
|| AGE_RT(rt
->rt_state
,
712 (void)fprintf(ftrace
, "\n %19s%-16s ", "",
713 (new->rts_gate
!= rts
->rts_gate
714 ? naddr_ntoa(new->rts_gate
) : ""));
716 -(new->rts_metric
== rts
->rts_metric
),
717 -(new->rts_ifp
== rts
->rts_ifp
),
719 rts
->rts_tag
!= new->rts_tag
,
720 (new->rts_time
!= rts
->rts_time
721 && (rts
!= rt
->rt_spares
722 || AGE_RT(rt
->rt_state
, new->rts_ifp
))));
725 (void)fprintf(ftrace
, "Add #%d %-35s ",
726 (int)(rts
- rt
->rt_spares
),
727 rtname(rt
->rt_dst
, rt
->rt_mask
, new->rts_gate
));
728 print_rts(new, 0,0,0,0,
729 (rts
!= rt
->rt_spares
730 || AGE_RT(rt
->rt_state
,new->rts_ifp
)));
732 (void)fputc('\n',ftrace
);
736 /* miscellaneous message checked by the caller
739 trace_misc(const char *p
, ...)
748 vfprintf(ftrace
, p
, args
);
750 (void)fputc('\n',ftrace
);
754 /* display a message if tracing actions
757 trace_act(const char *p
, ...)
761 if (!TRACEACTIONS
|| ftrace
== 0)
766 vfprintf(ftrace
, p
, args
);
768 (void)fputc('\n',ftrace
);
772 /* display a message if tracing packets
775 trace_pkt(const char *p
, ...)
779 if (!TRACEPACKETS
|| ftrace
== 0)
784 vfprintf(ftrace
, p
, args
);
786 (void)fputc('\n',ftrace
);
791 trace_change(struct rt_entry
*rt
,
793 struct rt_spare
*new,
799 if (rt
->rt_metric
== new->rts_metric
800 && rt
->rt_gate
== new->rts_gate
801 && rt
->rt_router
== new->rts_router
802 && rt
->rt_state
== state
803 && rt
->rt_tag
== new->rts_tag
804 && rt
->rt_de_ag
== new->rts_de_ag
)
808 (void)fprintf(ftrace
, "%s %-35s ",
810 rtname(rt
->rt_dst
, rt
->rt_mask
, rt
->rt_gate
));
811 print_rts(rt
->rt_spares
,
812 0,0,0,0, AGE_RT(rt
->rt_state
, rt
->rt_ifp
));
813 trace_bits(rs_bits
, rt
->rt_state
, rt
->rt_state
!= state
);
815 (void)fprintf(ftrace
, "\n%*s %19s%-16s ",
816 (int)strlen(label
), "", "",
817 (rt
->rt_gate
!= new->rts_gate
818 ? naddr_ntoa(new->rts_gate
) : ""));
820 -(new->rts_metric
== rt
->rt_metric
),
821 -(new->rts_ifp
== rt
->rt_ifp
),
823 rt
->rt_tag
!= new->rts_tag
,
824 (rt
->rt_time
!= new->rts_time
825 && AGE_RT(rt
->rt_state
,new->rts_ifp
)));
826 if (rt
->rt_state
!= state
)
827 trace_bits(rs_bits
, state
, 1);
828 (void)fputc('\n',ftrace
);
833 trace_add_del(const char * action
, struct rt_entry
*rt
)
839 (void)fprintf(ftrace
, "%s %-35s ",
841 rtname(rt
->rt_dst
, rt
->rt_mask
, rt
->rt_gate
));
842 print_rts(rt
->rt_spares
, 0,0,0,0,AGE_RT(rt
->rt_state
,rt
->rt_ifp
));
843 trace_bits(rs_bits
, rt
->rt_state
, 0);
844 (void)fputc('\n',ftrace
);
850 walk_trace(struct radix_node
*rn
,
851 struct walkarg
*w UNUSED
)
853 #define RT ((struct rt_entry *)rn)
854 struct rt_spare
*rts
;
857 (void)fprintf(ftrace
, " %-35s ",
858 rtname(RT
->rt_dst
, RT
->rt_mask
, RT
->rt_gate
));
859 print_rts(&RT
->rt_spares
[0], 0,0,0,0, AGE_RT(RT
->rt_state
, RT
->rt_ifp
));
860 trace_bits(rs_bits
, RT
->rt_state
, 0);
861 if (RT
->rt_poison_time
>= now_garbage
862 && RT
->rt_poison_metric
< RT
->rt_metric
)
863 (void)fprintf(ftrace
, "pm=%d@%s",
864 RT
->rt_poison_metric
, ts(RT
->rt_poison_time
));
866 rts
= &RT
->rt_spares
[1];
867 for (i
= 1; i
< NUM_SPARES
; i
++, rts
++) {
868 if (rts
->rts_gate
!= RIP_DEFAULT
) {
869 (void)fprintf(ftrace
,"\n #%d%15s%-16s ",
870 i
, "", naddr_ntoa(rts
->rts_gate
));
871 print_rts(rts
, 0,0,0,0,1);
874 (void)fputc('\n',ftrace
);
883 struct interface
*ifp
;
889 (void)fputs("current daemon state:\n", ftrace
);
890 for (ifp
= ifnet
; ifp
!= 0; ifp
= ifp
->int_next
)
892 (void)rn_walktree(rhead
, walk_trace
, 0);
897 trace_rip(const char *dir1
, const char *dir2
,
898 struct sockaddr_in
*who
,
899 struct interface
*ifp
,
901 int size
) /* total size of message */
903 struct netinfo
*n
, *lim
;
904 # define NA ((struct netauth*)n)
907 if (!TRACEPACKETS
|| ftrace
== 0)
911 if (msg
->rip_cmd
>= RIPCMD_MAX
912 || msg
->rip_vers
== 0) {
913 (void)fprintf(ftrace
, "%s bad RIPv%d cmd=%d %s"
915 dir1
, msg
->rip_vers
, msg
->rip_cmd
, dir2
,
916 naddr_ntoa(who
->sin_addr
.s_addr
),
917 ntohs(who
->sin_port
),
922 (void)fprintf(ftrace
, "%s RIPv%d %s %s %s.%d%s%s\n",
923 dir1
, msg
->rip_vers
, ripcmds
[msg
->rip_cmd
], dir2
,
924 naddr_ntoa(who
->sin_addr
.s_addr
), ntohs(who
->sin_port
),
925 ifp
? " via " : "", ifp
? ifp
->int_name
: "");
930 switch (msg
->rip_cmd
) {
932 case RIPCMD_RESPONSE
:
934 lim
= (struct netinfo
*)((char*)msg
+ size
);
935 for (; n
< lim
; n
++) {
937 && n
->n_family
== RIP_AF_UNSPEC
938 && ntohl(n
->n_metric
) == HOPCNT_INFINITY
939 && msg
->rip_cmd
== RIPCMD_REQUEST
942 && (n
+1)->n_family
== RIP_AF_AUTH
))) {
943 (void)fputs("\tQUERY ", ftrace
);
945 (void)fprintf(ftrace
, "%s ",
946 naddr_ntoa(n
->n_dst
));
948 (void)fprintf(ftrace
, "mask=%#x ",
949 (u_int
)ntohl(n
->n_mask
));
951 (void)fprintf(ftrace
, "nhop=%s ",
952 naddr_ntoa(n
->n_nhop
));
954 (void)fprintf(ftrace
, "tag=%#x ",
956 (void)fputc('\n',ftrace
);
960 if (n
->n_family
== RIP_AF_AUTH
) {
961 if (NA
->a_type
== RIP_AUTH_PW
962 && n
== msg
->rip_nets
) {
963 (void)fprintf(ftrace
, "\tPassword"
966 qstring(NA
->au
.au_pw
,
971 if (NA
->a_type
== RIP_AUTH_MD5
972 && n
== msg
->rip_nets
) {
973 (void)fprintf(ftrace
,
975 " pkt_len=%d KeyID=%u"
979 ntohs(NA
->au
.a_md5
.md5_pkt_len
),
980 NA
->au
.a_md5
.md5_keyid
,
981 NA
->au
.a_md5
.md5_auth_len
,
982 (int)ntohl(NA
->au
.a_md5
.md5_seqno
),
983 (int)ntohs(NA
->au
.a_md5
.rsvd
[0]),
984 (int)ntohs(NA
->au
.a_md5
.rsvd
[1]));
987 (void)fprintf(ftrace
,
988 "\tAuthentication type %d: ",
991 i
< (int)sizeof(NA
->au
.au_pw
);
993 (void)fprintf(ftrace
, "%02x ",
995 (void)fputc('\n',ftrace
);
1000 if (n
->n_family
!= RIP_AF_INET
) {
1001 (void)fprintf(ftrace
,
1002 "\t(af %d) %-18s mask=%#x ",
1004 naddr_ntoa(n
->n_dst
),
1005 (u_int
)ntohl(n
->n_mask
));
1006 } else if (msg
->rip_vers
== RIPv1
) {
1007 (void)fprintf(ftrace
, "\t%-18s ",
1010 n
->n_mask
==0 ? 2 : 1));
1012 (void)fprintf(ftrace
, "\t%-18s ",
1015 n
->n_mask
==0 ? 2 : 0));
1017 (void)fprintf(ftrace
, "metric=%-2d ",
1018 (u_int
)ntohl(n
->n_metric
));
1020 (void)fprintf(ftrace
, " nhop=%s ",
1021 naddr_ntoa(n
->n_nhop
));
1023 (void)fprintf(ftrace
, "tag=%#x",
1025 (void)fputc('\n',ftrace
);
1027 if (size
!= (char *)n
- (char *)msg
)
1028 (void)fprintf(ftrace
, "truncated record, len %d\n",
1032 case RIPCMD_TRACEON
:
1033 fprintf(ftrace
, "\tfile=\"%.*s\"\n", size
-4,
1034 msg
->rip_tracefile
);
1037 case RIPCMD_TRACEOFF
: