aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2015-04-05 08:41:08 -0400
committerPablo Neira Ayuso <pablo@netfilter.org>2015-04-08 10:58:27 -0400
commit22fe54d5fefcfa98c58cc2f4607dd26d9648b3f5 (patch)
tree153c791a6efb2c0eb7aca4baecb84cb76199b706 /include
parent11113e190bf0ad73086884f87efccc994ff28b3d (diff)
netfilter: nf_tables: add support for dynamic set updates
Add a new "dynset" expression for dynamic set updates. A new set op ->update() is added which, for non existant elements, invokes an initialization callback and inserts the new element. For both new or existing elements the extenstion pointer is returned to the caller to optionally perform timer updates or other actions. Element removal is not supported so far, however that seems to be a rather exotic need and can be added later on. Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include')
-rw-r--r--include/net/netfilter/nf_tables.h17
-rw-r--r--include/net/netfilter/nf_tables_core.h3
-rw-r--r--include/uapi/linux/netfilter/nf_tables.h27
3 files changed, 47 insertions, 0 deletions
diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
index e7e6365c248f..38c3496f7bf2 100644
--- a/include/net/netfilter/nf_tables.h
+++ b/include/net/netfilter/nf_tables.h
@@ -196,6 +196,7 @@ struct nft_set_estimate {
196}; 196};
197 197
198struct nft_set_ext; 198struct nft_set_ext;
199struct nft_expr;
199 200
200/** 201/**
201 * struct nft_set_ops - nf_tables set operations 202 * struct nft_set_ops - nf_tables set operations
@@ -218,6 +219,15 @@ struct nft_set_ops {
218 bool (*lookup)(const struct nft_set *set, 219 bool (*lookup)(const struct nft_set *set,
219 const struct nft_data *key, 220 const struct nft_data *key,
220 const struct nft_set_ext **ext); 221 const struct nft_set_ext **ext);
222 bool (*update)(struct nft_set *set,
223 const struct nft_data *key,
224 void *(*new)(struct nft_set *,
225 const struct nft_expr *,
226 struct nft_data []),
227 const struct nft_expr *expr,
228 struct nft_data data[],
229 const struct nft_set_ext **ext);
230
221 int (*insert)(const struct nft_set *set, 231 int (*insert)(const struct nft_set *set,
222 const struct nft_set_elem *elem); 232 const struct nft_set_elem *elem);
223 void (*activate)(const struct nft_set *set, 233 void (*activate)(const struct nft_set *set,
@@ -466,6 +476,11 @@ static inline struct nft_set_ext *nft_set_elem_ext(const struct nft_set *set,
466 return elem + set->ops->elemsize; 476 return elem + set->ops->elemsize;
467} 477}
468 478
479void *nft_set_elem_init(const struct nft_set *set,
480 const struct nft_set_ext_tmpl *tmpl,
481 const struct nft_data *key,
482 const struct nft_data *data,
483 u64 timeout, gfp_t gfp);
469void nft_set_elem_destroy(const struct nft_set *set, void *elem); 484void nft_set_elem_destroy(const struct nft_set *set, void *elem);
470 485
471/** 486/**
@@ -845,6 +860,8 @@ static inline u8 nft_genmask_cur(const struct net *net)
845 return 1 << ACCESS_ONCE(net->nft.gencursor); 860 return 1 << ACCESS_ONCE(net->nft.gencursor);
846} 861}
847 862
863#define NFT_GENMASK_ANY ((1 << 0) | (1 << 1))
864
848/* 865/*
849 * Set element transaction helpers 866 * Set element transaction helpers
850 */ 867 */
diff --git a/include/net/netfilter/nf_tables_core.h b/include/net/netfilter/nf_tables_core.h
index a75fc8e27cd6..c6f400cfaac8 100644
--- a/include/net/netfilter/nf_tables_core.h
+++ b/include/net/netfilter/nf_tables_core.h
@@ -31,6 +31,9 @@ void nft_cmp_module_exit(void);
31int nft_lookup_module_init(void); 31int nft_lookup_module_init(void);
32void nft_lookup_module_exit(void); 32void nft_lookup_module_exit(void);
33 33
34int nft_dynset_module_init(void);
35void nft_dynset_module_exit(void);
36
34int nft_bitwise_module_init(void); 37int nft_bitwise_module_init(void);
35void nft_bitwise_module_exit(void); 38void nft_bitwise_module_exit(void);
36 39
diff --git a/include/uapi/linux/netfilter/nf_tables.h b/include/uapi/linux/netfilter/nf_tables.h
index 83441cc4594b..0b87b2f67fe3 100644
--- a/include/uapi/linux/netfilter/nf_tables.h
+++ b/include/uapi/linux/netfilter/nf_tables.h
@@ -515,6 +515,33 @@ enum nft_lookup_attributes {
515}; 515};
516#define NFTA_LOOKUP_MAX (__NFTA_LOOKUP_MAX - 1) 516#define NFTA_LOOKUP_MAX (__NFTA_LOOKUP_MAX - 1)
517 517
518enum nft_dynset_ops {
519 NFT_DYNSET_OP_ADD,
520 NFT_DYNSET_OP_UPDATE,
521};
522
523/**
524 * enum nft_dynset_attributes - dynset expression attributes
525 *
526 * @NFTA_DYNSET_SET_NAME: name of set the to add data to (NLA_STRING)
527 * @NFTA_DYNSET_SET_ID: uniquely identifier of the set in the transaction (NLA_U32)
528 * @NFTA_DYNSET_OP: operation (NLA_U32)
529 * @NFTA_DYNSET_SREG_KEY: source register of the key (NLA_U32)
530 * @NFTA_DYNSET_SREG_DATA: source register of the data (NLA_U32)
531 * @NFTA_DYNSET_TIMEOUT: timeout value for the new element (NLA_U64)
532 */
533enum nft_dynset_attributes {
534 NFTA_DYNSET_UNSPEC,
535 NFTA_DYNSET_SET_NAME,
536 NFTA_DYNSET_SET_ID,
537 NFTA_DYNSET_OP,
538 NFTA_DYNSET_SREG_KEY,
539 NFTA_DYNSET_SREG_DATA,
540 NFTA_DYNSET_TIMEOUT,
541 __NFTA_DYNSET_MAX,
542};
543#define NFTA_DYNSET_MAX (__NFTA_DYNSET_MAX - 1)
544
518/** 545/**
519 * enum nft_payload_bases - nf_tables payload expression offset bases 546 * enum nft_payload_bases - nf_tables payload expression offset bases
520 * 547 *