Netfilter updates for net-next
Subsystems (3)
Pablo Neira Ayuso
maintainerPATCH 1/3 netfilter: nftables: add helper function to release one table
In reply to Pablo Neira AyusoAdd a function to release one table.
--- net/netfilter/nf_tables_api.c | 75 +++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 35 deletions(-)
net/netfilter/nf_tables_api.c +40 -35
@@ -8999,10 +8999,9 @@ static void __nft_release_hooks(struct net *net) } } -static void __nft_release_tables (struct net *net) +static void __nft_release_table (struct net *net,struct nft_table *table) {struct nft_flowtable *flowtable, *nf; -struct nft_table *table, *nt;struct nft_chain *chain, *nc;struct nft_object *obj, *ne;struct nft_rule *rule, *nr;
@@ -9012,41 +9011,47 @@ static void __nft_release_tables(struct net *net) .family = NFPROTO_NETDEV, }; -list_for_each_entry_safe (table, nt, &net->nft.tables, list) { - ctx.family = table->family; - ctx.table = table; -list_for_each_entry (chain, &table->chains, list) { - ctx.chain = chain; -list_for_each_entry_safe (rule, nr, &chain->rules, list) { -list_del (&rule->list); - chain->use--; -nf_tables_rule_release (&ctx, rule); - } - } -list_for_each_entry_safe (flowtable, nf, &table->flowtables, list) { -list_del (&flowtable->list); - table->use--; -nf_tables_flowtable_destroy (flowtable); - } -list_for_each_entry_safe (set, ns, &table->sets, list) { -list_del (&set->list); - table->use--; -nft_set_destroy (&ctx, set); - } -list_for_each_entry_safe (obj, ne, &table->objects, list) { -nft_obj_del (obj); - table->use--; -nft_obj_destroy (&ctx, obj); - } -list_for_each_entry_safe (chain, nc, &table->chains, list) { - ctx.chain = chain; -nft_chain_del (chain); - table->use--; -nf_tables_chain_destroy (&ctx); + ctx.family = table->family; + ctx.table = table; +list_for_each_entry (chain, &table->chains, list) { + ctx.chain = chain; +list_for_each_entry_safe (rule, nr, &chain->rules, list) { +list_del (&rule->list); + chain->use--; +nf_tables_rule_release (&ctx, rule); } -list_del (&table->list); -nf_tables_table_destroy (&ctx); } +list_for_each_entry_safe (flowtable, nf, &table->flowtables, list) { +list_del (&flowtable->list); + table->use--; +nf_tables_flowtable_destroy (flowtable); + } +list_for_each_entry_safe (set, ns, &table->sets, list) { +list_del (&set->list); + table->use--; +nft_set_destroy (&ctx, set); + } +list_for_each_entry_safe (obj, ne, &table->objects, list) { +nft_obj_del (obj); + table->use--; +nft_obj_destroy (&ctx, obj); + } +list_for_each_entry_safe (chain, nc, &table->chains, list) { + ctx.chain = chain; +nft_chain_del (chain); + table->use--; +nf_tables_chain_destroy (&ctx); + } +list_del (&table->list); +nf_tables_table_destroy (&ctx); +} + +static void __nft_release_tables (struct net *net) +{ +struct nft_table *table, *nt; + +list_for_each_entry_safe (table, nt, &net->nft.tables, list) +__nft_release_table (net, table); }static int __net_init nf_tables_init_net (struct net *net)
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 3/3 netfilter: nftables: introduce table ownership
In reply to Pablo Neira AyusoA userspace daemon like firewalld might need to monitor for netlink updates to detect its ruleset removal by the (global) flush ruleset command to ensure ruleset persistency. This adds extra complexity from userspace and, for some little time, the firewall policy is not in place.
This patch adds the NFT_TABLE_F_OWNER flag which allows a userspace program to own the table that creates in exclusivity.
Tables that are owned...
- can only be updated and removed by the owner, non-owners hit EPERM if they try to update it or remove it.
- are destroyed when the owner closes the netlink socket or the process is gone (implicit netlink socket closure).
- are skipped by the global flush ruleset command.
- are listed in the global ruleset.
The userspace process that sets on the NFT_TABLE_F_OWNER flag need to leave open the netlink socket.
A new NFTA_TABLE_OWNER netlink attribute specifies the netlink port ID to identify the owner from userspace.
This patch also updates error reporting when an unknown table flag is specified to change it from EINVAL to EOPNOTSUPP given that EINVAL is usually reserved to report for malformed netlink messages to userspace.
--- include/net/netfilter/nf_tables.h | 6 + include/uapi/linux/netfilter/nf_tables.h | 5 + net/netfilter/nf_tables_api.c | 163 ++++++++++++++++------- 3 files changed, 128 insertions(+), 46 deletions(-)
include/net/netfilter/nf_tables.h +6 -0
@@ -1106,11 +1106,17 @@ struct nft_table { u16 family:6, flags:8, genmask:2; +u32 nlpid;char *name;u16 udlen;u8 *udata; }; +static inline bool nft_table_has_owner (const struct nft_table *table) +{ +return table->flags &NFT_TABLE_F_OWNER ; +} +static inline bool nft_base_chain_netdev (int family,u32 hooknum) { return family == NFPROTO_NETDEV ||
include/uapi/linux/netfilter/nf_tables.h +5 -0
@@ -164,7 +164,10 @@ enum nft_hook_attributes {*/ enum nft_table_flags {NFT_TABLE_F_DORMANT =0x1 , +NFT_TABLE_F_OWNER =0x2 , }; +#define NFT_TABLE_F_MASK (NFT_TABLE_F_DORMANT | \ + NFT_TABLE_F_OWNER)/** * enum nft_table_attributes - nf_tables table netlink attributes
@@ -173,6 +176,7 @@ enum nft_table_flags {* @NFTA_TABLE_FLAGS: bitmask of enum nft_table_flags (NLA_U32) * @NFTA_TABLE_USE: number of chains in this table (NLA_U32) * @NFTA_TABLE_USERDATA: user data (NLA_BINARY) +* @NFTA_TABLE_OWNER: owner of this table through netlink portID (NLA_U32) */ enum nft_table_attributes {NFTA_TABLE_UNSPEC ,
@@ -182,6 +186,7 @@ enum nft_table_attributes {NFTA_TABLE_HANDLE ,NFTA_TABLE_PAD ,NFTA_TABLE_USERDATA , +NFTA_TABLE_OWNER , __NFTA_TABLE_MAX };#define NFTA_TABLE_MAX (__NFTA_TABLE_MAX - 1)
net/netfilter/nf_tables_api.c +117 -46
411 lines not on this page · raw message
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainercover Netfilter updates for net-next
Hi,
The following patchset contains Netfilter updates for net-next:
1) Add two helper functions to release one table and hooks from the netns and netlink event path.
2) Add table ownership infrastructure, this new infrastructure allows users to bind a table (and its content) to a process through the netlink socket.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Thanks!
----------------------------------------------------------------
The following changes since commit c4762993129f48f5f5e233f09c246696815ef263:
Merge branch 'skbuff-introduce-skbuff_heads-bulking-and-reusing' (2021-02-13 14:32:04 -0800)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git HEAD
for you to fetch changes up to 6001a930ce0378b62210d4f83583fc88a903d89d:
netfilter: nftables: introduce table ownership (2021-02-15 18:17:15 +0100)
----------------------------------------------------------------
Pablo Neira Ayuso (3):
netfilter: nftables: add helper function to release one table
netfilter: nftables: add helper function to release hooks of one single table
netfilter: nftables: introduce table ownership
include/net/netfilter/nf_tables.h | 6 + include/uapi/linux/netfilter/nf_tables.h | 5 + net/netfilter/nf_tables_api.c | 245 ++++++++++++++++++++----------- 3 files changed, 174 insertions(+), 82 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 2/3 netfilter: nftables: add helper function to release hooks of one single table
Add a function to release the hooks of one single table.
--- net/netfilter/nf_tables_api.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
net/netfilter/nf_tables_api.c +10 -5
@@ -8988,15 +8988,20 @@ int __nft_release_basechain(struct nft_ctx *ctx) }EXPORT_SYMBOL_GPL (__nft_release_basechain); +static void __nft_release_hook (struct net *net,struct nft_table *table) +{ +struct nft_chain *chain; + +list_for_each_entry (chain, &table->chains, list) +nf_tables_unregister_hook (net, table, chain); +} +static void __nft_release_hooks (struct net *net) {struct nft_table *table; -struct nft_chain *chain; -list_for_each_entry (table, &net->nft.tables, list) { -list_for_each_entry (chain, &table->chains, list) -nf_tables_unregister_hook (net, table, chain); - } +list_for_each_entry (table, &net->nft.tables, list) +__nft_release_hook (net, table); }static void __nft_release_table (struct net *net,struct nft_table *table)
Signature · 1 line
2.20.1
Re: [PATCH net-next 1/3] netfilter: nftables: add helper function to release one table
In reply to Pablo Neira AyusoThis series was applied to netdev/net-next.git (refs/heads/master):
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
Quoted 6 lines · On Wed, 17 Feb 2021 20:03:30 +0100 you wrote:
Add a function to release one table.
Signed-off-by Pablo Neira Ayuso <[email protected]>--- net/netfilter/nf_tables_api.c | 75 +++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 35 deletions(-)
Here is the summary with links:
- [net-next,1/3] netfilter: nftables: add helper function to release one table
https://git.kernel.org/netdev/net-next/c/fd020332c156 - [net-next,2/3] netfilter: nftables: add helper function to release hooks of one single table https://git.kernel.org/netdev/net-next/c/00dfe9bebdf0 - [net-next,3/3] netfilter: nftables: introduce table ownership https://git.kernel.org/netdev/net-next/c/6001a930ce03
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html