1996-05-30 16:19:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1983, 1988, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
1999-05-02 10:51:54 +00:00
|
|
|
* must display the following acknowledgment:
|
1996-05-30 16:19:16 +00:00
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1999-05-02 13:14:16 +00:00
|
|
|
*
|
|
|
|
* $Id$
|
1996-05-30 16:19:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define RIPCMDS
|
|
|
|
#include "defs.h"
|
|
|
|
#include "pathnames.h"
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
#if !defined(sgi) && !defined(__NetBSD__)
|
|
|
|
static char sccsid[] __attribute__((unused)) = "@(#)trace.c 8.1 (Berkeley) 6/5/93";
|
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
__RCSID("$NetBSD$");
|
|
|
|
#endif
|
|
|
|
#ident "$Revision: 2.17 $"
|
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
#ifdef sgi
|
|
|
|
/* use *stat64 for files on large filesystems */
|
|
|
|
#define stat stat64
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NRECORDS 50 /* size of circular trace buffer */
|
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
int tracelevel, new_tracelevel;
|
1996-05-30 16:19:16 +00:00
|
|
|
FILE *ftrace = stdout; /* output trace file */
|
1999-05-02 10:51:54 +00:00
|
|
|
static const char *sigtrace_pat = "%s";
|
1996-12-11 20:59:33 +00:00
|
|
|
static char savetracename[MAXPATHLEN+1];
|
|
|
|
char inittracename[MAXPATHLEN+1];
|
|
|
|
int file_trace; /* 1=tracing to file, not stdout */
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-09-16 16:51:32 +00:00
|
|
|
static void trace_dump(void);
|
1999-05-02 10:51:54 +00:00
|
|
|
static void tmsg(const char *, ...) PATTRIB(1,2);
|
1996-09-16 16:51:32 +00:00
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-11-19 20:23:47 +00:00
|
|
|
/* convert string to printable characters
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
qstring(u_char *s, int len)
|
|
|
|
{
|
|
|
|
static char buf[8*20+1];
|
|
|
|
char *p;
|
|
|
|
u_char *s2, c;
|
|
|
|
|
|
|
|
|
|
|
|
for (p = buf; len != 0 && p < &buf[sizeof(buf)-1]; len--) {
|
|
|
|
c = *s++;
|
|
|
|
if (c == '\0') {
|
|
|
|
for (s2 = s+1; s2 < &s[len]; s2++) {
|
|
|
|
if (*s2 != '\0')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (s2 >= &s[len])
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c >= ' ' && c < 0x7f && c != '\\') {
|
|
|
|
*p++ = c;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*p++ = '\\';
|
|
|
|
switch (c) {
|
|
|
|
case '\\':
|
|
|
|
*p++ = '\\';
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
*p++= 'n';
|
|
|
|
break;
|
|
|
|
case '\r':
|
|
|
|
*p++= 'r';
|
|
|
|
break;
|
|
|
|
case '\t':
|
|
|
|
*p++ = 't';
|
|
|
|
break;
|
|
|
|
case '\b':
|
|
|
|
*p++ = 'b';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
p += sprintf(p,"%o",c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exit:
|
|
|
|
*p = '\0';
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
/* convert IP address to a string, but not into a single buffer
|
|
|
|
*/
|
1996-05-30 16:19:16 +00:00
|
|
|
char *
|
|
|
|
naddr_ntoa(naddr a)
|
|
|
|
{
|
|
|
|
#define NUM_BUFS 4
|
1996-08-27 16:13:00 +00:00
|
|
|
static int bufno;
|
1996-05-30 16:19:16 +00:00
|
|
|
static struct {
|
|
|
|
char str[16]; /* xxx.xxx.xxx.xxx\0 */
|
|
|
|
} bufs[NUM_BUFS];
|
|
|
|
char *s;
|
1996-08-27 16:13:00 +00:00
|
|
|
struct in_addr addr;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
addr.s_addr = a;
|
1996-08-27 16:13:00 +00:00
|
|
|
s = strcpy(bufs[bufno].str, inet_ntoa(addr));
|
|
|
|
bufno = (bufno+1) % NUM_BUFS;
|
1996-05-30 16:19:16 +00:00
|
|
|
return s;
|
1996-08-27 16:13:00 +00:00
|
|
|
#undef NUM_BUFS
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
const char *
|
1996-05-30 16:19:16 +00:00
|
|
|
saddr_ntoa(struct sockaddr *sa)
|
|
|
|
{
|
|
|
|
return (sa == 0) ? "?" : naddr_ntoa(S_ADDR(sa));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
ts(time_t secs) {
|
|
|
|
static char s[20];
|
|
|
|
|
|
|
|
secs += epoch.tv_sec;
|
|
|
|
#ifdef sgi
|
|
|
|
(void)cftime(s, "%T", &secs);
|
|
|
|
#else
|
1999-05-02 10:51:54 +00:00
|
|
|
memcpy(s, ctime(&secs)+11, 8);
|
1996-05-30 16:19:16 +00:00
|
|
|
s[8] = '\0';
|
|
|
|
#endif
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* On each event, display a time stamp.
|
|
|
|
* This assumes that 'now' is update once for each event, and
|
|
|
|
* that at least now.tv_usec changes.
|
|
|
|
*/
|
1996-12-11 20:59:33 +00:00
|
|
|
static struct timeval lastlog_time;
|
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
void
|
|
|
|
lastlog(void)
|
|
|
|
{
|
1996-12-11 20:59:33 +00:00
|
|
|
if (lastlog_time.tv_sec != now.tv_sec
|
|
|
|
|| lastlog_time.tv_usec != now.tv_usec) {
|
1996-07-22 20:56:54 +00:00
|
|
|
(void)fprintf(ftrace, "-- %s --\n", ts(now.tv_sec));
|
1996-12-11 20:59:33 +00:00
|
|
|
lastlog_time = now;
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
1999-05-02 10:51:54 +00:00
|
|
|
tmsg(const char *p, ...)
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
1996-07-22 20:56:54 +00:00
|
|
|
va_list args;
|
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
if (ftrace != 0) {
|
|
|
|
lastlog();
|
1996-07-22 20:56:54 +00:00
|
|
|
va_start(args, p);
|
|
|
|
vfprintf(ftrace, p, args);
|
1999-05-02 10:51:54 +00:00
|
|
|
(void)fputc('\n',ftrace);
|
1996-07-22 20:56:54 +00:00
|
|
|
fflush(ftrace);
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
void
|
|
|
|
trace_close(int zap_stdio)
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
fflush(stdout);
|
|
|
|
fflush(stderr);
|
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
if (ftrace != 0 && zap_stdio) {
|
1996-12-11 20:59:33 +00:00
|
|
|
if (ftrace != stdout)
|
|
|
|
fclose(ftrace);
|
|
|
|
ftrace = 0;
|
1996-07-22 20:56:54 +00:00
|
|
|
fd = open(_PATH_DEVNULL, O_RDWR);
|
1999-05-02 10:51:54 +00:00
|
|
|
if (isatty(STDIN_FILENO))
|
|
|
|
(void)dup2(fd, STDIN_FILENO);
|
|
|
|
if (isatty(STDOUT_FILENO))
|
|
|
|
(void)dup2(fd, STDOUT_FILENO);
|
|
|
|
if (isatty(STDERR_FILENO))
|
|
|
|
(void)dup2(fd, STDERR_FILENO);
|
1996-07-22 20:56:54 +00:00
|
|
|
(void)close(fd);
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
1996-12-11 20:59:33 +00:00
|
|
|
lastlog_time.tv_sec = 0;
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
trace_flush(void)
|
|
|
|
{
|
|
|
|
if (ftrace != 0) {
|
|
|
|
fflush(ftrace);
|
|
|
|
if (ferror(ftrace))
|
1999-05-02 10:51:54 +00:00
|
|
|
trace_off("tracing off: %s", strerror(ferror(ftrace)));
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
1999-05-02 10:51:54 +00:00
|
|
|
trace_off(const char *p, ...)
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
1996-07-22 20:56:54 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
|
|
if (ftrace != 0) {
|
|
|
|
lastlog();
|
|
|
|
va_start(args, p);
|
|
|
|
vfprintf(ftrace, p, args);
|
1999-05-02 10:51:54 +00:00
|
|
|
(void)fputc('\n',ftrace);
|
1996-07-22 20:56:54 +00:00
|
|
|
}
|
1999-05-02 10:51:54 +00:00
|
|
|
trace_close(file_trace);
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
new_tracelevel = tracelevel = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
/* log a change in tracing
|
|
|
|
*/
|
1996-05-30 16:19:16 +00:00
|
|
|
void
|
1999-05-02 10:51:54 +00:00
|
|
|
tracelevel_msg(const char *pat,
|
1996-12-11 20:59:33 +00:00
|
|
|
int dump) /* -1=no dump, 0=default, 1=force */
|
|
|
|
{
|
1999-05-02 10:51:54 +00:00
|
|
|
static const char *off_msgs[MAX_TRACELEVEL] = {
|
1996-12-11 20:59:33 +00:00
|
|
|
"Tracing actions stopped",
|
|
|
|
"Tracing packets stopped",
|
|
|
|
"Tracing packet contents stopped",
|
|
|
|
"Tracing kernel changes stopped",
|
|
|
|
};
|
1999-05-02 10:51:54 +00:00
|
|
|
static const char *on_msgs[MAX_TRACELEVEL] = {
|
1996-12-11 20:59:33 +00:00
|
|
|
"Tracing actions started",
|
|
|
|
"Tracing packets started",
|
|
|
|
"Tracing packet contents started",
|
|
|
|
"Tracing kernel changes started",
|
|
|
|
};
|
|
|
|
u_int old_tracelevel = tracelevel;
|
|
|
|
|
|
|
|
|
|
|
|
if (new_tracelevel < 0)
|
|
|
|
new_tracelevel = 0;
|
|
|
|
else if (new_tracelevel > MAX_TRACELEVEL)
|
|
|
|
new_tracelevel = MAX_TRACELEVEL;
|
|
|
|
|
|
|
|
if (new_tracelevel < tracelevel) {
|
|
|
|
if (new_tracelevel <= 0) {
|
|
|
|
trace_off(pat, off_msgs[0]);
|
|
|
|
} else do {
|
|
|
|
tmsg(pat, off_msgs[tracelevel]);
|
|
|
|
}
|
|
|
|
while (--tracelevel != new_tracelevel);
|
|
|
|
|
|
|
|
} else if (new_tracelevel > tracelevel) {
|
|
|
|
do {
|
|
|
|
tmsg(pat, on_msgs[tracelevel++]);
|
|
|
|
} while (tracelevel != new_tracelevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dump > 0
|
|
|
|
|| (dump == 0 && old_tracelevel == 0 && tracelevel != 0))
|
|
|
|
trace_dump();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
1999-05-02 10:51:54 +00:00
|
|
|
set_tracefile(const char *filename,
|
|
|
|
const char *pat,
|
1996-12-11 20:59:33 +00:00
|
|
|
int dump) /* -1=no dump, 0=default, 1=force */
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
|
|
|
struct stat stbuf;
|
|
|
|
FILE *n_ftrace;
|
1999-05-02 10:51:54 +00:00
|
|
|
const char *fn;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
/* Allow a null filename to increase the level if the trace file
|
|
|
|
* is already open or if coming from a trusted source, such as
|
|
|
|
* a signal or the command line.
|
1996-07-22 20:56:54 +00:00
|
|
|
*/
|
1996-12-11 20:59:33 +00:00
|
|
|
if (filename == 0 || filename[0] == '\0') {
|
|
|
|
filename = 0;
|
|
|
|
if (ftrace == 0) {
|
|
|
|
if (inittracename[0] == '\0') {
|
|
|
|
msglog("missing trace file name");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fn = inittracename;
|
|
|
|
} else {
|
|
|
|
fn = 0;
|
1996-07-22 20:56:54 +00:00
|
|
|
}
|
|
|
|
|
1996-09-16 16:51:32 +00:00
|
|
|
} else if (!strcmp(filename,"dump/../table")) {
|
|
|
|
trace_dump();
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else {
|
1996-12-11 20:59:33 +00:00
|
|
|
/* Allow the file specified with "-T file" to be reopened,
|
|
|
|
* but require all other names specified over the net to
|
|
|
|
* match the official path. The path can specify a directory
|
|
|
|
* in which the file is to be created.
|
|
|
|
*/
|
|
|
|
if (strcmp(filename, inittracename)
|
|
|
|
#ifdef _PATH_TRACE
|
|
|
|
&& (strncmp(filename, _PATH_TRACE, sizeof(_PATH_TRACE)-1)
|
|
|
|
|| strstr(filename,"../")
|
|
|
|
|| 0 > stat(_PATH_TRACE, &stbuf))
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
msglog("wrong trace file \"%s\"", filename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the new tracefile exists, it must be a regular file.
|
|
|
|
*/
|
1999-05-02 10:51:54 +00:00
|
|
|
if (stat(filename, &stbuf) >= 0 && !S_ISREG(stbuf.st_mode)) {
|
1996-07-22 20:56:54 +00:00
|
|
|
msglog("wrong type (%#x) of trace file \"%s\"",
|
|
|
|
stbuf.st_mode, filename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
fn = filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fn != 0) {
|
|
|
|
n_ftrace = fopen(fn, "a");
|
|
|
|
if (n_ftrace == 0) {
|
|
|
|
msglog("failed to open trace file \"%s\" %s",
|
|
|
|
fn, strerror(errno));
|
|
|
|
if (fn == inittracename)
|
|
|
|
inittracename[0] = '\0';
|
1996-07-22 20:56:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
tmsg("switch to trace file %s", fn);
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
trace_close(file_trace = 1);
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
if (fn != savetracename)
|
|
|
|
strncpy(savetracename, fn, sizeof(savetracename)-1);
|
|
|
|
ftrace = n_ftrace;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
fflush(stdout);
|
|
|
|
fflush(stderr);
|
|
|
|
dup2(fileno(ftrace), STDOUT_FILENO);
|
|
|
|
dup2(fileno(ftrace), STDERR_FILENO);
|
|
|
|
}
|
1996-11-19 20:23:47 +00:00
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
if (new_tracelevel == 0 || filename == 0)
|
|
|
|
new_tracelevel++;
|
|
|
|
tracelevel_msg(pat, dump != 0 ? dump : (filename != 0));
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
void
|
1999-05-02 10:51:54 +00:00
|
|
|
sigtrace_on(int s UNUSED)
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
|
|
|
new_tracelevel++;
|
1999-05-02 10:51:54 +00:00
|
|
|
sigtrace_pat = "SIGUSR1: %s";
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
void
|
1999-05-02 10:51:54 +00:00
|
|
|
sigtrace_off(int s UNUSED)
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
|
|
|
new_tracelevel--;
|
1999-05-02 10:51:54 +00:00
|
|
|
sigtrace_pat = "SIGUSR2: %s";
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
/* Set tracing after a signal.
|
1996-05-30 16:19:16 +00:00
|
|
|
*/
|
|
|
|
void
|
1996-12-11 20:59:33 +00:00
|
|
|
set_tracelevel(void)
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
1996-12-11 20:59:33 +00:00
|
|
|
if (new_tracelevel == tracelevel)
|
|
|
|
return;
|
1996-11-19 20:23:47 +00:00
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
/* If tracing entirely off, and there was no tracefile specified
|
|
|
|
* on the command line, then leave it off.
|
|
|
|
*/
|
|
|
|
if (new_tracelevel > tracelevel && ftrace == 0) {
|
|
|
|
if (savetracename[0] != '\0') {
|
|
|
|
set_tracefile(savetracename,sigtrace_pat,0);
|
|
|
|
} else if (inittracename[0] != '\0') {
|
|
|
|
set_tracefile(inittracename,sigtrace_pat,0);
|
1996-05-30 16:19:16 +00:00
|
|
|
} else {
|
1996-12-11 20:59:33 +00:00
|
|
|
new_tracelevel = 0;
|
|
|
|
return;
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
1996-12-11 20:59:33 +00:00
|
|
|
} else {
|
|
|
|
tracelevel_msg(sigtrace_pat, 0);
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* display an address
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
addrname(naddr addr, /* in network byte order */
|
|
|
|
naddr mask,
|
|
|
|
int force) /* 0=show mask if nonstandard, */
|
|
|
|
{ /* 1=always show mask, 2=never */
|
1996-08-27 16:13:00 +00:00
|
|
|
#define NUM_BUFS 4
|
|
|
|
static int bufno;
|
|
|
|
static struct {
|
|
|
|
char str[15+20];
|
|
|
|
} bufs[NUM_BUFS];
|
|
|
|
char *s, *sp;
|
1996-05-30 16:19:16 +00:00
|
|
|
naddr dmask;
|
|
|
|
int i;
|
|
|
|
|
1996-08-27 16:13:00 +00:00
|
|
|
s = strcpy(bufs[bufno].str, naddr_ntoa(addr));
|
|
|
|
bufno = (bufno+1) % NUM_BUFS;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
if (force == 1 || (force == 0 && mask != std_mask(addr))) {
|
|
|
|
sp = &s[strlen(s)];
|
|
|
|
|
|
|
|
dmask = mask & -mask;
|
|
|
|
if (mask + dmask == 0) {
|
|
|
|
for (i = 0; i != 32 && ((1<<i) & mask) == 0; i++)
|
|
|
|
continue;
|
|
|
|
(void)sprintf(sp, "/%d", 32-i);
|
|
|
|
|
|
|
|
} else {
|
1996-08-27 16:13:00 +00:00
|
|
|
(void)sprintf(sp, " (mask %#x)", (u_int)mask);
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
1996-08-27 16:13:00 +00:00
|
|
|
#undef NUM_BUFS
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* display a bit-field
|
|
|
|
*/
|
|
|
|
struct bits {
|
1999-05-02 10:51:54 +00:00
|
|
|
u_int bits_mask;
|
|
|
|
u_int bits_clear;
|
|
|
|
const char *bits_name;
|
1996-05-30 16:19:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct bits if_bits[] = {
|
1996-07-22 20:56:54 +00:00
|
|
|
{ IFF_LOOPBACK, 0, "LOOPBACK" },
|
|
|
|
{ IFF_POINTOPOINT, 0, "PT-TO-PT" },
|
|
|
|
{ 0, 0, 0}
|
1996-05-30 16:19:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct bits is_bits[] = {
|
1996-11-19 20:23:47 +00:00
|
|
|
{ IS_ALIAS, 0, "ALIAS" },
|
1996-07-22 20:56:54 +00:00
|
|
|
{ IS_SUBNET, 0, "" },
|
1996-11-19 20:23:47 +00:00
|
|
|
{ IS_REMOTE, (IS_NO_RDISC
|
|
|
|
| IS_BCAST_RDISC), "REMOTE" },
|
1996-07-22 20:56:54 +00:00
|
|
|
{ IS_PASSIVE, (IS_NO_RDISC
|
|
|
|
| IS_NO_RIP
|
|
|
|
| IS_NO_SUPER_AG
|
|
|
|
| IS_PM_RDISC
|
|
|
|
| IS_NO_AG), "PASSIVE" },
|
|
|
|
{ IS_EXTERNAL, 0, "EXTERNAL" },
|
|
|
|
{ IS_CHECKED, 0, "" },
|
|
|
|
{ IS_ALL_HOSTS, 0, "" },
|
|
|
|
{ IS_ALL_ROUTERS, 0, "" },
|
1996-11-19 20:23:47 +00:00
|
|
|
{ IS_DISTRUST, 0, "DISTRUST" },
|
1996-07-22 20:56:54 +00:00
|
|
|
{ IS_BROKE, IS_SICK, "BROKEN" },
|
|
|
|
{ IS_SICK, 0, "SICK" },
|
1996-11-19 20:23:47 +00:00
|
|
|
{ IS_DUP, 0, "DUPLICATE" },
|
1996-12-11 20:59:33 +00:00
|
|
|
{ IS_REDIRECT_OK, 0, "REDIRECT_OK" },
|
1996-07-22 20:56:54 +00:00
|
|
|
{ IS_NEED_NET_SYN, 0, "" },
|
|
|
|
{ IS_NO_AG, IS_NO_SUPER_AG, "NO_AG" },
|
|
|
|
{ IS_NO_SUPER_AG, 0, "NO_SUPER_AG" },
|
1996-05-30 16:19:16 +00:00
|
|
|
{ (IS_NO_RIPV1_IN
|
|
|
|
| IS_NO_RIPV2_IN
|
|
|
|
| IS_NO_RIPV1_OUT
|
1996-07-22 20:56:54 +00:00
|
|
|
| IS_NO_RIPV2_OUT), 0, "NO_RIP" },
|
|
|
|
{ (IS_NO_RIPV1_IN
|
|
|
|
| IS_NO_RIPV1_OUT), 0, "RIPV2" },
|
|
|
|
{ IS_NO_RIPV1_IN, 0, "NO_RIPV1_IN" },
|
|
|
|
{ IS_NO_RIPV2_IN, 0, "NO_RIPV2_IN" },
|
|
|
|
{ IS_NO_RIPV1_OUT, 0, "NO_RIPV1_OUT" },
|
|
|
|
{ IS_NO_RIPV2_OUT, 0, "NO_RIPV2_OUT" },
|
1996-05-30 16:19:16 +00:00
|
|
|
{ (IS_NO_ADV_IN
|
|
|
|
| IS_NO_SOL_OUT
|
1996-07-22 20:56:54 +00:00
|
|
|
| IS_NO_ADV_OUT), IS_BCAST_RDISC, "NO_RDISC" },
|
|
|
|
{ IS_NO_SOL_OUT, 0, "NO_SOLICIT" },
|
|
|
|
{ IS_SOL_OUT, 0, "SEND_SOLICIT" },
|
|
|
|
{ IS_NO_ADV_OUT, IS_BCAST_RDISC, "NO_RDISC_ADV" },
|
|
|
|
{ IS_ADV_OUT, 0, "RDISC_ADV" },
|
|
|
|
{ IS_BCAST_RDISC, 0, "BCAST_RDISC" },
|
1996-11-19 20:23:47 +00:00
|
|
|
{ IS_PM_RDISC, 0, "" },
|
1996-07-22 20:56:54 +00:00
|
|
|
{ 0, 0, "%#x"}
|
1996-05-30 16:19:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct bits rs_bits[] = {
|
1996-07-22 20:56:54 +00:00
|
|
|
{ RS_IF, 0, "IF" },
|
|
|
|
{ RS_NET_INT, RS_NET_SYN, "NET_INT" },
|
|
|
|
{ RS_NET_SYN, 0, "NET_SYN" },
|
|
|
|
{ RS_SUBNET, 0, "" },
|
|
|
|
{ RS_LOCAL, 0, "LOCAL" },
|
|
|
|
{ RS_MHOME, 0, "MHOME" },
|
|
|
|
{ RS_STATIC, 0, "STATIC" },
|
|
|
|
{ RS_RDISC, 0, "RDISC" },
|
|
|
|
{ 0, 0, "%#x"}
|
1996-05-30 16:19:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
1999-05-02 10:51:54 +00:00
|
|
|
trace_bits(const struct bits *tbl,
|
1996-07-22 20:56:54 +00:00
|
|
|
u_int field,
|
|
|
|
int force)
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
1999-05-02 10:51:54 +00:00
|
|
|
u_int b;
|
1996-07-22 20:56:54 +00:00
|
|
|
char c;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
if (force) {
|
|
|
|
(void)putc('<', ftrace);
|
|
|
|
c = 0;
|
|
|
|
} else {
|
|
|
|
c = '<';
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
while (field != 0
|
|
|
|
&& (b = tbl->bits_mask) != 0) {
|
|
|
|
if ((b & field) == b) {
|
|
|
|
if (tbl->bits_name[0] != '\0') {
|
|
|
|
if (c)
|
|
|
|
(void)putc(c, ftrace);
|
|
|
|
(void)fprintf(ftrace, "%s", tbl->bits_name);
|
|
|
|
c = '|';
|
|
|
|
}
|
|
|
|
if (0 == (field &= ~(b | tbl->bits_clear)))
|
|
|
|
break;
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
tbl++;
|
|
|
|
}
|
1996-07-22 20:56:54 +00:00
|
|
|
if (field != 0 && tbl->bits_name != 0) {
|
|
|
|
if (c)
|
|
|
|
(void)putc(c, ftrace);
|
|
|
|
(void)fprintf(ftrace, tbl->bits_name, field);
|
|
|
|
c = '|';
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
1996-08-27 16:13:00 +00:00
|
|
|
if (c != '<' || force)
|
1996-05-30 16:19:16 +00:00
|
|
|
(void)fputs("> ", ftrace);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
char *
|
|
|
|
rtname(naddr dst,
|
|
|
|
naddr mask,
|
|
|
|
naddr gate)
|
1996-07-22 20:56:54 +00:00
|
|
|
{
|
|
|
|
static char buf[3*4+3+1+2+3 /* "xxx.xxx.xxx.xxx/xx-->" */
|
|
|
|
+3*4+3+1]; /* "xxx.xxx.xxx.xxx" */
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = sprintf(buf, "%-16s-->", addrname(dst, mask, 0));
|
1999-05-02 10:51:54 +00:00
|
|
|
(void)sprintf(&buf[i], "%-*s", 15+20-MAX(20,i), naddr_ntoa(gate));
|
1996-07-22 20:56:54 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
static void
|
|
|
|
print_rts(struct rt_spare *rts,
|
|
|
|
int force_metric, /* -1=suppress, 0=default */
|
|
|
|
int force_ifp, /* -1=suppress, 0=default */
|
|
|
|
int force_router, /* -1=suppress, 0=default, 1=display */
|
|
|
|
int force_tag, /* -1=suppress, 0=default, 1=display */
|
|
|
|
int force_time) /* 0=suppress, 1=display */
|
|
|
|
{
|
1999-05-02 10:51:54 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
if (force_metric >= 0)
|
|
|
|
(void)fprintf(ftrace, "metric=%-2d ", rts->rts_metric);
|
|
|
|
if (force_ifp >= 0)
|
|
|
|
(void)fprintf(ftrace, "%s ", (rts->rts_ifp == 0 ?
|
|
|
|
"if?" : rts->rts_ifp->int_name));
|
|
|
|
if (force_router > 0
|
|
|
|
|| (force_router == 0 && rts->rts_router != rts->rts_gate))
|
|
|
|
(void)fprintf(ftrace, "router=%s ",
|
|
|
|
naddr_ntoa(rts->rts_router));
|
|
|
|
if (force_time > 0)
|
|
|
|
(void)fprintf(ftrace, "%s ", ts(rts->rts_time));
|
|
|
|
if (force_tag > 0
|
|
|
|
|| (force_tag == 0 && rts->rts_tag != 0))
|
1999-05-02 10:51:54 +00:00
|
|
|
(void)fprintf(ftrace, "tag=%#x ", ntohs(rts->rts_tag));
|
|
|
|
if (rts->rts_de_ag != 0) {
|
|
|
|
for (i = 1; (u_int)(1 << i) <= rts->rts_de_ag; i++)
|
|
|
|
continue;
|
|
|
|
(void)fprintf(ftrace, "de_ag=%d ", i);
|
|
|
|
}
|
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
void
|
1999-05-02 10:51:54 +00:00
|
|
|
trace_if(const char *act,
|
|
|
|
struct interface *ifp)
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
1996-07-22 20:56:54 +00:00
|
|
|
if (!TRACEACTIONS || ftrace == 0)
|
1996-05-30 16:19:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
lastlog();
|
1996-11-19 20:23:47 +00:00
|
|
|
(void)fprintf(ftrace, "%-3s interface %-4s ", act, ifp->int_name);
|
1996-08-27 16:13:00 +00:00
|
|
|
(void)fprintf(ftrace, "%-15s-->%-15s ",
|
1996-05-30 16:19:16 +00:00
|
|
|
naddr_ntoa(ifp->int_addr),
|
1996-11-19 20:23:47 +00:00
|
|
|
addrname(((ifp->int_if_flags & IFF_POINTOPOINT)
|
|
|
|
? ifp->int_dstaddr
|
|
|
|
: htonl(ifp->int_net)),
|
1996-08-27 16:13:00 +00:00
|
|
|
ifp->int_mask, 1));
|
|
|
|
if (ifp->int_metric != 0)
|
|
|
|
(void)fprintf(ftrace, "metric=%d ", ifp->int_metric);
|
1996-11-19 20:23:47 +00:00
|
|
|
if (!IS_RIP_OUT_OFF(ifp->int_state)
|
|
|
|
&& ifp->int_d_metric != 0)
|
|
|
|
(void)fprintf(ftrace, "fake_default=%d ", ifp->int_d_metric);
|
1996-07-22 20:56:54 +00:00
|
|
|
trace_bits(if_bits, ifp->int_if_flags, 0);
|
|
|
|
trace_bits(is_bits, ifp->int_state, 0);
|
1996-05-30 16:19:16 +00:00
|
|
|
(void)fputc('\n',ftrace);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
trace_upslot(struct rt_entry *rt,
|
|
|
|
struct rt_spare *rts,
|
1999-05-02 10:51:54 +00:00
|
|
|
struct rt_spare *new)
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
1996-07-22 20:56:54 +00:00
|
|
|
if (!TRACEACTIONS || ftrace == 0)
|
1996-05-30 16:19:16 +00:00
|
|
|
return;
|
1996-12-11 20:59:33 +00:00
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
if (rts->rts_gate == new->rts_gate
|
|
|
|
&& rts->rts_router == new->rts_router
|
|
|
|
&& rts->rts_metric == new->rts_metric
|
|
|
|
&& rts->rts_tag == new->rts_tag
|
|
|
|
&& rts->rts_de_ag == new->rts_de_ag)
|
1996-05-30 16:19:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
lastlog();
|
1999-05-02 10:51:54 +00:00
|
|
|
if (new->rts_gate == 0) {
|
|
|
|
(void)fprintf(ftrace, "Del #%d %-35s ",
|
|
|
|
(int)(rts - rt->rt_spares),
|
|
|
|
rtname(rt->rt_dst, rt->rt_mask, rts->rts_gate));
|
|
|
|
print_rts(rts, 0,0,0,0,
|
|
|
|
(rts != rt->rt_spares
|
|
|
|
|| AGE_RT(rt->rt_state,new->rts_ifp)));
|
|
|
|
|
|
|
|
} else if (rts->rts_gate != RIP_DEFAULT) {
|
1996-07-22 20:56:54 +00:00
|
|
|
(void)fprintf(ftrace, "Chg #%d %-35s ",
|
1999-05-02 10:51:54 +00:00
|
|
|
(int)(rts - rt->rt_spares),
|
|
|
|
rtname(rt->rt_dst, rt->rt_mask, rts->rts_gate));
|
1996-12-11 20:59:33 +00:00
|
|
|
print_rts(rts, 0,0,
|
1999-05-02 10:51:54 +00:00
|
|
|
rts->rts_gate != new->rts_gate,
|
|
|
|
rts->rts_tag != new->rts_tag,
|
1996-12-11 20:59:33 +00:00
|
|
|
rts != rt->rt_spares || AGE_RT(rt->rt_state,
|
|
|
|
rt->rt_ifp));
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
(void)fprintf(ftrace, "\n %19s%-16s ", "",
|
1999-05-02 10:51:54 +00:00
|
|
|
(new->rts_gate != rts->rts_gate
|
|
|
|
? naddr_ntoa(new->rts_gate) : ""));
|
|
|
|
print_rts(new,
|
|
|
|
-(new->rts_metric == rts->rts_metric),
|
|
|
|
-(new->rts_ifp == rts->rts_ifp),
|
1996-12-11 20:59:33 +00:00
|
|
|
0,
|
1999-05-02 10:51:54 +00:00
|
|
|
rts->rts_tag != new->rts_tag,
|
|
|
|
(new->rts_time != rts->rts_time
|
|
|
|
&& (rts != rt->rt_spares
|
|
|
|
|| AGE_RT(rt->rt_state, new->rts_ifp))));
|
1996-05-30 16:19:16 +00:00
|
|
|
|
|
|
|
} else {
|
1996-07-22 20:56:54 +00:00
|
|
|
(void)fprintf(ftrace, "Add #%d %-35s ",
|
1999-05-02 10:51:54 +00:00
|
|
|
(int)(rts - rt->rt_spares),
|
|
|
|
rtname(rt->rt_dst, rt->rt_mask, new->rts_gate));
|
|
|
|
print_rts(new, 0,0,0,0,
|
|
|
|
(rts != rt->rt_spares
|
|
|
|
|| AGE_RT(rt->rt_state,new->rts_ifp)));
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
1996-12-11 20:59:33 +00:00
|
|
|
(void)fputc('\n',ftrace);
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
/* miscellaneous message checked by the caller
|
1996-09-16 16:51:32 +00:00
|
|
|
*/
|
|
|
|
void
|
1999-05-02 10:51:54 +00:00
|
|
|
trace_misc(const char *p, ...)
|
1996-09-16 16:51:32 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
if (ftrace == 0)
|
1996-09-16 16:51:32 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
lastlog();
|
|
|
|
va_start(args, p);
|
|
|
|
vfprintf(ftrace, p, args);
|
1999-05-02 10:51:54 +00:00
|
|
|
(void)fputc('\n',ftrace);
|
1996-09-16 16:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
/* display a message if tracing actions
|
|
|
|
*/
|
1996-05-30 16:19:16 +00:00
|
|
|
void
|
1999-05-02 10:51:54 +00:00
|
|
|
trace_act(const char *p, ...)
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
if (!TRACEACTIONS || ftrace == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lastlog();
|
|
|
|
va_start(args, p);
|
|
|
|
vfprintf(ftrace, p, args);
|
1996-11-19 20:23:47 +00:00
|
|
|
(void)fputc('\n',ftrace);
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
/* display a message if tracing packets
|
|
|
|
*/
|
|
|
|
void
|
1999-05-02 10:51:54 +00:00
|
|
|
trace_pkt(const char *p, ...)
|
1996-07-22 20:56:54 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
if (!TRACEPACKETS || ftrace == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lastlog();
|
|
|
|
va_start(args, p);
|
|
|
|
vfprintf(ftrace, p, args);
|
1996-11-19 20:23:47 +00:00
|
|
|
(void)fputc('\n',ftrace);
|
1996-07-22 20:56:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
void
|
|
|
|
trace_change(struct rt_entry *rt,
|
|
|
|
u_int state,
|
1999-05-02 10:51:54 +00:00
|
|
|
struct rt_spare *new,
|
|
|
|
const char *label)
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
|
|
|
if (ftrace == 0)
|
|
|
|
return;
|
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
if (rt->rt_metric == new->rts_metric
|
|
|
|
&& rt->rt_gate == new->rts_gate
|
|
|
|
&& rt->rt_router == new->rts_router
|
1996-05-30 16:19:16 +00:00
|
|
|
&& rt->rt_state == state
|
1999-05-02 10:51:54 +00:00
|
|
|
&& rt->rt_tag == new->rts_tag
|
|
|
|
&& rt->rt_de_ag == new->rts_de_ag)
|
1996-05-30 16:19:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
lastlog();
|
1996-12-11 20:59:33 +00:00
|
|
|
(void)fprintf(ftrace, "%s %-35s ",
|
1996-05-30 16:19:16 +00:00
|
|
|
label,
|
1999-05-02 10:51:54 +00:00
|
|
|
rtname(rt->rt_dst, rt->rt_mask, rt->rt_gate));
|
1996-12-11 20:59:33 +00:00
|
|
|
print_rts(rt->rt_spares,
|
|
|
|
0,0,0,0, AGE_RT(rt->rt_state, rt->rt_ifp));
|
1996-07-22 20:56:54 +00:00
|
|
|
trace_bits(rs_bits, rt->rt_state, rt->rt_state != state);
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
(void)fprintf(ftrace, "\n%*s %19s%-16s ",
|
1999-05-02 10:51:54 +00:00
|
|
|
(int)strlen(label), "", "",
|
|
|
|
(rt->rt_gate != new->rts_gate
|
|
|
|
? naddr_ntoa(new->rts_gate) : ""));
|
|
|
|
print_rts(new,
|
|
|
|
-(new->rts_metric == rt->rt_metric),
|
|
|
|
-(new->rts_ifp == rt->rt_ifp),
|
1996-12-11 20:59:33 +00:00
|
|
|
0,
|
1999-05-02 10:51:54 +00:00
|
|
|
rt->rt_tag != new->rts_tag,
|
|
|
|
(rt->rt_time != new->rts_time
|
|
|
|
&& AGE_RT(rt->rt_state,new->rts_ifp)));
|
1996-05-30 16:19:16 +00:00
|
|
|
if (rt->rt_state != state)
|
1996-07-22 20:56:54 +00:00
|
|
|
trace_bits(rs_bits, state, 1);
|
1996-12-11 20:59:33 +00:00
|
|
|
(void)fputc('\n',ftrace);
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
1999-05-02 10:51:54 +00:00
|
|
|
trace_add_del(const char * action, struct rt_entry *rt)
|
1996-05-30 16:19:16 +00:00
|
|
|
{
|
|
|
|
if (ftrace == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lastlog();
|
1996-12-11 20:59:33 +00:00
|
|
|
(void)fprintf(ftrace, "%s %-35s ",
|
1996-05-30 16:19:16 +00:00
|
|
|
action,
|
1999-05-02 10:51:54 +00:00
|
|
|
rtname(rt->rt_dst, rt->rt_mask, rt->rt_gate));
|
1996-12-11 20:59:33 +00:00
|
|
|
print_rts(rt->rt_spares, 0,0,0,0,AGE_RT(rt->rt_state,rt->rt_ifp));
|
|
|
|
trace_bits(rs_bits, rt->rt_state, 0);
|
|
|
|
(void)fputc('\n',ftrace);
|
1996-05-30 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-09-16 16:51:32 +00:00
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
walk_trace(struct radix_node *rn,
|
1999-05-02 10:51:54 +00:00
|
|
|
struct walkarg *w UNUSED)
|
1996-09-16 16:51:32 +00:00
|
|
|
{
|
|
|
|
#define RT ((struct rt_entry *)rn)
|
|
|
|
struct rt_spare *rts;
|
1999-05-02 10:51:54 +00:00
|
|
|
int i;
|
1996-09-16 16:51:32 +00:00
|
|
|
|
1999-05-02 10:51:54 +00:00
|
|
|
(void)fprintf(ftrace, " %-35s ",
|
|
|
|
rtname(RT->rt_dst, RT->rt_mask, RT->rt_gate));
|
|
|
|
print_rts(&RT->rt_spares[0], 0,0,0,0, AGE_RT(RT->rt_state, RT->rt_ifp));
|
1996-09-16 16:51:32 +00:00
|
|
|
trace_bits(rs_bits, RT->rt_state, 0);
|
1996-12-11 20:59:33 +00:00
|
|
|
if (RT->rt_poison_time >= now_garbage
|
|
|
|
&& RT->rt_poison_metric < RT->rt_metric)
|
|
|
|
(void)fprintf(ftrace, "pm=%d@%s",
|
1999-05-02 10:51:54 +00:00
|
|
|
RT->rt_poison_metric, ts(RT->rt_poison_time));
|
1996-09-16 16:51:32 +00:00
|
|
|
|
|
|
|
rts = &RT->rt_spares[1];
|
|
|
|
for (i = 1; i < NUM_SPARES; i++, rts++) {
|
1996-12-11 20:59:33 +00:00
|
|
|
if (rts->rts_gate != RIP_DEFAULT) {
|
|
|
|
(void)fprintf(ftrace,"\n #%d%15s%-16s ",
|
|
|
|
i, "", naddr_ntoa(rts->rts_gate));
|
|
|
|
print_rts(rts, 0,0,0,0,1);
|
1996-09-16 16:51:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
(void)fputc('\n',ftrace);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
trace_dump(void)
|
|
|
|
{
|
1996-11-19 20:23:47 +00:00
|
|
|
struct interface *ifp;
|
|
|
|
|
1996-09-16 16:51:32 +00:00
|
|
|
if (ftrace == 0)
|
|
|
|
return;
|
|
|
|
lastlog();
|
|
|
|
|
1996-12-11 20:59:33 +00:00
|
|
|
(void)fputs("current daemon state:\n", ftrace);
|
1996-11-19 20:23:47 +00:00
|
|
|
for (ifp = ifnet; ifp != 0; ifp = ifp->int_next)
|
|
|
|
trace_if("", ifp);
|
1996-09-16 16:51:32 +00:00
|
|
|
(void)rn_walktree(rhead, walk_trace, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-05-30 16:19:16 +00:00
|
|
|
void
|
1999-05-02 10:51:54 +00:00
|
|
|
trace_rip(const char *dir1, const char *dir2,
|
1996-05-30 16:19:16 +00:00
|
|
|
struct sockaddr_in *who,
|
|
|
|
struct interface *ifp,
|
|
|
|
struct rip *msg,
|
|
|
|
int size) /* total size of message */
|
|
|
|
{
|
|
|
|
struct netinfo *n, *lim;
|
1999-05-02 10:51:54 +00:00
|
|
|
# define NA ((struct netauth*)n)
|
1996-11-19 20:23:47 +00:00
|
|
|
int i, seen_route;
|
1996-05-30 16:19:16 +00:00
|
|
|
|
1996-07-22 20:56:54 +00:00
|
|
|
if (!TRACEPACKETS || ftrace == 0)
|
1996-05-30 16:19:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
lastlog();
|
|
|
|
if (msg->rip_cmd >= RIPCMD_MAX
|
|
|
|
|| msg->rip_vers == 0) {
|
1996-08-27 16:13:00 +00:00
|
|
|
(void)fprintf(ftrace, "%s bad RIPv%d cmd=%d %s"
|
|
|
|
" %s.%d size=%d\n",
|
1996-05-30 16:19:16 +00:00
|
|
|
dir1, msg->rip_vers, msg->rip_cmd, dir2,
|
|
|
|
naddr_ntoa(who->sin_addr.s_addr),
|
|
|
|
ntohs(who->sin_port),
|
1996-08-27 16:13:00 +00:00
|
|
|
size);
|
1996-05-30 16:19:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)fprintf(ftrace, "%s RIPv%d %s %s %s.%d%s%s\n",
|
|
|
|
dir1, msg->rip_vers, ripcmds[msg->rip_cmd], dir2,
|
|
|
|
naddr_ntoa(who->sin_addr.s_addr), ntohs(who->sin_port),
|
|
|
|
ifp ? " via " : "", ifp ? ifp->int_name : "");
|
|
|
|
if (!TRACECONTENTS)
|
|
|
|
return;
|
|
|
|
|
1996-11-19 20:23:47 +00:00
|
|
|
seen_route = 0;
|
1996-05-30 16:19:16 +00:00
|
|
|
switch (msg->rip_cmd) {
|
|
|
|
case RIPCMD_REQUEST:
|
|
|
|
case RIPCMD_RESPONSE:
|
|
|
|
n = msg->rip_nets;
|
|
|
|
lim = (struct netinfo *)((char*)msg + size);
|
|
|
|
for (; n < lim; n++) {
|
1996-11-19 20:23:47 +00:00
|
|
|
if (!seen_route
|
|
|
|
&& n->n_family == RIP_AF_UNSPEC
|
1996-05-30 16:19:16 +00:00
|
|
|
&& ntohl(n->n_metric) == HOPCNT_INFINITY
|
1996-11-19 20:23:47 +00:00
|
|
|
&& msg->rip_cmd == RIPCMD_REQUEST
|
|
|
|
&& (n+1 == lim
|
|
|
|
|| (n+2 == lim
|
|
|
|
&& (n+1)->n_family == RIP_AF_AUTH))) {
|
1996-05-30 16:19:16 +00:00
|
|
|
(void)fputs("\tQUERY ", ftrace);
|
|
|
|
if (n->n_dst != 0)
|
|
|
|
(void)fprintf(ftrace, "%s ",
|
|
|
|
naddr_ntoa(n->n_dst));
|
|
|
|
if (n->n_mask != 0)
|
|
|
|
(void)fprintf(ftrace, "mask=%#x ",
|
1996-08-27 16:13:00 +00:00
|
|
|
(u_int)ntohl(n->n_mask));
|
1996-05-30 16:19:16 +00:00
|
|
|
if (n->n_nhop != 0)
|
1996-11-19 20:23:47 +00:00
|
|
|
(void)fprintf(ftrace, "nhop=%s ",
|
1996-05-30 16:19:16 +00:00
|
|
|
naddr_ntoa(n->n_nhop));
|
|
|
|
if (n->n_tag != 0)
|
1996-11-19 20:23:47 +00:00
|
|
|
(void)fprintf(ftrace, "tag=%#x ",
|
1996-08-27 16:13:00 +00:00
|
|
|
ntohs(n->n_tag));
|
1996-05-30 16:19:16 +00:00
|
|
|
(void)fputc('\n',ftrace);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n->n_family == RIP_AF_AUTH) {
|
1996-11-19 20:23:47 +00:00
|
|
|
if (NA->a_type == RIP_AUTH_PW
|
|
|
|
&& n == msg->rip_nets) {
|
|
|
|
(void)fprintf(ftrace, "\tPassword"
|
|
|
|
" Authentication:"
|
|
|
|
" \"%s\"\n",
|
|
|
|
qstring(NA->au.au_pw,
|
|
|
|
RIP_AUTH_PW_LEN));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NA->a_type == RIP_AUTH_MD5
|
|
|
|
&& n == msg->rip_nets) {
|
|
|
|
(void)fprintf(ftrace,
|
1999-05-02 10:51:54 +00:00
|
|
|
"\tMD5 Auth"
|
|
|
|
" pkt_len=%d KeyID=%u"
|
|
|
|
" auth_len=%d"
|
|
|
|
" seqno=%#x"
|
1996-11-19 20:23:47 +00:00
|
|
|
" rsvd=%#x,%#x\n",
|
1999-05-02 10:51:54 +00:00
|
|
|
ntohs(NA->au.a_md5.md5_pkt_len),
|
|
|
|
NA->au.a_md5.md5_keyid,
|
|
|
|
NA->au.a_md5.md5_auth_len,
|
|
|
|
(int)ntohl(NA->au.a_md5.md5_seqno),
|
|
|
|
(int)ntohs(NA->au.a_md5.rsvd[0]),
|
|
|
|
(int)ntohs(NA->au.a_md5.rsvd[1]));
|
1996-11-19 20:23:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
1996-05-30 16:19:16 +00:00
|
|
|
(void)fprintf(ftrace,
|
1999-05-02 10:51:54 +00:00
|
|
|
"\tAuthentication type %d: ",
|
1996-11-19 20:23:47 +00:00
|
|
|
ntohs(NA->a_type));
|
1996-05-30 16:19:16 +00:00
|
|
|
for (i = 0;
|
1999-05-02 10:51:54 +00:00
|
|
|
i < (int)sizeof(NA->au.au_pw);
|
1996-05-30 16:19:16 +00:00
|
|
|
i++)
|
|
|
|
(void)fprintf(ftrace, "%02x ",
|
1996-11-19 20:23:47 +00:00
|
|
|
NA->au.au_pw[i]);
|
1996-05-30 16:19:16 +00:00
|
|
|
(void)fputc('\n',ftrace);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1996-11-19 20:23:47 +00:00
|
|
|
seen_route = 1;
|
1996-05-30 16:19:16 +00:00
|
|
|
if (n->n_family != RIP_AF_INET) {
|
|
|
|
(void)fprintf(ftrace,
|
1996-11-19 20:23:47 +00:00
|
|
|
"\t(af %d) %-18s mask=%#x ",
|
1996-05-30 16:19:16 +00:00
|
|
|
ntohs(n->n_family),
|
|
|
|
naddr_ntoa(n->n_dst),
|
1996-08-27 16:13:00 +00:00
|
|
|
(u_int)ntohl(n->n_mask));
|
1996-05-30 16:19:16 +00:00
|
|
|
} else if (msg->rip_vers == RIPv1) {
|
|
|
|
(void)fprintf(ftrace, "\t%-18s ",
|
|
|
|
addrname(n->n_dst,
|
|
|
|
ntohl(n->n_mask),
|
|
|
|
n->n_mask==0 ? 2 : 1));
|
|
|
|
} else {
|
|
|
|
(void)fprintf(ftrace, "\t%-18s ",
|
|
|
|
addrname(n->n_dst,
|
|
|
|
ntohl(n->n_mask),
|
|
|
|
n->n_mask==0 ? 2 : 0));
|
|
|
|
}
|
|
|
|
(void)fprintf(ftrace, "metric=%-2d ",
|
1996-08-27 16:13:00 +00:00
|
|
|
(u_int)ntohl(n->n_metric));
|
1996-05-30 16:19:16 +00:00
|
|
|
if (n->n_nhop != 0)
|
|
|
|
(void)fprintf(ftrace, " nhop=%s ",
|
|
|
|
naddr_ntoa(n->n_nhop));
|
|
|
|
if (n->n_tag != 0)
|
|
|
|
(void)fprintf(ftrace, "tag=%#x",
|
1996-08-27 16:13:00 +00:00
|
|
|
ntohs(n->n_tag));
|
1996-05-30 16:19:16 +00:00
|
|
|
(void)fputc('\n',ftrace);
|
|
|
|
}
|
|
|
|
if (size != (char *)n - (char *)msg)
|
|
|
|
(void)fprintf(ftrace, "truncated record, len %d\n",
|
|
|
|
size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIPCMD_TRACEON:
|
1996-12-11 20:59:33 +00:00
|
|
|
fprintf(ftrace, "\tfile=\"%.*s\"\n", size-4,
|
|
|
|
msg->rip_tracefile);
|
1996-05-30 16:19:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RIPCMD_TRACEOFF:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|