2 * test/set flag bits stored in conntrack extension area.
4 * (C) 2013 Astaro GmbH & Co KG
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/ctype.h>
12 #include <linux/export.h>
13 #include <linux/jhash.h>
14 #include <linux/spinlock.h>
15 #include <linux/types.h>
16 #include <linux/slab.h>
18 #include <net/netfilter/nf_conntrack_ecache.h>
19 #include <net/netfilter/nf_conntrack_labels.h>
21 static unsigned int label_bits(const struct nf_conn_labels
*l
)
23 unsigned int longs
= l
->words
;
24 return longs
* BITS_PER_LONG
;
27 bool nf_connlabel_match(const struct nf_conn
*ct
, u16 bit
)
29 struct nf_conn_labels
*labels
= nf_ct_labels_find(ct
);
34 return bit
< label_bits(labels
) && test_bit(bit
, labels
->bits
);
36 EXPORT_SYMBOL_GPL(nf_connlabel_match
);
38 int nf_connlabel_set(struct nf_conn
*ct
, u16 bit
)
40 struct nf_conn_labels
*labels
= nf_ct_labels_find(ct
);
42 if (!labels
|| bit
>= label_bits(labels
))
45 if (test_bit(bit
, labels
->bits
))
48 if (test_and_set_bit(bit
, labels
->bits
))
53 EXPORT_SYMBOL_GPL(nf_connlabel_set
);
55 static struct nf_ct_ext_type labels_extend __read_mostly
= {
56 .len
= sizeof(struct nf_conn_labels
),
57 .align
= __alignof__(struct nf_conn_labels
),
58 .id
= NF_CT_EXT_LABELS
,
61 int nf_conntrack_labels_init(struct net
*net
)
63 if (net_eq(net
, &init_net
))
64 return nf_ct_extend_register(&labels_extend
);
68 void nf_conntrack_labels_fini(struct net
*net
)
70 if (net_eq(net
, &init_net
))
71 nf_ct_extend_unregister(&labels_extend
);