aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/linux/netfilter_bridge/ebtables.h3
-rw-r--r--include/net/netfilter/nf_tables.h103
-rw-r--r--include/net/netfilter/nft_meta.h4
-rw-r--r--include/uapi/linux/netfilter/nf_tables.h40
-rw-r--r--include/uapi/linux/netfilter_bridge/ebtables.h2
5 files changed, 116 insertions, 36 deletions
diff --git a/include/linux/netfilter_bridge/ebtables.h b/include/linux/netfilter_bridge/ebtables.h
index 34e7a2b7f867..f1bd3962e6b6 100644
--- a/include/linux/netfilter_bridge/ebtables.h
+++ b/include/linux/netfilter_bridge/ebtables.h
@@ -12,9 +12,10 @@
12#ifndef __LINUX_BRIDGE_EFF_H 12#ifndef __LINUX_BRIDGE_EFF_H
13#define __LINUX_BRIDGE_EFF_H 13#define __LINUX_BRIDGE_EFF_H
14 14
15#include <linux/if.h>
16#include <linux/if_ether.h>
15#include <uapi/linux/netfilter_bridge/ebtables.h> 17#include <uapi/linux/netfilter_bridge/ebtables.h>
16 18
17
18/* return values for match() functions */ 19/* return values for match() functions */
19#define EBT_MATCH 0 20#define EBT_MATCH 0
20#define EBT_NOMATCH 1 21#define EBT_NOMATCH 1
diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
index d6a2f0ed5130..e6bcf55dcf20 100644
--- a/include/net/netfilter/nf_tables.h
+++ b/include/net/netfilter/nf_tables.h
@@ -1,6 +1,7 @@
1#ifndef _NET_NF_TABLES_H 1#ifndef _NET_NF_TABLES_H
2#define _NET_NF_TABLES_H 2#define _NET_NF_TABLES_H
3 3
4#include <linux/module.h>
4#include <linux/list.h> 5#include <linux/list.h>
5#include <linux/netfilter.h> 6#include <linux/netfilter.h>
6#include <linux/netfilter/nfnetlink.h> 7#include <linux/netfilter/nfnetlink.h>
@@ -36,29 +37,43 @@ static inline void nft_set_pktinfo(struct nft_pktinfo *pkt,
36 pkt->xt.family = ops->pf; 37 pkt->xt.family = ops->pf;
37} 38}
38 39
40/**
41 * struct nft_verdict - nf_tables verdict
42 *
43 * @code: nf_tables/netfilter verdict code
44 * @chain: destination chain for NFT_JUMP/NFT_GOTO
45 */
46struct nft_verdict {
47 u32 code;
48 struct nft_chain *chain;
49};
50
39struct nft_data { 51struct nft_data {
40 union { 52 union {
41 u32 data[4]; 53 u32 data[4];
42 struct { 54 struct nft_verdict verdict;
43 u32 verdict;
44 struct nft_chain *chain;
45 };
46 }; 55 };
47} __attribute__((aligned(__alignof__(u64)))); 56} __attribute__((aligned(__alignof__(u64))));
48 57
49static inline int nft_data_cmp(const struct nft_data *d1, 58/**
50 const struct nft_data *d2, 59 * struct nft_regs - nf_tables register set
51 unsigned int len) 60 *
52{ 61 * @data: data registers
53 return memcmp(d1->data, d2->data, len); 62 * @verdict: verdict register
54} 63 *
64 * The first four data registers alias to the verdict register.
65 */
66struct nft_regs {
67 union {
68 u32 data[20];
69 struct nft_verdict verdict;
70 };
71};
55 72
56static inline void nft_data_copy(struct nft_data *dst, 73static inline void nft_data_copy(u32 *dst, const struct nft_data *src,
57 const struct nft_data *src) 74 unsigned int len)
58{ 75{
59 BUILD_BUG_ON(__alignof__(*dst) != __alignof__(u64)); 76 memcpy(dst, src, len);
60 *(u64 *)&dst->data[0] = *(u64 *)&src->data[0];
61 *(u64 *)&dst->data[2] = *(u64 *)&src->data[2];
62} 77}
63 78
64static inline void nft_data_debug(const struct nft_data *data) 79static inline void nft_data_debug(const struct nft_data *data)
@@ -96,7 +111,8 @@ struct nft_data_desc {
96 unsigned int len; 111 unsigned int len;
97}; 112};
98 113
99int nft_data_init(const struct nft_ctx *ctx, struct nft_data *data, 114int nft_data_init(const struct nft_ctx *ctx,
115 struct nft_data *data, unsigned int size,
100 struct nft_data_desc *desc, const struct nlattr *nla); 116 struct nft_data_desc *desc, const struct nlattr *nla);
101void nft_data_uninit(const struct nft_data *data, enum nft_data_types type); 117void nft_data_uninit(const struct nft_data *data, enum nft_data_types type);
102int nft_data_dump(struct sk_buff *skb, int attr, const struct nft_data *data, 118int nft_data_dump(struct sk_buff *skb, int attr, const struct nft_data *data,
@@ -112,12 +128,14 @@ static inline enum nft_registers nft_type_to_reg(enum nft_data_types type)
112 return type == NFT_DATA_VERDICT ? NFT_REG_VERDICT : NFT_REG_1; 128 return type == NFT_DATA_VERDICT ? NFT_REG_VERDICT : NFT_REG_1;
113} 129}
114 130
115int nft_validate_input_register(enum nft_registers reg); 131unsigned int nft_parse_register(const struct nlattr *attr);
116int nft_validate_output_register(enum nft_registers reg); 132int nft_dump_register(struct sk_buff *skb, unsigned int attr, unsigned int reg);
117int nft_validate_data_load(const struct nft_ctx *ctx, enum nft_registers reg,
118 const struct nft_data *data,
119 enum nft_data_types type);
120 133
134int nft_validate_register_load(enum nft_registers reg, unsigned int len);
135int nft_validate_register_store(const struct nft_ctx *ctx,
136 enum nft_registers reg,
137 const struct nft_data *data,
138 enum nft_data_types type, unsigned int len);
121 139
122/** 140/**
123 * struct nft_userdata - user defined data associated with an object 141 * struct nft_userdata - user defined data associated with an object
@@ -141,7 +159,10 @@ struct nft_userdata {
141 * @priv: element private data and extensions 159 * @priv: element private data and extensions
142 */ 160 */
143struct nft_set_elem { 161struct nft_set_elem {
144 struct nft_data key; 162 union {
163 u32 buf[NFT_DATA_VALUE_MAXLEN / sizeof(u32)];
164 struct nft_data val;
165 } key;
145 void *priv; 166 void *priv;
146}; 167};
147 168
@@ -216,15 +237,15 @@ struct nft_expr;
216 */ 237 */
217struct nft_set_ops { 238struct nft_set_ops {
218 bool (*lookup)(const struct nft_set *set, 239 bool (*lookup)(const struct nft_set *set,
219 const struct nft_data *key, 240 const u32 *key,
220 const struct nft_set_ext **ext); 241 const struct nft_set_ext **ext);
221 bool (*update)(struct nft_set *set, 242 bool (*update)(struct nft_set *set,
222 const struct nft_data *key, 243 const u32 *key,
223 void *(*new)(struct nft_set *, 244 void *(*new)(struct nft_set *,
224 const struct nft_expr *, 245 const struct nft_expr *,
225 struct nft_data []), 246 struct nft_regs *),
226 const struct nft_expr *expr, 247 const struct nft_expr *expr,
227 struct nft_data data[], 248 struct nft_regs *regs,
228 const struct nft_set_ext **ext); 249 const struct nft_set_ext **ext);
229 250
230 int (*insert)(const struct nft_set *set, 251 int (*insert)(const struct nft_set *set,
@@ -350,6 +371,7 @@ void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set,
350 * @NFT_SET_EXT_TIMEOUT: element timeout 371 * @NFT_SET_EXT_TIMEOUT: element timeout
351 * @NFT_SET_EXT_EXPIRATION: element expiration time 372 * @NFT_SET_EXT_EXPIRATION: element expiration time
352 * @NFT_SET_EXT_USERDATA: user data associated with the element 373 * @NFT_SET_EXT_USERDATA: user data associated with the element
374 * @NFT_SET_EXT_EXPR: expression assiociated with the element
353 * @NFT_SET_EXT_NUM: number of extension types 375 * @NFT_SET_EXT_NUM: number of extension types
354 */ 376 */
355enum nft_set_extensions { 377enum nft_set_extensions {
@@ -359,6 +381,7 @@ enum nft_set_extensions {
359 NFT_SET_EXT_TIMEOUT, 381 NFT_SET_EXT_TIMEOUT,
360 NFT_SET_EXT_EXPIRATION, 382 NFT_SET_EXT_EXPIRATION,
361 NFT_SET_EXT_USERDATA, 383 NFT_SET_EXT_USERDATA,
384 NFT_SET_EXT_EXPR,
362 NFT_SET_EXT_NUM 385 NFT_SET_EXT_NUM
363}; 386};
364 387
@@ -470,6 +493,11 @@ static inline struct nft_userdata *nft_set_ext_userdata(const struct nft_set_ext
470 return nft_set_ext(ext, NFT_SET_EXT_USERDATA); 493 return nft_set_ext(ext, NFT_SET_EXT_USERDATA);
471} 494}
472 495
496static inline struct nft_expr *nft_set_ext_expr(const struct nft_set_ext *ext)
497{
498 return nft_set_ext(ext, NFT_SET_EXT_EXPR);
499}
500
473static inline bool nft_set_elem_expired(const struct nft_set_ext *ext) 501static inline bool nft_set_elem_expired(const struct nft_set_ext *ext)
474{ 502{
475 return nft_set_ext_exists(ext, NFT_SET_EXT_EXPIRATION) && 503 return nft_set_ext_exists(ext, NFT_SET_EXT_EXPIRATION) &&
@@ -484,8 +512,7 @@ static inline struct nft_set_ext *nft_set_elem_ext(const struct nft_set *set,
484 512
485void *nft_set_elem_init(const struct nft_set *set, 513void *nft_set_elem_init(const struct nft_set *set,
486 const struct nft_set_ext_tmpl *tmpl, 514 const struct nft_set_ext_tmpl *tmpl,
487 const struct nft_data *key, 515 const u32 *key, const u32 *data,
488 const struct nft_data *data,
489 u64 timeout, gfp_t gfp); 516 u64 timeout, gfp_t gfp);
490void nft_set_elem_destroy(const struct nft_set *set, void *elem); 517void nft_set_elem_destroy(const struct nft_set *set, void *elem);
491 518
@@ -556,6 +583,7 @@ static inline void nft_set_gc_batch_add(struct nft_set_gc_batch *gcb,
556 * @policy: netlink attribute policy 583 * @policy: netlink attribute policy
557 * @maxattr: highest netlink attribute number 584 * @maxattr: highest netlink attribute number
558 * @family: address family for AF-specific types 585 * @family: address family for AF-specific types
586 * @flags: expression type flags
559 */ 587 */
560struct nft_expr_type { 588struct nft_expr_type {
561 const struct nft_expr_ops *(*select_ops)(const struct nft_ctx *, 589 const struct nft_expr_ops *(*select_ops)(const struct nft_ctx *,
@@ -567,8 +595,11 @@ struct nft_expr_type {
567 const struct nla_policy *policy; 595 const struct nla_policy *policy;
568 unsigned int maxattr; 596 unsigned int maxattr;
569 u8 family; 597 u8 family;
598 u8 flags;
570}; 599};
571 600
601#define NFT_EXPR_STATEFUL 0x1
602
572/** 603/**
573 * struct nft_expr_ops - nf_tables expression operations 604 * struct nft_expr_ops - nf_tables expression operations
574 * 605 *
@@ -584,7 +615,7 @@ struct nft_expr_type {
584struct nft_expr; 615struct nft_expr;
585struct nft_expr_ops { 616struct nft_expr_ops {
586 void (*eval)(const struct nft_expr *expr, 617 void (*eval)(const struct nft_expr *expr,
587 struct nft_data data[NFT_REG_MAX + 1], 618 struct nft_regs *regs,
588 const struct nft_pktinfo *pkt); 619 const struct nft_pktinfo *pkt);
589 unsigned int size; 620 unsigned int size;
590 621
@@ -622,6 +653,18 @@ static inline void *nft_expr_priv(const struct nft_expr *expr)
622 return (void *)expr->data; 653 return (void *)expr->data;
623} 654}
624 655
656struct nft_expr *nft_expr_init(const struct nft_ctx *ctx,
657 const struct nlattr *nla);
658void nft_expr_destroy(const struct nft_ctx *ctx, struct nft_expr *expr);
659int nft_expr_dump(struct sk_buff *skb, unsigned int attr,
660 const struct nft_expr *expr);
661
662static inline void nft_expr_clone(struct nft_expr *dst, struct nft_expr *src)
663{
664 __module_get(src->ops->type->owner);
665 memcpy(dst, src, src->ops->size);
666}
667
625/** 668/**
626 * struct nft_rule - nf_tables rule 669 * struct nft_rule - nf_tables rule
627 * 670 *
diff --git a/include/net/netfilter/nft_meta.h b/include/net/netfilter/nft_meta.h
index 0ee47c3e2e31..711887a09e91 100644
--- a/include/net/netfilter/nft_meta.h
+++ b/include/net/netfilter/nft_meta.h
@@ -26,11 +26,11 @@ int nft_meta_set_dump(struct sk_buff *skb,
26 const struct nft_expr *expr); 26 const struct nft_expr *expr);
27 27
28void nft_meta_get_eval(const struct nft_expr *expr, 28void nft_meta_get_eval(const struct nft_expr *expr,
29 struct nft_data data[NFT_REG_MAX + 1], 29 struct nft_regs *regs,
30 const struct nft_pktinfo *pkt); 30 const struct nft_pktinfo *pkt);
31 31
32void nft_meta_set_eval(const struct nft_expr *expr, 32void nft_meta_set_eval(const struct nft_expr *expr,
33 struct nft_data data[NFT_REG_MAX + 1], 33 struct nft_regs *regs,
34 const struct nft_pktinfo *pkt); 34 const struct nft_pktinfo *pkt);
35 35
36#endif 36#endif
diff --git a/include/uapi/linux/netfilter/nf_tables.h b/include/uapi/linux/netfilter/nf_tables.h
index 05ee1e0804a3..5fa1cd04762e 100644
--- a/include/uapi/linux/netfilter/nf_tables.h
+++ b/include/uapi/linux/netfilter/nf_tables.h
@@ -5,16 +5,45 @@
5#define NFT_CHAIN_MAXNAMELEN 32 5#define NFT_CHAIN_MAXNAMELEN 32
6#define NFT_USERDATA_MAXLEN 256 6#define NFT_USERDATA_MAXLEN 256
7 7
8/**
9 * enum nft_registers - nf_tables registers
10 *
11 * nf_tables used to have five registers: a verdict register and four data
12 * registers of size 16. The data registers have been changed to 16 registers
13 * of size 4. For compatibility reasons, the NFT_REG_[1-4] registers still
14 * map to areas of size 16, the 4 byte registers are addressed using
15 * NFT_REG32_00 - NFT_REG32_15.
16 */
8enum nft_registers { 17enum nft_registers {
9 NFT_REG_VERDICT, 18 NFT_REG_VERDICT,
10 NFT_REG_1, 19 NFT_REG_1,
11 NFT_REG_2, 20 NFT_REG_2,
12 NFT_REG_3, 21 NFT_REG_3,
13 NFT_REG_4, 22 NFT_REG_4,
14 __NFT_REG_MAX 23 __NFT_REG_MAX,
24
25 NFT_REG32_00 = 8,
26 MFT_REG32_01,
27 NFT_REG32_02,
28 NFT_REG32_03,
29 NFT_REG32_04,
30 NFT_REG32_05,
31 NFT_REG32_06,
32 NFT_REG32_07,
33 NFT_REG32_08,
34 NFT_REG32_09,
35 NFT_REG32_10,
36 NFT_REG32_11,
37 NFT_REG32_12,
38 NFT_REG32_13,
39 NFT_REG32_14,
40 NFT_REG32_15,
15}; 41};
16#define NFT_REG_MAX (__NFT_REG_MAX - 1) 42#define NFT_REG_MAX (__NFT_REG_MAX - 1)
17 43
44#define NFT_REG_SIZE 16
45#define NFT_REG32_SIZE 4
46
18/** 47/**
19 * enum nft_verdicts - nf_tables internal verdicts 48 * enum nft_verdicts - nf_tables internal verdicts
20 * 49 *
@@ -209,6 +238,7 @@ enum nft_rule_compat_attributes {
209 * @NFT_SET_INTERVAL: set contains intervals 238 * @NFT_SET_INTERVAL: set contains intervals
210 * @NFT_SET_MAP: set is used as a dictionary 239 * @NFT_SET_MAP: set is used as a dictionary
211 * @NFT_SET_TIMEOUT: set uses timeouts 240 * @NFT_SET_TIMEOUT: set uses timeouts
241 * @NFT_SET_EVAL: set contains expressions for evaluation
212 */ 242 */
213enum nft_set_flags { 243enum nft_set_flags {
214 NFT_SET_ANONYMOUS = 0x1, 244 NFT_SET_ANONYMOUS = 0x1,
@@ -216,6 +246,7 @@ enum nft_set_flags {
216 NFT_SET_INTERVAL = 0x4, 246 NFT_SET_INTERVAL = 0x4,
217 NFT_SET_MAP = 0x8, 247 NFT_SET_MAP = 0x8,
218 NFT_SET_TIMEOUT = 0x10, 248 NFT_SET_TIMEOUT = 0x10,
249 NFT_SET_EVAL = 0x20,
219}; 250};
220 251
221/** 252/**
@@ -293,6 +324,7 @@ enum nft_set_elem_flags {
293 * @NFTA_SET_ELEM_TIMEOUT: timeout value (NLA_U64) 324 * @NFTA_SET_ELEM_TIMEOUT: timeout value (NLA_U64)
294 * @NFTA_SET_ELEM_EXPIRATION: expiration time (NLA_U64) 325 * @NFTA_SET_ELEM_EXPIRATION: expiration time (NLA_U64)
295 * @NFTA_SET_ELEM_USERDATA: user data (NLA_BINARY) 326 * @NFTA_SET_ELEM_USERDATA: user data (NLA_BINARY)
327 * @NFTA_SET_ELEM_EXPR: expression (NLA_NESTED: nft_expr_attributes)
296 */ 328 */
297enum nft_set_elem_attributes { 329enum nft_set_elem_attributes {
298 NFTA_SET_ELEM_UNSPEC, 330 NFTA_SET_ELEM_UNSPEC,
@@ -302,6 +334,7 @@ enum nft_set_elem_attributes {
302 NFTA_SET_ELEM_TIMEOUT, 334 NFTA_SET_ELEM_TIMEOUT,
303 NFTA_SET_ELEM_EXPIRATION, 335 NFTA_SET_ELEM_EXPIRATION,
304 NFTA_SET_ELEM_USERDATA, 336 NFTA_SET_ELEM_USERDATA,
337 NFTA_SET_ELEM_EXPR,
305 __NFTA_SET_ELEM_MAX 338 __NFTA_SET_ELEM_MAX
306}; 339};
307#define NFTA_SET_ELEM_MAX (__NFTA_SET_ELEM_MAX - 1) 340#define NFTA_SET_ELEM_MAX (__NFTA_SET_ELEM_MAX - 1)
@@ -359,6 +392,9 @@ enum nft_data_attributes {
359}; 392};
360#define NFTA_DATA_MAX (__NFTA_DATA_MAX - 1) 393#define NFTA_DATA_MAX (__NFTA_DATA_MAX - 1)
361 394
395/* Maximum length of a value */
396#define NFT_DATA_VALUE_MAXLEN 64
397
362/** 398/**
363 * enum nft_verdict_attributes - nf_tables verdict netlink attributes 399 * enum nft_verdict_attributes - nf_tables verdict netlink attributes
364 * 400 *
@@ -531,6 +567,7 @@ enum nft_dynset_ops {
531 * @NFTA_DYNSET_SREG_KEY: source register of the key (NLA_U32) 567 * @NFTA_DYNSET_SREG_KEY: source register of the key (NLA_U32)
532 * @NFTA_DYNSET_SREG_DATA: source register of the data (NLA_U32) 568 * @NFTA_DYNSET_SREG_DATA: source register of the data (NLA_U32)
533 * @NFTA_DYNSET_TIMEOUT: timeout value for the new element (NLA_U64) 569 * @NFTA_DYNSET_TIMEOUT: timeout value for the new element (NLA_U64)
570 * @NFTA_DYNSET_EXPR: expression (NLA_NESTED: nft_expr_attributes)
534 */ 571 */
535enum nft_dynset_attributes { 572enum nft_dynset_attributes {
536 NFTA_DYNSET_UNSPEC, 573 NFTA_DYNSET_UNSPEC,
@@ -540,6 +577,7 @@ enum nft_dynset_attributes {
540 NFTA_DYNSET_SREG_KEY, 577 NFTA_DYNSET_SREG_KEY,
541 NFTA_DYNSET_SREG_DATA, 578 NFTA_DYNSET_SREG_DATA,
542 NFTA_DYNSET_TIMEOUT, 579 NFTA_DYNSET_TIMEOUT,
580 NFTA_DYNSET_EXPR,
543 __NFTA_DYNSET_MAX, 581 __NFTA_DYNSET_MAX,
544}; 582};
545#define NFTA_DYNSET_MAX (__NFTA_DYNSET_MAX - 1) 583#define NFTA_DYNSET_MAX (__NFTA_DYNSET_MAX - 1)
diff --git a/include/uapi/linux/netfilter_bridge/ebtables.h b/include/uapi/linux/netfilter_bridge/ebtables.h
index ba993360dbe9..773dfe8924c7 100644
--- a/include/uapi/linux/netfilter_bridge/ebtables.h
+++ b/include/uapi/linux/netfilter_bridge/ebtables.h
@@ -12,9 +12,7 @@
12 12
13#ifndef _UAPI__LINUX_BRIDGE_EFF_H 13#ifndef _UAPI__LINUX_BRIDGE_EFF_H
14#define _UAPI__LINUX_BRIDGE_EFF_H 14#define _UAPI__LINUX_BRIDGE_EFF_H
15#include <linux/if.h>
16#include <linux/netfilter_bridge.h> 15#include <linux/netfilter_bridge.h>
17#include <linux/if_ether.h>
18 16
19#define EBT_TABLE_MAXNAMELEN 32 17#define EBT_TABLE_MAXNAMELEN 32
20#define EBT_CHAIN_MAXNAMELEN EBT_TABLE_MAXNAMELEN 18#define EBT_CHAIN_MAXNAMELEN EBT_TABLE_MAXNAMELEN