summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authormpi <mpi@openbsd.org>2016-12-02 11:16:04 +0000
committermpi <mpi@openbsd.org>2016-12-02 11:16:04 +0000
commit90fa29fac0505950d914a1db12f79a6e10ea0f54 (patch)
tree436d6c78bd2116342966e32891bd19a8108cab7b /sys
parentenable hvn(4) (diff)
downloadwireguard-openbsd-90fa29fac0505950d914a1db12f79a6e10ea0f54.tar.xz
wireguard-openbsd-90fa29fac0505950d914a1db12f79a6e10ea0f54.zip
Rremoves 'struct route_in6 *' argument from in6_selectsrc().
Move the corresponding code in in6_pcbselsrc(). This reduces differences with IPv4 and will help us to get rid of 'struct route*'. ok vgross@
Diffstat (limited to 'sys')
-rw-r--r--sys/net/if_vxlan.c4
-rw-r--r--sys/netinet6/in6_src.c103
-rw-r--r--sys/netinet6/ip6_var.h4
3 files changed, 55 insertions, 56 deletions
diff --git a/sys/net/if_vxlan.c b/sys/net/if_vxlan.c
index 366c78b0378..17db4624206 100644
--- a/sys/net/if_vxlan.c
+++ b/sys/net/if_vxlan.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_vxlan.c,v 1.52 2016/11/29 10:09:57 reyk Exp $ */
+/* $OpenBSD: if_vxlan.c,v 1.53 2016/12/02 11:16:04 mpi Exp $ */
/*
* Copyright (c) 2013 Reyk Floeter <reyk@openbsd.org>
@@ -768,7 +768,7 @@ vxlan_encap6(struct ifnet *ifp, struct mbuf *m,
ip6->ip6_hlim = ip6_defhlim;
if (IN6_IS_ADDR_UNSPECIFIED(&satosin6(src)->sin6_addr)) {
- error = in6_selectsrc(&in6a, satosin6(dst), NULL, NULL,
+ error = in6_selectsrc(&in6a, satosin6(dst), NULL,
sc->sc_rdomain);
if (error != 0) {
m_freem(m);
diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c
index 36fb922c638..419ca22a430 100644
--- a/sys/netinet6/in6_src.c
+++ b/sys/netinet6/in6_src.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in6_src.c,v 1.80 2016/09/02 13:53:44 vgross Exp $ */
+/* $OpenBSD: in6_src.c,v 1.81 2016/12/02 11:16:04 mpi Exp $ */
/* $KAME: in6_src.c,v 1.36 2001/02/06 04:08:17 itojun Exp $ */
/*
@@ -99,7 +99,6 @@ in6_pcbselsrc(struct in6_addr **in6src, struct sockaddr_in6 *dstsock,
struct route_in6 *ro = &inp->inp_route6;
struct in6_addr *laddr = &inp->inp_laddr6;
u_int rtableid = inp->inp_rtableid;
-
struct ifnet *ifp = NULL;
struct in6_addr *dst;
struct in6_ifaddr *ia6 = NULL;
@@ -172,7 +171,55 @@ in6_pcbselsrc(struct in6_addr **in6src, struct sockaddr_in6 *dstsock,
return (0);
}
- return in6_selectsrc(in6src, dstsock, mopts, ro, rtableid);
+ error = in6_selectsrc(in6src, dstsock, mopts, rtableid);
+ if (error != EADDRNOTAVAIL)
+ return (error);
+
+ /*
+ * If route is known or can be allocated now,
+ * our src addr is taken from the i/f, else punt.
+ */
+ if (!rtisvalid(ro->ro_rt) || (ro->ro_tableid != rtableid) ||
+ !IN6_ARE_ADDR_EQUAL(&ro->ro_dst.sin6_addr, dst)) {
+ rtfree(ro->ro_rt);
+ ro->ro_rt = NULL;
+ }
+ if (ro->ro_rt == NULL) {
+ struct sockaddr_in6 *sa6;
+
+ /* No route yet, so try to acquire one */
+ bzero(&ro->ro_dst, sizeof(struct sockaddr_in6));
+ ro->ro_tableid = rtableid;
+ sa6 = &ro->ro_dst;
+ sa6->sin6_family = AF_INET6;
+ sa6->sin6_len = sizeof(struct sockaddr_in6);
+ sa6->sin6_addr = *dst;
+ sa6->sin6_scope_id = dstsock->sin6_scope_id;
+ ro->ro_rt = rtalloc(sin6tosa(&ro->ro_dst),
+ RT_RESOLVE, ro->ro_tableid);
+ }
+
+ /*
+ * in_pcbconnect() checks out IFF_LOOPBACK to skip using
+ * the address. But we don't know why it does so.
+ * It is necessary to ensure the scope even for lo0
+ * so doesn't check out IFF_LOOPBACK.
+ */
+
+ if (ro->ro_rt) {
+ ifp = if_get(ro->ro_rt->rt_ifidx);
+ if (ifp != NULL) {
+ 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)
+ return (EHOSTUNREACH); /* no route */
+
+ *in6src = &ia6->ia_addr.sin6_addr;
+ return (0);
}
/*
@@ -183,7 +230,7 @@ in6_pcbselsrc(struct in6_addr **in6src, struct sockaddr_in6 *dstsock,
*/
int
in6_selectsrc(struct in6_addr **in6src, struct sockaddr_in6 *dstsock,
- struct ip6_moptions *mopts, struct route_in6 *ro, u_int rtableid)
+ struct ip6_moptions *mopts, unsigned int rtableid)
{
struct ifnet *ifp = NULL;
struct in6_addr *dst;
@@ -241,54 +288,6 @@ in6_selectsrc(struct in6_addr **in6src, struct sockaddr_in6 *dstsock,
}
}
- /*
- * If route is known or can be allocated now,
- * our src addr is taken from the i/f, else punt.
- */
- if (ro) {
- if (!rtisvalid(ro->ro_rt) || (ro->ro_tableid != rtableid) ||
- !IN6_ARE_ADDR_EQUAL(&ro->ro_dst.sin6_addr, dst)) {
- rtfree(ro->ro_rt);
- ro->ro_rt = NULL;
- }
- if (ro->ro_rt == NULL) {
- struct sockaddr_in6 *sa6;
-
- /* No route yet, so try to acquire one */
- bzero(&ro->ro_dst, sizeof(struct sockaddr_in6));
- ro->ro_tableid = rtableid;
- sa6 = &ro->ro_dst;
- sa6->sin6_family = AF_INET6;
- sa6->sin6_len = sizeof(struct sockaddr_in6);
- sa6->sin6_addr = *dst;
- sa6->sin6_scope_id = dstsock->sin6_scope_id;
- ro->ro_rt = rtalloc(sin6tosa(&ro->ro_dst),
- RT_RESOLVE, ro->ro_tableid);
- }
-
- /*
- * in_pcbconnect() checks out IFF_LOOPBACK to skip using
- * the address. But we don't know why it does so.
- * It is necessary to ensure the scope even for lo0
- * so doesn't check out IFF_LOOPBACK.
- */
-
- if (ro->ro_rt) {
- ifp = if_get(ro->ro_rt->rt_ifidx);
- if (ifp != NULL) {
- 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)
- return (EHOSTUNREACH); /* no route */
-
- *in6src = &ia6->ia_addr.sin6_addr;
- return (0);
- }
-
return (EADDRNOTAVAIL);
}
diff --git a/sys/netinet6/ip6_var.h b/sys/netinet6/ip6_var.h
index 0278b75bea4..a7e1fefb682 100644
--- a/sys/netinet6/ip6_var.h
+++ b/sys/netinet6/ip6_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip6_var.h,v 1.64 2016/08/24 09:41:12 mpi Exp $ */
+/* $OpenBSD: ip6_var.h,v 1.65 2016/12/02 11:16:04 mpi Exp $ */
/* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */
/*
@@ -297,7 +297,7 @@ int none_input(struct mbuf **, int *, int);
int in6_pcbselsrc(struct in6_addr **, struct sockaddr_in6 *,
struct inpcb *, struct ip6_pktopts *);
int in6_selectsrc(struct in6_addr **, struct sockaddr_in6 *,
- struct ip6_moptions *, struct route_in6 *, u_int);
+ struct ip6_moptions *, unsigned int);
struct rtentry *in6_selectroute(struct sockaddr_in6 *, struct ip6_pktopts *,
struct route_in6 *, unsigned int rtableid);