netfilter: nf_tables: allow to dump all existing sets
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/3 netfilter: nf_tables: allow to dump all existing sets
If no table specified, dump all existing sets. This simplifies userspace applications, which don't require to iterate over the existing list of tables anymore to retrieve all the existing sets.
--- net/netfilter/nf_tables_api.c | 96 +++++++++++++++++++++++++++++++---------- 1 file changed, 74 insertions(+), 22 deletions(-)
net/netfilter/nf_tables_api.c +74 -22
@@ -1901,15 +1901,17 @@ static int nft_ctx_init_from_setattr(struct nft_ctx *ctx,struct net *net =sock_net (skb->sk);const struct nfgenmsg *nfmsg =nlmsg_data (nlh);const struct nft_af_info *afi; -const struct nft_table *table; +const struct nft_table *table =NULL ; afi =nf_tables_afinfo_lookup (net, nfmsg->nfgen_family, false);if (IS_ERR (afi))return PTR_ERR (afi); - table =nf_tables_table_lookup (afi, nla[NFTA_SET_TABLE ]); -if (IS_ERR (table)) -return PTR_ERR (table); +if (nla[NFTA_SET_TABLE ] !=NULL ) { + table =nf_tables_table_lookup (afi, nla[NFTA_SET_TABLE ]); +if (IS_ERR (table)) +return PTR_ERR (table); + }nft_ctx_init (ctx, skb, nlh, afi, table,NULL , nla);return 0 ;
@@ -2044,14 +2046,70 @@ err:return err; } +static int nf_tables_dump_sets_table (struct nft_ctx *ctx,struct sk_buff *skb, +struct netlink_callback *cb) +{ +const struct nft_set *set; +unsigned int idx =0 , s_idx = cb->args[0 ]; + +if (cb->args[1 ]) +return skb->len; + +list_for_each_entry (set, &ctx->table->sets, list) { +if (idx < s_idx) + goto cont; +if (nf_tables_fill_set (skb, ctx, set,NFT_MSG_NEWSET , +NLM_F_MULTI ) <0 ) { + cb->args[0 ] = idx; + goto done; + } +cont: + idx++; + } + cb->args[1 ] =1 ; +done: +return skb->len; +} + +static int nf_tables_dump_sets_all (struct nft_ctx *ctx,struct sk_buff *skb, +struct netlink_callback *cb) +{ +const struct nft_set *set; +unsigned int idx =0 , s_idx = cb->args[0 ]; +struct nft_table *table, *cur_table = (struct nft_table *)cb->args[2 ]; + +if (cb->args[1 ]) +return skb->len; + +list_for_each_entry (table, &ctx->afi->tables, list) { +if (cur_table && cur_table != table) +continue ; + + ctx->table = table; +list_for_each_entry (set, &ctx->table->sets, list) { +if (idx < s_idx) + goto cont; +if (nf_tables_fill_set (skb, ctx, set,NFT_MSG_NEWSET , +NLM_F_MULTI ) <0 ) { + cb->args[0 ] = idx; + cb->args[2 ] = (unsigned long ) table; + goto done; + } +cont: + idx++; + } + } + cb->args[1 ] =1 ; +done: +return skb->len; +} +static int nf_tables_dump_sets (struct sk_buff *skb,struct netlink_callback *cb) {const struct nfgenmsg *nfmsg =nlmsg_data (cb->nlh);struct nlattr *nla[NFTA_SET_MAX +1 ]; -const struct nft_set *set;struct nft_ctx ctx; -unsigned int idx =0 , s_idx = cb->args[0 ]; -int err; +int err, ret; err =nlmsg_parse (cb->nlh,sizeof (*nfmsg), nla,NFTA_SET_MAX , nft_set_policy);
@@ -2062,21 +2120,12 @@ static int nf_tables_dump_sets(struct sk_buff *skb, struct netlink_callback *cb)if (err <0 )return err; -list_for_each_entry (set, &ctx.table->sets, list) { -if (idx < s_idx) - goto cont; -if (idx > s_idx) -memset (&cb->args[1 ],0 , -sizeof (cb->args) -sizeof (cb->args[0 ])); -if (nf_tables_fill_set (skb, &ctx, set,NFT_MSG_NEWSET , -NLM_F_MULTI ) <0 ) - goto done; -cont: - idx++; - } -done: - cb->args[0 ] = idx; -return skb->len; +if (ctx.table ==NULL ) + ret =nf_tables_dump_sets_all (&ctx, skb, cb); +else + ret =nf_tables_dump_sets_table (&ctx, skb, cb); + +return ret; } static int nf_tables_getset(struct sock *nlsk, struct sk_buff *skb,
@@ -2273,6 +2322,9 @@ static int nf_tables_delset(struct sock *nlsk, struct sk_buff *skb,struct nft_ctx ctx;int err; +if (nla[NFTA_SET_TABLE ] ==NULL ) +return -EINVAL ; + err =nft_ctx_init_from_setattr (&ctx, skb, nlh, nla);if (err <0 )return err;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/3 netfilter: nf_tables: nft_meta: fix socket uid,gid handling
net/netfilter/nft_meta.c: In function ‘nft_meta_eval’:net/netfilter/nft_meta.c:82:17: error: incompatible types when assigning to type ‘u32’ from type ‘kuid_t’ net/netfilter/nft_meta.c:88:17: error: incompatible types when assigning to type ‘u32’ from type ‘kgid_t’
--- net/netfilter/nft_meta.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-)
net/netfilter/nft_meta.c +26 -6
@@ -16,6 +16,7 @@#include <linux/netfilter/nf_tables.h> #include <net/dst.h> #include <net/sock.h> +#include <net/tcp_states.h> /* for TCP_TIME_WAIT */ #include <net/netfilter/nf_tables.h> struct nft_meta {
@@ -76,16 +77,35 @@ static void nft_meta_eval(const struct nft_expr *expr, *(u16 *)dest->data = out->type;break ;case NFT_META_SKUID : -if (skb->sk ==NULL || skb->sk->sk_socket ==NULL || - skb->sk->sk_socket->file ==NULL ) +if (skb->sk ==NULL || skb->sk->sk_state ==TCP_TIME_WAIT ) goto err; - dest->data[0 ] = skb->sk->sk_socket->file->f_cred->fsuid; + +read_lock_bh (&skb->sk->sk_callback_lock); +if (skb->sk->sk_socket ==NULL || + skb->sk->sk_socket->file ==NULL ) { +read_unlock_bh (&skb->sk->sk_callback_lock); + goto err; + } + + dest->data[0 ] = +from_kuid_munged (&init_user_ns, + skb->sk->sk_socket->file->f_cred->fsuid); +read_unlock_bh (&skb->sk->sk_callback_lock);break ;case NFT_META_SKGID : -if (skb->sk ==NULL || skb->sk->sk_socket ==NULL || - skb->sk->sk_socket->file ==NULL ) +if (skb->sk ==NULL || skb->sk->sk_state ==TCP_TIME_WAIT ) + goto err; + +read_lock_bh (&skb->sk->sk_callback_lock); +if (skb->sk->sk_socket ==NULL || + skb->sk->sk_socket->file ==NULL ) { +read_unlock_bh (&skb->sk->sk_callback_lock); goto err; - dest->data[0 ] = skb->sk->sk_socket->file->f_cred->fsgid; + } + dest->data[0 ] = +from_kgid_munged (&init_user_ns, + skb->sk->sk_socket->file->f_cred->fsgid); +read_unlock_bh (&skb->sk->sk_callback_lock);break ;#ifdef CONFIG_NET_CLS_ROUTE case NFT_META_RTCLASSID : {
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Pablo Neira Ayuso
maintainerPATCH 3/3 netfilter: fix missing dependency
In reply to Pablo Neira AyusoWith CONFIG_NFT_CHAIN_NAT_IPV4=y
net/ipv4/netfilter/nft_chain_nat_ipv4.c: In function ‘nf_nat_fn’:net/ipv4/netfilter/nft_chain_nat_ipv4.c:56:1: error: ‘NF_CT_EXT_NAT’ undeclared (first use in this function) net/ipv4/netfilter/nft_chain_nat_ipv4.c:56:1: note: each undeclared identifier is reported only once for each function it appears in
--- net/ipv4/netfilter/Kconfig | 2 +- net/ipv6/netfilter/Kconfig | 2 +- net/netfilter/Kconfig | 1 + 3 files changed, 3 insertions(+), 2 deletions(-)
net/ipv4/netfilter/Kconfig +1 -1
@@ -50,7 +50,7 @@ config NFT_CHAIN_ROUTE_IPV4 config NFT_CHAIN_NAT_IPV4 depends on NF_TABLES_IPV4 - depends on NFT_NAT + depends on NF_NAT_IPV4 && NFT_NAT tristate "IPv4 nf_tables nat chain support" config NF_TABLES_ARP
net/ipv6/netfilter/Kconfig +1 -1
@@ -35,7 +35,7 @@ config NFT_CHAIN_ROUTE_IPV6 config NFT_CHAIN_NAT_IPV6 depends on NF_TABLES_IPV6 - depends on NFT_NAT + depends on NF_NAT_IPV6 && NFT_NAT tristate "IPv6 nf_tables nat chain support" config IP6_NF_IPTABLES
net/netfilter/Kconfig +1 -0
@@ -464,6 +464,7 @@ config NFT_LIMIT config NFT_NAT depends on NF_TABLES depends on NF_CONNTRACK + depends on NF_NAT tristate "Netfilter nf_tables nat module" config NFT_COMPAT
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html