netlink: netlink_dump_start takes pointer to data
Subsystems (7)
[email protected]
maintainercover netlink: netlink_dump_start takes pointer to data
From: Pablo Neira Ayuso <[email protected]>
Hi!
This is the second version of the extension for netlink_dump_start to take one data pointer that can be pass to the dump callback.
These changes allow to filter by the ctmark in ctnetlink.
Suggestion from Davem has been included in this patchset.
Thanks!
Pablo Neira Ayuso (3):
netlink: add netlink_dump_control structure for netlink_dump_start()
netlink: allow to pass data pointer to netlink_dump_start() callback
netfilter: ctnetlink: support kernel-space dump filtering by ctmark
crypto/crypto_user.c | 10 +++- drivers/infiniband/core/netlink.c | 10 +++- include/linux/netfilter/nfnetlink_conntrack.h | 1 + include/linux/netlink.h | 12 ++++- net/core/rtnetlink.c | 9 +++- net/ipv4/inet_diag.c | 18 ++++++--- net/netfilter/ipset/ip_set_core.c | 10 +++- net/netfilter/nf_conntrack_netlink.c | 50 ++++++++++++++++++++++--- net/netfilter/nfnetlink_acct.c | 6 ++- net/netlink/af_netlink.c | 12 ++--- net/netlink/genetlink.c | 9 +++- net/unix/diag.c | 10 +++-- net/xfrm/xfrm_user.c | 9 +++- 13 files changed, 123 insertions(+), 43 deletions(-)
Signature · 1 line
1.7.7.3
[email protected]
maintainerPATCH 1/3 netlink: add netlink_dump_control structure for netlink_dump_start()
From: Pablo Neira Ayuso <[email protected]>
Davem considers that the argument list of this interface is getting out of control. This patch tries to address this issue following his proposal:
struct netlink_dump_control c = { .dump = dump, .done = done, ... };
netlink_dump_start(..., &c);
Suggested by David S. Miller.
--- crypto/crypto_user.c | 10 +++++++--- drivers/infiniband/core/netlink.c | 10 +++++++--- include/linux/netlink.h | 10 +++++++--- net/core/rtnetlink.c | 9 +++++++-- net/ipv4/inet_diag.c | 18 ++++++++++++------ net/netfilter/ipset/ip_set_core.c | 10 +++++++--- net/netfilter/nf_conntrack_netlink.c | 18 ++++++++++++------ net/netfilter/nfnetlink_acct.c | 6 ++++-- net/netlink/af_netlink.c | 11 ++++------- net/netlink/genetlink.c | 9 +++++++-- net/unix/diag.c | 10 ++++++---- net/xfrm/xfrm_user.c | 9 +++++++-- 12 files changed, 87 insertions(+), 43 deletions(-)
crypto/crypto_user.c +7 -3
@@ -389,9 +389,13 @@ static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) (nlh->nlmsg_flags & NLM_F_DUMP))) {if (link->dump ==NULL )return -EINVAL ; - -return netlink_dump_start (crypto_nlsk, skb, nlh, - link->dump, link->done,0 ); + { +struct netlink_dump_control c = { + .dump = link->dump, + .done = link->done, + }; +return netlink_dump_start (crypto_nlsk, skb, nlh, &c); + } } err = nlmsg_parse(nlh, crypto_msg_min[type], attrs, CRYPTOCFGA_MAX,
drivers/infiniband/core/netlink.c +7 -3
@@ -147,9 +147,13 @@ static int ibnl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)if (op <0 || op >= client->nops || !client->cb_table[RDMA_NL_GET_OP (op)].dump)return -EINVAL ; -return netlink_dump_start (nls, skb, nlh, - client->cb_table[op].dump, -NULL ,0 ); + + { +struct netlink_dump_control c = { + .dump = client->cb_table[op].dump, + }; +return netlink_dump_start (nls, skb, nlh, &c); + } } }
include/linux/netlink.h +7 -3
@@ -248,11 +248,15 @@ __nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len, int flags)#define NLMSG_PUT (skb, pid, seq, type, len) \ NLMSG_NEW(skb, pid, seq, type, len, 0) +struct netlink_dump_control { +int (*dump)(struct sk_buff *skb,struct netlink_callback *); +int (*done)(struct netlink_callback *); +u16 min_dump_alloc; +}; +extern int netlink_dump_start (struct sock *ssk,struct sk_buff *skb,const struct nlmsghdr *nlh, -int (*dump)(struct sk_buff *skb,struct netlink_callback *), -int (*done)(struct netlink_callback *), -u16 min_dump_alloc); +struct netlink_dump_control *control);#define NL_NONROOT_RECV 0x1
net/core/rtnetlink.c +7 -2
@@ -1981,8 +1981,13 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)__rtnl_unlock (); rtnl = net->rtnl; - err =netlink_dump_start (rtnl, skb, nlh, dumpit, -NULL , min_dump_alloc); + { +struct netlink_dump_control c = { + .dump = dumpit, + .min_dump_alloc = min_dump_alloc, + }; + err =netlink_dump_start (rtnl, skb, nlh, &c); + }rtnl_lock ();return err; }
net/ipv4/inet_diag.c +12 -6
@@ -960,9 +960,12 @@ static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh) inet_diag_bc_audit(nla_data(attr), nla_len(attr))) return -EINVAL; } - -return netlink_dump_start (sock_diag_nlsk, skb, nlh, - inet_diag_dump_compat,NULL ,0 ); + { +struct netlink_dump_control c = { + .dump = inet_diag_dump_compat, + }; +return netlink_dump_start (sock_diag_nlsk, skb, nlh, &c); + } }return inet_diag_get_exact_compat (skb, nlh);
@@ -985,9 +988,12 @@ static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) inet_diag_bc_audit(nla_data(attr), nla_len(attr))) return -EINVAL; } - -return netlink_dump_start (sock_diag_nlsk, skb, h, - inet_diag_dump,NULL ,0 ); + { +struct netlink_dump_control c = { + .dump = inet_diag_dump, + }; +return netlink_dump_start (sock_diag_nlsk, skb, h, &c); + } }return inet_diag_get_exact (skb, h, (struct inet_diag_req_v2 *)NLMSG_DATA (h));
net/netfilter/ipset/ip_set_core.c +7 -3
@@ -1162,9 +1162,13 @@ ip_set_dump(struct sock *ctnl, struct sk_buff *skb,if (unlikely (protocol_failed (attr)))return -IPSET_ERR_PROTOCOL ; -return netlink_dump_start (ctnl, skb, nlh, - ip_set_dump_start, - ip_set_dump_done,0 ); + { +struct netlink_dump_control c = { + .dump = ip_set_dump_start, + .done = ip_set_dump_done, + }; +return netlink_dump_start (ctnl, skb, nlh, &c); + } }/* Add, del and test */
net/netfilter/nf_conntrack_netlink.c +12 -6
@@ -977,9 +977,13 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,u16 zone;int err; -if (nlh->nlmsg_flags &NLM_F_DUMP ) -return netlink_dump_start (ctnl, skb, nlh, ctnetlink_dump_table, - ctnetlink_done,0 ); +if (nlh->nlmsg_flags &NLM_F_DUMP ) { +struct netlink_dump_control c = { + .dump = ctnetlink_dump_table, + .done = ctnetlink_done, + }; +return netlink_dump_start (ctnl, skb, nlh, &c); + } err =ctnetlink_parse_zone (cda[CTA_ZONE ], &zone);if (err <0 )
@@ -1881,9 +1885,11 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,int err;if (nlh->nlmsg_flags &NLM_F_DUMP ) { -return netlink_dump_start (ctnl, skb, nlh, - ctnetlink_exp_dump_table, - ctnetlink_exp_done,0 ); +struct netlink_dump_control c = { + .dump = ctnetlink_exp_dump_table, + .done = ctnetlink_exp_done, + }; +return netlink_dump_start (ctnl, skb, nlh, &c); } err =ctnetlink_parse_zone (cda[CTA_EXPECT_ZONE ], &zone);
net/netfilter/nfnetlink_acct.c +4 -2
@@ -171,8 +171,10 @@ nfnl_acct_get(struct sock *nfnl, struct sk_buff *skb,char *acct_name;if (nlh->nlmsg_flags &NLM_F_DUMP ) { -return netlink_dump_start (nfnl, skb, nlh, nfnl_acct_dump, -NULL ,0 ); +struct netlink_dump_control c = { + .dump = nfnl_acct_dump, + }; +return netlink_dump_start (nfnl, skb, nlh, &c); }if (!tb[NFACCT_NAME ])
net/netlink/af_netlink.c +4 -7
@@ -1736,10 +1736,7 @@ errout_skb:int netlink_dump_start (struct sock *ssk,struct sk_buff *skb,const struct nlmsghdr *nlh, -int (*dump)(struct sk_buff *skb, -struct netlink_callback *), -int (*done)(struct netlink_callback *), -u16 min_dump_alloc) +struct netlink_dump_control *control) {struct netlink_callback *cb;struct sock *sk;
@@ -1750,10 +1747,10 @@ int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,if (cb ==NULL )return -ENOBUFS ; - cb->dump = dump; - cb->done = done; + cb->dump = control->dump; + cb->done = control->done; cb->nlh = nlh; - cb->min_dump_alloc = min_dump_alloc; + cb->min_dump_alloc = control->min_dump_alloc;atomic_inc (&skb->users); cb->skb = skb;
net/netlink/genetlink.c +7 -2
@@ -563,8 +563,13 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)return -EOPNOTSUPP ;genl_unlock (); - err =netlink_dump_start (net->genl_sock, skb, nlh, - ops->dumpit, ops->done,0 ); + { +struct netlink_dump_control c = { + .dump = ops->dumpit, + .done = ops->done, + }; + err =netlink_dump_start (net->genl_sock, skb, nlh, &c); + }genl_lock ();return err; }
net/unix/diag.c +6 -4
@@ -301,10 +301,12 @@ static int unix_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)if (nlmsg_len (h) < hdrlen)return -EINVAL ; -if (h->nlmsg_flags &NLM_F_DUMP ) -return netlink_dump_start (sock_diag_nlsk, skb, h, - unix_diag_dump,NULL ,0 ); -else +if (h->nlmsg_flags &NLM_F_DUMP ) { +struct netlink_dump_control c = { + .dump = unix_diag_dump, + }; +return netlink_dump_start (sock_diag_nlsk, skb, h, &c); + }else return unix_diag_get_exact (skb, h, (struct unix_diag_req *)NLMSG_DATA (h)); }
net/xfrm/xfrm_user.c +7 -2
@@ -2299,8 +2299,13 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)if (link->dump ==NULL )return -EINVAL ; -return netlink_dump_start (net->xfrm.nlsk, skb, nlh, - link->dump, link->done,0 ); + { +struct netlink_dump_control c = { + .dump = link->dump, + .done = link->done, + }; +return netlink_dump_start (net->xfrm.nlsk, skb, nlh, &c); + } } err = nlmsg_parse(nlh, xfrm_msg_min[type], attrs, XFRMA_MAX,
Signature · 1 line
1.7.7.3
Re: [PATCH 1/3] netlink: add netlink_dump_control structure for netlink_dump_start()
Quoted 9 lines · On Saturday 2012-02-25 01:30, [email protected] wrote:
From: Pablo Neira Ayuso <[email protected]>
Davem considers that the argument list of this interface is getting out of control. This patch tries to address this issue following his proposal:
struct
netlink_dump_controlc = { .dump = dump, .done = done, ... };
netlink_dump_start(..., &c);
What about adding skb and nlh into c as well? After all, skb is not nearly as much {used directly} as it is in Xtables.
crypto/crypto_user.c static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 398
Quoted 7 lines
crypto/crypto_user.c +7
-0+ { +struct netlink_dump_control c = { + .dump = link->dump, + .done = link->done, + }; +return netlink_dump_start (crypto_nlsk, skb, nlh, &c); + }
You can also use
return netlink_dump_start(crypto_nlsk, skb,
&(const struct netlink_dump_control) {.dump = link->dump, .done = link->done}));
Pablo Neira Ayuso
maintainerRe: [PATCH 1/3] netlink: add netlink_dump_control structure for netlink_dump_start()
Quoted 8 lines · Jan Engelhardt
Quoted 6 lines · On Saturday 2012-02-25 01:30, [email protected] wrote:
From: Pablo Neira Ayuso <[email protected]>
Davem considers that the argument list of this interface is getting out of control. This patch tries to address this issue following his proposal:
Quoted 6 lines
Quoted 3 lines
struct
netlink_dump_controlc = { .dump = dump, .done = done, ... };
netlink_dump_start(..., &c);What about adding skb and nlh into c as well? After all, skb is not nearly as much {used directly} as it is in Xtables.
If you look at all netlink_dump_start invocations. Those are always included. The idea was to add to the structure fields that may be unset.
Quoted 10 lines
crypto/crypto_user.c static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 398
Quoted 7 lines
crypto/crypto_user.c +7
-0+ { +struct netlink_dump_control c = { + .dump = link->dump, + .done = link->done, + }; +return netlink_dump_start (crypto_nlsk, skb, nlh, &c); + }You can also use
Quoted 3 lines
return netlink_dump_start(crypto_nlsk, skb,
&(const structnetlink_dump_control) {.dump =link->dump, .done =link->done}));
Nice to know, thanks. Haven't see this in any other part of the kernel code though and it looks a bit ugly IMO. I think I prefer the way it is now.
Re: [PATCH 1/3] netlink: add netlink_dump_control structure for netlink_dump_start()
In reply to [email protected]From: [email protected]
Date: Sat, 25 Feb 2012 01:30:15 +0100
Quoted 6 lines
From: Pablo Neira Ayuso <[email protected]>
Davem considers that the argument list of this interface is getting out of control. This patch tries to address this issue following his proposal:
Quoted 7 lines
struct
netlink_dump_controlc = { .dump = dump, .done = done, ... };
netlink_dump_start(..., &c);Suggested by David S. Miller.
Signed-off-by Pablo Neira Ayuso <[email protected]>
Applied.
[email protected]
maintainerPATCH 2/3 netlink: allow to pass data pointer to netlink_dump_start() callback
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
This patch allows you to pass a data pointer that can be accessed from the dump callback.
Netfilter is going to use this patch to provide filtered dumps to user-space. This is specifically interesting in ctnetlink that may handle lots of conntrack entries. We can save precious cycles by skipping the conversion to TLV format of conntrack entries that are not interesting for user-space.
More specifically, ctnetlink will include one operation to allow to filter the dumping of conntrack entries by ctmark values.
--- include/linux/netlink.h | 2 ++ net/netlink/af_netlink.c | 1 + 2 files changed, 3 insertions(+), 0 deletions(-)
include/linux/netlink.h +2 -0
@@ -225,6 +225,7 @@ struct netlink_callback {int (*dump)(struct sk_buff * skb,struct netlink_callback *cb);int (*done)(struct netlink_callback *cb); +void *data;u16 family;u16 min_dump_alloc;unsigned int prev_seq, seq;
@@ -251,6 +252,7 @@ __nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len, int flags)struct netlink_dump_control {int (*dump)(struct sk_buff *skb,struct netlink_callback *);int (*done)(struct netlink_callback *); +void *data;u16 min_dump_alloc; };
net/netlink/af_netlink.c +1 -0
@@ -1750,6 +1750,7 @@ int netlink_dump_start(struct sock *ssk, struct sk_buff *skb, cb->dump = control->dump; cb->done = control->done; cb->nlh = nlh; + cb->data = control->data; cb->min_dump_alloc = control->min_dump_alloc;atomic_inc (&skb->users); cb->skb = skb;
Signature · 1 line
1.7.7.3
Re: [PATCH 2/3] netlink: allow to pass data pointer to netlink_dump_start() callback
From: [email protected]
Date: Sat, 25 Feb 2012 01:30:16 +0100
Quoted 11 lines
From: Pablo Neira Ayuso <[email protected]>
This patch allows you to pass a data pointer that can be accessed from the dump callback.
Netfilter is going to use this patch to provide filtered dumps to user-space. This is specifically interesting in ctnetlink that may handle lots of conntrack entries. We can save precious cycles by skipping the conversion to TLV format of conntrack entries that are not interesting for user-space.
Quoted 4 lines
More specifically, ctnetlink will include one operation to allow to filter the dumping of conntrack entries by ctmark values.
Signed-off-by Pablo Neira Ayuso <[email protected]>
Applied.
[email protected]
maintainerPATCH 3/3 netfilter: ctnetlink: support kernel-space dump filtering by ctmark
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
This patch adds CTA_MARK_MASK which, together with CTA_MARK, allows you to selectively send conntrack entries to user-space by returning those that match mark & mask.
With this, we can save cycles in the building and the parsing of the entries that may be later on filtered out in user-space by using the ctmark & mask.
--- include/linux/netfilter/nfnetlink_conntrack.h | 1 + net/netfilter/nf_conntrack_netlink.c | 32 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-)
include/linux/netfilter/nfnetlink_conntrack.h +1 -0
@@ -43,6 +43,7 @@ enum ctattr_type {CTA_ZONE ,CTA_SECCTX ,CTA_TIMESTAMP , +CTA_MARK_MASK , __CTA_MAX };#define CTA_MAX (__CTA_MAX - 1)
net/netfilter/nf_conntrack_netlink.c +32 -0
@@ -691,9 +691,18 @@ static int ctnetlink_done(struct netlink_callback *cb) {if (cb->args[1 ])nf_ct_put ((struct nf_conn *)cb->args[1 ]); +if (cb->data) +kfree (cb->data);return 0 ; } +struct ctnetlink_dump_filter { +struct { +u_int32_t val; +u_int32_t mask; + } mark; +}; +static int ctnetlink_dump_table (struct sk_buff *skb,struct netlink_callback *cb) {
@@ -703,6 +712,7 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)struct hlist_nulls_node *n;struct nfgenmsg *nfmsg =nlmsg_data (cb->nlh);u_int8_t l3proto = nfmsg->nfgen_family; +const struct ctnetlink_dump_filter *filter = cb->data;spin_lock_bh (&nf_conntrack_lock); last = (struct nf_conn *)cb->args[1 ];
@@ -723,6 +733,12 @@ restart:continue ; cb->args[1 ] =0 ; } +#ifdef CONFIG_NF_CONNTRACK_MARK +if (filter && !((ct->mark & filter->mark.mask) == + filter->mark.val)) { +continue ; + } +#endif if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid, cb->nlh->nlmsg_seq, NFNL_MSG_TYPE(
@@ -894,6 +910,7 @@ static const struct nla_policy ct_nla_policy[CTA_MAX+1] = { [CTA_NAT_DST] = { .type = NLA_NESTED }, [CTA_TUPLE_MASTER] = { .type = NLA_NESTED }, [CTA_ZONE] = { .type = NLA_U16 }, + [CTA_MARK_MASK] = { .type = NLA_U32 }, }; static int
@@ -982,6 +999,21 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb, .dump = ctnetlink_dump_table, .done = ctnetlink_done, }; +#ifdef CONFIG_NF_CONNTRACK_MARK +if (cda[CTA_MARK ] && cda[CTA_MARK_MASK ]) { +struct ctnetlink_dump_filter *filter; + + filter =kzalloc (sizeof (struct ctnetlink_dump_filter ), +GFP_ATOMIC ); +if (filter ==NULL ) +return -ENOMEM ; + + filter->mark.val =ntohl (nla_get_be32 (cda[CTA_MARK ])); + filter->mark.mask = +ntohl (nla_get_be32 (cda[CTA_MARK_MASK ])); + c.data = filter; + } +#endif return netlink_dump_start (ctnl, skb, nlh, &c); }
Signature · 1 line
1.7.7.3
Pablo Neira Ayuso
maintainerRe: [PATCH 3/3] netfilter: ctnetlink: support kernel-space dump filtering by ctmark
Quoted 9 lines · On Sat, Feb 25, 2012 at 01:30:17AM +0100, [email protected] wrote:
From: Pablo Neira Ayuso <[email protected]>
This patch adds
CTA_MARK_MASKwhich, together withCTA_MARK, allows you to selectively send conntrack entries to user-space by returning those that match mark & mask.With this, we can save cycles in the building and the parsing of the entries that may be later on filtered out in user-space by using the ctmark & mask.
Minor glitch in this patch. One ifdef was missing that would spot an unused variable warning if CONFIG_NF_CONNTRACK_MARK is disabled.
New patch for ctnetlink attached.
Quoted 1 line
From
604bb5f7385bcde5be0e0a5f3f52fa05ef21d3bcMon Sep 17 00:00:00 2001
From: Pablo Neira Ayuso <[email protected]>
Date: Sat, 25 Feb 2012 00:48:38 +0100
Subject: [PATCH 3/3] netfilter: ctnetlink: support kernel-space dump
filtering by ctmark
This patch adds CTA_MARK_MASK which, together with CTA_MARK, allows you to selectively send conntrack entries to user-space by returning those that match mark & mask.
With this, we can save cycles in the building and the parsing of the entries that may be later on filtered out in user-space by using the ctmark & mask.
--- include/linux/netfilter/nfnetlink_conntrack.h | 1 + net/netfilter/nf_conntrack_netlink.c | 35 ++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletions(-)
include/linux/netfilter/nfnetlink_conntrack.h +1 -0
@@ -43,6 +43,7 @@ enum ctattr_type {CTA_ZONE ,CTA_SECCTX ,CTA_TIMESTAMP , +CTA_MARK_MASK , __CTA_MAX };#define CTA_MAX (__CTA_MAX - 1)
net/netfilter/nf_conntrack_netlink.c +34 -1
@@ -691,9 +691,18 @@ static int ctnetlink_done(struct netlink_callback *cb) {if (cb->args[1 ])nf_ct_put ((struct nf_conn *)cb->args[1 ]); +if (cb->data) +kfree (cb->data);return 0 ; } +struct ctnetlink_dump_filter { +struct { +u_int32_t val; +u_int32_t mask; + } mark; +}; +static int ctnetlink_dump_table (struct sk_buff *skb,struct netlink_callback *cb) {
@@ -703,7 +712,9 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)struct hlist_nulls_node *n;struct nfgenmsg *nfmsg =nlmsg_data (cb->nlh);u_int8_t l3proto = nfmsg->nfgen_family; - +#ifdef CONFIG_NF_CONNTRACK_MARK +const struct ctnetlink_dump_filter *filter = cb->data; +#endif spin_lock_bh (&nf_conntrack_lock); last = (struct nf_conn *)cb->args[1 ];for (; cb->args[0 ] < net->ct.htable_size; cb->args[0 ]++) {
@@ -723,6 +734,12 @@ restart:continue ; cb->args[1 ] =0 ; } +#ifdef CONFIG_NF_CONNTRACK_MARK +if (filter && !((ct->mark & filter->mark.mask) == + filter->mark.val)) { +continue ; + } +#endif if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid, cb->nlh->nlmsg_seq, NFNL_MSG_TYPE(
@@ -894,6 +911,7 @@ static const struct nla_policy ct_nla_policy[CTA_MAX+1] = { [CTA_NAT_DST] = { .type = NLA_NESTED }, [CTA_TUPLE_MASTER] = { .type = NLA_NESTED }, [CTA_ZONE] = { .type = NLA_U16 }, + [CTA_MARK_MASK] = { .type = NLA_U32 }, }; static int
@@ -982,6 +1000,21 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb, .dump = ctnetlink_dump_table, .done = ctnetlink_done, }; +#ifdef CONFIG_NF_CONNTRACK_MARK +if (cda[CTA_MARK ] && cda[CTA_MARK_MASK ]) { +struct ctnetlink_dump_filter *filter; + + filter =kzalloc (sizeof (struct ctnetlink_dump_filter ), +GFP_ATOMIC ); +if (filter ==NULL ) +return -ENOMEM ; + + filter->mark.val =ntohl (nla_get_be32 (cda[CTA_MARK ])); + filter->mark.mask = +ntohl (nla_get_be32 (cda[CTA_MARK_MASK ])); + c.data = filter; + } +#endif return netlink_dump_start (ctnl, skb, nlh, &c); }
Signature · 1 line
1.7.7.3
Re: [PATCH 3/3] netfilter: ctnetlink: support kernel-space dump filtering by ctmark
From: Pablo Neira Ayuso <[email protected]>
Date: Sat, 25 Feb 2012 01:41:50 +0100
Quoted 7 lines · On Sat, Feb 25, 2012 at 01:30:17AM +0100, [email protected] wrote:
Quoted 6 lines
From: Pablo Neira Ayuso <[email protected]>
This patch adds
CTA_MARK_MASKwhich, together withCTA_MARK, allows you to selectively send conntrack entries to user-space by returning those that match mark & mask.
Quoted 8 lines
Quoted 3 lines
With this, we can save cycles in the building and the parsing of the entries that may be later on filtered out in user-space by using the ctmark & mask.
Minor glitch in this patch. One ifdef was missing that would spot an unused variable warning if
CONFIG_NF_CONNTRACK_MARKis disabled.New patch for ctnetlink attached.
Applied.