summaryrefslogtreecommitdiffstats
path: root/kernel/include/linux/netfilter/ipset/ip_set_compat.h.in
blob: 5938d8f5b5aa8269491b581cf81eaa07a61885e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#ifndef __IP_SET_COMPAT_H
#define __IP_SET_COMPAT_H

#ifndef CONFIG_IP_SET_MAX
#ifdef IP_SET_MAX
#define CONFIG_IP_SET_MAX	IP_SET_MAX
#else
#define CONFIG_IP_SET_MAX	256
#endif
#endif

#ifndef IS_ENABLED
#define __X_ARG_PLACEHOLDER_1 0,
#define x_config_enabled(cfg) _x_config_enabled(cfg)
#define _x_config_enabled(value) __x_config_enabled(__X_ARG_PLACEHOLDER_##value)
#define __x_config_enabled(arg1_or_junk) ___x_config_enabled(arg1_or_junk 1, 0)
#define ___x_config_enabled(__ignored, val, ...) val

#define IS_ENABLED(option) \
	(x_config_enabled(option) || x_config_enabled(option##_MODULE))
#endif

#@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_BE16@ HAVE_NLA_PUT_BE16
#@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
#@HAVE_USER_NS_IN_STRUCT_NET@ HAVE_USER_NS_IN_STRUCT_NET
#@HAVE_RBTREE_POSTORDER_FOR_EACH_ENTRY_SAFE@ HAVE_RBTREE_POSTORDER_FOR_EACH_ENTRY_SAFE
#@HAVE_KVFREE@ HAVE_KVFREE
#@HAVE_XT_MTCHK_PARAM_STRUCT_NET@ HAVE_XT_MTCHK_PARAM_STRUCT_NET
#@HAVE_TCF_EMATCH_OPS_CHANGE_ARG_NET@ HAVE_TCF_EMATCH_OPS_CHANGE_ARG_NET
#@HAVE_TCF_EMATCH_STRUCT_NET@ HAVE_TCF_EMATCH_STRUCT_NET
#@HAVE_LIST_LAST_ENTRY@ HAVE_LIST_LAST_ENTRY
#@HAVE_LIST_NEXT_ENTRY@ HAVE_LIST_NEXT_ENTRY
#@HAVE_ETHER_ADDR_COPY@ HAVE_ETHER_ADDR_COPY

/* 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 <linux/version.h>
#include <linux/netlink.h>

#ifndef rcu_dereference_bh
#define rcu_dereference_bh(p)		rcu_dereference(p)
#endif

#ifndef rcu_dereference_protected
#define rcu_dereference_protected(p, c)	(p)
#endif

#ifndef rcu_dereference_bh_check
#define rcu_dereference_bh_check(p, c)	rcu_dereference_bh(p)
#endif

#ifndef __rcu
#define	__rcu
#define RCU_INIT_POINTER(p, v) \
	do { \
		p = v; \
	} while (0)
#else

#ifndef RCU_INITIALIZER
#define RCU_INITIALIZER(v)	(typeof(*(v)) __force __rcu *)(v)
#define RCU_INIT_POINTER(p, v)	\
	do { \
		p = RCU_INITIALIZER(v); \
	} while (0)
#endif
#endif

#ifndef kfree_rcu

static inline void kfree_call_rcu(struct rcu_head *head,
				  void (*func)(struct rcu_head *rcu))
{
	call_rcu(head, func);
}

#define __is_kfree_rcu_offset(offset) ((offset) < 4096)

#define __kfree_rcu(head, offset)	\
do {				\
	BUILD_BUG_ON(!__is_kfree_rcu_offset(offset));	\
	kfree_call_rcu(head, (void (*)(struct rcu_head *))(unsigned long)(offset)); \
} while (0)

#define kfree_rcu(ptr, rcu_head)	\
	__kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head))
#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 <linux/etherdevice.h>

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_USER_NS_IN_STRUCT_NET
#define ns_capable(ns, cap)	capable(cap)
#endif

#ifndef HAVE_NFNL_LOCK_SUBSYS
#define nfnl_lock(x)		nfnl_lock()
#define nfnl_unlock(x)		nfnl_unlock()
#endif

#if HAVE_IPV6_SKIP_EXTHDR_ARGS == 3
#define ipv6_skip_exthdr(skbuff, start, nexthdrp, frag_offp)	\
	ipv6_skip_exthdr(skbuff, start, nexthdrp)
#endif

#ifndef HAVE_KVFREE
static inline void kvfree(const void *addr)
{
	if (is_vmalloc_addr(addr))
		vfree(addr);
	else
		kfree(addr);
}
#endif

#ifndef HAVE_NLA_PUT_BE16
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

#ifndef HAVE_LIST_LAST_ENTRY
#define list_last_entry(ptr, type, member) \
	list_entry((ptr)->prev, type, member)
#endif
#ifndef HAVE_LIST_NEXT_ENTRY
#define list_next_entry(pos, member)	\
	list_entry((pos)->member.next, typeof(*(pos)), member)
#define list_prev_entry(pos, member)	\
	list_entry((pos)->member.prev, typeof(*(pos)), member)
#endif

#ifndef HAVE_ETHER_ADDR_COPY
#define ether_addr_copy(dst, src)	memcpy(dst, src, ETH_ALEN)
#endif

#ifndef smp_mb__before_atomic
#define smp_mb__before_atomic()	smp_mb()
#define smp_mb__after_atomic()	smp_mb()
#endif

#ifndef __aligned_u64
#define __aligned_u64 __u64
#endif

#ifndef pr_warn
#define pr_warn	pr_warning
#endif

#ifndef SIZE_MAX
#define SIZE_MAX	(~(size_t)0)
#endif

#endif /* __IP_SET_COMPAT_H */