aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/socket.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2016-07-15 01:34:37 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2016-07-18 03:41:57 +0200
commit3106d632de4235f8c6d63d602fe2fa9e0175d690 (patch)
treef166c00ca76b4ed076429a993b40bdd2b5cbca7e /src/socket.c
parenttests: improve test suite and add qemu tester (diff)
downloadwireguard-monolithic-historical-3106d632de4235f8c6d63d602fe2fa9e0175d690.tar.xz
wireguard-monolithic-historical-3106d632de4235f8c6d63d602fe2fa9e0175d690.zip
build system: revamp building and configuration
Diffstat (limited to 'src/socket.c')
-rw-r--r--src/socket.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/socket.c b/src/socket.c
index ac19a47..463e027 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -62,6 +62,7 @@ static inline struct dst_entry *route(struct wireguard_device *wg, struct flowi4
dst = ERR_PTR(PTR_ERR(rt));
dst = &rt->dst;
} else if (addr->ss_family == AF_INET6) {
+#if IS_ENABLED(CONFIG_IPV6)
int ret;
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr;
@@ -84,6 +85,7 @@ static inline struct dst_entry *route(struct wireguard_device *wg, struct flowi4
#endif
if (unlikely(ret))
dst = ERR_PTR(ret);
+#endif
}
return dst;
}
@@ -122,7 +124,7 @@ static inline int send(struct net_device *dev, struct sk_buff *skb, struct dst_e
ret = -ENONET;
goto err;
}
-
+#if IS_ENABLED(CONFIG_IPV6)
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
return udp_tunnel6_xmit_skb(dst, sock6, skb, dev,
&fl6->saddr, &fl6->daddr,
@@ -144,6 +146,9 @@ static inline int send(struct net_device *dev, struct sk_buff *skb, struct dst_e
false);
return 0;
#endif
+#else
+ goto err;
+#endif
}
err:
@@ -391,11 +396,14 @@ static inline void set_sock_opts(struct socket *sock)
int socket_init(struct wireguard_device *wg)
{
+ struct socket *new4 = NULL;
struct udp_port_cfg port4 = {
.family = AF_INET,
.local_ip.s_addr = htonl(INADDR_ANY),
.use_udp_checksums = true
};
+#if IS_ENABLED(CONFIG_IPV6)
+ struct socket *new6 = NULL;
struct udp_port_cfg port6 = {
.family = AF_INET6,
.local_ip6 = IN6ADDR_ANY_INIT,
@@ -405,6 +413,7 @@ int socket_init(struct wireguard_device *wg)
.ipv6_v6only = true
#endif
};
+#endif
struct udp_tunnel_sock_cfg cfg = {
.sk_user_data = wg,
.encap_type = 1,
@@ -412,7 +421,6 @@ int socket_init(struct wireguard_device *wg)
};
int ret = 0;
- struct socket *new4 = NULL, *new6 = NULL;
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0)
int old_bindv6only;
#endif
@@ -427,7 +435,11 @@ int socket_init(struct wireguard_device *wg)
if (!wg->incoming_port)
wg->incoming_port = generate_default_incoming_port(wg);
- port4.local_udp_port = port6.local_udp_port = htons(wg->incoming_port);
+ port4.local_udp_port =
+#if IS_ENABLED(CONFIG_IPV6)
+ port6.local_udp_port =
+#endif
+ htons(wg->incoming_port);
ret = udp_sock_create(wg->creating_net, &port4, &new4);
if (ret < 0) {
@@ -435,6 +447,11 @@ int socket_init(struct wireguard_device *wg)
goto out;
}
+ set_sock_opts(new4);
+ setup_udp_tunnel_sock(wg->creating_net, new4, &cfg);
+ rcu_assign_pointer(wg->sock4, new4->sk);
+
+#if IS_ENABLED(CONFIG_IPV6)
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0)
/* Since udp_port_cfg only learned of ipv6_v6only in 4.3, we do this horrible
* hack here and set the sysctl variable temporarily to something that will
@@ -452,12 +469,10 @@ int socket_init(struct wireguard_device *wg)
goto out;
}
- set_sock_opts(new4);
set_sock_opts(new6);
- setup_udp_tunnel_sock(wg->creating_net, new4, &cfg);
setup_udp_tunnel_sock(wg->creating_net, new6, &cfg);
- rcu_assign_pointer(wg->sock4, new4->sk);
rcu_assign_pointer(wg->sock6, new6->sk);
+#endif
out:
mutex_unlock(&wg->socket_update_lock);