]> git.karo-electronics.de Git - linux-beck.git/commitdiff
netfilter: connlabels: move helpers to xt_connlabel
authorFlorian Westphal <fw@strlen.de>
Tue, 12 Apr 2016 16:14:23 +0000 (18:14 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 18 Apr 2016 18:39:41 +0000 (20:39 +0200)
Currently labels can only be set either by iptables connlabel
match or via ctnetlink.

Before adding nftables set support, clean up the clabel core and move
helpers that nft will not need after all to the xtables module.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/net/netfilter/nf_conntrack_labels.h
net/netfilter/nf_conntrack_labels.c
net/netfilter/xt_connlabel.c

index 7e2b1d025f5037fc764a8376693680546c3835f6..51678180e56c7e316ef1adecf3bc921a4eb0927c 100644 (file)
@@ -45,7 +45,6 @@ static inline struct nf_conn_labels *nf_ct_labels_ext_add(struct nf_conn *ct)
 #endif
 }
 
-bool nf_connlabel_match(const struct nf_conn *ct, u16 bit);
 int nf_connlabel_set(struct nf_conn *ct, u16 bit);
 
 int nf_connlabels_replace(struct nf_conn *ct,
index 3ce5c314ea4bc63ebe5cfc294f6f335726ed85c0..3a30900891c1a9539243696299d6881e0b1e288d 100644 (file)
 
 static spinlock_t nf_connlabels_lock;
 
-static unsigned int label_bits(const struct nf_conn_labels *l)
-{
-       unsigned int longs = l->words;
-       return longs * BITS_PER_LONG;
-}
-
-bool nf_connlabel_match(const struct nf_conn *ct, u16 bit)
-{
-       struct nf_conn_labels *labels = nf_ct_labels_find(ct);
-
-       if (!labels)
-               return false;
-
-       return bit < label_bits(labels) && test_bit(bit, labels->bits);
-}
-EXPORT_SYMBOL_GPL(nf_connlabel_match);
-
 int nf_connlabel_set(struct nf_conn *ct, u16 bit)
 {
        struct nf_conn_labels *labels = nf_ct_labels_find(ct);
 
-       if (!labels || bit >= label_bits(labels))
+       if (!labels || BIT_WORD(bit) >= labels->words)
                return -ENOSPC;
 
        if (test_bit(bit, labels->bits))
index bb9cbeb188686f5f858ba8e35493457063d3f6ea..d9b3e535d13a4956d5da1eac968f9f9e07e4c594 100644 (file)
@@ -18,6 +18,16 @@ MODULE_DESCRIPTION("Xtables: add/match connection trackling labels");
 MODULE_ALIAS("ipt_connlabel");
 MODULE_ALIAS("ip6t_connlabel");
 
+static bool connlabel_match(const struct nf_conn *ct, u16 bit)
+{
+       struct nf_conn_labels *labels = nf_ct_labels_find(ct);
+
+       if (!labels)
+               return false;
+
+       return BIT_WORD(bit) < labels->words && test_bit(bit, labels->bits);
+}
+
 static bool
 connlabel_mt(const struct sk_buff *skb, struct xt_action_param *par)
 {
@@ -33,7 +43,7 @@ connlabel_mt(const struct sk_buff *skb, struct xt_action_param *par)
        if (info->options & XT_CONNLABEL_OP_SET)
                return (nf_connlabel_set(ct, info->bit) == 0) ^ invert;
 
-       return nf_connlabel_match(ct, info->bit) ^ invert;
+       return connlabel_match(ct, info->bit) ^ invert;
 }
 
 static int connlabel_mt_check(const struct xt_mtchk_param *par)