Netfilter/nftables updates for net-next
Subsystems (4)
Pablo Neira Ayuso
maintainercover Netfilter/nftables updates for net-next
Hi David,
The following patchset contains Netfilter/nftables updates for net-next, most relevantly they are:
1) Add set element update notification via netlink, from Arturo Borrero.
2) Put all object updates in one single message batch that is sent to kernel-space. Before this patch only rules where included in the batch. This series also introduces the generic transaction infrastructure so updates to all objects (tables, chains, rules and sets) are applied in an all-or-nothing fashion, these series from me.
3) Defer release of objects via call_rcu to reduce the time required to commit changes. The assumption is that all objects are destroyed in reverse order to ensure that dependencies betweem them are fulfilled (ie. rules and sets are destroyed first, then chains, and finally tables).
4) Allow to match by bridge port name, from Tomasz Bursztyka. This series include two patches to prepare this new feature.
5) Implement the proper set selection based on the characteristics of the data. The new infrastructure also allows you to specify your preferences in terms of memory and computational complexity so the underlying set type is also selected according to your needs, from Patrick McHardy.
6) Several cleanup patches for nft expressions, including one minor possible compilation breakage due to missing mark support, also from Patrick.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nftables.git
Thanks!
----------------------------------------------------------------
The following changes since commit b1586f099ba897542ece36e8a23c1a62907261ef:
netpoll: Use skb_irq_freeable to make zap_completion_queue safe. (2014-04-01 17:53:36 -0400)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nftables.git master
for you to fetch changes up to c7c32e72cbe23cea97c5d87ffcf6e23cc1ec1a65:
netfilter: nf_tables: defer all object release via rcu (2014-05-19 12:06:13 +0200)
----------------------------------------------------------------
Arturo Borrero (1):
netfilter: nf_tables: add set_elem notifications
Pablo Neira (1):
netfilter: nf_tables: relax string validation of NFTA_CHAIN_TYPE
Pablo Neira Ayuso (14):
netfilter: nf_tables: deconstify table and chain in context structure
netfilter: nf_tables: generalise transaction infrastructure
netfilter: nf_tables: relocate commit and abort routines in the source file
netfilter: nf_tables: add message type to transactions
netfilter: nf_tables: use new transaction infrastructure to handle sets
netfilter: nf_tables: refactor chain statistic routines
netfilter: nf_tables: use new transaction infrastructure to handle chain
netfilter: nf_tables: disabling table hooks always succeeds
netfilter: nf_tables: pass context to nf_tables_updtable()
netfilter: nf_tables: use new transaction infrastructure to handle table
netfilter: nf_tables: use new transaction infrastructure to handle elements
netfilter: nf_tables: simplify nf_tables_*_notify
netfilter: nf_tables: remove skb and nlh from context structure
netfilter: nf_tables: defer all object release via rcu
Patrick McHardy (6):
netfilter: nft_ct: add missing ifdef for NFT_MARK setting
netfilter: nft_meta: split nft_meta_init() into two functions for get/set
netfilter: nft_ct: split nft_ct_init() into two functions for get/set
netfilter: nf_tables: implement proper set selection
netfilter: nft_hash: use set global element counter instead of private one
netfilter: nf_tables: handle more than 8 * PAGE_SIZE set name allocations
Tomasz Bursztyka (3):
netfilter: nf_tables: Stack expression type depending on their family
netfilter: nf_tables: Make meta expression core functions public
netfilter: nf_tables: Add meta expression key for bridge interface name
include/net/netfilter/nf_tables.h | 130 +++- include/net/netfilter/nft_meta.h | 36 + include/uapi/linux/netfilter/nf_tables.h | 37 + net/bridge/Makefile | 2 +- net/bridge/netfilter/Kconfig | 14 +- net/bridge/netfilter/Makefile | 1 + net/bridge/netfilter/nft_meta_bridge.c | 139 ++++ net/netfilter/nf_tables_api.c | 1236 +++++++++++++++++++++--------- net/netfilter/nft_ct.c | 96 ++- net/netfilter/nft_hash.c | 54 +- net/netfilter/nft_lookup.c | 10 +- net/netfilter/nft_meta.c | 103 ++- net/netfilter/nft_rbtree.c | 21 + 13 files changed, 1407 insertions(+), 472 deletions(-) create mode 100644 include/net/netfilter/nft_meta.h create mode 100644 net/bridge/netfilter/nft_meta_bridge.c
Pablo Neira Ayuso
maintainerPATCH 1/25 netfilter: nft_ct: add missing ifdef for NFT_MARK setting
From: Patrick McHardy <[email protected]>
The set operation for ct mark is only valid if CONFIG_NF_CONNTRACK_MARK is enabled.
--- net/netfilter/nft_ct.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/nft_ct.c +2 -0
@@ -268,8 +268,10 @@ static int nft_ct_init_validate_get(const struct nft_expr *expr,static int nft_ct_init_validate_set (uint32_t key) {switch (key) { +#ifdef CONFIG_NF_CONNTRACK_MARK case NFT_CT_MARK :break ; +#endif default :return -EOPNOTSUPP ; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/25 netfilter: nft_meta: split nft_meta_init() into two functions for get/set
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
For value spanning multiple registers, we need to validate the length of data loads. In order to add this to nft_meta, we need the length from key validation. Split the nft_meta_init() function into two functions for the get and set operations as preparation for that.
--- net/netfilter/nft_meta.c | 65 +++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 35 deletions(-)
net/netfilter/nft_meta.c +30 -35
@@ -170,21 +170,15 @@ static const struct nla_policy nft_meta_policy[NFTA_META_MAX + 1] = { [NFTA_META_SREG] = { .type = NLA_U32 }, }; -static int nft_meta_init_validate_set (uint32_t key) +static int nft_meta_get_init (const struct nft_ctx *ctx, +const struct nft_expr *expr, +const struct nlattr *const tb[]) { -switch (key) { -case NFT_META_MARK : -case NFT_META_PRIORITY : -case NFT_META_NFTRACE : -return 0 ; -default : -return -EOPNOTSUPP ; - } -} +struct nft_meta *priv =nft_expr_priv (expr); +int err; -static int nft_meta_init_validate_get (uint32_t key) -{ -switch (key) { + priv->key =ntohl (nla_get_be32 (tb[NFTA_META_KEY ])); +switch (priv->key) {case NFT_META_LEN :case NFT_META_PROTOCOL :case NFT_META_NFPROTO :
@@ -205,39 +199,40 @@ static int nft_meta_init_validate_get(uint32_t key)#ifdef CONFIG_NETWORK_SECMARK case NFT_META_SECMARK :#endif -return 0 ; +break ;default :return -EOPNOTSUPP ; } + priv->dreg =ntohl (nla_get_be32 (tb[NFTA_META_DREG ])); + err =nft_validate_output_register (priv->dreg); +if (err <0 ) +return err; + + err =nft_validate_data_load (ctx, priv->dreg,NULL ,NFT_DATA_VALUE ); +if (err <0 ) +return err; + +return 0 ; } -static int nft_meta_init (const struct nft_ctx *ctx,const struct nft_expr *expr, -const struct nlattr *const tb[]) +static int nft_meta_set_init (const struct nft_ctx *ctx, +const struct nft_expr *expr, +const struct nlattr *const tb[]) {struct nft_meta *priv =nft_expr_priv (expr);int err; priv->key =ntohl (nla_get_be32 (tb[NFTA_META_KEY ])); - -if (tb[NFTA_META_DREG ]) { - err =nft_meta_init_validate_get (priv->key); -if (err <0 ) -return err; - - priv->dreg =ntohl (nla_get_be32 (tb[NFTA_META_DREG ])); - err =nft_validate_output_register (priv->dreg); -if (err <0 ) -return err; - -return nft_validate_data_load (ctx, priv->dreg,NULL , -NFT_DATA_VALUE ); +switch (priv->key) { +case NFT_META_MARK : +case NFT_META_PRIORITY : +case NFT_META_NFTRACE : +break ; +default : +return -EOPNOTSUPP ; } - err =nft_meta_init_validate_set (priv->key); -if (err <0 ) -return err; - priv->sreg =ntohl (nla_get_be32 (tb[NFTA_META_SREG ])); err =nft_validate_input_register (priv->sreg);if (err <0 )
@@ -282,7 +277,7 @@ static const struct nft_expr_ops nft_meta_get_ops = { .type = &nft_meta_type, .size = NFT_EXPR_SIZE(sizeof(struct nft_meta)), .eval = nft_meta_get_eval, - .init = nft_meta_init, + .init = nft_meta_get_init, .dump = nft_meta_get_dump, };
@@ -290,7 +285,7 @@ static const struct nft_expr_ops nft_meta_set_ops = { .type = &nft_meta_type, .size = NFT_EXPR_SIZE(sizeof(struct nft_meta)), .eval = nft_meta_set_eval, - .init = nft_meta_init, + .init = nft_meta_set_init, .dump = nft_meta_set_dump, };
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/25 netfilter: nft_ct: split nft_ct_init() into two functions for get/set
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
For value spanning multiple registers, we need to validate the length of data loads. In order to add this to nft_ct, we need the length from key validation. Split the nft_ct_init() function into two functions for the get and set operations as preparation for that.
--- net/netfilter/nft_ct.c | 96 ++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 53 deletions(-)
net/netfilter/nft_ct.c +43 -53
@@ -215,22 +215,14 @@ static void nft_ct_l3proto_module_put(uint8_t family)nf_ct_l3proto_module_put (family); } -static int nft_ct_init_validate_get (const struct nft_expr *expr, -const struct nlattr *const tb[]) +static int nft_ct_get_init (const struct nft_ctx *ctx, +const struct nft_expr *expr, +const struct nlattr *const tb[]) {struct nft_ct *priv =nft_expr_priv (expr); +int err; -if (tb[NFTA_CT_DIRECTION ] !=NULL ) { - priv->dir =nla_get_u8 (tb[NFTA_CT_DIRECTION ]); -switch (priv->dir) { -case IP_CT_DIR_ORIGINAL : -case IP_CT_DIR_REPLY : -break ; -default : -return -EINVAL ; - } - } - + priv->key =ntohl (nla_get_be32 (tb[NFTA_CT_KEY ]));switch (priv->key) {case NFT_CT_STATE :case NFT_CT_DIRECTION :
@@ -262,12 +254,42 @@ static int nft_ct_init_validate_get(const struct nft_expr *expr,return -EOPNOTSUPP ; } +if (tb[NFTA_CT_DIRECTION ] !=NULL ) { + priv->dir =nla_get_u8 (tb[NFTA_CT_DIRECTION ]); +switch (priv->dir) { +case IP_CT_DIR_ORIGINAL : +case IP_CT_DIR_REPLY : +break ; +default : +return -EINVAL ; + } + } + + priv->dreg =ntohl (nla_get_be32 (tb[NFTA_CT_DREG ])); + err =nft_validate_output_register (priv->dreg); +if (err <0 ) +return err; + + err =nft_validate_data_load (ctx, priv->dreg,NULL ,NFT_DATA_VALUE ); +if (err <0 ) +return err; + + err =nft_ct_l3proto_try_module_get (ctx->afi->family); +if (err <0 ) +return err; +return 0 ; } -static int nft_ct_init_validate_set (uint32_t key) +static int nft_ct_set_init (const struct nft_ctx *ctx, +const struct nft_expr *expr, +const struct nlattr *const tb[]) { -switch (key) { +struct nft_ct *priv =nft_expr_priv (expr); +int err; + + priv->key =ntohl (nla_get_be32 (tb[NFTA_CT_KEY ])); +switch (priv->key) {#ifdef CONFIG_NF_CONNTRACK_MARK case NFT_CT_MARK :break ;
@@ -276,42 +298,10 @@ static int nft_ct_init_validate_set(uint32_t key)return -EOPNOTSUPP ; } -return 0 ; -} - -static int nft_ct_init (const struct nft_ctx *ctx, -const struct nft_expr *expr, -const struct nlattr *const tb[]) -{ -struct nft_ct *priv =nft_expr_priv (expr); -int err; - - priv->key =ntohl (nla_get_be32 (tb[NFTA_CT_KEY ])); - -if (tb[NFTA_CT_DREG ]) { - err =nft_ct_init_validate_get (expr, tb); -if (err <0 ) -return err; - - priv->dreg =ntohl (nla_get_be32 (tb[NFTA_CT_DREG ])); - err =nft_validate_output_register (priv->dreg); -if (err <0 ) -return err; - - err =nft_validate_data_load (ctx, priv->dreg,NULL , -NFT_DATA_VALUE ); -if (err <0 ) -return err; - }else { - err =nft_ct_init_validate_set (priv->key); -if (err <0 ) -return err; - - priv->sreg =ntohl (nla_get_be32 (tb[NFTA_CT_SREG ])); - err =nft_validate_input_register (priv->sreg); -if (err <0 ) -return err; - } + priv->sreg =ntohl (nla_get_be32 (tb[NFTA_CT_SREG ])); + err =nft_validate_input_register (priv->sreg); +if (err <0 ) +return err; err =nft_ct_l3proto_try_module_get (ctx->afi->family);if (err <0 )
@@ -372,7 +362,7 @@ static const struct nft_expr_ops nft_ct_get_ops = { .type = &nft_ct_type, .size = NFT_EXPR_SIZE(sizeof(struct nft_ct)), .eval = nft_ct_get_eval, - .init = nft_ct_init, + .init = nft_ct_get_init, .destroy = nft_ct_destroy, .dump = nft_ct_get_dump, };
@@ -381,7 +371,7 @@ static const struct nft_expr_ops nft_ct_set_ops = { .type = &nft_ct_type, .size = NFT_EXPR_SIZE(sizeof(struct nft_ct)), .eval = nft_ct_set_eval, - .init = nft_ct_init, + .init = nft_ct_set_init, .destroy = nft_ct_destroy, .dump = nft_ct_set_dump, };
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 4/25 netfilter: nf_tables: implement proper set selection
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
The current set selection simply choses the first set type that provides the requested features, which always results in the rbtree being chosen by virtue of being the first set in the list.
What we actually want to do is choose the implementation that can provide the requested features and is optimal from either a performance or memory perspective depending on the characteristics of the elements and the preferences specified by the user.
The elements are not known when creating a set. Even if we would provide them for anonymous (literal) sets, we'd still have standalone sets where the elements are not known in advance. We therefore need an abstract description of the data charcteristics.
The kernel already knows the size of the key, this patch starts by introducing a nested set description which so far contains only the maximum amount of elements. Based on this the set implementations are changed to provide an estimate of the required amount of memory and the lookup complexity class.
The set ops have a new callback ->estimate() that is invoked during set selection. It receives a structure containing the attributes known to the kernel and is supposed to populate a struct nft_set_estimate with the complexity class and, in case the size is known, the complete amount of memory required, or the amount of memory required per element otherwise.
Based on the policy specified by the user (performance/memory, defaulting to performance) the kernel will then select the best suited implementation.
Even if the set implementation would allow to add more than the specified maximum amount of elements, they are enforced since new implementations might not be able to add more than maximum based on which they were selected.
--- include/net/netfilter/nf_tables.h | 46 ++++++++++++ include/uapi/linux/netfilter/nf_tables.h | 27 +++++++ net/netfilter/nf_tables_api.c | 121 ++++++++++++++++++++++++++---- net/netfilter/nft_hash.c | 45 ++++++++++- net/netfilter/nft_rbtree.c | 21 ++++++ 5 files changed, 242 insertions(+), 18 deletions(-)
include/net/netfilter/nf_tables.h +46 -0
@@ -146,6 +146,44 @@ struct nft_set_iter { };/** +* struct nft_set_desc - description of set elements +* +* @klen: key length +* @dlen: data length +* @size: number of set elements +*/ +struct nft_set_desc { +unsigned int klen; +unsigned int dlen; +unsigned int size; +}; + +/** +* enum nft_set_class - performance class +* +* @NFT_LOOKUP_O_1: constant, O(1) +* @NFT_LOOKUP_O_LOG_N: logarithmic, O(log N) +* @NFT_LOOKUP_O_N: linear, O(N) +*/ +enum nft_set_class { +NFT_SET_CLASS_O_1 , +NFT_SET_CLASS_O_LOG_N , +NFT_SET_CLASS_O_N , +}; + +/** +* struct nft_set_estimate - estimation of memory and performance +* characteristics +* +* @size: required memory +* @class: lookup performance class +*/ +struct nft_set_estimate { +unsigned int size; +enum nft_set_class class; +}; + +/** * struct nft_set_ops - nf_tables set operations * * @lookup: look up an element within the set
@@ -174,7 +212,11 @@ struct nft_set_ops { struct nft_set_iter *iter);unsigned int (*privsize)(const struct nlattr *const nla[]); +bool (*estimate)(const struct nft_set_desc *desc, +u32 features, +struct nft_set_estimate *est);int (*init)(const struct nft_set *set, +const struct nft_set_desc *desc,const struct nlattr *const nla[]);void (*destroy)(const struct nft_set *set);
@@ -194,6 +236,8 @@ void nft_unregister_set(struct nft_set_ops *ops);* @name: name of the set * @ktype: key type (numeric type defined by userspace, not used in the kernel) * @dtype: data type (verdict or numeric type defined by userspace) +* @size: maximum set size +* @nelems: number of elements * @ops: set ops * @flags: set flags * @klen: key length
@@ -206,6 +250,8 @@ struct nft_set {char name[IFNAMSIZ ];u32 ktype;u32 dtype; +u32 size; +u32 nelems;/* runtime data below here */ const struct nft_set_ops *ops____cacheline_aligned ;u16 flags;
include/uapi/linux/netfilter/nf_tables.h +27 -0
@@ -212,6 +212,29 @@ enum nft_set_flags { };/** +* enum nft_set_policies - set selection policy +* +* @NFT_SET_POL_PERFORMANCE: prefer high performance over low memory use +* @NFT_SET_POL_MEMORY: prefer low memory use over high performance +*/ +enum nft_set_policies { +NFT_SET_POL_PERFORMANCE , +NFT_SET_POL_MEMORY , +}; + +/** +* enum nft_set_desc_attributes - set element description +* +* @NFTA_SET_DESC_SIZE: number of elements in set (NLA_U32) +*/ +enum nft_set_desc_attributes { +NFTA_SET_DESC_UNSPEC , +NFTA_SET_DESC_SIZE , + __NFTA_SET_DESC_MAX +}; +#define NFTA_SET_DESC_MAX (__NFTA_SET_DESC_MAX - 1) + +/** * enum nft_set_attributes - nf_tables set netlink attributes * * @NFTA_SET_TABLE: table name (NLA_STRING)
@@ -221,6 +244,8 @@ enum nft_set_flags {* @NFTA_SET_KEY_LEN: key data length (NLA_U32) * @NFTA_SET_DATA_TYPE: mapping data type (NLA_U32) * @NFTA_SET_DATA_LEN: mapping data length (NLA_U32) +* @NFTA_SET_POLICY: selection policy (NLA_U32) +* @NFTA_SET_DESC: set description (NLA_NESTED) */ enum nft_set_attributes {NFTA_SET_UNSPEC ,
@@ -231,6 +256,8 @@ enum nft_set_attributes {NFTA_SET_KEY_LEN ,NFTA_SET_DATA_TYPE ,NFTA_SET_DATA_LEN , +NFTA_SET_POLICY , +NFTA_SET_DESC , __NFTA_SET_MAX };#define NFTA_SET_MAX (__NFTA_SET_MAX - 1)
net/netfilter/nf_tables_api.c +105 -16
233 lines not on this page · raw message
net/netfilter/nft_hash.c +43 -2
87 lines not on this page · raw message
net/netfilter/nft_rbtree.c +21 -0
@@ -201,6 +201,7 @@ static unsigned int nft_rbtree_privsize(const struct nlattr * const nla[]) }static int nft_rbtree_init (const struct nft_set *set, +const struct nft_set_desc *desc,const struct nlattr *const nla[]) {struct nft_rbtree *priv =nft_set_priv (set);
@@ -222,8 +223,28 @@ static void nft_rbtree_destroy(const struct nft_set *set) } } +static bool nft_rbtree_estimate (const struct nft_set_desc *desc,u32 features, +struct nft_set_estimate *est) +{ +unsigned int nsize; + + nsize =sizeof (struct nft_rbtree_elem ); +if (features &NFT_SET_MAP ) + nsize += FIELD_SIZEOF(struct nft_rbtree_elem, data[0]); + +if (desc->size) + est->size =sizeof (struct nft_rbtree ) + desc->size * nsize; +else + est->size = nsize; + + est->class =NFT_SET_CLASS_O_LOG_N ; + +return true; +} +static struct nft_set_ops nft_rbtree_ops__read_mostly = { .privsize = nft_rbtree_privsize, + .estimate = nft_rbtree_estimate, .init = nft_rbtree_init, .destroy = nft_rbtree_destroy, .insert = nft_rbtree_insert,
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 5/25 netfilter: nft_hash: use set global element counter instead of private one
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
Now that nf_tables performs global accounting of set elements, it is not needed in the hash type anymore.
--- net/netfilter/nft_hash.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
net/netfilter/nft_hash.c +2 -7
@@ -28,7 +28,6 @@ struct nft_hash {struct nft_hash_table {unsigned int size; -unsigned int elements;struct nft_hash_elem __rcu *buckets[]; };
@@ -167,7 +166,6 @@ static int nft_hash_tbl_expand(const struct nft_set *set, struct nft_hash *priv)break ; } } - ntbl->elements = tbl->elements;/* Publish new table */ rcu_assign_pointer (priv->tbl, ntbl);
@@ -207,7 +205,6 @@ static int nft_hash_tbl_shrink(const struct nft_set *set, struct nft_hash *priv) ;RCU_INIT_POINTER (*pprev, tbl->buckets[i + ntbl->size]); } - ntbl->elements = tbl->elements;/* Publish new table */ rcu_assign_pointer (priv->tbl, ntbl);
@@ -243,10 +240,9 @@ static int nft_hash_insert(const struct nft_set *set, h =nft_hash_data (&he->key, tbl->size, set->klen);RCU_INIT_POINTER (he->next, tbl->buckets[h]);rcu_assign_pointer (tbl->buckets[h], he); - tbl->elements++;/* Expand table when exceeding 75% load */ -if (tbl->elements > tbl->size /4 *3 ) +if (set->nelems +1 > tbl->size /4 *3 )nft_hash_tbl_expand (set, priv);return 0 ;
@@ -274,10 +270,9 @@ static void nft_hash_remove(const struct nft_set *set,RCU_INIT_POINTER (*pprev, he->next);synchronize_rcu ();kfree (he); - tbl->elements--;/* Shrink table beneath 30% load */ -if (tbl->elements < tbl->size *3 /10 && +if (set->nelems -1 < tbl->size *3 /10 && tbl->size >NFT_HASH_MIN_SIZE )nft_hash_tbl_shrink (set, priv); }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 6/25 netfilter: nf_tables: add set_elem notifications
In reply to Pablo Neira AyusoFrom: Arturo Borrero <[email protected]>
This patch adds set_elems notifications. When a set_elem is added/deleted, all listening peers in userspace will receive the corresponding notification.
--- net/netfilter/nf_tables_api.c | 82 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+)
net/netfilter/nf_tables_api.c +82 -0
@@ -2807,6 +2807,85 @@ static int nf_tables_getsetelem(struct sock *nlsk, struct sk_buff *skb,return -EOPNOTSUPP ; } +static int nf_tables_fill_setelem_info (struct sk_buff *skb, +const struct nft_ctx *ctx,u32 seq, +u32 portid,int event,u16 flags, +const struct nft_set *set, +const struct nft_set_elem *elem) +{ +struct nfgenmsg *nfmsg; +struct nlmsghdr *nlh; +struct nlattr *nest; +int err; + + event |=NFNL_SUBSYS_NFTABLES <<8 ; + nlh =nlmsg_put (skb, portid, seq, event,sizeof (struct nfgenmsg ), + flags); +if (nlh ==NULL ) + goto nla_put_failure; + + nfmsg =nlmsg_data (nlh); + nfmsg->nfgen_family = ctx->afi->family; + nfmsg->version =NFNETLINK_V0 ; + nfmsg->res_id =0 ; + +if (nla_put_string (skb,NFTA_SET_TABLE , ctx->table->name)) + goto nla_put_failure; +if (nla_put_string (skb,NFTA_SET_NAME , set->name)) + goto nla_put_failure; + + nest =nla_nest_start (skb,NFTA_SET_ELEM_LIST_ELEMENTS ); +if (nest ==NULL ) + goto nla_put_failure; + + err =nf_tables_fill_setelem (skb, set, elem); +if (err <0 ) + goto nla_put_failure; + +nla_nest_end (skb, nest); + +return nlmsg_end (skb, nlh); + +nla_put_failure: +nlmsg_trim (skb, nlh); +return -1 ; +} + +static int nf_tables_setelem_notify (const struct nft_ctx *ctx, +const struct nft_set *set, +const struct nft_set_elem *elem, +int event,u16 flags) +{ +const struct sk_buff *oskb = ctx->skb; +struct net *net =sock_net (oskb->sk); +u32 portid =NETLINK_CB (oskb).portid; +bool report =nlmsg_report (ctx->nlh); +struct sk_buff *skb; +int err; + +if (!report && !nfnetlink_has_listeners (net,NFNLGRP_NFTABLES )) +return 0 ; + + err = -ENOBUFS ; + skb =nlmsg_new (NLMSG_GOODSIZE ,GFP_KERNEL ); +if (skb ==NULL ) + goto err; + + err =nf_tables_fill_setelem_info (skb, ctx,0 , portid, event, flags, + set, elem); +if (err <0 ) { +kfree_skb (skb); + goto err; + } + + err =nfnetlink_send (skb, net, portid,NFNLGRP_NFTABLES , report, +GFP_KERNEL ); +err: +if (err <0 ) +nfnetlink_set_err (net, portid,NFNLGRP_NFTABLES , err); +return err; +} +static int nft_add_set_elem (const struct nft_ctx *ctx,struct nft_set *set,const struct nlattr *attr) {
@@ -2887,6 +2966,7 @@ static int nft_add_set_elem(const struct nft_ctx *ctx, struct nft_set *set, goto err3; set->nelems++; +nf_tables_setelem_notify (ctx, set, &elem,NFT_MSG_NEWSETELEM ,0 );return 0 ; err3:
@@ -2957,6 +3037,8 @@ static int nft_del_setelem(const struct nft_ctx *ctx, struct nft_set *set, set->ops->remove (set, &elem); set->nelems--; +nf_tables_setelem_notify (ctx, set, &elem,NFT_MSG_DELSETELEM ,0 ); +nft_data_uninit (&elem.key,NFT_DATA_VALUE );if (set->flags &NFT_SET_MAP )nft_data_uninit (&elem.data, set->dtype);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 7/25 netfilter: nf_tables: handle more than 8 * PAGE_SIZE set name allocations
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
We currently have a limit of 8 * PAGE_SIZE anonymous sets. Lift that limit by continuing the scan if the entire page is exhausted.
--- net/netfilter/nf_tables_api.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
net/netfilter/nf_tables_api.c +10 -5
@@ -2049,7 +2049,7 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,const struct nft_set *i;const char *p;unsigned long *inuse; -unsigned int n =0 ; +unsigned int n =0 , min =0 ; p =strnchr (name,IFNAMSIZ ,'%' );if (p !=NULL ) {
@@ -2059,23 +2059,28 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set, inuse = (unsigned long *)get_zeroed_page (GFP_KERNEL );if (inuse ==NULL )return -ENOMEM ; - +cont:list_for_each_entry (i, &ctx->table->sets, list) {int tmp;if (!sscanf (i->name, name, &tmp))continue ; -if (tmp <0 || tmp >=BITS_PER_BYTE *PAGE_SIZE ) +if (tmp < min || tmp >= min +BITS_PER_BYTE *PAGE_SIZE )continue ; -set_bit (tmp, inuse); +set_bit (tmp - min, inuse); } n =find_first_zero_bit (inuse,BITS_PER_BYTE *PAGE_SIZE ); +if (n >=BITS_PER_BYTE *PAGE_SIZE ) { + min +=BITS_PER_BYTE *PAGE_SIZE ; +memset (inuse,0 ,PAGE_SIZE ); + goto cont; + }free_page ((unsigned long )inuse); } -snprintf (set->name,sizeof (set->name), name, n); +snprintf (set->name,sizeof (set->name), name, min + n);list_for_each_entry (i, &ctx->table->sets, list) {if (!strcmp (set->name, i->name))return -ENFILE ;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 8/25 netfilter: nf_tables: Stack expression type depending on their family
In reply to Pablo Neira AyusoFrom: Tomasz Bursztyka <[email protected]>
To ensure family tight expression gets selected in priority to family agnostic ones.
--- net/netfilter/nf_tables_api.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +4 -1
@@ -1093,7 +1093,10 @@ static void nft_ctx_init(struct nft_ctx *ctx,int nft_register_expr (struct nft_expr_type *type) {nfnl_lock (NFNL_SUBSYS_NFTABLES ); -list_add_tail (&type->list, &nf_tables_expressions); +if (type->family ==NFPROTO_UNSPEC ) +list_add_tail (&type->list, &nf_tables_expressions); +else +list_add (&type->list, &nf_tables_expressions);nfnl_unlock (NFNL_SUBSYS_NFTABLES );return 0 ; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 10/25 netfilter: nf_tables: Add meta expression key for bridge interface name
In reply to Pablo Neira AyusoFrom: Tomasz Bursztyka <[email protected]>
NFT_META_BRI_IIFNAME to get packet input bridge interface name NFT_META_BRI_OIFNAME to get packet output bridge interface name
Such meta key are accessible only through NFPROTO_BRIDGE family, on a dedicated nft meta module: nft_meta_bridge.
--- include/uapi/linux/netfilter/nf_tables.h | 4 + net/bridge/Makefile | 2 +- net/bridge/netfilter/Kconfig | 14 ++- net/bridge/netfilter/Makefile | 1 + net/bridge/netfilter/nft_meta_bridge.c | 139 ++++++++++++++++++++++++++++++ 5 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 net/bridge/netfilter/nft_meta_bridge.c
include/uapi/linux/netfilter/nf_tables.h +4 -0
@@ -563,6 +563,8 @@ enum nft_exthdr_attributes {* @NFT_META_SECMARK: packet secmark (skb->secmark) * @NFT_META_NFPROTO: netfilter protocol * @NFT_META_L4PROTO: layer 4 protocol number +* @NFT_META_BRI_IIFNAME: packet input bridge interface name +* @NFT_META_BRI_OIFNAME: packet output bridge interface name */ enum nft_meta_keys {NFT_META_LEN ,
@@ -582,6 +584,8 @@ enum nft_meta_keys {NFT_META_SECMARK ,NFT_META_NFPROTO ,NFT_META_L4PROTO , +NFT_META_BRI_IIFNAME , + NFT_META_BRI_OIFNAME, };/**
net/bridge/Makefile +1 -1
@@ -16,4 +16,4 @@ bridge-$(CONFIG_BRIDGE_IGMP_SNOOPING) += br_multicast.o br_mdb.o bridge-$(CONFIG_BRIDGE_VLAN_FILTERING) += br_vlan.o -obj-$(CONFIG_BRIDGE_NF_EBTABLES) += netfilter/ +obj-$(CONFIG_BRIDGE_NETFILTER) += netfilter/
net/bridge/netfilter/Kconfig +13 -1
@@ -2,13 +2,25 @@ # Bridge netfilter configuration # # -config NF_TABLES_BRIDGE +menuconfig NF_TABLES_BRIDGE depends on NF_TABLES + select BRIDGE_NETFILTER tristate "Ethernet Bridge nf_tables support" +if NF_TABLES_BRIDGE + +config NFT_BRIDGE_META + tristate "Netfilter nf_table bridge meta support" + depends on NFT_META + help + Add support for bridge dedicated meta key. + +endif # NF_TABLES_BRIDGE + menuconfig BRIDGE_NF_EBTABLES tristate "Ethernet Bridge tables (ebtables) support" depends on BRIDGE && NETFILTER + select BRIDGE_NETFILTER select NETFILTER_XTABLES help ebtables is a general, extensible frame/packet identification
net/bridge/netfilter/Makefile +1 -0
@@ -3,6 +3,7 @@ # obj-$(CONFIG_NF_TABLES_BRIDGE) += nf_tables_bridge.o +obj-$(CONFIG_NFT_BRIDGE_META) += nft_meta_bridge.o obj-$(CONFIG_BRIDGE_NF_EBTABLES) += ebtables.o
net/bridge/netfilter/nft_meta_bridge.c new file +139 -0
139 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 11/25 netfilter: nf_tables: relax string validation of NFTA_CHAIN_TYPE
In reply to Pablo Neira AyusoFrom: Pablo Neira <[email protected]>
Use NLA_STRING for consistency with other string attributes in nf_tables.
--- net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -541,7 +541,7 @@ static const struct nla_policy nft_chain_policy[NFTA_CHAIN_MAX + 1] = { .len = NFT_CHAIN_MAXNAMELEN - 1 }, [NFTA_CHAIN_HOOK] = { .type = NLA_NESTED }, [NFTA_CHAIN_POLICY] = { .type = NLA_U32 }, - [NFTA_CHAIN_TYPE] = { .type = NLA_NUL_STRING }, + [NFTA_CHAIN_TYPE] = { .type = NLA_STRING }, [NFTA_CHAIN_COUNTERS] = { .type = NLA_NESTED }, };
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 12/25 netfilter: nf_tables: deconstify table and chain in context structure
In reply to Pablo Neira AyusoThe new transaction infrastructure updates the family, table and chain objects in the context structure, so let's deconstify them. While at it, move the context structure initialization routine to the top of the source file as it will be also used from the table and chain routines.
--- include/net/netfilter/nf_tables.h | 6 ++-- net/netfilter/nf_tables_api.c | 58 ++++++++++++++++++------------------- 2 files changed, 32 insertions(+), 32 deletions(-)
include/net/netfilter/nf_tables.h +3 -3
@@ -83,9 +83,9 @@ struct nft_ctx {struct net *net;const struct sk_buff *skb;const struct nlmsghdr *nlh; -const struct nft_af_info *afi; -const struct nft_table *table; -const struct nft_chain *chain; +struct nft_af_info *afi; +struct nft_table *table; +struct nft_chain *chain;const struct nlattr *const *nla; };
net/netfilter/nf_tables_api.c +29 -29
125 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 13/25 netfilter: nf_tables: generalise transaction infrastructure
In reply to Pablo Neira AyusoThis patch generalises the existing rule transaction infrastructure so it can be used to handle set, table and chain object transactions as well. The transaction provides a data area that stores private information depending on the transaction type.
--- include/net/netfilter/nf_tables.h | 15 +++-- net/netfilter/nf_tables_api.c | 123 +++++++++++++++++++++---------------- 2 files changed, 80 insertions(+), 58 deletions(-)
include/net/netfilter/nf_tables.h +11 -4
@@ -387,18 +387,25 @@ struct nft_rule { };/** -* struct nft_rule_trans - nf_tables rule update in transaction +* struct nft_trans - nf_tables object update in transaction * * @list: used internally -* @ctx: rule context -* @rule: rule that needs to be updated +* @ctx: transaction context +* @data: internal information related to the transaction */ -struct nft_rule_trans { +struct nft_trans {struct list_head list;struct nft_ctx ctx; +char data[0 ]; +}; + +struct nft_trans_rule {struct nft_rule *rule; }; +#define nft_trans_rule (trans) \ + (((struct nft_trans_rule *)trans->data)->rule) +static inline struct nft_expr *nft_expr_first (const struct nft_rule *rule) {return (struct nft_expr *)&rule->data[0 ];
net/netfilter/nf_tables_api.c +69 -54
213 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 14/25 netfilter: nf_tables: relocate commit and abort routines in the source file
In reply to Pablo Neira AyusoMove the commit and abort routines to the bottom of the source code file. This change is required by the follow up patches that add the set, chain and table transaction support.
This patch is just a cleanup to access several functions without having to declare their prototypes.
--- net/netfilter/nf_tables_api.c | 160 ++++++++++++++++++++--------------------- 1 file changed, 80 insertions(+), 80 deletions(-)
net/netfilter/nf_tables_api.c +80 -80
@@ -1827,86 +1827,6 @@ static int nf_tables_delrule(struct sock *nlsk, struct sk_buff *skb,return err; } -static int nf_tables_commit (struct sk_buff *skb) -{ -struct net *net =sock_net (skb->sk); -struct nft_trans *trans, *next; - -/* Bump generation counter, invalidate any dump in progress */ - net->nft.genctr++; - -/* A new generation has just started */ - net->nft.gencursor =gencursor_next (net); - -/* Make sure all packets have left the previous generation before -* purging old rules. -*/ -synchronize_rcu (); - -list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { -/* This rule was inactive in the past and just became active. -* Clear the next bit of the genmask since its meaning has -* changed, now it is the future. -*/ -if (nft_rule_is_active (net,nft_trans_rule (trans))) { -nft_rule_clear (net,nft_trans_rule (trans)); -nf_tables_rule_notify (skb, trans->ctx.nlh, - trans->ctx.table, - trans->ctx.chain, -nft_trans_rule (trans), -NFT_MSG_NEWRULE ,0 , - trans->ctx.afi->family); -nft_trans_destroy (trans); -continue ; - } - -/* This rule is in the past, get rid of it */ -list_del_rcu (&nft_trans_rule (trans)->list); -nf_tables_rule_notify (skb, trans->ctx.nlh, - trans->ctx.table, trans->ctx.chain, -nft_trans_rule (trans),NFT_MSG_DELRULE , -0 , trans->ctx.afi->family); - } - -/* Make sure we don't see any packet traversing old rules */ -synchronize_rcu (); - -/* Now we can safely release unused old rules */ -list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { -nf_tables_rule_destroy (&trans->ctx,nft_trans_rule (trans)); -nft_trans_destroy (trans); - } - -return 0 ; -} - -static int nf_tables_abort (struct sk_buff *skb) -{ -struct net *net =sock_net (skb->sk); -struct nft_trans *trans, *next; - -list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { -if (!nft_rule_is_active_next (net,nft_trans_rule (trans))) { -nft_rule_clear (net,nft_trans_rule (trans)); -nft_trans_destroy (trans); -continue ; - } - -/* This rule is inactive, get rid of it */ -list_del_rcu (&nft_trans_rule (trans)->list); - } - -/* Make sure we don't see any packet accessing aborted rules */ -synchronize_rcu (); - -list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { -nf_tables_rule_destroy (&trans->ctx,nft_trans_rule (trans)); -nft_trans_destroy (trans); - } - -return 0 ; -} -/* * Sets */
@@ -3177,6 +3097,86 @@ static const struct nfnl_callback nf_tables_cb[NFT_MSG_MAX] = { }, }; +static int nf_tables_commit (struct sk_buff *skb) +{ +struct net *net =sock_net (skb->sk); +struct nft_trans *trans, *next; + +/* Bump generation counter, invalidate any dump in progress */ + net->nft.genctr++; + +/* A new generation has just started */ + net->nft.gencursor =gencursor_next (net); + +/* Make sure all packets have left the previous generation before +* purging old rules. +*/ +synchronize_rcu (); + +list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { +/* This rule was inactive in the past and just became active. +* Clear the next bit of the genmask since its meaning has +* changed, now it is the future. +*/ +if (nft_rule_is_active (net,nft_trans_rule (trans))) { +nft_rule_clear (net,nft_trans_rule (trans)); +nf_tables_rule_notify (skb, trans->ctx.nlh, + trans->ctx.table, + trans->ctx.chain, +nft_trans_rule (trans), +NFT_MSG_NEWRULE ,0 , + trans->ctx.afi->family); +nft_trans_destroy (trans); +continue ; + } + +/* This rule is in the past, get rid of it */ +list_del_rcu (&nft_trans_rule (trans)->list); +nf_tables_rule_notify (skb, trans->ctx.nlh, + trans->ctx.table, trans->ctx.chain, +nft_trans_rule (trans),NFT_MSG_DELRULE , +0 , trans->ctx.afi->family); + } + +/* Make sure we don't see any packet traversing old rules */ +synchronize_rcu (); + +/* Now we can safely release unused old rules */ +list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { +nf_tables_rule_destroy (&trans->ctx,nft_trans_rule (trans)); +nft_trans_destroy (trans); + } + +return 0 ; +} + +static int nf_tables_abort (struct sk_buff *skb) +{ +struct net *net =sock_net (skb->sk); +struct nft_trans *trans, *next; + +list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { +if (!nft_rule_is_active_next (net,nft_trans_rule (trans))) { +nft_rule_clear (net,nft_trans_rule (trans)); +nft_trans_destroy (trans); +continue ; + } + +/* This rule is inactive, get rid of it */ +list_del_rcu (&nft_trans_rule (trans)->list); + } + +/* Make sure we don't see any packet accessing aborted rules */ +synchronize_rcu (); + +list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { +nf_tables_rule_destroy (&trans->ctx,nft_trans_rule (trans)); +nft_trans_destroy (trans); + } + +return 0 ; +} +static const struct nfnetlink_subsystem nf_tables_subsys = { .name ="nf_tables" , .subsys_id =NFNL_SUBSYS_NFTABLES ,
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 15/25 netfilter: nf_tables: add message type to transactions
In reply to Pablo Neira AyusoThe patch adds message type to the transaction to simplify the commit the and abort routines. Yet another step forward in the generalisation of the transaction infrastructure.
--- include/net/netfilter/nf_tables.h | 2 + net/netfilter/nf_tables_api.c | 74 +++++++++++++++++++++---------------- 2 files changed, 45 insertions(+), 31 deletions(-)
include/net/netfilter/nf_tables.h +2 -0
@@ -390,11 +390,13 @@ struct nft_rule {* struct nft_trans - nf_tables object update in transaction * * @list: used internally +* @msg_type: message type * @ctx: transaction context * @data: internal information related to the transaction */ struct nft_trans {struct list_head list; +int msg_type;struct nft_ctx ctx;char data[0 ]; };
net/netfilter/nf_tables_api.c +43 -31
147 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 16/25 netfilter: nf_tables: use new transaction infrastructure to handle sets
In reply to Pablo Neira AyusoThis patch reworks the nf_tables API so set updates are included in the same batch that contains rule updates. This speeds up rule-set updates since we skip a dialog of four messages between kernel and user-space (two on each direction), from:
1) create the set and send netlink message to the kernel
2) process the response from the kernel that contains the allocated name.
3) add the set elements and send netlink message to the kernel.
4) process the response from the kernel (to check for errors).
To:
1) add the set to the batch.
2) add the set elements to the batch.
3) add the rule that points to the set.
4) send batch to the kernel.
This also introduces an internal set ID (NFTA_SET_ID) that is unique in the batch so set elements and rules can refer to new sets.
Backward compatibility has been only retained in userspace, this means that new nft versions can talk to the kernel both in the new and the old fashion.
--- include/net/netfilter/nf_tables.h | 12 +++ include/uapi/linux/netfilter/nf_tables.h | 6 ++ net/netfilter/nf_tables_api.c | 123 ++++++++++++++++++++++++++---- net/netfilter/nft_lookup.c | 10 ++- 4 files changed, 133 insertions(+), 18 deletions(-)
include/net/netfilter/nf_tables.h +12 -0
@@ -268,6 +268,8 @@ static inline void *nft_set_priv(const struct nft_set *set)struct nft_set *nf_tables_set_lookup (const struct nft_table *table,const struct nlattr *nla); +struct nft_set *nf_tables_set_lookup_byid (const struct net *net, +const struct nlattr *nla);/** * struct nft_set_binding - nf_tables set binding
@@ -408,6 +410,16 @@ struct nft_trans_rule {#define nft_trans_rule (trans) \ (((struct nft_trans_rule *)trans->data)->rule) +struct nft_trans_set { +struct nft_set *set; +u32 set_id; +}; + +#define nft_trans_set (trans) \ + (((struct nft_trans_set *)trans->data)->set) +#define nft_trans_set_id (trans) \ + (((struct nft_trans_set *)trans->data)->set_id) +static inline struct nft_expr *nft_expr_first (const struct nft_rule *rule) {return (struct nft_expr *)&rule->data[0 ];
include/uapi/linux/netfilter/nf_tables.h +6 -0
@@ -246,6 +246,7 @@ enum nft_set_desc_attributes {* @NFTA_SET_DATA_LEN: mapping data length (NLA_U32) * @NFTA_SET_POLICY: selection policy (NLA_U32) * @NFTA_SET_DESC: set description (NLA_NESTED) +* @NFTA_SET_ID: uniquely identifies a set in a transaction (NLA_U32) */ enum nft_set_attributes {NFTA_SET_UNSPEC ,
@@ -258,6 +259,7 @@ enum nft_set_attributes {NFTA_SET_DATA_LEN ,NFTA_SET_POLICY ,NFTA_SET_DESC , +NFTA_SET_ID , __NFTA_SET_MAX };#define NFTA_SET_MAX (__NFTA_SET_MAX - 1)
@@ -293,12 +295,14 @@ enum nft_set_elem_attributes {* @NFTA_SET_ELEM_LIST_TABLE: table of the set to be changed (NLA_STRING) * @NFTA_SET_ELEM_LIST_SET: name of the set to be changed (NLA_STRING) * @NFTA_SET_ELEM_LIST_ELEMENTS: list of set elements (NLA_NESTED: nft_set_elem_attributes) +* @NFTA_SET_ELEM_LIST_SET_ID: uniquely identifies a set in a transaction (NLA_U32) */ enum nft_set_elem_list_attributes {NFTA_SET_ELEM_LIST_UNSPEC ,NFTA_SET_ELEM_LIST_TABLE ,NFTA_SET_ELEM_LIST_SET ,NFTA_SET_ELEM_LIST_ELEMENTS , +NFTA_SET_ELEM_LIST_SET_ID , __NFTA_SET_ELEM_LIST_MAX };#define NFTA_SET_ELEM_LIST_MAX (__NFTA_SET_ELEM_LIST_MAX - 1)
@@ -484,12 +488,14 @@ enum nft_cmp_attributes {* @NFTA_LOOKUP_SET: name of the set where to look for (NLA_STRING) * @NFTA_LOOKUP_SREG: source register of the data to look for (NLA_U32: nft_registers) * @NFTA_LOOKUP_DREG: destination register (NLA_U32: nft_registers) +* @NFTA_LOOKUP_SET_ID: uniquely identifies a set in a transaction (NLA_U32) */ enum nft_lookup_attributes {NFTA_LOOKUP_UNSPEC ,NFTA_LOOKUP_SET ,NFTA_LOOKUP_SREG ,NFTA_LOOKUP_DREG , +NFTA_LOOKUP_SET_ID , __NFTA_LOOKUP_MAX };#define NFTA_LOOKUP_MAX (__NFTA_LOOKUP_MAX - 1)
net/netfilter/nf_tables_api.c +107 -16
273 lines not on this page · raw message
net/netfilter/nft_lookup.c +8 -2
@@ -56,8 +56,14 @@ static int nft_lookup_init(const struct nft_ctx *ctx,return -EINVAL ; set =nf_tables_set_lookup (ctx->table, tb[NFTA_LOOKUP_SET ]); -if (IS_ERR (set)) -return PTR_ERR (set); +if (IS_ERR (set)) { +if (tb[NFTA_LOOKUP_SET_ID ]) { + set =nf_tables_set_lookup_byid (ctx->net, + tb[NFTA_LOOKUP_SET_ID ]); + } +if (IS_ERR (set)) +return PTR_ERR (set); + } priv->sreg =ntohl (nla_get_be32 (tb[NFTA_LOOKUP_SREG ])); err =nft_validate_input_register (priv->sreg);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 17/25 netfilter: nf_tables: refactor chain statistic routines
In reply to Pablo Neira AyusoAdd new routines to encapsulate chain statistics allocation and replacement.
--- net/netfilter/nf_tables_api.c | 45 ++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 21 deletions(-)
net/netfilter/nf_tables_api.c +24 -21
@@ -805,8 +805,7 @@ static const struct nla_policy nft_counter_policy[NFTA_COUNTER_MAX + 1] = { [NFTA_COUNTER_BYTES] = { .type = NLA_U64 }, }; -static int -nf_tables_counters (struct nft_base_chain *chain,const struct nlattr *attr) +static struct nft_stats __percpu *nft_stats_alloc (const struct nlattr *attr) {struct nlattr *tb[NFTA_COUNTER_MAX +1 ];struct nft_stats __percpu *newstats;
@@ -815,14 +814,14 @@ nf_tables_counters(struct nft_base_chain *chain, const struct nlattr *attr) err =nla_parse_nested (tb,NFTA_COUNTER_MAX , attr, nft_counter_policy);if (err <0 ) -return err; +return ERR_PTR (err);if (!tb[NFTA_COUNTER_BYTES ] || !tb[NFTA_COUNTER_PACKETS ]) -return -EINVAL ; +return ERR_PTR (-EINVAL ); newstats = alloc_percpu(struct nft_stats);if (newstats ==NULL ) -return -ENOMEM ; +return ERR_PTR (-ENOMEM );/* Restore old counters on this cpu, no problem. Per-cpu statistics * are not exposed to userspace.
@@ -831,6 +830,12 @@ nf_tables_counters(struct nft_base_chain *chain, const struct nlattr *attr) stats->bytes =be64_to_cpu (nla_get_be64 (tb[NFTA_COUNTER_BYTES ])); stats->pkts =be64_to_cpu (nla_get_be64 (tb[NFTA_COUNTER_PACKETS ])); +return newstats; +} + +static void nft_chain_stats_replace (struct nft_base_chain *chain, +struct nft_stats __percpu *newstats) +{if (chain->stats) {struct nft_stats __percpu *oldstats =nft_dereference (chain->stats);
@@ -840,8 +845,6 @@ nf_tables_counters(struct nft_base_chain *chain, const struct nlattr *attr)free_percpu (oldstats); }else rcu_assign_pointer (chain->stats, newstats); - -return 0 ; } static int nf_tables_newchain(struct sock *nlsk, struct sk_buff *skb,
@@ -860,6 +863,7 @@ static int nf_tables_newchain(struct sock *nlsk, struct sk_buff *skb,u8 policy =NF_ACCEPT ;u64 handle =0 ;unsigned int i; +struct nft_stats __percpu *stats;int err;bool create;
@@ -920,10 +924,11 @@ static int nf_tables_newchain(struct sock *nlsk, struct sk_buff *skb,if (!(chain->flags &NFT_BASE_CHAIN ))return -EOPNOTSUPP ; - err =nf_tables_counters (nft_base_chain (chain), - nla[NFTA_CHAIN_COUNTERS ]); -if (err <0 ) -return err; + stats =nft_stats_alloc (nla[NFTA_CHAIN_COUNTERS ]); +if (IS_ERR (stats)) +return PTR_ERR (stats); + +nft_chain_stats_replace (nft_base_chain (chain), stats); }if (nla[NFTA_CHAIN_POLICY ])
@@ -977,23 +982,21 @@ static int nf_tables_newchain(struct sock *nlsk, struct sk_buff *skb,return -ENOMEM ;if (nla[NFTA_CHAIN_COUNTERS ]) { - err =nf_tables_counters (basechain, - nla[NFTA_CHAIN_COUNTERS ]); -if (err <0 ) { + stats =nft_stats_alloc (nla[NFTA_CHAIN_COUNTERS ]); +if (IS_ERR (stats)) {module_put (type->owner);kfree (basechain); -return err; +return PTR_ERR (stats); } + basechain->stats = stats; }else { -struct nft_stats __percpu *newstats; - - newstats = alloc_percpu(struct nft_stats); -if (newstats ==NULL ) { + stats = alloc_percpu(struct nft_stats); +if (IS_ERR (stats)) {module_put (type->owner);kfree (basechain); -return -ENOMEM ; +return PTR_ERR (stats); } -rcu_assign_pointer (basechain->stats, newstats); +rcu_assign_pointer (basechain->stats, stats); } basechain->type = type;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 18/25 netfilter: nf_tables: use new transaction infrastructure to handle chain
In reply to Pablo Neira AyusoThis patch speeds up rule-set updates and it also introduces a way to revert chain updates if the batch is aborted. The idea is to store the changes in the transaction to apply that in the commit step.
--- include/net/netfilter/nf_tables.h | 17 ++++ net/netfilter/nf_tables_api.c | 203 +++++++++++++++++++++++++++++-------- 2 files changed, 175 insertions(+), 45 deletions(-)
include/net/netfilter/nf_tables.h +17 -0
@@ -420,6 +420,22 @@ struct nft_trans_set {#define nft_trans_set_id (trans) \ (((struct nft_trans_set *)trans->data)->set_id) +struct nft_trans_chain { +bool update; +char name[NFT_CHAIN_MAXNAMELEN ]; +struct nft_stats __percpu *stats; +u8 policy; +}; + +#define nft_trans_chain_update (trans) \ + (((struct nft_trans_chain *)trans->data)->update) +#define nft_trans_chain_name (trans) \ + (((struct nft_trans_chain *)trans->data)->name) +#define nft_trans_chain_stats (trans) \ + (((struct nft_trans_chain *)trans->data)->stats) +#define nft_trans_chain_policy (trans) \ + (((struct nft_trans_chain *)trans->data)->policy) +static inline struct nft_expr *nft_expr_first (const struct nft_rule *rule) {return (struct nft_expr *)&rule->data[0 ];
@@ -452,6 +468,7 @@ static inline void *nft_userdata(const struct nft_rule *rule)enum nft_chain_flags {NFT_BASE_CHAIN =0x1 , +NFT_CHAIN_INACTIVE =0x2 , };/**
net/netfilter/nf_tables_api.c +158 -45
310 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 19/25 netfilter: nf_tables: disabling table hooks always succeeds
In reply to Pablo Neira Ayusonf_tables_table_disable() always succeeds, make this function void.
--- net/netfilter/nf_tables_api.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
net/netfilter/nf_tables_api.c +3 -6
@@ -381,7 +381,7 @@ err:return err; } -static int nf_tables_table_disable (const struct nft_af_info *afi, +static void nf_tables_table_disable (const struct nft_af_info *afi,struct nft_table *table) {struct nft_chain *chain;
@@ -391,8 +391,6 @@ static int nf_tables_table_disable(const struct nft_af_info *afi,nf_unregister_hooks (nft_base_chain (chain)->ops, afi->nops); } - -return 0 ; } static int nf_tables_updtable(struct sock *nlsk, struct sk_buff *skb,
@@ -412,9 +410,8 @@ static int nf_tables_updtable(struct sock *nlsk, struct sk_buff *skb,if ((flags &NFT_TABLE_F_DORMANT ) && !(table->flags &NFT_TABLE_F_DORMANT )) { - ret =nf_tables_table_disable (afi, table); -if (ret >=0 ) - table->flags |=NFT_TABLE_F_DORMANT ; +nf_tables_table_disable (afi, table); + table->flags |=NFT_TABLE_F_DORMANT ; }else if (!(flags &NFT_TABLE_F_DORMANT ) && table->flags &NFT_TABLE_F_DORMANT ) { ret =nf_tables_table_enable (afi, table);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 20/25 netfilter: nf_tables: pass context to nf_tables_updtable()
In reply to Pablo Neira AyusoSo nf_tables_uptable() only takes one single parameter.
--- net/netfilter/nf_tables_api.c | 51 +++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-)
net/netfilter/nf_tables_api.c +26 -25
@@ -393,36 +393,34 @@ static void nf_tables_table_disable(const struct nft_af_info *afi, } } -static int nf_tables_updtable (struct sock *nlsk,struct sk_buff *skb, -const struct nlmsghdr *nlh, -const struct nlattr *const nla[], -struct nft_af_info *afi,struct nft_table *table) +static int nf_tables_updtable (struct nft_ctx *ctx) { -const struct nfgenmsg *nfmsg =nlmsg_data (nlh); +const struct nfgenmsg *nfmsg =nlmsg_data (ctx->nlh);int family = nfmsg->nfgen_family, ret =0 ; +u32 flags; -if (nla[NFTA_TABLE_FLAGS ]) { -u32 flags; +if (!ctx->nla[NFTA_TABLE_FLAGS ]) +return 0 ; - flags =ntohl (nla_get_be32 (nla[NFTA_TABLE_FLAGS ])); -if (flags & ~NFT_TABLE_F_DORMANT ) -return -EINVAL ; + flags =ntohl (nla_get_be32 (ctx->nla[NFTA_TABLE_FLAGS ])); +if (flags & ~NFT_TABLE_F_DORMANT ) +return -EINVAL ; -if ((flags &NFT_TABLE_F_DORMANT ) && - !(table->flags &NFT_TABLE_F_DORMANT )) { -nf_tables_table_disable (afi, table); - table->flags |=NFT_TABLE_F_DORMANT ; - }else if (!(flags &NFT_TABLE_F_DORMANT ) && - table->flags &NFT_TABLE_F_DORMANT ) { - ret =nf_tables_table_enable (afi, table); -if (ret >=0 ) - table->flags &= ~NFT_TABLE_F_DORMANT ; - } -if (ret <0 ) - goto err; - } +if ((flags &NFT_TABLE_F_DORMANT ) && + !(ctx->table->flags &NFT_TABLE_F_DORMANT )) { +nf_tables_table_disable (ctx->afi, ctx->table); + ctx->table->flags |=NFT_TABLE_F_DORMANT ; + }else if (!(flags &NFT_TABLE_F_DORMANT ) && + ctx->table->flags &NFT_TABLE_F_DORMANT ) { + ret =nf_tables_table_enable (ctx->afi, ctx->table); +if (ret >=0 ) + ctx->table->flags &= ~NFT_TABLE_F_DORMANT ; + } +if (ret <0 ) + goto err; -nf_tables_table_notify (skb, nlh, table,NFT_MSG_NEWTABLE , family); +nf_tables_table_notify (ctx->skb, ctx->nlh, ctx->table, +NFT_MSG_NEWTABLE , family); err:return ret; }
@@ -438,6 +436,7 @@ static int nf_tables_newtable(struct sock *nlsk, struct sk_buff *skb,struct net *net =sock_net (skb->sk);int family = nfmsg->nfgen_family;u32 flags =0 ; +struct nft_ctx ctx; afi =nf_tables_afinfo_lookup (net, family, true);if (IS_ERR (afi))
@@ -456,7 +455,9 @@ static int nf_tables_newtable(struct sock *nlsk, struct sk_buff *skb,return -EEXIST ;if (nlh->nlmsg_flags &NLM_F_REPLACE )return -EOPNOTSUPP ; -return nf_tables_updtable (nlsk, skb, nlh, nla, afi, table); + +nft_ctx_init (&ctx, skb, nlh, afi, table,NULL , nla); +return nf_tables_updtable (&ctx); }if (nla[NFTA_TABLE_FLAGS ]) {
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 21/25 netfilter: nf_tables: use new transaction infrastructure to handle table
In reply to Pablo Neira AyusoThis patch speeds up rule-set updates and it also provides a way to revert updates and leave things in consistent state in case that the batch needs to be aborted.
--- include/net/netfilter/nf_tables.h | 10 +++ net/netfilter/nf_tables_api.c | 145 ++++++++++++++++++++++++++++++++----- 2 files changed, 136 insertions(+), 19 deletions(-)
include/net/netfilter/nf_tables.h +10 -0
@@ -436,6 +436,16 @@ struct nft_trans_chain {#define nft_trans_chain_policy (trans) \ (((struct nft_trans_chain *)trans->data)->policy) +struct nft_trans_table { +bool update; +bool enable; +}; + +#define nft_trans_table_update (trans) \ + (((struct nft_trans_table *)trans->data)->update) +#define nft_trans_table_enable (trans) \ + (((struct nft_trans_table *)trans->data)->enable) +static inline struct nft_expr *nft_expr_first (const struct nft_rule *rule) {return (struct nft_expr *)&rule->data[0 ];
net/netfilter/nf_tables_api.c +126 -19
325 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 22/25 netfilter: nf_tables: use new transaction infrastructure to handle elements
In reply to Pablo Neira AyusoLeave the set content in consistent state if we fail to load the batch. Use the new generic transaction infrastructure to achieve this.
--- include/net/netfilter/nf_tables.h | 10 +++++ net/netfilter/nf_tables_api.c | 82 ++++++++++++++++++++++++++++++------- 2 files changed, 78 insertions(+), 14 deletions(-)
include/net/netfilter/nf_tables.h +10 -0
@@ -446,6 +446,16 @@ struct nft_trans_table {#define nft_trans_table_enable (trans) \ (((struct nft_trans_table *)trans->data)->enable) +struct nft_trans_elem { +struct nft_set *set; +struct nft_set_elem elem; +}; + +#define nft_trans_elem_set (trans) \ + (((struct nft_trans_elem *)trans->data)->set) +#define nft_trans_elem (trans) \ + (((struct nft_trans_elem *)trans->data)->elem) +static inline struct nft_expr *nft_expr_first (const struct nft_rule *rule) {return (struct nft_expr *)&rule->data[0 ];
net/netfilter/nf_tables_api.c +68 -14
169 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 23/25 netfilter: nf_tables: simplify nf_tables_*_notify
In reply to Pablo Neira AyusoNow that all these function are called from the commit path, we can pass the context structure to reduce the amount of parameters in all of the nf_tables_*_notify functions. This patch also removes unneeded branches to check for skb, nlh and net that should be always set in the context structure.
--- net/netfilter/nf_tables_api.c | 90 +++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 58 deletions(-)
net/netfilter/nf_tables_api.c +32 -58
@@ -235,19 +235,16 @@ nla_put_failure:return -1 ; } -static int nf_tables_table_notify (const struct sk_buff *oskb, -const struct nlmsghdr *nlh, -const struct nft_table *table, -int event,int family) +static int nf_tables_table_notify (const struct nft_ctx *ctx,int event) {struct sk_buff *skb; -u32 portid = oskb ?NETLINK_CB (oskb).portid :0 ; -u32 seq = nlh ? nlh->nlmsg_seq :0 ; -struct net *net = oskb ?sock_net (oskb->sk) : &init_net; +u32 portid =NETLINK_CB (ctx->skb).portid; +u32 seq = ctx->nlh->nlmsg_seq; +struct net *net =sock_net (ctx->skb->sk);bool report;int err; - report = nlh ?nlmsg_report (nlh) : false; + report =nlmsg_report (ctx->nlh);if (!report && !nfnetlink_has_listeners (net,NFNLGRP_NFTABLES ))return 0 ;
@@ -257,7 +254,7 @@ static int nf_tables_table_notify(const struct sk_buff *oskb, goto err; err =nf_tables_fill_table_info (skb, portid, seq, event,0 , - family, table); + ctx->afi->family, ctx->table);if (err <0 ) {kfree_skb (skb); goto err;
@@ -721,20 +718,16 @@ nla_put_failure:return -1 ; } -static int nf_tables_chain_notify (const struct sk_buff *oskb, -const struct nlmsghdr *nlh, -const struct nft_table *table, -const struct nft_chain *chain, -int event,int family) +static int nf_tables_chain_notify (const struct nft_ctx *ctx,int event) {struct sk_buff *skb; -u32 portid = oskb ?NETLINK_CB (oskb).portid :0 ; -struct net *net = oskb ?sock_net (oskb->sk) : &init_net; -u32 seq = nlh ? nlh->nlmsg_seq :0 ; +u32 portid =NETLINK_CB (ctx->skb).portid; +struct net *net =sock_net (ctx->skb->sk); +u32 seq = ctx->nlh->nlmsg_seq;bool report;int err; - report = nlh ?nlmsg_report (nlh) : false; + report =nlmsg_report (ctx->nlh);if (!report && !nfnetlink_has_listeners (net,NFNLGRP_NFTABLES ))return 0 ;
@@ -743,8 +736,9 @@ static int nf_tables_chain_notify(const struct sk_buff *oskb,if (skb ==NULL ) goto err; - err =nf_tables_fill_chain_info (skb, portid, seq, event,0 , family, - table, chain); + err =nf_tables_fill_chain_info (skb, portid, seq, event,0 , + ctx->afi->family, ctx->table, + ctx->chain);if (err <0 ) {kfree_skb (skb); goto err;
@@ -1475,21 +1469,19 @@ nla_put_failure:return -1 ; } -static int nf_tables_rule_notify (const struct sk_buff *oskb, -const struct nlmsghdr *nlh, -const struct nft_table *table, -const struct nft_chain *chain, +static int nf_tables_rule_notify (const struct nft_ctx *ctx,const struct nft_rule *rule, -int event,u32 flags,int family) +int event) { +const struct sk_buff *oskb = ctx->skb;struct sk_buff *skb;u32 portid =NETLINK_CB (oskb).portid; -struct net *net = oskb ?sock_net (oskb->sk) : &init_net; -u32 seq = nlh->nlmsg_seq; +struct net *net =sock_net (oskb->sk); +u32 seq = ctx->nlh->nlmsg_seq;bool report;int err; - report =nlmsg_report (nlh); + report =nlmsg_report (ctx->nlh);if (!report && !nfnetlink_has_listeners (net,NFNLGRP_NFTABLES ))return 0 ;
@@ -1498,8 +1490,9 @@ static int nf_tables_rule_notify(const struct sk_buff *oskb,if (skb ==NULL ) goto err; - err =nf_tables_fill_rule_info (skb, portid, seq, event, flags, - family, table, chain, rule); + err =nf_tables_fill_rule_info (skb, portid, seq, event,0 , + ctx->afi->family, ctx->table, + ctx->chain, rule);if (err <0 ) {kfree_skb (skb); goto err;
@@ -3343,17 +3336,11 @@ static int nf_tables_commit(struct sk_buff *skb) }else { trans->ctx.table->flags &= ~NFT_TABLE_INACTIVE ; } -nf_tables_table_notify (trans->ctx.skb, trans->ctx.nlh, - trans->ctx.table, -NFT_MSG_NEWTABLE , - trans->ctx.afi->family); +nf_tables_table_notify (&trans->ctx,NFT_MSG_NEWTABLE );nft_trans_destroy (trans);break ;case NFT_MSG_DELTABLE : -nf_tables_table_notify (trans->ctx.skb, trans->ctx.nlh, - trans->ctx.table, -NFT_MSG_DELTABLE , - trans->ctx.afi->family); +nf_tables_table_notify (&trans->ctx,NFT_MSG_DELTABLE );break ;case NFT_MSG_NEWCHAIN :if (nft_trans_chain_update (trans))
@@ -3362,20 +3349,12 @@ static int nf_tables_commit(struct sk_buff *skb) trans->ctx.chain->flags &= ~NFT_CHAIN_INACTIVE ; trans->ctx.table->use++; } -nf_tables_chain_notify (trans->ctx.skb, trans->ctx.nlh, - trans->ctx.table, - trans->ctx.chain, -NFT_MSG_NEWCHAIN , - trans->ctx.afi->family); +nf_tables_chain_notify (&trans->ctx,NFT_MSG_NEWCHAIN );nft_trans_destroy (trans);break ;case NFT_MSG_DELCHAIN : trans->ctx.table->use--; -nf_tables_chain_notify (trans->ctx.skb, trans->ctx.nlh, - trans->ctx.table, - trans->ctx.chain, -NFT_MSG_DELCHAIN , - trans->ctx.afi->family); +nf_tables_chain_notify (&trans->ctx,NFT_MSG_DELCHAIN );if (!(trans->ctx.table->flags &NFT_TABLE_F_DORMANT ) && trans->ctx.chain->flags &NFT_BASE_CHAIN ) { nf_unregister_hooks(nft_base_chain(trans->ctx.chain)->ops,
@@ -3384,21 +3363,16 @@ static int nf_tables_commit(struct sk_buff *skb)break ;case NFT_MSG_NEWRULE :nft_rule_clear (trans->ctx.net,nft_trans_rule (trans)); -nf_tables_rule_notify (trans->ctx.skb, trans->ctx.nlh, - trans->ctx.table, - trans->ctx.chain, +nf_tables_rule_notify (&trans->ctx,nft_trans_rule (trans), -NFT_MSG_NEWRULE ,0 , - trans->ctx.afi->family); +NFT_MSG_NEWRULE );nft_trans_destroy (trans);break ;case NFT_MSG_DELRULE :list_del_rcu (&nft_trans_rule (trans)->list); -nf_tables_rule_notify (trans->ctx.skb, trans->ctx.nlh, - trans->ctx.table, - trans->ctx.chain, -nft_trans_rule (trans),NFT_MSG_DELRULE ,0 , - trans->ctx.afi->family); +nf_tables_rule_notify (&trans->ctx, +nft_trans_rule (trans), +NFT_MSG_DELRULE );break ;case NFT_MSG_NEWSET :nft_trans_set (trans)->flags &= ~NFT_SET_INACTIVE ;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 24/25 netfilter: nf_tables: remove skb and nlh from context structure
In reply to Pablo Neira AyusoInstead of caching the original skbuff that contains the netlink messages, this stores the netlink message sequence number, the netlink portID and the report flag. This helps to prepare the introduction of the object release via call_rcu.
--- include/net/netfilter/nf_tables.h | 10 ++-- net/netfilter/nf_tables_api.c | 101 +++++++++++++++++-------------------- 2 files changed, 52 insertions(+), 59 deletions(-)
include/net/netfilter/nf_tables.h +6 -4
@@ -72,21 +72,23 @@ static inline void nft_data_debug(const struct nft_data *data)* struct nft_ctx - nf_tables rule/set context * * @net: net namespace -* @skb: netlink skb -* @nlh: netlink message header * @afi: address family info * @table: the table the chain is contained in * @chain: the chain the rule is contained in * @nla: netlink attributes +* @portid: netlink portID of the original message +* @seq: netlink sequence number +* @report: notify via unicast netlink message */ struct nft_ctx {struct net *net; -const struct sk_buff *skb; -const struct nlmsghdr *nlh;struct nft_af_info *afi;struct nft_table *table;struct nft_chain *chain;const struct nlattr *const *nla; +u32 portid; +u32 seq; +bool report; };struct nft_data_desc {
net/netfilter/nf_tables_api.c +46 -55
206 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 25/25 netfilter: nf_tables: defer all object release via rcu
In reply to Pablo Neira AyusoNow that all objects are released in the reverse order via the transaction infrastructure, we can enqueue the release via call_rcu to save one synchronize_rcu. For small rule-sets loaded via nft -f, it now takes around 50ms less here.
--- include/net/netfilter/nf_tables.h | 2 + net/netfilter/nf_tables_api.c | 93 +++++++++++++++++++++---------------- 2 files changed, 56 insertions(+), 39 deletions(-)
include/net/netfilter/nf_tables.h +2 -0
@@ -393,12 +393,14 @@ struct nft_rule {/** * struct nft_trans - nf_tables object update in transaction * +* @rcu_head: rcu head to defer release of transaction data * @list: used internally * @msg_type: message type * @ctx: transaction context * @data: internal information related to the transaction */ struct nft_trans { +struct rcu_head rcu_head;struct list_head list;int msg_type;struct nft_ctx ctx;
net/netfilter/nf_tables_api.c +54 -39
118 lines not on this page · raw message
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Wed, 21 May 2014 11:42:58 +0200
Quoted 2 lines
The following patchset contains Netfilter/nftables updates for net-next, most relevantly they are:
Pulled, thanks a lot Pablo.