]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
c539f017 FW |
2 | #include <linux/types.h> |
3 | #include <net/net_namespace.h> | |
4 | #include <linux/netfilter/nf_conntrack_common.h> | |
5 | #include <linux/netfilter/nf_conntrack_tuple_common.h> | |
6 | #include <net/netfilter/nf_conntrack.h> | |
7 | #include <net/netfilter/nf_conntrack_extend.h> | |
8 | ||
9 | #include <uapi/linux/netfilter/xt_connlabel.h> | |
10 | ||
d2bf2f34 FW |
11 | #define NF_CT_LABELS_MAX_SIZE ((XT_CONNLABEL_MAXBIT + 1) / BITS_PER_BYTE) |
12 | ||
c539f017 | 13 | struct nf_conn_labels { |
23014011 | 14 | unsigned long bits[NF_CT_LABELS_MAX_SIZE / sizeof(long)]; |
c539f017 FW |
15 | }; |
16 | ||
17 | static inline struct nf_conn_labels *nf_ct_labels_find(const struct nf_conn *ct) | |
18 | { | |
19 | #ifdef CONFIG_NF_CONNTRACK_LABELS | |
20 | return nf_ct_ext_find(ct, NF_CT_EXT_LABELS); | |
21 | #else | |
22 | return NULL; | |
23 | #endif | |
24 | } | |
25 | ||
26 | static inline struct nf_conn_labels *nf_ct_labels_ext_add(struct nf_conn *ct) | |
27 | { | |
28 | #ifdef CONFIG_NF_CONNTRACK_LABELS | |
c539f017 | 29 | struct net *net = nf_ct_net(ct); |
c539f017 | 30 | |
23014011 | 31 | if (net->ct.labels_used == 0) |
c539f017 FW |
32 | return NULL; |
33 | ||
cdb436d1 | 34 | return nf_ct_ext_add(ct, NF_CT_EXT_LABELS, GFP_ATOMIC); |
c539f017 FW |
35 | #else |
36 | return NULL; | |
37 | #endif | |
38 | } | |
39 | ||
9b21f6a9 FW |
40 | int nf_connlabels_replace(struct nf_conn *ct, |
41 | const u32 *data, const u32 *mask, unsigned int words); | |
42 | ||
c539f017 | 43 | #ifdef CONFIG_NF_CONNTRACK_LABELS |
5f69b8f5 G |
44 | int nf_conntrack_labels_init(void); |
45 | void nf_conntrack_labels_fini(void); | |
adff6c65 | 46 | int nf_connlabels_get(struct net *net, unsigned int bit); |
86ca02e7 | 47 | void nf_connlabels_put(struct net *net); |
c539f017 | 48 | #else |
5f69b8f5 G |
49 | static inline int nf_conntrack_labels_init(void) { return 0; } |
50 | static inline void nf_conntrack_labels_fini(void) {} | |
adff6c65 | 51 | static inline int nf_connlabels_get(struct net *net, unsigned int bit) { return 0; } |
86ca02e7 | 52 | static inline void nf_connlabels_put(struct net *net) {} |
c539f017 | 53 | #endif |