compat: Backport nf_connlabels_{get, put}().
authorJoe Stringer <joestringer@nicira.com>
Thu, 3 Dec 2015 07:53:39 +0000 (23:53 -0800)
committerJoe Stringer <joe@ovn.org>
Fri, 4 Dec 2015 01:08:15 +0000 (17:08 -0800)
This is a partial backport of Linux commit 86ca02e77408
"netfilter: connlabels: Export setting connlabel length".

Signed-off-by: Joe Stringer <joestringer@nicira.com>
Acked-by: Pravin B Shelar <pshelar@nicira.com>
datapath/linux/Modules.mk
datapath/linux/compat/include/net/netfilter/nf_conntrack_labels.h [new file with mode: 0644]

index 29a90ea..02bab71 100644 (file)
@@ -93,6 +93,7 @@ openvswitch_headers += \
        linux/compat/include/net/vxlan.h \
        linux/compat/include/net/netfilter/nf_conntrack_core.h \
        linux/compat/include/net/netfilter/nf_conntrack_expect.h \
+       linux/compat/include/net/netfilter/nf_conntrack_labels.h \
        linux/compat/include/net/netfilter/nf_conntrack_zones.h \
        linux/compat/include/net/sctp/checksum.h
 EXTRA_DIST += linux/compat/build-aux/export-check-whitelist
diff --git a/datapath/linux/compat/include/net/netfilter/nf_conntrack_labels.h b/datapath/linux/compat/include/net/netfilter/nf_conntrack_labels.h
new file mode 100644 (file)
index 0000000..e49a289
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef _NF_CONNTRACK_LABELS_WRAPPER_H
+#define _NF_CONNTRACK_LABELS_WRAPPER_H
+
+#include <linux/kconfig.h>
+#include <linux/version.h>
+#include_next <net/netfilter/nf_conntrack_labels.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,3,0) && \
+    IS_ENABLED(CONFIG_NF_CONNTRACK_LABELS)
+
+#ifndef NF_CT_LABELS_MAX_SIZE
+#define NF_CT_LABELS_MAX_SIZE ((XT_CONNLABEL_MAXBIT + 1) / BITS_PER_BYTE)
+#endif
+
+/* XXX: This doesn't lock others out from doing the same configuration
+ *     simultaneously. */
+static inline int nf_connlabels_get(struct net *net, unsigned int n_bits)
+{
+       size_t words;
+
+       if (n_bits > (NF_CT_LABELS_MAX_SIZE * BITS_PER_BYTE))
+               return -ERANGE;
+
+       words = BITS_TO_LONGS(n_bits);
+
+       net->ct.labels_used++;
+       if (words > net->ct.label_words)
+               net->ct.label_words = words;
+
+       return 0;
+}
+
+static inline void nf_connlabels_put(struct net *net)
+{
+       net->ct.labels_used--;
+       if (net->ct.labels_used == 0)
+               net->ct.label_words = 0;
+}
+
+#endif
+#endif /* _NF_CONNTRACK_LABELS_WRAPPER_H */