2 * Copyright (c) 1983, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgment:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * $FreeBSD: src/sbin/routed/trace.c,v 1.5.2.1 2002/11/07 17:19:13 imp Exp $
34 * $DragonFly: src/sbin/routed/trace.c,v 1.3 2004/12/18 21:43:40 swildner Exp $
39 #include "pathnames.h"
41 #include <sys/signal.h>
44 #if !defined(sgi) && !defined(__NetBSD__)
45 static char sccsid
[] __attribute__((unused
)) = "@(#)trace.c 8.1 (Berkeley) 6/5/93";
46 #elif defined(__NetBSD__)
49 #ident "$FreeBSD: src/sbin/routed/trace.c,v 1.5.2.1 2002/11/07 17:19:13 imp Exp $"
53 /* use *stat64 for files on large filesystems */
57 #define NRECORDS 50 /* size of circular trace buffer */
59 int tracelevel
, new_tracelevel
;
60 FILE *ftrace
; /* output trace file */
61 static const char *sigtrace_pat
= "%s";
62 static char savetracename
[MAXPATHLEN
+1];
63 char inittracename
[MAXPATHLEN
+1];
64 int file_trace
; /* 1=tracing to file, not stdout */
66 static void trace_dump(void);
67 static void tmsg(const char *, ...) PATTRIB(1,2);
70 /* convert string to printable characters
73 qstring(u_char
*s
, int len
)
75 static char buf
[8*20+1];
80 for (p
= buf
; len
!= 0 && p
< &buf
[sizeof(buf
)-1]; len
--) {
83 for (s2
= s
+1; s2
< &s
[len
]; s2
++) {
91 if (c
>= ' ' && c
< 0x7f && c
!= '\\') {
113 p
+= sprintf(p
,"%o",c
);
123 /* convert IP address to a string, but not into a single buffer
131 char str
[16]; /* xxx.xxx.xxx.xxx\0 */
137 s
= strcpy(bufs
[bufno
].str
, inet_ntoa(addr
));
138 bufno
= (bufno
+1) % NUM_BUFS
;
145 saddr_ntoa(struct sockaddr
*sa
)
147 return (sa
== 0) ? "?" : naddr_ntoa(S_ADDR(sa
));
155 secs
+= epoch
.tv_sec
;
157 cftime(s
, "%T", &secs
);
159 memcpy(s
, ctime(&secs
)+11, 8);
166 /* On each event, display a time stamp.
167 * This assumes that 'now' is update once for each event, and
168 * that at least now.tv_usec changes.
170 static struct timeval lastlog_time
;
175 if (lastlog_time
.tv_sec
!= now
.tv_sec
176 || lastlog_time
.tv_usec
!= now
.tv_usec
) {
177 fprintf(ftrace
, "-- %s --\n", ts(now
.tv_sec
));
184 tmsg(const char *p
, ...)
191 vfprintf(ftrace
, p
, args
);
199 trace_close(int zap_stdio
)
207 if (ftrace
!= 0 && zap_stdio
) {
208 if (ftrace
!= stdout
)
211 fd
= open(_PATH_DEVNULL
, O_RDWR
);
212 if (isatty(STDIN_FILENO
))
213 dup2(fd
, STDIN_FILENO
);
214 if (isatty(STDOUT_FILENO
))
215 dup2(fd
, STDOUT_FILENO
);
216 if (isatty(STDERR_FILENO
))
217 dup2(fd
, STDERR_FILENO
);
220 lastlog_time
.tv_sec
= 0;
230 trace_off("tracing off: %s", strerror(ferror(ftrace
)));
236 trace_off(const char *p
, ...)
244 vfprintf(ftrace
, p
, args
);
247 trace_close(file_trace
);
249 new_tracelevel
= tracelevel
= 0;
253 /* log a change in tracing
256 tracelevel_msg(const char *pat
,
257 int dump
) /* -1=no dump, 0=default, 1=force */
259 static const char *off_msgs
[MAX_TRACELEVEL
] = {
260 "Tracing actions stopped",
261 "Tracing packets stopped",
262 "Tracing packet contents stopped",
263 "Tracing kernel changes stopped",
265 static const char *on_msgs
[MAX_TRACELEVEL
] = {
266 "Tracing actions started",
267 "Tracing packets started",
268 "Tracing packet contents started",
269 "Tracing kernel changes started",
271 u_int old_tracelevel
= tracelevel
;
274 if (new_tracelevel
< 0)
276 else if (new_tracelevel
> MAX_TRACELEVEL
)
277 new_tracelevel
= MAX_TRACELEVEL
;
279 if (new_tracelevel
< tracelevel
) {
280 if (new_tracelevel
<= 0) {
281 trace_off(pat
, off_msgs
[0]);
283 tmsg(pat
, off_msgs
[tracelevel
]);
285 while (--tracelevel
!= new_tracelevel
);
287 } else if (new_tracelevel
> tracelevel
) {
289 tmsg(pat
, on_msgs
[tracelevel
++]);
290 } while (tracelevel
!= new_tracelevel
);
294 || (dump
== 0 && old_tracelevel
== 0 && tracelevel
!= 0))
300 set_tracefile(const char *filename
,
302 int dump
) /* -1=no dump, 0=default, 1=force */
309 /* Allow a null filename to increase the level if the trace file
310 * is already open or if coming from a trusted source, such as
311 * a signal or the command line.
313 if (filename
== 0 || filename
[0] == '\0') {
316 if (inittracename
[0] == '\0') {
317 msglog("missing trace file name");
325 } else if (!strcmp(filename
,"dump/../table")) {
330 /* Allow the file specified with "-T file" to be reopened,
331 * but require all other names specified over the net to
332 * match the official path. The path can specify a directory
333 * in which the file is to be created.
335 if (strcmp(filename
, inittracename
)
337 && (strncmp(filename
, _PATH_TRACE
, sizeof(_PATH_TRACE
)-1)
338 || strstr(filename
,"../")
339 || 0 > stat(_PATH_TRACE
, &stbuf
))
342 msglog("wrong trace file \"%s\"", filename
);
346 /* If the new tracefile exists, it must be a regular file.
348 if (stat(filename
, &stbuf
) >= 0 && !S_ISREG(stbuf
.st_mode
)) {
349 msglog("wrong type (%#x) of trace file \"%s\"",
350 stbuf
.st_mode
, filename
);
358 n_ftrace
= fopen(fn
, "a");
360 msglog("failed to open trace file \"%s\" %s",
361 fn
, strerror(errno
));
362 if (fn
== inittracename
)
363 inittracename
[0] = '\0';
367 tmsg("switch to trace file %s", fn
);
369 trace_close(file_trace
= 1);
371 if (fn
!= savetracename
)
372 strncpy(savetracename
, fn
, sizeof(savetracename
)-1);
377 dup2(fileno(ftrace
), STDOUT_FILENO
);
378 dup2(fileno(ftrace
), STDERR_FILENO
);
381 if (new_tracelevel
== 0 || filename
== 0)
383 tracelevel_msg(pat
, dump
!= 0 ? dump
: (filename
!= 0));
389 sigtrace_on(int s UNUSED
)
392 sigtrace_pat
= "SIGUSR1: %s";
398 sigtrace_off(int s UNUSED
)
401 sigtrace_pat
= "SIGUSR2: %s";
405 /* Set tracing after a signal.
410 if (new_tracelevel
== tracelevel
)
413 /* If tracing entirely off, and there was no tracefile specified
414 * on the command line, then leave it off.
416 if (new_tracelevel
> tracelevel
&& ftrace
== 0) {
417 if (savetracename
[0] != '\0') {
418 set_tracefile(savetracename
,sigtrace_pat
,0);
419 } else if (inittracename
[0] != '\0') {
420 set_tracefile(inittracename
,sigtrace_pat
,0);
426 tracelevel_msg(sigtrace_pat
, 0);
431 /* display an address
434 addrname(naddr addr
, /* in network byte order */
436 int force
) /* 0=show mask if nonstandard, */
437 { /* 1=always show mask, 2=never */
447 s
= strcpy(bufs
[bufno
].str
, naddr_ntoa(addr
));
448 bufno
= (bufno
+1) % NUM_BUFS
;
450 if (force
== 1 || (force
== 0 && mask
!= std_mask(addr
))) {
453 dmask
= mask
& -mask
;
454 if (mask
+ dmask
== 0) {
455 for (i
= 0; i
!= 32 && ((1<<i
) & mask
) == 0; i
++)
457 sprintf(sp
, "/%d", 32-i
);
460 sprintf(sp
, " (mask %#x)", (u_int
)mask
);
469 /* display a bit-field
474 const char *bits_name
;
477 static struct bits if_bits
[] = {
478 { IFF_LOOPBACK
, 0, "LOOPBACK" },
479 { IFF_POINTOPOINT
, 0, "PT-TO-PT" },
483 static struct bits is_bits
[] = {
484 { IS_ALIAS
, 0, "ALIAS" },
485 { IS_SUBNET
, 0, "" },
486 { IS_REMOTE
, (IS_NO_RDISC
487 | IS_BCAST_RDISC
), "REMOTE" },
488 { IS_PASSIVE
, (IS_NO_RDISC
492 | IS_NO_AG
), "PASSIVE" },
493 { IS_EXTERNAL
, 0, "EXTERNAL" },
494 { IS_CHECKED
, 0, "" },
495 { IS_ALL_HOSTS
, 0, "" },
496 { IS_ALL_ROUTERS
, 0, "" },
497 { IS_DISTRUST
, 0, "DISTRUST" },
498 { IS_BROKE
, IS_SICK
, "BROKEN" },
499 { IS_SICK
, 0, "SICK" },
500 { IS_DUP
, 0, "DUPLICATE" },
501 { IS_REDIRECT_OK
, 0, "REDIRECT_OK" },
502 { IS_NEED_NET_SYN
, 0, "" },
503 { IS_NO_AG
, IS_NO_SUPER_AG
, "NO_AG" },
504 { IS_NO_SUPER_AG
, 0, "NO_SUPER_AG" },
508 | IS_NO_RIPV2_OUT
), 0, "NO_RIP" },
510 | IS_NO_RIPV1_OUT
), 0, "RIPV2" },
511 { IS_NO_RIPV1_IN
, 0, "NO_RIPV1_IN" },
512 { IS_NO_RIPV2_IN
, 0, "NO_RIPV2_IN" },
513 { IS_NO_RIPV1_OUT
, 0, "NO_RIPV1_OUT" },
514 { IS_NO_RIPV2_OUT
, 0, "NO_RIPV2_OUT" },
517 | IS_NO_ADV_OUT
), IS_BCAST_RDISC
, "NO_RDISC" },
518 { IS_NO_SOL_OUT
, 0, "NO_SOLICIT" },
519 { IS_SOL_OUT
, 0, "SEND_SOLICIT" },
520 { IS_NO_ADV_OUT
, IS_BCAST_RDISC
, "NO_RDISC_ADV" },
521 { IS_ADV_OUT
, 0, "RDISC_ADV" },
522 { IS_BCAST_RDISC
, 0, "BCAST_RDISC" },
523 { IS_PM_RDISC
, 0, "" },
527 static struct bits rs_bits
[] = {
529 { RS_NET_INT
, RS_NET_SYN
, "NET_INT" },
530 { RS_NET_SYN
, 0, "NET_SYN" },
531 { RS_SUBNET
, 0, "" },
532 { RS_LOCAL
, 0, "LOCAL" },
533 { RS_MHOME
, 0, "MHOME" },
534 { RS_STATIC
, 0, "STATIC" },
535 { RS_RDISC
, 0, "RDISC" },
541 trace_bits(const struct bits
*tbl
,
556 && (b
= tbl
->bits_mask
) != 0) {
557 if ((b
& field
) == b
) {
558 if (tbl
->bits_name
[0] != '\0') {
561 fprintf(ftrace
, "%s", tbl
->bits_name
);
564 if (0 == (field
&= ~(b
| tbl
->bits_clear
)))
569 if (field
!= 0 && tbl
->bits_name
!= 0) {
572 fprintf(ftrace
, tbl
->bits_name
, field
);
576 if (c
!= '<' || force
)
586 static char buf
[3*4+3+1+2+3 /* "xxx.xxx.xxx.xxx/xx-->" */
587 +3*4+3+1]; /* "xxx.xxx.xxx.xxx" */
590 i
= sprintf(buf
, "%-16s-->", addrname(dst
, mask
, 0));
591 sprintf(&buf
[i
], "%-*s", 15+20-MAX(20,i
), naddr_ntoa(gate
));
597 print_rts(struct rt_spare
*rts
,
598 int force_metric
, /* -1=suppress, 0=default */
599 int force_ifp
, /* -1=suppress, 0=default */
600 int force_router
, /* -1=suppress, 0=default, 1=display */
601 int force_tag
, /* -1=suppress, 0=default, 1=display */
602 int force_time
) /* 0=suppress, 1=display */
607 if (force_metric
>= 0)
608 fprintf(ftrace
, "metric=%-2d ", rts
->rts_metric
);
610 fprintf(ftrace
, "%s ", (rts
->rts_ifp
== 0 ?
611 "if?" : rts
->rts_ifp
->int_name
));
613 || (force_router
== 0 && rts
->rts_router
!= rts
->rts_gate
))
614 fprintf(ftrace
, "router=%s ", naddr_ntoa(rts
->rts_router
));
616 fprintf(ftrace
, "%s ", ts(rts
->rts_time
));
618 || (force_tag
== 0 && rts
->rts_tag
!= 0))
619 fprintf(ftrace
, "tag=%#x ", ntohs(rts
->rts_tag
));
620 if (rts
->rts_de_ag
!= 0) {
621 for (i
= 1; (u_int
)(1 << i
) <= rts
->rts_de_ag
; i
++)
623 fprintf(ftrace
, "de_ag=%d ", i
);
630 trace_if(const char *act
,
631 struct interface
*ifp
)
633 if (!TRACEACTIONS
|| ftrace
== 0)
637 fprintf(ftrace
, "%-3s interface %-4s ", act
, ifp
->int_name
);
638 fprintf(ftrace
, "%-15s-->%-15s ",
639 naddr_ntoa(ifp
->int_addr
),
640 addrname(((ifp
->int_if_flags
& IFF_POINTOPOINT
)
641 ? ifp
->int_dstaddr
: htonl(ifp
->int_net
)),
643 if (ifp
->int_metric
!= 0)
644 fprintf(ftrace
, "metric=%d ", ifp
->int_metric
);
645 if (!IS_RIP_OUT_OFF(ifp
->int_state
)
646 && ifp
->int_d_metric
!= 0)
647 fprintf(ftrace
, "fake_default=%d ", ifp
->int_d_metric
);
648 trace_bits(if_bits
, ifp
->int_if_flags
, 0);
649 trace_bits(is_bits
, ifp
->int_state
, 0);
655 trace_upslot(struct rt_entry
*rt
,
656 struct rt_spare
*rts
,
657 struct rt_spare
*new)
659 if (!TRACEACTIONS
|| ftrace
== 0)
662 if (rts
->rts_gate
== new->rts_gate
663 && rts
->rts_router
== new->rts_router
664 && rts
->rts_metric
== new->rts_metric
665 && rts
->rts_tag
== new->rts_tag
666 && rts
->rts_de_ag
== new->rts_de_ag
)
670 if (new->rts_gate
== 0) {
671 fprintf(ftrace
, "Del #%d %-35s ",
672 (int)(rts
- rt
->rt_spares
),
673 rtname(rt
->rt_dst
, rt
->rt_mask
, rts
->rts_gate
));
674 print_rts(rts
, 0,0,0,0,
675 (rts
!= rt
->rt_spares
676 || AGE_RT(rt
->rt_state
,new->rts_ifp
)));
678 } else if (rts
->rts_gate
!= RIP_DEFAULT
) {
679 fprintf(ftrace
, "Chg #%d %-35s ",
680 (int)(rts
- rt
->rt_spares
),
681 rtname(rt
->rt_dst
, rt
->rt_mask
, rts
->rts_gate
));
683 rts
->rts_gate
!= new->rts_gate
,
684 rts
->rts_tag
!= new->rts_tag
,
685 rts
!= rt
->rt_spares
|| AGE_RT(rt
->rt_state
,
688 fprintf(ftrace
, "\n %19s%-16s ", "",
689 (new->rts_gate
!= rts
->rts_gate
690 ? naddr_ntoa(new->rts_gate
) : ""));
692 -(new->rts_metric
== rts
->rts_metric
),
693 -(new->rts_ifp
== rts
->rts_ifp
),
695 rts
->rts_tag
!= new->rts_tag
,
696 (new->rts_time
!= rts
->rts_time
697 && (rts
!= rt
->rt_spares
698 || AGE_RT(rt
->rt_state
, new->rts_ifp
))));
701 fprintf(ftrace
, "Add #%d %-35s ",
702 (int)(rts
- rt
->rt_spares
),
703 rtname(rt
->rt_dst
, rt
->rt_mask
, new->rts_gate
));
704 print_rts(new, 0,0,0,0,
705 (rts
!= rt
->rt_spares
706 || AGE_RT(rt
->rt_state
,new->rts_ifp
)));
712 /* miscellaneous message checked by the caller
715 trace_misc(const char *p
, ...)
724 vfprintf(ftrace
, p
, args
);
729 /* display a message if tracing actions
732 trace_act(const char *p
, ...)
736 if (!TRACEACTIONS
|| ftrace
== 0)
741 vfprintf(ftrace
, p
, args
);
746 /* display a message if tracing packets
749 trace_pkt(const char *p
, ...)
753 if (!TRACEPACKETS
|| ftrace
== 0)
758 vfprintf(ftrace
, p
, args
);
764 trace_change(struct rt_entry
*rt
,
766 struct rt_spare
*new,
772 if (rt
->rt_metric
== new->rts_metric
773 && rt
->rt_gate
== new->rts_gate
774 && rt
->rt_router
== new->rts_router
775 && rt
->rt_state
== state
776 && rt
->rt_tag
== new->rts_tag
777 && rt
->rt_de_ag
== new->rts_de_ag
)
781 fprintf(ftrace
, "%s %-35s ",
782 label
, rtname(rt
->rt_dst
, rt
->rt_mask
, rt
->rt_gate
));
783 print_rts(rt
->rt_spares
,
784 0,0,0,0, AGE_RT(rt
->rt_state
, rt
->rt_ifp
));
785 trace_bits(rs_bits
, rt
->rt_state
, rt
->rt_state
!= state
);
787 fprintf(ftrace
, "\n%*s %19s%-16s ",
788 (int)strlen(label
), "", "",
789 (rt
->rt_gate
!= new->rts_gate
790 ? naddr_ntoa(new->rts_gate
) : ""));
792 -(new->rts_metric
== rt
->rt_metric
),
793 -(new->rts_ifp
== rt
->rt_ifp
),
795 rt
->rt_tag
!= new->rts_tag
,
796 (rt
->rt_time
!= new->rts_time
797 && AGE_RT(rt
->rt_state
,new->rts_ifp
)));
798 if (rt
->rt_state
!= state
)
799 trace_bits(rs_bits
, state
, 1);
805 trace_add_del(const char * action
, struct rt_entry
*rt
)
811 fprintf(ftrace
, "%s %-35s ",
812 action
, rtname(rt
->rt_dst
, rt
->rt_mask
, rt
->rt_gate
));
813 print_rts(rt
->rt_spares
, 0,0,0,0,AGE_RT(rt
->rt_state
,rt
->rt_ifp
));
814 trace_bits(rs_bits
, rt
->rt_state
, 0);
821 walk_trace(struct radix_node
*rn
,
822 struct walkarg
*w UNUSED
)
824 #define RT ((struct rt_entry *)rn)
825 struct rt_spare
*rts
;
828 fprintf(ftrace
, " %-35s ",
829 rtname(RT
->rt_dst
, RT
->rt_mask
, RT
->rt_gate
));
830 print_rts(&RT
->rt_spares
[0], 0,0,0,0, AGE_RT(RT
->rt_state
, RT
->rt_ifp
));
831 trace_bits(rs_bits
, RT
->rt_state
, 0);
832 if (RT
->rt_poison_time
>= now_garbage
833 && RT
->rt_poison_metric
< RT
->rt_metric
)
834 fprintf(ftrace
, "pm=%d@%s",
835 RT
->rt_poison_metric
, ts(RT
->rt_poison_time
));
837 rts
= &RT
->rt_spares
[1];
838 for (i
= 1; i
< NUM_SPARES
; i
++, rts
++) {
839 if (rts
->rts_gate
!= RIP_DEFAULT
) {
840 fprintf(ftrace
,"\n #%d%15s%-16s ",
841 i
, "", naddr_ntoa(rts
->rts_gate
));
842 print_rts(rts
, 0,0,0,0,1);
854 struct interface
*ifp
;
860 fputs("current daemon state:\n", ftrace
);
861 for (ifp
= ifnet
; ifp
!= 0; ifp
= ifp
->int_next
)
863 rn_walktree(rhead
, walk_trace
, 0);
868 trace_rip(const char *dir1
, const char *dir2
,
869 struct sockaddr_in
*who
,
870 struct interface
*ifp
,
872 int size
) /* total size of message */
874 struct netinfo
*n
, *lim
;
875 # define NA ((struct netauth*)n)
878 if (!TRACEPACKETS
|| ftrace
== 0)
882 if (msg
->rip_cmd
>= RIPCMD_MAX
883 || msg
->rip_vers
== 0) {
884 fprintf(ftrace
, "%s bad RIPv%d cmd=%d %s"
886 dir1
, msg
->rip_vers
, msg
->rip_cmd
, dir2
,
887 naddr_ntoa(who
->sin_addr
.s_addr
),
888 ntohs(who
->sin_port
),
893 fprintf(ftrace
, "%s RIPv%d %s %s %s.%d%s%s\n",
894 dir1
, msg
->rip_vers
, ripcmds
[msg
->rip_cmd
], dir2
,
895 naddr_ntoa(who
->sin_addr
.s_addr
), ntohs(who
->sin_port
),
896 ifp
? " via " : "", ifp
? ifp
->int_name
: "");
901 switch (msg
->rip_cmd
) {
903 case RIPCMD_RESPONSE
:
905 lim
= (struct netinfo
*)((char*)msg
+ size
);
906 for (; n
< lim
; n
++) {
908 && n
->n_family
== RIP_AF_UNSPEC
909 && ntohl(n
->n_metric
) == HOPCNT_INFINITY
910 && msg
->rip_cmd
== RIPCMD_REQUEST
913 && (n
+1)->n_family
== RIP_AF_AUTH
))) {
914 fputs("\tQUERY ", ftrace
);
916 fprintf(ftrace
, "%s ",
917 naddr_ntoa(n
->n_dst
));
919 fprintf(ftrace
, "mask=%#x ",
920 (u_int
)ntohl(n
->n_mask
));
922 fprintf(ftrace
, "nhop=%s ",
923 naddr_ntoa(n
->n_nhop
));
925 fprintf(ftrace
, "tag=%#x ",
931 if (n
->n_family
== RIP_AF_AUTH
) {
932 if (NA
->a_type
== RIP_AUTH_PW
933 && n
== msg
->rip_nets
) {
934 fprintf(ftrace
, "\tPassword"
937 qstring(NA
->au
.au_pw
,
942 if (NA
->a_type
== RIP_AUTH_MD5
943 && n
== msg
->rip_nets
) {
946 " pkt_len=%d KeyID=%u"
950 ntohs(NA
->au
.a_md5
.md5_pkt_len
),
951 NA
->au
.a_md5
.md5_keyid
,
952 NA
->au
.a_md5
.md5_auth_len
,
953 (int)ntohl(NA
->au
.a_md5
.md5_seqno
),
954 (int)ntohs(NA
->au
.a_md5
.rsvd
[0]),
955 (int)ntohs(NA
->au
.a_md5
.rsvd
[1]));
959 "\tAuthentication type %d: ",
962 i
< (int)sizeof(NA
->au
.au_pw
);
964 fprintf(ftrace
, "%02x ",
971 if (n
->n_family
!= RIP_AF_INET
) {
973 "\t(af %d) %-18s mask=%#x ",
975 naddr_ntoa(n
->n_dst
),
976 (u_int
)ntohl(n
->n_mask
));
977 } else if (msg
->rip_vers
== RIPv1
) {
978 fprintf(ftrace
, "\t%-18s ",
979 addrname(n
->n_dst
, ntohl(n
->n_mask
),
980 n
->n_mask
==0 ? 2 : 1));
982 fprintf(ftrace
, "\t%-18s ",
983 addrname(n
->n_dst
, ntohl(n
->n_mask
),
984 n
->n_mask
==0 ? 2 : 0));
986 fprintf(ftrace
, "metric=%-2d ",
987 (u_int
)ntohl(n
->n_metric
));
989 fprintf(ftrace
, " nhop=%s ",
990 naddr_ntoa(n
->n_nhop
));
992 fprintf(ftrace
, "tag=%#x", ntohs(n
->n_tag
));
995 if (size
!= (char *)n
- (char *)msg
)
996 fprintf(ftrace
, "truncated record, len %d\n", size
);
1000 fprintf(ftrace
, "\tfile=\"%.*s\"\n", size
-4,
1001 msg
->rip_tracefile
);
1004 case RIPCMD_TRACEOFF
: