ovs-vsctl: Add another Flow_Table example.
[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_TAKES_BIT
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 rpl_nf_connlabels_get(struct net *net, unsigned int bits)
18 {
19 #ifndef HAVE_NF_CONNLABELS_GET
20         size_t words;
21
22         words = BIT_WORD(bits) + 1;
23         if (words > NF_CT_LABELS_MAX_SIZE / sizeof(long))
24                 return -ERANGE;
25
26         net->ct.labels_used++;
27         if (words > net->ct.label_words)
28                 net->ct.label_words = words;
29
30         return 0;
31 #else
32         return nf_connlabels_get(net, bits + 1);
33 #endif /* HAVE_NF_CONNLABELS_GET */
34 }
35 #define nf_connlabels_get rpl_nf_connlabels_get
36
37 static inline void rpl_nf_connlabels_put(struct net *net)
38 {
39 #ifndef HAVE_NF_CONNLABELS_GET
40         net->ct.labels_used--;
41         if (net->ct.labels_used == 0)
42                 net->ct.label_words = 0;
43 #else
44         nf_connlabels_put(net);
45 #endif /* HAVE_NF_CONNLABELS_GET */
46 }
47 #define nf_connlabels_put rpl_nf_connlabels_put
48
49 #else /* CONFIG_NF_CONNTRACK_LABELS */
50 static inline int nf_connlabels_get(struct net *net, unsigned int bits)
51 {
52         return -ERANGE;
53 }
54
55 static inline void nf_connlabels_put(struct net *net) { }
56 #endif /* CONFIG_NF_CONNTRACK_LABELS */
57 #endif /* HAVE_NF_CONNLABELS_GET_TAKES_BIT */
58 #endif /* _NF_CONNTRACK_LABELS_WRAPPER_H */