SCCS-vsn: sbin/routed/routed.c 4.6
SCCS-vsn: sbin/routed/defs.h 4.2
-/* defs.h 4.1 82/05/22 */
+/* defs.h 4.2 82/05/25 */
/*
* Internal data structure definitions for
/*
* Internal data structure definitions for
* protocol specs with mods relevant to more
* general addressing scheme.
*/
* protocol specs with mods relevant to more
* general addressing scheme.
*/
/*
* Internal routing table structure.
* Differs a bit from kernel tables.
*/
/*
* Internal routing table structure.
* Differs a bit from kernel tables.
*/
struct rt_entry *rt_forw;
struct rt_entry *rt_back;
};
struct rt_entry *rt_forw;
struct rt_entry *rt_back;
};
struct rt_entry {
struct rt_entry *rt_forw;
struct rt_entry *rt_back;
struct rt_entry {
struct rt_entry *rt_forw;
struct rt_entry *rt_back;
- u_long rt_hash; /* for net or for host */
- struct sockaddr rt_dst; /* match value */
- struct sockaddr rt_gateway; /* who to forward to */
- short rt_flags; /* see below */
- short rt_retry; /* # ioctl retries */
- int rt_timer; /* for invalidation */
- int rt_metric; /* hop count of route */
- struct ifnet *rt_ifp; /* corresponding interface */
+ union {
+ struct rtentry rtu_rt;
+ struct {
+ u_long rtu_hash;
+ struct sockaddr rtu_dst;
+ struct sockaddr rtu_gateway;
+ short rtu_flags;
+ short rtu_retry;
+ int rtu_timer;
+ int rtu_metric;
+ struct ifnet *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_gateway rt_rtu.rtu_entry.rtu_gateway /* who to forward to */
+#define rt_flags rt_rtu.rtu_entry.rtu_flags /* see below */
+#define rt_retry rt_rtu.rtu_entry.rtu_retry /* retries of ioctl */
+#define rt_timer rt_rtu.rtu_entry.rtu_timer /* for invalidation */
+#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 19
/*
#define ROUTEHASHSIZ 19
/*
#define RTF_ADDRT 0x20 /* add command pending */
#define RTF_SILENT 0x40 /* don't send to router */
#define RTF_ADDRT 0x20 /* add command pending */
#define RTF_SILENT 0x40 /* don't send to router */
-struct rt_hash nethash[ROUTEHASHSIZ], hosthash[ROUTEHASHSIZ];
+struct rthash nethash[ROUTEHASHSIZ], hosthash[ROUTEHASHSIZ];
struct rt_entry *rtlookup();
/*
struct rt_entry *rtlookup();
/*
-static char sccsid[] = "@(#)routed.c 4.5 %G%";
+static char sccsid[] = "@(#)routed.c 4.6 %G%";
-#include <sys/param.h>
-#include <sys/protosw.h>
+/*
+ * Routing Table Management Daemon
+ */
+#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/in.h>
-#define KERNEL
-#include <net/route.h>
#include <net/if.h>
#include <errno.h>
#include <stdio.h>
#include <net/if.h>
#include <errno.h>
#include <stdio.h>
char packet[MAXPACKETSIZE];
char packet[MAXPACKETSIZE];
+struct in_addr if_makeaddr();
+struct ifnet *if_ifwithaddr(), *if_ifwithnet();
extern char *malloc();
extern int errno, exit();
extern char *malloc();
extern int errno, exit();
- register struct rt_hash *rh;
+ register struct rthash *rh;
register struct rt_entry *rt;
register struct rt_entry *rt;
- struct rt_hash *base = hosthash;
+ struct rthash *base = hosthash;
int doinghost = 1;
if (trace)
int doinghost = 1;
if (trace)
if (rt->rt_timer >= EXPIRE_TIME)
rt->rt_metric = HOPCNT_INFINITY;
if (rt->rt_flags & RTF_CHGRT)
if (rt->rt_timer >= EXPIRE_TIME)
rt->rt_metric = HOPCNT_INFINITY;
if (rt->rt_flags & RTF_CHGRT)
- if (!ioctl(s, SIOCCHGRT,(char *)&rt->rt_hash) ||
+ if (!ioctl(s, SIOCCHGRT,(char *)&rt->rt_rt) ||
--rt->rt_retry == 0)
rt->rt_flags &= ~RTF_CHGRT;
--rt->rt_retry == 0)
rt->rt_flags &= ~RTF_CHGRT;
* in use), retry the operation a few more times.
*/
if (rt->rt_flags & RTF_ADDRT) {
* in use), retry the operation a few more times.
*/
if (rt->rt_flags & RTF_ADDRT) {
- if (!ioctl(s, SIOCADDRT,(char *)&rt->rt_hash)) {
+ if (!ioctl(s, SIOCADDRT,(char *)&rt->rt_rt)) {
if (errno == EEXIST) {
rt->rt_flags &= ~RTF_ADDRT;
rt->rt_flags |= RTF_CHGRT;
if (errno == EEXIST) {
rt->rt_flags &= ~RTF_ADDRT;
rt->rt_flags |= RTF_CHGRT;
/*
* Find the network interfaces attached to this machine.
* The info is used to:
/*
* Find the network interfaces attached to this machine.
* The info is used to:
* (4) figure out if we're an internetwork gateway.
*
* We don't handle anything but Internet addresses.
* (4) figure out if we're an internetwork gateway.
*
* We don't handle anything but Internet addresses.
+ *
+ * Note: this routine may be called periodically to
+ * scan for new interfaces. In fact, the timer routine
+ * does so based on the flag lookforinterfaces. The
+ * flag performnlist is set whenever something odd occurs
+ * while scanning the kernel; this is likely to occur
+ * if /vmunix isn't up to date (e.g. someone booted /ovmunix).
+/*
+ * Send "packet" to all neighbors.
+ */
- register struct rt_hash *rh;
+ register struct rthash *rh;
register struct rt_entry *rt;
register struct sockaddr *dst;
register struct rt_entry *rt;
register struct sockaddr *dst;
- struct rt_hash *base = hosthash;
+ struct rthash *base = hosthash;
int doinghost = 1;
again:
int doinghost = 1;
again:
supplyall()
{
register struct rt_entry *rt;
supplyall()
{
register struct rt_entry *rt;
- register struct rt_hash *rh;
+ register struct rthash *rh;
register struct sockaddr *dst;
register struct sockaddr *dst;
- struct rt_hash *base = hosthash;
+ struct rthash *base = hosthash;
int doinghost = 1;
again:
int doinghost = 1;
again:
{
struct rip *msg = (struct rip *)packet;
struct netinfo *n = msg->rip_nets;
{
struct rip *msg = (struct rip *)packet;
struct netinfo *n = msg->rip_nets;
- register struct rt_hash *rh;
+ register struct rthash *rh;
register struct rt_entry *rt;
register struct rt_entry *rt;
- struct rt_hash *base = hosthash;
+ struct rthash *base = hosthash;
int doinghost = 1, size;
int (*output)() = afswitch[sa->sa_family].af_output;
int doinghost = 1, size;
int (*output)() = afswitch[sa->sa_family].af_output;
*/
(*afswitch[from->sa_family].af_canon)(from);
if (trace)
*/
(*afswitch[from->sa_family].af_canon)(from);
if (trace)
- printf("input from %x\n", from->sin_addr);
+ printf("input from %x\n",
+ ((struct sockaddr_in *)from)->sin_addr);
/*
* If response packet is from ourselves, use it only
* to reset timer on entry. Otherwise, we'd believe
/*
* If response packet is from ourselves, use it only
* to reset timer on entry. Otherwise, we'd believe
if (size < sizeof (struct netinfo))
break;
if (trace)
if (size < sizeof (struct netinfo))
break;
if (trace)
- printf("dst %x hc %d...", n->rip_dst.sin_addr,
+ printf("dst %x hc %d...",
+ ((struct sockaddr_in *)&n->rip_dst)->sin_addr,
n->rip_metric);
rt = rtlookup(&n->rip_dst);
n->rip_metric);
rt = rtlookup(&n->rip_dst);
if (trace)
printf("ours: gate %x hc %d timer %d\n",
if (trace)
printf("ours: gate %x hc %d timer %d\n",
- rt->rt_gateway.sin_addr,
- rt->rt_metric, rt->rt_timer);
+ ((struct sockaddr_in *)&rt->rt_gateway)->sin_addr,
+ rt->rt_metric, rt->rt_timer);
/*
* Update the entry if one of the following is true:
*
/*
* Update the entry if one of the following is true:
*
+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;
+}
+
/*
* Lookup an entry to the appropriate dstination.
*/
/*
* Lookup an entry to the appropriate dstination.
*/
struct sockaddr *dst;
{
register struct rt_entry *rt;
struct sockaddr *dst;
{
register struct rt_entry *rt;
- register struct rt_hash *rh;
+ register struct rthash *rh;
register int hash, (*match)();
struct afhash h;
int af = dst->sa_family, doinghost = 1;
register int hash, (*match)();
struct afhash h;
int af = dst->sa_family, doinghost = 1;
-rtinit()
-{
- register struct rt_hash *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;
-}
-
{
struct afhash h;
register struct rt_entry *rt;
{
struct afhash h;
register struct rt_entry *rt;
int af = dst->sa_family, flags, hash;
if (af >= AF_MAX)
int af = dst->sa_family, flags, hash;
if (af >= AF_MAX)
{
log("delete", rt);
if (install)
{
log("delete", rt);
if (install)
- if (ioctl(s, SIOCDELRT, (char *)&rt->rt_hash) &&
+ if (ioctl(s, SIOCDELRT, (char *)&rt->rt_rt) &&
errno == EBUSY)
rt->rt_flags |= RTF_DELRT;
remque(rt);
errno == EBUSY)
rt->rt_flags |= RTF_DELRT;
remque(rt);
+/*
+ * Find the interface with address "addr".
+ */
struct ifnet *
if_ifwithaddr(addr)
struct sockaddr *addr;
struct ifnet *
if_ifwithaddr(addr)
struct sockaddr *addr;
+/*
+ * Find the interface with network imbedded in
+ * the sockaddr "addr". Must use per-af routine
+ * look for match.
+ */
struct ifnet *
if_ifwithnet(addr)
register struct sockaddr *addr;
struct ifnet *
if_ifwithnet(addr)
register struct sockaddr *addr;
+/*
+ * Formulate an Internet address.
+ */
struct in_addr
if_makeaddr(net, host)
int net, host;
struct in_addr
if_makeaddr(net, host)
int net, host;