/* Copyright 2015-2016 Jason A. Donenfeld . All Rights Reserved. */ #ifndef COMPAT_H #define COMPAT_H #include #include #include #include #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