1 #ifndef _NF_CONNTRACK_LABELS_WRAPPER_H
2 #define _NF_CONNTRACK_LABELS_WRAPPER_H
4 #include <linux/kconfig.h>
5 #include <linux/version.h>
6 #include_next <net/netfilter/nf_conntrack_labels.h>
8 #ifndef HAVE_NF_CONNLABELS_GET_TAKES_BIT
9 #if IS_ENABLED(CONFIG_NF_CONNTRACK_LABELS)
11 #ifndef NF_CT_LABELS_MAX_SIZE
12 #define NF_CT_LABELS_MAX_SIZE ((XT_CONNLABEL_MAXBIT + 1) / BITS_PER_BYTE)
15 /* XXX: This doesn't lock others out from doing the same configuration
17 static inline int rpl_nf_connlabels_get(struct net *net, unsigned int bits)
19 #ifndef HAVE_NF_CONNLABELS_GET
22 words = BIT_WORD(bits) + 1;
23 if (words > NF_CT_LABELS_MAX_SIZE / sizeof(long))
26 net->ct.labels_used++;
27 if (words > net->ct.label_words)
28 net->ct.label_words = words;
32 return nf_connlabels_get(net, bits + 1);
33 #endif /* HAVE_NF_CONNLABELS_GET */
35 #define nf_connlabels_get rpl_nf_connlabels_get
37 static inline void rpl_nf_connlabels_put(struct net *net)
39 #ifndef HAVE_NF_CONNLABELS_GET
40 net->ct.labels_used--;
41 if (net->ct.labels_used == 0)
42 net->ct.label_words = 0;
44 nf_connlabels_put(net);
45 #endif /* HAVE_NF_CONNLABELS_GET */
47 #define nf_connlabels_put rpl_nf_connlabels_put
49 #else /* CONFIG_NF_CONNTRACK_LABELS */
50 static inline int nf_connlabels_get(struct net *net, unsigned int bits)
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 */