aboutsummaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
Diffstat (limited to 'sbin')
-rw-r--r--sbin/Makefile10
-rw-r--r--sbin/XNSrouted/Makefile10
-rw-r--r--sbin/XNSrouted/XNSrouted.8186
-rw-r--r--sbin/XNSrouted/af.c246
-rw-r--r--sbin/XNSrouted/af.h64
-rw-r--r--sbin/XNSrouted/defs.h88
-rw-r--r--sbin/XNSrouted/if.c147
-rw-r--r--sbin/XNSrouted/input.c189
-rw-r--r--sbin/XNSrouted/interface.h90
-rw-r--r--sbin/XNSrouted/main.c245
-rw-r--r--sbin/XNSrouted/output.c147
-rw-r--r--sbin/XNSrouted/protocol.h85
-rw-r--r--sbin/XNSrouted/startup.c218
-rw-r--r--sbin/XNSrouted/table.h99
-rw-r--r--sbin/XNSrouted/tables.c265
-rw-r--r--sbin/XNSrouted/timer.c139
-rw-r--r--sbin/XNSrouted/tools/query.c232
-rw-r--r--sbin/XNSrouted/trace.c313
-rw-r--r--sbin/XNSrouted/trace.h96
-rw-r--r--sbin/chkconfig/chkconfig.c30
-rw-r--r--sbin/comcontrol/comcontrol.879
-rw-r--r--sbin/comcontrol/comcontrol.c24
-rw-r--r--sbin/disklabel/disklabel.c113
-rw-r--r--sbin/dump/dump.82
-rw-r--r--sbin/dump/dumpoptr.c3
-rw-r--r--sbin/dump/dumptape.c17
-rw-r--r--sbin/dump/rdump.82
-rw-r--r--sbin/fsck/fsck.82
-rw-r--r--sbin/fsck/pass5.c15
-rw-r--r--sbin/fsck/setup.c4
-rw-r--r--sbin/fsck/utilities.c6
-rw-r--r--sbin/ft/Makefile3
-rw-r--r--sbin/ft/ft.86
-rw-r--r--sbin/ft/ft.c219
-rw-r--r--sbin/ft/ftecc.c448
-rw-r--r--sbin/ifconfig/ifconfig.c6
-rw-r--r--sbin/init.chmr/configure.c26
-rw-r--r--sbin/init/init.obin0 -> 5660 bytes
-rw-r--r--sbin/md5/Makefile34
-rw-r--r--sbin/md5/README34
-rw-r--r--sbin/md5/global.h30
-rw-r--r--sbin/md5/md5-announcement.txt37
-rw-r--r--sbin/md5/md5.143
-rw-r--r--sbin/md5/md5.h36
-rw-r--r--sbin/md5/md5c.c333
-rw-r--r--sbin/md5/mddriver.c231
-rw-r--r--sbin/mount/mount.84
-rw-r--r--sbin/mount/mount.c18
-rw-r--r--sbin/mountd/mountd.c2
-rw-r--r--sbin/ping/ping.c66
-rw-r--r--sbin/restore/Makefile2
-rw-r--r--sbin/restore/dirs.c2
-rw-r--r--sbin/restore/pathnames.h2
-rw-r--r--sbin/restore/restore.h2
-rw-r--r--sbin/restore/rrestore.82
-rw-r--r--sbin/restore/tape.c2
-rw-r--r--sbin/route/route.c4
-rw-r--r--sbin/routed/Makefile22
-rw-r--r--sbin/routed/af.c171
-rw-r--r--sbin/routed/af.h65
-rw-r--r--sbin/routed/defs.h93
-rw-r--r--sbin/routed/if.c148
-rw-r--r--sbin/routed/inet.c214
-rw-r--r--sbin/routed/input.c362
-rw-r--r--sbin/routed/interface.h90
-rw-r--r--sbin/routed/main.c343
-rw-r--r--sbin/routed/output.c172
-rw-r--r--sbin/routed/pathnames.h38
-rw-r--r--sbin/routed/query/Makefile7
-rw-r--r--sbin/routed/query/query.c289
-rw-r--r--sbin/routed/routed.8360
-rw-r--r--sbin/routed/startup.c486
-rw-r--r--sbin/routed/table.h106
-rw-r--r--sbin/routed/tables.c410
-rw-r--r--sbin/routed/timer.c127
-rw-r--r--sbin/routed/trace.c426
-rw-r--r--sbin/routed/trace.h96
-rw-r--r--sbin/routed/trace/Makefile7
-rw-r--r--sbin/routed/trace/trace.c125
-rw-r--r--sbin/slattach/slattach.c11
80 files changed, 1537 insertions, 7389 deletions
diff --git a/sbin/Makefile b/sbin/Makefile
index a1ac2c6c8c66..80613ba20d4c 100644
--- a/sbin/Makefile
+++ b/sbin/Makefile
@@ -1,11 +1,11 @@
# @(#)Makefile 5.4.1.1 (Berkeley) 5/7/91
-# $Id: Makefile,v 1.10 1994/02/07 05:23:06 alm Exp $
+# $Id: Makefile,v 1.13 1994/05/18 16:40:00 jkh Exp $
#
-SUBDIR= XNSrouted adjkerntz badsect chkconfig clri comcontrol disklabel dmesg \
- dump dumpfs fastboot fdisk fsck ft halt ifconfig mknod mount \
- mount_isofs mount_pcfs mount_procfs mountd newfs nfsd nfsiod ping \
- quotacheck reboot restore route routed savecore scsi shutdown \
+SUBDIR= adjkerntz badsect chkconfig clri comcontrol disklabel dmesg \
+ dump dumpfs fastboot fdisk fsck ft halt ifconfig md5 mknod mount \
+ mount_isofs mount_pcfs mount_procfs mountd newfs nfsd nfsiod \
+ ping quotacheck reboot restore route savecore scsi shutdown \
slattach st swapon tunefs umount
.if defined(INIT_ORIG)
diff --git a/sbin/XNSrouted/Makefile b/sbin/XNSrouted/Makefile
deleted file mode 100644
index 9f6583f8ee56..000000000000
--- a/sbin/XNSrouted/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
-# From: @(#)Makefile 5.14 (Berkeley) 2/26/91
-# $Id: Makefile,v 1.1 1993/09/07 14:13:06 rgrimes Exp $
-
-PROG= XNSrouted
-MAN8= XNSrouted.8
-SRCS= af.c if.c input.c main.c output.c startup.c tables.c timer.c trace.c
-DPADD= ${LIBUTIL}
-LDADD= -lutil
-
-.include <bsd.prog.mk>
diff --git a/sbin/XNSrouted/XNSrouted.8 b/sbin/XNSrouted/XNSrouted.8
deleted file mode 100644
index 144cb1d40453..000000000000
--- a/sbin/XNSrouted/XNSrouted.8
+++ /dev/null
@@ -1,186 +0,0 @@
-.\" Copyright (c) 1986, 1991 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
-.\" must display the following acknowledgement:
-.\" 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.
-.\"
-.\" @(#)XNSrouted.8 6.4 (Berkeley) 3/16/91
-.\"
-.Dd March 16, 1991
-.Dt XNSROUTED 8
-.Os BSD 4.3
-.Sh NAME
-.Nm XNSrouted
-.Nd NS Routing Information Protocol daemon
-.Sh SYNOPSIS
-.Nm XNSrouted
-.Op Fl q
-.Op Fl s
-.Op Fl t
-.Op Ar logfile
-.Sh DESCRIPTION
-.Nm XNSrouted
-is invoked at boot time to manage the Xerox NS routing tables.
-The NS routing daemon uses the Xerox NS Routing
-Information Protocol in maintaining up to date kernel routing
-table entries.
-.Pp
-Available options:
-.Bl -tag -width logfile
-.It Fl q
-Do not supply routing information (opposite of
-.Fl s
-option below).
-.It Fl s
-Forces
-.Nm XNSrouted
-to supply routing information whether it is acting as an internetwork
-router or not.
-.It Fl t
-All packets sent or received are
-printed on the standard output. In addition,
-.Nm XNSrouted
-will not divorce itself from the controlling terminal
-so that interrupts from the keyboard will kill the process.
-.It Ar logfile
-Name of file in which
-.Nm XNSrouted Ns 's
-actions should be logged. This log contains information
-about any changes to the routing tables and a history of
-recent messages sent and received which are related to
-the changed route.
-.El
-.Pp
-In normal operation
-.Nm XNSrouted
-listens
-for routing information packets. If the host is connected to
-multiple NS networks, it periodically supplies copies
-of its routing tables to any directly connected hosts
-and networks.
-.Pp
-When
-.Nm XNSrouted
-is started, it uses the
-.Dv SIOCGIFCONF
-.Xr ioctl 2
-to find those
-directly connected interfaces configured into the
-system and marked
-.Dq up
-(the software loopback interface
-is ignored). If multiple interfaces
-are present, it is assumed the host will forward packets
-between networks.
-.Nm XNSrouted
-then transmits a
-.Em request
-packet on each interface (using a broadcast packet if
-the interface supports it) and enters a loop, listening
-for
-.Em request
-and
-.Em response
-packets from other hosts.
-.Pp
-When a
-.Em request
-packet is received,
-.Nm XNSrouted
-formulates a reply based on the information maintained in its
-internal tables. The
-.Em response
-packet generated contains a list of known routes, each marked
-with a
-.Dq hop count
-metric (a count of 16, or greater, is
-considered
-.Dq infinite ) .
-The metric associated with each
-route returned provides a metric
-.Em relative to the sender .
-.Pp
-.Em Response
-packets received by
-.Nm XNSrouted
-are used to update the routing tables if one of the following
-conditions is satisfied:
-.Bl -bullet
-.It
-No routing table entry exists for the destination network
-or host, and the metric indicates the destination is ``reachable''
-(i.e. the hop count is not infinite).
-.It
-The source host of the packet is the same as the router in the
-existing routing table entry. That is, updated information is
-being received from the very internetwork router through which
-packets for the destination are being routed.
-.It
-The existing entry in the routing table has not been updated for
-some time (defined to be 90 seconds) and the route is at least
-as cost effective as the current route.
-.It
-The new route describes a shorter route to the destination than
-the one currently stored in the routing tables; the metric of
-the new route is compared against the one stored in the table
-to decide this.
-.El
-.Pp
-When an update is applied,
-.Nm XNSrouted
-records the change in its internal tables and generates a
-.Em response
-packet to all directly connected hosts and networks.
-.Xr Routed 8
-waits a short period
-of time (no more than 30 seconds) before modifying the kernel's
-routing tables to allow possible unstable situations to settle.
-.Pp
-In addition to processing incoming packets,
-.Nm XNSrouted
-also periodically checks the routing table entries.
-If an entry has not been updated for 3 minutes, the entry's metric
-is set to infinity and marked for deletion. Deletions are delayed
-an additional 60 seconds to insure the invalidation is propagated
-to other routers.
-.Pp
-Hosts acting as internetwork routers gratuitously supply their
-routing tables every 30 seconds to all directly connected hosts
-and networks.
-.Sh SEE ALSO
-.Xr idp 4
-.Rs
-.%T "Internet Transport Protocols"
-.%R "XSIS 028112"
-.%Q "Xerox System Integration Standard"
-.Re
-.Sh HISTORY
-The
-.Nm
-command appeared in
-.Bx 4.3 .
diff --git a/sbin/XNSrouted/af.c b/sbin/XNSrouted/af.c
deleted file mode 100644
index d131e8773992..000000000000
--- a/sbin/XNSrouted/af.c
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * Copyright (c) 1985 The Regents of the University of California.
- * All rights reserved.
- *
- * This file includes significant work done at Cornell University by
- * Bill Nesheim. That work included by permission.
- *
- * Redistribution and use in source and binary forms, 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)af.c 5.11 (Berkeley) 2/26/91";
-#endif /* not lint */
-
-#include "defs.h"
-
-/*
- * Address family support routines
- */
-int null_hash(), null_netmatch(), null_output(),
- null_portmatch(), null_portcheck(),
- null_checkhost(), null_ishost(), null_canon();
-int xnnet_hash(), xnnet_netmatch(), xnnet_output(),
- xnnet_portmatch(),
- xnnet_checkhost(), xnnet_ishost(), xnnet_canon();
-#define NIL \
- { null_hash, null_netmatch, null_output, \
- null_portmatch, null_portcheck, null_checkhost, \
- null_ishost, null_canon }
-#define XNSNET \
- { xnnet_hash, xnnet_netmatch, xnnet_output, \
- xnnet_portmatch, xnnet_portmatch, xnnet_checkhost, \
- xnnet_ishost, xnnet_canon }
-
-struct afswitch afswitch[AF_MAX] =
- { NIL, NIL, NIL, NIL, NIL, NIL, XNSNET, NIL, NIL, NIL, NIL };
-
-struct sockaddr_ns xnnet_default = { sizeof(struct sockaddr_ns), AF_NS };
-
-union ns_net ns_anynet;
-union ns_net ns_zeronet;
-
-xnnet_hash(sns, hp)
- register struct sockaddr_ns *sns;
- struct afhash *hp;
-{
- register long hash = 0;
- register u_short *s = sns->sns_addr.x_host.s_host;
- union ns_net_u net;
-
- net.net_e = sns->sns_addr.x_net;
- hp->afh_nethash = net.long_e;
- hash = *s++; hash <<= 8; hash += *s++; hash <<= 8; hash += *s;
- hp->afh_hosthash = hash;
-}
-
-xnnet_netmatch(sxn1, sxn2)
- struct sockaddr_ns *sxn1, *sxn2;
-{
- return (ns_neteq(sxn1->sns_addr, sxn2->sns_addr));
-}
-
-/*
- * Verify the message is from the right port.
- */
-xnnet_portmatch(sns)
- register struct sockaddr_ns *sns;
-{
-
- return (ntohs(sns->sns_addr.x_port) == IDPPORT_RIF );
-}
-
-
-/*
- * xns output routine.
- */
-#ifdef DEBUG
-int do_output = 0;
-#endif
-xnnet_output(flags, sns, size)
- int flags;
- struct sockaddr_ns *sns;
- int size;
-{
- struct sockaddr_ns dst;
-
- dst = *sns;
- sns = &dst;
- if (sns->sns_addr.x_port == 0)
- sns->sns_addr.x_port = htons(IDPPORT_RIF);
-#ifdef DEBUG
- if(do_output || ntohs(msg->rip_cmd) == RIPCMD_REQUEST)
-#endif
- /*
- * Kludge to allow us to get routes out to machines that
- * don't know their addresses yet; send to that address on
- * ALL connected nets
- */
- if (ns_neteqnn(sns->sns_addr.x_net, ns_zeronet)) {
- extern struct interface *ifnet;
- register struct interface *ifp;
-
- for (ifp = ifnet; ifp; ifp = ifp->int_next) {
- sns->sns_addr.x_net =
- satons_addr(ifp->int_addr).x_net;
- (void) sendto(s, msg, size, flags,
- (struct sockaddr *)sns, sizeof (*sns));
- }
- return;
- }
-
- (void) sendto(s, msg, size, flags,
- (struct sockaddr *)sns, sizeof (*sns));
-}
-
-/*
- * Return 1 if we want this route.
- * We use this to disallow route net G entries for one for multiple
- * point to point links.
- */
-xnnet_checkhost(sns)
- struct sockaddr_ns *sns;
-{
- register struct interface *ifp = if_ifwithnet(sns);
- /*
- * We want this route if there is no more than one
- * point to point interface with this network.
- */
- if (ifp == 0 || (ifp->int_flags & IFF_POINTOPOINT)==0) return (1);
- return (ifp->int_sq.n == ifp->int_sq.p);
-}
-
-/*
- * Return 1 if the address is
- * for a host, 0 for a network.
- */
-xnnet_ishost(sns)
-struct sockaddr_ns *sns;
-{
- register u_short *s = sns->sns_addr.x_host.s_host;
-
- if ((s[0]==0xffff) && (s[1]==0xffff) && (s[2]==0xffff))
- return (0);
- else
- return (1);
-}
-
-xnnet_canon(sns)
- struct sockaddr_ns *sns;
-{
-
- sns->sns_addr.x_port = 0;
-}
-
-/*ARGSUSED*/
-null_hash(addr, hp)
- struct sockaddr *addr;
- struct afhash *hp;
-{
-
- hp->afh_nethash = hp->afh_hosthash = 0;
-}
-
-/*ARGSUSED*/
-null_netmatch(a1, a2)
- struct sockaddr *a1, *a2;
-{
-
- return (0);
-}
-
-/*ARGSUSED*/
-null_output(s, f, a1, n)
- int s, f;
- struct sockaddr *a1;
- int n;
-{
-
- ;
-}
-
-/*ARGSUSED*/
-null_portmatch(a1)
- struct sockaddr *a1;
-{
-
- return (0);
-}
-
-/*ARGSUSED*/
-null_portcheck(a1)
- struct sockaddr *a1;
-{
-
- return (0);
-}
-
-/*ARGSUSED*/
-null_ishost(a1)
- struct sockaddr *a1;
-{
-
- return (0);
-}
-
-/*ARGSUSED*/
-null_checkhost(a1)
- struct sockaddr *a1;
-{
-
- return (0);
-}
-
-/*ARGSUSED*/
-null_canon(a1)
- struct sockaddr *a1;
-{
-
- ;
-}
diff --git a/sbin/XNSrouted/af.h b/sbin/XNSrouted/af.h
deleted file mode 100644
index d2b27c531380..000000000000
--- a/sbin/XNSrouted/af.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 1983 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
- * must display the following acknowledgement:
- * 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.
- *
- * @(#)af.h 5.1 (Berkeley) 6/4/85 (routed/af.h)
- *
- * @(#)af.h 5.2 (Berkeley) 6/1/90
- */
-
-/*
- * Routing table management daemon.
- */
-
-/*
- * Per address family routines.
- */
-struct afswitch {
- int (*af_hash)(); /* returns keys based on address */
- int (*af_netmatch)(); /* verifies net # matching */
- int (*af_output)(); /* interprets address for sending */
- int (*af_portmatch)(); /* packet from some other router? */
- int (*af_portcheck)(); /* packet from privileged peer? */
- int (*af_checkhost)(); /* tells if address for host or net */
- int (*af_ishost)(); /* tells if address is valid */
- int (*af_canon)(); /* canonicalize address for compares */
-};
-
-/*
- * Structure returned by af_hash routines.
- */
-struct afhash {
- u_int afh_hosthash; /* host based hash */
- u_int afh_nethash; /* network based hash */
-};
-
-struct afswitch afswitch[AF_MAX]; /* table proper */
diff --git a/sbin/XNSrouted/defs.h b/sbin/XNSrouted/defs.h
deleted file mode 100644
index 5414d8c08ca3..000000000000
--- a/sbin/XNSrouted/defs.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (c) 1983 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
- * must display the following acknowledgement:
- * 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.
- *
- * @(#)defs.h 5.9 (Berkeley) 2/26/91
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <net/route.h>
-#include <netns/ns.h>
-#include <netns/idp.h>
-#if defined(vax) || defined(pdp11)
-#define xnnet(x) ((u_long) (x)->rip_dst[1] << 16 | (u_long) (x)->rip_dst[0] )
-#else
-#define xnnet(x) ((u_long) (x)->rip_dst[0] << 16 | (u_long) (x)->rip_dst[1] )
-#endif
-#define IDPPORT_RIF 1
-
-#include <stdio.h>
-#include <syslog.h>
-
-#include "protocol.h"
-#include "trace.h"
-#include "interface.h"
-#include "table.h"
-#include "af.h"
-
-
-/*
- * When we find any interfaces marked down we rescan the
- * kernel every CHECK_INTERVAL seconds to see if they've
- * come up.
- */
-#define CHECK_INTERVAL (5*60)
-
-#define equal(a1, a2) \
- (bcmp((caddr_t)(a1), (caddr_t)(a2), sizeof (struct sockaddr)) == 0)
-#define min(a,b) ((a)>(b)?(b):(a))
-
-struct sockaddr_ns addr; /* Daemon's Address */
-int s; /* Socket to listen on */
-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 /vmunix has changed */
-int externalinterfaces; /* # of remote and local interfaces */
-int timeval; /* local idea of time */
-int noteremoterequests; /* squawk on requests from non-local nets */
-
-char packet[MAXPACKETSIZE+sizeof(struct idp)+1];
-struct rip *msg;
-
-char **argv0;
-
-int sndmsg();
-int supply();
-int cleanup();
diff --git a/sbin/XNSrouted/if.c b/sbin/XNSrouted/if.c
deleted file mode 100644
index 0f597a66fac3..000000000000
--- a/sbin/XNSrouted/if.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright (c) 1983 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
- * must display the following acknowledgement:
- * 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.
- *
- * static char sccsid[] = "@(#)if.c 5.1 (Berkeley) 6/4/85"; (routed/if.c)
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)if.c 5.2 (Berkeley) 6/1/90";
-#endif /* not lint */
-
-/*
- * Routing Table Management Daemon
- */
-#include "defs.h"
-
-extern struct interface *ifnet;
-
-/*
- * Find the interface with address addr.
- */
-struct interface *
-if_ifwithaddr(addr)
- struct sockaddr *addr;
-{
- register struct interface *ifp;
-
-#define same(a1, a2) \
- (bcmp((caddr_t)((a1)->sa_data), (caddr_t)((a2)->sa_data), 14) == 0)
- for (ifp = ifnet; ifp; ifp = ifp->int_next) {
- if (ifp->int_flags & IFF_REMOTE)
- continue;
- if (ifp->int_addr.sa_family != addr->sa_family)
- continue;
- if (same(&ifp->int_addr, addr))
- break;
- if ((ifp->int_flags & IFF_BROADCAST) &&
- same(&ifp->int_broadaddr, addr))
- break;
- }
- return (ifp);
-}
-
-/*
- * Find the point-to-point interface with destination address addr.
- */
-struct interface *
-if_ifwithdstaddr(addr)
- struct sockaddr *addr;
-{
- register struct interface *ifp;
-
- for (ifp = ifnet; ifp; ifp = ifp->int_next) {
- if ((ifp->int_flags & IFF_POINTOPOINT) == 0)
- continue;
- if (same(&ifp->int_dstaddr, addr))
- break;
- }
- return (ifp);
-}
-
-/*
- * Find the interface on the network
- * of the specified address.
- */
-struct interface *
-if_ifwithnet(addr)
- register struct sockaddr *addr;
-{
- register struct interface *ifp;
- register int af = addr->sa_family;
- register int (*netmatch)();
-
- if (af >= AF_MAX)
- return (0);
- netmatch = afswitch[af].af_netmatch;
- for (ifp = ifnet; ifp; ifp = ifp->int_next) {
- if (ifp->int_flags & IFF_REMOTE)
- continue;
- if (af != ifp->int_addr.sa_family)
- continue;
- if ((*netmatch)(addr, &ifp->int_addr))
- break;
- }
- return (ifp);
-}
-
-/*
- * Find an interface from which the specified address
- * should have come from. Used for figuring out which
- * interface a packet came in on -- for tracing.
- */
-struct interface *
-if_iflookup(addr)
- struct sockaddr *addr;
-{
- register struct interface *ifp, *maybe;
- register int af = addr->sa_family;
- register int (*netmatch)();
-
- if (af >= AF_MAX)
- return (0);
- maybe = 0;
- netmatch = afswitch[af].af_netmatch;
- for (ifp = ifnet; ifp; ifp = ifp->int_next) {
- if (ifp->int_addr.sa_family != af)
- continue;
- if (same(&ifp->int_addr, addr))
- break;
- if ((ifp->int_flags & IFF_BROADCAST) &&
- same(&ifp->int_broadaddr, addr))
- break;
- if (maybe == 0 && (*netmatch)(addr, &ifp->int_addr))
- maybe = ifp;
- }
- if (ifp == 0)
- ifp = maybe;
- return (ifp);
-}
diff --git a/sbin/XNSrouted/input.c b/sbin/XNSrouted/input.c
deleted file mode 100644
index 7dc64fa5cc9c..000000000000
--- a/sbin/XNSrouted/input.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Copyright (c) 1985 The Regents of the University of California.
- * All rights reserved.
- *
- * This file includes significant work done at Cornell University by
- * Bill Nesheim. That work included by permission.
- *
- * Redistribution and use in source and binary forms, 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)input.c 5.9 (Berkeley) 6/1/90";
-#endif /* not lint */
-
-/*
- * XNS Routing Table Management Daemon
- */
-#include "defs.h"
-
-struct sockaddr *
-xns_nettosa(net)
-union ns_net net;
-{
- static struct sockaddr_ns sxn;
- extern char ether_broadcast_addr[6];
-
- bzero(&sxn, sizeof (struct sockaddr_ns));
- sxn.sns_family = AF_NS;
- sxn.sns_len = sizeof (sxn);
- sxn.sns_addr.x_net = net;
- sxn.sns_addr.x_host = *(union ns_host *)ether_broadcast_addr;
- return( (struct sockaddr *)&sxn);
-
-}
-
-/*
- * Process a newly received packet.
- */
-rip_input(from, size)
- struct sockaddr *from;
- int size;
-{
- struct rt_entry *rt;
- struct netinfo *n;
- struct interface *ifp;
- int newsize;
- struct afswitch *afp;
-
-
- ifp = 0;
- TRACE_INPUT(ifp, from, size);
- if (from->sa_family >= AF_MAX)
- return;
- afp = &afswitch[from->sa_family];
-
- size -= sizeof (u_short) /* command */;
- n = msg->rip_nets;
-
- switch (ntohs(msg->rip_cmd)) {
-
- case RIPCMD_REQUEST:
- newsize = 0;
- while (size > 0) {
- if (size < sizeof (struct netinfo))
- break;
- size -= sizeof (struct netinfo);
-
- /*
- * A single entry with rip_dst == DSTNETS_ALL and
- * metric ``infinity'' means ``all routes''.
- */
- if (ns_neteqnn(n->rip_dst, ns_anynet) &&
- ntohs(n->rip_metric) == HOPCNT_INFINITY &&
- size == 0) {
- ifp = if_ifwithnet(from);
- supply(from, 0, ifp);
- return;
- }
- /*
- * request for specific nets
- */
- rt = rtlookup(xns_nettosa(n->rip_dst));
- if (ftrace) {
- fprintf(ftrace,
- "specific request for %s",
- xns_nettoa(n->rip_dst));
- fprintf(ftrace,
- " yields route %x\n",
- rt);
- }
- n->rip_metric = htons( rt == 0 ? HOPCNT_INFINITY :
- min(rt->rt_metric+1, HOPCNT_INFINITY));
- n++;
- newsize += sizeof (struct netinfo);
- }
- if (newsize > 0) {
- msg->rip_cmd = htons(RIPCMD_RESPONSE);
- newsize += sizeof (u_short);
- /* should check for if with dstaddr(from) first */
- (*afp->af_output)(0, from, newsize);
- ifp = if_ifwithnet(from);
- TRACE_OUTPUT(ifp, from, newsize);
- if (ftrace) {
- fprintf(ftrace,
- "request arrived on interface %s\n",
- ifp->int_name);
- }
- }
- return;
-
- case RIPCMD_RESPONSE:
- /* verify message came from a router */
- if ((*afp->af_portmatch)(from) == 0)
- return;
- (*afp->af_canon)(from);
- /* are we talking to ourselves? */
- if (ifp = if_ifwithaddr(from)) {
- rt = rtfind(from);
- if (rt == 0 || (rt->rt_state & RTS_INTERFACE) == 0)
- addrouteforif(ifp);
- else
- rt->rt_timer = 0;
- return;
- }
- /* Update timer for interface on which the packet arrived.
- * If from other end of a point-to-point link that isn't
- * in the routing tables, (re-)add the route.
- */
- if ((rt = rtfind(from)) && (rt->rt_state & RTS_INTERFACE)) {
- if(ftrace) fprintf(ftrace, "Got route\n");
- rt->rt_timer = 0;
- } else if (ifp = if_ifwithdstaddr(from)) {
- if(ftrace) fprintf(ftrace, "Got partner\n");
- addrouteforif(ifp);
- }
- for (; size > 0; size -= sizeof (struct netinfo), n++) {
- struct sockaddr *sa;
- if (size < sizeof (struct netinfo))
- break;
- if ((unsigned) ntohs(n->rip_metric) >= HOPCNT_INFINITY)
- continue;
- rt = rtfind(sa = xns_nettosa(n->rip_dst));
- if (rt == 0) {
- rtadd(sa, from, ntohs(n->rip_metric), 0);
- continue;
- }
-
- /*
- * Update if from gateway and different,
- * from anywhere and shorter, or getting stale and equivalent.
- */
- if ((equal(from, &rt->rt_router) &&
- ntohs(n->rip_metric) != rt->rt_metric ) ||
- (unsigned) ntohs(n->rip_metric) < rt->rt_metric ||
- (rt->rt_timer > (EXPIRE_TIME/2) &&
- rt->rt_metric == ntohs(n->rip_metric))) {
- rtchange(rt, from, ntohs(n->rip_metric));
- rt->rt_timer = 0;
- }
- }
- return;
- }
-}
diff --git a/sbin/XNSrouted/interface.h b/sbin/XNSrouted/interface.h
deleted file mode 100644
index 7cb416699a1b..000000000000
--- a/sbin/XNSrouted/interface.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 1983 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
- * must display the following acknowledgement:
- * 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.
- *
- * @(#)interface.h 5.5 (Berkeley) 6/1/90
- */
-
-/*
- * Routing table management daemon.
- */
-
-/*
- * An ``interface'' is similar to an ifnet structure,
- * except it doesn't contain q'ing info, and it also
- * handles ``logical'' interfaces (remote gateways
- * that we want to keep polling even if they go down).
- * The list of interfaces which we maintain is used
- * in supplying the gratuitous routing table updates.
- * We list only one address for each interface, the AF_XNS one.
- */
-#define NIFADDR 3
-struct interface {
- struct interface *int_next;
- struct sockaddr int_addr; /* address on this host */
- union {
- struct sockaddr intu_broadaddr;
- struct sockaddr intu_dstaddr;
- } int_intu;
-#define int_broadaddr int_intu.intu_broadaddr /* broadcast address */
-#define int_dstaddr int_intu.intu_dstaddr /* other end of p-to-p link */
- int int_metric; /* init's routing entry */
- int int_flags; /* see below */
- struct ifdebug int_input, int_output; /* packet tracing stuff */
- int int_ipackets; /* input packets received */
- int int_opackets; /* output packets sent */
- char *int_name; /* from kernel if structure */
- u_short int_transitions; /* times gone up-down */
-/*XNS Specific entry */
- struct sameq {
- struct sameq *n; /* q of other pt-to-pt links */
- struct sameq *p; /* with same net # */
- } int_sq;
-};
-
-/*
- * 0x1 to 0x10 are reused from the kernel's ifnet definitions,
- * the others agree with the RTS_ flags defined elsewhere.
- */
-#define IFF_UP 0x1 /* interface is up */
-#define IFF_BROADCAST 0x2 /* broadcast address valid */
-#define IFF_DEBUG 0x4 /* turn on debugging */
-#define IFF_ROUTE 0x8 /* routing entry installed */
-#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
-
-#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 */
-
-struct interface *if_ifwithaddr();
-struct interface *if_ifwithdstaddr();
-struct interface *if_ifwithnet();
-struct interface *if_iflookup();
diff --git a/sbin/XNSrouted/main.c b/sbin/XNSrouted/main.c
deleted file mode 100644
index f4ddf285839c..000000000000
--- a/sbin/XNSrouted/main.c
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Copyright (c) 1985 The Regents of the University of California.
- * All rights reserved.
- *
- * This file includes significant work done at Cornell University by
- * Bill Nesheim. That work included by permission.
- *
- * Redistribution and use in source and binary forms, 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1985 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)main.c 5.11 (Berkeley) 2/26/91";
-#endif /* not lint */
-
-/*
- * XNS Routing Information Protocol Daemon
- */
-#include "defs.h"
-#include <sys/time.h>
-
-#include <net/if.h>
-
-#include <errno.h>
-#include <nlist.h>
-#include <signal.h>
-#include <paths.h>
-
-int supplier = -1; /* process should supply updates */
-extern int gateway;
-
-struct rip *msg = (struct rip *) &packet[sizeof (struct idp)];
-void hup(), fkexit(), timer();
-
-main(argc, argv)
- int argc;
- char *argv[];
-{
- int cc;
- struct sockaddr from;
- u_char retry;
-
- argv0 = argv;
- argv++, argc--;
- while (argc > 0 && **argv == '-') {
- if (strcmp(*argv, "-s") == 0) {
- supplier = 1;
- argv++, argc--;
- continue;
- }
- if (strcmp(*argv, "-q") == 0) {
- supplier = 0;
- argv++, argc--;
- continue;
- }
- if (strcmp(*argv, "-R") == 0) {
- noteremoterequests++;
- argv++, argc--;
- continue;
- }
- if (strcmp(*argv, "-t") == 0) {
- tracepackets++;
- argv++, argc--;
- ftrace = stderr;
- tracing = 1;
- continue;
- }
- if (strcmp(*argv, "-g") == 0) {
- gateway = 1;
- argv++, argc--;
- continue;
- }
- if (strcmp(*argv, "-l") == 0) {
- gateway = -1;
- argv++, argc--;
- continue;
- }
- fprintf(stderr,
- "usage: xnsrouted [ -s ] [ -q ] [ -t ] [ -g ] [ -l ]\n");
- exit(1);
- }
-
-
-#ifndef DEBUG
- if (!tracepackets)
- daemon(0, 0);
-#endif
- openlog("XNSrouted", LOG_PID, LOG_DAEMON);
-
- ns_anynet.s_net[0] = -1; ns_anynet.s_net[1] = -1;
- addr.sns_family = AF_NS;
- addr.sns_len = sizeof(addr);
- addr.sns_port = htons(IDPPORT_RIF);
- s = getsocket(SOCK_DGRAM, 0, &addr);
- if (s < 0)
- exit(1);
- /*
- * Any extra argument is considered
- * a tracing log file.
- */
- if (argc > 0)
- traceon(*argv);
- /*
- * Collect an initial view of the world by
- * snooping in the kernel. Then, send a request packet on all
- * directly connected networks to find out what
- * everyone else thinks.
- */
- rtinit();
- ifinit();
- if (supplier < 0)
- supplier = 0;
- /* request the state of the world */
- msg->rip_cmd = htons(RIPCMD_REQUEST);
- msg->rip_nets[0].rip_dst = ns_anynet;
- msg->rip_nets[0].rip_metric = htons(HOPCNT_INFINITY);
- toall(sndmsg);
- signal(SIGALRM, timer);
- signal(SIGHUP, hup);
- signal(SIGINT, hup);
- signal(SIGEMT, fkexit);
- timer();
-
-
- for (;;)
- process(s);
-
-}
-
-process(fd)
- int fd;
-{
- struct sockaddr from;
- int fromlen = sizeof (from), cc, omask;
- struct idp *idp = (struct idp *)packet;
-
- cc = recvfrom(fd, packet, sizeof (packet), 0, &from, &fromlen);
- if (cc <= 0) {
- if (cc < 0 && errno != EINTR)
- syslog(LOG_ERR, "recvfrom: %m");
- return;
- }
- if (tracepackets > 1 && ftrace) {
- fprintf(ftrace,"rcv %d bytes on %s ", cc, xns_ntoa(&idp->idp_dna));
- fprintf(ftrace," from %s\n", xns_ntoa(&idp->idp_sna));
- }
-
- if (noteremoterequests && !ns_neteqnn(idp->idp_sna.x_net, ns_zeronet)
- && !ns_neteq(idp->idp_sna, idp->idp_dna))
- {
- syslog(LOG_ERR,
- "net of interface (%s) != net on ether (%s)!\n",
- xns_nettoa(idp->idp_dna.x_net),
- xns_nettoa(idp->idp_sna.x_net));
- }
-
- /* We get the IDP header in front of the RIF packet*/
- cc -= sizeof (struct idp);
-#define mask(s) (1<<((s)-1))
- omask = sigblock(mask(SIGALRM));
- rip_input(&from, cc);
- sigsetmask(omask);
-}
-
-getsocket(type, proto, sns)
- int type, proto;
- struct sockaddr_ns *sns;
-{
- int domain = sns->sns_family;
- int retry, s, on = 1;
-
- retry = 1;
- while ((s = socket(domain, type, proto)) < 0 && retry) {
- syslog(LOG_ERR, "socket: %m");
- sleep(5 * retry);
- retry <<= 1;
- }
- if (retry == 0)
- return (-1);
- while (bind(s, (struct sockaddr *)sns, sizeof (*sns)) < 0 && retry) {
- syslog(LOG_ERR, "bind: %m");
- sleep(5 * retry);
- retry <<= 1;
- }
- if (retry == 0)
- return (-1);
- if (domain==AF_NS) {
- struct idp idp;
- if (setsockopt(s, 0, SO_HEADERS_ON_INPUT, &on, sizeof(on))) {
- syslog(LOG_ERR, "setsockopt SEE HEADERS: %m");
- exit(1);
- }
- idp.idp_pt = NSPROTO_RI;
- if (setsockopt(s, 0, SO_DEFAULT_HEADERS, &idp, sizeof(idp))) {
- syslog(LOG_ERR, "setsockopt SET HEADER: %m");
- exit(1);
- }
- }
- if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0) {
- syslog(LOG_ERR, "setsockopt SO_BROADCAST: %m");
- exit(1);
- }
- return (s);
-}
-
-/*
- * Fork and exit on EMT-- for profiling.
- */
-void
-fkexit()
-{
- if (fork() == 0)
- exit(0);
-}
diff --git a/sbin/XNSrouted/output.c b/sbin/XNSrouted/output.c
deleted file mode 100644
index cdea11f2b73f..000000000000
--- a/sbin/XNSrouted/output.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright (c) 1985 The Regents of the University of California.
- * All rights reserved.
- *
- * This file includes significant work done at Cornell University by
- * Bill Nesheim. That work included by permission.
- *
- * Redistribution and use in source and binary forms, 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)output.c 5.8 (Berkeley) 2/26/91";
-#endif /* not lint */
-
-/*
- * Routing Table Management Daemon
- */
-#include "defs.h"
-
-/*
- * Apply the function "f" to all non-passive
- * interfaces. If the interface supports the
- * use of broadcasting use it, otherwise address
- * the output to the known router.
- */
-toall(f)
- int (*f)();
-{
- register struct interface *ifp;
- register struct sockaddr *dst;
- register int flags;
- extern struct interface *ifnet;
-
- for (ifp = ifnet; ifp; ifp = ifp->int_next) {
- if (ifp->int_flags & IFF_PASSIVE)
- continue;
- dst = ifp->int_flags & IFF_BROADCAST ? &ifp->int_broadaddr :
- ifp->int_flags & IFF_POINTOPOINT ? &ifp->int_dstaddr :
- &ifp->int_addr;
- flags = ifp->int_flags & IFF_INTERFACE ? MSG_DONTROUTE : 0;
- (*f)(dst, flags, ifp);
- }
-}
-
-/*
- * Output a preformed packet.
- */
-/*ARGSUSED*/
-sndmsg(dst, flags, ifp)
- struct sockaddr *dst;
- int flags;
- struct interface *ifp;
-{
-
- (*afswitch[dst->sa_family].af_output)
- (flags, dst, sizeof (struct rip));
- TRACE_OUTPUT(ifp, dst, sizeof (struct rip));
-}
-
-/*
- * Supply dst with the contents of the routing tables.
- * If this won't fit in one packet, chop it up into several.
- */
-supply(dst, flags, ifp)
- struct sockaddr *dst;
- int flags;
- struct interface *ifp;
-{
- register struct rt_entry *rt;
- register struct rthash *rh;
- register struct netinfo *nn;
- register struct netinfo *n = msg->rip_nets;
- struct rthash *base = hosthash;
- struct sockaddr_ns *sns = (struct sockaddr_ns *) dst;
- int (*output)() = afswitch[dst->sa_family].af_output;
- int doinghost = 1, size, metric;
- union ns_net net;
-
- msg->rip_cmd = ntohs(RIPCMD_RESPONSE);
-again:
- for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++)
- for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
- size = (char *)n - (char *)msg;
- if (size > MAXPACKETSIZE - sizeof (struct netinfo)) {
- (*output)(flags, dst, size);
- TRACE_OUTPUT(ifp, dst, size);
- n = msg->rip_nets;
- }
- sns = (struct sockaddr_ns *)&rt->rt_dst;
- if ((rt->rt_flags & (RTF_HOST|RTF_GATEWAY)) == RTF_HOST)
- sns = (struct sockaddr_ns *)&rt->rt_router;
- metric = min(rt->rt_metric + 1, HOPCNT_INFINITY);
- net = sns->sns_addr.x_net;
- /*
- * Make sure that we don't put out a two net entries
- * for a pt to pt link (one for the G route, one for the if)
- * This is a kludge, and won't work if there are lots of nets.
- */
- for (nn = msg->rip_nets; nn < n; nn++) {
- if (ns_neteqnn(net, nn->rip_dst)) {
- if (metric < ntohs(nn->rip_metric))
- nn->rip_metric = htons(metric);
- goto next;
- }
- }
- n->rip_dst = net;
- n->rip_metric = htons(metric);
- n++;
- next:;
- }
- if (doinghost) {
- doinghost = 0;
- base = nethash;
- goto again;
- }
- if (n != msg->rip_nets) {
- size = (char *)n - (char *)msg;
- (*output)(flags, dst, size);
- TRACE_OUTPUT(ifp, dst, size);
- }
-}
diff --git a/sbin/XNSrouted/protocol.h b/sbin/XNSrouted/protocol.h
deleted file mode 100644
index 9bf422b60625..000000000000
--- a/sbin/XNSrouted/protocol.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 1985 The Regents of the University of California.
- * All rights reserved.
- *
- * This file includes significant work done at Cornell University by
- * Bill Nesheim. That work included by permission.
- *
- * Redistribution and use in source and binary forms, 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
- * must display the following acknowledgement:
- * 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.
- *
- * @(#)protocol.h 5.6 (Berkeley) 6/1/90
- */
-
-/*
- * Xerox Routing Information Protocol
- *
- */
-
-struct netinfo {
- union ns_net rip_dst; /* destination net */
- u_short rip_metric; /* cost of route */
-};
-
-struct rip {
- u_short rip_cmd; /* request/response */
- struct netinfo rip_nets[1]; /* variable length */
-};
-
-/*
- * Packet types.
- */
-#define RIPCMD_REQUEST 1 /* want info */
-#define RIPCMD_RESPONSE 2 /* responding to request */
-
-#define RIPCMD_MAX 3
-#ifdef RIPCMDS
-char *ripcmds[RIPCMD_MAX] =
- { "#0", "REQUEST", "RESPONSE" };
-#endif
-
-#define HOPCNT_INFINITY 16 /* per Xerox NS */
-#define DSTNETS_ALL 0xffffffff /* per Xerox NS */
-#define MAXPACKETSIZE 512 /* max broadcast size */
-
-extern union ns_net ns_anynet;
-extern union ns_net ns_zeronet;
-
-/*
- * Timer values used in managing the routing table.
- * Every update forces an entry's timer to be reset. After
- * EXPIRE_TIME without updates, the entry is marked invalid,
- * but held onto until GARBAGE_TIME so that others may
- * see it "be deleted".
- */
-#define TIMER_RATE 30 /* alarm clocks every 30 seconds */
-
-#define SUPPLY_INTERVAL 30 /* time to supply tables */
-
-#define EXPIRE_TIME 180 /* time to mark entry invalid */
-#define GARBAGE_TIME 240 /* time to garbage collect */
diff --git a/sbin/XNSrouted/startup.c b/sbin/XNSrouted/startup.c
deleted file mode 100644
index 8887c1fc474a..000000000000
--- a/sbin/XNSrouted/startup.c
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * Copyright (c) 1985 The Regents of the University of California.
- * All rights reserved.
- *
- * This file includes significant work done at Cornell University by
- * Bill Nesheim. That work included by permission.
- *
- * Redistribution and use in source and binary forms, 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)startup.c 5.11 (Berkeley) 2/26/91";
-#endif /* not lint */
-
-/*
- * Routing Table Management Daemon
- */
-#include "defs.h"
-#include <sys/ioctl.h>
-#include <net/if.h>
-#include <nlist.h>
-#include <stdlib.h>
-
-struct interface *ifnet;
-int lookforinterfaces = 1;
-int performnlist = 1;
-int gateway = 0;
-int externalinterfaces = 0; /* # of remote and local interfaces */
-char ether_broadcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
-
-
-/*
- * Find the network interfaces which have configured themselves.
- * If the interface is present but not yet up (for example an
- * ARPANET IMP), set the lookforinterfaces flag so we'll
- * come back later and look again.
- */
-ifinit()
-{
- struct interface ifs, *ifp;
- int s;
- struct ifconf ifc;
- char buf[BUFSIZ], *cp, *cplim;
- struct ifreq ifreq, *ifr;
- u_long i;
-
- if ((s = socket(AF_NS, SOCK_DGRAM, 0)) < 0) {
- syslog(LOG_ERR, "socket: %m");
- exit(1);
- }
- 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);
- exit(1);
- }
- ifr = ifc.ifc_req;
- 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, "ioctl (get interface flags)");
- continue;
- }
- ifs.int_flags = ifreq.ifr_flags | IFF_INTERFACE;
- if ((ifs.int_flags & IFF_UP) == 0 ||
- ifr->ifr_addr.sa_family == AF_UNSPEC) {
- lookforinterfaces = 1;
- continue;
- }
- if (ifs.int_addr.sa_family != AF_NS)
- continue;
- if (ifs.int_flags & IFF_POINTOPOINT) {
- if (ioctl(s, SIOCGIFDSTADDR, (char *)&ifreq) < 0) {
- syslog(LOG_ERR, "ioctl (get dstaddr): %m");
- continue;
- }
- ifs.int_dstaddr = ifreq.ifr_dstaddr;
- }
- if (ifs.int_flags & IFF_BROADCAST) {
- if (ioctl(s, SIOCGIFBRDADDR, (char *)&ifreq) < 0) {
- syslog(LOG_ERR, "ioctl (get broadaddr: %m");
- continue;
- }
- ifs.int_broadaddr = ifreq.ifr_broadaddr;
- }
- /*
- * already known to us?
- * what makes a POINTOPOINT if unique is its dst addr,
- * NOT its source address
- */
- if ( ((ifs.int_flags & IFF_POINTOPOINT) &&
- if_ifwithdstaddr(&ifs.int_dstaddr)) ||
- ( ((ifs.int_flags & IFF_POINTOPOINT) == 0) &&
- if_ifwithaddr(&ifs.int_addr)))
- continue;
- /* no one cares about software loopback interfaces */
- if (strncmp(ifr->ifr_name,"lo", 2)==0)
- continue;
- ifp = (struct interface *)malloc(sizeof (struct interface));
- if (ifp == 0) {
- syslog(LOG_ERR,"XNSrouted: out of memory\n");
- break;
- }
- *ifp = ifs;
- /*
- * Count the # of directly connected networks
- * and point to point links which aren't looped
- * back to ourself. This is used below to
- * decide if we should be a routing ``supplier''.
- */
- if ((ifs.int_flags & IFF_POINTOPOINT) == 0 ||
- if_ifwithaddr(&ifs.int_dstaddr) == 0)
- externalinterfaces++;
- /*
- * If we have a point-to-point link, we want to act
- * as a supplier even if it's our only interface,
- * as that's the only way our peer on the other end
- * can tell that the link is up.
- */
- if ((ifs.int_flags & IFF_POINTOPOINT) && supplier < 0)
- supplier = 1;
- ifp->int_name = malloc(strlen(ifr->ifr_name) + 1);
- if (ifp->int_name == 0) {
- syslog(LOG_ERR,"XNSrouted: out of memory\n");
- exit(1);
- }
- strcpy(ifp->int_name, ifr->ifr_name);
- ifp->int_metric = 0;
- ifp->int_next = ifnet;
- ifnet = ifp;
- traceinit(ifp);
- addrouteforif(ifp);
- }
- if (externalinterfaces > 1 && supplier < 0)
- supplier = 1;
- close(s);
-}
-
-addrouteforif(ifp)
- struct interface *ifp;
-{
- struct sockaddr_ns net;
- struct sockaddr *dst;
- int state, metric;
- struct rt_entry *rt;
-
- if (ifp->int_flags & IFF_POINTOPOINT) {
- int (*match)();
- register struct interface *ifp2 = ifnet;
- register struct interface *ifprev = ifnet;
-
- dst = &ifp->int_dstaddr;
-
- /* Search for interfaces with the same net */
- ifp->int_sq.n = ifp->int_sq.p = &(ifp->int_sq);
- match = afswitch[dst->sa_family].af_netmatch;
- if (match)
- for (ifp2 = ifnet; ifp2; ifp2 =ifp2->int_next) {
- if (ifp->int_flags & IFF_POINTOPOINT == 0)
- continue;
- if ((*match)(&ifp2->int_dstaddr,&ifp->int_dstaddr)) {
- insque(&ifp2->int_sq,&ifp->int_sq);
- break;
- }
- }
- } else {
- dst = &ifp->int_broadaddr;
- }
- rt = rtlookup(dst);
- if (rt)
- rtdelete(rt);
- if (tracing)
- fprintf(stderr, "Adding route to interface %s\n", ifp->int_name);
- if (ifp->int_transitions++ > 0)
- syslog(LOG_ERR, "re-installing interface %s", ifp->int_name);
- rtadd(dst, &ifp->int_addr, ifp->int_metric,
- ifp->int_flags & (IFF_INTERFACE|IFF_PASSIVE|IFF_REMOTE));
-}
-
diff --git a/sbin/XNSrouted/table.h b/sbin/XNSrouted/table.h
deleted file mode 100644
index 159dc4e64252..000000000000
--- a/sbin/XNSrouted/table.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 1983 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
- * must display the following acknowledgement:
- * 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.
- *
- * @(#)table.h 5.1 (Berkeley) 6/4/85 (routed/table.h)
- *
- * @(#)table.h 5.3 (Berkeley) 6/1/90
- */
-
-/*
- * Routing table management daemon.
- */
-
-/*
- * Routing table structure; differs a bit from kernel tables.
- *
- * Note: the union below must agree in the first 4 members
- * so the ioctl's will work.
- */
-struct rthash {
- struct rt_entry *rt_forw;
- struct rt_entry *rt_back;
-};
-
-#ifdef RTM_ADD
-#define rtentry ortentry
-#endif
-
-struct rt_entry {
- struct rt_entry *rt_forw;
- struct rt_entry *rt_back;
- union {
- struct rtentry rtu_rt;
- struct {
- u_long rtu_hash;
- struct sockaddr rtu_dst;
- struct sockaddr rtu_router;
- short rtu_flags;
- short rtu_state;
- int rtu_timer;
- int rtu_metric;
- struct interface *rtu_ifp;
- } rtu_entry;
- } rt_rtu;
-};
-
-#define rt_rt rt_rtu.rtu_rt /* 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 */
-#define rt_flags rt_rtu.rtu_entry.rtu_flags /* kernel flags */
-#define rt_timer rt_rtu.rtu_entry.rtu_timer /* for invalidation */
-#define rt_state rt_rtu.rtu_entry.rtu_state /* see below */
-#define rt_metric rt_rtu.rtu_entry.rtu_metric /* cost of route */
-#define rt_ifp rt_rtu.rtu_entry.rtu_ifp /* interface to take */
-
-#define ROUTEHASHSIZ 32 /* must be a power of 2 */
-#define ROUTEHASHMASK (ROUTEHASHSIZ - 1)
-
-/*
- * "State" of routing table entry.
- */
-#define RTS_CHANGED 0x1 /* route has been altered recently */
-#define RTS_PASSIVE IFF_PASSIVE /* don't time out route */
-#define RTS_INTERFACE IFF_INTERFACE /* route is for network interface */
-#define RTS_REMOTE IFF_REMOTE /* route is for ``remote'' entity */
-
-struct rthash nethash[ROUTEHASHSIZ];
-struct rthash hosthash[ROUTEHASHSIZ];
-struct rt_entry *rtlookup();
-struct rt_entry *rtfind();
diff --git a/sbin/XNSrouted/tables.c b/sbin/XNSrouted/tables.c
deleted file mode 100644
index 38ce4386fe25..000000000000
--- a/sbin/XNSrouted/tables.c
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * Copyright (c) 1985 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)tables.c 5.9 (Berkeley) 6/1/90";
-#endif /* not lint */
-
-/*
- * Routing Table Management Daemon
- */
-#include "defs.h"
-#include <sys/ioctl.h>
-#include <errno.h>
-
-#ifndef DEBUG
-#define DEBUG 0
-#endif
-
-extern char *xns_ntoa();
-#define FIXLEN(s) { if ((s)->sa_len == 0) (s)->sa_len = sizeof (*(s));}
-
-int install = !DEBUG; /* if 1 call kernel */
-int delete = 1;
-/*
- * Lookup dst in the tables for an exact match.
- */
-struct rt_entry *
-rtlookup(dst)
- struct sockaddr *dst;
-{
- register struct rt_entry *rt;
- register struct rthash *rh;
- register u_int hash;
- struct afhash h;
- int doinghost = 1;
-
- if (dst->sa_family >= AF_MAX)
- return (0);
- (*afswitch[dst->sa_family].af_hash)(dst, &h);
- hash = h.afh_hosthash;
- rh = &hosthash[hash & ROUTEHASHMASK];
-again:
- for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
- if (rt->rt_hash != hash)
- continue;
- if (equal(&rt->rt_dst, dst))
- return (rt);
- }
- if (doinghost) {
- doinghost = 0;
- hash = h.afh_nethash;
- rh = &nethash[hash & ROUTEHASHMASK];
- goto again;
- }
- return (0);
-}
-
-/*
- * Find a route to dst as the kernel would.
- */
-struct rt_entry *
-rtfind(dst)
- struct sockaddr *dst;
-{
- register struct rt_entry *rt;
- register struct rthash *rh;
- register u_int hash;
- struct afhash h;
- int af = dst->sa_family;
- int doinghost = 1, (*match)();
-
- if (af >= AF_MAX)
- return (0);
- (*afswitch[af].af_hash)(dst, &h);
- hash = h.afh_hosthash;
- rh = &hosthash[hash & ROUTEHASHMASK];
-
-again:
- for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
- if (rt->rt_hash != hash)
- continue;
- if (doinghost) {
- if (equal(&rt->rt_dst, dst))
- return (rt);
- } else {
- if (rt->rt_dst.sa_family == af &&
- (*match)(&rt->rt_dst, dst))
- return (rt);
- }
- }
- if (doinghost) {
- doinghost = 0;
- hash = h.afh_nethash;
- rh = &nethash[hash & ROUTEHASHMASK];
- match = afswitch[af].af_netmatch;
- goto again;
- }
- return (0);
-}
-
-rtadd(dst, gate, metric, state)
- struct sockaddr *dst, *gate;
- int metric, state;
-{
- struct afhash h;
- register struct rt_entry *rt;
- struct rthash *rh;
- int af = dst->sa_family, flags;
- u_int hash;
-
- FIXLEN(dst);
- FIXLEN(gate);
- if (af >= AF_MAX)
- return;
- (*afswitch[af].af_hash)(dst, &h);
- flags = (*afswitch[af].af_ishost)(dst) ? RTF_HOST : 0;
- if (flags & RTF_HOST) {
- hash = h.afh_hosthash;
- rh = &hosthash[hash & ROUTEHASHMASK];
- } else {
- hash = h.afh_nethash;
- rh = &nethash[hash & ROUTEHASHMASK];
- }
- rt = (struct rt_entry *)malloc(sizeof (*rt));
- if (rt == 0)
- return;
- rt->rt_hash = hash;
- rt->rt_dst = *dst;
- rt->rt_router = *gate;
- rt->rt_metric = metric;
- rt->rt_timer = 0;
- rt->rt_flags = RTF_UP | flags;
- rt->rt_state = state | RTS_CHANGED;
- rt->rt_ifp = if_ifwithnet(&rt->rt_router);
- if (metric)
- rt->rt_flags |= RTF_GATEWAY;
- insque(rt, rh);
- TRACE_ACTION(ADD, rt);
- /*
- * If the ioctl fails because the gateway is unreachable
- * from this host, discard the entry. This should only
- * occur because of an incorrect entry in /etc/gateways.
- */
- if (install && ioctl(s, SIOCADDRT, (char *)&rt->rt_rt) < 0) {
- if (errno != EEXIST)
- perror("SIOCADDRT");
- if (errno == ENETUNREACH) {
- TRACE_ACTION(DELETE, rt);
- remque(rt);
- free((char *)rt);
- }
- }
-}
-
-rtchange(rt, gate, metric)
- struct rt_entry *rt;
- struct sockaddr *gate;
- short metric;
-{
- int doioctl = 0, metricchanged = 0;
- struct rtentry oldroute;
-
- FIXLEN(gate);
- if (!equal(&rt->rt_router, gate))
- doioctl++;
- if (metric != rt->rt_metric)
- metricchanged++;
- if (doioctl || metricchanged) {
- TRACE_ACTION(CHANGE FROM, rt);
- if (doioctl) {
- oldroute = rt->rt_rt;
- rt->rt_router = *gate;
- }
- rt->rt_metric = metric;
- if ((rt->rt_state & RTS_INTERFACE) && metric) {
- rt->rt_state &= ~RTS_INTERFACE;
- syslog(LOG_ERR,
- "changing route from interface %s (timed out)",
- rt->rt_ifp->int_name);
- }
- if (metric)
- rt->rt_flags |= RTF_GATEWAY;
- else
- rt->rt_flags &= ~RTF_GATEWAY;
- rt->rt_state |= RTS_CHANGED;
- TRACE_ACTION(CHANGE TO, rt);
- }
- if (doioctl && install) {
-#ifndef RTM_ADD
- if (ioctl(s, SIOCADDRT, (char *)&rt->rt_rt) < 0)
- syslog(LOG_ERR, "SIOCADDRT dst %s, gw %s: %m",
- xns_ntoa(&((struct sockaddr_ns *)&rt->rt_dst)->sns_addr),
- xns_ntoa(&((struct sockaddr_ns *)&rt->rt_router)->sns_addr));
- if (delete && ioctl(s, SIOCDELRT, (char *)&oldroute) < 0)
- perror("SIOCDELRT");
-#else
- if (delete && ioctl(s, SIOCDELRT, (char *)&oldroute) < 0)
- perror("SIOCDELRT");
- if (ioctl(s, SIOCADDRT, (char *)&rt->rt_rt) < 0)
- syslog(LOG_ERR, "SIOCADDRT dst %s, gw %s: %m",
- xns_ntoa(&((struct sockaddr_ns *)&rt->rt_dst)->sns_addr),
- xns_ntoa(&((struct sockaddr_ns *)&rt->rt_router)->sns_addr));
-#endif
- }
-}
-
-rtdelete(rt)
- struct rt_entry *rt;
-{
-
- struct sockaddr *sa = &(rt->rt_rt.rt_gateway);
- FIXLEN(sa);
-#undef rt_dst
- sa = &(rt->rt_rt.rt_dst);
- FIXLEN(sa);
- if (rt->rt_state & RTS_INTERFACE) {
- syslog(LOG_ERR, "deleting route to interface %s (timed out)",
- rt->rt_ifp->int_name);
- }
- TRACE_ACTION(DELETE, rt);
- if (install && ioctl(s, SIOCDELRT, (char *)&rt->rt_rt))
- perror("SIOCDELRT");
- remque(rt);
- free((char *)rt);
-}
-
-rtinit()
-{
- register struct rthash *rh;
-
- for (rh = nethash; rh < &nethash[ROUTEHASHSIZ]; rh++)
- rh->rt_forw = rh->rt_back = (struct rt_entry *)rh;
- for (rh = hosthash; rh < &hosthash[ROUTEHASHSIZ]; rh++)
- rh->rt_forw = rh->rt_back = (struct rt_entry *)rh;
-}
diff --git a/sbin/XNSrouted/timer.c b/sbin/XNSrouted/timer.c
deleted file mode 100644
index f420bc074e00..000000000000
--- a/sbin/XNSrouted/timer.c
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright (c) 1985 The Regents of the University of California.
- * All rights reserved.
- *
- * This file includes significant work done at Cornell University by
- * Bill Nesheim. That work included by permission.
- *
- * Redistribution and use in source and binary forms, 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)timer.c 5.7 (Berkeley) 2/26/91";
-#endif /* not lint */
-
-/*
- * Routing Table Management Daemon
- */
-#include "defs.h"
-
-int timeval = -TIMER_RATE;
-
-/*
- * Timer routine. Performs routing information supply
- * duties and manages timers on routing table entries.
- */
-void
-timer()
-{
- register struct rthash *rh;
- register struct rt_entry *rt;
- struct rthash *base = hosthash;
- int doinghost = 1, timetobroadcast;
-
- timeval += TIMER_RATE;
- if (lookforinterfaces && (timeval % CHECK_INTERVAL) == 0)
- ifinit();
- timetobroadcast = supplier && (timeval % SUPPLY_INTERVAL) == 0;
-again:
- for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
- rt = rh->rt_forw;
- for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
- /*
- * We don't advance time on a routing entry for
- * a passive gateway or that for our only interface.
- * The latter is excused because we don't act as
- * a routing information supplier and hence would
- * time it out. This is fair as if it's down
- * we're cut off from the world anyway and it's
- * not likely we'll grow any new hardware in
- * the mean time.
- */
- if (!(rt->rt_state & RTS_PASSIVE) &&
- (supplier || !(rt->rt_state & RTS_INTERFACE)))
- rt->rt_timer += TIMER_RATE;
- if (rt->rt_timer >= EXPIRE_TIME)
- rt->rt_metric = HOPCNT_INFINITY;
- if (rt->rt_timer >= GARBAGE_TIME) {
- rt = rt->rt_back;
- /* Perhaps we should send a REQUEST for this route? */
- rtdelete(rt->rt_forw);
- continue;
- }
- if (rt->rt_state & RTS_CHANGED) {
- rt->rt_state &= ~RTS_CHANGED;
- /* don't send extraneous packets */
- if (!supplier || timetobroadcast)
- continue;
- msg->rip_cmd = htons(RIPCMD_RESPONSE);
- msg->rip_nets[0].rip_dst =
- (satons_addr(rt->rt_dst)).x_net;
- msg->rip_nets[0].rip_metric =
- htons(min(rt->rt_metric+1, HOPCNT_INFINITY));
- toall(sndmsg);
- }
- }
- }
- if (doinghost) {
- doinghost = 0;
- base = nethash;
- goto again;
- }
- if (timetobroadcast)
- toall(supply);
- alarm(TIMER_RATE);
-}
-
-/*
- * On hangup, let everyone know we're going away.
- */
-void
-hup()
-{
- register struct rthash *rh;
- register struct rt_entry *rt;
- struct rthash *base = hosthash;
- int doinghost = 1;
-
- if (supplier) {
-again:
- for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
- rt = rh->rt_forw;
- for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw)
- rt->rt_metric = HOPCNT_INFINITY;
- }
- if (doinghost) {
- doinghost = 0;
- base = nethash;
- goto again;
- }
- toall(supply);
- }
- exit(1);
-}
diff --git a/sbin/XNSrouted/tools/query.c b/sbin/XNSrouted/tools/query.c
deleted file mode 100644
index 2e6374d1f63f..000000000000
--- a/sbin/XNSrouted/tools/query.c
+++ /dev/null
@@ -1,232 +0,0 @@
-/*-
- * Copyright (c) 1983, 1986 The Regents of the University of California.
- * All rights reserved.
- *
- * This code includes software contributed to Berkeley by
- * Bill Nesheim at Cornell University.
- *
- * 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1983, 1986 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)query.c 5.8 (Berkeley) 4/16/91";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/protosw.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-#include <netns/ns.h>
-#include <netns/idp.h>
-#include <errno.h>
-#include <stdio.h>
-#include <netdb.h>
-#include "../protocol.h"
-#define IDPPORT_RIF 1
-
-#define WTIME 5 /* Time to wait for responses */
-
-int s;
-int timedout, timeout();
-char packet[MAXPACKETSIZE];
-extern int errno;
-struct sockaddr_ns myaddr = {sizeof(myaddr), AF_NS};
-char *ns_ntoa();
-struct ns_addr ns_addr();
-main(argc, argv)
-int argc;
-char *argv[];
-{
- int cc, count, bits;
- struct sockaddr from;
- int fromlen = sizeof(from);
- struct timeval notime;
-
- if (argc < 2) {
- printf("usage: query hosts...\n");
- exit(1);
- }
- s = getsocket(SOCK_DGRAM, 0);
- if (s < 0) {
- perror("socket");
- exit(2);
- }
-
- argv++, argc--;
- query(argv,argc);
-
- /*
- * Listen for returning packets;
- * may be more than one packet per host.
- */
- bits = 1 << s;
- bzero(&notime, sizeof(notime));
- signal(SIGALRM, timeout);
- alarm(WTIME);
- while (!timedout ||
- select(20, &bits, 0, 0, &notime) > 0) {
- struct nspacket {
- struct idp hdr;
- char data[512];
- } response;
- cc = recvfrom(s, &response, sizeof (response), 0,
- &from, &fromlen);
- if (cc <= 0) {
- if (cc < 0) {
- if (errno == EINTR)
- continue;
- perror("recvfrom");
- (void) close(s);
- exit(1);
- }
- continue;
- }
- rip_input(&from, response.data, cc);
- count--;
- }
-}
-static struct sockaddr_ns router = {sizeof(myaddr), AF_NS};
-static struct ns_addr zero_addr;
-static short allones[] = {-1, -1, -1};
-
-query(argv,argc)
-char **argv;
-{
- register struct rip *msg = (struct rip *)packet;
- char *host = *argv;
- int flags = 0;
- struct ns_addr specific;
-
- if (bcmp(*argv, "-r", 3) == 0) {
- flags = MSG_DONTROUTE; argv++; argc--;
- }
- host = *argv;
- router.sns_addr = ns_addr(host);
- router.sns_addr.x_port = htons(IDPPORT_RIF);
- if (ns_hosteq(zero_addr, router.sns_addr)) {
- router.sns_addr.x_host = *(union ns_host *) allones;
- }
- msg->rip_cmd = htons(RIPCMD_REQUEST);
- msg->rip_nets[0].rip_dst = *(union ns_net *) allones;
- msg->rip_nets[0].rip_metric = htons(HOPCNT_INFINITY);
- if (argc > 0) {
- specific = ns_addr(*argv);
- msg->rip_nets[0].rip_dst = specific.x_net;
- specific.x_host = zero_addr.x_host;
- specific.x_port = zero_addr.x_port;
- printf("Net asked for was %s\n", ns_ntoa(specific));
- }
- if (sendto(s, packet, sizeof (struct rip), flags,
- &router, sizeof(router)) < 0)
- perror(host);
-}
-
-/*
- * Handle an incoming routing packet.
- */
-rip_input(from, msg, size)
- struct sockaddr_ns *from;
- register struct rip *msg;
- int size;
-{
- struct netinfo *n;
- char *name;
- int lna, net, subnet;
- struct hostent *hp;
- struct netent *np;
- static struct ns_addr work;
-
- if (htons(msg->rip_cmd) != RIPCMD_RESPONSE)
- return;
- printf("from %s\n", ns_ntoa(from->sns_addr));
- size -= sizeof (struct idp);
- size -= sizeof (short);
- n = msg->rip_nets;
- while (size > 0) {
- union ns_net_u net;
- if (size < sizeof (struct netinfo))
- break;
- net.net_e = n->rip_dst;
- printf("\t%d, metric %d\n", ntohl(net.long_e),
- ntohs(n->rip_metric));
- size -= sizeof (struct netinfo), n++;
- }
-}
-
-timeout()
-{
- timedout = 1;
-}
-getsocket(type, proto)
- int type, proto;
-{
- struct sockaddr_ns *sns = &myaddr;
- int domain = sns->sns_family;
- int retry, s, on = 1;
-
- retry = 1;
- while ((s = socket(domain, type, proto)) < 0 && retry) {
- perror("socket");
- sleep(5 * retry);
- retry <<= 1;
- }
- if (retry == 0)
- return (-1);
- while (bind(s, sns, sizeof (*sns), 0) < 0 && retry) {
- perror("bind");
- sleep(5 * retry);
- retry <<= 1;
- }
- if (retry == 0)
- return (-1);
- if (domain==AF_NS) {
- struct idp idp;
- if (setsockopt(s, 0, SO_HEADERS_ON_INPUT, &on, sizeof(on))) {
- perror("setsockopt SEE HEADERS");
- exit(1);
- }
- idp.idp_pt = NSPROTO_RI;
- if (setsockopt(s, 0, SO_DEFAULT_HEADERS, &idp, sizeof(idp))) {
- perror("setsockopt SET HEADERS");
- exit(1);
- }
- }
- if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0) {
- perror("setsockopt SO_BROADCAST");
- exit(1);
- }
- return (s);
-}
diff --git a/sbin/XNSrouted/trace.c b/sbin/XNSrouted/trace.c
deleted file mode 100644
index 51728733a387..000000000000
--- a/sbin/XNSrouted/trace.c
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- * Copyright (c) 1985 The Regents of the University of California.
- * All rights reserved.
- *
- * This file includes significant work done at Cornell University by
- * Bill Nesheim. That work included by permission.
- *
- * Redistribution and use in source and binary forms, 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)trace.c 5.11 (Berkeley) 2/26/91";
-#endif /* not lint */
-
-/*
- * Routing Table Management Daemon
- */
-#define RIPCMDS
-#include <stdlib.h>
-#include "defs.h"
-
-#define NRECORDS 50 /* size of circular trace buffer */
-#ifdef DEBUG
-FILE *ftrace = stdout;
-int tracing = 1;
-#else DEBUG
-FILE *ftrace = NULL;
-int tracing = 0;
-#endif
-
-char *xns_ntoa();
-
-traceinit(ifp)
- register struct interface *ifp;
-{
- static int iftraceinit();
-
- if (iftraceinit(ifp, &ifp->int_input) &&
- iftraceinit(ifp, &ifp->int_output))
- return;
- tracing = 0;
- syslog(LOG_ERR, "traceinit: can't init %s\n", ifp->int_name);
-}
-
-static
-iftraceinit(ifp, ifd)
- struct interface *ifp;
- register struct ifdebug *ifd;
-{
- register struct iftrace *t;
-
- ifd->ifd_records =
- (struct iftrace *)malloc(NRECORDS * sizeof (struct iftrace));
- if (ifd->ifd_records == 0)
- return (0);
- ifd->ifd_front = ifd->ifd_records;
- ifd->ifd_count = 0;
- for (t = ifd->ifd_records; t < ifd->ifd_records + NRECORDS; t++) {
- t->ift_size = 0;
- t->ift_packet = 0;
- }
- ifd->ifd_if = ifp;
- return (1);
-}
-
-traceon(file)
- char *file;
-{
-
- if (ftrace != NULL)
- return;
- ftrace = fopen(file, "a");
- if (ftrace == NULL)
- return;
- dup2(fileno(ftrace), 1);
- dup2(fileno(ftrace), 2);
- tracing = 1;
-}
-
-traceoff()
-{
- if (!tracing)
- return;
- if (ftrace != NULL)
- fclose(ftrace);
- ftrace = NULL;
- tracing = 0;
-}
-
-trace(ifd, who, p, len, m)
- register struct ifdebug *ifd;
- struct sockaddr *who;
- char *p;
- int len, m;
-{
- register struct iftrace *t;
-
- if (ifd->ifd_records == 0)
- return;
- t = ifd->ifd_front++;
- if (ifd->ifd_front >= ifd->ifd_records + NRECORDS)
- ifd->ifd_front = ifd->ifd_records;
- if (ifd->ifd_count < NRECORDS)
- ifd->ifd_count++;
- if (t->ift_size > 0 && t->ift_packet)
- free(t->ift_packet);
- t->ift_packet = 0;
- t->ift_stamp = time(0);
- t->ift_who = *who;
- if (len > 0) {
- t->ift_packet = malloc(len);
- if (t->ift_packet)
- bcopy(p, t->ift_packet, len);
- else
- len = 0;
- }
- t->ift_size = len;
- t->ift_metric = m;
-}
-
-traceaction(fd, action, rt)
- FILE *fd;
- char *action;
- struct rt_entry *rt;
-{
- struct sockaddr_ns *dst, *gate;
- static struct bits {
- int t_bits;
- char *t_name;
- } flagbits[] = {
- { RTF_UP, "UP" },
- { RTF_GATEWAY, "GATEWAY" },
- { RTF_HOST, "HOST" },
- { 0 }
- }, statebits[] = {
- { RTS_PASSIVE, "PASSIVE" },
- { RTS_REMOTE, "REMOTE" },
- { RTS_INTERFACE,"INTERFACE" },
- { RTS_CHANGED, "CHANGED" },
- { 0 }
- };
- register struct bits *p;
- register int first;
- char *cp;
- struct interface *ifp;
-
- if (fd == NULL)
- return;
- fprintf(fd, "%s ", action);
- dst = (struct sockaddr_ns *)&rt->rt_dst;
- gate = (struct sockaddr_ns *)&rt->rt_router;
- fprintf(fd, "dst %s, ", xns_ntoa(&dst->sns_addr));
- fprintf(fd, "router %s, metric %d, flags",
- xns_ntoa(&gate->sns_addr), rt->rt_metric);
- cp = " %s";
- for (first = 1, p = flagbits; p->t_bits > 0; p++) {
- if ((rt->rt_flags & p->t_bits) == 0)
- continue;
- fprintf(fd, cp, p->t_name);
- if (first) {
- cp = "|%s";
- first = 0;
- }
- }
- fprintf(fd, " state");
- cp = " %s";
- for (first = 1, p = statebits; p->t_bits > 0; p++) {
- if ((rt->rt_state & p->t_bits) == 0)
- continue;
- fprintf(fd, cp, p->t_name);
- if (first) {
- cp = "|%s";
- first = 0;
- }
- }
- putc('\n', fd);
- if (!tracepackets && (rt->rt_state & RTS_PASSIVE) == 0 && rt->rt_ifp)
- dumpif(fd, rt->rt_ifp);
- fflush(fd);
-}
-
-dumpif(fd, ifp)
- register struct interface *ifp;
- FILE *fd;
-{
- if (ifp->int_input.ifd_count || ifp->int_output.ifd_count) {
- fprintf(fd, "*** Packet history for interface %s ***\n",
- ifp->int_name);
- dumptrace(fd, "to", &ifp->int_output);
- dumptrace(fd, "from", &ifp->int_input);
- fprintf(fd, "*** end packet history ***\n");
- }
-}
-
-dumptrace(fd, dir, ifd)
- FILE *fd;
- char *dir;
- register struct ifdebug *ifd;
-{
- register struct iftrace *t;
- char *cp = !strcmp(dir, "to") ? "Output" : "Input";
-
- if (ifd->ifd_front == ifd->ifd_records &&
- ifd->ifd_front->ift_size == 0) {
- fprintf(fd, "%s: no packets.\n", cp);
- return;
- }
- fprintf(fd, "%s trace:\n", cp);
- t = ifd->ifd_front - ifd->ifd_count;
- if (t < ifd->ifd_records)
- t += NRECORDS;
- for ( ; ifd->ifd_count; ifd->ifd_count--, t++) {
- if (t >= ifd->ifd_records + NRECORDS)
- t = ifd->ifd_records;
- if (t->ift_size == 0)
- continue;
- fprintf(fd, "%.24s: metric=%d\n", ctime(&t->ift_stamp),
- t->ift_metric);
- dumppacket(fd, dir, &t->ift_who, t->ift_packet, t->ift_size);
- }
-}
-
-dumppacket(fd, dir, who, cp, size)
- FILE *fd;
- struct sockaddr_ns *who; /* should be sockaddr */
- char *dir, *cp;
- register int size;
-{
- register struct rip *msg = (struct rip *)cp;
- register struct netinfo *n;
- char *xns_nettoa();
-
- if (msg->rip_cmd && ntohs(msg->rip_cmd) < RIPCMD_MAX)
- fprintf(fd, "%s %s %s#%x", ripcmds[ntohs(msg->rip_cmd)],
- dir, xns_ntoa(&who->sns_addr), ntohs(who->sns_addr.x_port));
- else {
- fprintf(fd, "Bad cmd 0x%x %s %s#%x\n", ntohs(msg->rip_cmd),
- dir, xns_ntoa(&who->sns_addr), ntohs(who->sns_addr.x_port));
- fprintf(fd, "size=%d cp=%x packet=%x\n", size, cp, packet);
- return;
- }
- switch (ntohs(msg->rip_cmd)) {
-
- case RIPCMD_REQUEST:
- case RIPCMD_RESPONSE:
- fprintf(fd, ":\n");
- size -= sizeof (u_short);
- n = msg->rip_nets;
- for (; size > 0; n++, size -= sizeof (struct netinfo)) {
- if (size < sizeof (struct netinfo))
- break;
- fprintf(fd, "\tnet %s metric %d\n",
- xns_nettoa(n->rip_dst),
- ntohs(n->rip_metric));
- }
- break;
-
- }
-}
-
-union ns_net_u net;
-
-char *
-xns_nettoa(val)
-union ns_net val;
-{
- static char buf[100];
- net.net_e = val;
- (void)sprintf(buf, "%lx", ntohl(net.long_e));
- return (buf);
-}
-
-
-char *
-xns_ntoa(addr)
-struct ns_addr *addr;
-{
- static char buf[100];
-
- (void)sprintf(buf, "%s#%x:%x:%x:%x:%x:%x",
- xns_nettoa(addr->x_net),
- addr->x_host.c_host[0], addr->x_host.c_host[1],
- addr->x_host.c_host[2], addr->x_host.c_host[3],
- addr->x_host.c_host[4], addr->x_host.c_host[5]);
-
- return(buf);
-}
diff --git a/sbin/XNSrouted/trace.h b/sbin/XNSrouted/trace.h
deleted file mode 100644
index be48553d6c13..000000000000
--- a/sbin/XNSrouted/trace.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (c) 1983 The Regents of the University of California.
- * All rights reserved.
- *
- * This file includes significant work done at Cornell University by
- * Bill Nesheim. That work included by permission.
- *
- * Redistribution and use in source and binary forms, 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
- * must display the following acknowledgement:
- * 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.
- *
- * @(#)trace.h 5.6 (Berkeley) 6/1/90
- */
-
-/*
- * Xerox Routing Information Protocol.
- */
-
-/*
- * Trace record format.
- */
-struct iftrace {
- time_t ift_stamp; /* time stamp */
- struct sockaddr ift_who; /* from/to */
- char *ift_packet; /* pointer to packet */
- short ift_size; /* size of packet */
- short ift_metric; /* metric */
-};
-
-/*
- * Per interface packet tracing buffers. An incoming and
- * outgoing circular buffer of packets is maintained, per
- * interface, for debugging. Buffers are dumped whenever
- * an interface is marked down.
- */
-struct ifdebug {
- struct iftrace *ifd_records; /* array of trace records */
- struct iftrace *ifd_front; /* next empty trace record */
- int ifd_count; /* number of unprinted records */
- struct interface *ifd_if; /* for locating stuff */
-};
-
-/*
- * Packet tracing stuff.
- */
-int tracepackets; /* watch packets as they go by */
-int tracing; /* on/off */
-FILE *ftrace; /* output trace file */
-
-#define TRACE_ACTION(action, route) { \
- if (tracing) \
- traceaction(ftrace, "action", route); \
- }
-#define TRACE_INPUT(ifp, src, size) { \
- if (tracing) { \
- ifp = if_iflookup(src); \
- if (ifp) \
- trace(&ifp->int_input, src, &packet[sizeof(struct idp)], size, \
- ntohl(ifp->int_metric)); \
- } \
- if (tracepackets && ftrace) \
- dumppacket(ftrace, "from", src, &packet[sizeof(struct idp)], size); \
- }
-#define TRACE_OUTPUT(ifp, dst, size) { \
- if (tracing) { \
- ifp = if_iflookup(dst); \
- if (ifp) \
- trace(&ifp->int_output, dst, &packet[sizeof(struct idp)], size, ifp->int_metric); \
- } \
- if (tracepackets && ftrace) \
- dumppacket(ftrace, "to", dst, &packet[sizeof(struct idp)], size); \
- }
diff --git a/sbin/chkconfig/chkconfig.c b/sbin/chkconfig/chkconfig.c
index 0c0f51da79d8..0c6af5ae851d 100644
--- a/sbin/chkconfig/chkconfig.c
+++ b/sbin/chkconfig/chkconfig.c
@@ -26,7 +26,7 @@
*/
const char chkconfig_c_rcsid[] =
- "$Id: chkconfig.c,v 1.4 1993/11/12 03:54:24 wollman Exp $";
+ "$Id: chkconfig.c,v 1.5 1994/04/17 09:22:15 alm Exp $";
#include <stdio.h>
#include <stdlib.h>
@@ -43,7 +43,7 @@ static int setvalue(const char *, int);
static int printvalues(void);
static void usage(void);
static void die(const char *);
-static int is_on(const char *);
+static int is_on(const char *, size_t);
const char *whoami;
static const char *configdir = _PATH_CONFIG;
@@ -101,7 +101,8 @@ int main(int argc, char **argv) {
return doflags ? printflags(argv[optind]) : testvalue(argv[optind]);
case 2:
- return setvalue(argv[optind], is_on(argv[optind + 1]));
+ return setvalue(argv[optind], is_on(argv[optind + 1],
+ strlen(argv[optind + 1])));
default:
usage();
@@ -109,11 +110,11 @@ int main(int argc, char **argv) {
}
}
-static int is_on(const char *str) {
- if(!str) return 0;
+static int is_on(const char *str, size_t len) {
+ if(!str || len < 2) return 0;
return ( ((str[0] == 'o') || (str[0] == 'O'))
&& ((str[1] == 'n') || (str[1] == 'N'))
- && ((str[2] == '\n')|| (str[2] == '\0')));
+ && ((len == 2) || (str[2] == '\n')));
}
static void chat(const char *str, int state) {
@@ -141,15 +142,16 @@ static int testvalue(const char *str) {
FILE *fp;
char *line;
const char *fname;
+ size_t len = 0;
int rv = 1; /* NB: shell's convention is opposite C's */
fname = confname(str, "");
fp = fopen(fname, "r");
if(fp) {
do {
- line = fgetline(fp, (size_t *)0);
+ line = fgetln(fp, &len);
} while(line && line[0] == '#');
- rv = !is_on(line); /* shell's convention is opposite C's */
+ rv = !is_on(line, len); /* shell's convention is opposite C's */
fclose(fp);
}
@@ -163,6 +165,7 @@ static char *getflags(const char *str) {
char *line;
const char *fname;
char *rv = strdup("");
+ size_t len = 0;
if(!rv) {
errno = ENOMEM;
@@ -173,17 +176,18 @@ static char *getflags(const char *str) {
fp = fopen(fname, "r");
if(fp) {
do {
- line = fgetline(fp, (size_t *)0);
+ line = fgetln(fp, &len);
} while(line && line[0] == '#');
if(line) {
free(rv);
- rv = strdup(line);
-
- if(!rv) {
+ if(line[len - 1] == '\n') --len;
+ if((rv = (char *) malloc(len + 1)) == NULL) {
errno = ENOMEM;
- die("getflags: strdup");
+ die("getflags: malloc");
}
+ bcopy(line, rv, len);
+ rv[len] = '\0';
}
fclose(fp);
diff --git a/sbin/comcontrol/comcontrol.8 b/sbin/comcontrol/comcontrol.8
index bcb44e1088ee..eec9520db62f 100644
--- a/sbin/comcontrol/comcontrol.8
+++ b/sbin/comcontrol/comcontrol.8
@@ -1,47 +1,30 @@
-.Dd December 10, 1993
+.Dd May 15, 1994
.Dt COMCONTROL 8
.Os FreeBSD
.Sh NAME
.Nm comcontrol
-.Nd "control the bidirectional status of a sio port and waiting time after DTR drop"
+.Nd control an sio device.
.Sh SYNOPSIS
.Nm comcontrol
.Ar sio_special_device
-.Op Cm bidir | Fl bidir
-.Op Cm dtrwait Ar ticks
+.Op options
.Sh DESCRIPTION
.Nm Comcontrol
-is used to examine and modify the bidirectional status
-of a specified
-sio communications port
-and its waiting time after DTR drop.
-By default (if
-.Ar sio_special_device
-only specified),
-.Nm comcontrol
-will print the current port state
-(if kernel was built with
-.Cm options COM_BIDIR )
-as either
-.Cm bidir
-to indicate that bidirectional operation is enabled or
-.Fl bidir
-to indicate that it is disabled, string
-.Cm dtrwait
-and current waiting time in ticks
-after DTR drop.
-To modify the status of the port or waiting time, simply
-specify the desired new state
-and/or new waiting time
-on the command line. All users with
-read access to the
-.Ar sio_special_device
-can use
-.Nm comcontrol
-to get the port's status and current waiting time.
-Only root can set a port's status and waiting time.
-By default, each port is initially unidirectional, waiting time is
-2 seconds.
+is used to examine and modify some of the special characterstics
+of the specified sio device.
+If no arguments other than the device are specified,
+it prints the settings of all controllable characteristics.
+This usage requires only read access on the device.
+Only the superuser can change the settings.
+.Pp
+The following options are available:
+.Bl -tag -width Fl
+.It Cm dtrwait Ar number
+Set the time to wait after dropping DTR
+to the given number.
+The units are hundredths of a second.
+The default is 300 hundredths, i.e., 3 seconds.
+.El
.Pp
The standard way to use
.Nm comcontrol
@@ -50,25 +33,21 @@ is to put invocations of it in the
startup script.
.Sh SEE ALSO
.Xr sio 4
+.Xr stty 1 .
.Sh FILES
.Bl -tag -width Pa
-.It Pa /dev/sio??
-.Sh DIAGNOSTICS
-.Cm TIOCMSBIDIR: Inappropriate ioctl for device.
-.Pp
-This indicates attempt to change port status on
-a non-sio special device file,
-or the kernel has not been built with
-.Cm options COM_BIDIR .
-For more information concerning reconfiguration
-of your kernel see
-.Ar /usr/src/sys/i386/doc/config_options.doc.
+.It Pa /dev/ttyd?
+dialin devices.
+.It Pa /dev/cua0?
+dialout devices.
.Sh AUTHOR
Christopher G. Demetriou
.Sh BUGS
-It is strongly recommended that you do *not*
-change the bidirectional status of a port while there are programs
-using the port. Read that as: if you do, and it breaks, don't yell
-at me; that's a really weird thing to do.
+.Nm comcontrol
+should be named
+.Nm siocontrol .
+.
.Sh HISTORY
Originally part of cgd's com package patches, version 0.2.1, to 386BSD 0.1.
+Once controlled bidirectional capabilities. Little is left to control now
+that these capabilities are standard.
diff --git a/sbin/comcontrol/comcontrol.c b/sbin/comcontrol/comcontrol.c
index e88e3d8f71e0..40cf8d25c8a8 100644
--- a/sbin/comcontrol/comcontrol.c
+++ b/sbin/comcontrol/comcontrol.c
@@ -38,7 +38,7 @@
void usage(char *progname)
{
- fprintf(stderr, "usage: %s <filename> [[-]bidir] [dtrwait <n>]\n", progname);
+ fprintf(stderr, "usage: %s <filename> [dtrwait <n>]\n", progname);
exit(1);
}
@@ -58,10 +58,6 @@ int main(int argc, char *argv[])
}
if (argc == 2) {
- if (ioctl(fd, TIOCMGBIDIR, &res) >= 0) {
- if (!res) printf("-");
- printf("bidir ");
- }
if (ioctl(fd, TIOCMGDTRWAIT, &dtrwait) < 0) {
perror("TIOCMGDTRWAIT");
exit(1);
@@ -72,17 +68,7 @@ int main(int argc, char *argv[])
res = dtrwait = -1;
while (argv[2] != NULL) {
- if (!strcmp(argv[2],"bidir")) {
- if (res >= 0)
- usage(prg);
- res = 1;
- argv++;
- } else if (!strcmp(argv[2],"-bidir")) {
- if (res >= 0)
- usage(prg);
- res = 0;
- argv++;
- } else if (!strcmp(argv[2],"dtrwait")) {
+ if (!strcmp(argv[2],"dtrwait")) {
if (dtrwait >= 0)
usage(prg);
if (argv[3] == NULL || !isdigit(argv[3][0]))
@@ -93,12 +79,6 @@ int main(int argc, char *argv[])
usage(prg);
}
}
- if (res >= 0) {
- if (ioctl(fd, TIOCMSBIDIR, &res) < 0) {
- perror("TIOCMSBIDIR");
- exit(1);
- }
- }
if (dtrwait >= 0) {
if (ioctl(fd, TIOCMSDTRWAIT, &dtrwait) < 0) {
perror("TIOCMSDTRWAIT");
diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c
index f8810370dd6a..4fd3bbdcd58e 100644
--- a/sbin/disklabel/disklabel.c
+++ b/sbin/disklabel/disklabel.c
@@ -88,13 +88,14 @@ static char sccsid[] = "@(#)disklabel.c 5.20 (Berkeley) 2/9/91";
#define RAWPARTITION 'c'
#endif
-#if defined(i386)
+#if defined(__386BSD__)
/* with 386BSD, 'c' maps the portion of the disk given over to 386BSD,
and 'd' maps the entire drive, ignoring any partition tables */
+#define LABELPARTITION ('c' - 'a')
#define RAWPARTITION 'd'
#endif
-#if defined(vax)==0 && defined(i386)==0
+#ifndef RAWPARTITION
#define RAWPARTITION 'a'
#endif
@@ -102,7 +103,7 @@ static char sccsid[] = "@(#)disklabel.c 5.20 (Berkeley) 2/9/91";
#define BBSIZE 8192 /* size of boot area, with label */
#endif
-#if defined(vax) || defined(i386)
+#if defined(vax) || defined(__386BSD__)
#define BOOT /* also have bootstrap in "boot area" */
#define BOOTDIR _PATH_BOOTDIR /* source of boot binaries */
#else
@@ -226,12 +227,14 @@ main(argc, argv)
* partition.
*/
dosdp = readmbr(f);
+#ifdef notdef /* not used (some bootstraps copy wd tables to 0x300) */
{ int mfd; unsigned char params[0x10];
/* sleezy, but we need it fast! */
mfd = open("/dev/mem", 0);
lseek(mfd, 0x300, 0);
read (mfd, params, 0x10);
}
+#endif
#endif
@@ -240,6 +243,19 @@ main(argc, argv)
if (argc != 1)
usage();
lp = readlabel(f);
+ if (lp == NULL) {
+ /*
+ * It's too much trouble to make -e -r work
+ * when there is no on-disk label.
+ *
+ * XXX -e without -r will fail if there is no
+ * on-disk label, but not until the user has
+ * wasted time editing the in-core label.
+ */
+ errno = ESRCH;
+ l_perror("-e flag is not suitable");
+ exit(1);
+ }
error = edit(lp, f);
break;
case NOWRITE: {
@@ -253,6 +269,12 @@ main(argc, argv)
usage();
lp = readlabel(f);
+ if (lp == NULL) {
+ fprintf(stderr,
+ "Ignoring -r and trying to read in-core label\n");
+ rflag = 0;
+ lp = readlabel(f);
+ }
display(stdout, lp);
error = checklabel(lp);
break;
@@ -370,7 +392,7 @@ writelabel(f, boot, lp)
register int i;
int flag;
#ifdef __386BSD__
- off_t lbl_off; struct partition *pp = lp->d_partitions;
+ off_t lbl_off; struct partition *pp = lp->d_partitions + LABELPARTITION;
#endif
lp->d_magic = DISKMAGIC;
@@ -385,7 +407,7 @@ writelabel(f, boot, lp)
* the label to be written is not within partition,
* prompt first. Need to allow this in case operator
* wants to convert the drive for dedicated use.
- * In this case, partition 'a' had better start at 0,
+ * In this case, partition 'c' had better start at 0,
* otherwise we reject the request as meaningless. -wfj
*/
@@ -394,15 +416,15 @@ writelabel(f, boot, lp)
lbl_off = pp->p_offset;
} else {
if (dosdp) {
- char c;
+ int c;
- printf("overwriting disk with DOS partition table? (n):");
+ printf("overwrite DOS partition table? [n]: ");
fflush(stdout);
c = getchar();
- if (c != EOF && c != (int)'\n')
- while (getchar() != (int)'\n')
+ if (c != EOF && c != '\n')
+ while (getchar() != '\n')
;
- if (c == (int)'n')
+ if (c != 'y')
exit(0);
}
lbl_off = 0;
@@ -444,10 +466,23 @@ writelabel(f, boot, lp)
if (lp->d_type != DTYPE_SCSI && lp->d_flags & D_BADSECT) {
daddr_t alt;
- alt = lp->d_ncylinders * lp->d_secpercyl - lp->d_nsectors;
+ /*
+ * XXX this knows too much about bad144 internals
+ */
+#ifdef __386BSD__
+#define BAD144_PART 2 /* XXX scattered magic numbers */
+#define BSD_PART 0 /* XXX should be 2 but bad144.c uses 0 */
+ if (lp->d_partitions[BSD_PART].p_offset != 0)
+ alt = lp->d_partitions[BAD144_PART].p_offset
+ + lp->d_partitions[BAD144_PART].p_size;
+ else
+#endif
+ alt = lp->d_secperunit;
+ alt -= lp->d_nsectors;
for (i = 1; i < 11 && i < lp->d_nsectors; i += 2) {
- (void)lseek(f, (off_t)((alt + i) * lp->d_secsize), L_SET);
- if (write(f, boot, lp->d_secsize) < lp->d_secsize) {
+ lseek(f, (off_t)((alt + i) * lp->d_secsize), L_SET);
+ if (write(f, boot + (LABELSECTOR * lp->d_secsize),
+ lp->d_secsize) < lp->d_secsize) {
int oerrno = errno;
fprintf(stderr, "alternate label %d ", i/2);
errno = oerrno;
@@ -471,7 +506,7 @@ l_perror(s)
case ESRCH:
fprintf(stderr, "No disk label on disk;\n");
fprintf(stderr,
- "use \"disklabel -r\" to install initial label\n");
+ "use flags \"-w -r\" or \"-R -r\" to install initial label\n");
break;
case EINVAL:
@@ -506,7 +541,7 @@ readmbr(f)
{
static struct dos_partition dos_partitions[NDOSPART];
struct dos_partition *dp, *bsdp;
- char mbr[DEV_BSIZE];
+ char mbr[DEV_BSIZE]; /* XXX - DOS_DEV_BSIZE */
int i, npart, nboot, njunk;
(void)lseek(f, (off_t)DOSBBSECTOR, L_SET);
@@ -519,6 +554,10 @@ readmbr(f)
* Don't (yet) know disk geometry (BIOS), use
* partition table to find 386BSD partition, and obtain
* disklabel from there.
+ *
+ * XXX - the checks for a valid partition table are inadequate.
+ * This gets called for floppies, which will never have an mbr
+ * and may have junk that looks like a partition table...
*/
dp = dos_partitions;
npart = njunk = nboot = 0;
@@ -533,6 +572,11 @@ readmbr(f)
}
/* valid partition table? */
+ /*
+ * XXX - ignore `nboot'. Drives other than the first do not need a
+ * boot flag. The first drive doesn't need a boot flag when it is
+ * booted from a multi-boot program.
+ */
if (npart == 0 || njunk) /* 18 Sep 92*/
/* was: if (nboot != 1 || npart == 0 || njunk)*/
return (0);
@@ -579,12 +623,9 @@ readlabel(f)
dkcksum(lp) != 0) {
fprintf(stderr,
"Bad pack magic number (label is damaged, or pack is unlabeled)\n");
- /* lp = (struct disklabel *)(bootarea + LABELOFFSET);
- exit (1); */
- goto tryioctl;
+ return (NULL);
}
} else {
-tryioctl:
lp = &lab;
if (ioctl(f, DIOCGDINFO, lp) < 0)
Perror("ioctl DIOCGDINFO");
@@ -746,7 +787,7 @@ display(f, lp)
(pp->p_offset +
pp->p_size + lp->d_secpercyl - 1) /
lp->d_secpercyl - 1);
- if (pp->p_size % lp->d_secpercyl)
+ if ((pp->p_offset + pp->p_size) % lp->d_secpercyl)
putc('*', f);
fprintf(f, ")\n");
}
@@ -791,10 +832,10 @@ edit(lp, f)
}
printf("re-edit the label? [y]: "); fflush(stdout);
c = getchar();
- if (c != EOF && c != (int)'\n')
- while (getchar() != (int)'\n')
+ if (c != EOF && c != '\n')
+ while (getchar() != '\n')
;
- if (c == (int)'n')
+ if (c == 'n')
break;
}
(void) unlink(tmpfil);
@@ -1169,6 +1210,7 @@ checklabel(lp)
register struct partition *pp;
int i, errors = 0;
char part;
+ unsigned long secper;
if (lp->d_secsize == 0) {
fprintf(stderr, "sector size %d\n", lp->d_secsize);
@@ -1188,10 +1230,31 @@ checklabel(lp)
}
if (lp->d_rpm == 0)
Warning("revolutions/minute %d\n", lp->d_rpm);
+ secper = lp->d_nsectors * lp->d_ntracks;
if (lp->d_secpercyl == 0)
- lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks;
+ lp->d_secpercyl = secper;
+ else if (lp->d_secpercyl != secper) {
+ fprintf(stderr, "sectors/cylinder %lu should be %lu\n",
+ lp->d_secpercyl, secper);
+ errors++;
+ }
+ secper = lp->d_secpercyl * lp->d_ncylinders;
if (lp->d_secperunit == 0)
- lp->d_secperunit = lp->d_secpercyl * lp->d_ncylinders;
+ lp->d_secperunit = secper;
+ else if (lp->d_secperunit != secper) {
+ /*
+ * lp->d_secperunit makes sense as a limit on the disk size
+ * independent of the product. However, bad144 handling at
+ * least requires it to be the same as the product, and the
+ * "whole disk" partition may be used to limit the size.
+ *
+ * XXX It's silly to accept derived quantities as input only
+ * to reject them.
+ */
+ fprintf(stderr, "sectors/unit %lu should be %lu\n",
+ lp->d_secperunit, secper);
+ errors++;
+ }
#ifdef __386BSD__notyet
if (dosdp && dosdp->dp_size && dosdp->dp_typ == DOSPTYP_386BSD
&& lp->d_secperunit > dosdp->dp_start + dosdp->dp_size) {
diff --git a/sbin/dump/dump.8 b/sbin/dump/dump.8
index ff5a914a191b..1cefb8f39747 100644
--- a/sbin/dump/dump.8
+++ b/sbin/dump/dump.8
@@ -31,7 +31,7 @@
.\"
.\" @(#)dump.8 6.8 (Berkeley) 6/17/91
.\"
-.\" $Header: /home/cvs/386BSD/src/sbin/dump/dump.8,v 1.2.2.1 1994/05/01 16:06:51 jkh Exp $
+.\" $Header: /home/cvs/386BSD/src/sbin/dump/dump.8,v 1.2 1993/07/22 16:49:13 jkh Exp $
.\"
.Dd June 17, 1991
.Dt DUMP 8
diff --git a/sbin/dump/dumpoptr.c b/sbin/dump/dumpoptr.c
index deff36a7fd19..5db2bc134473 100644
--- a/sbin/dump/dumpoptr.c
+++ b/sbin/dump/dumpoptr.c
@@ -33,7 +33,7 @@
#ifndef lint
static char sccsid[] = "@(#)dumpoptr.c 5.8 (Berkeley) 3/7/91";
-static char rcsid[] = "$Header: /home/cvs/386BSD/src/sbin/dump/dumpoptr.c,v 1.2 1993/07/22 16:49:17 jkh Exp $";
+static char rcsid[] = "$Header: /home/cvs/386BSD/src/sbin/dump/dumpoptr.c,v 1.3 1994/03/07 16:37:08 ats Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -505,6 +505,7 @@ lastdump(arg)
time(&tnow);
getfstab(); /* /etc/fstab input */
initdumptimes(); /* /etc/dumpdates input */
+ if(ddatev == NULL) exit(1); /* /etc/dumpdates doesn't exist */
qsort(ddatev, nddates, sizeof(struct dumpdates *), datesort);
if (arg == 'w')
diff --git a/sbin/dump/dumptape.c b/sbin/dump/dumptape.c
index 52992ecf8117..b1f7fddc82c6 100644
--- a/sbin/dump/dumptape.c
+++ b/sbin/dump/dumptape.c
@@ -33,7 +33,7 @@
#ifndef lint
static char sccsid[] = "@(#)dumptape.c 5.18 (Berkeley) 4/24/91";
-static char rcsid[] = "$Header: /home/cvs/386BSD/src/sbin/dump/dumptape.c,v 1.2 1993/07/22 16:49:19 jkh Exp $";
+static char rcsid[] = "$Header: /home/cvs/386BSD/src/sbin/dump/dumptape.c,v 1.3 1994/03/08 16:20:06 ats Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -66,7 +66,7 @@ char *nexttape;
extern char *host;
int rmtopen(), rmtwrite();
void rmtclose();
-#endif RDUMP
+#endif /* RDUMP */
int atomic();
void doslave(), enslave(), flushtape(), killall();
@@ -231,7 +231,7 @@ trewind()
rmtclose();
return;
}
-#endif RDUMP
+#endif /* RDUMP */
close(tapefd);
while ((f = open(tape, 0)) < 0)
sleep (10);
@@ -363,10 +363,10 @@ startnewtape()
#ifdef RDUMP
while ((tapefd = (host ? rmtopen(tape, 2) :
pipeout ? 1 : open(tape, O_WRONLY|O_CREAT, 0666))) < 0)
-#else RDUMP
+#else /* RDUMP */
while ((tapefd =
pipeout ? 1 : open(tape, O_WRONLY|O_CREAT, 0666)) < 0)
-#endif RDUMP
+#endif /* RDUMP */
{
msg("Cannot open output \"%s\".\n", tape);
if (!query("Do you want to retry the open?"))
@@ -404,6 +404,9 @@ dumpabort()
killall();
msg("The ENTIRE dump is aborted.\n");
}
+#ifdef RDUMP
+ rmtclose();
+#endif
Exit(X_ABORT);
}
@@ -538,10 +541,10 @@ doslave(cmd, prev, next)
#ifdef RDUMP
if ((nwrite = (host ? rmtwrite(tblock[0], writesize)
: write(tapefd, tblock[0], writesize))) != writesize) {
-#else RDUMP
+#else /* RDUMP */
if ((nwrite = write(tapefd, tblock[0], writesize))
!= writesize) {
-#endif RDUMP
+#endif /* RDUMP */
if (nwrite == -1)
perror("write");
else
diff --git a/sbin/dump/rdump.8 b/sbin/dump/rdump.8
index acbfeab5367b..41b65836cdf0 100644
--- a/sbin/dump/rdump.8
+++ b/sbin/dump/rdump.8
@@ -31,7 +31,7 @@
.\"
.\" @(#)rdump.8 6.3 (Berkeley) 3/16/91
.\"
-.\" $Header: /home/cvs/386BSD/src/sbin/dump/rdump.8,v 1.3.2.1 1994/05/01 16:06:53 jkh Exp $
+.\" $Header: /home/cvs/386BSD/src/sbin/dump/rdump.8,v 1.3 1993/09/13 21:25:13 rgrimes Exp $
.\"
.Dd March 16, 1991
.Dt RDUMP 8
diff --git a/sbin/fsck/fsck.8 b/sbin/fsck/fsck.8
index ecc96c322b53..b3ecd7b43f9f 100644
--- a/sbin/fsck/fsck.8
+++ b/sbin/fsck/fsck.8
@@ -31,7 +31,7 @@
.\"
.\" @(#)fsck.8 6.9 (Berkeley) 4/20/91
.\"
-.\" $Header: /home/cvs/386BSD/src/sbin/fsck/fsck.8,v 1.2.2.1 1994/05/01 16:06:58 jkh Exp $
+.\" $Header: /home/cvs/386BSD/src/sbin/fsck/fsck.8,v 1.2 1993/07/22 16:51:48 jkh Exp $
.\"
.TH FSCK 8 "April 20, 1991"
.UC 4
diff --git a/sbin/fsck/pass5.c b/sbin/fsck/pass5.c
index 475b9a15ed85..4d0385732b0b 100644
--- a/sbin/fsck/pass5.c
+++ b/sbin/fsck/pass5.c
@@ -33,7 +33,7 @@
#ifndef lint
static char sccsid[] = "@(#)pass5.c 5.13 (Berkeley) 7/20/90";
-static char rcsid[] = "$Header: /home/cvs/386BSD/src/sbin/fsck/pass5.c,v 1.2 1993/07/22 16:51:58 jkh Exp $";
+static char rcsid[] = "$Id: pass5.c,v 1.3 1994/05/05 23:41:06 wollman Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -42,6 +42,14 @@ static char rcsid[] = "$Header: /home/cvs/386BSD/src/sbin/fsck/pass5.c,v 1.2 199
#include <string.h>
#include "fsck.h"
+/*
+ * Allow time in cg summary data to be this number of seconds in the future.
+ * Currently we allow up to one day of slack because of problem that
+ * adjkerntz(8) can change the time by up to a day when it runs and adjusts
+ * the timezone.
+ */
+#define TIME_SLACK (60*60*24)
+
pass5()
{
int c, blk, frags, basesize, sumsize, mapsize, savednrpos;
@@ -110,7 +118,10 @@ pass5()
dmax = dbase + fs->fs_fpg;
if (dmax > fs->fs_size)
dmax = fs->fs_size;
- if (now > cg->cg_time)
+#ifndef TIME_SLACK
+#define TIME_SLACK 0
+#endif
+ if (now > cg->cg_time - TIME_SLACK)
newcg->cg_time = cg->cg_time;
else
newcg->cg_time = now;
diff --git a/sbin/fsck/setup.c b/sbin/fsck/setup.c
index 9f10ccb5b63a..e7e111371488 100644
--- a/sbin/fsck/setup.c
+++ b/sbin/fsck/setup.c
@@ -33,7 +33,7 @@
#ifndef lint
static char sccsid[] = "@(#)setup.c 5.33 (Berkeley) 2/22/91";
-static char rcsid[] = "$Header: /home/cvs/386BSD/src/sbin/fsck/setup.c,v 1.2 1993/07/22 16:52:00 jkh Exp $";
+static char rcsid[] = "$Header: /home/cvs/386BSD/src/sbin/fsck/setup.c,v 1.3 1994/03/07 22:27:23 ats Exp $";
#endif /* not lint */
#define DKTYPENAMES
@@ -461,6 +461,8 @@ calcsb(dev, devfd, fs)
fs->fs_cgoffset = roundup(
howmany(fs->fs_nsect, NSPF(fs)), fs->fs_frag);
fs->fs_fpg = (fs->fs_cpg * fs->fs_spc) / NSPF(fs);
+ /* Make sure, that fs->fs_cpg is not zero to avoid a divide by zero */
+ if(fs->fs_cpg == 0) fs->fs_cpg = 1;
fs->fs_ncg = howmany(fs->fs_size / fs->fs_spc, fs->fs_cpg);
for (fs->fs_fsbtodb = 0, i = NSPF(fs); i > 1; i >>= 1)
fs->fs_fsbtodb++;
diff --git a/sbin/fsck/utilities.c b/sbin/fsck/utilities.c
index 85b67288b52b..7fa78324e395 100644
--- a/sbin/fsck/utilities.c
+++ b/sbin/fsck/utilities.c
@@ -33,7 +33,7 @@
#ifndef lint
static char sccsid[] = "@(#)utilities.c 5.30 (Berkeley) 7/26/91";
-static char rcsid[] = "$Header: /home/cvs/386BSD/src/sbin/fsck/utilities.c,v 1.2 1993/07/22 16:52:01 jkh Exp $";
+static char rcsid[] = "$Header: /home/cvs/386BSD/src/sbin/fsck/utilities.c,v 1.3 1994/06/03 22:04:59 ats Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -195,7 +195,7 @@ flush(fd, bp)
{
register int i, j;
- if (!bp->b_dirty)
+ if (!bp || !bp->b_dirty)
return;
if (bp->b_errs != 0)
pfatal("WRITING %sZERO'ED BLOCK %d TO DISK\n",
@@ -240,7 +240,7 @@ ckfini()
}
flush(fswritefd, &cgblk);
free(cgblk.b_un.b_buf);
- for (bp = bufhead.b_prev; bp != &bufhead; bp = nbp) {
+ for (bp = bufhead.b_prev; bp && (bp != &bufhead); bp = nbp) {
cnt++;
flush(fswritefd, bp);
nbp = bp->b_prev;
diff --git a/sbin/ft/Makefile b/sbin/ft/Makefile
index 41acb7b37fb9..95e8a96f062f 100644
--- a/sbin/ft/Makefile
+++ b/sbin/ft/Makefile
@@ -1,7 +1,8 @@
-# $Id: Makefile,v 1.2 1994/02/07 08:40:16 rgrimes Exp $
+# $Id: Makefile,v 1.3 1994/06/22 04:49:02 jkh Exp $
PROG= ft
MAN8= ft.8
SRCS= ft.c ftecc.c
+COPTS= -O2 -finline-functions -funroll-loops -fexpensive-optimizations
.include <bsd.prog.mk>
diff --git a/sbin/ft/ft.8 b/sbin/ft/ft.8
index 477f09b36d28..962001ec7bef 100644
--- a/sbin/ft/ft.8
+++ b/sbin/ft/ft.8
@@ -40,7 +40,7 @@
.Sh SYNOPSIS
.Nm ft
.Op Fl f Ar tape
-.Op Fl description
+.Op Ar description
.Sh DESCRIPTION
The
.Nm ft
@@ -59,8 +59,8 @@ To extract /usr from tape:
.Bd -literal -offset indent
% ft | tar xvzf -
.Ed
-.Sh SEE ALSO
-.Xr qtar 1
+.\" .Sh SEE ALSO
+.\" .Xr qtar 1
.Sh BUGS
Formatting/Verifying is in the works. You will need to use your
existing backup program to do this for the time being.
diff --git a/sbin/ft/ft.c b/sbin/ft/ft.c
index 4aa92f81625f..49aadd3331cc 100644
--- a/sbin/ft/ft.c
+++ b/sbin/ft/ft.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1993 Steve Gerakines
+ * Copyright (c) 1993, 1994 Steve Gerakines
*
* This is freely redistributable software. You may do anything you
* wish with it, so long as the above notice stays intact.
@@ -18,6 +18,10 @@
*
* ft.c - simple floppy tape filter
*
+ * 06/07/94 v1.0 ++sg
+ * Added support for tape retension. Added retries for ecc failures.
+ * Moved to release.
+ *
* 01/28/94 v0.3b (Jim Babb)
* Fixed bug when all sectors in a segment are marked bad.
*
@@ -27,7 +31,7 @@
* 09/02/93 v0.2 pl01
* Initial revision.
*
- * usage: ftfilt [ -f tape ] [ description ]
+ * usage: ft [ -f tape ] [ description ]
*/
#include <stdio.h>
@@ -51,6 +55,7 @@ int tvlast; /* TRUE if last volume in set */
long tvsize = 0; /* tape volume size in bytes */
long tvtime = NULL; /* tape change time */
char *tvnote = ""; /* tape note */
+int doretension = 0; /* TRUE if we should retension tape */
/* Lookup the badmap for a given track and segment. */
#define BADMAP(t,s) hptr->qh_badmap[(t)*geo.g_segtrk+(s)]
@@ -62,45 +67,22 @@ char *tvnote = ""; /* tape note */
#define equal(s1,s2) (strcmp(s1, s2) == 0)
-
-/* Entry */
-main(int argc, char *argv[])
+/*
+ * Print tape usage and then leave.
+ */
+void
+usage(void)
{
- int r, s;
- char *tape, *getenv();
-
- if (argc > 2 && (equal(argv[1], "-t") || equal(argv[1], "-f"))) {
- argc -= 2;
- tape = argv[2];
- argv += 2;
- } else
- if ((tape = getenv("TAPE")) == NULL)
- tape = DEFQIC;
- if (argc > 1) {
- tvnote = argv[1];
- if (strlen(tvnote) > 18) argv[1][18] = '\0';
- }
-
- /* Open the tape device */
- if ((tfd = open(tape, 2)) < 0) {
- perror(tape);
- exit(1);
- }
-
- if (!isatty(0))
- do_write();
- else if (!isatty(1))
- do_read();
- else
- do_getname();
-
- close(tfd);
- exit(0);
+ fprintf(stderr, "usage: ft [ -r ] [ -f device ] [ \"description\" ]\n");
+ exit(1);
}
-/* Check status of tape drive */
-int check_stat(int fd, int wr)
+/*
+ * Check status of tape drive
+ */
+int
+check_stat(int fd, int wr)
{
int r, s;
int sawit = 0;
@@ -138,8 +120,11 @@ int check_stat(int fd, int wr)
}
-
-ULONG qtimeval(time_t t)
+/*
+ * Convert time_t value to QIC time value.
+ */
+ULONG
+qtimeval(time_t t)
{
struct tm *tp;
ULONG r;
@@ -154,8 +139,12 @@ ULONG qtimeval(time_t t)
return(r);
}
-/* Return tm struct from QIC date format. */
-struct tm *qtime(UCHAR *qt)
+
+/*
+ * Return tm struct from QIC date format.
+ */
+struct tm *
+qtime(UCHAR *qt)
{
ULONG *vp = (ULONG *)qt;
struct tm t;
@@ -178,7 +167,10 @@ struct tm *qtime(UCHAR *qt)
return(localtime(&tv));
}
-/* Return a string, zero terminated */
+
+/*
+ * Return a string, zero terminated.
+ */
char *qstr(char *str, int nchar)
{
static char tstr[256];
@@ -187,7 +179,11 @@ char *qstr(char *str, int nchar)
return(tstr);
}
-/* Read header from tape */
+
+/*
+ * Read header from tape
+ */
+int
get_header(int fd)
{
int r, sn, bytes;
@@ -238,6 +234,9 @@ get_header(int fd)
}
+/*
+ * Open /dev/tty and ask for next volume.
+ */
ask_vol(int vn)
{
FILE *inp;
@@ -255,21 +254,26 @@ ask_vol(int vn)
}
-/* Return the name of the tape only. */
-do_getname()
+/*
+ * Return the name of the tape only.
+ */
+void
+do_getname(void)
{
if (check_stat(tfd, 0)) exit(1);
if (get_header(tfd)) exit(1);
fprintf(stderr, "\"%s\" - %s",
qstr(hptr->qh_tname,44), asctime(qtime(hptr->qh_chgdate)));
- ioctl(tfd, QIOREWIND);
}
-/* Extract data from tape to stdout */
-do_read()
+/*
+ * Extract data from tape to stdout.
+ */
+void
+do_read(void)
{
- int sno, vno, sbytes, r;
+ int sno, vno, sbytes, r, eccfails;
long curpos;
char *hname;
QIC_Segment s;
@@ -281,6 +285,13 @@ do_read()
ask_vol(vno);
continue;
}
+
+ if (doretension) {
+ ioctl(tfd, QIOBOT);
+ ioctl(tfd, QIOEOT);
+ ioctl(tfd, QIOBOT);
+ }
+
if (get_header(tfd)) {
ask_vol(vno);
continue;
@@ -303,36 +314,50 @@ do_read()
/* Process this volume */
curpos = 0;
- for (sno = hptr->qh_first; tvsize > 0; sno++) {
+ eccfails = 0;
+ sno = hptr->qh_first;
+ while (tvsize > 0) {
s.sg_trk = sno / geo.g_segtrk;
s.sg_seg = sno % geo.g_segtrk;
s.sg_badmap = BADMAP(s.sg_trk,s.sg_seg);
sbytes = sect_bytes(s.sg_badmap) - QCV_ECCSIZE;
s.sg_data = (UCHAR *)&buff[0];
-
- /* skip segments with *all* sectors flagged as bad */
- if (sbytes > 0) {
- if (ioctl(tfd, QIOREAD, &s) < 0) perror("QIOREAD");
- r = check_parity(s.sg_data, s.sg_badmap, s.sg_crcmap);
- if (r) fprintf(stderr, "** warning: ecc failed at byte %ld\n",
- curpos);
- if (tvsize < sbytes) sbytes = tvsize;
- write(1, s.sg_data, sbytes);
- tvsize -= sbytes;
- curpos += sbytes;
+ if (sbytes <= 0) {
+ sno++;
+ continue;
+ }
+ if (ioctl(tfd, QIOREAD, &s) < 0) perror("QIOREAD");
+
+ if (check_parity(s.sg_data, s.sg_badmap, s.sg_crcmap)) {
+ if (++eccfails <= 5) {
+ fprintf(stderr,
+ "ft: retry %d at segment %d byte %ld\n",
+ eccfails, sno, curpos);
+ continue;
+ } else
+ fprintf(stderr,
+ "ft: *** ecc failure in segment %d at byte %ld\n",
+ sno, curpos);
}
+ if (tvsize < sbytes) sbytes = tvsize;
+ write(1, s.sg_data, sbytes);
+ tvsize -= sbytes;
+ curpos += sbytes;
+ sno++;
+ eccfails = 0;
}
if (tvlast) break;
ioctl(tfd, QIOREWIND);
ask_vol(++vno);
}
- ioctl(tfd, QIOREWIND);
- return(0);
}
-/* Dump data from stdin to tape */
-do_write()
+/*
+ * Dump data from stdin to tape.
+ */
+void
+do_write(void)
{
int sno, vno, amt, sbytes;
int c, maxseg, r;
@@ -348,6 +373,13 @@ do_write()
ask_vol(vno);
continue;
}
+
+ if (doretension) {
+ ioctl(tfd, QIOBOT);
+ ioctl(tfd, QIOEOT);
+ ioctl(tfd, QIOBOT);
+ }
+
if (get_header(tfd)) {
ask_vol(vno);
continue;
@@ -376,6 +408,7 @@ do_write()
break;
}
}
+
/* skip the segment if *all* sectors are flagged as bad */
if (amt) {
if (amt < sbytes)
@@ -410,7 +443,7 @@ do_write()
if (ioctl(tfd, QIOWRITE, &s) < 0) {
perror("QIOWRITE");
exit(1);
- }
+ }
}
if (dhsn >= 0) {
s.sg_trk = dhsn / geo.g_segtrk;
@@ -428,5 +461,57 @@ do_write()
if (tvlast) break;
ask_vol(++vno);
}
- return(0);
+}
+
+
+/*
+ * Entry.
+ */
+void
+main(int argc, char *argv[])
+{
+ int r, s, i;
+ char *tape, *getenv();
+
+
+ /* Get device from environment, command line will override. */
+ if ((tape = getenv("TAPE")) == NULL) tape = DEFQIC;
+
+ /* Process args. */
+ for (i = 1; i < argc; i++) {
+ if (argv[i][0] != '-') break;
+ switch (argv[i][1]) {
+ case 'f':
+ case 't':
+ if (i == (argc - 1)) usage();
+ tape = argv[++i];
+ break;
+ case 'r':
+ doretension = 1;
+ break;
+ default:
+ usage();
+ }
+ }
+ if (i < (argc - 1)) usage();
+ if (i < argc) {
+ tvnote = argv[i];
+ if (strlen(tvnote) > 18) argv[i][18] = '\0';
+ }
+
+ /* Open the tape device */
+ if ((tfd = open(tape, 2)) < 0) {
+ perror(tape);
+ exit(1);
+ }
+
+ if (!isatty(0))
+ do_write();
+ else if (!isatty(1))
+ do_read();
+ else
+ do_getname();
+
+ close(tfd);
+ exit(0);
}
diff --git a/sbin/ft/ftecc.c b/sbin/ft/ftecc.c
index 430f3a8316bb..fbba10f07fa5 100644
--- a/sbin/ft/ftecc.c
+++ b/sbin/ft/ftecc.c
@@ -1,32 +1,46 @@
/*
- * ftecc.c 10/30/93 v0.3
- * Handle error correction for floppy tape drives.
+ * Copyright (c) 1994 Steve Gerakines
*
- * File contents are copyrighted by David L. Brown and falls under the
- * terms of the GPL version 2 or greater. See his original release for
- * the specific terms.
+ * This is freely redistributable software. You may do anything you
+ * wish with it, so long as the above notice stays intact.
*
- * Steve Gerakines
- * steve2@genesis.nred.ma.us
- * Modified slightly to fit with my tape driver. I'm not at all happy
- * with this module and will have it replaced with a more functional one
- * in the next release(/RSN). I am close, but progress will continue to
- * be slow until I can find a book on the subject where the translator
- * understands both the to and from languages. :-( For now it will
- * suffice.
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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 AUTHOR(S) 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.
+ *
+ * ftecc.c - QIC-40/80 Reed-Solomon error correction
+ * 05/30/94 v1.0 ++sg
+ * Did some minor optimization. The multiply by 0xc0 was a dog so it
+ * was replaced with a table lookup. Fixed a couple of places where
+ * bad sectors could go unnoticed. Moved to release.
+ *
+ * 03/22/94 v0.4
+ * Major re-write. It can handle everything required by QIC now.
+ *
+ * 09/14/93 v0.2 pl01
+ * Modified slightly to fit with my driver. Based entirely upon David
+ * L. Brown's package.
*/
#include <sys/ftape.h>
-/*
- * In order to speed up the correction and adjustment, we can compute
- * a matrix of coefficients for the multiplication.
- */
+/* Inverse matrix */
struct inv_mat {
- UCHAR log_denom; /* The log z of the denominator. */
- UCHAR zs[3][3]; /* The coefficients for the adjustment matrix. */
+ UCHAR log_denom; /* Log of the denominator */
+ UCHAR zs[3][3]; /* The matrix */
};
-/* This array is a table of powers of x, from 0 to 254. */
+
+/*
+ * Powers of x, modulo 255.
+ */
static UCHAR alpha_power[] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x87, 0x89, 0x95, 0xad, 0xdd, 0x3d, 0x7a, 0xf4,
@@ -59,12 +73,12 @@ static UCHAR alpha_power[] = {
0xc8, 0x17, 0x2e, 0x5c, 0xb8, 0xf7, 0x69, 0xd2,
0x23, 0x46, 0x8c, 0x9f, 0xb9, 0xf5, 0x6d, 0xda,
0x33, 0x66, 0xcc, 0x1f, 0x3e, 0x7c, 0xf8, 0x77,
- 0xee, 0x5b, 0xb6, 0xeb, 0x51, 0xa2, 0xc3
+ 0xee, 0x5b, 0xb6, 0xeb, 0x51, 0xa2, 0xc3, 0x01
};
+
/*
- * This is the reverse lookup table. There is no log of 0, so the
- * first element is not valid.
+ * Log table, modulo 255 + 1.
*/
static UCHAR alpha_log[] = {
0xff, 0x00, 0x01, 0x63, 0x02, 0xc6, 0x64, 0x6a,
@@ -101,8 +115,51 @@ static UCHAR alpha_log[] = {
0xf6, 0x87, 0xa5, 0x17, 0x3a, 0xa3, 0x3c, 0xb7
};
-/* Return number of sectors available in a segment. */
-int sect_count(ULONG badmap)
+
+/*
+ * Multiplication table for 0xc0.
+ */
+static UCHAR mult_c0[] = {
+ 0x00, 0xc0, 0x07, 0xc7, 0x0e, 0xce, 0x09, 0xc9,
+ 0x1c, 0xdc, 0x1b, 0xdb, 0x12, 0xd2, 0x15, 0xd5,
+ 0x38, 0xf8, 0x3f, 0xff, 0x36, 0xf6, 0x31, 0xf1,
+ 0x24, 0xe4, 0x23, 0xe3, 0x2a, 0xea, 0x2d, 0xed,
+ 0x70, 0xb0, 0x77, 0xb7, 0x7e, 0xbe, 0x79, 0xb9,
+ 0x6c, 0xac, 0x6b, 0xab, 0x62, 0xa2, 0x65, 0xa5,
+ 0x48, 0x88, 0x4f, 0x8f, 0x46, 0x86, 0x41, 0x81,
+ 0x54, 0x94, 0x53, 0x93, 0x5a, 0x9a, 0x5d, 0x9d,
+ 0xe0, 0x20, 0xe7, 0x27, 0xee, 0x2e, 0xe9, 0x29,
+ 0xfc, 0x3c, 0xfb, 0x3b, 0xf2, 0x32, 0xf5, 0x35,
+ 0xd8, 0x18, 0xdf, 0x1f, 0xd6, 0x16, 0xd1, 0x11,
+ 0xc4, 0x04, 0xc3, 0x03, 0xca, 0x0a, 0xcd, 0x0d,
+ 0x90, 0x50, 0x97, 0x57, 0x9e, 0x5e, 0x99, 0x59,
+ 0x8c, 0x4c, 0x8b, 0x4b, 0x82, 0x42, 0x85, 0x45,
+ 0xa8, 0x68, 0xaf, 0x6f, 0xa6, 0x66, 0xa1, 0x61,
+ 0xb4, 0x74, 0xb3, 0x73, 0xba, 0x7a, 0xbd, 0x7d,
+ 0x47, 0x87, 0x40, 0x80, 0x49, 0x89, 0x4e, 0x8e,
+ 0x5b, 0x9b, 0x5c, 0x9c, 0x55, 0x95, 0x52, 0x92,
+ 0x7f, 0xbf, 0x78, 0xb8, 0x71, 0xb1, 0x76, 0xb6,
+ 0x63, 0xa3, 0x64, 0xa4, 0x6d, 0xad, 0x6a, 0xaa,
+ 0x37, 0xf7, 0x30, 0xf0, 0x39, 0xf9, 0x3e, 0xfe,
+ 0x2b, 0xeb, 0x2c, 0xec, 0x25, 0xe5, 0x22, 0xe2,
+ 0x0f, 0xcf, 0x08, 0xc8, 0x01, 0xc1, 0x06, 0xc6,
+ 0x13, 0xd3, 0x14, 0xd4, 0x1d, 0xdd, 0x1a, 0xda,
+ 0xa7, 0x67, 0xa0, 0x60, 0xa9, 0x69, 0xae, 0x6e,
+ 0xbb, 0x7b, 0xbc, 0x7c, 0xb5, 0x75, 0xb2, 0x72,
+ 0x9f, 0x5f, 0x98, 0x58, 0x91, 0x51, 0x96, 0x56,
+ 0x83, 0x43, 0x84, 0x44, 0x8d, 0x4d, 0x8a, 0x4a,
+ 0xd7, 0x17, 0xd0, 0x10, 0xd9, 0x19, 0xde, 0x1e,
+ 0xcb, 0x0b, 0xcc, 0x0c, 0xc5, 0x05, 0xc2, 0x02,
+ 0xef, 0x2f, 0xe8, 0x28, 0xe1, 0x21, 0xe6, 0x26,
+ 0xf3, 0x33, 0xf4, 0x34, 0xfd, 0x3d, 0xfa, 0x3a
+};
+
+
+/*
+ * Return number of sectors available in a segment.
+ */
+int
+sect_count(ULONG badmap)
{
int i, amt;
@@ -111,8 +168,12 @@ int sect_count(ULONG badmap)
return(amt);
}
-/* Return number of bytes available in a segment. */
-int sect_bytes(ULONG badmap)
+
+/*
+ * Return number of bytes available in a segment.
+ */
+int
+sect_bytes(ULONG badmap)
{
int i, amt;
@@ -121,146 +182,215 @@ int sect_bytes(ULONG badmap)
return(amt);
}
-/* Multiply two numbers in the field. */
-static UCHAR multiply(UCHAR a, UCHAR b)
+
+/*
+ * Multiply two numbers in the field.
+ */
+static inline UCHAR
+multiply(UCHAR a, UCHAR b)
{
int tmp;
- if (a == 0 || b == 0) return(0);
- tmp = (alpha_log[a] + alpha_log[b]);
+ if (!a || !b) return(0);
+ tmp = alpha_log[a] + alpha_log[b];
if (tmp > 254) tmp -= 255;
- return (alpha_power[tmp]);
+ return(alpha_power[tmp]);
+}
+
+
+/*
+ * Multiply by an exponent.
+ */
+static inline UCHAR
+multiply_out(UCHAR a, int b)
+{
+ int tmp;
+
+ if (!a) return(0);
+ tmp = alpha_log[a] + b;
+ if (tmp > 254) tmp -= 255;
+ return(alpha_power[tmp]);
}
-static UCHAR divide(UCHAR a, UCHAR b)
+
+/*
+ * Divide two numbers.
+ */
+static inline UCHAR
+divide(UCHAR a, UCHAR b)
{
int tmp;
- if (a == 0 || b == 0) return(0);
- tmp = (alpha_log[a] - alpha_log[b]);
+ if (!a || !b) return(0);
+ tmp = alpha_log[a] - alpha_log[b];
if (tmp < 0) tmp += 255;
return (alpha_power[tmp]);
}
+
/*
- * This is just like divide, except we have already looked up the log
- * of the second number.
+ * Divide using exponent.
*/
-static UCHAR divide_out(UCHAR a, UCHAR b)
+static inline UCHAR
+divide_out(UCHAR a, UCHAR b)
{
int tmp;
- if (a == 0) return 0;
+ if (!a) return 0;
tmp = alpha_log[a] - b;
if (tmp < 0) tmp += 255;
return (alpha_power[tmp]);
}
-/* This returns the value z^{a-b}. */
-static UCHAR z_of_ab(UCHAR a, UCHAR b)
+
+/*
+ * This returns the value z^{a-b}.
+ */
+static inline UCHAR
+z_of_ab(UCHAR a, UCHAR b)
{
- int tmp = (int)a - (int)b;
+ int tmp = a - b;
- if (tmp < 0)
- tmp += 255;
- else if (tmp >= 255)
- tmp -= 255;
+ if (tmp < 0) tmp += 255;
return(alpha_power[tmp]);
}
-/* Calculate the inverse matrix. Returns 1 if the matrix is valid, or
- * zero if there is no inverse. The i's are the indices of the bytes
- * to be corrected.
+
+/*
+ * Calculate the inverse matrix for two or three errors. Returns 0
+ * if there is no inverse or 1 if successful.
*/
-static int calculate_inverse (int *pblk, struct inv_mat *inv)
+static inline int
+calculate_inverse(int nerrs, int *pblk, struct inv_mat *inv)
{
/* First some variables to remember some of the results. */
UCHAR z20, z10, z21, z12, z01, z02;
UCHAR i0, i1, i2;
+ UCHAR iv0, iv1, iv2;
- i0 = pblk[0]; i1 = pblk[1]; i2 = pblk[2];
+ if (nerrs < 2) return(1);
+ if (nerrs > 3) return(0);
- z20 = z_of_ab (i2, i0); z10 = z_of_ab (i1, i0);
- z21 = z_of_ab (i2, i1); z12 = z_of_ab (i1, i2);
- z01 = z_of_ab (i0, i1); z02 = z_of_ab (i0, i2);
- inv->log_denom = (z20 ^ z10 ^ z21 ^ z12 ^ z01 ^ z02);
- if (inv->log_denom == 0) return 0;
- inv->log_denom = alpha_log[inv->log_denom];
-
- /* Calculate all of the coefficients on the top. */
- inv->zs[0][0] = alpha_power[i1] ^ alpha_power[i2];
- inv->zs[0][1] = z21 ^ z12;
- inv->zs[0][2] = alpha_power[255-i1] ^ alpha_power[255-i2];
-
- inv->zs[1][0] = alpha_power[i0] ^ alpha_power[i2];
- inv->zs[1][1] = z20 ^ z02;
- inv->zs[1][2] = alpha_power[255-i0] ^ alpha_power[255-i2];
-
- inv->zs[2][0] = alpha_power[i0] ^ alpha_power[i1];
- inv->zs[2][1] = z10 ^ z01;
- inv->zs[2][2] = alpha_power[255-i0] ^ alpha_power[255-i1];
+ i0 = pblk[0]; i1 = pblk[1]; i2 = pblk[2];
+ if (nerrs == 2) {
+ /* 2 errs */
+ z01 = alpha_power[255 - i0];
+ z02 = alpha_power[255 - i1];
+ inv->log_denom = (z01 ^ z02);
+ if (!inv->log_denom) return(0);
+ inv->log_denom = 255 - alpha_log[inv->log_denom];
+
+ inv->zs[0][0] = multiply_out( 1, inv->log_denom);
+ inv->zs[0][1] = multiply_out(z02, inv->log_denom);
+ inv->zs[1][0] = multiply_out( 1, inv->log_denom);
+ inv->zs[1][1] = multiply_out(z01, inv->log_denom);
+ } else {
+ /* 3 errs */
+ z20 = z_of_ab (i2, i0);
+ z10 = z_of_ab (i1, i0);
+ z21 = z_of_ab (i2, i1);
+ z12 = z_of_ab (i1, i2);
+ z01 = z_of_ab (i0, i1);
+ z02 = z_of_ab (i0, i2);
+ inv->log_denom = (z20 ^ z10 ^ z21 ^ z12 ^ z01 ^ z02);
+ if (!inv->log_denom) return(0);
+ inv->log_denom = 255 - alpha_log[inv->log_denom];
+
+ iv0 = alpha_power[255 - i0];
+ iv1 = alpha_power[255 - i1];
+ iv2 = alpha_power[255 - i2];
+ i0 = alpha_power[i0];
+ i1 = alpha_power[i1];
+ i2 = alpha_power[i2];
+ inv->zs[0][0] = multiply_out(i1 ^ i2, inv->log_denom);
+ inv->zs[0][1] = multiply_out(z21 ^ z12, inv->log_denom);
+ inv->zs[0][2] = multiply_out(iv1 ^ iv2, inv->log_denom);
+ inv->zs[1][0] = multiply_out(i0 ^ i2, inv->log_denom);
+ inv->zs[1][1] = multiply_out(z20 ^ z02, inv->log_denom);
+ inv->zs[1][2] = multiply_out(iv0 ^ iv2, inv->log_denom);
+ inv->zs[2][0] = multiply_out(i0 ^ i1, inv->log_denom);
+ inv->zs[2][1] = multiply_out(z10 ^ z01, inv->log_denom);
+ inv->zs[2][2] = multiply_out(iv0 ^ iv1, inv->log_denom);
+ }
return(1);
}
+
/*
- * Determine the error values for a given inverse matrix and syndromes.
+ * Determine the error magnitudes for a given matrix and syndromes.
*/
-static void determine3(struct inv_mat *inv, UCHAR *es, UCHAR *ss)
+static inline void
+determine(int nerrs, struct inv_mat *inv, UCHAR *ss, UCHAR *es)
{
UCHAR tmp;
int i, j;
- for (i = 0; i < 3; i++) {
- tmp = 0;
- for (j = 0; j < 3; j++) tmp ^= multiply (ss[j], inv->zs[i][j]);
- es[i] = divide_out(tmp, inv->log_denom);
+ for (i = 0; i < nerrs; i++) {
+ es[i] = 0;
+ for (j = 0; j < nerrs; j++)
+ es[i] ^= multiply(ss[j], inv->zs[i][j]);
}
}
/*
- * Compute the 3 syndrome values. The data pointer should point to
- * the offset within the first block of the column to calculate. The
- * count of blocks is in blocks. The three bytes will be placed in
- * ss[0], ss[1], and ss[2].
+ * Compute the 3 syndrome values.
*/
-static void compute_syndromes(UCHAR *data, int nblks, int col, UCHAR *ss)
+static inline int
+compute_syndromes(UCHAR *data, int nblks, int col, UCHAR *ss)
{
- int i;
- UCHAR v;
-
- ss[0] = 0; ss[1] = 0; ss[2] = 0;
- for (i = (nblks-1)*QCV_BLKSIZE; i >= 0; i -= QCV_BLKSIZE) {
- v = data[i+col];
- if (ss[0] & 0x01) { ss[0] >>= 1; ss[0] ^= 0xc3; } else ss[0] >>= 1;
- ss[0] ^= v;
- ss[1] ^= v;
- if (ss[2] & 0x80) { ss[2] <<= 1; ss[2] ^= 0x87; } else ss[2] <<= 1;
- ss[2] ^= v;
+ UCHAR r0, r1, r2, t1, t2;
+ UCHAR *rptr;
+
+ rptr = data + col;
+ data += nblks << 10;
+ r0 = r1 = r2 = 0;
+ while (rptr < data) {
+ t1 = *rptr ^ r0;
+ t2 = mult_c0[t1];
+ r0 = t2 ^ r1;
+ r1 = t2 ^ r2;
+ r2 = t1;
+ rptr += QCV_BLKSIZE;
+ }
+ if (r0 || r1 || r2) {
+ ss[0] = divide_out(r0 ^ divide_out(r1 ^ divide_out(r2, 1), 1), nblks);
+ ss[1] = r0 ^ r1 ^ r2;
+ ss[2] = multiply_out(r0 ^ multiply_out(r1 ^ multiply_out(r2, 1), 1), nblks);
+ return(0);
}
+ return(1);
}
+
/*
- * Calculate the parity bytes for a segment. Returns 0 on success.
+ * Calculate the parity bytes for a segment, returns 0 on success (always).
*/
-int set_parity (UCHAR *data, ULONG badmap)
+int
+set_parity (UCHAR *data, ULONG badmap)
{
- int col;
- struct inv_mat inv;
- UCHAR ss[3], es[3];
- int nblks, pblk[3];
-
- nblks = sect_count(badmap);
- pblk[0] = nblks-3; pblk[1] = nblks-2; pblk[2] = nblks-1;
- if (!calculate_inverse(pblk, &inv)) return(1);
-
- pblk[0] *= QCV_BLKSIZE; pblk[1] *= QCV_BLKSIZE; pblk[2] *= QCV_BLKSIZE;
- for (col = 0; col < QCV_BLKSIZE; col++) {
- compute_syndromes (data, nblks-3, col, ss);
- determine3(&inv, es, ss);
- data[pblk[0]+col] = es[0];
- data[pblk[1]+col] = es[1];
- data[pblk[2]+col] = es[2];
+ UCHAR r0, r1, r2, t1, t2;
+ UCHAR *rptr;
+ int max, row, col;
+
+ max = sect_count(badmap) - 3;
+ col = QCV_BLKSIZE;
+ while (col--) {
+ rptr = data;
+ r0 = r1 = r2 = 0;
+ row = max;
+ while (row--) {
+ t1 = *rptr ^ r0;
+ t2 = mult_c0[t1];
+ r0 = t2 ^ r1;
+ r1 = t2 ^ r2;
+ r2 = t1;
+ rptr += QCV_BLKSIZE;
+ }
+ *rptr = r0; rptr += QCV_BLKSIZE;
+ *rptr = r1; rptr += QCV_BLKSIZE;
+ *rptr = r2;
+ data++;
}
return(0);
}
@@ -270,47 +400,81 @@ int set_parity (UCHAR *data, ULONG badmap)
* Check and correct errors in a block. Returns 0 on success,
* 1 if failed.
*/
-int check_parity(UCHAR *data, ULONG badmap, ULONG crcmap)
+int
+check_parity(UCHAR *data, ULONG badmap, ULONG crcmap)
{
- int i, j, col, crcerrs, r, tries, nblks;
- struct inv_mat inv;
+ int crcerrs, eblk[3];
+ int col, row;
+ int i, j, nblks;
UCHAR ss[3], es[3];
- int i1, i2, eblk[3];
+ int i1, i2, saverrs;
+ struct inv_mat inv;
nblks = sect_count(badmap);
- crcerrs = 0;
- for (i = 0; crcerrs < 3 && i < nblks; i++)
- if (crcmap & (1 << i)) eblk[crcerrs++] = i;
- for (i = 1, j = crcerrs; j < 3 && i < nblks; i++)
- if ((crcmap & (1 << i)) == 0) eblk[j++] = i;
+ /* Count the number of CRC errors and note their locations. */
+ crcerrs = 0;
+ if (crcmap) {
+ for (i = 0; i < nblks; i++) {
+ if (crcmap & (1 << i)) {
+ if (crcerrs == 3) return(1);
+ eblk[crcerrs++] = i;
+ }
+ }
+ }
- if (!calculate_inverse (eblk, &inv)) return(1);
+ /* Calculate the inverse matrix */
+ if (!calculate_inverse(crcerrs, eblk, &inv)) return(1);
- eblk[0] *= QCV_BLKSIZE; eblk[1] *= QCV_BLKSIZE; eblk[2] *= QCV_BLKSIZE;
- r = 0;
+ /* Scan each column for problems and attempt to correct. */
for (col = 0; col < QCV_BLKSIZE; col++) {
- compute_syndromes (data, nblks, col, ss);
-
- if (!ss[0] && !ss[1] && !ss[2]) continue;
- if (crcerrs) {
- determine3 (&inv, es, ss);
- for (j = 0; j < crcerrs; j++)
- data[eblk[j] + col] ^= es[j];
- compute_syndromes (data, nblks, col, ss);
- if (!ss[0] && !ss[1] && !ss[2]) {
- r = 1;
- continue;
+ if (compute_syndromes(data, nblks, col, ss)) continue;
+ es[0] = es[1] = es[2] = 0;
+
+ /* Analyze the error situation. */
+ switch (crcerrs) {
+ case 0: /* 0 errors >0 failures */
+ if (!ss[0]) return(1);
+ eblk[crcerrs] = alpha_log[divide(ss[1], ss[0])];
+ if (eblk[crcerrs] >= nblks) return(1);
+ es[0] = ss[1];
+ if (++crcerrs > 3) return(1);
+ break;
+
+ case 1: /* 1 error (+ possible failures) */
+ i1 = ss[2] ^ multiply_out(ss[1], eblk[0]);
+ i2 = ss[1] ^ multiply_out(ss[0], eblk[0]);
+ if (!i1 && !i2) { /* only 1 error */
+ inv.zs[0][0] = alpha_power[eblk[0]];
+ inv.log_denom = 0;
+ } else if (!i1 || !i2) { /* too many errors */
+ return(1);
+ } else { /* add failure */
+ eblk[crcerrs] = alpha_log[divide(i1, i2)];
+ if (eblk[crcerrs] >= nblks) return(1);
+ if (++crcerrs > 3) return(1);
+ if (!calculate_inverse(crcerrs, eblk, &inv)) return(1);
}
+ determine(crcerrs, &inv, ss, es);
+ break;
+
+ case 2: /* 2 errors */
+ case 3: /* 3 errors */
+ determine(crcerrs, &inv, ss, es);
+ break;
+
+ default:
+ return(1);
}
- determine3 (&inv, es, ss);
- i1 = alpha_log[divide(ss[2], ss[1])];
- i2 = alpha_log[divide(ss[1], ss[0])];
- if (i1 != i2 || ((QCV_BLKSIZE * i1) + col) > QCV_SEGSIZE)
- r = 1;
- else
- data[QCV_BLKSIZE * i1 + col] ^= ss[1];
- }
- return(r);
+ /* Make corrections. */
+ for (i = 0; i < crcerrs; i++) {
+ data[(eblk[i] << 10) | col] ^= es[i];
+ ss[0] ^= divide_out(es[i], eblk[i]);
+ ss[1] ^= es[i];
+ ss[2] ^= multiply_out(es[i], eblk[i]);
+ }
+ if (ss[0] || ss[1] || ss[2]) return(1);
+ }
+ return(0);
}
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 45a3628afe0e..06413bb9da30 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -41,7 +41,7 @@ char copyright[] =
#ifndef lint
static char sccsid[] = "@(#)ifconfig.c 5.1 (Berkeley) 2/28/91";
static const char rcsid[] =
- "$Id: ifconfig.c,v 1.6 1994/01/22 08:23:47 rgrimes Exp $";
+ "$Id: ifconfig.c,v 1.7 1994/05/17 15:17:16 jkh Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -78,7 +78,7 @@ struct iso_aliasreq iso_addreq;
struct sockaddr_in netmask;
char name[30];
-int flags;
+u_int flags;
int metric;
int nsellength = 1;
int setaddr;
@@ -620,7 +620,7 @@ in_getaddr(s, which)
printb(s, v, bits)
char *s;
register char *bits;
- register unsigned short v;
+ register unsigned int v;
{
register int i, any = 0;
register char c;
diff --git a/sbin/init.chmr/configure.c b/sbin/init.chmr/configure.c
index 367c4f03102b..1c8ca0f2e452 100644
--- a/sbin/init.chmr/configure.c
+++ b/sbin/init.chmr/configure.c
@@ -35,6 +35,7 @@
#ifdef CONFIGURE
+#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
@@ -58,7 +59,7 @@ static int evaluate_line(char *, int, int, char **, int);
static int parseline(char *, int, int, char **);
-char *fgetline(FILE *, size_t *); /* XXX */
+char *fgetln(FILE *, size_t *); /* XXX */
extern const struct Command Commands[];
@@ -76,10 +77,11 @@ char *filename;
{
static int ncalled = 0;
FILE *cf;
-char *line, *s, *errmsg;
+char *fline, *line, *s, *errmsg;
int lineno;
char **cline;
int argc;
+size_t len;
Debug (1, "Configuring from file %s", filename);
@@ -97,11 +99,25 @@ int argc;
}
Debug(1, "Config file %s opened.", filename);
+ if ((line = (char *) malloc(1)) == (char *) 0) {
+ syslog(LOG_ERR, "%s: %s", filename, strerror(errno));
+ ncalled --;
+ return;
+ }
+
lineno = 0;
- while ((line = fgetline(cf, (size_t *)0))) {
+ while ((fline = fgetln(cf, &len))) {
lineno ++;
- if (*line == '#')
+ if (*fline == '#')
continue; /* Skip comment line */
+ else if (fline[len - 1] == '\n')
+ --len;
+ if ((line = (char *) realloc(line, len + 1)) == (char *) 0) {
+ syslog(LOG_ERR, "%s: %s", filename, strerror(errno));
+ break;
+ }
+ bcopy(fline, line, len);
+ line[len] = '\0';
for (s = line; *s; s++)
if ((*s != ' ') && (*s != '\t'))
break;
@@ -112,8 +128,8 @@ int argc;
syslog(LOG_ERR, "%s line %d: %s", filename, lineno, errmsg);
if (cline && argc > 0)
(void)parseline(filename, lineno, argc, cline);
-
}
+ free(line);
fclose(cf);
ncalled --;
}
diff --git a/sbin/init/init.o b/sbin/init/init.o
new file mode 100644
index 000000000000..15ec01b7f530
--- /dev/null
+++ b/sbin/init/init.o
Binary files differ
diff --git a/sbin/md5/Makefile b/sbin/md5/Makefile
new file mode 100644
index 000000000000..80df7e5f4108
--- /dev/null
+++ b/sbin/md5/Makefile
@@ -0,0 +1,34 @@
+# $Id: Makefile,v 1.3 1994/05/21 21:30:07 jkh Exp $
+
+PROG= md5
+MAN1= md5.1
+SRCS= md5c.c mddriver.c
+CFLAGS+= -DMD=5
+CLEANFILES= test.rfc
+
+# For security reasons, this has to be static.
+LDFLAGS= -static
+
+all: ${PROG} test
+
+test: md5 test.rfc
+ -./md5 -x | diff - test.rfc > diffs 2>&1
+ @-if test -s diffs ; then \
+ echo '*** MD5 TEST FAILED'; cat diffs; \
+ else \
+ echo ' MD5 Test Passed'; \
+ fi
+ rm -f diffs
+
+# test.rfc is taken from Appendix 5 of RFC 1321.
+test.rfc:
+ @echo 'MD5 test suite:' > test.rfc
+ @echo 'MD5 ("") = d41d8cd98f00b204e9800998ecf8427e' >> test.rfc
+ @echo 'MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661' >> test.rfc
+ @echo 'MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72' >> test.rfc
+ @echo 'MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0' >> test.rfc
+ @echo 'MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b' >> test.rfc
+ @echo 'MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") = d174ab98d277d9f5a5611c2c9f419d9f' >> test.rfc
+ @echo 'MD5 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") = 57edf4a22be3c955ac49da2e2107b67a' >> test.rfc
+
+.include <bsd.prog.mk>
diff --git a/sbin/md5/README b/sbin/md5/README
new file mode 100644
index 000000000000..387790748869
--- /dev/null
+++ b/sbin/md5/README
@@ -0,0 +1,34 @@
+Adapted for FreeBSD by Poul-Henning Kamp, phk@login.dkuug.dk. Only the
+Makefile is modified.
+-----------------------------------------------------------------------
+This directory contains source code for the MD5 message-digest algorithm.
+
+MD5.tar.Z is a compressed tar file of all the other files in this directory.
+
+"md5-announcement.txt" is the announcement from RSA Data Security that
+MD5 is being placed in the public domain for free general use.
+
+"rfc1321.txt" is the RFC that describes in detail the MD2, MD4, and MD5
+message-digest algorithms.
+
+The *.[ch] files were taken exactly from RFC 1321.
+I wrote a simple Makefile to build an md5 executable by default,
+with targets for "test" (which implements the test in Appendix A.5 in the RFC)
+and "clean". Running Makefile with no targets will build the "md5" binary.
+
+There is a typo in the RFC Appendix A.4 (mddriver.c).
+Line 20 sets MD to "MD5" by default, but the code wants
+MD to be set to one of "2", "4", or "5".
+I put a -DMD=5 in the Makefile to mask this problem so that the
+code itself remains unchanged from what is in RFC 1321.
+
+Ric Anderson, ric@Artisoft.COM, provided a bug fix to the timing test
+code that caused a divide by zero aborts on a Sun sparc station-10
+running soalris 2.3. This fix to mddriver.c is the only change to the
+code in RFC 1321 and corrects only a problem with the timing tests.
+No change to the code that implements the actual checksum has been made.
+
+Ric has also provided a man page - "md5.1". A postscript version
+of this man page is in "md5.1.ps" and a text version in "md5.1.txt".
+
+ -- Jim Ellis (jte@cert.org)
diff --git a/sbin/md5/global.h b/sbin/md5/global.h
new file mode 100644
index 000000000000..ee255142f5dc
--- /dev/null
+++ b/sbin/md5/global.h
@@ -0,0 +1,30 @@
+/* GLOBAL.H - RSAREF types and constants
+ */
+
+/* PROTOTYPES should be set to one if and only if the compiler supports
+ function argument prototyping.
+The following makes PROTOTYPES default to 0 if it has not already
+ been defined with C compiler flags.
+ */
+#ifndef PROTOTYPES
+#define PROTOTYPES 0
+#endif
+
+/* POINTER defines a generic pointer type */
+typedef unsigned char *POINTER;
+
+/* UINT2 defines a two byte word */
+typedef unsigned short int UINT2;
+
+/* UINT4 defines a four byte word */
+typedef unsigned long int UINT4;
+
+/* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
+If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
+ returns an empty list.
+ */
+#if PROTOTYPES
+#define PROTO_LIST(list) list
+#else
+#define PROTO_LIST(list) ()
+#endif
diff --git a/sbin/md5/md5-announcement.txt b/sbin/md5/md5-announcement.txt
new file mode 100644
index 000000000000..931a1b73f1d0
--- /dev/null
+++ b/sbin/md5/md5-announcement.txt
@@ -0,0 +1,37 @@
+ MD5 -- New Message Digest Algorithm
+ (Feel free to distribute further)
+
+RSA Data Security is announcing MD5, a new message-digest algorithm.
+Like MD4, this algorithm is being placed in the public domain for free
+general use.
+
+The MD5 algorithm is a strengthened version of MD4. It has four
+rounds instead of three, and incorporates other revisions based on a
+year's worth of collected comments on the MD4 algorithm. For example,
+the input access patterns in rounds two and three have been improved,
+and the rotation amounts have been optimized for maximum ``avalanche
+effect.'' The additive constants have been made unique in each step,
+and an additional dependence of each step on the previous one has been
+added.
+
+These changes cause MD5 to be somewhat slower than MD4. We estimate
+that MD5 will typically run about 15-30% slower than MD4, depending on
+the degree to which the versions of MD4 and MD5 have been optimized.
+The more they are both optimized, the greater the percentage
+difference in speed. An optimized version of MD5 on a Sun
+SparcStation runs at about 890 Kbytes/second.
+
+Why MD5? While we do not know of any way to ``break'' MD4, we feel
+that MD4 is being pressed into service far too quickly for such an
+``aggressive'' design. We have been surprised at the speed with which
+MD4 is being designed into products. MD5 is ``MD4 with seatbelts''
+and thus, as a more conservative design, is more suitable for rapid
+deployment.
+
+It is the intent of RSA Data Security to use MD5 in its products and
+standards instead of MD4. We recommend that our customers generally
+do the same, unless there is an overwhelming need for the higher speed
+of MD4. Copies of the MD5 algorithm, including a reference
+implementation in C, are available from the company. (Over the
+Internet, you can access this documentation by anonymous FTP to
+rsa.com and obtaining the file pub/md5.doc.)
diff --git a/sbin/md5/md5.1 b/sbin/md5/md5.1
new file mode 100644
index 000000000000..ccccb01f7e78
--- /dev/null
+++ b/sbin/md5/md5.1
@@ -0,0 +1,43 @@
+.TH MD5 1 "Feb 14, 1994"
+.SH NAME
+md5 \- calculate a message-digest fingerprint (checksum) for a file
+.SH SYNOPSIS
+.B md5
+[ -t | -x | -sstring | filename(s) ]
+.SH DESCRIPTION
+.B md5
+takes as input a message of arbitrary length and produces
+as output a 128-bit "fingerprint" or "message digest" of the input.
+It is conjectured that it is computationally infeasible to produce
+two messages having the same message digest, or to produce any
+message having a given prespecified target message digest.
+The MD5 algorithm is intended for digital signature applications, where a
+large file must be "compressed" in a secure manner before being
+encrypted with a private (secret) key under a public-key cryptosystem
+such as
+.I RSA.
+.SH OPTIONS
+The following four options may be used in any combination, except
+that
+.B "filename(s)"
+must be the last objects on the command line.
+.in +5
+.PP
+.B -sstring
+prints a checksum of the given "string".
+.PP
+.B -t
+runs a built-in time trial.
+.PP
+.B -x
+runs a built-in test script.
+.PP
+.B filename(s)
+prints a checksum(s) for each of the files.
+.SH "SEE ALSO"
+.BR sum (1)
+.PP
+RFC 1321 describes in detail the MD2, MD4, and MD5 message-digest algorithms.
+.SH ACKNOWLEDGEMENTS
+This program is placed in the public domain for free general use by
+RSA Data Security.
diff --git a/sbin/md5/md5.h b/sbin/md5/md5.h
new file mode 100644
index 000000000000..f9d29c7d9649
--- /dev/null
+++ b/sbin/md5/md5.h
@@ -0,0 +1,36 @@
+/* MD5.H - header file for MD5C.C
+ */
+
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
+rights reserved.
+
+License to copy and use this software is granted provided that it
+is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+Algorithm" in all material mentioning or referencing this software
+or this function.
+
+License is also granted to make and use derivative works provided
+that such works are identified as "derived from the RSA Data
+Security, Inc. MD5 Message-Digest Algorithm" in all material
+mentioning or referencing the derived work.
+
+RSA Data Security, Inc. makes no representations concerning either
+the merchantability of this software or the suitability of this
+software for any particular purpose. It is provided "as is"
+without express or implied warranty of any kind.
+
+These notices must be retained in any copies of any part of this
+documentation and/or software.
+ */
+
+/* MD5 context. */
+typedef struct {
+ UINT4 state[4]; /* state (ABCD) */
+ UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
+ unsigned char buffer[64]; /* input buffer */
+} MD5_CTX;
+
+void MD5Init PROTO_LIST ((MD5_CTX *));
+void MD5Update PROTO_LIST
+ ((MD5_CTX *, unsigned char *, unsigned int));
+void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
diff --git a/sbin/md5/md5c.c b/sbin/md5/md5c.c
new file mode 100644
index 000000000000..7023bff6b8b3
--- /dev/null
+++ b/sbin/md5/md5c.c
@@ -0,0 +1,333 @@
+/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
+ */
+
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
+rights reserved.
+
+License to copy and use this software is granted provided that it
+is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+Algorithm" in all material mentioning or referencing this software
+or this function.
+
+License is also granted to make and use derivative works provided
+that such works are identified as "derived from the RSA Data
+Security, Inc. MD5 Message-Digest Algorithm" in all material
+mentioning or referencing the derived work.
+
+RSA Data Security, Inc. makes no representations concerning either
+the merchantability of this software or the suitability of this
+software for any particular purpose. It is provided "as is"
+without express or implied warranty of any kind.
+
+These notices must be retained in any copies of any part of this
+documentation and/or software.
+ */
+
+#include "global.h"
+#include "md5.h"
+
+/* Constants for MD5Transform routine.
+ */
+#define S11 7
+#define S12 12
+#define S13 17
+#define S14 22
+#define S21 5
+#define S22 9
+#define S23 14
+#define S24 20
+#define S31 4
+#define S32 11
+#define S33 16
+#define S34 23
+#define S41 6
+#define S42 10
+#define S43 15
+#define S44 21
+
+static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
+static void Encode PROTO_LIST
+ ((unsigned char *, UINT4 *, unsigned int));
+static void Decode PROTO_LIST
+ ((UINT4 *, unsigned char *, unsigned int));
+static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
+static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
+
+static unsigned char PADDING[64] = {
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+/* F, G, H and I are basic MD5 functions.
+ */
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define I(x, y, z) ((y) ^ ((x) | (~z)))
+
+/* ROTATE_LEFT rotates x left n bits.
+ */
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+
+/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+Rotation is separate from addition to prevent recomputation.
+ */
+#define FF(a, b, c, d, x, s, ac) { \
+ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define GG(a, b, c, d, x, s, ac) { \
+ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define HH(a, b, c, d, x, s, ac) { \
+ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define II(a, b, c, d, x, s, ac) { \
+ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+
+/* MD5 initialization. Begins an MD5 operation, writing a new context.
+ */
+void MD5Init (context)
+MD5_CTX *context; /* context */
+{
+ context->count[0] = context->count[1] = 0;
+ /* Load magic initialization constants.
+*/
+ context->state[0] = 0x67452301;
+ context->state[1] = 0xefcdab89;
+ context->state[2] = 0x98badcfe;
+ context->state[3] = 0x10325476;
+}
+
+/* MD5 block update operation. Continues an MD5 message-digest
+ operation, processing another message block, and updating the
+ context.
+ */
+void MD5Update (context, input, inputLen)
+MD5_CTX *context; /* context */
+unsigned char *input; /* input block */
+unsigned int inputLen; /* length of input block */
+{
+ unsigned int i, index, partLen;
+
+ /* Compute number of bytes mod 64 */
+ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
+
+ /* Update number of bits */
+ if ((context->count[0] += ((UINT4)inputLen << 3))
+ < ((UINT4)inputLen << 3))
+ context->count[1]++;
+ context->count[1] += ((UINT4)inputLen >> 29);
+
+ partLen = 64 - index;
+
+ /* Transform as many times as possible.
+*/
+ if (inputLen >= partLen) {
+ MD5_memcpy
+ ((POINTER)&context->buffer[index], (POINTER)input, partLen);
+ MD5Transform (context->state, context->buffer);
+
+ for (i = partLen; i + 63 < inputLen; i += 64)
+ MD5Transform (context->state, &input[i]);
+
+ index = 0;
+ }
+ else
+ i = 0;
+
+ /* Buffer remaining input */
+ MD5_memcpy
+ ((POINTER)&context->buffer[index], (POINTER)&input[i],
+ inputLen-i);
+}
+
+/* MD5 finalization. Ends an MD5 message-digest operation, writing the
+ the message digest and zeroizing the context.
+ */
+void MD5Final (digest, context)
+unsigned char digest[16]; /* message digest */
+MD5_CTX *context; /* context */
+{
+ unsigned char bits[8];
+ unsigned int index, padLen;
+
+ /* Save number of bits */
+ Encode (bits, context->count, 8);
+
+ /* Pad out to 56 mod 64.
+*/
+ index = (unsigned int)((context->count[0] >> 3) & 0x3f);
+ padLen = (index < 56) ? (56 - index) : (120 - index);
+ MD5Update (context, PADDING, padLen);
+
+ /* Append length (before padding) */
+ MD5Update (context, bits, 8);
+ /* Store state in digest */
+ Encode (digest, context->state, 16);
+
+ /* Zeroize sensitive information.
+*/
+ MD5_memset ((POINTER)context, 0, sizeof (*context));
+}
+
+/* MD5 basic transformation. Transforms state based on block.
+ */
+static void MD5Transform (state, block)
+UINT4 state[4];
+unsigned char block[64];
+{
+ UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+
+ Decode (x, block, 64);
+
+ /* Round 1 */
+ FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
+ FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
+ FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
+ FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
+ FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
+ FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
+ FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
+ FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
+ FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
+ FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
+ FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
+ FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
+ FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
+ FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
+ FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
+ FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
+
+ /* Round 2 */
+ GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
+ GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
+ GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
+ GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
+ GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
+ GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
+ GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
+ GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
+ GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
+ GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
+ GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
+ GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
+ GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
+ GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
+ GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
+ GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
+
+ /* Round 3 */
+ HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
+ HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
+ HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
+ HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
+ HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
+ HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
+ HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
+ HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
+ HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
+ HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
+ HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
+ HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
+ HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
+ HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
+ HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
+ HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
+
+ /* Round 4 */
+ II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
+ II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
+ II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
+ II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
+ II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
+ II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
+ II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
+ II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
+ II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
+ II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
+ II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
+ II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
+ II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
+ II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
+ II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
+ II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
+
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+
+ /* Zeroize sensitive information.
+*/
+ MD5_memset ((POINTER)x, 0, sizeof (x));
+}
+
+/* Encodes input (UINT4) into output (unsigned char). Assumes len is
+ a multiple of 4.
+ */
+static void Encode (output, input, len)
+unsigned char *output;
+UINT4 *input;
+unsigned int len;
+{
+ unsigned int i, j;
+
+ for (i = 0, j = 0; j < len; i++, j += 4) {
+ output[j] = (unsigned char)(input[i] & 0xff);
+ output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
+ output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
+ output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
+ }
+}
+
+/* Decodes input (unsigned char) into output (UINT4). Assumes len is
+ a multiple of 4.
+ */
+static void Decode (output, input, len)
+UINT4 *output;
+unsigned char *input;
+unsigned int len;
+{
+ unsigned int i, j;
+
+ for (i = 0, j = 0; j < len; i++, j += 4)
+ output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
+ (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
+}
+
+/* Note: Replace "for loop" with standard memcpy if possible.
+ */
+
+static void MD5_memcpy (output, input, len)
+POINTER output;
+POINTER input;
+unsigned int len;
+{
+ unsigned int i;
+
+ for (i = 0; i < len; i++)
+ output[i] = input[i];
+}
+
+/* Note: Replace "for loop" with standard memset if possible.
+ */
+static void MD5_memset (output, value, len)
+POINTER output;
+int value;
+unsigned int len;
+{
+ unsigned int i;
+
+ for (i = 0; i < len; i++)
+ ((char *)output)[i] = (char)value;
+}
diff --git a/sbin/md5/mddriver.c b/sbin/md5/mddriver.c
new file mode 100644
index 000000000000..c2a246eb2490
--- /dev/null
+++ b/sbin/md5/mddriver.c
@@ -0,0 +1,231 @@
+/* MDDRIVER.C - test driver for MD2, MD4 and MD5
+ */
+
+/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
+rights reserved.
+
+RSA Data Security, Inc. makes no representations concerning either
+the merchantability of this software or the suitability of this
+software for any particular purpose. It is provided "as is"
+without express or implied warranty of any kind.
+
+These notices must be retained in any copies of any part of this
+documentation and/or software.
+ */
+
+/* The following makes MD default to MD5 if it has not already been
+ defined with C compiler flags.
+ */
+#ifndef MD
+#define MD MD5
+#endif
+
+#include <stdio.h>
+#include <time.h>
+#include <string.h>
+#include "global.h"
+#if MD == 2
+#include "md2.h"
+#endif
+#if MD == 4
+#include "md4.h"
+#endif
+#if MD == 5
+#include "md5.h"
+#endif
+
+/* Length of test block, number of test blocks.
+ */
+#define TEST_BLOCK_LEN 1000
+#define TEST_BLOCK_COUNT 1000
+
+static void MDString PROTO_LIST ((char *));
+static void MDTimeTrial PROTO_LIST ((void));
+static void MDTestSuite PROTO_LIST ((void));
+static void MDFile PROTO_LIST ((char *));
+static void MDFilter PROTO_LIST ((void));
+static void MDPrint PROTO_LIST ((unsigned char [16]));
+
+#if MD == 2
+#define MD_CTX MD2_CTX
+#define MDInit MD2Init
+#define MDUpdate MD2Update
+#define MDFinal MD2Final
+#endif
+#if MD == 4
+#define MD_CTX MD4_CTX
+#define MDInit MD4Init
+#define MDUpdate MD4Update
+#define MDFinal MD4Final
+#endif
+#if MD == 5
+#define MD_CTX MD5_CTX
+#define MDInit MD5Init
+#define MDUpdate MD5Update
+#define MDFinal MD5Final
+#endif
+
+/* Main driver.
+
+Arguments (may be any combination):
+ -sstring - digests string
+ -t - runs time trial
+ -x - runs test script
+ filename - digests file
+ (none) - digests standard input
+ */
+int main (argc, argv)
+int argc;
+char *argv[];
+{
+ int i;
+
+ if (argc > 1)
+ for (i = 1; i < argc; i++)
+ if (argv[i][0] == '-' && argv[i][1] == 's')
+ MDString (argv[i] + 2);
+ else if (strcmp (argv[i], "-t") == 0)
+ MDTimeTrial ();
+ else if (strcmp (argv[i], "-x") == 0)
+ MDTestSuite ();
+ else
+ MDFile (argv[i]);
+ else
+ MDFilter ();
+
+ return (0);
+}
+
+/* Digests a string and prints the result.
+ */
+static void MDString (string)
+char *string;
+{
+ MD_CTX context;
+ unsigned char digest[16];
+ unsigned int len = strlen (string);
+
+ MDInit (&context);
+ MDUpdate (&context, string, len);
+ MDFinal (digest, &context);
+
+ printf ("MD%d (\"%s\") = ", MD, string);
+ MDPrint (digest);
+ printf ("\n");
+}
+
+/* Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte
+ blocks.
+ */
+static void MDTimeTrial ()
+{
+ MD_CTX context;
+ time_t endTime, startTime;
+ unsigned char block[TEST_BLOCK_LEN], digest[16];
+ unsigned int i;
+
+ printf
+ ("MD%d time trial. Digesting %d %d-byte blocks ...", MD,
+ TEST_BLOCK_LEN, TEST_BLOCK_COUNT);
+
+ /* Initialize block */
+ for (i = 0; i < TEST_BLOCK_LEN; i++)
+ block[i] = (unsigned char)(i & 0xff);
+
+ /* Start timer */
+ time (&startTime);
+
+ /* Digest blocks */
+ MDInit (&context);
+ for (i = 0; i < TEST_BLOCK_COUNT; i++)
+ MDUpdate (&context, block, TEST_BLOCK_LEN);
+ MDFinal (digest, &context);
+
+ /* Stop timer */
+ time (&endTime);
+
+ printf (" done\n");
+ printf ("Digest = ");
+ MDPrint (digest);
+ printf ("\nTime = %ld seconds\n", (long)(endTime-startTime));
+ /*
+ * Be careful that endTime-startTime is not zero.
+ * (Bug fix from Ric Anderson, ric@Artisoft.COM.)
+ */
+ printf
+ ("Speed = %ld bytes/second\n",
+ (long)TEST_BLOCK_LEN * (long)TEST_BLOCK_COUNT/((endTime-startTime) != 0 ? (endTime-startTime):1));
+}
+
+/* Digests a reference suite of strings and prints the results.
+ */
+static void MDTestSuite ()
+{
+ printf ("MD%d test suite:\n", MD);
+
+ MDString ("");
+ MDString ("a");
+ MDString ("abc");
+ MDString ("message digest");
+ MDString ("abcdefghijklmnopqrstuvwxyz");
+ MDString
+ ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
+ MDString
+ ("1234567890123456789012345678901234567890\
+1234567890123456789012345678901234567890");
+}
+
+/* Digests a file and prints the result.
+ */
+static void MDFile (filename)
+char *filename;
+{
+ FILE *file;
+ MD_CTX context;
+ int len;
+ unsigned char buffer[1024], digest[16];
+
+ if ((file = fopen (filename, "rb")) == NULL)
+ printf ("%s can't be opened\n", filename);
+
+ else {
+ MDInit (&context);
+ while (len = fread (buffer, 1, 1024, file))
+ MDUpdate (&context, buffer, len);
+ MDFinal (digest, &context);
+
+ fclose (file);
+
+ printf ("MD%d (%s) = ", MD, filename);
+ MDPrint (digest);
+ printf ("\n");
+ }
+}
+
+/* Digests the standard input and prints the result.
+ */
+static void MDFilter ()
+{
+ MD_CTX context;
+ int len;
+ unsigned char buffer[16], digest[16];
+
+ MDInit (&context);
+ while (len = fread (buffer, 1, 16, stdin))
+ MDUpdate (&context, buffer, len);
+ MDFinal (digest, &context);
+
+ MDPrint (digest);
+ printf ("\n");
+}
+
+/* Prints a message digest in hexadecimal.
+ */
+static void MDPrint (digest)
+unsigned char digest[16];
+{
+ unsigned int i;
+
+ for (i = 0; i < 16; i++)
+ printf ("%02x", digest[i]);
+}
diff --git a/sbin/mount/mount.8 b/sbin/mount/mount.8
index ae55108c7c72..bf37d462257e 100644
--- a/sbin/mount/mount.8
+++ b/sbin/mount/mount.8
@@ -234,6 +234,10 @@ Use
.Tn TCP
transport instead of
.Tn UDP .
+.It port=#
+Set server IP port number to
+.Ar # .
+If not specified, the portmapper is queried for the NFS service.
.It rsize=#
Set read size to
.Ar #
diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c
index 0d468233e78c..4c3bfa40a9c7 100644
--- a/sbin/mount/mount.c
+++ b/sbin/mount/mount.c
@@ -103,6 +103,7 @@ int retrycnt;
#define BGRND 1
#define ISBGRND 2
int opflags = 0;
+u_short serverport = 0;
#endif
main(argc, argv, arge)
@@ -301,9 +302,11 @@ mountfs(spec, name, flags, type, options, mntopts)
case MOUNT_NFS:
retrycnt = DEF_RETRY;
if (mntopts)
- getnfsopts(mntopts, &nfsargs, &opflags, &retrycnt);
+ getnfsopts(mntopts, &nfsargs, &opflags, &retrycnt,
+ &serverport);
if (options)
- getnfsopts(options, &nfsargs, &opflags, &retrycnt);
+ getnfsopts(options, &nfsargs, &opflags, &retrycnt,
+ &serverport);
if (argp = getnfsargs(spec, &nfsargs))
break;
return (1);
@@ -643,11 +646,12 @@ exclusive(a, b)
* Handle the getoption arg.
* Essentially update "opflags", "retrycnt" and "nfsargs"
*/
-getnfsopts(optarg, nfsargsp, opflagsp, retrycntp)
+getnfsopts(optarg, nfsargsp, opflagsp, retrycntp, serverport)
char *optarg;
register struct nfs_args *nfsargsp;
int *opflagsp;
int *retrycntp;
+ u_short *serverport;
{
register char *cp, *nextcp;
int num;
@@ -696,6 +700,8 @@ getnfsopts(optarg, nfsargsp, opflagsp, retrycntp)
} else if (!strcmp(cp, "retrans") && num > 0) {
nfsargsp->retrans = num;
nfsargsp->flags |= NFSMNT_RETRANS;
+ } else if (!strcmp(cp, "port") && num > 0) {
+ *serverport = num;
}
}
if (nfsargsp->sotype == SOCK_DGRAM) {
@@ -748,8 +754,10 @@ getnfsargs(spec, nfsargsp)
while (retrycnt > 0) {
saddr.sin_family = AF_INET;
saddr.sin_port = htons(PMAPPORT);
- if ((tport = pmap_getport(&saddr, RPCPROG_NFS,
- NFS_VER2, IPPROTO_UDP)) == 0) {
+ tport = serverport;
+ if (serverport == 0 &&
+ ((tport = pmap_getport(&saddr, RPCPROG_NFS,
+ NFS_VER2, IPPROTO_UDP)) == 0)) {
if ((opflags & ISBGRND) == 0)
clnt_pcreateerror("NFS Portmap");
} else {
diff --git a/sbin/mountd/mountd.c b/sbin/mountd/mountd.c
index e2e5a26a2100..67490e81a905 100644
--- a/sbin/mountd/mountd.c
+++ b/sbin/mountd/mountd.c
@@ -820,7 +820,7 @@ send_umntall()
{
(void) clnt_broadcast(RPCPROG_MNT, RPCMNT_VER1, RPCMNT_UMNTALL,
xdr_void, (caddr_t)0, xdr_void, (caddr_t)0, umntall_each);
- exit();
+ exit(0);
}
umntall_each(resultsp, raddr)
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
index 3609ae2fe621..13f3344cbcbb 100644
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -105,6 +105,12 @@ int options;
#define F_SO_DONTROUTE 0x080
#define F_VERBOSE 0x100
+/* multicast options */
+int moptions;
+#define MULTICAST_NOLOOP 0x001
+#define MULTICAST_TTL 0x002
+#define MULTICAST_IF 0x004
+
/*
* MAX_DUP_CHK is the number of bits in received table, i.e. the maximum
* number of received sequence numbers we can keep track of. Change 128
@@ -149,17 +155,19 @@ main(argc, argv)
struct hostent *hp;
struct sockaddr_in *to;
struct protoent *proto;
- register int i;
+ struct in_addr ifaddr;
+ int i;
int ch, fdmask, hold, packlen, preload;
u_char *datap, *packet;
char *target, hnamebuf[MAXHOSTNAMELEN], *malloc();
+ u_char ttl, loop;
#ifdef IP_OPTIONS
char rspace[3 + 4 * NROUTES + 1]; /* record route space */
#endif
preload = 0;
datap = &outpack[8 + sizeof(struct timeval)];
- while ((ch = getopt(argc, argv, "Rc:dfh:i:l:np:qrs:v")) != EOF)
+ while ((ch = getopt(argc, argv, "I:LRc:dfh:i:l:np:qrs:t:v")) != EOF)
switch(ch) {
case 'c':
npackets = atoi(optarg);
@@ -230,12 +238,40 @@ main(argc, argv)
case 'v':
options |= F_VERBOSE;
break;
+ case 'L':
+ moptions |= MULTICAST_NOLOOP;
+ loop = 0;
+ break;
+ case 't':
+ moptions |= MULTICAST_TTL;
+ i = atoi(optarg);
+ if (i < 0 || i > 255) {
+ printf("ttl %u out of range\n", i);
+ exit(1);
+ }
+ ttl = i;
+ break;
+ case 'I':
+ moptions |= MULTICAST_IF;
+ {
+ int i1, i2, i3, i4;
+
+ if (sscanf(optarg, "%u.%u.%u.%u%c",
+ &i1, &i2, &i3, &i4, &i) != 4) {
+ printf("bad interface address '%s'\n",
+ optarg);
+ exit(1);
+ }
+ ifaddr.s_addr = (i1<<24)|(i2<<16)|(i3<<8)|i4;
+ ifaddr.s_addr = htonl(ifaddr.s_addr);
+ }
+ break;
default:
usage();
}
argc -= optind;
argv += optind;
-
+
if (argc != 1)
usage();
target = *argv;
@@ -322,6 +358,28 @@ main(argc, argv)
(void)setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&hold,
sizeof(hold));
+ if (moptions & MULTICAST_NOLOOP) {
+ if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP,
+ &loop, 1) == -1) {
+ perror ("can't disable multicast loopback");
+ exit(92);
+ }
+ }
+ if (moptions & MULTICAST_TTL) {
+ if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL,
+ &ttl, 1) == -1) {
+ perror ("can't set multicast time-to-live");
+ exit(93);
+ }
+ }
+ if (moptions & MULTICAST_IF) {
+ if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF,
+ &ifaddr, sizeof(ifaddr)) == -1) {
+ perror ("can't set multicast source interface");
+ exit(94);
+ }
+ }
+
if (to->sin_family == AF_INET)
(void)printf("PING %s (%s): %d data bytes\n", hostname,
inet_ntoa(*(struct in_addr *)&to->sin_addr.s_addr),
@@ -990,6 +1048,6 @@ fill(bp, patp)
usage()
{
(void)fprintf(stderr,
- "usage: ping [-Rdfnqrv] [-c count] [-i wait] [-l preload]\n\t[-p pattern] [-s packetsize] host\n");
+ "usage: ping [-LRdfnqrv] [-c count] [-i wait] [-l preload]\n\t[-p pattern] [-s packetsize] [-t ttl] [-I interface address] host\n");
exit(1);
}
diff --git a/sbin/restore/Makefile b/sbin/restore/Makefile
index 782f8d179422..a4a0926c9402 100644
--- a/sbin/restore/Makefile
+++ b/sbin/restore/Makefile
@@ -11,7 +11,7 @@ CLEANFILES+=dumprmt.o rtape.o rrestore
all: rrestore
rrestore: ${ROBJS} ${LIBC}
- ${CC} ${CFLAGS} -o ${.TARGET} ${ROBJS}
+ ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${ROBJS}
rtape.o: tape.c ${LIBC}
${CC} ${CFLAGS} -c -DRRESTORE ${.CURDIR}/tape.c -o ${.TARGET}
diff --git a/sbin/restore/dirs.c b/sbin/restore/dirs.c
index d5da24a456ab..b35372132886 100644
--- a/sbin/restore/dirs.c
+++ b/sbin/restore/dirs.c
@@ -5,7 +5,7 @@
* or UNIX System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
- * $Id: dirs.c,v 1.1.1.1.2.1 1994/05/04 07:42:51 rgrimes Exp $
+ * $Id: dirs.c,v 1.2 1994/05/04 08:20:30 rgrimes Exp $
*/
/*
* Copyright (c) 1983 The Regents of the University of California.
diff --git a/sbin/restore/pathnames.h b/sbin/restore/pathnames.h
index 6c3ef24e8829..9fd333ec7db9 100644
--- a/sbin/restore/pathnames.h
+++ b/sbin/restore/pathnames.h
@@ -5,7 +5,7 @@
* or UNIX System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
- * $Id: pathnames.h,v 1.1.1.1.2.1 1994/05/04 07:42:53 rgrimes Exp $
+ * $Id: pathnames.h,v 1.2 1994/05/04 08:20:38 rgrimes Exp $
*/
/*
* Copyright (c) 1989 The Regents of the University of California.
diff --git a/sbin/restore/restore.h b/sbin/restore/restore.h
index 85c951caa348..8d4bf8bf398f 100644
--- a/sbin/restore/restore.h
+++ b/sbin/restore/restore.h
@@ -5,7 +5,7 @@
* or UNIX System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
- * $Id: restore.h,v 1.1.1.1.2.1 1994/05/04 07:42:55 rgrimes Exp $
+ * $Id: restore.h,v 1.2 1994/05/04 08:20:44 rgrimes Exp $
*/
/*
* Copyright (c) 1983 The Regents of the University of California.
diff --git a/sbin/restore/rrestore.8 b/sbin/restore/rrestore.8
index e597806e8af8..e0d5a32778cf 100644
--- a/sbin/restore/rrestore.8
+++ b/sbin/restore/rrestore.8
@@ -55,7 +55,7 @@ except the
.Cm f
key should be specified and the file
supplied should be of the form
-.Ar machine:device .
+.Ar [user@]machine:device .
.Pp
.Nm Rrestore
creates a remote server,
diff --git a/sbin/restore/tape.c b/sbin/restore/tape.c
index 02bda1d6d478..40ba9da5be41 100644
--- a/sbin/restore/tape.c
+++ b/sbin/restore/tape.c
@@ -5,7 +5,7 @@
* or UNIX System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
- * $Id: tape.c,v 1.2.2.1 1994/05/04 07:42:57 rgrimes Exp $
+ * $Id: tape.c,v 1.3 1994/05/04 08:20:52 rgrimes Exp $
*/
/*
* Copyright (c) 1983 The Regents of the University of California.
diff --git a/sbin/route/route.c b/sbin/route/route.c
index 4d0c02746ed6..1930ea6ffb31 100644
--- a/sbin/route/route.c
+++ b/sbin/route/route.c
@@ -40,7 +40,7 @@ char copyright[] =
#ifndef lint
/* From: static char sccsid[] = "@(#)route.c 5.35 (Berkeley) 6/27/91"; */
const char main_c_rcsid[] =
- "$Id: route.c,v 1.3 1993/11/17 21:27:20 wollman Exp $";
+ "$Id: route.c,v 1.4 1994/06/23 17:10:40 ats Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -166,7 +166,7 @@ main(argc, argv)
break;
case '?':
default:
- usage();
+ usage((char *)NULL);
}
argc -= optind;
argv += optind;
diff --git a/sbin/routed/Makefile b/sbin/routed/Makefile
deleted file mode 100644
index 0fc8bc839cbf..000000000000
--- a/sbin/routed/Makefile
+++ /dev/null
@@ -1,22 +0,0 @@
-# @(#)Makefile 5.16 (Berkeley) 4/26/91
-
-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.8
-SUBDIR= query trace
-DPADD= ${LIBUTIL} ${LIBCOMPAT}
-LDADD= -lutil
-
-.include <bsd.prog.mk>
-
-.if (${MACHINE} == "vax")
-# The following can be deleted where not appropriate to use the kernel's
-# inline code expansions.
-INLINE= /sys/vax/inline/obj/inline
-C2= /usr/libexec/c2
-.c.o:
- ${CC} -S ${CFLAGS} ${.CURDIR}/${.PREFIX}.c
- @${C2} ${.PREFIX}.s | ${INLINE} | ${AS} -o ${.PREFIX}.o
- @rm -f ${.PREFIX}.s
-.endif
diff --git a/sbin/routed/af.c b/sbin/routed/af.c
deleted file mode 100644
index 19807b71db41..000000000000
--- a/sbin/routed/af.c
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (c) 1983 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)af.c 5.11 (Berkeley) 2/28/91";
-#endif /* not lint */
-
-#include "defs.h"
-
-/*
- * Address family support routines
- */
-int inet_hash(), inet_netmatch(), inet_output(),
- inet_portmatch(), inet_portcheck(),
- inet_checkhost(), inet_rtflags(), inet_sendroute(), inet_canon();
-char *inet_format();
-
-#define NIL { 0 }
-#define INET \
- { inet_hash, inet_netmatch, inet_output, \
- inet_portmatch, inet_portcheck, inet_checkhost, \
- inet_rtflags, inet_sendroute, inet_canon, \
- inet_format \
- }
-
-struct afswitch afswitch[AF_MAX] = {
- NIL, /* 0- unused */
- NIL, /* 1- Unix domain, unused */
- INET, /* Internet */
-};
-
-int af_max = sizeof(afswitch) / sizeof(afswitch[0]);
-
-struct sockaddr_in inet_default = {
-#ifdef RTM_ADD
- sizeof (inet_default),
-#endif
- AF_INET, INADDR_ANY };
-
-inet_hash(sin, hp)
- register struct sockaddr_in *sin;
- struct afhash *hp;
-{
- register u_long n;
-
- n = inet_netof(sin->sin_addr);
- if (n)
- while ((n & 0xff) == 0)
- n >>= 8;
- hp->afh_nethash = n;
- hp->afh_hosthash = ntohl(sin->sin_addr.s_addr);
- hp->afh_hosthash &= 0x7fffffff;
-}
-
-inet_netmatch(sin1, sin2)
- struct sockaddr_in *sin1, *sin2;
-{
-
- return (inet_netof(sin1->sin_addr) == inet_netof(sin2->sin_addr));
-}
-
-/*
- * Verify the message is from the right port.
- */
-inet_portmatch(sin)
- register struct sockaddr_in *sin;
-{
-
- return (sin->sin_port == sp->s_port);
-}
-
-/*
- * Verify the message is from a "trusted" port.
- */
-inet_portcheck(sin)
- struct sockaddr_in *sin;
-{
-
- return (ntohs(sin->sin_port) <= IPPORT_RESERVED);
-}
-
-/*
- * Internet output routine.
- */
-inet_output(s, flags, sin, size)
- int s, flags;
- struct sockaddr_in *sin;
- int size;
-{
- struct sockaddr_in dst;
-
- dst = *sin;
- sin = &dst;
- if (sin->sin_port == 0)
- sin->sin_port = sp->s_port;
- if (sin->sin_len == 0)
- sin->sin_len = sizeof (*sin);
- if (sendto(s, packet, size, flags,
- (struct sockaddr *)sin, sizeof (*sin)) < 0)
- perror("sendto");
-}
-
-/*
- * Return 1 if the address is believed
- * for an Internet host -- THIS IS A KLUDGE.
- */
-inet_checkhost(sin)
- struct sockaddr_in *sin;
-{
- u_long i = ntohl(sin->sin_addr.s_addr);
-
-#ifndef IN_EXPERIMENTAL
-#define IN_EXPERIMENTAL(i) (((long) (i) & 0xe0000000) == 0xe0000000)
-#endif
-
- if (IN_EXPERIMENTAL(i) || sin->sin_port != 0)
- return (0);
- if (i != 0 && (i & 0xff000000) == 0)
- return (0);
- for (i = 0; i < sizeof(sin->sin_zero)/sizeof(sin->sin_zero[0]); i++)
- if (sin->sin_zero[i])
- return (0);
- return (1);
-}
-
-inet_canon(sin)
- struct sockaddr_in *sin;
-{
-
- sin->sin_port = 0;
- sin->sin_len = sizeof(*sin);
-}
-
-char *
-inet_format(sin)
- struct sockaddr_in *sin;
-{
- char *inet_ntoa();
-
- return (inet_ntoa(sin->sin_addr));
-}
diff --git a/sbin/routed/af.h b/sbin/routed/af.h
deleted file mode 100644
index 2d1bf293d365..000000000000
--- a/sbin/routed/af.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 1983 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
- * must display the following acknowledgement:
- * 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.
- *
- * @(#)af.h 5.7 (Berkeley) 6/1/90
- */
-
-/*
- * Routing table management daemon.
- */
-
-/*
- * Per address family routines.
- */
-struct afswitch {
- int (*af_hash)(); /* returns keys based on address */
- int (*af_netmatch)(); /* verifies net # matching */
- int (*af_output)(); /* interprets address for sending */
- int (*af_portmatch)(); /* packet from some other router? */
- int (*af_portcheck)(); /* packet from privileged peer? */
- int (*af_checkhost)(); /* tells if address is valid */
- int (*af_rtflags)(); /* get flags for route (host or net) */
- int (*af_sendroute)(); /* check bounds of subnet broadcast */
- int (*af_canon)(); /* canonicalize address for compares */
- char *(*af_format)(); /* convert address to string */
-};
-
-/*
- * Structure returned by af_hash routines.
- */
-struct afhash {
- u_int afh_hosthash; /* host based hash */
- u_int afh_nethash; /* network based hash */
-};
-
-struct afswitch afswitch[]; /* table proper */
-int af_max; /* number of entries in table */
diff --git a/sbin/routed/defs.h b/sbin/routed/defs.h
deleted file mode 100644
index f4fdf7a68f29..000000000000
--- a/sbin/routed/defs.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (c) 1983, 1988 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
- * must display the following acknowledgement:
- * 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.
- *
- * @(#)defs.h 5.10 (Berkeley) 2/28/91
- */
-
-/*
- * Internal data structure definitions for
- * user routing process. Based on Xerox NS
- * protocol specs with mods relevant to more
- * general addressing scheme.
- */
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-
-#include <net/route.h>
-#include <netinet/in.h>
-#include <protocols/routed.h>
-
-#include <stdio.h>
-#include <netdb.h>
-
-#include "trace.h"
-#include "interface.h"
-#include "table.h"
-#include "af.h"
-
-/*
- * When we find any interfaces marked down we rescan the
- * kernel every CHECK_INTERVAL seconds to see if they've
- * come up.
- */
-#define CHECK_INTERVAL (1*60)
-
-#define equal(a1, a2) \
- (bcmp((caddr_t)(a1), (caddr_t)(a2), sizeof (struct sockaddr)) == 0)
-
-struct sockaddr_in addr; /* address of daemon's socket */
-
-int s; /* source and sink of all data */
-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 /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 */
-struct timeval lastfullupdate; /* last time full table broadcast */
-struct timeval nextbcast; /* time to wait before changes broadcast */
-int needupdate; /* true if we need update at nextbcast */
-
-char packet[MAXPACKETSIZE+1];
-struct rip *msg;
-
-char **argv0;
-struct servent *sp;
-
-struct in_addr inet_makeaddr();
-int inet_addr();
-int sndmsg();
-int supply();
-int cleanup();
diff --git a/sbin/routed/if.c b/sbin/routed/if.c
deleted file mode 100644
index 4871c9df32aa..000000000000
--- a/sbin/routed/if.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (c) 1983 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)if.c 5.6 (Berkeley) 6/1/90";
-#endif /* not lint */
-
-/*
- * Routing Table Management Daemon
- */
-#include "defs.h"
-
-extern struct interface *ifnet;
-
-/*
- * Find the interface with address addr.
- */
-struct interface *
-if_ifwithaddr(addr)
- struct sockaddr *addr;
-{
- register struct interface *ifp;
-
-#define same(a1, a2) \
- (bcmp((caddr_t)((a1)->sa_data), (caddr_t)((a2)->sa_data), 14) == 0)
- for (ifp = ifnet; ifp; ifp = ifp->int_next) {
- if (ifp->int_flags & IFF_REMOTE)
- continue;
- if (ifp->int_addr.sa_family != addr->sa_family)
- continue;
- if (same(&ifp->int_addr, addr))
- break;
- if ((ifp->int_flags & IFF_BROADCAST) &&
- same(&ifp->int_broadaddr, addr))
- break;
- }
- return (ifp);
-}
-
-/*
- * Find the point-to-point interface with destination address addr.
- */
-struct interface *
-if_ifwithdstaddr(addr)
- struct sockaddr *addr;
-{
- register struct interface *ifp;
-
- for (ifp = ifnet; ifp; ifp = ifp->int_next) {
- if ((ifp->int_flags & IFF_POINTOPOINT) == 0)
- continue;
- if (same(&ifp->int_dstaddr, addr))
- break;
- }
- return (ifp);
-}
-
-/*
- * Find the interface on the network
- * of the specified address.
- */
-struct interface *
-if_ifwithnet(addr)
- register struct sockaddr *addr;
-{
- register struct interface *ifp;
- register int af = addr->sa_family;
- register int (*netmatch)();
-
- if (af >= af_max)
- return (0);
- netmatch = afswitch[af].af_netmatch;
- for (ifp = ifnet; ifp; ifp = ifp->int_next) {
- if (ifp->int_flags & IFF_REMOTE)
- continue;
- if (af != ifp->int_addr.sa_family)
- continue;
- if ((*netmatch)(addr, &ifp->int_addr))
- break;
- }
- return (ifp);
-}
-
-/*
- * Find an interface from which the specified address
- * should have come from. Used for figuring out which
- * interface a packet came in on -- for tracing.
- */
-struct interface *
-if_iflookup(addr)
- struct sockaddr *addr;
-{
- register struct interface *ifp, *maybe;
- register int af = addr->sa_family;
- register int (*netmatch)();
-
- if (af >= af_max)
- return (0);
- maybe = 0;
- netmatch = afswitch[af].af_netmatch;
- for (ifp = ifnet; ifp; ifp = ifp->int_next) {
- if (ifp->int_addr.sa_family != af)
- continue;
- if (same(&ifp->int_addr, addr))
- break;
- if ((ifp->int_flags & IFF_BROADCAST) &&
- same(&ifp->int_broadaddr, addr))
- break;
- if ((ifp->int_flags & IFF_POINTOPOINT) &&
- same(&ifp->int_dstaddr, addr))
- break;
- if (maybe == 0 && (*netmatch)(addr, &ifp->int_addr))
- maybe = ifp;
- }
- if (ifp == 0)
- ifp = maybe;
- return (ifp);
-}
diff --git a/sbin/routed/inet.c b/sbin/routed/inet.c
deleted file mode 100644
index a465ac7637c9..000000000000
--- a/sbin/routed/inet.c
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * Copyright (c) 1983 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)inet.c 5.8 (Berkeley) 6/1/90";
-#endif /* not lint */
-
-/*
- * Temporarily, copy these routines from the kernel,
- * as we need to know about subnets.
- */
-#include "defs.h"
-
-extern struct interface *ifnet;
-
-/*
- * Formulate an Internet address from network + host.
- */
-struct in_addr
-inet_makeaddr(net, host)
- u_long net, host;
-{
- register struct interface *ifp;
- register u_long mask;
- u_long addr;
-
- if (IN_CLASSA(net))
- mask = IN_CLASSA_HOST;
- else if (IN_CLASSB(net))
- mask = IN_CLASSB_HOST;
- else
- mask = IN_CLASSC_HOST;
- for (ifp = ifnet; ifp; ifp = ifp->int_next)
- if ((ifp->int_netmask & net) == ifp->int_net) {
- mask = ~ifp->int_subnetmask;
- break;
- }
- addr = net | (host & mask);
- addr = htonl(addr);
- return (*(struct in_addr *)&addr);
-}
-
-/*
- * Return the network number from an internet address.
- */
-inet_netof(in)
- struct in_addr in;
-{
- register u_long i = ntohl(in.s_addr);
- register u_long net;
- register struct interface *ifp;
-
- if (IN_CLASSA(i))
- net = i & IN_CLASSA_NET;
- else if (IN_CLASSB(i))
- net = i & IN_CLASSB_NET;
- else
- net = i & IN_CLASSC_NET;
-
- /*
- * Check whether network is a subnet;
- * if so, return subnet number.
- */
- for (ifp = ifnet; ifp; ifp = ifp->int_next)
- if ((ifp->int_netmask & net) == ifp->int_net)
- return (i & ifp->int_subnetmask);
- return (net);
-}
-
-/*
- * Return the host portion of an internet address.
- */
-inet_lnaof(in)
- struct in_addr in;
-{
- register u_long i = ntohl(in.s_addr);
- register u_long net, host;
- register struct interface *ifp;
-
- if (IN_CLASSA(i)) {
- net = i & IN_CLASSA_NET;
- host = i & IN_CLASSA_HOST;
- } else if (IN_CLASSB(i)) {
- net = i & IN_CLASSB_NET;
- host = i & IN_CLASSB_HOST;
- } else {
- net = i & IN_CLASSC_NET;
- host = i & IN_CLASSC_HOST;
- }
-
- /*
- * 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 & net) == ifp->int_net)
- return (host &~ ifp->int_subnetmask);
- return (host);
-}
-
-/*
- * Return RTF_HOST if the address is
- * for an Internet host, RTF_SUBNET for a subnet,
- * 0 for a network.
- */
-inet_rtflags(sin)
- struct sockaddr_in *sin;
-{
- register u_long i = ntohl(sin->sin_addr.s_addr);
- register u_long net, host;
- register struct interface *ifp;
-
- if (IN_CLASSA(i)) {
- net = i & IN_CLASSA_NET;
- host = i & IN_CLASSA_HOST;
- } else if (IN_CLASSB(i)) {
- net = i & IN_CLASSB_NET;
- host = i & IN_CLASSB_HOST;
- } else {
- net = i & IN_CLASSC_NET;
- host = i & IN_CLASSC_HOST;
- }
-
- /*
- * Check whether this network is subnetted;
- * if so, check whether this is a subnet or a host.
- */
- for (ifp = ifnet; ifp; ifp = ifp->int_next)
- if (net == ifp->int_net) {
- if (host &~ ifp->int_subnetmask)
- return (RTF_HOST);
- else if (ifp->int_subnetmask != ifp->int_netmask)
- return (RTF_SUBNET);
- else
- return (0); /* network */
- }
- if (host == 0)
- return (0); /* network */
- else
- return (RTF_HOST);
-}
-
-/*
- * Return true if a route to subnet/host of route rt should be sent to dst.
- * Send it only if dst is on the same logical network if not "internal",
- * otherwise only if the route is the "internal" route for the logical net.
- */
-inet_sendroute(rt, dst)
- struct rt_entry *rt;
- struct sockaddr_in *dst;
-{
- register u_long r =
- ntohl(((struct sockaddr_in *)&rt->rt_dst)->sin_addr.s_addr);
- register u_long d = ntohl(dst->sin_addr.s_addr);
-
- if (IN_CLASSA(r)) {
- if ((r & IN_CLASSA_NET) == (d & IN_CLASSA_NET)) {
- if ((r & IN_CLASSA_HOST) == 0)
- return ((rt->rt_state & RTS_INTERNAL) == 0);
- return (1);
- }
- if (r & IN_CLASSA_HOST)
- return (0);
- return ((rt->rt_state & RTS_INTERNAL) != 0);
- } else if (IN_CLASSB(r)) {
- if ((r & IN_CLASSB_NET) == (d & IN_CLASSB_NET)) {
- if ((r & IN_CLASSB_HOST) == 0)
- return ((rt->rt_state & RTS_INTERNAL) == 0);
- return (1);
- }
- if (r & IN_CLASSB_HOST)
- return (0);
- return ((rt->rt_state & RTS_INTERNAL) != 0);
- } else {
- if ((r & IN_CLASSC_NET) == (d & IN_CLASSC_NET)) {
- if ((r & IN_CLASSC_HOST) == 0)
- return ((rt->rt_state & RTS_INTERNAL) == 0);
- return (1);
- }
- if (r & IN_CLASSC_HOST)
- return (0);
- return ((rt->rt_state & RTS_INTERNAL) != 0);
- }
-}
diff --git a/sbin/routed/input.c b/sbin/routed/input.c
deleted file mode 100644
index ec8c9d76239b..000000000000
--- a/sbin/routed/input.c
+++ /dev/null
@@ -1,362 +0,0 @@
-/*
- * Copyright (c) 1983, 1988 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)input.c 5.22 (Berkeley) 6/1/90";
-#endif /* not lint */
-
-/*
- * Routing Table Management Daemon
- */
-#include "defs.h"
-#include <sys/syslog.h>
-
-/*
- * Process a newly received packet.
- */
-rip_input(from, rip, size)
- struct sockaddr *from;
- register struct rip *rip;
- int size;
-{
- register struct rt_entry *rt;
- register struct netinfo *n;
- register struct interface *ifp;
- struct interface *if_ifwithdstaddr();
- int count, changes = 0;
- register struct afswitch *afp;
- static struct sockaddr badfrom, badfrom2;
-
- ifp = 0;
- TRACE_INPUT(ifp, from, (char *)rip, size);
- if (from->sa_family >= af_max ||
- (afp = &afswitch[from->sa_family])->af_hash == (int (*)())0) {
- syslog(LOG_INFO,
- "\"from\" address in unsupported address family (%d), cmd %d\n",
- from->sa_family, rip->rip_cmd);
- return;
- }
- if (rip->rip_vers == 0) {
- syslog(LOG_ERR,
- "RIP version 0 packet received from %s! (cmd %d)",
- (*afswitch[from->sa_family].af_format)(from), rip->rip_cmd);
- return;
- }
- switch (rip->rip_cmd) {
-
- case RIPCMD_REQUEST:
- n = rip->rip_nets;
- count = size - ((char *)n - (char *)rip);
- if (count < sizeof (struct netinfo))
- return;
- for (; count > 0; n++) {
- if (count < sizeof (struct netinfo))
- break;
- count -= sizeof (struct netinfo);
-
-#if BSD < 198810
- if (sizeof(n->rip_dst.sa_family) > 1) /* XXX */
- n->rip_dst.sa_family = ntohs(n->rip_dst.sa_family);
-#else
-#define osa(x) ((struct osockaddr *)(&(x)))
- n->rip_dst.sa_family =
- ntohs(osa(n->rip_dst)->sa_family);
- n->rip_dst.sa_len = sizeof(n->rip_dst);
-#endif
- n->rip_metric = ntohl(n->rip_metric);
- /*
- * A single entry with sa_family == AF_UNSPEC and
- * metric ``infinity'' means ``all routes''.
- * We respond to routers only if we are acting
- * as a supplier, or to anyone other than a router
- * (eg, query).
- */
- if (n->rip_dst.sa_family == AF_UNSPEC &&
- n->rip_metric == HOPCNT_INFINITY && count == 0) {
- if (supplier || (*afp->af_portmatch)(from) == 0)
- supply(from, 0, 0, 0);
- return;
- }
- if (n->rip_dst.sa_family < af_max &&
- afswitch[n->rip_dst.sa_family].af_hash)
- rt = rtlookup(&n->rip_dst);
- else
- rt = 0;
-#define min(a, b) (a < b ? a : b)
- n->rip_metric = rt == 0 ? HOPCNT_INFINITY :
- min(rt->rt_metric + 1, HOPCNT_INFINITY);
-#if BSD < 198810
- if (sizeof(n->rip_dst.sa_family) > 1) /* XXX */
- n->rip_dst.sa_family = htons(n->rip_dst.sa_family);
-#else
- osa(n->rip_dst)->sa_family =
- htons(n->rip_dst.sa_family);
-#endif
- n->rip_metric = htonl(n->rip_metric);
- }
- rip->rip_cmd = RIPCMD_RESPONSE;
- bcopy((char *)rip, packet, size);
- (*afp->af_output)(s, 0, from, size);
- return;
-
- case RIPCMD_TRACEON:
- case RIPCMD_TRACEOFF:
- /* verify message came from a privileged port */
- if ((*afp->af_portcheck)(from) == 0)
- return;
- if ((ifp = if_iflookup(from)) == 0 || (ifp->int_flags &
- (IFF_BROADCAST | IFF_POINTOPOINT | IFF_REMOTE)) == 0 ||
- ifp->int_flags & IFF_PASSIVE) {
- syslog(LOG_ERR, "trace command from unknown router, %s",
- (*afswitch[from->sa_family].af_format)(from));
- return;
- }
- ((char *)rip)[size] = '\0';
- if (rip->rip_cmd == RIPCMD_TRACEON)
- traceon(rip->rip_tracefile);
- else
- traceoff();
- return;
-
- case RIPCMD_RESPONSE:
- /* verify message came from a router */
- if ((*afp->af_portmatch)(from) == 0)
- return;
- (*afp->af_canon)(from);
- /* are we talking to ourselves? */
- ifp = if_ifwithaddr(from);
- if (ifp) {
- if (ifp->int_flags & IFF_PASSIVE) {
- syslog(LOG_ERR,
- "bogus input (from passive interface, %s)",
- (*afswitch[from->sa_family].af_format)(from));
- return;
- }
- rt = rtfind(from);
- if (rt == 0 || ((rt->rt_state & RTS_INTERFACE) == 0) &&
- rt->rt_metric >= ifp->int_metric)
- addrouteforif(ifp);
- else
- rt->rt_timer = 0;
- return;
- }
- /*
- * Update timer for interface on which the packet arrived.
- * If from other end of a point-to-point link that isn't
- * in the routing tables, (re-)add the route.
- */
- if ((rt = rtfind(from)) &&
- (rt->rt_state & (RTS_INTERFACE | RTS_REMOTE)))
- rt->rt_timer = 0;
- else if ((ifp = if_ifwithdstaddr(from)) &&
- (rt == 0 || rt->rt_metric >= ifp->int_metric))
- addrouteforif(ifp);
- /*
- * "Authenticate" router from which message originated.
- * We accept routing packets from routers directly connected
- * via broadcast or point-to-point networks,
- * and from those listed in /etc/gateways.
- */
- if ((ifp = if_iflookup(from)) == 0 || (ifp->int_flags &
- (IFF_BROADCAST | IFF_POINTOPOINT | IFF_REMOTE)) == 0 ||
- ifp->int_flags & IFF_PASSIVE) {
- if (bcmp((char *)from, (char *)&badfrom,
- sizeof(badfrom)) != 0) {
- syslog(LOG_ERR,
- "packet from unknown router, %s",
- (*afswitch[from->sa_family].af_format)(from));
- badfrom = *from;
- }
- return;
- }
- size -= 4 * sizeof (char);
- n = rip->rip_nets;
- for (; size > 0; size -= sizeof (struct netinfo), n++) {
- if (size < sizeof (struct netinfo))
- break;
-#if BSD < 198810
- if (sizeof(n->rip_dst.sa_family) > 1) /* XXX */
- n->rip_dst.sa_family =
- ntohs(n->rip_dst.sa_family);
-#else
- n->rip_dst.sa_family =
- ntohs(osa(n->rip_dst)->sa_family);
- n->rip_dst.sa_len = sizeof(n->rip_dst);
-#endif
- n->rip_metric = ntohl(n->rip_metric);
- if (n->rip_dst.sa_family >= af_max ||
- (afp = &afswitch[n->rip_dst.sa_family])->af_hash ==
- (int (*)())0) {
- syslog(LOG_INFO,
- "route in unsupported address family (%d), from %s (af %d)\n",
- n->rip_dst.sa_family,
- (*afswitch[from->sa_family].af_format)(from),
- from->sa_family);
- continue;
- }
- if (((*afp->af_checkhost)(&n->rip_dst)) == 0) {
- syslog(LOG_DEBUG,
- "bad host in route from %s (af %d)\n",
- (*afswitch[from->sa_family].af_format)(from),
- from->sa_family);
- continue;
- }
- if (n->rip_metric == 0 ||
- (unsigned) n->rip_metric > HOPCNT_INFINITY) {
- if (bcmp((char *)from, (char *)&badfrom2,
- sizeof(badfrom2)) != 0) {
- syslog(LOG_ERR,
- "bad metric (%d) from %s\n",
- n->rip_metric,
- (*afswitch[from->sa_family].af_format)(from));
- badfrom2 = *from;
- }
- continue;
- }
- /*
- * Adjust metric according to incoming interface.
- */
- if ((unsigned) n->rip_metric < HOPCNT_INFINITY)
- n->rip_metric += ifp->int_metric;
- if ((unsigned) n->rip_metric > HOPCNT_INFINITY)
- n->rip_metric = HOPCNT_INFINITY;
- rt = rtlookup(&n->rip_dst);
- if (rt == 0 ||
- (rt->rt_state & (RTS_INTERNAL|RTS_INTERFACE)) ==
- (RTS_INTERNAL|RTS_INTERFACE)) {
- /*
- * If we're hearing a logical network route
- * back from a peer to which we sent it,
- * ignore it.
- */
- if (rt && rt->rt_state & RTS_SUBNET &&
- (*afp->af_sendroute)(rt, from))
- continue;
- if ((unsigned)n->rip_metric < HOPCNT_INFINITY) {
- /*
- * Look for an equivalent route that
- * includes this one before adding
- * this route.
- */
- rt = rtfind(&n->rip_dst);
- if (rt && equal(from, &rt->rt_router))
- continue;
- rtadd(&n->rip_dst, from, n->rip_metric, 0);
- changes++;
- }
- continue;
- }
-
- /*
- * Update if from gateway and different,
- * shorter, or equivalent but old route
- * is getting stale.
- */
- if (equal(from, &rt->rt_router)) {
- if (n->rip_metric != rt->rt_metric) {
- rtchange(rt, from, n->rip_metric);
- changes++;
- rt->rt_timer = 0;
- if (rt->rt_metric >= HOPCNT_INFINITY)
- rt->rt_timer =
- GARBAGE_TIME - EXPIRE_TIME;
- } else if (rt->rt_metric < HOPCNT_INFINITY)
- rt->rt_timer = 0;
- } else if ((unsigned) n->rip_metric < rt->rt_metric ||
- (rt->rt_metric == n->rip_metric &&
- rt->rt_timer > (EXPIRE_TIME/2) &&
- (unsigned) n->rip_metric < HOPCNT_INFINITY)) {
- rtchange(rt, from, n->rip_metric);
- changes++;
- rt->rt_timer = 0;
- }
- }
- break;
- }
-
- /*
- * If changes have occurred, and if we have not sent a broadcast
- * recently, send a dynamic update. This update is sent only
- * on interfaces other than the one on which we received notice
- * of the change. If we are within MIN_WAITTIME of a full update,
- * don't bother sending; if we just sent a dynamic update
- * and set a timer (nextbcast), delay until that time.
- * If we just sent a full update, delay the dynamic update.
- * Set a timer for a randomized value to suppress additional
- * dynamic updates until it expires; if we delayed sending
- * the current changes, set needupdate.
- */
- if (changes && supplier &&
- now.tv_sec - lastfullupdate.tv_sec < SUPPLY_INTERVAL-MAX_WAITTIME) {
- u_long delay;
- extern long random();
-
- if (now.tv_sec - lastbcast.tv_sec >= MIN_WAITTIME &&
- timercmp(&nextbcast, &now, <)) {
- if (traceactions)
- fprintf(ftrace, "send dynamic update\n");
- toall(supply, RTS_CHANGED, ifp);
- lastbcast = now;
- needupdate = 0;
- nextbcast.tv_sec = 0;
- } else {
- needupdate++;
- if (traceactions)
- fprintf(ftrace, "delay dynamic update\n");
- }
-#define RANDOMDELAY() (MIN_WAITTIME * 1000000 + \
- (u_long)random() % ((MAX_WAITTIME - MIN_WAITTIME) * 1000000))
-
- if (nextbcast.tv_sec == 0) {
- delay = RANDOMDELAY();
- if (traceactions)
- fprintf(ftrace,
- "inhibit dynamic update for %d usec\n",
- delay);
- nextbcast.tv_sec = delay / 1000000;
- nextbcast.tv_usec = delay % 1000000;
- timevaladd(&nextbcast, &now);
- /*
- * If the next possibly dynamic update
- * is within MIN_WAITTIME of the next full update,
- * force the delay past the full update,
- * or we might send a dynamic update just before
- * the full update.
- */
- if (nextbcast.tv_sec > lastfullupdate.tv_sec +
- SUPPLY_INTERVAL - MIN_WAITTIME)
- nextbcast.tv_sec = lastfullupdate.tv_sec +
- SUPPLY_INTERVAL + 1;
- }
- }
-}
diff --git a/sbin/routed/interface.h b/sbin/routed/interface.h
deleted file mode 100644
index 6e555cb27830..000000000000
--- a/sbin/routed/interface.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 1983 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
- * must display the following acknowledgement:
- * 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.
- *
- * @(#)interface.h 5.6 (Berkeley) 6/1/90
- */
-
-/*
- * Routing table management daemon.
- */
-
-/*
- * An ``interface'' is similar to an ifnet structure,
- * except it doesn't contain q'ing info, and it also
- * handles ``logical'' interfaces (remote gateways
- * that we want to keep polling even if they go down).
- * The list of interfaces which we maintain is used
- * in supplying the gratuitous routing table updates.
- */
-struct interface {
- struct interface *int_next;
- struct sockaddr int_addr; /* address on this host */
- union {
- struct sockaddr intu_broadaddr;
- struct sockaddr intu_dstaddr;
- } int_intu;
-#define int_broadaddr int_intu.intu_broadaddr /* broadcast address */
-#define int_dstaddr int_intu.intu_dstaddr /* other end of p-to-p link */
- int int_metric; /* init's routing entry */
- int int_flags; /* see below */
- /* START INTERNET SPECIFIC */
- u_long int_net; /* network # */
- u_long int_netmask; /* net mask for addr */
- u_long int_subnet; /* subnet # */
- u_long int_subnetmask; /* subnet mask for addr */
- /* END INTERNET SPECIFIC */
- struct ifdebug int_input, int_output; /* packet tracing stuff */
- int int_ipackets; /* input packets received */
- int int_opackets; /* output packets sent */
- char *int_name; /* from kernel if structure */
- u_short int_transitions; /* times gone up-down */
-};
-
-/*
- * 0x1 to 0x10 are reused from the kernel's ifnet definitions,
- * the others agree with the RTS_ flags defined elsewhere.
- */
-#define IFF_UP 0x1 /* interface is up */
-#define IFF_BROADCAST 0x2 /* broadcast address valid */
-#define IFF_DEBUG 0x4 /* turn on debugging */
-#define IFF_LOOPBACK 0x8 /* software loopback net */
-#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
-
-#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 */
-
-struct interface *if_ifwithaddr();
-struct interface *if_ifwithdstaddr();
-struct interface *if_ifwithnet();
-struct interface *if_iflookup();
diff --git a/sbin/routed/main.c b/sbin/routed/main.c
deleted file mode 100644
index 75ed82f58e56..000000000000
--- a/sbin/routed/main.c
+++ /dev/null
@@ -1,343 +0,0 @@
-/*
- * Copyright (c) 1983, 1988 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1983, 1988 Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)main.c 5.23 (Berkeley) 7/1/91";
-#endif /* not lint */
-
-/*
- * Routing Table Management Daemon
- */
-#include "defs.h"
-#include <sys/ioctl.h>
-#include <sys/file.h>
-
-#include <net/if.h>
-
-#include <sys/errno.h>
-#include <sys/signal.h>
-#include <sys/syslog.h>
-#include "pathnames.h"
-
-int supplier = -1; /* process should supply updates */
-int gateway = 0; /* 1 if we are a gateway to parts beyond */
-int debug = 0;
-int bufspace = 127*1024; /* max. input buffer size to request */
-
-struct rip *msg = (struct rip *)packet;
-void hup(), rtdeleteall(), sigtrace(), timer();
-
-main(argc, argv)
- int argc;
- char *argv[];
-{
- int n, cc, nfd, omask, tflags = 0;
- struct sockaddr from;
- struct timeval *tvp, waittime;
- struct itimerval itval;
- register struct rip *query = msg;
- fd_set ibits;
- u_char retry;
-
- argv0 = argv;
-#if BSD >= 43
- openlog("routed", LOG_PID | LOG_ODELAY, LOG_DAEMON);
- setlogmask(LOG_UPTO(LOG_WARNING));
-#else
- openlog("routed", LOG_PID);
-#define LOG_UPTO(x) (x)
-#define setlogmask(x) (x)
-#endif
- sp = getservbyname("router", "udp");
- if (sp == NULL) {
- fprintf(stderr, "routed: router/udp: unknown service\n");
- exit(1);
- }
- addr.sin_family = AF_INET;
- addr.sin_port = sp->s_port;
- s = getsocket(AF_INET, SOCK_DGRAM, &addr);
- if (s < 0)
- exit(1);
- argv++, argc--;
- while (argc > 0 && **argv == '-') {
- if (strcmp(*argv, "-s") == 0) {
- supplier = 1;
- argv++, argc--;
- continue;
- }
- if (strcmp(*argv, "-q") == 0) {
- supplier = 0;
- argv++, argc--;
- continue;
- }
- if (strcmp(*argv, "-t") == 0) {
- tflags++;
- setlogmask(LOG_UPTO(LOG_DEBUG));
- argv++, argc--;
- continue;
- }
- if (strcmp(*argv, "-d") == 0) {
- debug++;
- setlogmask(LOG_UPTO(LOG_DEBUG));
- argv++, argc--;
- continue;
- }
- if (strcmp(*argv, "-g") == 0) {
- gateway = 1;
- argv++, argc--;
- continue;
- }
- fprintf(stderr,
- "usage: routed [ -s ] [ -q ] [ -t ] [ -g ]\n");
- exit(1);
- }
-
- if (debug == 0)
- daemon(0, 0);
- /*
- * Any extra argument is considered
- * a tracing log file.
- */
- if (argc > 0)
- traceon(*argv);
- while (tflags-- > 0)
- bumploglevel();
-
- (void) gettimeofday(&now, (struct timezone *)NULL);
- /*
- * Collect an initial view of the world by
- * checking the interface configuration and the gateway kludge
- * file. Then, send a request packet on all
- * directly connected networks to find out what
- * everyone else thinks.
- */
- rtinit();
- ifinit();
- gwkludge();
- if (gateway > 0)
- rtdefault();
- if (supplier < 0)
- supplier = 0;
- query->rip_cmd = RIPCMD_REQUEST;
- query->rip_vers = RIPVERSION;
- if (sizeof(query->rip_nets[0].rip_dst.sa_family) > 1) /* XXX */
- query->rip_nets[0].rip_dst.sa_family = htons((u_short)AF_UNSPEC);
- else
- query->rip_nets[0].rip_dst.sa_family = AF_UNSPEC;
- query->rip_nets[0].rip_metric = htonl((u_long)HOPCNT_INFINITY);
- toall(sndmsg);
- signal(SIGALRM, timer);
- signal(SIGHUP, hup);
- signal(SIGTERM, hup);
- signal(SIGINT, rtdeleteall);
- signal(SIGUSR1, sigtrace);
- signal(SIGUSR2, sigtrace);
- itval.it_interval.tv_sec = TIMER_RATE;
- itval.it_value.tv_sec = TIMER_RATE;
- itval.it_interval.tv_usec = 0;
- itval.it_value.tv_usec = 0;
- srandom(getpid());
- if (setitimer(ITIMER_REAL, &itval, (struct itimerval *)NULL) < 0)
- syslog(LOG_ERR, "setitimer: %m\n");
-
- FD_ZERO(&ibits);
- nfd = s + 1; /* 1 + max(fd's) */
- for (;;) {
- FD_SET(s, &ibits);
- /*
- * If we need a dynamic update that was held off,
- * needupdate will be set, and nextbcast is the time
- * by which we want select to return. Compute time
- * until dynamic update should be sent, and select only
- * until then. If we have already passed nextbcast,
- * just poll.
- */
- if (needupdate) {
- waittime = nextbcast;
- timevalsub(&waittime, &now);
- if (waittime.tv_sec < 0) {
- waittime.tv_sec = 0;
- waittime.tv_usec = 0;
- }
- if (traceactions)
- fprintf(ftrace,
- "select until dynamic update %d/%d sec/usec\n",
- waittime.tv_sec, waittime.tv_usec);
- tvp = &waittime;
- } else
- tvp = (struct timeval *)NULL;
- n = select(nfd, &ibits, 0, 0, tvp);
- if (n <= 0) {
- /*
- * Need delayed dynamic update if select returned
- * nothing and we timed out. Otherwise, ignore
- * errors (e.g. EINTR).
- */
- if (n < 0) {
- if (errno == EINTR)
- continue;
- syslog(LOG_ERR, "select: %m");
- }
- omask = sigblock(sigmask(SIGALRM));
- if (n == 0 && needupdate) {
- if (traceactions)
- fprintf(ftrace,
- "send delayed dynamic update\n");
- (void) gettimeofday(&now,
- (struct timezone *)NULL);
- toall(supply, RTS_CHANGED,
- (struct interface *)NULL);
- lastbcast = now;
- needupdate = 0;
- nextbcast.tv_sec = 0;
- }
- sigsetmask(omask);
- continue;
- }
- (void) gettimeofday(&now, (struct timezone *)NULL);
- omask = sigblock(sigmask(SIGALRM));
-#ifdef doesntwork
-/*
-printf("s %d, ibits %x index %d, mod %d, sh %x, or %x &ibits %x\n",
- s,
- ibits.fds_bits[0],
- (s)/(sizeof(fd_mask) * 8),
- ((s) % (sizeof(fd_mask) * 8)),
- (1 << ((s) % (sizeof(fd_mask) * 8))),
- ibits.fds_bits[(s)/(sizeof(fd_mask) * 8)] & (1 << ((s) % (sizeof(fd_mask) * 8))),
- &ibits
- );
-*/
- if (FD_ISSET(s, &ibits))
-#else
- if (ibits.fds_bits[s/32] & (1 << s))
-#endif
- process(s);
- /* handle ICMP redirects */
- sigsetmask(omask);
- }
-}
-
-timevaladd(t1, t2)
- struct timeval *t1, *t2;
-{
-
- t1->tv_sec += t2->tv_sec;
- if ((t1->tv_usec += t2->tv_usec) > 1000000) {
- t1->tv_sec++;
- t1->tv_usec -= 1000000;
- }
-}
-
-timevalsub(t1, t2)
- struct timeval *t1, *t2;
-{
-
- t1->tv_sec -= t2->tv_sec;
- if ((t1->tv_usec -= t2->tv_usec) < 0) {
- t1->tv_sec--;
- t1->tv_usec += 1000000;
- }
-}
-
-process(fd)
- int fd;
-{
- struct sockaddr from;
- int fromlen, cc;
- union {
- char buf[MAXPACKETSIZE+1];
- struct rip rip;
- } inbuf;
-
- for (;;) {
- fromlen = sizeof (from);
- cc = recvfrom(fd, &inbuf, sizeof (inbuf), 0, &from, &fromlen);
- if (cc <= 0) {
- if (cc < 0 && errno != EWOULDBLOCK)
- perror("recvfrom");
- break;
- }
- if (fromlen != sizeof (struct sockaddr_in))
- break;
- rip_input(&from, &inbuf.rip, cc);
- }
-}
-
-getsocket(domain, type, sin)
- int domain, type;
- struct sockaddr_in *sin;
-{
- int sock, on = 1;
-
- if ((sock = socket(domain, type, 0)) < 0) {
- perror("socket");
- syslog(LOG_ERR, "socket: %m");
- return (-1);
- }
-#ifdef SO_BROADCAST
- if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0) {
- syslog(LOG_ERR, "setsockopt SO_BROADCAST: %m");
- close(sock);
- return (-1);
- }
-#endif
-#ifdef SO_RCVBUF
- for (on = bufspace; ; on -= 1024) {
- if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
- &on, sizeof (on)) == 0)
- break;
- if (on <= 8*1024) {
- syslog(LOG_ERR, "setsockopt SO_RCVBUF: %m");
- break;
- }
- }
- if (traceactions)
- fprintf(ftrace, "recv buf %d\n", on);
-#endif
- if (bind(sock, (struct sockaddr *)sin, sizeof (*sin)) < 0) {
- perror("bind");
- syslog(LOG_ERR, "bind: %m");
- close(sock);
- return (-1);
- }
- if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1)
- syslog(LOG_ERR, "fcntl O_NONBLOCK: %m\n");
- return (sock);
-}
diff --git a/sbin/routed/output.c b/sbin/routed/output.c
deleted file mode 100644
index 10c81b1a0ca0..000000000000
--- a/sbin/routed/output.c
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Copyright (c) 1983, 1988 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)output.c 5.15 (Berkeley) 2/28/91";
-#endif /* not lint */
-
-/*
- * Routing Table Management Daemon
- */
-#include "defs.h"
-
-/*
- * Apply the function "f" to all non-passive
- * interfaces. If the interface supports the
- * use of broadcasting use it, otherwise address
- * the output to the known router.
- */
-toall(f, rtstate, skipif)
- int (*f)();
- int rtstate;
- struct interface *skipif;
-{
- register struct interface *ifp;
- register struct sockaddr *dst;
- register int flags;
- extern struct interface *ifnet;
-
- for (ifp = ifnet; ifp; ifp = ifp->int_next) {
- if (ifp->int_flags & IFF_PASSIVE || ifp == skipif)
- continue;
- dst = ifp->int_flags & IFF_BROADCAST ? &ifp->int_broadaddr :
- ifp->int_flags & IFF_POINTOPOINT ? &ifp->int_dstaddr :
- &ifp->int_addr;
- flags = ifp->int_flags & IFF_INTERFACE ? MSG_DONTROUTE : 0;
- (*f)(dst, flags, ifp, rtstate);
- }
-}
-
-/*
- * Output a preformed packet.
- */
-/*ARGSUSED*/
-sndmsg(dst, flags, ifp, rtstate)
- struct sockaddr *dst;
- int flags;
- struct interface *ifp;
- int rtstate;
-{
-
- (*afswitch[dst->sa_family].af_output)(s, flags,
- dst, sizeof (struct rip));
- TRACE_OUTPUT(ifp, dst, sizeof (struct rip));
-}
-
-/*
- * Supply dst with the contents of the routing tables.
- * If this won't fit in one packet, chop it up into several.
- */
-supply(dst, flags, ifp, rtstate)
- struct sockaddr *dst;
- int flags;
- register struct interface *ifp;
- int rtstate;
-{
- register struct rt_entry *rt;
- register struct netinfo *n = msg->rip_nets;
- register struct rthash *rh;
- struct rthash *base = hosthash;
- int doinghost = 1, size;
- int (*output)() = afswitch[dst->sa_family].af_output;
- int (*sendroute)() = afswitch[dst->sa_family].af_sendroute;
- int npackets = 0;
-
- msg->rip_cmd = RIPCMD_RESPONSE;
- msg->rip_vers = RIPVERSION;
- bzero(msg->rip_res1, sizeof(msg->rip_res1));
-again:
- for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++)
- for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
- /*
- * Don't resend the information on the network
- * from which it was received (unless sending
- * in response to a query).
- */
- if (ifp && rt->rt_ifp == ifp &&
- (rt->rt_state & RTS_INTERFACE) == 0)
- continue;
- if (rt->rt_state & RTS_EXTERNAL)
- continue;
- /*
- * For dynamic updates, limit update to routes
- * with the specified state.
- */
- if (rtstate && (rt->rt_state & rtstate) == 0)
- continue;
- /*
- * Limit the spread of subnet information
- * to those who are interested.
- */
- if (doinghost == 0 && rt->rt_state & RTS_SUBNET) {
- if (rt->rt_dst.sa_family != dst->sa_family)
- continue;
- if ((*sendroute)(rt, dst) == 0)
- continue;
- }
- size = (char *)n - packet;
- if (size > MAXPACKETSIZE - sizeof (struct netinfo)) {
- TRACE_OUTPUT(ifp, dst, size);
- (*output)(s, flags, dst, size);
- /*
- * If only sending to ourselves,
- * one packet is enough to monitor interface.
- */
- if (ifp && (ifp->int_flags &
- (IFF_BROADCAST | IFF_POINTOPOINT | IFF_REMOTE)) == 0)
- return;
- n = msg->rip_nets;
- npackets++;
- }
- n->rip_dst = rt->rt_dst;
-#if BSD < 198810
- if (sizeof(n->rip_dst.sa_family) > 1) /* XXX */
- n->rip_dst.sa_family = htons(n->rip_dst.sa_family);
-#else
-#define osa(x) ((struct osockaddr *)(&(x)))
- osa(n->rip_dst)->sa_family = htons(n->rip_dst.sa_family);
-#endif
- n->rip_metric = htonl(rt->rt_metric);
- n++;
- }
- if (doinghost) {
- doinghost = 0;
- base = nethash;
- goto again;
- }
- if (n != msg->rip_nets || (npackets == 0 && rtstate == 0)) {
- size = (char *)n - packet;
- TRACE_OUTPUT(ifp, dst, size);
- (*output)(s, flags, dst, size);
- }
-}
diff --git a/sbin/routed/pathnames.h b/sbin/routed/pathnames.h
deleted file mode 100644
index 54bac2751e52..000000000000
--- a/sbin/routed/pathnames.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 1989 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
- * must display the following acknowledgement:
- * 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.
- *
- * @(#)pathnames.h 5.3 (Berkeley) 6/1/90
- */
-
-#include <paths.h>
-
-#define _PATH_GATEWAYS "/etc/gateways"
diff --git a/sbin/routed/query/Makefile b/sbin/routed/query/Makefile
deleted file mode 100644
index 03746d30652d..000000000000
--- a/sbin/routed/query/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# @(#)Makefile 5.6 (Berkeley) 5/11/90
-
-PROG= query
-NOMAN= noman
-
-.include "../../Makefile.inc"
-.include <bsd.prog.mk>
diff --git a/sbin/routed/query/query.c b/sbin/routed/query/query.c
deleted file mode 100644
index 32c10c1e1a8b..000000000000
--- a/sbin/routed/query/query.c
+++ /dev/null
@@ -1,289 +0,0 @@
-/*-
- * Copyright (c) 1982, 1986 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1982, 1986 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)query.c 5.13 (Berkeley) 4/16/91";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/protosw.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <signal.h>
-#include <netinet/in.h>
-#include <protocols/routed.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define WTIME 5 /* Time to wait for all responses */
-#define STIME 500000 /* usec to wait for another response */
-
-int s;
-int timedout;
-void timeout();
-char packet[MAXPACKETSIZE];
-int nflag;
-
-main(argc, argv)
- int argc;
- char *argv[];
-{
- extern char *optarg;
- extern int optind;
- int ch, cc, count, bits;
- struct sockaddr from;
- int fromlen = sizeof(from), size = 32*1024;
- struct timeval shorttime;
-
- while ((ch = getopt(argc, argv, "n")) != EOF)
- switch((char)ch) {
- case 'n':
- nflag++;
- break;
- case '?':
- default:
- goto usage;
- }
- argv += optind;
-
- if (!*argv) {
-usage: printf("usage: query [-n] hosts...\n");
- exit(1);
- }
-
- s = socket(AF_INET, SOCK_DGRAM, 0);
- if (s < 0) {
- perror("socket");
- exit(2);
- }
- if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)) < 0)
- perror("setsockopt SO_RCVBUF");
-
- while (*argv) {
- query(*argv++);
- count++;
- }
-
- /*
- * Listen for returning packets;
- * may be more than one packet per host.
- */
- bits = 1 << s;
- bzero(&shorttime, sizeof(shorttime));
- shorttime.tv_usec = STIME;
- signal(SIGALRM, timeout);
- alarm(WTIME);
- while ((count > 0 && !timedout) ||
- select(20, (fd_set *)&bits, NULL, NULL, &shorttime) > 0) {
- cc = recvfrom(s, packet, sizeof (packet), 0,
- &from, &fromlen);
- if (cc <= 0) {
- if (cc < 0) {
- if (errno == EINTR)
- continue;
- perror("recvfrom");
- (void) close(s);
- exit(1);
- }
- continue;
- }
- rip_input(&from, cc);
- count--;
- }
- exit (count > 0 ? count : 0);
-}
-
-query(host)
- char *host;
-{
- struct sockaddr_in router;
- register struct rip *msg = (struct rip *)packet;
- struct hostent *hp;
- struct servent *sp;
-
- bzero((char *)&router, sizeof (router));
- router.sin_family = AF_INET;
- router.sin_addr.s_addr = inet_addr(host);
- if (router.sin_addr.s_addr == -1) {
- hp = gethostbyname(host);
- if (hp == NULL) {
- fprintf(stderr, "query: %s: ", host);
- herror((char *)NULL);
- exit(1);
- }
- bcopy(hp->h_addr, &router.sin_addr, hp->h_length);
- }
- sp = getservbyname("router", "udp");
- if (sp == 0) {
- printf("udp/router: service unknown\n");
- exit(1);
- }
- router.sin_port = sp->s_port;
- msg->rip_cmd = RIPCMD_REQUEST;
- msg->rip_vers = RIPVERSION;
- msg->rip_nets[0].rip_dst.sa_family = htons(AF_UNSPEC);
- msg->rip_nets[0].rip_metric = htonl(HOPCNT_INFINITY);
- if (sendto(s, packet, sizeof (struct rip), 0,
- (struct sockaddr *)&router, sizeof(router)) < 0)
- perror(host);
-}
-
-/*
- * Handle an incoming routing packet.
- */
-rip_input(from, size)
- struct sockaddr_in *from;
- int size;
-{
- register struct rip *msg = (struct rip *)packet;
- register struct netinfo *n;
- char *name;
- int lna, net, subnet;
- struct hostent *hp;
- struct netent *np;
-
- if (msg->rip_cmd != RIPCMD_RESPONSE)
- return;
- printf("%d bytes from ", size);
- if (nflag)
- printf("%s:\n", inet_ntoa(from->sin_addr));
- else {
- hp = gethostbyaddr((char *)&from->sin_addr,
- sizeof (struct in_addr), AF_INET);
- name = hp == 0 ? "???" : hp->h_name;
- printf("%s(%s):\n", name, inet_ntoa(from->sin_addr));
- }
- size -= sizeof (int);
- n = msg->rip_nets;
- while (size > 0) {
- if (size < sizeof (struct netinfo))
- break;
- if (msg->rip_vers > 0) {
- n->rip_dst.sa_family =
- ntohs(n->rip_dst.sa_family);
- n->rip_metric = ntohl(n->rip_metric);
- }
- switch (n->rip_dst.sa_family) {
-
- case AF_INET:
- { register struct sockaddr_in *sin;
-
- sin = (struct sockaddr_in *)&n->rip_dst;
- net = inet_netof(sin->sin_addr);
- subnet = inet_subnetof(sin->sin_addr);
- lna = inet_lnaof(sin->sin_addr);
- name = "???";
- if (!nflag) {
- if (sin->sin_addr.s_addr == 0)
- name = "default";
- else if (lna == INADDR_ANY) {
- np = getnetbyaddr(net, AF_INET);
- if (np)
- name = np->n_name;
- else if (net == 0)
- name = "default";
- } else if ((lna & 0xff) == 0 &&
- (np = getnetbyaddr(subnet, AF_INET))) {
- struct in_addr subnaddr, inet_makeaddr();
-
- subnaddr = inet_makeaddr(subnet, INADDR_ANY);
- if (bcmp(&sin->sin_addr, &subnaddr,
- sizeof(subnaddr)) == 0)
- name = np->n_name;
- else
- goto host;
- } else {
- host:
- hp = gethostbyaddr((char *)&sin->sin_addr,
- sizeof (struct in_addr), AF_INET);
- if (hp)
- name = hp->h_name;
- }
- printf("\t%-17s metric %2d name %s\n",
- inet_ntoa(sin->sin_addr), n->rip_metric, name);
- } else
- printf("\t%-17s metric %2d\n",
- inet_ntoa(sin->sin_addr), n->rip_metric);
- break;
- }
-
- default:
- { u_short *p = (u_short *)n->rip_dst.sa_data;
-
- printf("\t(af %d) %x %x %x %x %x %x %x, metric %d\n",
- p[0], p[1], p[2], p[3], p[4], p[5], p[6],
- n->rip_dst.sa_family,
- n->rip_metric);
- break;
- }
-
- }
- size -= sizeof (struct netinfo), n++;
- }
-}
-
-void
-timeout()
-{
- timedout = 1;
-}
-
-/*
- * Return the possible subnetwork number from an internet address.
- * SHOULD FIND OUT WHETHER THIS IS A LOCAL NETWORK BEFORE LOOKING
- * INSIDE OF THE HOST PART. We can only believe this if we have other
- * information (e.g., we can find a name for this number).
- */
-inet_subnetof(in)
- struct in_addr in;
-{
- register u_long i = ntohl(in.s_addr);
-
- if (IN_CLASSA(i))
- return ((i & IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
- else if (IN_CLASSB(i))
- return ((i & IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
- else
- return ((i & 0xffffffc0) >> 28);
-}
diff --git a/sbin/routed/routed.8 b/sbin/routed/routed.8
deleted file mode 100644
index 1d428a7b39b3..000000000000
--- a/sbin/routed/routed.8
+++ /dev/null
@@ -1,360 +0,0 @@
-.\" Copyright (c) 1983, 1991 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
-.\" must display the following acknowledgement:
-.\" 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.
-.\"
-.\" @(#)routed.8 6.6 (Berkeley) 3/16/91
-.\"
-.Dd March 16, 1991
-.Dt ROUTED 8
-.Os BSD 4.2
-.Sh NAME
-.Nm routed
-.Nd network routing daemon
-.Sh SYNOPSIS
-.Nm routed
-.Op Fl d
-.Op Fl g
-.Op Fl q
-.Op Fl s
-.Op Fl t
-.Op Ar logfile
-.Sh DESCRIPTION
-.Nm Routed
-is invoked at boot time to manage the network routing tables.
-The routing daemon uses a variant of the Xerox NS Routing
-Information Protocol in maintaining up to date kernel routing
-table entries.
-It used a generalized protocol capable of use with multiple
-address types, but is currently used only for Internet routing
-within a cluster of networks.
-.Pp
-In normal operation
-.Nm routed
-listens on the
-.Xr udp 4
-socket for the
-.Xr route 8
-service (see
-.Xr services 5 )
-for routing information packets. If the host is an
-internetwork router, it periodically supplies copies
-of its routing tables to any directly connected hosts
-and networks.
-.Pp
-When
-.Nm routed
-is started, it uses the
-.Dv SIOCGIFCONF
-.Xr ioctl 2
-to find those
-directly connected interfaces configured into the
-system and marked ``up'' (the software loopback interface
-is ignored). If multiple interfaces
-are present, it is assumed that the host will forward packets
-between networks.
-.Nm Routed
-then transmits a
-.Em request
-packet on each interface (using a broadcast packet if
-the interface supports it) and enters a loop, listening
-for
-.Em request
-and
-.Em response
-packets from other hosts.
-.Pp
-When a
-.Em request
-packet is received,
-.Nm routed
-formulates a reply based on the information maintained in its
-internal tables. The
-.Em response
-packet generated contains a list of known routes, each marked
-with a ``hop count'' metric (a count of 16, or greater, is
-considered ``infinite''). The metric associated with each
-route returned provides a metric
-.Em relative to the sender .
-.Pp
-.Em Response
-packets received by
-.Nm routed
-are used to update the routing tables if one of the following
-conditions is satisfied:
-.Bl -enum
-.It
-No routing table entry exists for the destination network
-or host, and the metric indicates the destination is ``reachable''
-(i.e. the hop count is not infinite).
-.It
-The source host of the packet is the same as the router in the
-existing routing table entry. That is, updated information is
-being received from the very internetwork router through which
-packets for the destination are being routed.
-.It
-The existing entry in the routing table has not been updated for
-some time (defined to be 90 seconds) and the route is at least
-as cost effective as the current route.
-.It
-The new route describes a shorter route to the destination than
-the one currently stored in the routing tables; the metric of
-the new route is compared against the one stored in the table
-to decide this.
-.El
-.Pp
-When an update is applied,
-.Nm routed
-records the change in its internal tables and updates the kernel
-routing table.
-The change is reflected in the next
-.Em response
-packet sent.
-.Pp
-In addition to processing incoming packets,
-.Nm routed
-also periodically checks the routing table entries.
-If an entry has not been updated for 3 minutes, the entry's metric
-is set to infinity and marked for deletion. Deletions are delayed
-an additional 60 seconds to insure the invalidation is propagated
-throughout the local internet.
-.Pp
-Hosts acting as internetwork routers gratuitously supply their
-routing tables every 30 seconds to all directly connected hosts
-and networks.
-The response is sent to the broadcast address on nets capable of that function,
-to the destination address on point-to-point links, and to the router's
-own address on other networks.
-The normal routing tables are bypassed when sending gratuitous responses.
-The reception of responses on each network is used to determine that the
-network and interface are functioning correctly.
-If no response is received on an interface, another route may be chosen
-to route around the interface, or the route may be dropped if no alternative
-is available.
-.Pp
-Options supported by
-.Nm routed :
-.Bl -tag -width Ds
-.It Fl d
-Enable additional debugging information to be logged,
-such as bad packets received.
-.It Fl g
-This flag is used on internetwork routers to offer a route
-to the ``default'' destination.
-This is typically used on a gateway to the Internet,
-or on a gateway that uses another routing protocol whose routes
-are not reported to other local routers.
-.It Fl s
-Supplying this
-option forces
-.Nm routed
-to supply routing information whether it is acting as an internetwork
-router or not.
-This is the default if multiple network interfaces are present,
-or if a point-to-point link is in use.
-.It Fl q
-This
-is the opposite of the
-.Fl s
-option.
-.It Fl t
-If the
-.Fl t
-option is specified, all packets sent or received are
-printed on the standard output. In addition,
-.Nm routed
-will not divorce itself from the controlling terminal
-so that interrupts from the keyboard will kill the process.
-.El
-.Pp
-Any other argument supplied is interpreted as the name
-of file in which
-.Nm routed Ns \'s
-actions should be logged. This log contains information
-about any changes to the routing tables and, if not tracing all packets,
-a history of recent messages sent and received which are related to
-the changed route.
-.Pp
-In addition to the facilities described above,
-.Nm routed
-supports the notion of ``distant''
-.Em passive
-and
-.Em active
-gateways. When
-.Nm routed
-is started up, it reads the file
-.Pa /etc/gateways
-to find gateways which may not be located using
-only information from the
-.Dv SIOGIFCONF
-.Xr ioctl 2 .
-Gateways specified in this manner should be marked passive
-if they are not expected to exchange routing information,
-while gateways marked active
-should be willing to exchange routing information (i.e.
-they should have a
-.Nm routed
-process running on the machine).
-Routes through passive gateways are installed in the
-kernel's routing tables once upon startup.
-Such routes are not included in
-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
-route is deleted.
-Gateways marked
-.Em external
-are also passive, but are not placed in the kernel
-routing table nor are they included in routing updates.
-The function of external entries is to inform
-.Nm routed
-that another routing process
-will install such a route, and that alternate routes to that destination
-should not be installed.
-Such entries are only required when both routers may learn of routes
-to the same destination.
-.Pp
-The
-.Pa /etc/gateways
-is comprised of a series of lines, each in
-the following format:
-.Bd -ragged
-.Pf < Cm net No \&|
-.Cm host Ns >
-.Ar name1
-.Cm gateway
-.Ar name2
-.Cm metric
-.Ar value
-.Pf < Cm passive No \&|
-.Cm active No \&|
-.Cm external Ns >
-.Ed
-.Pp
-The
-.Cm net
-or
-.Cm host
-keyword indicates if the route is to a network or specific host.
-.Pp
-.Ar Name1
-is the name of the destination network or host. This may be a
-symbolic name located in
-.Pa /etc/networks
-or
-.Pa /etc/hosts
-(or, if started after
-.Xr named 8 ,
-known to the name server),
-or an Internet address specified in ``dot'' notation; see
-.Xr inet 3 .
-.Pp
-.Ar Name2
-is the name or address of the gateway to which messages should
-be forwarded.
-.Pp
-.Ar Value
-is a metric indicating the hop count to the destination host
-or network.
-.Pp
-One of the keywords
-.Cm passive ,
-.Cm active
-or
-.Cm external
-indicates if the gateway should be treated as
-.Em passive
-or
-.Em active
-(as described above),
-or whether the gateway is
-.Em external
-to the scope of the
-.Nm routed
-protocol.
-.Pp
-Internetwork routers that are directly attached to the Arpanet or Milnet
-should use the Exterior Gateway Protocol
-.Pq Tn EGP
-to gather routing information
-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
-for distant gateways
-.El
-.Sh SEE ALSO
-.Xr udp 4 ,
-.Xr icmp 4 ,
-.Xr XNSrouted 8 ,
-.Xr htable 8
-.Rs
-.%T Internet Transport Protocols
-.%R XSIS 028112
-.%Q Xerox System Integration Standard
-.Re
-.Sh BUGS
-The kernel's routing tables may not correspond to those of
-.Nm routed
-when redirects change or add routes.
-.Nm Routed
-should note any redirects received by reading
-the
-.Tn ICMP
-packets received via a raw socket.
-.Pp
-.Nm Routed
-should incorporate other routing protocols,
-such as Xerox
-.Tn \&NS
-.Pq Xr XNSrouted 8
-and
-.Tn EGP .
-Using separate processes for each requires configuration options
-to avoid redundant or competing routes.
-.Pp
-.Nm Routed
-should listen to intelligent interfaces, such as an
-.Tn IMP ,
-to gather more information.
-It does not always detect unidirectional failures in network interfaces
-(e.g., when the output side fails).
-.Sh HISTORY
-The
-.Nm
-command appeared in
-.Bx 4.2 .
diff --git a/sbin/routed/startup.c b/sbin/routed/startup.c
deleted file mode 100644
index f88d5935c025..000000000000
--- a/sbin/routed/startup.c
+++ /dev/null
@@ -1,486 +0,0 @@
-/*
- * Copyright (c) 1983, 1988 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)startup.c 5.19 (Berkeley) 2/28/91";
-#endif /* not lint */
-
-/*
- * Routing Table Management Daemon
- */
-#include "defs.h"
-#include <sys/ioctl.h>
-#include <net/if.h>
-#include <syslog.h>
-#include <stdlib.h>
-#include "pathnames.h"
-
-struct interface *ifnet;
-struct interface **ifnext = &ifnet;
-int lookforinterfaces = 1;
-int externalinterfaces = 0; /* # of remote and local interfaces */
-int foundloopback; /* valid flag for loopaddr */
-struct sockaddr loopaddr; /* our address on loopback */
-
-/*
- * Find the network interfaces which have configured themselves.
- * If the interface is present but not yet up (for example an
- * ARPANET IMP), set the lookforinterfaces flag so we'll
- * come back later and look again.
- */
-ifinit()
-{
- struct interface ifs, *ifp;
- int s;
- char buf[BUFSIZ], *cp, *cplim;
- struct ifconf ifc;
- struct ifreq ifreq, *ifr;
- 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;
- 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_INTERFACE;
- if ((ifs.int_flags & IFF_UP) == 0 ||
- ifr->ifr_addr.sa_family == AF_UNSPEC) {
- lookforinterfaces = 1;
- continue;
- }
- /* argh, this'll have to change sometime */
- 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;
- }
- if (ifr->ifr_addr.sa_family == AF_UNSPEC) {
- lookforinterfaces = 1;
- continue;
- }
- ifs.int_dstaddr = ifreq.ifr_dstaddr;
- }
- /*
- * already known to us?
- * This allows multiple point-to-point links
- * to share a source address (possibly with one
- * other link), but assumes that there will not be
- * multiple links with the same destination address.
- */
- if (ifs.int_flags & IFF_POINTOPOINT) {
- if (if_ifwithdstaddr(&ifs.int_dstaddr))
- continue;
- } else if (if_ifwithaddr(&ifs.int_addr))
- continue;
- if (ifs.int_flags & IFF_LOOPBACK) {
- ifs.int_flags |= IFF_PASSIVE;
- foundloopback = 1;
- loopaddr = ifs.int_addr;
- for (ifp = ifnet; ifp; ifp = ifp->int_next)
- 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
- }
-#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;
- }
- sin = (struct sockaddr_in *)&ifreq.ifr_addr;
- ifs.int_subnetmask = ntohl(sin->sin_addr.s_addr);
- sin = (struct sockaddr_in *)&ifs.int_addr;
- i = ntohl(sin->sin_addr.s_addr);
- if (IN_CLASSA(i))
- ifs.int_netmask = IN_CLASSA_NET;
- else if (IN_CLASSB(i))
- ifs.int_netmask = IN_CLASSB_NET;
- else
- ifs.int_netmask = IN_CLASSC_NET;
- ifs.int_net = i & ifs.int_netmask;
- 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));
- if (ifp == 0) {
- printf("routed: out of memory\n");
- break;
- }
- *ifp = ifs;
- /*
- * Count the # of directly connected networks
- * and point to point links which aren't looped
- * back to ourself. This is used below to
- * decide if we should be a routing ``supplier''.
- */
- if ((ifs.int_flags & IFF_LOOPBACK) == 0 &&
- ((ifs.int_flags & IFF_POINTOPOINT) == 0 ||
- if_ifwithaddr(&ifs.int_dstaddr) == 0))
- externalinterfaces++;
- /*
- * If we have a point-to-point link, we want to act
- * as a supplier even if it's our only interface,
- * as that's the only way our peer on the other end
- * can tell that the link is up.
- */
- 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);
- *ifnext = ifp;
- ifnext = &ifp->int_next;
- traceinit(ifp);
- addrouteforif(ifp);
- }
- if (externalinterfaces > 1 && supplier < 0)
- supplier = 1;
- close(s);
-}
-
-/*
- * Add route for interface if not currently installed.
- * Create route to other end if a point-to-point link,
- * otherwise a route to this (sub)network.
- * INTERNET SPECIFIC.
- */
-addrouteforif(ifp)
- register struct interface *ifp;
-{
- struct sockaddr_in net;
- struct sockaddr *dst;
- int state;
- register struct rt_entry *rt;
-
- if (ifp->int_flags & IFF_POINTOPOINT)
- dst = &ifp->int_dstaddr;
- else {
- bzero((char *)&net, sizeof (net));
- net.sin_family = AF_INET;
- net.sin_addr = inet_makeaddr(ifp->int_subnet, INADDR_ANY);
- dst = (struct sockaddr *)&net;
- }
- rt = rtfind(dst);
- if (rt &&
- (rt->rt_state & (RTS_INTERFACE | RTS_INTERNAL)) == RTS_INTERFACE)
- return;
- if (rt)
- rtdelete(rt);
- /*
- * If interface on subnetted network,
- * install route to network as well.
- * This is meant for external viewers.
- */
- if ((ifp->int_flags & (IFF_SUBNET|IFF_POINTOPOINT)) == IFF_SUBNET) {
- struct in_addr subnet;
-
- subnet = net.sin_addr;
- net.sin_addr = inet_makeaddr(ifp->int_net, INADDR_ANY);
- rt = rtfind(dst);
- if (rt == 0)
- rtadd(dst, &ifp->int_addr, ifp->int_metric,
- ((ifp->int_flags & (IFF_INTERFACE|IFF_REMOTE)) |
- RTS_PASSIVE | RTS_INTERNAL | RTS_SUBNET));
- else if ((rt->rt_state & (RTS_INTERNAL|RTS_SUBNET)) ==
- (RTS_INTERNAL|RTS_SUBNET) &&
- ifp->int_metric < rt->rt_metric)
- rtchange(rt, &rt->rt_router, ifp->int_metric);
- net.sin_addr = subnet;
- }
- if (ifp->int_transitions++ > 0)
- syslog(LOG_ERR, "re-installing interface %s", ifp->int_name);
- state = ifp->int_flags &
- (IFF_INTERFACE | IFF_PASSIVE | IFF_REMOTE | IFF_SUBNET);
- if (ifp->int_flags & IFF_POINTOPOINT &&
- (ntohl(((struct sockaddr_in *)&ifp->int_dstaddr)->sin_addr.s_addr) &
- ifp->int_netmask) != ifp->int_net)
- state &= ~RTS_SUBNET;
- if (ifp->int_flags & IFF_LOOPBACK)
- state |= RTS_EXTERNAL;
- rtadd(dst, &ifp->int_addr, ifp->int_metric, state);
- if (ifp->int_flags & IFF_POINTOPOINT && foundloopback)
- add_ptopt_localrt(ifp);
-}
-
-/*
- * Add route to local end of point-to-point using loopback.
- * If a route to this network is being sent to neighbors on other nets,
- * mark this route as subnet so we don't have to propagate it too.
- */
-add_ptopt_localrt(ifp)
- register struct interface *ifp;
-{
- struct rt_entry *rt;
- struct sockaddr *dst;
- struct sockaddr_in net;
- int state;
-
- state = RTS_INTERFACE | RTS_PASSIVE;
-
- /* look for route to logical network */
- bzero((char *)&net, sizeof (net));
- net.sin_family = AF_INET;
- net.sin_addr = inet_makeaddr(ifp->int_net, INADDR_ANY);
- dst = (struct sockaddr *)&net;
- rt = rtfind(dst);
- if (rt && rt->rt_state & RTS_INTERNAL)
- state |= RTS_SUBNET;
-
- dst = &ifp->int_addr;
- if (rt = rtfind(dst)) {
- if (rt && rt->rt_state & RTS_INTERFACE)
- return;
- rtdelete(rt);
- }
- rtadd(dst, &loopaddr, 1, state);
-}
-
-/*
- * As a concession to the ARPANET we read a list of gateways
- * from /etc/gateways and add them to our tables. This file
- * exists at each ARPANET gateway and indicates a set of ``remote''
- * gateways (i.e. a gateway which we can't immediately determine
- * if it's present or not as we can do for those directly connected
- * at the hardware level). If a gateway is marked ``passive''
- * in the file, then we assume it doesn't have a routing process
- * of our design and simply assume it's always present. Those
- * not marked passive are treated as if they were directly
- * connected -- they're added into the interface list so we'll
- * send them routing updates.
- *
- * PASSIVE ENTRIES AREN'T NEEDED OR USED ON GATEWAYS RUNNING EGP.
- */
-gwkludge()
-{
- struct sockaddr_in dst, gate;
- FILE *fp;
- char *type, *dname, *gname, *qual, buf[BUFSIZ];
- struct interface *ifp;
- int metric, n;
- struct rt_entry route;
-
- fp = fopen(_PATH_GATEWAYS, "r");
- if (fp == NULL)
- return;
- qual = buf;
- dname = buf + 64;
- gname = buf + ((BUFSIZ - 64) / 3);
- type = buf + (((BUFSIZ - 64) * 2) / 3);
- bzero((char *)&dst, sizeof (dst));
- bzero((char *)&gate, sizeof (gate));
- bzero((char *)&route, sizeof(route));
-/* format: {net | host} XX gateway XX metric DD [passive | external]\n */
-#define readentry(fp) \
- fscanf((fp), "%s %s gateway %s metric %d %s\n", \
- type, dname, gname, &metric, qual)
- for (;;) {
- if ((n = readentry(fp)) == EOF)
- break;
- if (!getnetorhostname(type, dname, &dst))
- continue;
- if (!gethostnameornumber(gname, &gate))
- continue;
- if (metric == 0) /* XXX */
- metric = 1;
- if (strcmp(qual, "passive") == 0) {
- /*
- * Passive entries aren't placed in our tables,
- * only the kernel's, so we don't copy all of the
- * external routing information within a net.
- * Internal machines should use the default
- * route to a suitable gateway (like us).
- */
- route.rt_dst = *(struct sockaddr *) &dst;
- route.rt_router = *(struct sockaddr *) &gate;
- route.rt_flags = RTF_UP;
- if (strcmp(type, "host") == 0)
- route.rt_flags |= RTF_HOST;
- if (metric)
- route.rt_flags |= RTF_GATEWAY;
- (void) ioctl(s, SIOCADDRT, (char *)&route.rt_rt);
- continue;
- }
- if (strcmp(qual, "external") == 0) {
- /*
- * Entries marked external are handled
- * by other means, e.g. EGP,
- * and are placed in our tables only
- * to prevent overriding them
- * with something else.
- */
- rtadd(&dst, &gate, metric, RTS_EXTERNAL|RTS_PASSIVE);
- continue;
- }
- /* assume no duplicate entries */
- externalinterfaces++;
- ifp = (struct interface *)malloc(sizeof (*ifp));
- bzero((char *)ifp, sizeof (*ifp));
- ifp->int_flags = IFF_REMOTE;
- /* can't identify broadcast capability */
- ifp->int_net = inet_netof(dst.sin_addr);
- if (strcmp(type, "host") == 0) {
- ifp->int_flags |= IFF_POINTOPOINT;
- ifp->int_dstaddr = *((struct sockaddr *)&dst);
- }
- ifp->int_addr = *((struct sockaddr *)&gate);
- ifp->int_metric = metric;
- ifp->int_next = ifnet;
- ifnet = ifp;
- addrouteforif(ifp);
- }
- fclose(fp);
-}
-
-getnetorhostname(type, name, sin)
- char *type, *name;
- struct sockaddr_in *sin;
-{
-
- if (strcmp(type, "net") == 0) {
- struct netent *np = getnetbyname(name);
- int n;
-
- if (np == 0)
- n = inet_network(name);
- else {
- if (np->n_addrtype != AF_INET)
- return (0);
- n = np->n_net;
- /*
- * getnetbyname returns right-adjusted value.
- */
- if (n < 128)
- n <<= IN_CLASSA_NSHIFT;
- else if (n < 65536)
- n <<= IN_CLASSB_NSHIFT;
- else
- n <<= IN_CLASSC_NSHIFT;
- }
- sin->sin_family = AF_INET;
- sin->sin_addr = inet_makeaddr(n, INADDR_ANY);
- return (1);
- }
- if (strcmp(type, "host") == 0) {
- struct hostent *hp = gethostbyname(name);
-
- if (hp == 0)
- sin->sin_addr.s_addr = inet_addr(name);
- else {
- if (hp->h_addrtype != AF_INET)
- return (0);
- bcopy(hp->h_addr, &sin->sin_addr, hp->h_length);
- }
- sin->sin_family = AF_INET;
- return (1);
- }
- return (0);
-}
-
-gethostnameornumber(name, sin)
- char *name;
- struct sockaddr_in *sin;
-{
- struct hostent *hp;
-
- hp = gethostbyname(name);
- if (hp) {
- bcopy(hp->h_addr, &sin->sin_addr, hp->h_length);
- sin->sin_family = hp->h_addrtype;
- return (1);
- }
- sin->sin_addr.s_addr = inet_addr(name);
- sin->sin_family = AF_INET;
- return (sin->sin_addr.s_addr != -1);
-}
diff --git a/sbin/routed/table.h b/sbin/routed/table.h
deleted file mode 100644
index 124e098eb295..000000000000
--- a/sbin/routed/table.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (c) 1983 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
- * must display the following acknowledgement:
- * 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.
- *
- * @(#)table.h 5.8 (Berkeley) 6/1/90
- */
-
-/*
- * Routing table management daemon.
- */
-
-/*
- * Routing table structure; differs a bit from kernel tables.
- *
- * Note: the union below must agree in the first 4 members
- * so the ioctl's will work.
- */
-struct rthash {
- struct rt_entry *rt_forw;
- struct rt_entry *rt_back;
-};
-#ifdef RTM_ADD
-#define rtentry ortentry
-#endif
-
-struct rt_entry {
- struct rt_entry *rt_forw;
- struct rt_entry *rt_back;
- union {
- struct rtentry rtu_rt;
- struct {
- u_long rtu_hash;
- struct sockaddr rtu_dst;
- struct sockaddr rtu_router;
- short rtu_flags;
- short rtu_state;
- int rtu_timer;
- int rtu_metric;
- int rtu_ifmetric;
- struct interface *rtu_ifp;
- } rtu_entry;
- } rt_rtu;
-};
-
-#define rt_rt rt_rtu.rtu_rt /* 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 */
-#define rt_flags rt_rtu.rtu_entry.rtu_flags /* kernel flags */
-#define rt_timer rt_rtu.rtu_entry.rtu_timer /* for invalidation */
-#define rt_state rt_rtu.rtu_entry.rtu_state /* see below */
-#define rt_metric rt_rtu.rtu_entry.rtu_metric /* cost of route */
-#define rt_ifmetric rt_rtu.rtu_entry.rtu_ifmetric /* cost of route if */
-#define rt_ifp rt_rtu.rtu_entry.rtu_ifp /* interface to take */
-
-#define ROUTEHASHSIZ 32 /* must be a power of 2 */
-#define ROUTEHASHMASK (ROUTEHASHSIZ - 1)
-
-/*
- * "State" of routing table entry.
- */
-#define RTS_CHANGED 0x1 /* route has been altered recently */
-#define RTS_EXTERNAL 0x2 /* extern info, not installed or sent */
-#define RTS_INTERNAL 0x4 /* internal route, not installed */
-#define RTS_PASSIVE IFF_PASSIVE /* don't time out route */
-#define RTS_INTERFACE IFF_INTERFACE /* route is for network interface */
-#define RTS_REMOTE IFF_REMOTE /* route is for ``remote'' entity */
-#define RTS_SUBNET IFF_SUBNET /* route is for network subnet */
-
-/*
- * Flags are same as kernel, with this addition for af_rtflags:
- */
-#define RTF_SUBNET 0x8000 /* pseudo: route to subnet */
-
-struct rthash nethash[ROUTEHASHSIZ];
-struct rthash hosthash[ROUTEHASHSIZ];
-struct rt_entry *rtlookup();
-struct rt_entry *rtfind();
diff --git a/sbin/routed/tables.c b/sbin/routed/tables.c
deleted file mode 100644
index 17a4fb7b966e..000000000000
--- a/sbin/routed/tables.c
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- * Copyright (c) 1983, 1988 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)tables.c 5.17 (Berkeley) 6/1/90";
-#endif /* not lint */
-
-/*
- * Routing Table Management Daemon
- */
-#include "defs.h"
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <sys/syslog.h>
-
-#ifndef DEBUG
-#define DEBUG 0
-#endif
-
-#ifdef RTM_ADD
-#define FIXLEN(s) {if ((s)->sa_len == 0) (s)->sa_len = sizeof *(s);}
-#else
-#define FIXLEN(s) { }
-#endif
-
-int install = !DEBUG; /* if 1 call kernel */
-
-/*
- * Lookup dst in the tables for an exact match.
- */
-struct rt_entry *
-rtlookup(dst)
- struct sockaddr *dst;
-{
- register struct rt_entry *rt;
- register struct rthash *rh;
- register u_int hash;
- struct afhash h;
- int doinghost = 1;
-
- if (dst->sa_family >= af_max)
- return (0);
- (*afswitch[dst->sa_family].af_hash)(dst, &h);
- hash = h.afh_hosthash;
- rh = &hosthash[hash & ROUTEHASHMASK];
-again:
- for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
- if (rt->rt_hash != hash)
- continue;
- if (equal(&rt->rt_dst, dst))
- return (rt);
- }
- if (doinghost) {
- doinghost = 0;
- hash = h.afh_nethash;
- rh = &nethash[hash & ROUTEHASHMASK];
- goto again;
- }
- return (0);
-}
-
-struct sockaddr wildcard; /* zero valued cookie for wildcard searches */
-
-/*
- * Find a route to dst as the kernel would.
- */
-struct rt_entry *
-rtfind(dst)
- struct sockaddr *dst;
-{
- register struct rt_entry *rt;
- register struct rthash *rh;
- register u_int hash;
- struct afhash h;
- int af = dst->sa_family;
- int doinghost = 1, (*match)();
-
- if (af >= af_max)
- return (0);
- (*afswitch[af].af_hash)(dst, &h);
- hash = h.afh_hosthash;
- rh = &hosthash[hash & ROUTEHASHMASK];
-
-again:
- for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
- if (rt->rt_hash != hash)
- continue;
- if (doinghost) {
- if (equal(&rt->rt_dst, dst))
- return (rt);
- } else {
- if (rt->rt_dst.sa_family == af &&
- (*match)(&rt->rt_dst, dst))
- return (rt);
- }
- }
- if (doinghost) {
- doinghost = 0;
- hash = h.afh_nethash;
- rh = &nethash[hash & ROUTEHASHMASK];
- match = afswitch[af].af_netmatch;
- goto again;
- }
-#ifdef notyet
- /*
- * Check for wildcard gateway, by convention network 0.
- */
- if (dst != &wildcard) {
- dst = &wildcard, hash = 0;
- goto again;
- }
-#endif
- return (0);
-}
-
-rtadd(dst, gate, metric, state)
- struct sockaddr *dst, *gate;
- int metric, state;
-{
- struct afhash h;
- register struct rt_entry *rt;
- struct rthash *rh;
- int af = dst->sa_family, flags;
- u_int hash;
-
- if (af >= af_max)
- return;
- (*afswitch[af].af_hash)(dst, &h);
- flags = (*afswitch[af].af_rtflags)(dst);
- /*
- * Subnet flag isn't visible to kernel, move to state. XXX
- */
- FIXLEN(dst);
- FIXLEN(gate);
- if (flags & RTF_SUBNET) {
- state |= RTS_SUBNET;
- flags &= ~RTF_SUBNET;
- }
- if (flags & RTF_HOST) {
- hash = h.afh_hosthash;
- rh = &hosthash[hash & ROUTEHASHMASK];
- } else {
- hash = h.afh_nethash;
- rh = &nethash[hash & ROUTEHASHMASK];
- }
- rt = (struct rt_entry *)malloc(sizeof (*rt));
- if (rt == 0)
- return;
- rt->rt_hash = hash;
- rt->rt_dst = *dst;
- rt->rt_router = *gate;
- rt->rt_timer = 0;
- rt->rt_flags = RTF_UP | flags;
- rt->rt_state = state | RTS_CHANGED;
- rt->rt_ifp = if_ifwithdstaddr(&rt->rt_dst);
- if (rt->rt_ifp == 0) {
- rt->rt_ifp = if_ifwithnet(&rt->rt_router);
- /*
- * seems like we can't figure out the interface for the
- * IP address of the local side of a point to point
- * connection, we just don't add that entry in the
- * table. (it seems to already be there anyway)
- */
- if (rt->rt_ifp == 0) {
- syslog(LOG_DEBUG,
- "rtadd: can't get interface for %s",
- (*afswitch[dst->sa_family].af_format)(dst));
- return;
- }
- }
- if ((state & RTS_INTERFACE) == 0)
- rt->rt_flags |= RTF_GATEWAY;
- rt->rt_metric = metric;
- insque(rt, rh);
- TRACE_ACTION("ADD", rt);
- /*
- * If the ioctl fails because the gateway is unreachable
- * 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 (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");
- if (errno == ENETUNREACH) {
- TRACE_ACTION("DELETE", rt);
- remque(rt);
- free((char *)rt);
- }
- }
-}
-
-rtchange(rt, gate, metric)
- struct rt_entry *rt;
- struct sockaddr *gate;
- short metric;
-{
- int add = 0, delete = 0, newgateway = 0;
- struct rtentry oldroute;
-
- FIXLEN(gate);
- FIXLEN(&(rt->rt_router));
- FIXLEN(&(rt->rt_dst));
- if (!equal(&rt->rt_router, gate)) {
- newgateway++;
- TRACE_ACTION("CHANGE FROM ", rt);
- } else if (metric != rt->rt_metric)
- TRACE_NEWMETRIC(rt, metric);
- if ((rt->rt_state & RTS_INTERNAL) == 0) {
- /*
- * If changing to different router, we need to add
- * new route and delete old one if in the kernel.
- * If the router is the same, we need to delete
- * the route if has become unreachable, or re-add
- * it if it had been unreachable.
- */
- if (newgateway) {
- add++;
- if (rt->rt_metric != HOPCNT_INFINITY)
- delete++;
- } else if (metric == HOPCNT_INFINITY)
- delete++;
- else if (rt->rt_metric == HOPCNT_INFINITY)
- add++;
- }
- if (delete)
- oldroute = rt->rt_rt;
- if ((rt->rt_state & RTS_INTERFACE) && delete) {
- rt->rt_state &= ~RTS_INTERFACE;
- rt->rt_flags |= RTF_GATEWAY;
- if (metric > rt->rt_metric && delete)
- syslog(LOG_ERR, "%s route to interface %s (timed out)",
- add? "changing" : "deleting",
- rt->rt_ifp->int_name);
- }
- if (add) {
- rt->rt_router = *gate;
- rt->rt_ifp = if_ifwithdstaddr(&rt->rt_router);
- if (rt->rt_ifp == 0) {
- rt->rt_ifp = if_ifwithnet(&rt->rt_router);
- /*
- * seems like we can't figure out the interface for the
- * IP address of the local side of a point to point
- * connection, we just don't add that entry in the
- * table. (it seems to already be there anyway)
- */
- if (rt->rt_ifp == 0) {
- struct sockaddr *dst = &(rt->rt_dst);
- syslog(LOG_DEBUG,
- "rtchange: can't get interface for %s",
- (*afswitch[dst->sa_family].af_format)(dst));
- return;
- }
- }
- }
- rt->rt_metric = metric;
- rt->rt_state |= RTS_CHANGED;
- 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");
-#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");
- }
-#endif
-}
-
-rtdelete(rt)
- struct rt_entry *rt;
-{
-
- TRACE_ACTION("DELETE", rt);
- FIXLEN(&(rt->rt_router));
- FIXLEN(&(rt->rt_dst));
- if (rt->rt_metric < HOPCNT_INFINITY) {
- if ((rt->rt_state & (RTS_INTERFACE|RTS_INTERNAL)) == RTS_INTERFACE)
- 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");
- }
- remque(rt);
- free((char *)rt);
-}
-
-rtdeleteall(sig)
- int sig;
-{
- register struct rthash *rh;
- register struct rt_entry *rt;
- struct rthash *base = hosthash;
- int doinghost = 1;
-
-again:
- for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
- rt = rh->rt_forw;
- for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
- if (rt->rt_state & RTS_INTERFACE ||
- rt->rt_metric >= HOPCNT_INFINITY)
- continue;
- TRACE_ACTION("DELETE", rt);
- if ((rt->rt_state & (RTS_INTERNAL|RTS_EXTERNAL)) == 0 &&
- ioctl(s, SIOCDELRT, (char *)&rt->rt_rt))
- perror("SIOCDELRT");
- }
- }
- if (doinghost) {
- doinghost = 0;
- base = nethash;
- goto again;
- }
- exit(sig);
-}
-
-/*
- * If we have an interface to the wide, wide world,
- * add an entry for an Internet default route (wildcard) to the internal
- * tables and advertise it. This route is not added to the kernel routes,
- * but this entry prevents us from listening to other people's defaults
- * and installing them in the kernel here.
- */
-rtdefault()
-{
- extern struct sockaddr inet_default;
-
- rtadd(&inet_default, &inet_default, 1,
- RTS_CHANGED | RTS_PASSIVE | RTS_INTERNAL);
-}
-
-rtinit()
-{
- register struct rthash *rh;
-
- for (rh = nethash; rh < &nethash[ROUTEHASHSIZ]; rh++)
- rh->rt_forw = rh->rt_back = (struct rt_entry *)rh;
- for (rh = hosthash; rh < &hosthash[ROUTEHASHSIZ]; rh++)
- 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;
-{
- 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;
-}
-
-/*
- * 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;
-}
diff --git a/sbin/routed/timer.c b/sbin/routed/timer.c
deleted file mode 100644
index fd0851d20ad9..000000000000
--- a/sbin/routed/timer.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (c) 1983, 1988 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)timer.c 5.10 (Berkeley) 2/28/91";
-#endif /* not lint */
-
-/*
- * Routing Table Management Daemon
- */
-#include "defs.h"
-
-int faketime;
-
-/*
- * Timer routine. Performs routing information supply
- * duties and manages timers on routing table entries.
- * Management of the RTS_CHANGED bit assumes that we broadcast
- * each time called.
- */
-void
-timer()
-{
- register struct rthash *rh;
- register struct rt_entry *rt;
- struct rthash *base = hosthash;
- int doinghost = 1, timetobroadcast;
- extern int externalinterfaces;
-
- (void) gettimeofday(&now, (struct timezone *)NULL);
- faketime += TIMER_RATE;
- if (lookforinterfaces && (faketime % CHECK_INTERVAL) == 0)
- ifinit();
- timetobroadcast = supplier && (faketime % SUPPLY_INTERVAL) == 0;
-again:
- for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
- rt = rh->rt_forw;
- for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
- /*
- * We don't advance time on a routing entry for
- * a passive gateway, or any interface if we're
- * not acting as supplier.
- */
- if (!(rt->rt_state & RTS_PASSIVE) &&
- (supplier || !(rt->rt_state & RTS_INTERFACE)))
- rt->rt_timer += TIMER_RATE;
- if (rt->rt_timer >= GARBAGE_TIME) {
- rt = rt->rt_back;
- rtdelete(rt->rt_forw);
- continue;
- }
- if (rt->rt_timer >= EXPIRE_TIME &&
- rt->rt_metric < HOPCNT_INFINITY)
- rtchange(rt, &rt->rt_router, HOPCNT_INFINITY);
- rt->rt_state &= ~RTS_CHANGED;
- }
- }
- if (doinghost) {
- doinghost = 0;
- base = nethash;
- goto again;
- }
- if (timetobroadcast) {
- toall(supply, 0, (struct interface *)NULL);
- lastbcast = now;
- lastfullupdate = now;
- needupdate = 0; /* cancel any pending dynamic update */
- nextbcast.tv_sec = 0;
- }
-}
-
-/*
- * On hangup, let everyone know we're going away.
- */
-hup()
-{
- register struct rthash *rh;
- register struct rt_entry *rt;
- struct rthash *base = hosthash;
- int doinghost = 1;
-
- if (supplier) {
-again:
- for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
- rt = rh->rt_forw;
- for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw)
- rt->rt_metric = HOPCNT_INFINITY;
- }
- if (doinghost) {
- doinghost = 0;
- base = nethash;
- goto again;
- }
- toall(supply, 0, (struct interface *)NULL);
- }
- exit(1);
-}
diff --git a/sbin/routed/trace.c b/sbin/routed/trace.c
deleted file mode 100644
index 6e0b478bc55d..000000000000
--- a/sbin/routed/trace.c
+++ /dev/null
@@ -1,426 +0,0 @@
-/*
- * Copyright (c) 1983, 1988 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)trace.c 5.11 (Berkeley) 2/28/91";
-#endif /* not lint */
-
-/*
- * Routing Table Management Daemon
- */
-#define RIPCMDS
-#include "defs.h"
-#include <sys/stat.h>
-#include <sys/signal.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include "pathnames.h"
-
-#define NRECORDS 50 /* size of circular trace buffer */
-#ifdef DEBUG
-FILE *ftrace = stdout;
-int traceactions = 0;
-#endif
-static struct timeval lastlog;
-static char *savetracename;
-
-traceinit(ifp)
- register struct interface *ifp;
-{
- static int iftraceinit();
-
- if (iftraceinit(ifp, &ifp->int_input) &&
- iftraceinit(ifp, &ifp->int_output))
- return;
- tracehistory = 0;
- fprintf(stderr, "traceinit: can't init %s\n", ifp->int_name);
-}
-
-static
-iftraceinit(ifp, ifd)
- struct interface *ifp;
- register struct ifdebug *ifd;
-{
- register struct iftrace *t;
-
- ifd->ifd_records =
- (struct iftrace *)malloc(NRECORDS * sizeof (struct iftrace));
- if (ifd->ifd_records == 0)
- return (0);
- ifd->ifd_front = ifd->ifd_records;
- ifd->ifd_count = 0;
- for (t = ifd->ifd_records; t < ifd->ifd_records + NRECORDS; t++) {
- t->ift_size = 0;
- t->ift_packet = 0;
- }
- ifd->ifd_if = ifp;
- return (1);
-}
-
-traceon(file)
- char *file;
-{
- struct stat stbuf;
-
- if (ftrace != NULL)
- return;
- if (stat(file, &stbuf) >= 0 && (stbuf.st_mode & S_IFMT) != S_IFREG)
- return;
- savetracename = file;
- (void) gettimeofday(&now, (struct timezone *)NULL);
- ftrace = fopen(file, "a");
- if (ftrace == NULL)
- return;
- dup2(fileno(ftrace), 1);
- dup2(fileno(ftrace), 2);
- traceactions = 1;
- fprintf(ftrace, "Tracing enabled %s\n", ctime((time_t *)&now.tv_sec));
-}
-
-traceoff()
-{
- if (!traceactions)
- return;
- if (ftrace != NULL) {
- int fd = open(_PATH_DEVNULL, O_RDWR);
-
- fprintf(ftrace, "Tracing disabled %s\n",
- ctime((time_t *)&now.tv_sec));
- fflush(ftrace);
- (void) dup2(fd, 1);
- (void) dup2(fd, 2);
- (void) close(fd);
- fclose(ftrace);
- ftrace = NULL;
- }
- traceactions = 0;
- tracehistory = 0;
- tracepackets = 0;
- tracecontents = 0;
-}
-
-void
-sigtrace(s)
- int s;
-{
-
- if (s == SIGUSR2)
- traceoff();
- else if (ftrace == NULL && savetracename)
- traceon(savetracename);
- else
- bumploglevel();
-}
-
-/*
- * Move to next higher level of tracing when -t option processed or
- * SIGUSR1 is received. Successive levels are:
- * traceactions
- * traceactions + tracepackets
- * traceactions + tracehistory (packets and contents after change)
- * traceactions + tracepackets + tracecontents
- */
-bumploglevel()
-{
-
- (void) gettimeofday(&now, (struct timezone *)NULL);
- if (traceactions == 0) {
- traceactions++;
- if (ftrace)
- fprintf(ftrace, "Tracing actions started %s\n",
- ctime((time_t *)&now.tv_sec));
- } else if (tracepackets == 0) {
- tracepackets++;
- tracehistory = 0;
- tracecontents = 0;
- if (ftrace)
- fprintf(ftrace, "Tracing packets started %s\n",
- ctime((time_t *)&now.tv_sec));
- } else if (tracehistory == 0) {
- tracehistory++;
- if (ftrace)
- fprintf(ftrace, "Tracing history started %s\n",
- ctime((time_t *)&now.tv_sec));
- } else {
- tracepackets++;
- tracecontents++;
- tracehistory = 0;
- if (ftrace)
- fprintf(ftrace, "Tracing packet contents started %s\n",
- ctime((time_t *)&now.tv_sec));
- }
- if (ftrace)
- fflush(ftrace);
-}
-
-trace(ifd, who, p, len, m)
- register struct ifdebug *ifd;
- struct sockaddr *who;
- char *p;
- int len, m;
-{
- register struct iftrace *t;
-
- if (ifd->ifd_records == 0)
- return;
- t = ifd->ifd_front++;
- if (ifd->ifd_front >= ifd->ifd_records + NRECORDS)
- ifd->ifd_front = ifd->ifd_records;
- if (ifd->ifd_count < NRECORDS)
- ifd->ifd_count++;
- if (t->ift_size > 0 && t->ift_size < len && t->ift_packet) {
- free(t->ift_packet);
- t->ift_packet = 0;
- }
- t->ift_stamp = now;
- t->ift_who = *who;
- if (len > 0 && t->ift_packet == 0) {
- t->ift_packet = malloc(len);
- if (t->ift_packet == 0)
- len = 0;
- }
- if (len > 0)
- bcopy(p, t->ift_packet, len);
- t->ift_size = len;
- t->ift_metric = m;
-}
-
-traceaction(fd, action, rt)
- FILE *fd;
- char *action;
- struct rt_entry *rt;
-{
- struct sockaddr_in *dst, *gate;
- static struct bits {
- int t_bits;
- char *t_name;
- } flagbits[] = {
- { RTF_UP, "UP" },
- { RTF_GATEWAY, "GATEWAY" },
- { RTF_HOST, "HOST" },
- { 0 }
- }, statebits[] = {
- { RTS_PASSIVE, "PASSIVE" },
- { RTS_REMOTE, "REMOTE" },
- { RTS_INTERFACE,"INTERFACE" },
- { RTS_CHANGED, "CHANGED" },
- { RTS_INTERNAL, "INTERNAL" },
- { RTS_EXTERNAL, "EXTERNAL" },
- { RTS_SUBNET, "SUBNET" },
- { 0 }
- };
- register struct bits *p;
- register int first;
- char *cp;
- struct interface *ifp;
-
- if (fd == NULL)
- return;
- if (lastlog.tv_sec != now.tv_sec || lastlog.tv_usec != now.tv_usec) {
- fprintf(fd, "\n%.19s:\n", ctime((time_t *)&now.tv_sec));
- lastlog = now;
- }
- fprintf(fd, "%s ", action);
- dst = (struct sockaddr_in *)&rt->rt_dst;
- gate = (struct sockaddr_in *)&rt->rt_router;
- fprintf(fd, "dst %s, ", inet_ntoa(dst->sin_addr));
- fprintf(fd, "router %s, metric %d, flags",
- inet_ntoa(gate->sin_addr), rt->rt_metric);
- cp = " %s";
- for (first = 1, p = flagbits; p->t_bits > 0; p++) {
- if ((rt->rt_flags & p->t_bits) == 0)
- continue;
- fprintf(fd, cp, p->t_name);
- if (first) {
- cp = "|%s";
- first = 0;
- }
- }
- fprintf(fd, " state");
- cp = " %s";
- for (first = 1, p = statebits; p->t_bits > 0; p++) {
- if ((rt->rt_state & p->t_bits) == 0)
- continue;
- fprintf(fd, cp, p->t_name);
- if (first) {
- cp = "|%s";
- first = 0;
- }
- }
- fprintf(fd, " timer %d\n", rt->rt_timer);
- if (tracehistory && !tracepackets &&
- (rt->rt_state & RTS_PASSIVE) == 0 && rt->rt_ifp)
- dumpif(fd, rt->rt_ifp);
- fflush(fd);
- if (ferror(fd))
- traceoff();
-}
-
-tracenewmetric(fd, rt, newmetric)
- FILE *fd;
- struct rt_entry *rt;
- int newmetric;
-{
- struct sockaddr_in *dst, *gate;
-
- if (fd == NULL)
- return;
- if (lastlog.tv_sec != now.tv_sec || lastlog.tv_usec != now.tv_usec) {
- fprintf(fd, "\n%.19s:\n", ctime((time_t *)&now.tv_sec));
- lastlog = now;
- }
- dst = (struct sockaddr_in *)&rt->rt_dst;
- gate = (struct sockaddr_in *)&rt->rt_router;
- fprintf(fd, "CHANGE metric dst %s, ", inet_ntoa(dst->sin_addr));
- fprintf(fd, "router %s, from %d to %d\n",
- inet_ntoa(gate->sin_addr), rt->rt_metric, newmetric);
- fflush(fd);
- if (ferror(fd))
- traceoff();
-}
-
-dumpif(fd, ifp)
- FILE *fd;
- register struct interface *ifp;
-{
- if (ifp->int_input.ifd_count || ifp->int_output.ifd_count) {
- fprintf(fd, "*** Packet history for interface %s ***\n",
- ifp->int_name);
-#ifdef notneeded
- dumptrace(fd, "to", &ifp->int_output);
-#endif
- dumptrace(fd, "from", &ifp->int_input);
- fprintf(fd, "*** end packet history ***\n");
- }
-}
-
-dumptrace(fd, dir, ifd)
- FILE *fd;
- char *dir;
- register struct ifdebug *ifd;
-{
- register struct iftrace *t;
- char *cp = !strcmp(dir, "to") ? "Output" : "Input";
-
- if (ifd->ifd_front == ifd->ifd_records &&
- ifd->ifd_front->ift_size == 0) {
- fprintf(fd, "%s: no packets.\n", cp);
- fflush(fd);
- return;
- }
- fprintf(fd, "%s trace:\n", cp);
- t = ifd->ifd_front - ifd->ifd_count;
- if (t < ifd->ifd_records)
- t += NRECORDS;
- for ( ; ifd->ifd_count; ifd->ifd_count--, t++) {
- if (t >= ifd->ifd_records + NRECORDS)
- t = ifd->ifd_records;
- if (t->ift_size == 0)
- continue;
- dumppacket(fd, dir, &t->ift_who, t->ift_packet, t->ift_size,
- &t->ift_stamp);
- }
-}
-
-dumppacket(fd, dir, who, cp, size, stamp)
- FILE *fd;
- struct sockaddr_in *who; /* should be sockaddr */
- char *dir, *cp;
- register int size;
- struct timeval *stamp;
-{
- register struct rip *msg = (struct rip *)cp;
- register struct netinfo *n;
-
- if (fd == NULL)
- return;
- if (msg->rip_cmd && msg->rip_cmd < RIPCMD_MAX)
- fprintf(fd, "%s %s %s.%d %.19s:\n", ripcmds[msg->rip_cmd],
- dir, inet_ntoa(who->sin_addr), ntohs(who->sin_port),
- ctime((time_t *)&stamp->tv_sec));
- else {
- fprintf(fd, "Bad cmd 0x%x %s %x.%d %.19s\n", msg->rip_cmd,
- dir, inet_ntoa(who->sin_addr), ntohs(who->sin_port));
- fprintf(fd, "size=%d cp=%x packet=%x\n", size, cp, packet,
- ctime((time_t *)&stamp->tv_sec));
- fflush(fd);
- return;
- }
- if (tracepackets && tracecontents == 0) {
- fflush(fd);
- return;
- }
- switch (msg->rip_cmd) {
-
- case RIPCMD_REQUEST:
- case RIPCMD_RESPONSE:
- size -= 4 * sizeof (char);
- n = msg->rip_nets;
- for (; size > 0; n++, size -= sizeof (struct netinfo)) {
- if (size < sizeof (struct netinfo)) {
- fprintf(fd, "(truncated record, len %d)\n",
- size);
- break;
- }
- if (sizeof(n->rip_dst.sa_family) > 1)
- n->rip_dst.sa_family = ntohs(n->rip_dst.sa_family);
-
- switch ((int)n->rip_dst.sa_family) {
-
- case AF_INET:
- fprintf(fd, "\tdst %s metric %d\n",
-#define satosin(sa) ((struct sockaddr_in *)&sa)
- inet_ntoa(satosin(n->rip_dst)->sin_addr),
- ntohl(n->rip_metric));
- break;
-
- default:
- fprintf(fd, "\taf %d? metric %d\n",
- n->rip_dst.sa_family,
- ntohl(n->rip_metric));
- break;
- }
- }
- break;
-
- case RIPCMD_TRACEON:
- fprintf(fd, "\tfile=%*s\n", size, msg->rip_tracefile);
- break;
-
- case RIPCMD_TRACEOFF:
- break;
- }
- fflush(fd);
- if (ferror(fd))
- traceoff();
-}
diff --git a/sbin/routed/trace.h b/sbin/routed/trace.h
deleted file mode 100644
index 741de720ce20..000000000000
--- a/sbin/routed/trace.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (c) 1983, 1988 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
- * must display the following acknowledgement:
- * 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.
- *
- * @(#)trace.h 5.8 (Berkeley) 6/1/90
- */
-
-/*
- * Routing table management daemon.
- */
-
-/*
- * Trace record format.
- */
-struct iftrace {
- struct timeval ift_stamp; /* time stamp */
- struct sockaddr ift_who; /* from/to */
- char *ift_packet; /* pointer to packet */
- short ift_size; /* size of packet */
- short ift_metric; /* metric on associated metric */
-};
-
-/*
- * Per interface packet tracing buffers. An incoming and
- * outgoing circular buffer of packets is maintained, per
- * interface, for debugging. Buffers are dumped whenever
- * an interface is marked down.
- */
-struct ifdebug {
- struct iftrace *ifd_records; /* array of trace records */
- struct iftrace *ifd_front; /* next empty trace record */
- int ifd_count; /* number of unprinted records */
- struct interface *ifd_if; /* for locating stuff */
-};
-
-/*
- * Packet tracing stuff.
- */
-int tracepackets; /* watch packets as they go by */
-int tracecontents; /* watch packet contents as they go by */
-int traceactions; /* on/off */
-int tracehistory; /* on/off */
-FILE *ftrace; /* output trace file */
-
-#define TRACE_ACTION(action, route) { \
- if (traceactions) \
- traceaction(ftrace, action, route); \
- }
-#define TRACE_NEWMETRIC(route, newmetric) { \
- if (traceactions) \
- tracenewmetric(ftrace, route, newmetric); \
- }
-#define TRACE_INPUT(ifp, src, pack, size) { \
- if (tracehistory) { \
- ifp = if_iflookup(src); \
- if (ifp) \
- trace(&ifp->int_input, src, pack, size, \
- ntohl(ifp->int_metric)); \
- } \
- if (tracepackets) \
- dumppacket(ftrace, "from", src, pack, size, &now); \
- }
-#define TRACE_OUTPUT(ifp, dst, size) { \
- if (tracehistory && ifp) \
- trace(&ifp->int_output, dst, packet, size, ifp->int_metric); \
- if (tracepackets) \
- dumppacket(ftrace, "to", dst, packet, size, &now); \
- }
diff --git a/sbin/routed/trace/Makefile b/sbin/routed/trace/Makefile
deleted file mode 100644
index 85e405af1d50..000000000000
--- a/sbin/routed/trace/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# @(#)Makefile 5.1 (Berkeley) 5/11/90
-
-PROG= trace
-NOMAN= noman
-
-.include "../../Makefile.inc"
-.include <bsd.prog.mk>
diff --git a/sbin/routed/trace/trace.c b/sbin/routed/trace/trace.c
deleted file mode 100644
index 64d928db8f20..000000000000
--- a/sbin/routed/trace/trace.c
+++ /dev/null
@@ -1,125 +0,0 @@
-/*-
- * Copyright (c) 1983, 1988 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
- * must display the following acknowledgement:
- * 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.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1983, 1988 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)trace.c 5.9 (Berkeley) 4/16/91";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/protosw.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <protocols/routed.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-struct sockaddr_in myaddr;
-char packet[MAXPACKETSIZE];
-
-main(argc, argv)
- int argc;
- char **argv;
-{
- int size, s;
- struct sockaddr from;
- struct sockaddr_in router;
- register struct rip *msg = (struct rip *)packet;
- struct hostent *hp;
- struct servent *sp;
-
- if (argc < 3) {
-usage:
- printf("usage: trace cmd machines,\n");
- printf("cmd either \"on filename\", or \"off\"\n");
- exit(1);
- }
- s = socket(AF_INET, SOCK_DGRAM, 0);
- if (s < 0) {
- perror("socket");
- exit(2);
- }
- myaddr.sin_family = AF_INET;
- myaddr.sin_port = htons(IPPORT_RESERVED-1);
- if (bind(s, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) {
- perror("bind");
- exit(2);
- }
-
- argv++, argc--;
- msg->rip_cmd = strcmp(*argv, "on") == 0 ?
- RIPCMD_TRACEON : RIPCMD_TRACEOFF;
- msg->rip_vers = RIPVERSION;
- argv++, argc--;
- size = sizeof (int);
- if (msg->rip_cmd == RIPCMD_TRACEON) {
- strcpy(msg->rip_tracefile, *argv);
- size += strlen(*argv);
- argv++, argc--;
- }
- if (argc == 0)
- goto usage;
- bzero((char *)&router, sizeof (router));
- router.sin_family = AF_INET;
- sp = getservbyname("router", "udp");
- if (sp == 0) {
- printf("udp/router: service unknown\n");
- exit(1);
- }
- router.sin_port = sp->s_port;
- while (argc > 0) {
- router.sin_family = AF_INET;
- router.sin_addr.s_addr = inet_addr(*argv);
- if (router.sin_addr.s_addr == -1) {
- hp = gethostbyname(*argv);
- if (hp == NULL) {
- fprintf(stderr, "trace: %s: ", *argv);
- herror((char *)NULL);
- continue;
- }
- bcopy(hp->h_addr, &router.sin_addr, hp->h_length);
- }
- if (sendto(s, packet, size, 0,
- (struct sockaddr *)&router, sizeof(router)) < 0)
- perror(*argv);
- argv++, argc--;
- }
-}
diff --git a/sbin/slattach/slattach.c b/sbin/slattach/slattach.c
index 66b8e1577075..8d429f06ef3a 100644
--- a/sbin/slattach/slattach.c
+++ b/sbin/slattach/slattach.c
@@ -145,6 +145,7 @@ int exiting = 0; /* allready running exit_handler */
FILE *console;
struct termios tty;
+struct termios tty_orig; /* For saving original tty state */
char devname[32];
char hostname[MAXHOSTNAMELEN];
@@ -268,6 +269,12 @@ int main(int argc, char **argv)
/* upon HUP redial and reconnect. */
if ((int)signal(SIGHUP,sighup_handler) < 0)
syslog(LOG_NOTICE,"cannot install SIGHUP handler: %s: %m");
+ /* Keep track of our original terminal values for redialing */
+ if (tcgetattr(fd, &tty_orig) < 0) {
+ syslog(LOG_ERR, "tcgetattr: %m");
+ exit_handler(1);
+ }
+
setup_line();
@@ -362,8 +369,8 @@ again:
syslog(LOG_NOTICE,"SIGHUP on %s (sl%d); running %s",
dev,unit,redial_cmd);
if (!(modem_control & CLOCAL)) {
- tty.c_cflag |= CLOCAL;
- if (tcsetattr(fd, TCSAFLUSH, &tty) < 0) {
+ tty_orig.c_cflag |= CLOCAL;
+ if (tcsetattr(fd, TCSAFLUSH, &tty_orig) < 0) {
syslog(LOG_ERR, "tcsetattr(TCSAFLUSH): %m");
exit_handler(1);
}