checkpoint semi-working version with routing socket
authorKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Wed, 14 Dec 1988 05:30:32 +0000 (21:30 -0800)
committerKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Wed, 14 Dec 1988 05:30:32 +0000 (21:30 -0800)
SCCS-vsn: sys/net/route.h 7.5
SCCS-vsn: sys/net/radix.c 7.2
SCCS-vsn: sys/net/radix.h 7.2

usr/src/sys/net/radix.c
usr/src/sys/net/radix.h
usr/src/sys/net/route.h

index 12ea6bb..05f9bb9 100644 (file)
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)radix.c     7.1 (Berkeley) %G%
+ *     @(#)radix.c     7.2 (Berkeley) %G%
  */
 
 /*
  * Routines to build and maintain radix trees for routing lookups.
  */
 #ifndef RNF_NORMAL
  */
 
 /*
  * Routines to build and maintain radix trees for routing lookups.
  */
 #ifndef RNF_NORMAL
-typedef unsigned char u_char;
+#include "param.h"
 #include "radix.h"
 #endif
 struct radix_node_head *radix_node_head;
 #include "radix.h"
 #endif
 struct radix_node_head *radix_node_head;
@@ -60,7 +60,7 @@ struct radix_mask *rn_mkfreelist;
 struct radix_node *
 rn_search(v, head)
        struct radix_node *head;
 struct radix_node *
 rn_search(v, head)
        struct radix_node *head;
-       register char *v;
+       register caddr_t v;
 {
        register struct radix_node *x;
 
 {
        register struct radix_node *x;
 
@@ -80,13 +80,13 @@ static char maskedKey[MAXKEYLEN];
 struct radix_node *
 rn_match(v, head)
        struct radix_node *head;
 struct radix_node *
 rn_match(v, head)
        struct radix_node *head;
-       char *v;
+       caddr_t v;
 {
        register struct radix_node *t = head, *x;
 {
        register struct radix_node *t = head, *x;
-       register char *cp = v, *cp2, *cp3;
-       char *cplim, *mstart;
+       register caddr_t cp = v, cp2, cp3;
+       caddr_t cplim, mstart;
        struct radix_node *saved_t;
        struct radix_node *saved_t;
-       int off = t->rn_off, vlen = *(u_char *)cp, head_off, matched_off;
+       int off = t->rn_off, vlen = *(u_char *)cp, matched_off;
 
        /*
         * Open code rn_search(v, head) to avoid overhead of extra
 
        /*
         * Open code rn_search(v, head) to avoid overhead of extra
@@ -158,7 +158,7 @@ int rn_saveinfo;
 
 struct radix_node *
 rn_newpair(v, b, nodes)
 
 struct radix_node *
 rn_newpair(v, b, nodes)
-       char *v;
+       caddr_t v;
        struct radix_node nodes[2];
 {
        register struct radix_node *tt = nodes, *t = tt + 1;
        struct radix_node nodes[2];
 {
        register struct radix_node *tt = nodes, *t = tt + 1;
@@ -176,23 +176,23 @@ rn_newpair(v, b, nodes)
 int rn_debug =  1;
 struct radix_node *
 rn_insert(v, head, dupentry, nodes)
 int rn_debug =  1;
 struct radix_node *
 rn_insert(v, head, dupentry, nodes)
-       char *v;
+       caddr_t v;
        struct radix_node *head;
        int *dupentry;
        struct radix_node nodes[2];
 {
        int head_off = head->rn_off, vlen = (int)*((u_char *)v);
        register struct radix_node *t = rn_search(v, head);
        struct radix_node *head;
        int *dupentry;
        struct radix_node nodes[2];
 {
        int head_off = head->rn_off, vlen = (int)*((u_char *)v);
        register struct radix_node *t = rn_search(v, head);
-       register char *cp = v + head_off;
+       register caddr_t cp = v + head_off;
        register int b;
        struct radix_node *tt;
        /*
         *find first bit at which v and t->rn_key differ
         */
     {
        register int b;
        struct radix_node *tt;
        /*
         *find first bit at which v and t->rn_key differ
         */
     {
-       register char *cp2 = t->rn_key + head_off;
+       register caddr_t cp2 = t->rn_key + head_off;
        register int cmp_res;
        register int cmp_res;
-       char *cplim = v + vlen;
+       caddr_t cplim = v + vlen;
 
        while (cp < cplim)
                if (*cp2++ != *cp++)
 
        while (cp < cplim)
                if (*cp2++ != *cp++)
@@ -240,15 +240,15 @@ on1:
 struct radix_node *
 rn_addroute(v, netmask, head, treenodes)
        struct radix_node *head;
 struct radix_node *
 rn_addroute(v, netmask, head, treenodes)
        struct radix_node *head;
-       char *netmask, *v;
+       caddr_t netmask, v;
        struct radix_node treenodes[2];
 {
        register int j;
        struct radix_node treenodes[2];
 {
        register int j;
-       register char *cp;
+       register caddr_t cp;
        register struct radix_node *t, *x, *tt;
        short b = 0, b_leaf;
        int vlen = *(u_char *)v, maskduplicated = 0, mlen, keyduplicated;
        register struct radix_node *t, *x, *tt;
        short b = 0, b_leaf;
        int vlen = *(u_char *)v, maskduplicated = 0, mlen, keyduplicated;
-       char *cplim; unsigned char *maskp;
+       caddr_t cplim; unsigned char *maskp;
        struct radix_mask *m, **mp;
        struct radix_node *saved_tt;
 
        struct radix_mask *m, **mp;
        struct radix_node *saved_tt;
 
@@ -305,11 +305,11 @@ rn_addroute(v, netmask, head, treenodes)
        if (netmask == 0)
                goto on1;
        if (maskduplicated == 0) {
        if (netmask == 0)
                goto on1;
        if (maskduplicated == 0) {
-               Malloc(x, struct radix_node *, MAXKEYLEN + 2 * sizeof (*x));
+               R_Malloc(x, struct radix_node *, MAXKEYLEN + 2 * sizeof (*x));
                if (x == 0)
                        return (0);
                Bzero(x, MAXKEYLEN + 2 * sizeof (*x));
                if (x == 0)
                        return (0);
                Bzero(x, MAXKEYLEN + 2 * sizeof (*x));
-               cp = (char *)(x + 2);
+               cp = (caddr_t)(x + 2);
                bcopy(netmask, cp, mlen);
                netmask = cp;
                x = rn_insert(netmask, rn_maskhead, &maskduplicated, x);
                bcopy(netmask, cp, mlen);
                netmask = cp;
                x = rn_insert(netmask, rn_maskhead, &maskduplicated, x);
@@ -407,7 +407,7 @@ on2:
 
 struct radix_node *
 rn_delete(v, netmask, head)
 
 struct radix_node *
 rn_delete(v, netmask, head)
-       char *v, *netmask;
+       caddr_t v, netmask;
        struct radix_node *head;
 {
        register struct radix_node *t, *p, *x = head;
        struct radix_node *head;
 {
        register struct radix_node *t, *p, *x = head;
@@ -531,17 +531,17 @@ rn_inithead(head, off, af)
 struct radix_node_head **head;
 int off;
 {
 struct radix_node_head **head;
 int off;
 {
-       register struct radix_node_head *hp;
+       register struct radix_node_head *rnh;
        register struct radix_node *t, *tt, *ttt;
        if (*head)
                return (1);
        register struct radix_node *t, *tt, *ttt;
        if (*head)
                return (1);
-       Malloc(hp, struct radix_node_head *, sizeof (*hp));
-       if (hp == 0)
+       R_Malloc(rnh, struct radix_node_head *, sizeof (*rnh));
+       if (rnh == 0)
                return (0);
                return (0);
-       Bzero(hp, sizeof (*hp));
-       *head = hp;
-       t = rn_newpair(rn_zeros, off, hp->rnh_nrt.nrt_nodes);
-       ttt = &(hp->rnh_upper);
+       Bzero(rnh, sizeof (*rnh));
+       *head = rnh;
+       t = rn_newpair(rn_zeros, off, rnh->rnh_nodes);
+       ttt = rnh->rnh_nodes + 2;
        t->rn_r = ttt;
        t->rn_p = t;
        tt = t->rn_l;
        t->rn_r = ttt;
        t->rn_p = t;
        tt = t->rn_l;
@@ -549,20 +549,20 @@ int off;
        tt->rn_b = -1 - off;
        *ttt = *tt;
        ttt->rn_key = rn_ones;
        tt->rn_b = -1 - off;
        *ttt = *tt;
        ttt->rn_key = rn_ones;
-       hp->rnh_af = af;
-       hp->rnh_treetop = t;
+       rnh->rnh_af = af;
+       rnh->rnh_treetop = t;
        if (radix_node_head == 0) {
        if (radix_node_head == 0) {
-               char *cp = rn_ones, *cplim = rn_ones + MAXKEYLEN;
+               caddr_t cp = rn_ones, cplim = rn_ones + MAXKEYLEN;
                while (cp < cplim)
                        *cp++ = -1;
                if (rn_inithead(&radix_node_head, 0, 0) == 0) {
                while (cp < cplim)
                        *cp++ = -1;
                if (rn_inithead(&radix_node_head, 0, 0) == 0) {
-                       Free(hp);
+                       Free(rnh);
                        *head = 0;
                        return (0);
                }
        }
                        *head = 0;
                        return (0);
                }
        }
-       hp->rnh_next = radix_node_head->rnh_next;
-       if (radix_node_head != hp)
-               radix_node_head->rnh_next = hp;
+       rnh->rnh_next = radix_node_head->rnh_next;
+       if (radix_node_head != rnh)
+               radix_node_head->rnh_next = rnh;
        return (1);
 }
        return (1);
 }
index ae89976..42a1a2f 100644 (file)
@@ -14,7 +14,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)radix.h     7.1 (Berkeley) %G%
+ *     @(#)radix.h     7.2 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -32,8 +32,8 @@ struct radix_node {
 #define RNF_ACTIVE     4               /* This node is alive (for rtfree) */
        union {
                struct {                        /* leaf only data: */
 #define RNF_ACTIVE     4               /* This node is alive (for rtfree) */
        union {
                struct {                        /* leaf only data: */
-                       char    *rn_Key;        /* object of search */
-                       char    *rn_Mask;       /* netmask, if present */
+                       caddr_t rn_Key; /* object of search */
+                       caddr_t rn_Mask;        /* netmask, if present */
                        struct  radix_node *rn_Dupedkey;
                } rn_leaf;
                struct {                        /* node only data: */
                        struct  radix_node *rn_Dupedkey;
                } rn_leaf;
                struct {                        /* node only data: */
@@ -49,68 +49,56 @@ struct radix_node {
 #endif
 };
 
 #endif
 };
 
+#define MAXKEYLEN 32
+
 #define rn_dupedkey rn_u.rn_leaf.rn_Dupedkey
 #define rn_key rn_u.rn_leaf.rn_Key
 #define rn_mask rn_u.rn_leaf.rn_Mask
 #define rn_off rn_u.rn_node.rn_Off
 #define rn_l rn_u.rn_node.rn_L
 #define rn_r rn_u.rn_node.rn_R
 #define rn_dupedkey rn_u.rn_leaf.rn_Dupedkey
 #define rn_key rn_u.rn_leaf.rn_Key
 #define rn_mask rn_u.rn_leaf.rn_Mask
 #define rn_off rn_u.rn_node.rn_Off
 #define rn_l rn_u.rn_node.rn_L
 #define rn_r rn_u.rn_node.rn_R
+
 /*
  * Annotations to tree concerning potential routes applying to subtrees.
  */
 /*
  * Annotations to tree concerning potential routes applying to subtrees.
  */
-struct radix_mask {
+
+extern struct radix_mask {
        short   rm_b;                   /* bit offset; -1-index(netmask) */
        char    rm_unused;              /* cf. rn_bmask */
        u_char  rm_flags;               /* cf. rn_flags */
        struct  radix_mask *rm_mklist;  /* more masks to try */
        short   rm_b;                   /* bit offset; -1-index(netmask) */
        char    rm_unused;              /* cf. rn_bmask */
        u_char  rm_flags;               /* cf. rn_flags */
        struct  radix_mask *rm_mklist;  /* more masks to try */
-       char    *rm_mask;               /* the mask */
+       caddr_t rm_mask;                /* the mask */
        int     rm_refs;                /* # of references to this struct */
        int     rm_refs;                /* # of references to this struct */
-};
+} *rn_mkfreelist;
+
+#define MKGet(m) {\
+       if (rn_mkfreelist) {\
+               m = rn_mkfreelist; \
+               rn_mkfreelist = (m)->rm_mklist; \
+       } else \
+               R_Malloc(m, struct radix_mask *, sizeof (*(m))); }\
+
+#define MKFree(m) { (m)->rm_mklist = rn_mkfreelist; rn_mkfreelist = (m);}
+
+extern struct radix_node_head {
+       struct  radix_node_head *rnh_next;
+       struct  radix_node *rnh_treetop;
+       int     rnh_af;
+       struct  radix_node rnh_nodes[3];
+} *radix_node_head;
+
 
 #ifndef KERNEL
 char *malloc();
 #define Bcmp(a, b, n) bcmp(((char *)(a)), ((char *)(b)), (n))
 
 #ifndef KERNEL
 char *malloc();
 #define Bcmp(a, b, n) bcmp(((char *)(a)), ((char *)(b)), (n))
-#define Malloc(p, t, n) (p = (t) malloc((unsigned int)(n)))
 #define Bzero(p, n) bzero((char *)(p), (int)(n));
 #define Bzero(p, n) bzero((char *)(p), (int)(n));
+#define R_Malloc(p, t, n) (p = (t) malloc((unsigned int)(n)))
 #define Free(p) free((char *)p);
 #define min(a, b) ((a) < (b) ? (a) : (b))
 #define Free(p) free((char *)p);
 #define min(a, b) ((a) < (b) ? (a) : (b))
-#ifndef RTF_UP
-/*
- * probably just testing here . . .
- */
-struct rtentry {
-       int     rt_unused;
-};
-#endif
 #else
 #define Bcmp(a, b, n) bcmp(((caddr_t)(a)), ((caddr_t)(b)), (n))
 #else
 #define Bcmp(a, b, n) bcmp(((caddr_t)(a)), ((caddr_t)(b)), (n))
-#define Malloc(p, t, n) (p = (t) malloc((n), M_RTABLE, M_DONTWAIT))
+#define Bcopy(a, b, n) bcopy(((caddr_t)(a)), ((caddr_t)(b)), (n))
 #define Bzero(p, n) bzero((caddr_t)(p), (int)(n));
 #define Bzero(p, n) bzero((caddr_t)(p), (int)(n));
+#define R_Malloc(p, t, n) (p = (t) malloc((n), M_RTABLE, M_DONTWAIT))
 #define Free(p) free((caddr_t)p);
 #endif KERNEL
 #define Free(p) free((caddr_t)p);
 #endif KERNEL
-
-struct nrtentry {
-       struct  radix_node nrt_nodes[2];
-       struct  rtentry nrt_rt;
-};
-
-#define MAXKEYLEN 32
-
-extern struct radix_node_head {
-       struct  radix_node_head *rnh_next;
-       struct  radix_node *rnh_treetop;
-       int     rnh_af;
-       struct  radix_node rnh_upper;
-       struct  nrtentry rnh_nrt;
-} *radix_node_head;
-
-extern struct radix_mask *rn_mkfreelist;
-
-#define MKGet(m) {\
-       if (rn_mkfreelist) {\
-               m = rn_mkfreelist; \
-               rn_mkfreelist = (m)->rm_mklist; \
-       } else \
-               Malloc(m, struct radix_mask *, sizeof (*(m))); }\
-
-#define MKFree(m) { (m)->rm_mklist = rn_mkfreelist; rn_mkfreelist = (m);}
index 2ab1cc1..dcd481c 100644 (file)
@@ -14,7 +14,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)route.h     7.4 (Berkeley) %G%
+ *     @(#)route.h     7.4 (Berkeley) 6/27/88
  */
 
 /*
  */
 
 /*
@@ -42,7 +42,23 @@ struct route {
  * gateways are marked so that the output routines know to address the
  * gateway rather than the ultimate destination.
  */
  * gateways are marked so that the output routines know to address the
  * gateway rather than the ultimate destination.
  */
+#include "radix.h"
 struct rtentry {
 struct rtentry {
+       struct  radix_node rt_nodes[2]; /* tree glue, and other values */
+#define        rt_key(r)       ((struct sockaddr *)((r)->rt_nodes->rn_key))
+#define        rt_mask(r)      ((struct sockaddr *)((r)->rt_nodes->rn_mask))
+       struct  sockaddr *rt_gateway;   /* value */
+       short   rt_flags;               /* up/down?, host/net */
+       short   rt_refcnt;              /* # held references */
+       u_long  rt_use;                 /* raw # packets forwarded */
+       struct  ifnet *rt_ifp;          /* the answer: interface to use */
+};
+
+/*
+ * Following structure necessary for 4.3 compatibility;
+ * We should eventually move it to a compat file.
+ */
+struct ortentry {
        u_long  rt_hash;                /* to speed lookups */
        struct  sockaddr rt_dst;        /* key */
        struct  sockaddr rt_gateway;    /* value */
        u_long  rt_hash;                /* to speed lookups */
        struct  sockaddr rt_dst;        /* key */
        struct  sockaddr rt_gateway;    /* value */
@@ -57,6 +73,9 @@ struct rtentry {
 #define        RTF_HOST        0x4             /* host entry (net otherwise) */
 #define        RTF_DYNAMIC     0x10            /* created dynamically (by redirect) */
 #define        RTF_MODIFIED    0x20            /* modified dynamically (by redirect) */
 #define        RTF_HOST        0x4             /* host entry (net otherwise) */
 #define        RTF_DYNAMIC     0x10            /* created dynamically (by redirect) */
 #define        RTF_MODIFIED    0x20            /* modified dynamically (by redirect) */
+#define RTF_DONE       0x40            /* message confirmed */
+#define RTF_MASK       0x80            /* subnet mask present */
+
 
 /*
  * Routing statistics.
 
 /*
  * Routing statistics.
@@ -68,6 +87,68 @@ struct       rtstat {
        short   rts_unreach;            /* lookups which failed */
        short   rts_wildcard;           /* lookups satisfied by a wildcard */
 };
        short   rts_unreach;            /* lookups which failed */
        short   rts_wildcard;           /* lookups satisfied by a wildcard */
 };
+/*
+ * Structures for routing messages.
+ */
+struct rt_metrics {
+       u_long  rtm_mtu;        /* MTU for this path */
+       u_long  rtm_hopcount;   /* max hops expected */
+       u_long  rtm_expire;     /* lifetime for route, e.g. redirect */
+       u_long  rtm_recvpipe;   /* inbound delay-bandwith product */
+       u_long  rtm_sendpipe;   /* outbound delay-bandwith product */
+       u_long  rtm_ssthresh;   /* outbound gateway buffer limit */
+       u_long  rtm_rtt;        /* estimated round trip time */
+       u_long  rtm_rttvar;     /* estimated rtt variance */
+};
+
+struct rt_msghdr {
+       u_short rtm_msglen;     /* to skip over non-understood messages */
+       u_char  rtm_version;    /* future binary compatability */
+       u_char  rtm_type;       /* message type */
+       u_char  rtm_count;      /* number of sockaddrs */
+       pid_t   rtm_pid;        /* identify sender */
+       int     rtm_seq;        /* for sender to identify action */
+       int     rtm_errno;      /* why failed */
+       int     rtm_flags;      /* flags, incl. kern & message, e.g. DONE */
+       int     rtm_locks;      /* which values kernel can alter */
+       int     rtm_inits;      /* which values we are initializing */
+};
+
+struct rt_chgmsg {             /* Good for RTM_ADD, RTM_CHANGE, RTM_GET */
+       struct  rt_msghdr cm_h;
+       struct  rt_metrics cm_m;
+};
+
+struct route_cb {
+       int     ip_count;
+       int     ns_count;
+       int     iso_count;
+       int     any_count;
+};
+
+#define RTM_ADD                0x1     /* Add Route */
+#define RTM_DELETE     0x2     /* Delete Route */
+#define RTM_CHANGE     0x3     /* Change Metrics or flags */
+#define RTM_GET                0x4     /* Report Metrics */
+#define RTM_LOSING     0x5     /* Kernel Suspects Partitioning */
+#define RTM_REDIRECT   0x6     /* Told to use different route */
+#define RTM_MISS       0x7     /* Lookup failed on this address */
+#define RTM_LOCK       0x8     /* fix specified metrics */
+#define RTM_OLDADD     0x9     /* caused by SIOCADDRT */
+#define RTM_OLDDEL     0xa     /* caused by SIOCDELRT */
+
+#define RTV_MTU                0x1     /* init or lock _mtu */
+#define RTV_HOPCOUNT   0x2     /* init or lock _hopcount */
+#define RTV_EXPIRE     0x4     /* init or lock _hopcount */
+#define RTV_RPIPE      0x8     /* init or lock _recvpipe */
+#define RTV_SPIPE      0x10    /* init or lock _sendpipe */
+#define RTV_SSTHRESH   0x20    /* init or lock _ssthresh */
+#define RTV_RTT                0x40    /* init or lock _rtt */
+#define RTV_RTTVAR     0x80    /* init or lock _rttvar */
+
+#ifdef KERNEL
+struct route_cb route_cb;
+#endif
 
 #ifdef KERNEL
 #define        RTFREE(rt) \
 
 #ifdef KERNEL
 #define        RTFREE(rt) \
@@ -89,4 +170,5 @@ struct       rtstat {
 struct mbuf *rthost[RTHASHSIZ];
 struct mbuf *rtnet[RTHASHSIZ];
 struct rtstat  rtstat;
 struct mbuf *rthost[RTHASHSIZ];
 struct mbuf *rtnet[RTHASHSIZ];
 struct rtstat  rtstat;
+struct rtentry *rtalloc1();
 #endif
 #endif