nf_tables atomic rule-set update
Subsystems (2)
Pablo Neira Ayuso
maintainerv2 cover nf_tables atomic rule-set update
This patchset introduces improvements for the atomic rule update infrastructure, main changes are:
* Get rid of the extra struct list_head per rule as discussed. With this patch, a temporary object is allocated to store the rule update information.
* The commit and abort loops have been also simplified. Basically, there is a single list per net namespace that contains pending rule updates.
* A new begin message to explicitly enter the transaction mode, The end message indicates that commit need to happen. If not specified, the pending updates are aborted.
* Remove the commit flag per rule, thus, all rule updates are transactional.
These changes requires userspace updates, they will be posted soon.
Pablo Neira Ayuso (4):
netfilter: nf_tables: get rid of per rule list_head for commits
netfilter: nf_tables: use per netns commit list
netfilter: nfnetlink: add batch support and use it from nf_tables
netfilter: nf_tables: all rule updates are transactional
include/linux/netfilter/nfnetlink.h | 2 + include/net/netfilter/nf_tables.h | 23 +++- include/net/netns/nftables.h | 1 + include/uapi/linux/netfilter/nf_tables.h | 7 - include/uapi/linux/netfilter/nfnetlink.h | 4 + net/netfilter/nf_tables_api.c | 213 +++++++++++------------------- net/netfilter/nfnetlink.c | 171 +++++++++++++++++++++++- 7 files changed, 272 insertions(+), 149 deletions(-)
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH v2 1/4 netfilter: nf_tables: get rid of per rule list_head for commits
Get rid of the extra struct list_head per rule. With this patch, a temporary object is allocated to store the rule update information.
--- include/net/netfilter/nf_tables.h | 15 ++++++- net/netfilter/nf_tables_api.c | 83 ++++++++++++++++++++++++------------- 2 files changed, 67 insertions(+), 31 deletions(-)
include/net/netfilter/nf_tables.h +13 -2
@@ -321,7 +321,6 @@ static inline void *nft_expr_priv(const struct nft_expr *expr)* struct nft_rule - nf_tables rule * * @list: used internally -* @dirty_list: this rule needs an update after new generation * @rcu_head: used internally for rcu * @handle: rule handle * @genmask: generation mask
@@ -330,7 +329,6 @@ static inline void *nft_expr_priv(const struct nft_expr *expr)*/ struct nft_rule {struct list_head list; -struct list_head dirty_list;struct rcu_head rcu_head;u64 handle:46 , genmask:2,
@@ -339,6 +337,19 @@ struct nft_rule { __attribute__((aligned(__alignof__(struct nft_expr)))); }; +/** +* struct nft_rule_trans - nf_tables rule update in transaction +* +* @list: used internally +* @rule: rule that needs to be updated +* @family: family expressesed as AF_* +*/ +struct nft_rule_trans { +struct list_head list; +struct nft_rule *rule; +u8 family; +}; +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 +54 -29
172 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH v2 2/4 netfilter: nf_tables: use per netns commit list
In reply to Pablo Neira AyusoInstead of one list per chain.
--- include/net/netfilter/nf_tables.h | 6 +- include/net/netns/nftables.h | 1 + net/netfilter/nf_tables_api.c | 109 +++++++++++++------------------------ 3 files changed, 44 insertions(+), 72 deletions(-)
include/net/netfilter/nf_tables.h +4 -2
@@ -342,11 +342,15 @@ struct nft_rule {* * @list: used internally * @rule: rule that needs to be updated +* @chain: chain that this rule belongs to +* @table: table for which this chain applies * @family: family expressesed as AF_* */ struct nft_rule_trans {struct list_head list;struct nft_rule *rule; +const struct nft_chain *chain; +const struct nft_table *table;u8 family; };
@@ -383,7 +387,6 @@ enum nft_chain_flags {* struct nft_chain - nf_tables chain * * @rules: list of rules in the chain -* @dirty_rules: rules that need an update after next generation * @list: used internally * @rcu_head: used internally * @net: net namespace that this chain belongs to
@@ -396,7 +399,6 @@ enum nft_chain_flags {*/ struct nft_chain {struct list_head rules; -struct list_head dirty_rules;struct list_head list;struct rcu_head rcu_head;struct net *net;
include/net/netns/nftables.h +1 -0
@@ -7,6 +7,7 @@ struct nft_af_info;struct netns_nftables {struct list_head af_info; +struct list_head commit_list;struct nft_af_info *ipv4;struct nft_af_info *ipv6;struct nft_af_info *arp;
net/netfilter/nf_tables_api.c +39 -70
161 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH v2 3/4 netfilter: nfnetlink: add batch support and use it from nf_tables
In reply to Pablo Neira AyusoThis patch adds batch support for nfnetlink, this allows you to atomically handle a batch of netlink messages. This is used by nf_tables to improve the existing atomic rule-set update approach.
Two new nfnetlink control messages are added for this purpose, they are:
* NFNL_MSG_BATCH_BEGIN, that indicates the beginning of a batch, the nfgenmsg->res_id indicates the nfnetlink subsystem ID.
* NFNL_MSG_BATCH_END, that results in the invocation of the ss->commit callback function. If not specified or an error ocurred in the batch, the ss->abort function is invoked instead.
This allows us to get rid of the NFT_MSG_COMMIT and NFT_MSG_ABORT nf_tables message types.
--- include/linux/netfilter/nfnetlink.h | 2 + include/net/netfilter/nf_tables.h | 2 + include/uapi/linux/netfilter/nf_tables.h | 2 - include/uapi/linux/netfilter/nfnetlink.h | 4 + net/netfilter/nf_tables_api.c | 25 ++--- net/netfilter/nfnetlink.c | 171 +++++++++++++++++++++++++++++- 6 files changed, 182 insertions(+), 24 deletions(-)
include/linux/netfilter/nfnetlink.h +2 -0
@@ -23,6 +23,8 @@ struct nfnetlink_subsystem {__u8 subsys_id;/* nfnetlink subsystem ID */ __u8 cb_count;/* number of callbacks */ const struct nfnl_callback *cb;/* callback for individual types */ +int (*commit)(struct sk_buff *skb); +int (*abort)(struct sk_buff *skb); };extern int nfnetlink_subsys_register (const struct nfnetlink_subsystem *n);
include/net/netfilter/nf_tables.h +2 -0
@@ -344,6 +344,7 @@ struct nft_rule {* @rule: rule that needs to be updated * @chain: chain that this rule belongs to * @table: table for which this chain applies +* @nlh: netlink header of the message that contain this update * @family: family expressesed as AF_* */ struct nft_rule_trans {
@@ -351,6 +352,7 @@ struct nft_rule_trans {struct nft_rule *rule;const struct nft_chain *chain;const struct nft_table *table; +const struct nlmsghdr *nlh;u8 family; };
include/uapi/linux/netfilter/nf_tables.h +0 -2
@@ -48,8 +48,6 @@ enum nf_tables_msg_types {NFT_MSG_NEWSETELEM ,NFT_MSG_GETSETELEM ,NFT_MSG_DELSETELEM , -NFT_MSG_COMMIT , -NFT_MSG_ABORT , NFT_MSG_MAX, };
include/uapi/linux/netfilter/nfnetlink.h +4 -0
@@ -57,4 +57,8 @@ struct nfgenmsg {#define NFNL_SUBSYS_NFT_COMPAT 11#define NFNL_SUBSYS_COUNT 12 +/* Reserved control nfnetlink messages */ +#define NFNL_MSG_BATCH_BEGIN NLMSG_MIN_TYPE +#define NFNL_MSG_BATCH_END NLMSG_MIN_TYPE+1 +#endif /* _UAPI_NFNETLINK_H */
net/netfilter/nf_tables_api.c +7 -18
@@ -1548,6 +1548,7 @@ static int nf_tables_trans_add(struct nft_rule *rule, const struct nft_ctx *ctx) rupd->table = ctx->table; rupd->rule = rule; rupd->family = ctx->afi->family; + rupd->nlh = ctx->nlh;list_add (&rupd->list, &ctx->net->nft.commit_list);return 0 ;
@@ -1772,9 +1773,7 @@ static int nf_tables_delrule(struct sock *nlsk, struct sk_buff *skb,return err; } -static int nf_tables_commit (struct sock *nlsk,struct sk_buff *skb, -const struct nlmsghdr *nlh, -const struct nlattr *const nla[]) +static int nf_tables_commit (struct sk_buff *skb) {struct net *net =sock_net (skb->sk);struct nft_rule_trans *rupd, *tmp;
@@ -1800,7 +1799,7 @@ static int nf_tables_commit(struct sock *nlsk, struct sk_buff *skb,*/ if (nft_rule_is_active (net, rupd->rule)) {nft_rule_clear (net, rupd->rule); -nf_tables_rule_notify (skb, nlh, rupd->table, +nf_tables_rule_notify (skb, rupd->nlh, rupd->table, rupd->chain, rupd->rule,NFT_MSG_NEWRULE ,0 , rupd->family);
@@ -1810,7 +1809,7 @@ static int nf_tables_commit(struct sock *nlsk, struct sk_buff *skb,/* This rule is in the past, get rid of it */ list_del_rcu (&rupd->rule->list); -nf_tables_rule_notify (skb, nlh, rupd->table, rupd->chain, +nf_tables_rule_notify (skb, rupd->nlh, rupd->table, rupd->chain, rupd->rule,NFT_MSG_DELRULE ,0 , rupd->family);nf_tables_rule_destroy (rupd->rule);
@@ -1820,9 +1819,7 @@ static int nf_tables_commit(struct sock *nlsk, struct sk_buff *skb,return 0 ; } -static int nf_tables_abort (struct sock *nlsk,struct sk_buff *skb, -const struct nlmsghdr *nlh, -const struct nlattr *const nla[]) +static int nf_tables_abort (struct sk_buff *skb) {struct net *net =sock_net (skb->sk);struct nft_rule_trans *rupd, *tmp;
@@ -2804,16 +2801,6 @@ static const struct nfnl_callback nf_tables_cb[NFT_MSG_MAX] = { .attr_count = NFTA_SET_ELEM_LIST_MAX, .policy = nft_set_elem_list_policy, }, - [NFT_MSG_COMMIT] = { - .call = nf_tables_commit, - .attr_count = NFTA_TABLE_MAX, - .policy = nft_rule_policy, - }, - [NFT_MSG_ABORT] = { - .call = nf_tables_abort, - .attr_count = NFTA_TABLE_MAX, - .policy = nft_rule_policy, - }, }; static const struct nfnetlink_subsystem nf_tables_subsys = {
@@ -2821,6 +2808,8 @@ static const struct nfnetlink_subsystem nf_tables_subsys = { .subsys_id = NFNL_SUBSYS_NFTABLES, .cb_count = NFT_MSG_MAX, .cb = nf_tables_cb, + .commit = nf_tables_commit, + .abort = nf_tables_abort, };/*
net/netfilter/nfnetlink.c +167 -4
185 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH v2 4/4 netfilter: nf_tables: all rule updates are transactional
In reply to Pablo Neira AyusoThis patch makes all rule updates transactional, this simplifies the ruleset update logic. Suggested by Patrick McHardy.
--- include/uapi/linux/netfilter/nf_tables.h | 5 --- net/netfilter/nf_tables_api.c | 62 ++++++------------------------ 2 files changed, 12 insertions(+), 55 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +0 -5
@@ -120,11 +120,6 @@ enum nft_chain_attributes { };#define NFTA_CHAIN_MAX (__NFTA_CHAIN_MAX - 1) -enum { -NFT_RULE_F_COMMIT = (1 <<0 ), -NFT_RULE_F_MASK =NFT_RULE_F_COMMIT , -}; -/** * enum nft_rule_attributes - nf_tables rule netlink attributes *
net/netfilter/nf_tables_api.c +12 -50
113 lines not on this page · raw message
Signature · 1 line
1.7.10.4