Clean up import.

This commit is contained in:
mycroft 1994-05-13 08:02:16 +00:00
parent f565d1b549
commit 4c8599d370
27 changed files with 835 additions and 486 deletions

View File

@ -1,16 +1,15 @@
# from: @(#)Makefile 5.6 (Berkeley) 6/27/91
# $Id: Makefile,v 1.6 1993/08/01 05:26:30 mycroft Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/5/93
# $Id: Makefile,v 1.7 1994/05/13 08:02:16 mycroft Exp $
PROG= route
MAN8= route.0
SRCS= route.c
SRCS= route.c ccitt_addr.c
CFLAGS+=-I.
CLEANFILES+=keywords.h
BINOWN= root
BINMODE=4555
all route depend lint tags: keywords.h
all: route ${MAN8}
keywords.h: keywords
sed -e '/^#/d' -e '/^$$/d' ${.CURDIR}/keywords > _keywords.tmp
@ -23,3 +22,5 @@ keywords.h: keywords
rm -f _keywords.tmp
.include <bsd.prog.mk>
route .depend lint tags: keywords.h

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1990, 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
@ -30,8 +30,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)ccitt_addr.c 5.1 (Berkeley) 6/27/91
* $Id: ccitt_addr.c,v 1.4 1993/08/01 18:24:59 mycroft Exp $
* from: @(#)ccitt_addr.c 8.1 (Berkeley) 6/5/93
* $Id: ccitt_addr.c,v 1.5 1994/05/13 08:02:17 mycroft Exp $
*/
/*
* parse CCITT addresses

View File

@ -1,8 +1,8 @@
# @(#)keywords 5.7 (Berkeley) 6/27/91
#
# $Header: /cvsroot/src/sbin/route/Attic/keywords,v 1.3 1993/03/23 00:30:03 cgd Exp $
# from: @(#)keywords 8.2 (Berkeley) 3/19/94
# $Id: keywords,v 1.4 1994/05/13 08:02:18 mycroft Exp $
add
blackhole
change
cloning
delete
@ -28,6 +28,7 @@ monitor
mtu
net
netmask
nostatic
osi
proto1
proto2
@ -38,6 +39,7 @@ rttvar
sa
sendpipe
ssthresh
static
x25
xns
xresolve

View File

@ -1,5 +1,5 @@
.\" Copyright (c) 1983, 1991 The Regents of the University of California.
.\" All rights reserved.
.\" Copyright (c) 1983, 1991, 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
@ -29,20 +29,18 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" from: @(#)route.8 6.11 (Berkeley) 3/16/91
.\" $Id: route.8,v 1.4 1993/08/01 07:38:18 mycroft Exp $
.\" @(#)route.8 8.3 (Berkeley) 3/19/94
.\" $Id: route.8,v 1.5 1994/05/13 08:02:19 mycroft Exp $
.\"
.Dd March 16, 1991
.Dd March 19, 1994
.Dt ROUTE 8
.Os BSD 4.2
.Os BSD 4.4
.Sh NAME
.Nm route
.Nd manually manipulate the routing tables (Interim)
.Nd manually manipulate the routing tables.
.Sh SYNOPSIS
.Nm route
.Op Fl n
.Op Fl q
.Op Fl v
.Op Fl nqv
.Ar command
.Oo
.Op Ar modifiers
@ -50,27 +48,36 @@
.Oc
.Sh DESCRIPTION
.Nm Route
is a program used to manually manipulate the network
routing tables. It normally is not needed, as the
system routing table management daemon,
is a utility used to manually manipulate the network
routing tables. It normally is not needed, as a
system routing table management daemon such as
.Xr routed 8 ,
should tend to this task.
.Pp
Options supported by
The
.Nm route :
utility supports a limited number of general options,
but a rich command language, enabling the user to specify
any arbitrary request that could be delivered via the
programmatic interface discussed in
.Xr route 4 .
.Pp
.Bl -tag -width Ds
.It Fl n
Prevent attempts to print host and network names symbolically
when reporting actions.
Bypasses attempts to print host and network names symbolically
when reporting actions. (The process of translating between symbolic
names and numerical equivalents can be quite time consuming, and
may require correct operation of the network; thus it may be expedient
to forgo this, especially when attempting to repair networking operations),
.It Fl v
(verbose) Print additional details.
.It Fl q
Suppress all output.
.El
.Pp
Commands accepted by
The
.Nm route :
utility provides six commands:
.Pp
.Bl -tag -width Fl -compact
.It Cm add
@ -85,7 +92,7 @@ Change aspects of a route (such as its gateway).
Lookup and display the route for a destination.
.It Cm monitor
Continuously report any changes to the routing information base,
routing lookup misses, or suspected network partionings.
routing lookup misses, or suspected network partitionings.
.El
.Pp
The monitor command has the syntax
@ -103,12 +110,18 @@ The flush command has the syntax
.Op Ar family
.Ed
.Pp
Where the address family may be specified by any of the
If the
.Cm flush
command is specified,
.Nm route
will ``flush'' the routing tables of all gateway entries.
When the address family may is specified by any of the
.Fl osi ,
.Fl xns ,
or
.Fl inet
keywords.
modifiers, only routes having destinations with addresses in the
delineated family will be deleted.
.Pp
The other commands have the following syntax:
.Pp
@ -123,11 +136,11 @@ where
.Ar destination
is the destination host or network,
.Ar gateway
is the next-hop gateway to which packets should be addressed.
Routes to a particular host are distinguished from those to
a network by interpreting the Internet address associated with
.Ar destination .
The optional keywords
is the next-hop intermediary via which packets should be routed.
Routes to a particular host may be distinguished from those to
a network by interpreting the Internet address specified as the
.Ar destination argument.
The optional modifiers
.Fl net
and
.Fl host
@ -157,8 +170,9 @@ and
is interpreted as
.Li 128.32.130.0 .
.Pp
If the route is via an interface rather than
via a gateway, the
If the destination is directly reachable
via an interface requiring
no intermediary system to act as a gateway, the
.Fl interface
modifier should be specified;
the gateway given is the address of this host on the common network,
@ -166,13 +180,14 @@ indicating the interface to be used for transmission.
.Pp
The optional modifiers
.Fl xns ,
.Fl osi ,
and
.Fl osi
.Fl link
specify that all subsequent addresses are in the
.Tn XNS
or
.Tn OSI
address families,
or are specified as link-level addresses,
and the names must be numeric specifications rather than
symbolic names.
.Pp
@ -182,12 +197,32 @@ qualifier is intended
to achieve the effect of an
.Tn OSI
.Tn ESIS
redirect with the netmask option.
redirect with the netmask option,
or to manually add subnet routes with
netmasks different from that of the implied network interface
(as would otherwise be communicated using the OSPF or ISIS routing protocols).
One specifies an additional ensuing address parameter
(to be interpreted as a network mask).
The implicit network mask generated in the inet case
The implicit network mask generated in the AF_INET case
can be overridden by making sure this option follows the destination parameter.
.Pp
Routes have associated flags which influence operation of the protocols
when sending to destinations matched by the routes.
These flags may be set (or sometimes cleared)
by indicating the following corresponding modifiers:
.Bd -literal
-cloning RTF_CLONING - generates a new route on use
-xresolve RTF_XRESOLVE - emit mesg on use (for external lookup)
-iface ~RTF_GATEWAY - destination is directly reachable
-static RTF_STATIC - manually added route
-nostatic ~RTF_STATIC - pretend route added by kernel or daemon
-reject RTF_REJECT - emit an ICMP unreachable when matched
-blackhole RTF_BLACKHOLE - silently discard pkts (during updates)
-proto1 RTF_PROTO1 - set protocol specific routing flag #1
-proto2 RTF_PROTO2 - set protocol specific routing flag #2
-llinfo RTF_LLINFO - validly translates proto addr to link addr
.Ed
.Pp
The optional modifiers
.Fl rtt ,
.Fl rttvar ,
@ -198,7 +233,8 @@ The optional modifiers
.Fl expire ,
and
.Fl ssthresh
provide initial values to metrics maintained in the routing entry.
provide initial values to quantities maintained in the routing entry
by transport level protocols, such as TCP or TP4.
These may be individually locked by preceding each such modifier to
be locked by
the
@ -241,15 +277,6 @@ and
RTM_CHANGE.
As such, only the super-user may modify
the routing tables.
.Pp
If the
.Cm flush
command is specified,
.Nm route
will ``flush'' the routing tables of all gateway entries.
One can choose to flush only those routes whose destinations
are of a given address family, by specifying an optional keyword
describing which address family.
.Sh DIAGNOSTICS
.Bl -tag -width Ds
.It Sy "add [host \&| network ] %s: gateway %s flags %x"

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983, 1989 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1983, 1989, 1991, 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
@ -32,14 +32,14 @@
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
All rights reserved.\n";
static char copyright[] =
"@(#) Copyright (c) 1983, 1989, 1991, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
/*static char sccsid[] = "from: @(#)route.c 5.35 (Berkeley) 6/27/91";*/
static char rcsid[] = "$Id: route.c,v 1.6 1993/08/01 18:24:56 mycroft Exp $";
/*static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/19/94";*/
static char *rcsid = "$Id: route.c,v 1.7 1994/05/13 08:02:21 mycroft Exp $";
#endif /* not lint */
#include <sys/param.h>
@ -47,8 +47,9 @@ static char rcsid[] = "$Id: route.c,v 1.6 1993/08/01 18:24:56 mycroft Exp $";
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/mbuf.h>
#include <sys/kinfo.h>
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/route.h>
#include <net/if_dl.h>
#include <netinet/in.h>
@ -71,7 +72,7 @@ struct keytab {
int kt_i;
} keywords[] = {
#include "keywords.h"
{0, 0}
{0, 0}
};
struct ortentry route;
@ -84,35 +85,29 @@ union sockunion {
struct sockaddr_x25 sx25;
} so_dst, so_gate, so_mask, so_genmask, so_ifa, so_ifp;
union sockunion *so_addrs[] =
{ &so_dst, &so_gate, &so_mask, &so_genmask, &so_ifp, &so_ifa, 0};
typedef union sockunion *sup;
int pid, rtm_addrs, uid;
int s;
int forcehost, forcenet, doflush, nflag, af, qflag, tflag, Cflag, keyword();
int forcehost, forcenet, doflush, nflag, af, qflag, tflag, keyword();
int iflag, verbose, aflen = sizeof (struct sockaddr_in);
int locking, lockrest, debugonly;
struct sockaddr_in s_in = { sizeof(s_in), AF_INET };
struct rt_metrics rt_metrics;
u_long rtm_inits;
struct in_addr inet_makeaddr();
char *routename(), *netname();
void flushroutes(), newroute(), monitor(), sockaddr();
void print_getmsg(), print_rtmsg(), pmsg_common(), sodump(), bprintf();
int getaddr(), rtmsg();
extern char *inet_ntoa(),
*iso_ntoa(),
*link_ntoa();
void flushroutes(), newroute(), monitor(), sockaddr(), sodump(), bprintf();
void print_getmsg(), print_rtmsg(), pmsg_common(), pmsg_addrs(), mask_addr();
int getaddr(), rtmsg(), x25_makemask();
extern char *inet_ntoa(), *iso_ntoa(), *link_ntoa();
void
__dead void
usage(cp)
char *cp;
{
if (cp)
(void) fprintf(stderr, "route: botched keyword: %s\n", cp);
(void) fprintf(stderr,
"usage: route [ -Cnqv ] cmd [[ -<qualifers> ] args ]\n");
"usage: route [ -nqv ] cmd [[ -<qualifers> ] args ]\n");
exit(1);
/* NOTREACHED */
}
@ -135,22 +130,19 @@ quit(s)
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
int
main(argc, argv)
int argc;
char **argv;
{
extern int optind;
int ch;
char *argvp;
if (argc < 2)
usage((char *)NULL);
while ((ch = getopt(argc, argv, "Cnqtv")) != EOF)
while ((ch = getopt(argc, argv, "nqdtv")) != EOF)
switch(ch) {
case 'C':
Cflag = 1; /* Use old ioctls. */
break;
case 'n':
nflag = 1;
break;
@ -163,9 +155,12 @@ main(argc, argv)
case 't':
tflag = 1;
break;
case 'd':
debugonly = 1;
break;
case '?':
default:
usage();
usage((char *)NULL);
}
argc -= optind;
argv += optind;
@ -174,8 +169,6 @@ main(argc, argv)
uid = getuid();
if (tflag)
s = open("/dev/null", O_WRONLY, 0);
else if (Cflag)
s = socket(AF_INET, SOCK_RAW, 0);
else
s = socket(PF_ROUTE, SOCK_RAW, 0);
if (s < 0)
@ -187,10 +180,6 @@ main(argc, argv)
/* FALLTHROUGH */
case K_CHANGE:
if (Cflag)
usage("change or get with -C");
/* FALLTHROUGH */
case K_ADD:
case K_DELETE:
newroute(argc, argv);
@ -219,12 +208,15 @@ flushroutes(argc, argv)
int argc;
char *argv[];
{
int needed, seqno, rlen;
size_t needed;
int mib[6], rlen, seqno;
char *buf, *next, *lim;
register struct rt_msghdr *rtm;
if (uid)
if (uid) {
errno = EACCES;
quit("must be root to alter routing table");
}
shutdown(s, 0); /* Don't want to read back our messages */
if (argc > 1) {
argv++;
@ -250,16 +242,26 @@ flushroutes(argc, argv)
} else
bad: usage(*argv);
}
if ((needed = getkerninfo(KINFO_RT_DUMP, 0, 0, 0)) < 0)
quit("route-getkerninfo-estimate");
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
mib[2] = 0; /* protocol */
mib[3] = 0; /* wildcard address family */
mib[4] = NET_RT_DUMP;
mib[5] = 0; /* no flags */
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
quit("route-sysctl-estimate");
if ((buf = malloc(needed)) == NULL)
quit("malloc");
if ((rlen = getkerninfo(KINFO_RT_DUMP, buf, &needed, 0)) < 0)
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
quit("actual retrieval of routing table");
lim = buf + rlen;
lim = buf + needed;
if (verbose)
(void) printf("Examining routing table from sysctl\n");
seqno = 0; /* ??? */
for (next = buf; next < lim; next += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *)next;
if (verbose)
print_rtmsg(rtm, rtm->rtm_msglen);
if ((rtm->rtm_flags & RTF_GATEWAY) == 0)
continue;
if (af) {
@ -268,6 +270,8 @@ bad: usage(*argv);
if (sa->sa_family != af)
continue;
}
if (debugonly)
continue;
rtm->rtm_type = RTM_DELETE;
rtm->rtm_seq = seqno;
rlen = write(s, next, rtm->rtm_msglen);
@ -293,7 +297,7 @@ bad: usage(*argv);
}
}
}
char *
routename(sa)
struct sockaddr *sa;
@ -313,14 +317,17 @@ routename(sa)
else
domain[0] = 0;
}
switch (sa->sa_family) {
if (sa->sa_len == 0)
strcpy(line, "default");
else switch (sa->sa_family) {
case AF_INET:
{ struct in_addr in;
in = ((struct sockaddr_in *)sa)->sin_addr;
cp = 0;
if (in.s_addr == INADDR_ANY)
if (in.s_addr == INADDR_ANY || sa->sa_len < 4)
cp = "default";
if (cp == 0 && !nflag) {
hp = gethostbyaddr((char *)&in, sizeof (struct in_addr),
@ -355,12 +362,12 @@ routename(sa)
break;
default:
{ u_short *s = (u_short *)sa->sa_data;
{ u_short *s = (u_short *)sa;
u_short *slim = s + ((sa->sa_len + 1) >> 1);
char *cp = line + sprintf(line, "(%d)", sa->sa_family);
while (s < slim)
cp += sprintf(cp, " %x", *s++);
while (++s < slim) /* start with sa->sa_data */
cp += sprintf(cp, " %x", *s);
break;
}
}
@ -465,7 +472,7 @@ set_metric(value, key)
char *value;
int key;
{
int flag = 0;
int flag = 0;
u_long noval, *valp = &noval;
switch (key) {
@ -493,12 +500,14 @@ newroute(argc, argv)
register char **argv;
{
char *cmd, *dest = "", *gateway = "", *err;
int ishost = 0, ret, attempts, oerrno, flags = 0;
int ishost = 0, ret, attempts, oerrno, flags = RTF_STATIC;
int key;
struct hostent *hp = 0;
if (uid)
if (uid) {
errno = EACCES;
quit("must be root to alter routing table");
}
cmd = argv[0];
if (*cmd != 'g')
shutdown(s, 0); /* Don't want to read back our messages */
@ -523,7 +532,7 @@ newroute(argc, argv)
aflen = sizeof(struct sockaddr_x25);
break;
case K_SA:
af = 0;
af = PF_ROUTE;
aflen = sizeof(union sockunion);
break;
case K_XNS:
@ -533,6 +542,8 @@ newroute(argc, argv)
case K_IFACE:
case K_INTERFACE:
iflag++;
case K_NOSTATIC:
flags &= ~RTF_STATIC;
break;
case K_LOCK:
locking = 1;
@ -546,6 +557,9 @@ newroute(argc, argv)
case K_REJECT:
flags |= RTF_REJECT;
break;
case K_BLACKHOLE:
flags |= RTF_BLACKHOLE;
break;
case K_PROTO1:
flags |= RTF_PROTO1;
break;
@ -558,6 +572,9 @@ newroute(argc, argv)
case K_XRESOLVE:
flags |= RTF_XRESOLVE;
break;
case K_STATIC:
flags |= RTF_STATIC;
break;
case K_IFA:
argc--;
(void) getaddr(RTA_IFA, *++argv, 0);
@ -609,9 +626,14 @@ newroute(argc, argv)
(void) getaddr(RTA_GATEWAY, *argv, &hp);
} else {
int ret = atoi(*argv);
if (ret == 0) {
printf("%s,%s", "old usage of trailing 0",
"assuming route to if\n");
if (strcmp(*argv, "0") == 0)
printf("%s,%s",
"old usage of trailing 0",
"assuming route to if\n");
else
usage((char *)NULL);
iflag = 1;
continue;
} else if (ret > 0 && ret < 10) {
@ -635,22 +657,13 @@ newroute(argc, argv)
flags |= RTF_GATEWAY;
for (attempts = 1; ; attempts++) {
errno = 0;
if (Cflag && (af == AF_INET || af == AF_NS)) {
route.rt_flags = flags;
route.rt_dst = so_dst.sa;
route.rt_gateway = so_gate.sa;
if ((ret = ioctl(s, *cmd == 'a' ? SIOCADDRT : SIOCDELRT,
(caddr_t)&route)) == 0)
break;
} else {
if ((ret = rtmsg(*cmd, flags)) == 0)
break;
}
if ((ret = rtmsg(*cmd, flags)) == 0)
break;
if (errno != ENETUNREACH && errno != ESRCH)
break;
if (af == AF_INET && hp && hp->h_addr_list[1]) {
if (af == AF_INET && *gateway && hp && hp->h_addr_list[1]) {
hp->h_addr_list++;
bcopy(hp->h_addr_list[0], (caddr_t)&so_dst.sin.sin_addr,
bcopy(hp->h_addr_list[0], &so_gate.sin.sin_addr,
hp->h_length);
} else
break;
@ -658,11 +671,13 @@ newroute(argc, argv)
if (*cmd == 'g')
exit(0);
oerrno = errno;
(void) printf("%s %s %s: gateway %s", cmd, ishost? "host" : "net",
dest, gateway);
if (attempts > 1 && ret == 0)
(void) printf(" (%s)",
inet_ntoa(((struct sockaddr_in *)&route.rt_gateway)->sin_addr));
(void) printf("%s %s %s", cmd, ishost? "host" : "net", dest);
if (*gateway) {
(void) printf(": gateway %s", gateway);
if (attempts > 1 && ret == 0 && af == AF_INET)
(void) printf(" (%s)",
inet_ntoa(((struct sockaddr_in *)&route.rt_gateway)->sin_addr));
}
if (ret == 0)
(void) printf("\n");
else {
@ -685,9 +700,9 @@ newroute(argc, argv)
}
void
inet_makenetandmask(net, s_in)
inet_makenetandmask(net, sin)
u_long net;
register struct sockaddr_in *s_in;
register struct sockaddr_in *sin;
{
u_long addr, mask = 0;
register char *cp;
@ -715,15 +730,15 @@ inet_makenetandmask(net, s_in)
else
mask = -1;
}
s_in->sin_addr.s_addr = htonl(addr);
s_in = &so_mask.sin;
s_in->sin_addr.s_addr = htonl(mask);
s_in->sin_len = 0;
s_in->sin_family = 0;
cp = (char *)(&s_in->sin_addr + 1);
while (*--cp == 0 && cp > (char *)s_in)
sin->sin_addr.s_addr = htonl(addr);
sin = &so_mask.sin;
sin->sin_addr.s_addr = htonl(mask);
sin->sin_len = 0;
sin->sin_family = 0;
cp = (char *)(&sin->sin_addr + 1);
while (*--cp == 0 && cp > (char *)sin)
;
s_in->sin_len = 1 + cp - (char *)s_in;
sin->sin_len = 1 + cp - (char *)sin;
}
/*
@ -749,13 +764,31 @@ getaddr(which, s, hpp)
}
rtm_addrs |= which;
switch (which) {
case RTA_DST: su = so_addrs[0]; su->sa.sa_family = af; break;
case RTA_GATEWAY: su = so_addrs[1]; su->sa.sa_family = af; break;
case RTA_NETMASK: su = so_addrs[2]; break;
case RTA_GENMASK: su = so_addrs[3]; break;
case RTA_IFP: su = so_addrs[4]; su->sa.sa_family = af; break;
case RTA_IFA: su = so_addrs[5]; su->sa.sa_family = af; break;
default: usage("Internal Error"); /*NOTREACHED*/
case RTA_DST:
su = &so_dst;
su->sa.sa_family = af;
break;
case RTA_GATEWAY:
su = &so_gate;
su->sa.sa_family = af;
break;
case RTA_NETMASK:
su = &so_mask;
break;
case RTA_GENMASK:
su = &so_genmask;
break;
case RTA_IFP:
su = &so_ifp;
su->sa.sa_family = af;
break;
case RTA_IFA:
su = &so_ifa;
su->sa.sa_family = af;
break;
default:
usage("Internal Error");
/*NOTREACHED*/
}
su->sa.sa_len = aflen;
if (strcmp(s, "default") == 0) {
@ -768,18 +801,50 @@ getaddr(which, s, hpp)
case RTA_GENMASK:
su->sa.sa_len = 0;
}
return 0;
return (0);
}
if (af == AF_NS)
goto do_xns;
if (af == AF_OSI)
goto do_osi;
if (af == AF_LINK)
goto do_link;
if (af == AF_CCITT)
goto do_ccitt;
if (af == 0)
goto do_sa;
switch (af) {
case AF_NS:
if (which == RTA_DST) {
extern short ns_bh[3];
struct sockaddr_ns *sms = &(so_mask.sns);
bzero((char *)sms, sizeof(*sms));
sms->sns_family = 0;
sms->sns_len = 6;
sms->sns_addr.x_net = *(union ns_net *)ns_bh;
rtm_addrs |= RTA_NETMASK;
}
su->sns.sns_addr = ns_addr(s);
return (!ns_nullhost(su->sns.sns_addr));
case AF_OSI:
su->siso.siso_addr = *iso_addr(s);
if (which == RTA_NETMASK || which == RTA_GENMASK) {
register char *cp = (char *)TSEL(&su->siso);
su->siso.siso_nlen = 0;
do {--cp ;} while ((cp > (char *)su) && (*cp == 0));
su->siso.siso_len = 1 + cp - (char *)su;
}
return (1);
case AF_LINK:
link_addr(s, &su->sdl);
return (1);
case AF_CCITT:
ccitt_addr(s, &su->sx25);
return (which == RTA_DST ? x25_makemask() : 1);
case PF_ROUTE:
su->sa.sa_len = sizeof(*su);
sockaddr(s, &su->sa);
return (1);
case AF_INET:
default:
break;
}
if (hpp == NULL)
hpp = &hp;
*hpp = NULL;
@ -790,19 +855,15 @@ getaddr(which, s, hpp)
return (1);
else {
val = ntohl(val);
out: if (which == RTA_DST)
inet_makenetandmask(val, &su->sin);
return (0);
goto netdone;
}
}
val = inet_network(s);
if (val != -1) {
goto out;
}
np = getnetbyname(s);
if (np) {
val = np->n_net;
goto out;
if ((val = inet_network(s)) != -1 ||
((np = getnetbyname(s)) != NULL && (val = np->n_net) != 0)) {
netdone:
if (which == RTA_DST)
inet_makenetandmask(val, &su->sin);
return (0);
}
hp = gethostbyname(s);
if (hp) {
@ -813,37 +874,21 @@ getaddr(which, s, hpp)
}
(void) fprintf(stderr, "%s: bad value\n", s);
exit(1);
do_xns:
if (which == RTA_DST) {
extern short ns_bh[3];
struct sockaddr_ns *sms = &(so_mask.sns);
bzero((char *)sms, sizeof(*sms));
sms->sns_family = 0;
sms->sns_len = 6;
sms->sns_addr.x_net = *(union ns_net *)ns_bh;
}
int
x25_makemask()
{
register char *cp;
if ((rtm_addrs & RTA_NETMASK) == 0) {
rtm_addrs |= RTA_NETMASK;
for (cp = (char *)&so_mask.sx25.x25_net;
cp < &so_mask.sx25.x25_opts.op_flags; cp++)
*cp = -1;
so_mask.sx25.x25_len = (u_char)&(((sup)0)->sx25.x25_opts);
}
su->sns.sns_addr = ns_addr(s);
return (!ns_nullhost(su->sns.sns_addr));
do_osi:
su->siso.siso_addr = *iso_addr(s);
if (which == RTA_NETMASK || which == RTA_GENMASK) {
register char *cp = (char *)TSEL(&su->siso);
su->siso.siso_nlen = 0;
do {--cp ;} while ((cp > (char *)su) && (*cp == 0));
su->siso.siso_len = 1 + cp - (char *)su;
}
return (1);
do_ccitt:
ccitt_addr(s, &su->sx25);
return (1);
do_link:
link_addr(s, &su->sdl);
return (1);
do_sa:
su->sa.sa_len = sizeof(*su);
sockaddr(s, &su->sa);
return (1);
return 0;
}
short ns_nullh[] = {0,0,0};
@ -872,7 +917,7 @@ ns_print(sns)
return (mybuf);
}
if (bcmp((char *)ns_bh, (char *)work.x_host.c_host, 6) == 0)
if (bcmp((char *)ns_bh, (char *)work.x_host.c_host, 6) == 0)
host = "any";
else if (bcmp((char *)ns_nullh, (char *)work.x_host.c_host, 6) == 0)
host = "*";
@ -893,6 +938,33 @@ ns_print(sns)
return (mybuf);
}
void
interfaces()
{
size_t needed;
int mib[6];
char *buf, *lim, *next;
register struct rt_msghdr *rtm;
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
mib[2] = 0; /* protocol */
mib[3] = 0; /* wildcard address family */
mib[4] = NET_RT_IFLIST;
mib[5] = 0; /* no flags */
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
quit("route-sysctl-estimate");
if ((buf = malloc(needed)) == NULL)
quit("malloc");
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
quit("actual retrieval of interface table");
lim = buf + needed;
for (next = buf; next < lim; next += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *)next;
print_rtmsg(rtm, rtm->rtm_msglen);
}
}
void
monitor()
{
@ -900,10 +972,14 @@ monitor()
char msg[2048];
verbose = 1;
if (debugonly) {
interfaces();
exit(0);
}
for(;;) {
n = read(s, msg, 2048);
(void) printf("got message of size %d\n", n);
print_rtmsg((struct rt_msghdr *)msg);
print_rtmsg((struct rt_msghdr *)msg, n);
}
}
@ -933,9 +1009,14 @@ rtmsg(cmd, flags)
cmd = RTM_ADD;
else if (cmd == 'c')
cmd = RTM_CHANGE;
else if (cmd == 'g')
else if (cmd == 'g') {
cmd = RTM_GET;
else
if (so_ifp.sa.sa_family == 0) {
so_ifp.sa.sa_family == AF_LINK;
so_ifp.sa.sa_len == sizeof(struct sockaddr_dl);
rtm_addrs |= RTA_IFP;
}
} else
cmd = RTM_DELETE;
#define rtm m_rtmsg.m_rtm
rtm.rtm_type = cmd;
@ -958,7 +1039,7 @@ rtmsg(cmd, flags)
if (verbose)
print_rtmsg(&rtm, l);
if (debugonly)
return 0;
return (0);
if ((rlen = write(s, (char *)&m_rtmsg, l)) < 0) {
perror("writing to routing socket");
return (-1);
@ -978,18 +1059,29 @@ rtmsg(cmd, flags)
return (0);
}
mask_addr() {
register char *cp1, *cp2;
int olen;
void
mask_addr()
{
int olen = so_mask.sa.sa_len;
register char *cp1 = olen + (char *)&so_mask, *cp2;
for (so_mask.sa.sa_len = 0; cp1 > (char *)&so_mask; )
if (*--cp1 != 0) {
so_mask.sa.sa_len = 1 + cp1 - (char *)&so_mask;
break;
}
if ((rtm_addrs & RTA_DST) == 0)
return;
switch(so_dst.sa.sa_family) {
switch (so_dst.sa.sa_family) {
case AF_NS:
case AF_INET: case 0:
case AF_INET:
case AF_CCITT:
case 0:
return;
case AF_ISO:
olen = MIN(so_dst.siso.siso_nlen, so_mask.sa.sa_len - 6);
olen = MIN(so_dst.siso.siso_nlen,
MAX(so_mask.sa.sa_len - 6, 0));
break;
}
cp1 = so_mask.sa.sa_len + 1 + (char *)&so_dst;
cp2 = so_dst.sa.sa_len + 1 + (char *)&so_dst;
@ -998,9 +1090,10 @@ mask_addr() {
cp2 = so_mask.sa.sa_len + 1 + (char *)&so_mask;
while (cp1 > so_dst.sa.sa_data)
*--cp1 &= *--cp2;
switch(so_dst.sa.sa_family) {
switch (so_dst.sa.sa_family) {
case AF_ISO:
so_dst.siso.siso_nlen = olen;
break;
}
}
@ -1016,20 +1109,30 @@ char *msgtypes[] = {
"RTM_LOCK: fix specified metrics",
"RTM_OLDADD: caused by SIOCADDRT",
"RTM_OLDDEL: caused by SIOCDELRT",
"RTM_RESOLVE: Route created by cloning",
"RTM_NEWADDR: address being added to iface",
"RTM_DELADDR: address being removed from iface",
"RTM_IFINFO: iface status change",
0,
};
char metricnames[] =
"\010rttvar\7rtt\6ssthresh\5sendpipe\4recvpipe\3expire\2hopcount\1mtu";
char routeflags[] =
"\1UP\2GATEWAY\3HOST\4REJECT\5DYNAMIC\6MODIFIED\7DONE\010MASK_PRESENT\011CLONING\012XRESOLVE\013LLINFO\017PROTO2\020PROTO1";
"\011pksent\010rttvar\7rtt\6ssthresh\5sendpipe\4recvpipe\3expire\2hopcount\1mtu";
char routeflags[] =
"\1UP\2GATEWAY\3HOST\4REJECT\5DYNAMIC\6MODIFIED\7DONE\010MASK_PRESENT\011CLONING\012XRESOLVE\013LLINFO\014STATIC\017PROTO2\020PROTO1";
char ifnetflags[] =
"\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5PTP\6NOTRAILERS\7RUNNING\010NOARP\011PPROMISC\012ALLMULTI\013OACTIVE\014SIMPLEX\015LINK0\016LINK1\017LINK2\020MULTICAST";
char addrnames[] =
"\1DST\2GATEWAY\3NETMASK\4GENMASK\5IFP\6IFA\7AUTHOR\010BRD";
void
print_rtmsg(rtm, msglen)
register struct rt_msghdr *rtm;
int msglen;
{
struct if_msghdr *ifm;
struct ifa_msghdr *ifam;
if (verbose == 0)
return;
if (rtm->rtm_version != RTM_VERSION) {
@ -1037,11 +1140,27 @@ print_rtmsg(rtm, msglen)
rtm->rtm_version);
return;
}
(void) printf("%s\npid: %d, len %d, seq %d, errno %d, flags:",
msgtypes[rtm->rtm_type], rtm->rtm_pid, rtm->rtm_msglen,
rtm->rtm_seq, rtm->rtm_errno);
bprintf(stdout, rtm->rtm_flags, routeflags);
pmsg_common(rtm);
(void)printf("%s: len %d, ", msgtypes[rtm->rtm_type], rtm->rtm_msglen);
switch (rtm->rtm_type) {
case RTM_IFINFO:
ifm = (struct if_msghdr *)rtm;
(void) printf("if# %d, flags:", ifm->ifm_index);
bprintf(stdout, ifm->ifm_flags, ifnetflags);
pmsg_addrs((char *)(ifm + 1), ifm->ifm_addrs);
break;
case RTM_NEWADDR:
case RTM_DELADDR:
ifam = (struct ifa_msghdr *)rtm;
(void) printf("metric %d, flags:", ifam->ifam_metric);
bprintf(stdout, ifam->ifam_flags, routeflags);
pmsg_addrs((char *)(ifam + 1), ifam->ifam_addrs);
break;
default:
(void) printf("pid: %d, seq %d, errno %d, flags:",
rtm->rtm_pid, rtm->rtm_seq, rtm->rtm_errno);
bprintf(stdout, rtm->rtm_flags, routeflags);
pmsg_common(rtm);
}
}
void
@ -1049,56 +1168,129 @@ print_getmsg(rtm, msglen)
register struct rt_msghdr *rtm;
int msglen;
{
struct sockaddr *dst = NULL, *gate = NULL, *mask = NULL;
struct sockaddr_dl *ifp = NULL;
register struct sockaddr *sa;
register char *cp;
register int i;
(void) printf(" route to: %s\n", routename(&so_dst));
if (rtm->rtm_version != RTM_VERSION) {
(void)printf("routing message version %d not understood\n",
(void)fprintf(stderr,
"routing message version %d not understood\n",
rtm->rtm_version);
return;
}
if (rtm->rtm_msglen > msglen) {
(void)printf("get length mismatch, in packet %d, returned %d\n",
(void)fprintf(stderr,
"message length mismatch, in packet %d, returned %d\n",
rtm->rtm_msglen, msglen);
}
(void) printf("RTM_GET: errno %d, flags:", rtm->rtm_errno);
if (rtm->rtm_errno) {
(void) fprintf(stderr, "RTM_GET: %s (errno %d)\n",
strerror(rtm->rtm_errno), rtm->rtm_errno);
return;
}
cp = ((char *)(rtm + 1));
if (rtm->rtm_addrs)
for (i = 1; i; i <<= 1)
if (i & rtm->rtm_addrs) {
sa = (struct sockaddr *)cp;
switch (i) {
case RTA_DST:
dst = sa;
break;
case RTA_GATEWAY:
gate = sa;
break;
case RTA_NETMASK:
mask = sa;
break;
case RTA_IFP:
if (sa->sa_family == AF_LINK &&
((struct sockaddr_dl *)sa)->sdl_nlen)
ifp = (struct sockaddr_dl *)sa;
break;
}
ADVANCE(cp, sa);
}
if (dst && mask)
mask->sa_family = dst->sa_family; /* XXX */
if (dst)
(void)printf("destination: %s\n", routename(dst));
if (mask) {
int savenflag = nflag;
nflag = 1;
(void)printf(" mask: %s\n", routename(mask));
nflag = savenflag;
}
if (gate && rtm->rtm_flags & RTF_GATEWAY)
(void)printf(" gateway: %s\n", routename(gate));
if (ifp)
(void)printf(" interface: %.*s\n",
ifp->sdl_nlen, ifp->sdl_data);
(void)printf(" flags: ");
bprintf(stdout, rtm->rtm_flags, routeflags);
(void) printf("\nmetric values:\n ");
#define metric(f, e)\
printf("%s: %d%s", __STRING(f), rtm->rtm_rmx.__CONCAT(rmx_,f), e)
metric(recvpipe, ", ");
metric(sendpipe, ", ");
metric(ssthresh, ", ");
metric(rtt, "\n ");
metric(rttvar, ", ");
metric(hopcount, ", ");
metric(mtu, ", ");
metric(expire, "\n");
#undef metric
pmsg_common(rtm);
#define lock(f) ((rtm->rtm_rmx.rmx_locks & __CONCAT(RTV_,f)) ? 'L' : ' ')
#define msec(u) (((u) + 500) / 1000) /* usec to msec */
(void) printf("\n%s\n", "\
recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire");
printf("%8d%c ", rtm->rtm_rmx.rmx_recvpipe, lock(RPIPE));
printf("%8d%c ", rtm->rtm_rmx.rmx_sendpipe, lock(SPIPE));
printf("%8d%c ", rtm->rtm_rmx.rmx_ssthresh, lock(SSTHRESH));
printf("%8d%c ", msec(rtm->rtm_rmx.rmx_rtt), lock(RTT));
printf("%8d%c ", msec(rtm->rtm_rmx.rmx_rttvar), lock(RTTVAR));
printf("%8d%c ", rtm->rtm_rmx.rmx_hopcount, lock(HOPCOUNT));
printf("%8d%c ", rtm->rtm_rmx.rmx_mtu, lock(MTU));
if (rtm->rtm_rmx.rmx_expire)
rtm->rtm_rmx.rmx_expire -= time(0);
printf("%8d%c\n", rtm->rtm_rmx.rmx_expire, lock(EXPIRE));
#undef lock
#undef msec
#define RTA_IGN (RTA_DST|RTA_GATEWAY|RTA_NETMASK|RTA_IFP|RTA_IFA|RTA_BRD)
if (verbose)
pmsg_common(rtm);
else if (rtm->rtm_addrs &~ RTA_IGN) {
(void) printf("sockaddrs: ");
bprintf(stdout, rtm->rtm_addrs, addrnames);
putchar('\n');
}
#undef RTA_IGN
}
void
pmsg_common(rtm)
register struct rt_msghdr *rtm;
{
char *cp;
register struct sockaddr *sa;
int i;
(void) printf("\nlocks: ");
bprintf(stdout, rtm->rtm_rmx.rmx_locks, metricnames);
(void) printf(" inits: ");
bprintf(stdout, rtm->rtm_inits, metricnames);
pmsg_addrs(((char *)(rtm + 1)), rtm->rtm_addrs);
}
void
pmsg_addrs(cp, addrs)
char *cp;
int addrs;
{
register struct sockaddr *sa;
int i;
if (addrs == 0)
return;
(void) printf("\nsockaddrs: ");
bprintf(stdout, rtm->rtm_addrs,
"\1DST\2GATEWAY\3NETMASK\4GENMASK\5IFP\6IFA\7AUTHOR");
bprintf(stdout, addrs, addrnames);
(void) putchar('\n');
cp = ((char *)(rtm + 1));
if (rtm->rtm_addrs)
for (i = 1; i; i <<= 1)
if (i & rtm->rtm_addrs) {
sa = (struct sockaddr *)cp;
(void) printf(" %s", routename(sa));
ADVANCE(cp, sa);
}
for (i = 1; i; i <<= 1)
if (i & addrs) {
sa = (struct sockaddr *)cp;
(void) printf(" %s", routename(sa));
ADVANCE(cp, sa);
}
(void) putchar('\n');
(void) fflush(stdout);
}
@ -1168,6 +1360,7 @@ sodump(su, which)
}
(void) fflush(stdout);
}
/* States*/
#define VIRGIN 0
#define GOTONE 1
@ -1179,8 +1372,8 @@ sodump(su, which)
void
sockaddr(addr, sa)
register char *addr;
register struct sockaddr *sa;
register char *addr;
register struct sockaddr *sa;
{
register char *cp = (char *)sa;
int size = sa->sa_len;
@ -1188,6 +1381,7 @@ register struct sockaddr *sa;
register int byte = 0, state = VIRGIN, new;
bzero(cp, size);
cp++;
do {
if ((*addr >= '0') && (*addr <= '9')) {
new = *addr - '0';
@ -1195,7 +1389,7 @@ register struct sockaddr *sa;
new = *addr - 'a' + 10;
} else if ((*addr >= 'A') && (*addr <= 'F')) {
new = *addr - 'A' + 10;
} else if (*addr == 0)
} else if (*addr == 0)
state |= END;
else
state |= DELIM;
@ -1216,6 +1410,6 @@ register struct sockaddr *sa;
break;
}
break;
} while (cp < cplim);
} while (cp < cplim);
sa->sa_len = cp - (char *)sa;
}

View File

@ -1,11 +1,13 @@
# from: @(#)Makefile 5.16 (Berkeley) 4/26/91
# $Id: Makefile,v 1.8 1994/01/28 00:38:59 cgd Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/19/93
# $Id: Makefile,v 1.9 1994/05/13 08:04:29 mycroft Exp $
PROG= routed
SRCS= af.c if.c input.c main.c output.c startup.c tables.c timer.c \
trace.c inet.c
MAN8= routed.0
#SUBDIR= query trace
SUBDIR= query trace
DPADD= ${LIBCOMPAT}
LDADD= -lcompat
.include <bsd.prog.mk>

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
* Copyright (c) 1983, 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
@ -32,8 +32,8 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)af.c 5.11 (Berkeley) 2/28/91";*/
static char rcsid[] = "$Id: af.c,v 1.4 1993/08/01 18:24:32 mycroft Exp $";
/*static char sccsid[] = "from: @(#)af.c 8.1 (Berkeley) 6/5/93";*/
static char *rcsid = "$Id: af.c,v 1.5 1994/05/13 08:04:31 mycroft Exp $";
#endif /* not lint */
#include "defs.h"

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
* Copyright (c) 1983, 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
@ -30,8 +30,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)af.h 5.7 (Berkeley) 6/1/90
* $Id: af.h,v 1.5 1993/12/30 10:44:15 cgd Exp $
* from: @(#)af.h 8.1 (Berkeley) 6/5/93
* $Id: af.h,v 1.6 1994/05/13 08:04:32 mycroft Exp $
*/
/*

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983, 1988 Regents of the University of California.
* All rights reserved.
* 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
@ -30,8 +30,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)defs.h 5.10 (Berkeley) 2/28/91
* $Id: defs.h,v 1.5 1994/04/13 04:29:54 cgd Exp $
* from: @(#)defs.h 8.1 (Berkeley) 6/5/93
* $Id: defs.h,v 1.6 1994/05/13 08:04:34 mycroft Exp $
*/
/*
@ -69,11 +69,15 @@
struct sockaddr_in addr; /* address of daemon's socket */
int s; /* source and sink of all data */
int r; /* routing socket */
pid_t pid; /* process id for identifying messages */
uid_t uid; /* user id for identifying messages */
int seqno; /* sequence number for identifying messages */
int kmem;
int supplier; /* process should supply updates */
int install; /* if 1 call kernel */
int lookforinterfaces; /* if 1 probe kernel for new up interfaces */
int performnlist; /* if 1 check if /netbsd has changed */
int performnlist; /* if 1 check if /vmunix has changed */
int externalinterfaces; /* # of remote and local interfaces */
struct timeval now; /* current idea of time */
struct timeval lastbcast; /* last time all/changes broadcast */
@ -89,6 +93,12 @@ struct servent *sp;
struct in_addr inet_makeaddr();
int inet_addr();
int inet_maskof();
int sndmsg();
int supply();
int cleanup();
int rtioctl();
#define ADD 1
#define DELETE 2
#define CHANGE 3

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
* Copyright (c) 1983, 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
@ -32,8 +32,8 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)if.c 5.6 (Berkeley) 6/1/90";*/
static char rcsid[] = "$Id: if.c,v 1.4 1993/08/01 18:24:30 mycroft Exp $";
/*static char sccsid[] = "from: @(#)if.c 8.1 (Berkeley) 6/5/93";*/
static char *rcsid = "$Id: if.c,v 1.5 1994/05/13 08:04:35 mycroft Exp $";
#endif /* not lint */
/*

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
* Copyright (c) 1983, 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
@ -32,8 +32,8 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)inet.c 5.8 (Berkeley) 6/1/90";*/
static char rcsid[] = "$Id: inet.c,v 1.4 1993/08/01 18:24:29 mycroft Exp $";
/*static char sccsid[] = "from: @(#)inet.c 8.2 (Berkeley) 8/14/93";*/
static char *rcsid = "$Id: inet.c,v 1.5 1994/05/13 08:04:37 mycroft Exp $";
#endif /* not lint */
/*
@ -129,6 +129,35 @@ inet_lnaof(in)
return (host);
}
/*
* Return the netmask pertaining to an internet address.
*/
inet_maskof(inaddr)
u_long inaddr;
{
register u_long i = ntohl(inaddr);
register u_long mask;
register struct interface *ifp;
if (i == 0) {
mask = 0;
} else if (IN_CLASSA(i)) {
mask = IN_CLASSA_NET;
} else if (IN_CLASSB(i)) {
mask = i & IN_CLASSB_NET;
} else
mask = i & IN_CLASSC_NET;
/*
* Check whether network is a subnet;
* if so, use the modified interpretation of `host'.
*/
for (ifp = ifnet; ifp; ifp = ifp->int_next)
if ((ifp->int_netmask & i) == ifp->int_net)
mask = ifp->int_subnetmask;
return (htonl(mask));
}
/*
* Return RTF_HOST if the address is
* for an Internet host, RTF_SUBNET for a subnet,

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983, 1988 Regents of the University of California.
* All rights reserved.
* 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
@ -32,8 +32,8 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)input.c 5.22 (Berkeley) 6/1/90";*/
static char rcsid[] = "$Id: input.c,v 1.4 1993/08/01 18:24:28 mycroft Exp $";
/*static char sccsid[] = "from: @(#)input.c 8.1 (Berkeley) 6/5/93";*/
static char *rcsid = "$Id: input.c,v 1.5 1994/05/13 08:04:39 mycroft Exp $";
#endif /* not lint */
/*

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
* Copyright (c) 1983, 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
@ -30,8 +30,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)interface.h 5.6 (Berkeley) 6/1/90
* $Id: interface.h,v 1.5 1993/12/11 01:47:28 cgd Exp $
* from: @(#)interface.h 8.1 (Berkeley) 6/5/93
* $Id: interface.h,v 1.6 1994/05/13 08:04:41 mycroft Exp $
*/
/*
@ -80,12 +80,10 @@ struct interface {
#define IFF_LOOPBACK 0x8 /* software loopback net */
#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
#define IFF_FLAGMASK 0x1f /* mask for relevant int_flags bits */
#define IFF_SUBNET 0x1000 /* interface on subnetted network */
#define IFF_PASSIVE 0x2000 /* can't tell if up/down */
#define IFF_INTERFACE 0x4000 /* hardware interface */
#define IFF_REMOTE 0x8000 /* interface isn't on this machine */
#define IFF_SUBNET 0x100000 /* interface on subnetted network */
#define IFF_PASSIVE 0x200000 /* can't tell if up/down */
#define IFF_INTERFACE 0x400000 /* hardware interface */
#define IFF_REMOTE 0x800000 /* interface isn't on this machine */
struct interface *if_ifwithaddr();
struct interface *if_ifwithdstaddr();

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983, 1988 Regents of the University of California.
* All rights reserved.
* 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
@ -32,14 +32,14 @@
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1983, 1988 Regents of the University of California.\n\
All rights reserved.\n";
static char copyright[] =
"@(#) Copyright (c) 1983, 1988, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
/*static char sccsid[] = "from: @(#)main.c 5.23 (Berkeley) 7/1/91";*/
static char rcsid[] = "$Id: main.c,v 1.4 1993/08/01 18:24:26 mycroft Exp $";
/*static char sccsid[] = "from: @(#)main.c 8.1 (Berkeley) 6/5/93";*/
static char *rcsid = "$Id: main.c,v 1.5 1994/05/13 08:04:43 mycroft Exp $";
#endif /* not lint */
/*
@ -92,6 +92,14 @@ main(argc, argv)
}
addr.sin_family = AF_INET;
addr.sin_port = sp->s_port;
r = socket(AF_ROUTE, SOCK_RAW, 0);
/* later, get smart about lookingforinterfaces */
if (r)
shutdown(r, 0); /* for now, don't want reponses */
else {
fprintf(stderr, "routed: no routing socket\n");
exit(1);
}
s = getsocket(AF_INET, SOCK_DGRAM, &addr);
if (s < 0)
exit(1);
@ -129,7 +137,7 @@ main(argc, argv)
exit(1);
}
if (debug == 0)
if (debug == 0 && tflags == 0)
daemon(0, 0);
/*
* Any extra argument is considered

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983, 1988 Regents of the University of California.
* All rights reserved.
* 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
@ -32,8 +32,8 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)output.c 5.15 (Berkeley) 2/28/91";*/
static char rcsid[] = "$Id: output.c,v 1.4 1993/08/01 18:24:24 mycroft Exp $";
/*static char sccsid[] = "from: @(#)output.c 8.1 (Berkeley) 6/5/93";*/
static char *rcsid = "$Id: output.c,v 1.5 1994/05/13 08:04:45 mycroft Exp $";
#endif /* not lint */
/*

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1989, 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
@ -30,8 +30,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)pathnames.h 5.3 (Berkeley) 6/1/90
* $Id: pathnames.h,v 1.4 1993/08/01 18:24:35 mycroft Exp $
* from: @(#)pathnames.h 8.1 (Berkeley) 6/5/93
* $Id: pathnames.h,v 1.5 1994/05/13 08:04:46 mycroft Exp $
*/
#include <paths.h>

View File

@ -1,5 +1,5 @@
# from: @(#)Makefile 5.6 (Berkeley) 5/11/90
# $Id: Makefile,v 1.4 1993/08/01 00:57:22 mycroft Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/5/93
# $Id: Makefile,v 1.5 1994/05/13 08:05:02 mycroft Exp $
PROG= query
NOMAN= noman

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 1982, 1986 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1982, 1986, 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
@ -32,14 +32,14 @@
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1982, 1986 The Regents of the University of California.\n\
All rights reserved.\n";
static char copyright[] =
"@(#) Copyright (c) 1982, 1986, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
/*static char sccsid[] = "from: @(#)query.c 5.13 (Berkeley) 4/16/91";*/
static char rcsid[] = "$Id: query.c,v 1.4 1993/08/01 18:24:51 mycroft Exp $";
/*static char sccsid[] = "from: @(#)query.c 8.1 (Berkeley) 6/5/93";*/
static char *rcsid = "$Id: query.c,v 1.5 1994/05/13 08:05:03 mycroft Exp $";
#endif /* not lint */
#include <sys/param.h>
@ -74,11 +74,12 @@ main(argc, argv)
extern int optind;
int ch, cc, count, bits;
struct sockaddr from;
struct sigaction sigact;
int fromlen = sizeof(from), size = 32*1024;
struct timeval shorttime;
while ((ch = getopt(argc, argv, "n")) != EOF)
switch((char)ch) {
switch (ch) {
case 'n':
nflag++;
break;
@ -113,7 +114,11 @@ usage: printf("usage: query [-n] hosts...\n");
bits = 1 << s;
bzero(&shorttime, sizeof(shorttime));
shorttime.tv_usec = STIME;
signal(SIGALRM, timeout);
bzero(&sigact, sizeof(sigact));
sigact.sa_handler = timeout;
/*sigact.sa_flags = 0; /* no restart */
if (sigaction(SIGALRM, &sigact, (struct sigaction *)NULL) == -1)
perror("sigaction");
alarm(WTIME);
while ((count > 0 && !timedout) ||
select(20, (fd_set *)&bits, NULL, NULL, &shorttime) > 0) {

View File

@ -1,5 +1,5 @@
.\" Copyright (c) 1983, 1991 The Regents of the University of California.
.\" All rights reserved.
.\" Copyright (c) 1983, 1991, 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
@ -29,10 +29,10 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" from: @(#)routed.8 6.6 (Berkeley) 3/16/91
.\" $Id: routed.8,v 1.4 1993/08/01 07:38:15 mycroft Exp $
.\" from: @(#)routed.8 8.2 (Berkeley) 12/11/93
.\" $Id: routed.8,v 1.5 1994/05/13 08:04:48 mycroft Exp $
.\"
.Dd March 16, 1991
.Dd December 11, 1993
.Dt ROUTED 8
.Os BSD 4.2
.Sh NAME
@ -230,7 +230,7 @@ any routing information transmitted.
Active gateways are treated equally to network
interfaces. Routing information is distributed
to the gateway and if no routing information is
received for a period of the time, the associated
received for a period of time, the associated
route is deleted.
Gateways marked
.Em external
@ -311,8 +311,6 @@ rather then using a static routing table of passive gateways.
.Tn EGP
is required in order to provide routes for local networks to the rest
of the Internet system.
Sites needing assistance with such configurations
should contact the Computer Systems Research Group at Berkeley.
.Sh FILES
.Bl -tag -width /etc/gateways -compact
.It Pa /etc/gateways

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983, 1988 Regents of the University of California.
* All rights reserved.
* 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
@ -32,8 +32,8 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)startup.c 5.19 (Berkeley) 2/28/91";*/
static char rcsid[] = "$Id: startup.c,v 1.5 1993/12/11 01:47:32 cgd Exp $";
/*static char sccsid[] = "from: @(#)startup.c 8.1 (Berkeley) 6/5/93";*/
static char *rcsid = "$Id: startup.c,v 1.6 1994/05/13 08:04:50 mycroft Exp $";
#endif /* not lint */
/*
@ -41,7 +41,9 @@ static char rcsid[] = "$Id: startup.c,v 1.5 1993/12/11 01:47:32 cgd Exp $";
*/
#include "defs.h"
#include <sys/ioctl.h>
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <syslog.h>
#include <stdlib.h>
#include "pathnames.h"
@ -53,6 +55,49 @@ int externalinterfaces = 0; /* # of remote and local interfaces */
int foundloopback; /* valid flag for loopaddr */
struct sockaddr loopaddr; /* our address on loopback */
void
quit(s)
char *s;
{
extern int errno;
int sverrno = errno;
(void) fprintf(stderr, "route: ");
if (s)
(void) fprintf(stderr, "%s: ", s);
(void) fprintf(stderr, "%s\n", strerror(sverrno));
exit(1);
/* NOTREACHED */
}
struct rt_addrinfo info;
/* Sleazy use of local variables throughout file, warning!!!! */
#define netmask info.rti_info[RTAX_NETMASK]
#define ifaaddr info.rti_info[RTAX_IFA]
#define brdaddr info.rti_info[RTAX_BRD]
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
void
rt_xaddrs(cp, cplim, rtinfo)
register caddr_t cp, cplim;
register struct rt_addrinfo *rtinfo;
{
register struct sockaddr *sa;
register int i;
bzero(rtinfo->rti_info, sizeof(rtinfo->rti_info));
for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) {
if ((rtinfo->rti_addrs & (1 << i)) == 0)
continue;
rtinfo->rti_info[i] = sa = (struct sockaddr *)cp;
ADVANCE(cp, sa);
}
}
/*
* Find the network interfaces which have configured themselves.
* If the interface is present but not yet up (for example an
@ -62,66 +107,67 @@ struct sockaddr loopaddr; /* our address on loopback */
ifinit()
{
struct interface ifs, *ifp;
int s;
char buf[BUFSIZ], *cp, *cplim;
struct ifconf ifc;
struct ifreq ifreq, *ifr;
size_t needed;
int mib[6], no_ipaddr = 0, flags = 0;
char *buf, *cplim, *cp;
register struct if_msghdr *ifm;
register struct ifa_msghdr *ifam;
struct sockaddr_dl *sdl;
struct sockaddr_in *sin;
u_long i;
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
syslog(LOG_ERR, "socket: %m");
close(s);
return;
}
ifc.ifc_len = sizeof (buf);
ifc.ifc_buf = buf;
if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) {
syslog(LOG_ERR, "ioctl (get interface configuration)");
close(s);
return;
}
ifr = ifc.ifc_req;
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
mib[2] = 0;
mib[3] = AF_INET;
mib[4] = NET_RT_IFLIST;
mib[5] = 0;
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
quit("route-sysctl-estimate");
if ((buf = malloc(needed)) == NULL)
quit("malloc");
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
quit("actual retrieval of interface table");
lookforinterfaces = 0;
#ifdef RTM_ADD
#define max(a, b) (a > b ? a : b)
#define size(p) max((p).sa_len, sizeof(p))
#else
#define size(p) (sizeof (p))
#endif
cplim = buf + ifc.ifc_len; /*skip over if's with big ifr_addr's */
for (cp = buf; cp < cplim;
cp += sizeof (ifr->ifr_name) + size(ifr->ifr_addr)) {
ifr = (struct ifreq *)cp;
bzero((char *)&ifs, sizeof(ifs));
ifs.int_addr = ifr->ifr_addr;
ifreq = *ifr;
if (ioctl(s, SIOCGIFFLAGS, (char *)&ifreq) < 0) {
syslog(LOG_ERR, "%s: ioctl (get interface flags)",
ifr->ifr_name);
continue;
}
ifs.int_flags =
(ifreq.ifr_flags & IFF_FLAGMASK) | IFF_INTERFACE;
if ((ifs.int_flags & IFF_UP) == 0 ||
ifr->ifr_addr.sa_family == AF_UNSPEC) {
lookforinterfaces = 1;
cplim = buf + needed;
for (cp = buf; cp < cplim; cp += ifm->ifm_msglen) {
ifm = (struct if_msghdr *)cp;
if (ifm->ifm_type == RTM_IFINFO) {
bzero(&ifs, sizeof(ifs));
ifs.int_flags = flags = (0xffff & ifm->ifm_flags) | IFF_INTERFACE;
if ((flags & IFF_UP) == 0 || no_ipaddr)
lookforinterfaces = 1;
sdl = (struct sockaddr_dl *) (ifm + 1);
sdl->sdl_data[sdl->sdl_nlen] = 0;
no_ipaddr = 1;
continue;
}
/* argh, this'll have to change sometime */
if (ifm->ifm_type != RTM_NEWADDR)
quit("ifinit: out of sync");
if ((flags & IFF_UP) == 0)
continue;
ifam = (struct ifa_msghdr *)ifm;
info.rti_addrs = ifam->ifam_addrs;
rt_xaddrs((char *)(ifam + 1), cp + ifam->ifam_msglen, &info);
if (ifaaddr == 0) {
syslog(LOG_ERR, "%s: (get addr)", sdl->sdl_data);
continue;
}
ifs.int_addr = *ifaaddr;
if (ifs.int_addr.sa_family != AF_INET)
continue;
if (ifs.int_flags & IFF_POINTOPOINT) {
if (ioctl(s, SIOCGIFDSTADDR, (char *)&ifreq) < 0) {
syslog(LOG_ERR, "%s: ioctl (get dstaddr)",
ifr->ifr_name);
continue;
no_ipaddr = 0;
if (ifs.int_flags & IFF_POINTOPOINT) {
if (brdaddr == 0) {
syslog(LOG_ERR, "%s: (get dstaddr)",
sdl->sdl_data);
continue;
}
if (ifr->ifr_addr.sa_family == AF_UNSPEC) {
if (brdaddr->sa_family == AF_UNSPEC) {
lookforinterfaces = 1;
continue;
}
ifs.int_dstaddr = ifreq.ifr_dstaddr;
ifs.int_dstaddr = *brdaddr;
}
/*
* already known to us?
@ -143,40 +189,26 @@ ifinit()
if (ifp->int_flags & IFF_POINTOPOINT)
add_ptopt_localrt(ifp);
}
if (ifs.int_flags & IFF_BROADCAST) {
if (ioctl(s, SIOCGIFBRDADDR, (char *)&ifreq) < 0) {
syslog(LOG_ERR, "%s: ioctl (get broadaddr)",
ifr->ifr_name);
continue;
}
#ifndef sun
ifs.int_broadaddr = ifreq.ifr_broadaddr;
#else
ifs.int_broadaddr = ifreq.ifr_addr;
#endif
if (ifs.int_flags & IFF_BROADCAST) {
if (brdaddr == 0) {
syslog(LOG_ERR, "%s: (get broadaddr)",
sdl->sdl_data);
continue;
}
ifs.int_dstaddr = *brdaddr;
}
#ifdef SIOCGIFMETRIC
if (ioctl(s, SIOCGIFMETRIC, (char *)&ifreq) < 0) {
syslog(LOG_ERR, "%s: ioctl (get metric)",
ifr->ifr_name);
ifs.int_metric = 0;
} else
ifs.int_metric = ifreq.ifr_metric;
#else
ifs.int_metric = 0;
#endif
/*
* Use a minimum metric of one;
* treat the interface metric (default 0)
* as an increment to the hop count of one.
*/
ifs.int_metric++;
if (ioctl(s, SIOCGIFNETMASK, (char *)&ifreq) < 0) {
syslog(LOG_ERR, "%s: ioctl (get netmask)",
ifr->ifr_name);
continue;
ifs.int_metric = ifam->ifam_metric + 1;
if (netmask == 0) {
syslog(LOG_ERR, "%s: (get netmask)",
sdl->sdl_data);
continue;
}
sin = (struct sockaddr_in *)&ifreq.ifr_addr;
sin = (struct sockaddr_in *)netmask;
ifs.int_subnetmask = ntohl(sin->sin_addr.s_addr);
sin = (struct sockaddr_in *)&ifs.int_addr;
i = ntohl(sin->sin_addr.s_addr);
@ -190,9 +222,11 @@ ifinit()
ifs.int_subnet = i & ifs.int_subnetmask;
if (ifs.int_subnetmask != ifs.int_netmask)
ifs.int_flags |= IFF_SUBNET;
ifp = (struct interface *)malloc(sizeof (struct interface));
ifp = (struct interface *)
malloc(sdl->sdl_nlen + 1 + sizeof(ifs));
if (ifp == 0) {
printf("routed: out of memory\n");
lookforinterfaces = 1;
break;
}
*ifp = ifs;
@ -214,14 +248,8 @@ ifinit()
*/
if ((ifs.int_flags & IFF_POINTOPOINT) && supplier < 0)
supplier = 1;
ifp->int_name = malloc(strlen(ifr->ifr_name) + 1);
if (ifp->int_name == 0) {
fprintf(stderr, "routed: ifinit: out of memory\n");
syslog(LOG_ERR, "routed: ifinit: out of memory\n");
close(s);
return;
}
strcpy(ifp->int_name, ifr->ifr_name);
ifp->int_name = (char *)(ifp + 1);
strcpy(ifp->int_name, sdl->sdl_data);
*ifnext = ifp;
ifnext = &ifp->int_next;
traceinit(ifp);
@ -229,7 +257,7 @@ ifinit()
}
if (externalinterfaces > 1 && supplier < 0)
supplier = 1;
close(s);
free(buf);
}
/*
@ -391,7 +419,7 @@ gwkludge()
route.rt_flags |= RTF_HOST;
if (metric)
route.rt_flags |= RTF_GATEWAY;
(void) ioctl(s, SIOCADDRT, (char *)&route.rt_rt);
(void) rtioctl(ADD, &route.rt_rt);
continue;
}
if (strcmp(qual, "external") == 0) {

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
* Copyright (c) 1983, 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
@ -30,8 +30,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)table.h 5.8 (Berkeley) 6/1/90
* $Id: table.h,v 1.4 1993/08/01 18:24:34 mycroft Exp $
* from: @(#)table.h 8.1 (Berkeley) 6/5/93
* $Id: table.h,v 1.5 1994/05/13 08:04:52 mycroft Exp $
*/
/*
@ -57,12 +57,14 @@ struct rt_entry {
struct rt_entry *rt_back;
union {
struct rtentry rtu_rt;
struct {
struct rtuentry {
u_long rtu_hash;
struct sockaddr rtu_dst;
struct sockaddr rtu_router;
short rtu_flags;
short rtu_state;
short rtu_rtflags; /* used by rtioctl */
short rtu_wasted[5];
int rtu_flags;
int rtu_state;
int rtu_timer;
int rtu_metric;
int rtu_ifmetric;
@ -71,7 +73,7 @@ struct rt_entry {
} rt_rtu;
};
#define rt_rt rt_rtu.rtu_rt /* pass to ioctl */
#define rt_rt rt_rtu.rtu_entry /* pass to ioctl */
#define rt_hash rt_rtu.rtu_entry.rtu_hash /* for net or host */
#define rt_dst rt_rtu.rtu_entry.rtu_dst /* match value */
#define rt_router rt_rtu.rtu_entry.rtu_router /* who to forward to */
@ -99,7 +101,7 @@ struct rt_entry {
/*
* Flags are same as kernel, with this addition for af_rtflags:
*/
#define RTF_SUBNET 0x8000 /* pseudo: route to subnet */
#define RTF_SUBNET 0x80000 /* pseudo: route to subnet */
struct rthash nethash[ROUTEHASHSIZ];
struct rthash hosthash[ROUTEHASHSIZ];

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983, 1988 Regents of the University of California.
* All rights reserved.
* 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
@ -32,8 +32,8 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)tables.c 5.17 (Berkeley) 6/1/90";*/
static char rcsid[] = "$Id: tables.c,v 1.6 1993/12/30 10:44:23 cgd Exp $";
/*static char sccsid[] = "from: @(#)tables.c 8.1 (Berkeley) 6/5/93";*/
static char *rcsid = "$Id: tables.c,v 1.7 1994/05/13 08:04:54 mycroft Exp $";
#endif /* not lint */
/*
@ -196,14 +196,14 @@ rtadd(dst, gate, metric, state)
* from this host, discard the entry. This should only
* occur because of an incorrect entry in /etc/gateways.
*/
if (install && (rt->rt_state & (RTS_INTERNAL | RTS_EXTERNAL)) == 0 &&
ioctl(s, SIOCADDRT, (char *)&rt->rt_rt) < 0) {
if ((rt->rt_state & (RTS_INTERNAL | RTS_EXTERNAL)) == 0 &&
rtioctl(ADD, &rt->rt_rt) < 0) {
if (errno != EEXIST && gate->sa_family < af_max)
syslog(LOG_ERR,
"adding route to net/host %s through gateway %s: %m\n",
(*afswitch[dst->sa_family].af_format)(dst),
(*afswitch[gate->sa_family].af_format)(gate));
perror("SIOCADDRT");
perror("ADD ROUTE");
if (errno == ENETUNREACH) {
TRACE_ACTION("DELETE", rt);
remque(rt);
@ -218,7 +218,7 @@ rtchange(rt, gate, metric)
short metric;
{
int add = 0, delete = 0, newgateway = 0;
struct rtentry oldroute;
struct rtuentry oldroute;
FIXLEN(gate);
FIXLEN(&(rt->rt_router));
@ -253,7 +253,7 @@ rtchange(rt, gate, metric)
if (metric > rt->rt_metric && delete)
syslog(LOG_ERR, "%s route to interface %s (timed out)",
add? "changing" : "deleting",
rt->rt_ifp->int_name);
rt->rt_ifp ? rt->rt_ifp->int_name : "?");
}
if (add) {
rt->rt_router = *gate;
@ -266,19 +266,20 @@ rtchange(rt, gate, metric)
if (newgateway)
TRACE_ACTION("CHANGE TO ", rt);
#ifndef RTM_ADD
if (add && install)
if (ioctl(s, SIOCADDRT, (char *)&rt->rt_rt) < 0)
perror("SIOCADDRT");
if (delete && install)
if (ioctl(s, SIOCDELRT, (char *)&oldroute) < 0)
perror("SIOCDELRT");
if (add && rtioctl(ADD, &rt->rt_rt) < 0)
perror("ADD ROUTE");
if (delete && rtioctl(DELETE, &oldroute) < 0)
perror("DELETE ROUTE");
#else
if (delete && install)
if (ioctl(s, SIOCDELRT, (char *)&oldroute) < 0)
perror("SIOCDELRT");
if (add && install) {
if (ioctl(s, SIOCADDRT, (char *)&rt->rt_rt) < 0)
perror("SIOCADDRT");
if (delete && !add) {
if (rtioctl(DELETE, &oldroute) < 0)
perror("DELETE ROUTE");
} else if (!delete && add) {
if (rtioctl(ADD, &rt->rt_rt) < 0)
perror("ADD ROUTE");
} else if (delete && add) {
if (rtioctl(CHANGE, &rt->rt_rt) < 0)
perror("CHANGE ROUTE");
}
#endif
}
@ -295,10 +296,9 @@ rtdelete(rt)
syslog(LOG_ERR,
"deleting route to interface %s? (timed out?)",
rt->rt_ifp->int_name);
if (install &&
(rt->rt_state & (RTS_INTERNAL | RTS_EXTERNAL)) == 0 &&
ioctl(s, SIOCDELRT, (char *)&rt->rt_rt))
perror("SIOCDELRT");
if ((rt->rt_state & (RTS_INTERNAL | RTS_EXTERNAL)) == 0 &&
rtioctl(DELETE, &rt->rt_rt) < 0)
perror("rtdelete");
}
remque(rt);
free((char *)rt);
@ -321,8 +321,8 @@ again:
continue;
TRACE_ACTION("DELETE", rt);
if ((rt->rt_state & (RTS_INTERNAL|RTS_EXTERNAL)) == 0 &&
ioctl(s, SIOCDELRT, (char *)&rt->rt_rt))
perror("SIOCDELRT");
rtioctl(DELETE, &rt->rt_rt) < 0)
perror("rtdeleteall");
}
}
if (doinghost) {
@ -358,27 +358,72 @@ rtinit()
rh->rt_forw = rh->rt_back = (struct rt_entry *)rh;
}
/* ffrom /sys/i386/i386/machdep.c */
/*
* insert an element into a queue
*/
insque(element, head)
register struct rthash *element, *head;
rtioctl(action, ort)
int action;
struct rtuentry *ort;
{
element->rt_forw = head->rt_forw;
head->rt_forw = (struct rt_entry *)element;
element->rt_back = (struct rt_entry *)head;
((struct rthash *)(element->rt_forw))->rt_back=(struct rt_entry *)element;
}
#ifndef RTM_ADD
if (install == 0)
return (errno = 0);
ort->rtu_rtflags = ort->rtu_flags;
switch (action) {
/*
* remove an element from a queue
*/
remque(element)
register struct rthash *element;
{
((struct rthash *)(element->rt_forw))->rt_back = element->rt_back;
((struct rthash *)(element->rt_back))->rt_forw = element->rt_forw;
element->rt_back = (struct rt_entry *)0;
case ADD:
return (ioctl(s, SIOCADDRT, (char *)ort));
case DELETE:
return (ioctl(s, SIOCDELRT, (char *)ort));
default:
return (-1);
}
#else /* RTM_ADD */
struct {
struct rt_msghdr w_rtm;
struct sockaddr_in w_dst;
struct sockaddr w_gate;
struct sockaddr_in w_netmask;
} w;
#define rtm w.w_rtm
bzero((char *)&w, sizeof(w));
rtm.rtm_msglen = sizeof(w);
rtm.rtm_version = RTM_VERSION;
rtm.rtm_type = (action == ADD ? RTM_ADD :
(action == DELETE ? RTM_DELETE : RTM_CHANGE));
#undef rt_dst
rtm.rtm_flags = ort->rtu_flags;
rtm.rtm_seq = ++seqno;
rtm.rtm_addrs = RTA_DST|RTA_GATEWAY;
bcopy((char *)&ort->rtu_dst, (char *)&w.w_dst, sizeof(w.w_dst));
bcopy((char *)&ort->rtu_router, (char *)&w.w_gate, sizeof(w.w_gate));
w.w_dst.sin_family = AF_INET;
w.w_dst.sin_len = sizeof(w.w_dst);
w.w_gate.sa_family = AF_INET;
w.w_gate.sa_len = sizeof(w.w_gate);
if (rtm.rtm_flags & RTF_HOST) {
rtm.rtm_msglen -= sizeof(w.w_netmask);
} else {
register char *cp;
int len;
rtm.rtm_addrs |= RTA_NETMASK;
w.w_netmask.sin_addr.s_addr =
inet_maskof(w.w_dst.sin_addr.s_addr);
for (cp = (char *)(1 + &w.w_netmask.sin_addr);
--cp > (char *) &w.w_netmask; )
if (*cp)
break;
len = cp - (char *)&w.w_netmask;
if (len) {
len++;
w.w_netmask.sin_len = len;
len = 1 + ((len - 1) | (sizeof(long) - 1));
} else
len = sizeof(long);
rtm.rtm_msglen -= (sizeof(w.w_netmask) - len);
}
errno = 0;
return (install ? write(r, (char *)&w, rtm.rtm_msglen) : (errno = 0));
#endif /* RTM_ADD */
}

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983, 1988 Regents of the University of California.
* All rights reserved.
* 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
@ -32,8 +32,8 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)timer.c 5.10 (Berkeley) 2/28/91";*/
static char rcsid[] = "$Id: timer.c,v 1.4 1993/08/01 18:24:19 mycroft Exp $";
/*static char sccsid[] = "from: @(#)timer.c 8.1 (Berkeley) 6/5/93";*/
static char *rcsid = "$Id: timer.c,v 1.5 1994/05/13 08:04:56 mycroft Exp $";
#endif /* not lint */
/*

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983, 1988 Regents of the University of California.
* All rights reserved.
* 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
@ -32,8 +32,8 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)trace.c 5.11 (Berkeley) 2/28/91";*/
static char rcsid[] = "$Id: trace.c,v 1.4 1993/08/01 18:24:17 mycroft Exp $";
/*static char sccsid[] = "from: @(#)trace.c 8.1 (Berkeley) 6/5/93";*/
static char *rcsid = "$Id: trace.c,v 1.5 1994/05/13 08:04:58 mycroft Exp $";
#endif /* not lint */
/*

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983, 1988 Regents of the University of California.
* All rights reserved.
* 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
@ -30,8 +30,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)trace.h 5.8 (Berkeley) 6/1/90
* $Id: trace.h,v 1.4 1993/08/01 18:24:33 mycroft Exp $
* from: @(#)trace.h 8.1 (Berkeley) 6/5/93
* $Id: trace.h,v 1.5 1994/05/13 08:04:59 mycroft Exp $
*/
/*

View File

@ -1,5 +1,5 @@
# from: @(#)Makefile 5.1 (Berkeley) 5/11/90
# $Id: Makefile,v 1.4 1993/08/01 00:57:08 mycroft Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/5/93
# $Id: Makefile,v 1.5 1994/05/13 08:05:06 mycroft Exp $
PROG= trace
NOMAN= noman

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 1983, 1988 The Regents of the University of California.
* All rights reserved.
* 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
@ -32,14 +32,14 @@
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1983, 1988 The Regents of the University of California.\n\
All rights reserved.\n";
static char copyright[] =
"@(#) Copyright (c) 1983, 1988, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
/*static char sccsid[] = "from: @(#)trace.c 5.9 (Berkeley) 4/16/91";*/
static char rcsid[] = "$Id: trace.c,v 1.4 1993/08/01 18:24:39 mycroft Exp $";
/*static char sccsid[] = "from: @(#)trace.c 8.1 (Berkeley) 6/5/93";*/
static char *rcsid = "$Id: trace.c,v 1.5 1994/05/13 08:05:09 mycroft Exp $";
#endif /* not lint */
#include <sys/param.h>