diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-09-29 04:36:14 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-09-29 19:25:30 +0200 |
commit | a18ceb81ca78a7f37adc436f35e6eeb8683bb984 (patch) | |
tree | e47051e5acf65c5d2cf8c3fa494abb6742d0bb24 /src/compat.h | |
parent | poly1305: optimize unaligned access (diff) | |
download | wireguard-monolithic-historical-a18ceb81ca78a7f37adc436f35e6eeb8683bb984.tar.xz wireguard-monolithic-historical-a18ceb81ca78a7f37adc436f35e6eeb8683bb984.zip |
Rework headers and includes
Diffstat (limited to 'src/compat.h')
-rw-r--r-- | src/compat.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/compat.h b/src/compat.h new file mode 100644 index 0000000..5a49655 --- /dev/null +++ b/src/compat.h @@ -0,0 +1,41 @@ +/* Copyright 2015-2016 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. */ + +#ifndef COMPAT_H +#define COMPAT_H + +#include <linux/kconfig.h> +#include <linux/version.h> +#include <linux/types.h> +#include <linux/netdevice.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0) +#error "WireGuard requires Linux >= 4.1" +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) && !defined(DEBUG) && defined(net_dbg_ratelimited) +#undef net_dbg_ratelimited +#define net_dbg_ratelimited(fmt, ...) do { if (0) no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0) +#define get_random_long() (((u64)get_random_int() << 32) | get_random_int()) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) +#define RCU_LOCKDEP_WARN(cond, message) rcu_lockdep_assert(!(cond), message) +#endif + +/* https://lkml.org/lkml/2016/9/28/904 + * 64-bit jiffy functions like in include/linux/jiffies.h */ +#define time_is_before_jiffies64(a) time_after64(get_jiffies_64(), a) +#define time_is_after_jiffies64(a) time_before64(get_jiffies_64(), a) +#define time_is_before_eq_jiffies64(a) time_after_eq64(get_jiffies_64(), a) +#define time_is_after_eq_jiffies64(a) time_before_eq64(get_jiffies_64(), a) + +/* https://lkml.org/lkml/2015/6/12/415 + * Inverse of netdev_priv in include/linux/netdevice.h */ +static inline struct net_device *netdev_pub(void *dev) +{ + return (struct net_device *)((char *)dev - ALIGN(sizeof(struct net_device), NETDEV_ALIGN)); +} +#endif |