new transaction infrastructure for nf_tables (v4)
Subsystems (2)
Pablo Neira Ayuso
maintainercover new transaction infrastructure for nf_tables (v4)
Hi!
A new round of the new transaction infrastructure patches for nf_tables, main changes from the previous version are:
* In patch 11/11 ("use new transaction infrastructure to handle elements"), the abort path has been simplified.
* The patch 6/11 ("netfilter: nf_tables: refactor chain statistic routines") is new in this stack, it basically reworks the chain counters so the follow up patch 7/11 to introduce chain transaction becomes smaller.
Comments welcome.
Pablo Neira Ayuso (11):
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_uptable
netfilter: nf_tables: use new transaction infrastructure to handle table
netfilter: nf_tables: use new transaction infrastructure to handle elements
include/net/netfilter/nf_tables.h | 72 ++- include/uapi/linux/netfilter/nf_tables.h | 6 + net/netfilter/nf_tables_api.c | 923 +++++++++++++++++++++--------- net/netfilter/nft_lookup.c | 10 +- 4 files changed, 737 insertions(+), 274 deletions(-)
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 1/11 netfilter: nf_tables: deconstify table and chain in context structure
The 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 2/11 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 3/11 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
@@ -1824,86 +1824,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 */
@@ -3169,6 +3089,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 4/11 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 5/11 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 6/11 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 7/11 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 8/11 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 9/11 netfilter: nf_tables: pass context to nf_tables_uptable
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 10/11 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 11/11 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