From 48110b4f044817a193821f42028a036feb3b8c36 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 22 Feb 2017 13:09:11 +0100 Subject: socket: do not try to create v6 socket when disabled --- src/compat/compat.h | 8 ++++++++ src/socket.c | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/compat/compat.h b/src/compat/compat.h index 6a9bfd9..277e7e7 100644 --- a/src/compat/compat.h +++ b/src/compat/compat.h @@ -153,6 +153,14 @@ __attribute__((unused)) static inline int udp_sock_create_new(struct net *net, s #define time_is_after_eq_jiffies64(a) time_before_eq64(get_jiffies_64(), a) #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 8, 0) && IS_ENABLED(CONFIG_IPV6) +#include +static inline bool ipv6_mod_enabled(void) +{ + return ipv6_stub->udpv6_encap_enable != NULL; +} +#endif + /* https://lkml.org/lkml/2015/6/12/415 */ #include static inline struct net_device *netdev_pub(void *dev) diff --git a/src/socket.c b/src/socket.c index f799d91..f894cfe 100644 --- a/src/socket.c +++ b/src/socket.c @@ -345,6 +345,8 @@ retry: rcu_assign_pointer(wg->sock4, new4->sk); #if IS_ENABLED(CONFIG_IPV6) + if (!ipv6_mod_enabled()) + goto out; port6.local_udp_port = htons(wg->incoming_port); ret = udp_sock_create(wg->creating_net, &port6, &new6); if (ret < 0) { -- cgit v1.2.3-59-g8ed1b