a594a0feecc169cbd7669fe07a69ed4acd5edd41
[cascardo/ovs.git] / datapath / linux / compat / include / net / netfilter / nf_conntrack_labels.h
1 #ifndef _NF_CONNTRACK_LABELS_WRAPPER_H
2 #define _NF_CONNTRACK_LABELS_WRAPPER_H
3
4 #include <linux/kconfig.h>
5 #include <linux/version.h>
6 #include_next <net/netfilter/nf_conntrack_labels.h>
7
8 #ifndef HAVE_NF_CONNLABELS_GET
9 #if IS_ENABLED(CONFIG_NF_CONNTRACK_LABELS)
10
11 #ifndef NF_CT_LABELS_MAX_SIZE
12 #define NF_CT_LABELS_MAX_SIZE ((XT_CONNLABEL_MAXBIT + 1) / BITS_PER_BYTE)
13 #endif
14
15 /* XXX: This doesn't lock others out from doing the same configuration
16  *      simultaneously. */
17 static inline int nf_connlabels_get(struct net *net, unsigned int n_bits)
18 {
19         size_t words;
20
21         if (n_bits > (NF_CT_LABELS_MAX_SIZE * BITS_PER_BYTE))
22                 return -ERANGE;
23
24         words = BITS_TO_LONGS(n_bits);
25
26         net->ct.labels_used++;
27         if (words > net->ct.label_words)
28                 net->ct.label_words = words;
29
30         return 0;
31 }
32
33 static inline void nf_connlabels_put(struct net *net)
34 {
35         net->ct.labels_used--;
36         if (net->ct.labels_used == 0)
37                 net->ct.label_words = 0;
38 }
39
40 #else /* CONFIG_NF_CONNTRACK_LABELS */
41 static inline int nf_connlabels_get(struct net *net, unsigned int n_bits)
42 {
43         return -ERANGE;
44 }
45
46 static inline void nf_connlabels_put(struct net *net) { }
47 #endif /* CONFIG_NF_CONNTRACK_LABELS */
48 #endif /* HAVE_NF_CONNLABELS_GET */
49 #endif /* _NF_CONNTRACK_LABELS_WRAPPER_H */