Changes to allow multiple pt to pt links to have the same local address.
authorKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Fri, 19 Jul 1985 13:34:14 +0000 (05:34 -0800)
committerKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Fri, 19 Jul 1985 13:34:14 +0000 (05:34 -0800)
SCCS-vsn: sys/net/route.c 6.11
SCCS-vsn: sys/net/if.c 6.8

usr/src/sys/net/if.c
usr/src/sys/net/route.c

index 0b8a213..3c40175 100644 (file)
@@ -3,7 +3,7 @@
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)if.c        6.7 (Berkeley) %G%
+ *     @(#)if.c        6.8 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -98,6 +98,27 @@ ifa_ifwithaddr(addr)
        }
        return ((struct ifaddr *)0);
 }
        }
        return ((struct ifaddr *)0);
 }
+/*
+ * Locate the point to point interface with a given destination address.
+ */
+/*ARGSUSED*/
+struct ifaddr *
+ifa_ifwithdstaddr(addr)
+       struct sockaddr *addr;
+{
+       register struct ifnet *ifp;
+       register struct ifaddr *ifa;
+
+       for (ifp = ifnet; ifp; ifp = ifp->if_next) 
+           if (ifp->if_flags & IFF_POINTOPOINT)
+               for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) {
+                       if (ifa->ifa_addr.sa_family != addr->sa_family)
+                               continue;
+                       if (equal(&ifa->ifa_dstaddr, addr))
+                               return (ifa);
+       }
+       return ((struct ifaddr *)0);
+}
 
 /*
  * Find an interface on a specific network.  If many, choice
 
 /*
  * Find an interface on a specific network.  If many, choice
index 54fb21a..ca1d869 100644 (file)
@@ -3,7 +3,7 @@
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)route.c     6.10 (Berkeley) %G%
+ *     @(#)route.c     6.11 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -202,6 +202,7 @@ rtrequest(req, entry)
        u_int af;
        u_long hash;
        struct ifaddr *ifa;
        u_int af;
        u_long hash;
        struct ifaddr *ifa;
+       struct ifaddr *ifa_ifwithdstaddr();
 
        af = entry->rt_dst.sa_family;
        if (af >= AF_MAX)
 
        af = entry->rt_dst.sa_family;
        if (af >= AF_MAX)
@@ -254,7 +255,25 @@ rtrequest(req, entry)
                        error = EEXIST;
                        goto bad;
                }
                        error = EEXIST;
                        goto bad;
                }
-               ifa = ifa_ifwithaddr(&entry->rt_gateway);
+               /*
+                * If we are adding a route to an interface,
+                * and the interface is a pt to pt link
+                * we should search for the destination
+                * as our clue to the interface.  Otherwise
+                * we can use the local address.
+                */
+               if ((entry->rt_flags & RTF_GATEWAY)==0) {
+                       if (entry->rt_flags & RTF_HOST) 
+                               ifa = ifa_ifwithdstaddr(&entry->rt_dst);
+                       else
+                               ifa = ifa_ifwithaddr(&entry->rt_gateway);
+               } else {
+               /* If we are adding a route to a remote net
+                * or host, the gateway may still be on the
+                * other end of a pt to pt link.
+                */
+                       ifa = ifa_ifwithdstaddr(&entry->rt_gateway);
+               }
                if (ifa == 0) {
                        ifa = ifa_ifwithnet(&entry->rt_gateway);
                        if (ifa == 0) {
                if (ifa == 0) {
                        ifa = ifa_ifwithnet(&entry->rt_gateway);
                        if (ifa == 0) {