From 8a82b39ef90b95cd4533fb5a6f5afa2b74ebd61d Mon Sep 17 00:00:00 2001 From: Jozsef Kadlecsik Date: Wed, 2 Oct 2013 17:31:15 +0200 Subject: Compatibility code is modified not to rely on kernel version numbers Instead the kernel source code is checked to verify the different compatibility issues for the supported kernel releases. This way hopefully backported features will be handled properly. --- .../include/linux/netfilter/ipset/ip_set_compat.h | 103 ------------------ .../linux/netfilter/ipset/ip_set_compat.h.in | 119 +++++++++++++++++++++ 2 files changed, 119 insertions(+), 103 deletions(-) delete mode 100644 kernel/include/linux/netfilter/ipset/ip_set_compat.h create mode 100644 kernel/include/linux/netfilter/ipset/ip_set_compat.h.in (limited to 'kernel/include') diff --git a/kernel/include/linux/netfilter/ipset/ip_set_compat.h b/kernel/include/linux/netfilter/ipset/ip_set_compat.h deleted file mode 100644 index cdc8f53..0000000 --- a/kernel/include/linux/netfilter/ipset/ip_set_compat.h +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef __IP_SET_COMPAT_H -#define __IP_SET_COMPAT_H - -/* Not everything could be moved here. Compatibility stuffs can be found in - * xt_set.c, ip_set_core.c, ip_set_getport.c, pfxlen.c too. - */ - -#include -#include - -#ifndef rcu_dereference_bh -#define rcu_dereference_bh(p) rcu_dereference(p) -#endif - -#ifndef rcu_dereference_protected -#define rcu_dereference_protected(p, c) rcu_dereference(p) -#endif - -#ifndef __rcu -#define __rcu -#endif - -#ifdef CHECK_KCONFIG -#ifndef CONFIG_SPARSE_RCU_POINTER -#error "CONFIG_SPARSE_RCU_POINTER must be enabled" -#endif -#endif - -#if defined(CONFIG_NETFILTER_NETLINK) || defined(CONFIG_NETFILTER_NETLINK_MODULE) -#else -#error "NETFILTER_NETLINK must be enabled: select NFACCT/NFQUEUE/LOG over NFNETLINK" -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) -#define xt_action_param xt_match_param -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37) -#define vzalloc(size) __vmalloc(size,\ - GFP_KERNEL|__GFP_ZERO|__GFP_HIGHMEM,\ - PAGE_KERNEL) -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 5, 0) -#include - -static inline bool ether_addr_equal(const u8 *addr1, const u8 *addr2) -{ - return !compare_ether_addr(addr1, addr2); -} - -static inline int nla_put_be64(struct sk_buff *skb, int attrtype, __be64 value) -{ - return nla_put(skb, attrtype, sizeof(__be64), &value); -} - -static inline int nla_put_net64(struct sk_buff *skb, int attrtype, __be64 value) -{ - return nla_put_be64(skb, attrtype | NLA_F_NET_BYTEORDER, value); -} -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0) -#define NETLINK_PORTID(skb) NETLINK_CB(skb).pid -#else -#define NETLINK_PORTID(skb) NETLINK_CB(skb).portid -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0) -#define ns_capable(ns, cap) capable(cap) -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) -#define lock_nfnl() nfnl_lock() -#define unlock_nfnl() nfnl_unlock() -#else -#define lock_nfnl() nfnl_lock(NFNL_SUBSYS_IPSET) -#define unlock_nfnl() nfnl_unlock(NFNL_SUBSYS_IPSET) -#endif - -#ifdef NLA_PUT_NET16 -static inline int nla_put_be16(struct sk_buff *skb, int attrtype, __be16 value) -{ - return nla_put(skb, attrtype, sizeof(__be16), &value); -} - -static inline int nla_put_net16(struct sk_buff *skb, int attrtype, __be16 value) -{ - return nla_put_be16(skb, attrtype | NLA_F_NET_BYTEORDER, value); -} - -static inline int nla_put_be32(struct sk_buff *skb, int attrtype, __be32 value) -{ - return nla_put(skb, attrtype, sizeof(__be32), &value); -} - -static inline int nla_put_net32(struct sk_buff *skb, int attrtype, __be32 value) -{ - return nla_put_be32(skb, attrtype | NLA_F_NET_BYTEORDER, value); -} -#endif - -#endif /* __IP_SET_COMPAT_H */ diff --git a/kernel/include/linux/netfilter/ipset/ip_set_compat.h.in b/kernel/include/linux/netfilter/ipset/ip_set_compat.h.in new file mode 100644 index 0000000..b93c5d9 --- /dev/null +++ b/kernel/include/linux/netfilter/ipset/ip_set_compat.h.in @@ -0,0 +1,119 @@ +#ifndef __IP_SET_COMPAT_H +#define __IP_SET_COMPAT_H + +#@HAVE_STRUCT_XT_ACTION_PARAM@ HAVE_STRUCT_XT_ACTION_PARAM +#@HAVE_VZALLOC@ HAVE_VZALLOC +#@HAVE_ETHER_ADDR_EQUAL@ HAVE_ETHER_ADDR_EQUAL +#@HAVE_NLA_PUT_BE64@ HAVE_NLA_PUT_BE64 +#@HAVE_NL_INFO_PORTID@ HAVE_NL_INFO_PORTID +#define HAVE_NETLINK_DUMP_START_ARGS @HAVE_NETLINK_DUMP_START_ARGS@ +#@HAVE_NS_CAPABLE@ HAVE_NS_CAPABLE +#@HAVE_NFNL_LOCK_SUBSYS@ HAVE_NFNL_LOCK_SUBSYS +#@HAVE_EXPORT_H@ HAVE_EXPORT_H +#define HAVE_IPV6_SKIP_EXTHDR_ARGS @HAVE_IPV6_SKIP_EXTHDR_ARGS@ +#@HAVE_CHECKENTRY_BOOL@ HAVE_CHECKENTRY_BOOL +#@HAVE_XT_TARGET_PARAM@ HAVE_XT_TARGET_PARAM +#@HAVE_NET_OPS_ID@ HAVE_NET_OPS_ID + +/* Not everything could be moved here. Compatibility stuffs can be found in + * xt_set.c, ip_set_core.c, ip_set_getport.c, pfxlen.c too. + */ + +#include +#include + +#ifndef rcu_dereference_bh +#define rcu_dereference_bh(p) rcu_dereference(p) +#endif + +#ifndef rcu_dereference_protected +#define rcu_dereference_protected(p, c) rcu_dereference(p) +#endif + +#ifndef __rcu +#define __rcu +#endif + +#ifdef CHECK_KCONFIG +#ifndef CONFIG_SPARSE_RCU_POINTER +#error "CONFIG_SPARSE_RCU_POINTER must be enabled" +#endif +#endif + +#if defined(CONFIG_NETFILTER_NETLINK) || defined(CONFIG_NETFILTER_NETLINK_MODULE) +#else +#error "NETFILTER_NETLINK must be enabled: select NFACCT/NFQUEUE/LOG over NFNETLINK" +#endif + +#ifndef HAVE_STRUCT_XT_ACTION_PARAM +#define xt_action_param xt_match_param +#endif + +#ifndef HAVE_VZALLOC +#define vzalloc(size) __vmalloc(size,\ + GFP_KERNEL|__GFP_ZERO|__GFP_HIGHMEM,\ + PAGE_KERNEL) +#endif + +#ifndef HAVE_ETHER_ADDR_EQUAL +#include + +static inline bool ether_addr_equal(const u8 *addr1, const u8 *addr2) +{ + return !compare_ether_addr(addr1, addr2); +} +#endif + +#ifndef HAVE_NLA_PUT_BE64 +static inline int nla_put_be64(struct sk_buff *skb, int attrtype, __be64 value) +{ + return nla_put(skb, attrtype, sizeof(__be64), &value); +} + +static inline int nla_put_net64(struct sk_buff *skb, int attrtype, __be64 value) +{ + return nla_put_be64(skb, attrtype | NLA_F_NET_BYTEORDER, value); +} +#endif + +#ifdef HAVE_NL_INFO_PORTID +#define NETLINK_PORTID(skb) NETLINK_CB(skb).portid +#else +#define NETLINK_PORTID(skb) NETLINK_CB(skb).pid +#endif + +#ifndef HAVE_NS_CAPABLE +#define ns_capable(ns, cap) capable(cap) +#endif + +#ifdef HAVE_NFNL_LOCK_SUBSYS +#define lock_nfnl() nfnl_lock(NFNL_SUBSYS_IPSET) +#define unlock_nfnl() nfnl_unlock(NFNL_SUBSYS_IPSET) +#else +#define lock_nfnl() nfnl_lock() +#define unlock_nfnl() nfnl_unlock() +#endif + +#ifdef NLA_PUT_NET16 +static inline int nla_put_be16(struct sk_buff *skb, int attrtype, __be16 value) +{ + return nla_put(skb, attrtype, sizeof(__be16), &value); +} + +static inline int nla_put_net16(struct sk_buff *skb, int attrtype, __be16 value) +{ + return nla_put_be16(skb, attrtype | NLA_F_NET_BYTEORDER, value); +} + +static inline int nla_put_be32(struct sk_buff *skb, int attrtype, __be32 value) +{ + return nla_put(skb, attrtype, sizeof(__be32), &value); +} + +static inline int nla_put_net32(struct sk_buff *skb, int attrtype, __be32 value) +{ + return nla_put_be32(skb, attrtype | NLA_F_NET_BYTEORDER, value); +} +#endif + +#endif /* __IP_SET_COMPAT_H */ -- cgit v1.2.3