Use ``rt_addr'' rather than ``rt_ifa'' to get the source address
authormpi <mpi@openbsd.org>
Thu, 30 Jun 2016 12:36:27 +0000 (12:36 +0000)
committermpi <mpi@openbsd.org>
Thu, 30 Jun 2016 12:36:27 +0000 (12:36 +0000)
corresponding to a route.

ok florian@ on a previous version, input and ok bluhm@

sys/netinet/in_pcb.c
sys/netinet6/in6_src.c

index 5cf54ac..24526a9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: in_pcb.c,v 1.207 2016/06/18 10:36:13 vgross Exp $     */
+/*     $OpenBSD: in_pcb.c,v 1.208 2016/06/30 12:36:27 mpi Exp $        */
 /*     $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $     */
 
 /*
@@ -879,7 +879,6 @@ in_selectsrc(struct in_addr **insrc, struct sockaddr_in *sin,
     u_int rtableid)
 {
        struct sockaddr_in *sin2;
-       struct in_ifaddr *ia = NULL;
 
        /*
         * If the socket(if any) is already bound, use that bound address
@@ -901,6 +900,8 @@ in_selectsrc(struct in_addr **insrc, struct sockaddr_in *sin,
 
                ifp = if_get(mopts->imo_ifidx);
                if (ifp != NULL) {
+                       struct in_ifaddr *ia = NULL;
+
                        if (ifp->if_rdomain == rtable_l2(rtableid))
                                IFP_TO_IA(ifp, ia);
                        if (ia == NULL) {
@@ -941,14 +942,12 @@ in_selectsrc(struct in_addr **insrc, struct sockaddr_in *sin,
         * If we found a route, use the address
         * corresponding to the outgoing interface.
         */
-       if (ro->ro_rt != NULL)
-               ia = ifatoia(ro->ro_rt->rt_ifa);
-
-       if (ia == NULL)
-               return (EADDRNOTAVAIL);
+       if (ro->ro_rt != NULL) {
+               *insrc = &satosin(ro->ro_rt->rt_addr)->sin_addr;
+               return (0);
+       }
 
-       *insrc = &ia->ia_addr.sin_addr;
-       return (0);
+       return (EADDRNOTAVAIL);
 }
 
 void
index de8de00..b26e0e6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: in6_src.c,v 1.73 2016/06/27 16:36:08 jca Exp $        */
+/*     $OpenBSD: in6_src.c,v 1.74 2016/06/30 12:36:27 mpi Exp $        */
 /*     $KAME: in6_src.c,v 1.36 2001/02/06 04:08:17 itojun Exp $        */
 
 /*
@@ -257,8 +257,11 @@ in6_selectsrc(struct in6_addr **in6src, struct sockaddr_in6 *dstsock,
                                ia6 = in6_ifawithscope(ifp, dst, rtableid);
                                if_put(ifp);
                        }
-                       if (ia6 == NULL) /* xxx scope error ?*/
-                               ia6 = ifatoia6(ro->ro_rt->rt_ifa);
+                       if (ia6 == NULL) { /* xxx scope error ?*/
+                               *in6src =
+                                   &satosin6(ro->ro_rt->rt_addr)->sin6_addr;
+                               return (0);
+                       }
                }
                if (ia6 == NULL)
                        return (EHOSTUNREACH);  /* no route */