must match entries entirely on lookup
authorSam Leffler <sam@ucbvax.Berkeley.EDU>
Tue, 1 Jun 1982 10:10:24 +0000 (02:10 -0800)
committerSam Leffler <sam@ucbvax.Berkeley.EDU>
Tue, 1 Jun 1982 10:10:24 +0000 (02:10 -0800)
SCCS-vsn: sbin/routed/routed.c 4.11
SCCS-vsn: sbin/routed/defs.h 4.5

usr/src/sbin/routed/defs.h
usr/src/sbin/routed/routed.c

index ad5c95c..9de9ffc 100644 (file)
@@ -1,4 +1,4 @@
-/*     defs.h  4.4     82/05/31        */
+/*     defs.h  4.5     82/05/31        */
 
 /*
  * Internal data structure definitions for
 
 /*
  * Internal data structure definitions for
@@ -60,7 +60,7 @@ struct rt_entry {
 #define        RTS_HIDDEN      0x8             /* don't send to router */
 
 struct rthash nethash[ROUTEHASHSIZ], hosthash[ROUTEHASHSIZ];
 #define        RTS_HIDDEN      0x8             /* don't send to router */
 
 struct rthash nethash[ROUTEHASHSIZ], hosthash[ROUTEHASHSIZ];
-struct rt_entry *rtlookup();
+struct rt_entry *rtlookup(), *rtfind();
 
 /*
  * Per address family routines.
 
 /*
  * Per address family routines.
index 52b9c82..8c527bb 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)routed.c   4.10 %G%";
+static char sccsid[] = "@(#)routed.c   4.11 %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -564,7 +564,7 @@ rip_input(from, size)
         * don't hear their own broadcasts?
         */
        if (if_ifwithaddr(from)) {
         * don't hear their own broadcasts?
         */
        if (if_ifwithaddr(from)) {
-               rt = rtlookup(from);
+               rt = rtfind(from);
                if (rt)
                        rt->rt_timer = 0;
                return;
                if (rt)
                        rt->rt_timer = 0;
                return;
@@ -635,9 +635,47 @@ rtlookup(dst)
 {
        register struct rt_entry *rt;
        register struct rthash *rh;
 {
        register struct rt_entry *rt;
        register struct rthash *rh;
-       register int hash, (*match)();
+       register int hash;
        struct afhash h;
        struct afhash h;
-       int af = dst->sa_family, doinghost = 1;
+       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 % ROUTEHASHSIZ];
+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 % ROUTEHASHSIZ];
+               goto again;
+       }
+       return (0);
+}
+
+/*
+ * Find an entry based on address "dst", as the kernel
+ * does in selecting routes.  This means we look first
+ * for a point to point link, settling for a route to
+ * the destination network if the former fails.
+ */
+struct rt_entry *
+rtfind(dst)
+       struct sockaddr *dst;
+{
+       register struct rt_entry *rt;
+       register struct rthash *rh;
+       register int hash;
+       struct afhash h;
+       int af = dst->sa_family;
+       int doinghost = 1, (*match)();
 
        if (af >= AF_MAX)
                return (0);
 
        if (af >= AF_MAX)
                return (0);
@@ -661,8 +699,8 @@ again:
        if (doinghost) {
                doinghost = 0;
                hash = h.afh_nethash;
        if (doinghost) {
                doinghost = 0;
                hash = h.afh_nethash;
-               match = afswitch[af].af_netmatch;
                rh = &nethash[hash % ROUTEHASHSIZ];
                rh = &nethash[hash % ROUTEHASHSIZ];
+               match = afswitch[af].af_netmatch;
                goto again;
        }
        return (0);
                goto again;
        }
        return (0);