From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: netfilter-devel <netfilter-devel@vger.kernel.org>
Subject: Re: [PATCH 3/3] netfilter: ctnetlink: allow userspace to set labels
Date: Tue, 27 Nov 2012 13:39:16 +0100 [thread overview]
Message-ID: <20121127123916.GB2351@1984> (raw)
In-Reply-To: <1352994915-3859-4-git-send-email-fw@strlen.de>
While at it, can you also address a couple of nitpicking suggestions?
See below.
On Thu, Nov 15, 2012 at 04:55:15PM +0100, Florian Westphal wrote:
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
> include/net/netfilter/nf_conntrack_labels.h | 3 ++
> net/netfilter/nf_conntrack_labels.c | 34 +++++++++++++++++++++++++++
> net/netfilter/nf_conntrack_netlink.c | 23 ++++++++++++++++++
> 3 files changed, 60 insertions(+), 0 deletions(-)
>
> diff --git a/include/net/netfilter/nf_conntrack_labels.h b/include/net/netfilter/nf_conntrack_labels.h
> index fdd88fb..e058b2b 100644
> --- a/include/net/netfilter/nf_conntrack_labels.h
> +++ b/include/net/netfilter/nf_conntrack_labels.h
> @@ -52,3 +52,6 @@ static inline void nf_conntrack_labels_fini(struct net *net) {}
>
> bool nf_connlabel_match(const struct nf_conn *ct, u16 bit);
> int nf_connlabel_set(struct nf_conn *ct, u16 bit);
> +
> +int nfnetlink_connlabel_set(struct nf_conn *ct, const void *data,
> + unsigned int length);
> diff --git a/net/netfilter/nf_conntrack_labels.c b/net/netfilter/nf_conntrack_labels.c
> index fe9c0c6..8bff33c 100644
> --- a/net/netfilter/nf_conntrack_labels.c
> +++ b/net/netfilter/nf_conntrack_labels.c
> @@ -52,6 +52,40 @@ int nf_connlabel_set(struct nf_conn *ct, u16 bit)
> }
> EXPORT_SYMBOL_GPL(nf_connlabel_set);
>
> +#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
> +int nfnetlink_connlabel_set(struct nf_conn *ct, const void *data, unsigned int length)
Probably rename this to nf_connlabel_set? It is not specific of
nfnetlink (although it is the only client of it so far).
> +{
> + const size_t maxblen = (1024 / BITS_PER_LONG) * sizeof(long);
> + struct nf_conn_labels *labels;
> + unsigned int size;
> +
> + if (length > maxblen)
> + return -EMSGSIZE;
> +
> + labels = nf_ct_labels_find(ct);
> + if (!labels)
> + return -ENOSPC;
> +
> + size = labels->words * sizeof(long);
> +
> + if (size < length)
> + length = size;
> +
> + if (length)
> + memcpy(labels->bits, data, length);
> +
> + if (size > length) {
> + unsigned int pad = size - length;
> + char *mem = (void *) labels->bits;
> + memset(mem + pad, 0, pad);
> + }
> +
> + nf_conntrack_event_cache(IPCT_LABEL, ct);
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(nfnetlink_connlabel_set);
> +#endif
> +
> static struct nf_ct_ext_type labels_extend __read_mostly = {
> .len = sizeof(struct nf_conn_labels),
> .align = __alignof__(struct nf_conn_labels),
> diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
> index 43a1247..834fe99 100644
> --- a/net/netfilter/nf_conntrack_netlink.c
> +++ b/net/netfilter/nf_conntrack_netlink.c
> @@ -1229,6 +1229,16 @@ ctnetlink_change_nat(struct nf_conn *ct, const struct nlattr * const cda[])
> }
>
> static inline int
> +ctnetlink_attach_label(struct nf_conn *ct, const struct nlattr * const cda[])
> +{
> +#ifdef CONFIG_NF_CONNTRACK_LABELS
> + return nfnetlink_connlabel_set(ct, nla_data(cda[CTA_LABELS]), nla_len(cda[CTA_LABELS]));
> +#else
> + return -EOPNOTSUPP;
> +#endif
> +}
Better move this function above to include/net/netfilter/nf_conntrack_labels.h.
> +
> +static inline int
> ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[])
> {
> struct nf_conntrack_helper *helper;
> @@ -1441,6 +1451,11 @@ ctnetlink_change_conntrack(struct nf_conn *ct,
> return err;
> }
> #endif
> + if (cda[CTA_LABELS]) {
> + err = ctnetlink_attach_label(ct, cda);
> + if (err < 0)
> + return err;
> + }
>
> return 0;
> }
> @@ -1649,6 +1664,9 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
> else
> events = IPCT_NEW;
>
> + if (cda[CTA_LABELS] && ctnetlink_attach_label(ct, cda) == 0)
> + events |= (1 << IPCT_LABEL);
> +
> nf_conntrack_eventmask_report((1 << IPCT_REPLY) |
> (1 << IPCT_ASSURED) |
> (1 << IPCT_HELPER) |
> @@ -1946,6 +1964,11 @@ ctnetlink_nfqueue_parse_ct(const struct nlattr *cda[], struct nf_conn *ct)
> if (err < 0)
> return err;
> }
> + if (cda[CTA_LABELS]) {
> + err = ctnetlink_attach_label(ct, cda);
> + if (err < 0)
> + return err;
> + }
> #if defined(CONFIG_NF_CONNTRACK_MARK)
> if (cda[CTA_MARK])
> ct->mark = ntohl(nla_get_be32(cda[CTA_MARK]));
> --
> 1.7.8.6
>
> --
> 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
next prev parent reply other threads:[~2012-11-27 12:39 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-15 15:55 [PATCH 0/3] netfilter: add connlabel conntrack extension Florian Westphal
2012-11-15 15:55 ` [PATCH 1/3] " Florian Westphal
2012-11-15 15:55 ` [PATCH 2/3] netfilter: ctnetlink: deliver labels to userspace via CTA_LABELS attribute Florian Westphal
2012-11-15 15:55 ` [PATCH 3/3] netfilter: ctnetlink: allow userspace to set labels Florian Westphal
2012-11-27 11:18 ` Pablo Neira Ayuso
2012-11-27 11:50 ` Florian Westphal
2012-11-27 12:31 ` Pablo Neira Ayuso
2012-11-27 13:09 ` Florian Westphal
2012-11-27 14:13 ` Pablo Neira Ayuso
2012-11-27 14:24 ` Florian Westphal
2012-11-30 13:58 ` Pablo Neira Ayuso
2012-11-30 14:02 ` Florian Westphal
2012-11-30 18:34 ` Pablo Neira Ayuso
2012-11-30 21:36 ` Florian Westphal
2012-12-03 11:04 ` Pablo Neira Ayuso
2012-12-03 11:13 ` Florian Westphal
2012-12-03 12:58 ` Pablo Neira Ayuso
2012-11-27 12:39 ` Pablo Neira Ayuso [this message]
2012-11-16 10:02 ` [PATCH 0/3] netfilter: add connlabel conntrack extension Pablo Neira Ayuso
2012-11-16 11:31 ` Florian Westphal
2012-11-16 11:52 ` Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20121127123916.GB2351@1984 \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).