diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-10-10 17:38:27 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-10-11 15:50:21 +0200 |
commit | 28c2976d6effa8787bfbfc67a5ee254d59d32e70 (patch) | |
tree | b49e293317ee87daec3be33a029ee4bb2bbeda51 | |
parent | f28ef15b87c54bbfd54dbc9f880fa9e09cacc756 (diff) |
compat: move version logic to compat.h and out of main .c
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | src/compat/compat.h | 14 | ||||
-rw-r--r-- | src/device.c | 12 | ||||
-rw-r--r-- | src/netlink.c | 4 |
3 files changed, 22 insertions, 8 deletions
diff --git a/src/compat/compat.h b/src/compat/compat.h index c75bfe3..efd4d45 100644 --- a/src/compat/compat.h +++ b/src/compat/compat.h @@ -438,6 +438,7 @@ static inline struct nlattr **genl_family_attrbuf(const struct genl_family *fami #else #define genl_register_family(a) genl_register_family_with_ops(a, genl_ops) #endif +#define COMPAT_CANNOT_USE_GENL_NOPS #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0) @@ -452,6 +453,19 @@ static int get_device_dump(a, b) { \ return get_device_dump_real(skb, cb); \ } \ static int get_device_dump_real(a, b) +#define COMPAT_CANNOT_USE_NETLINK_START +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) +#define COMPAT_CANNOT_USE_IN6_DEV_GET +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) +#define COMPAT_CANNOT_USE_DEV_CNF +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) +#define COMPAT_CANNOT_USE_IFF_NO_QUEUE #endif /* https://lkml.org/lkml/2017/6/23/790 */ diff --git a/src/device.c b/src/device.c index 0fb5dcd..6b56048 100644 --- a/src/device.c +++ b/src/device.c @@ -28,7 +28,7 @@ static int open(struct net_device *dev) int ret; struct wireguard_peer *peer, *temp; struct wireguard_device *wg = netdev_priv(dev); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0) +#ifndef COMPAT_CANNOT_USE_IN6_DEV_GET struct inet6_dev *dev_v6 = __in6_dev_get(dev); #endif struct in_device *dev_v4 = __in_dev_get_rtnl(dev); @@ -41,12 +41,12 @@ static int open(struct net_device *dev) IN_DEV_CONF_SET(dev_v4, SEND_REDIRECTS, false); IPV4_DEVCONF_ALL(dev_net(dev), SEND_REDIRECTS) = false; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0) +#ifndef COMPAT_CANNOT_USE_IN6_DEV_GET if (dev_v6) -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) - dev_v6->addr_gen_mode = IN6_ADDR_GEN_MODE_NONE; -#else +#ifndef COMPAT_CANNOT_USE_DEV_CNF dev_v6->cnf.addr_gen_mode = IN6_ADDR_GEN_MODE_NONE; +#else + dev_v6->addr_gen_mode = IN6_ADDR_GEN_MODE_NONE; #endif #endif @@ -238,7 +238,7 @@ static void setup(struct net_device *dev) dev->needed_tailroom = noise_encrypted_len(MESSAGE_PADDING_MULTIPLE); dev->type = ARPHRD_NONE; dev->flags = IFF_POINTOPOINT | IFF_NOARP; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0) +#ifndef COMPAT_CANNOT_USE_IFF_NO_QUEUE dev->priv_flags |= IFF_NO_QUEUE; #else dev->tx_queue_len = 0; diff --git a/src/netlink.c b/src/netlink.c index e727669..ff32fb6 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -456,7 +456,7 @@ out_nodev: static const struct genl_ops genl_ops[] = { { .cmd = WG_CMD_GET_DEVICE, -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) +#ifndef COMPAT_CANNOT_USE_NETLINK_START .start = get_device_start, #endif .dumpit = get_device_dump, @@ -471,7 +471,7 @@ static const struct genl_ops genl_ops[] = { } }; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) +#ifndef COMPAT_CANNOT_USE_GENL_NOPS static struct genl_family genl_family __ro_after_init = { .ops = genl_ops, .n_ops = ARRAY_SIZE(genl_ops), |