* Copyright (c) 1983, 1988 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of California at Berkeley. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
static char sccsid
[] = "@(#)trace.c 5.5 (Berkeley) %G%";
* Routing Table Management Daemon
#define NRECORDS 50 /* size of circular trace buffer */
register struct interface
*ifp
;
if (iftraceinit(ifp
, &ifp
->int_input
) &&
iftraceinit(ifp
, &ifp
->int_output
))
fprintf(stderr
, "traceinit: can't init %s\n", ifp
->int_name
);
register struct ifdebug
*ifd
;
register struct iftrace
*t
;
(struct iftrace
*)malloc(NRECORDS
* sizeof (struct iftrace
));
if (ifd
->ifd_records
== 0)
ifd
->ifd_front
= ifd
->ifd_records
;
for (t
= ifd
->ifd_records
; t
< ifd
->ifd_records
+ NRECORDS
; t
++) {
if (stat(file
, &stbuf
) >= 0 && (stbuf
.st_mode
& S_IFMT
) != S_IFREG
)
ftrace
= fopen(file
, "a");
} else if (traceactions
== 0)
else if (tracehistory
== 0)
trace(ifd
, who
, p
, len
, m
)
register struct ifdebug
*ifd
;
register struct iftrace
*t
;
if (ifd
->ifd_records
== 0)
if (ifd
->ifd_front
>= ifd
->ifd_records
+ NRECORDS
)
ifd
->ifd_front
= ifd
->ifd_records
;
if (ifd
->ifd_count
< NRECORDS
)
if (t
->ift_size
> 0 && t
->ift_size
< len
&& t
->ift_packet
) {
if (len
> 0 && t
->ift_packet
== 0) {
t
->ift_packet
= malloc(len
);
bcopy(p
, t
->ift_packet
, len
);
traceaction(fd
, action
, rt
)
struct sockaddr_in
*dst
, *gate
;
{ RTF_GATEWAY
, "GATEWAY" },
{ RTS_PASSIVE
, "PASSIVE" },
{ RTS_REMOTE
, "REMOTE" },
{ RTS_INTERFACE
,"INTERFACE" },
{ RTS_CHANGED
, "CHANGED" },
{ RTS_INTERNAL
, "INTERNAL" },
{ RTS_EXTERNAL
, "EXTERNAL" },
{ RTS_SUBNET
, "SUBNET" },
fprintf(fd
, "\n%s", curtime
);
fprintf(fd
, "%s ", action
);
dst
= (struct sockaddr_in
*)&rt
->rt_dst
;
gate
= (struct sockaddr_in
*)&rt
->rt_router
;
fprintf(fd
, "dst %s, ", inet_ntoa(dst
->sin_addr
));
fprintf(fd
, "router %s, metric %d, flags",
inet_ntoa(gate
->sin_addr
), rt
->rt_metric
);
for (first
= 1, p
= flagbits
; p
->t_bits
> 0; p
++) {
if ((rt
->rt_flags
& p
->t_bits
) == 0)
fprintf(fd
, cp
, p
->t_name
);
for (first
= 1, p
= statebits
; p
->t_bits
> 0; p
++) {
if ((rt
->rt_state
& p
->t_bits
) == 0)
fprintf(fd
, cp
, p
->t_name
);
fprintf(fd
, " timer %d\n", rt
->rt_timer
);
if (!tracepackets
&& (rt
->rt_state
& RTS_PASSIVE
) == 0 && rt
->rt_ifp
)
tracenewmetric(fd
, rt
, newmetric
)
struct sockaddr_in
*dst
, *gate
;
dst
= (struct sockaddr_in
*)&rt
->rt_dst
;
gate
= (struct sockaddr_in
*)&rt
->rt_router
;
fprintf(fd
, "CHANGE metric dst %s, ", inet_ntoa(dst
->sin_addr
));
fprintf(fd
, "router %s, from %d to %d\n",
inet_ntoa(gate
->sin_addr
), rt
->rt_metric
, newmetric
);
register struct interface
*ifp
;
if (ifp
->int_input
.ifd_count
|| ifp
->int_output
.ifd_count
) {
fprintf(fd
, "*** Packet history for interface %s ***\n",
dumptrace(fd
, "to", &ifp
->int_output
);
dumptrace(fd
, "from", &ifp
->int_input
);
fprintf(fd
, "*** end packet history ***\n");
register struct ifdebug
*ifd
;
register struct iftrace
*t
;
char *cp
= !strcmp(dir
, "to") ? "Output" : "Input";
if (ifd
->ifd_front
== ifd
->ifd_records
&&
ifd
->ifd_front
->ift_size
== 0) {
fprintf(fd
, "%s: no packets.\n", cp
);
fprintf(fd
, "%s trace:\n", cp
);
t
= ifd
->ifd_front
- ifd
->ifd_count
;
if (t
< ifd
->ifd_records
)
for ( ; ifd
->ifd_count
; ifd
->ifd_count
--, t
++) {
if (t
>= ifd
->ifd_records
+ NRECORDS
)
dumppacket(fd
, dir
, &t
->ift_who
, t
->ift_packet
, t
->ift_size
,
dumppacket(fd
, dir
, who
, cp
, size
, tstamp
)
struct sockaddr_in
*who
; /* should be sockaddr */
register struct rip
*msg
= (struct rip
*)cp
;
register struct netinfo
*n
;
if (msg
->rip_cmd
&& msg
->rip_cmd
< RIPCMD_MAX
)
fprintf(fd
, "%s %s %s.%d", ripcmds
[msg
->rip_cmd
],
dir
, inet_ntoa(who
->sin_addr
), ntohs(who
->sin_port
));
fprintf(fd
, "Bad cmd 0x%x %s %x.%d %.24s\n", msg
->rip_cmd
,
dir
, inet_ntoa(who
->sin_addr
), ntohs(who
->sin_port
),
fprintf(fd
, "size=%d cp=%x packet=%x\n", size
, cp
, packet
);
fprintf(fd
, " %.24s:\n", ctime(tstamp
));
size
-= 4 * sizeof (char);
for (; size
> 0; n
++, size
-= sizeof (struct netinfo
)) {
if (size
< sizeof (struct netinfo
))
fprintf(fd
, "\tdst %s metric %d\n",
#define satosin(sa) ((struct sockaddr_in *)&sa)
inet_ntoa(satosin(n
->rip_dst
)->sin_addr
),
fprintf(fd
, "\tfile=%*s\n", size
, msg
->rip_tracefile
);