static char sccsid
[] = "@(#)trace.c 4.6 (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
++) {
ftrace
= fopen(file
, "a");
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_packet
)
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" },
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
);
if (!tracepackets
&& (rt
->rt_state
& RTS_PASSIVE
) == 0 && rt
->rt_ifp
)
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
)
fprintf(fd
, "%.24s: metric=%d\n", ctime(&t
->ift_stamp
),
dumppacket(fd
, dir
, &t
->ift_who
, t
->ift_packet
, t
->ift_size
);
dumppacket(fd
, dir
, who
, cp
, size
)
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\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
);
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
, ", file=%*s\n", size
, msg
->rip_tracefile
);