* Copyright (c) 1985 The Regents of the University of California.
* This file includes significant work done at Cornell University by
* Bill Nesheim. That work included by permission.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, 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'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)trace.c 5.8 (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
))
syslog(LOG_ERR
, "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_ns
*dst
, *gate
;
{ RTF_GATEWAY
, "GATEWAY" },
{ RTS_PASSIVE
, "PASSIVE" },
{ RTS_REMOTE
, "REMOTE" },
{ RTS_INTERFACE
,"INTERFACE" },
{ RTS_CHANGED
, "CHANGED" },
fprintf(fd
, "%s ", action
);
dst
= (struct sockaddr_ns
*)&rt
->rt_dst
;
gate
= (struct sockaddr_ns
*)&rt
->rt_router
;
fprintf(fd
, "dst %s, ", xns_ntoa(&dst
->sns_addr
));
fprintf(fd
, "router %s, metric %d, flags",
xns_ntoa(&gate
->sns_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_ns
*who
; /* should be sockaddr */
register struct rip
*msg
= (struct rip
*)cp
;
register struct netinfo
*n
;
if (msg
->rip_cmd
&& ntohs(msg
->rip_cmd
) < RIPCMD_MAX
)
fprintf(fd
, "%s %s %s#%x", ripcmds
[ntohs(msg
->rip_cmd
)],
dir
, xns_ntoa(&who
->sns_addr
), ntohs(who
->sns_addr
.x_port
));
fprintf(fd
, "Bad cmd 0x%x %s %s#%x\n", ntohs(msg
->rip_cmd
),
dir
, xns_ntoa(&who
->sns_addr
), ntohs(who
->sns_addr
.x_port
));
fprintf(fd
, "size=%d cp=%x packet=%x\n", size
, cp
, packet
);
switch (ntohs(msg
->rip_cmd
)) {
size
-= sizeof (u_short
);
for (; size
> 0; n
++, size
-= sizeof (struct netinfo
)) {
if (size
< sizeof (struct netinfo
))
fprintf(fd
, "\tnet %s metric %d\n",
(void)sprintf(buf
, "%lx", ntohl(net
.long_e
));
(void)sprintf(buf
, "%s#%x:%x:%x:%x:%x:%x",
addr
->x_host
.c_host
[0], addr
->x_host
.c_host
[1],
addr
->x_host
.c_host
[2], addr
->x_host
.c_host
[3],
addr
->x_host
.c_host
[4], addr
->x_host
.c_host
[5]);