* [PATCH -nftables 1/3] netfilter: nf_tables: allow to dump all existing sets
@ 2013-09-19 20:18 Pablo Neira Ayuso
2013-09-19 20:18 ` [PATCH -nftables 2/3] netfilter: nf_tables: nft_meta: fix socket uid,gid handling Pablo Neira Ayuso
2013-09-19 20:18 ` [PATCH -nftables 3/3] netfilter: fix missing dependency Pablo Neira Ayuso
0 siblings, 2 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2013-09-19 20:18 UTC (permalink / raw)
To: netfilter-devel
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.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_tables_api.c | 96 +++++++++++++++++++++++++++++++----------
1 file changed, 74 insertions(+), 22 deletions(-)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 4bb0ea5..35e23b7 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -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;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH -nftables 2/3] netfilter: nf_tables: nft_meta: fix socket uid,gid handling
2013-09-19 20:18 [PATCH -nftables 1/3] netfilter: nf_tables: allow to dump all existing sets Pablo Neira Ayuso
@ 2013-09-19 20:18 ` Pablo Neira Ayuso
2013-09-19 20:18 ` [PATCH -nftables 3/3] netfilter: fix missing dependency Pablo Neira Ayuso
1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2013-09-19 20:18 UTC (permalink / raw)
To: netfilter-devel
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’
Reported-by: Bjørnar Ness <bjornar.ness@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nft_meta.c | 32 ++++++++++++++++++++++++++------
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c
index 84256bc..8c28220 100644
--- a/net/netfilter/nft_meta.c
+++ b/net/netfilter/nft_meta.c
@@ -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: {
--
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH -nftables 3/3] netfilter: fix missing dependency
2013-09-19 20:18 [PATCH -nftables 1/3] netfilter: nf_tables: allow to dump all existing sets Pablo Neira Ayuso
2013-09-19 20:18 ` [PATCH -nftables 2/3] netfilter: nf_tables: nft_meta: fix socket uid,gid handling Pablo Neira Ayuso
@ 2013-09-19 20:18 ` Pablo Neira Ayuso
1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2013-09-19 20:18 UTC (permalink / raw)
To: netfilter-devel
With 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
Reported-by: Bjørnar Ness <bjornar.ness@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/ipv4/netfilter/Kconfig | 2 +-
net/ipv6/netfilter/Kconfig | 2 +-
net/netfilter/Kconfig | 1 +
3 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig
index 4d6f03a..1ea0da4 100644
--- a/net/ipv4/netfilter/Kconfig
+++ b/net/ipv4/netfilter/Kconfig
@@ -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
diff --git a/net/ipv6/netfilter/Kconfig b/net/ipv6/netfilter/Kconfig
index 61270d1..4863516 100644
--- a/net/ipv6/netfilter/Kconfig
+++ b/net/ipv6/netfilter/Kconfig
@@ -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
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index 2e0c3f8..8e2ffe3 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -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
--
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-09-19 20:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-19 20:18 [PATCH -nftables 1/3] netfilter: nf_tables: allow to dump all existing sets Pablo Neira Ayuso
2013-09-19 20:18 ` [PATCH -nftables 2/3] netfilter: nf_tables: nft_meta: fix socket uid,gid handling Pablo Neira Ayuso
2013-09-19 20:18 ` [PATCH -nftables 3/3] netfilter: fix missing dependency Pablo Neira Ayuso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).