From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: [PATCH 21/23] netfilter: connlabels: change nf_connlabels_get bit arg to 'highest used'
Date: Fri, 22 Apr 2016 15:39:52 +0200 [thread overview]
Message-ID: <1461332394-3994-22-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1461332394-3994-1-git-send-email-pablo@netfilter.org>
From: Florian Westphal <fw@strlen.de>
nf_connlabel_set() takes the bit number that we would like to set.
nf_connlabels_get() however took the number of bits that we want to
support.
So e.g. nf_connlabels_get(32) support bits 0 to 31, but not 32.
This changes nf_connlabels_get() to take the highest bit that we want
to set.
Callers then don't have to cope with a potential integer wrap
when using nf_connlabels_get(bit + 1) anymore.
Current callers are fine, this change is only to make folloup
nft ct label set support simpler.
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/net/netfilter/nf_conntrack_labels.h | 4 ++--
net/netfilter/nf_conntrack_labels.c | 9 +++++----
net/netfilter/nft_ct.c | 2 ++
net/netfilter/xt_connlabel.c | 2 +-
net/openvswitch/conntrack.c | 2 +-
5 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/include/net/netfilter/nf_conntrack_labels.h b/include/net/netfilter/nf_conntrack_labels.h
index 5167818..c5f8fc73 100644
--- a/include/net/netfilter/nf_conntrack_labels.h
+++ b/include/net/netfilter/nf_conntrack_labels.h
@@ -53,11 +53,11 @@ int nf_connlabels_replace(struct nf_conn *ct,
#ifdef CONFIG_NF_CONNTRACK_LABELS
int nf_conntrack_labels_init(void);
void nf_conntrack_labels_fini(void);
-int nf_connlabels_get(struct net *net, unsigned int n_bits);
+int nf_connlabels_get(struct net *net, unsigned int bit);
void nf_connlabels_put(struct net *net);
#else
static inline int nf_conntrack_labels_init(void) { return 0; }
static inline void nf_conntrack_labels_fini(void) {}
-static inline int nf_connlabels_get(struct net *net, unsigned int n_bits) { return 0; }
+static inline int nf_connlabels_get(struct net *net, unsigned int bit) { return 0; }
static inline void nf_connlabels_put(struct net *net) {}
#endif
diff --git a/net/netfilter/nf_conntrack_labels.c b/net/netfilter/nf_conntrack_labels.c
index bd7f26b..252e6a7 100644
--- a/net/netfilter/nf_conntrack_labels.c
+++ b/net/netfilter/nf_conntrack_labels.c
@@ -78,15 +78,14 @@ int nf_connlabels_replace(struct nf_conn *ct,
}
EXPORT_SYMBOL_GPL(nf_connlabels_replace);
-int nf_connlabels_get(struct net *net, unsigned int n_bits)
+int nf_connlabels_get(struct net *net, unsigned int bits)
{
size_t words;
- if (n_bits > (NF_CT_LABELS_MAX_SIZE * BITS_PER_BYTE))
+ words = BIT_WORD(bits) + 1;
+ if (words > NF_CT_LABELS_MAX_SIZE / sizeof(long))
return -ERANGE;
- words = BITS_TO_LONGS(n_bits);
-
spin_lock(&nf_connlabels_lock);
net->ct.labels_used++;
if (words > net->ct.label_words)
@@ -115,6 +114,8 @@ static struct nf_ct_ext_type labels_extend __read_mostly = {
int nf_conntrack_labels_init(void)
{
+ BUILD_BUG_ON(NF_CT_LABELS_MAX_SIZE / sizeof(long) >= U8_MAX);
+
spin_lock_init(&nf_connlabels_lock);
return nf_ct_extend_register(&labels_extend);
}
diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c
index d4a4619..25998fa 100644
--- a/net/netfilter/nft_ct.c
+++ b/net/netfilter/nft_ct.c
@@ -484,6 +484,8 @@ static struct nft_expr_type nft_ct_type __read_mostly = {
static int __init nft_ct_module_init(void)
{
+ BUILD_BUG_ON(NF_CT_LABELS_MAX_SIZE > NFT_REG_SIZE);
+
return nft_register_expr(&nft_ct_type);
}
diff --git a/net/netfilter/xt_connlabel.c b/net/netfilter/xt_connlabel.c
index d9b3e53..a79af25 100644
--- a/net/netfilter/xt_connlabel.c
+++ b/net/netfilter/xt_connlabel.c
@@ -65,7 +65,7 @@ static int connlabel_mt_check(const struct xt_mtchk_param *par)
return ret;
}
- ret = nf_connlabels_get(par->net, info->bit + 1);
+ ret = nf_connlabels_get(par->net, info->bit);
if (ret < 0)
nf_ct_l3proto_module_put(par->family);
return ret;
diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
index 1b9d286..e5fe24a 100644
--- a/net/openvswitch/conntrack.c
+++ b/net/openvswitch/conntrack.c
@@ -1344,7 +1344,7 @@ void ovs_ct_init(struct net *net)
unsigned int n_bits = sizeof(struct ovs_key_ct_labels) * BITS_PER_BYTE;
struct ovs_net *ovs_net = net_generic(net, ovs_net_id);
- if (nf_connlabels_get(net, n_bits)) {
+ if (nf_connlabels_get(net, n_bits - 1)) {
ovs_net->xt_label = false;
OVS_NLERR(true, "Failed to set connlabel length");
} else {
--
2.1.4
next prev parent reply other threads:[~2016-04-22 13:39 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-22 13:39 [PATCH 00/23] Netfilter updates for net-next Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 01/23] netfilter: x_tables: don't move to non-existent next rule Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 02/23] netfilter: x_tables: validate targets of jumps Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 03/23] netfilter: x_tables: add and use xt_check_entry_offsets Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 04/23] netfilter: x_tables: kill check_entry helper Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 05/23] netfilter: x_tables: assert minimum target size Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 06/23] netfilter: x_tables: add compat version of xt_check_entry_offsets Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 07/23] netfilter: x_tables: check standard target size too Pablo Neira Ayuso
2016-06-05 21:11 ` Andreas Schwab
2016-06-05 22:02 ` Florian Westphal
2016-06-06 11:20 ` Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 08/23] netfilter: x_tables: check for bogus target offset Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 09/23] netfilter: x_tables: validate all offsets and sizes in a rule Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 10/23] netfilter: ip_tables: simplify translate_compat_table args Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 11/23] netfilter: ip6_tables: " Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 12/23] netfilter: arp_tables: " Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 13/23] netfilter: x_tables: xt_compat_match_from_user doesn't need a retval Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 14/23] netfilter: x_tables: do compat validation via translate_table Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 15/23] netfilter: x_tables: remove obsolete overflow check for compat case too Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 16/23] netfilter: x_tables: remove obsolete check Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 17/23] netfilter: x_tables: introduce and use xt_copy_counters_from_user Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 18/23] netfilter: ctnetlink: remove unnecessary inlining Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 19/23] netfilter: connlabels: move helpers to xt_connlabel Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 20/23] netfilter: labels: don't emit ct event if labels were not changed Pablo Neira Ayuso
2016-04-22 13:39 ` Pablo Neira Ayuso [this message]
2016-04-22 13:39 ` [PATCH 22/23] netfilter: ctnetlink: restore inlining for netlink message size calculation Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 23/23] netfilter: conntrack: don't acquire lock during seq_printf Pablo Neira Ayuso
2016-04-24 4:26 ` [PATCH 00/23] Netfilter updates for net-next David Miller
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=1461332394-3994-22-git-send-email-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--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).