summaryrefslogtreecommitdiffstats
path: root/kernel/include/linux/netfilter/ipset/ip_set_compat.h.in
blob: 72b77b3963b7f29e575dee46e438ab7fdd3d7353 (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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
#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.
 */

#@HAVE_STRUCT_XT_ACTION_PARAM@ HAVE_STRUCT_XT_ACTION_PARAM
#@HAVE_VZALLOC@ HAVE_VZALLOC
#@HAVE_ETHER_ADDR_EQUAL@ HAVE_ETHER_ADDR_EQUAL
#@HAVE_IS_ZERO_ETHER_ADDR@ HAVE_IS_ZERO_ETHER_ADDR
#@HAVE_NLA_PUT_BE16@ HAVE_NLA_PUT_BE16
#@HAVE_NLA_PUT_BE64@ HAVE_NLA_PUT_BE64
#@HAVE_NLA_PUT_64BIT@ HAVE_NLA_PUT_64BIT
#@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
#@HAVE_NF_BRIDGE_GET_PHYSDEV@ HAVE_NF_BRIDGE_GET_PHYSDEV
#@HAVE_NLA_PUT_IN_ADDR@ HAVE_NLA_PUT_IN_ADDR
#@HAVE_NET_IN_NFNL_CALLBACK_FN@ HAVE_NET_IN_NFNL_CALLBACK_FN
#@HAVE_EXPORT_SYMBOL_GPL_IN_MODULE_H@ HAVE_EXPORT_SYMBOL_GPL_IN_MODULE_H
#@HAVE_TC_SKB_PROTOCOL@ HAVE_TC_SKB_PROTOCOL
#@HAVE_NET_IN_XT_ACTION_PARAM@ HAVE_NET_IN_XT_ACTION_PARAM
#@HAVE_STATE_IN_XT_ACTION_PARAM@ HAVE_STATE_IN_XT_ACTION_PARAM
#@HAVE_XT_FAMILY@ HAVE_XT_FAMILY
#@HAVE_XT_NET@ HAVE_XT_NET
#@HAVE_NFNL_MSG_TYPE@ HAVE_NFNL_MSG_TYPE
#@HAVE_NETLINK_EXTENDED_ACK@ HAVE_NETLINK_EXTENDED_ACK
#@HAVE_PASSING_EXTENDED_ACK_TO_PARSERS@ HAVE_PASSING_EXTENDED_ACK_TO_PARSERS
#@HAVE_PASSING_EXTENDED_ACK_TO_CALLBACKS@ HAVE_PASSING_EXTENDED_ACK_TO_CALLBACKS
#@HAVE_TYPEDEF_SCTP_SCTPHDR_T@ HAVE_TYPEDEF_SCTP_SCTPHDR_T
#@HAVE_TIMER_SETUP@ HAVE_TIMER_SETUP
#@HAVE_LOCKDEP_NFNL_IS_HELD@ HAVE_LOCKDEP_NFNL_IS_HELD

#ifdef HAVE_EXPORT_SYMBOL_GPL_IN_MODULE_H
#include <linux/module.h>
#endif

#ifdef HAVE_EXPORT_H
#include <linux/export.h>
#endif

#ifndef IP_SET_COMPAT_HEADERS

#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

#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
#ifndef RCU_INIT_POINTER
#define RCU_INIT_POINTER(p, v) \
	do { \
		p = v; \
	} while (0)
#endif
#else

#ifndef RCU_INITIALIZER
#define RCU_INITIALIZER(v)	(typeof(*(v)) __force __rcu *)(v)
#endif
#ifndef RCU_INIT_POINTER
#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

#if !defined(HAVE_ETHER_ADDR_EQUAL) || !defined(HAVE_IS_ZERO_ETHER_ADDR)
#include <linux/etherdevice.h>

#ifndef HAVE_ETHER_ADDR_EQUAL
static inline bool ether_addr_equal(const u8 *addr1, const u8 *addr2)
{
	return !compare_ether_addr(addr1, addr2);
}
#endif

#ifndef HAVE_IS_ZERO_ETHER_ADDR
static inline bool is_zero_ether_addr(const u8 *addr)
{
	return (*(const u16 *)(addr + 0) |
		*(const u16 *)(addr + 2) |
		*(const u16 *)(addr + 4)) == 0;
}
#endif
#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_NLA_PUT_64BIT
#define IPSET_NLA_PUT_NET64(skb, t, v, pa) nla_put_net64(skb, t, v, pa)
#else
#define IPSET_NLA_PUT_NET64(skb, t, v, pa) nla_put_net64(skb, t, v)
#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

#ifndef HAVE_LOCKDEP_NFNL_IS_HELD
#define lockdep_nfnl_is_held(x)	1
#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
#include <linux/vmalloc.h>
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

#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
#ifndef HAVE_NF_BRIDGE_GET_PHYSDEV
static inline struct net_device *
nf_bridge_get_physindev(const struct sk_buff *skb)
{
	return skb->nf_bridge ? skb->nf_bridge->physindev : NULL;
}

static inline struct net_device *
nf_bridge_get_physoutdev(const struct sk_buff *skb)
{
	return skb->nf_bridge ? skb->nf_bridge->physoutdev : NULL;
}
#endif
#endif

#ifndef HAVE_NLA_PUT_IN_ADDR
static inline int nla_put_in_addr(struct sk_buff *skb, int attrtype,
				  __be32 addr)
{
	return nla_put_be32(skb, attrtype, addr);
}

static inline int nla_put_in6_addr(struct sk_buff *skb, int attrtype,
				   const struct in6_addr *addr)
{
	return nla_put(skb, attrtype, sizeof(*addr), addr);
}
#endif

#ifdef HAVE_PASSING_EXTENDED_ACK_TO_CALLBACKS
#define IPSET_CBFN(fn, net, nl, skb, nlh, cda, e)	fn(net, nl, skb, nlh, cda, e)
#define IPSET_SOCK_NET(net, ctnl)			net
#elif defined(HAVE_NET_IN_NFNL_CALLBACK_FN)
#define IPSET_CBFN(fn, net, nl, skb, nlh, cda, e)	fn(net, nl, skb, nlh, cda)
#define IPSET_SOCK_NET(net, ctnl)			net
#else
#define IPSET_CBFN(fn, net, nl, skb, nlh, cda,e)	fn(nl, skb, nlh, cda)
#define IPSET_SOCK_NET(net, ctnl)			sock_net(ctnl)
#endif

#ifndef HAVE_TC_SKB_PROTOCOL
#include <linux/if_vlan.h>
static inline __be16 tc_skb_protocol(const struct sk_buff *skb)
{
	if (vlan_tx_tag_present(skb))
		return skb->vlan_proto;
	return skb->protocol;
}
#endif

#ifdef HAVE_XT_NET
#define IPSET_DEV_NET(par)	xt_net(par)
#elif defined(HAVE_NET_IN_XT_ACTION_PARAM)
#define IPSET_DEV_NET(par)	(par)->net
#else
#define IPSET_DEV_NET(par)	dev_net((par)->in ? (par)->in : (par)->out)
#endif

#ifndef HAVE_NFNL_MSG_TYPE
static inline u16 nfnl_msg_type(u8 subsys, u8 msg_type)
{
	return subsys << 8 | msg_type;
}
#endif

#ifdef HAVE_NETLINK_EXTENDED_ACK
#define NETLINK_ACK(in_skb, nlh, err, extack)	netlink_ack(in_skb, nlh, err, extack)
#else
#define NETLINK_ACK(in_skb, nlh, err, extack)	netlink_ack(in_skb, nlh, err)
#endif

#ifdef HAVE_PASSING_EXTENDED_ACK_TO_PARSERS
#define NLA_PARSE(t, m, h, l, p, e)		nla_parse(t, m, h, l, p, e)
#define NLA_PARSE_NESTED(t, m, n, p, e)		nla_parse_nested(t, m, n, p, e)
#else
#define NLA_PARSE(t, m, h, l, p, e)		nla_parse(t, m, h, l, p)
#define NLA_PARSE_NESTED(t, m, n, p, e)		nla_parse_nested(t, m, n, p)
#endif

#ifdef HAVE_STATE_IN_XT_ACTION_PARAM
#define XAP_STATE(par)		(par->state)
#else
#define XAP_STATE(par)		par
#endif

#ifdef HAVE_XT_FAMILY
#define XT_FAMILY(par)		xt_family(par)
#else
#define XT_FAMILY(par)		(par)->family
#endif

#ifdef HAVE_TIMER_SETUP
#define GC_ARG			struct timer_list *t
#define TIMER_SETUP(a, b)	timer_setup(a, b, 0)
#define INIT_GC_VARS(type, var)				\
	struct type *var = from_timer(var, t, gc); 	\
	struct ip_set *set = var->set
#else
#define GC_ARG			unsigned long ul_set
#define TIMER_SETUP(a, b)	setup_timer(a, b, (unsigned long)set)
#define INIT_GC_VARS(type, var)				\
	struct ip_set *set = (struct ip_set *)ul_set;	\
	struct type *var = set->data
#endif

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

#ifndef pr_warn
#define pr_warn	pr_warning
#endif

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

#endif /* IP_SET_COMPAT_HEADERS */
#endif /* __IP_SET_COMPAT_H */