3942ddf0d4ff3382beae83ed721ad7df1646e77a
[deliverable/linux.git] / include / net / netfilter / nf_conntrack_zones.h
1 #ifndef _NF_CONNTRACK_ZONES_H
2 #define _NF_CONNTRACK_ZONES_H
3
4 #include <linux/netfilter/nf_conntrack_tuple_common.h>
5
6 #define NF_CT_DEFAULT_ZONE_ID 0
7
8 #define NF_CT_ZONE_DIR_ORIG (1 << IP_CT_DIR_ORIGINAL)
9 #define NF_CT_ZONE_DIR_REPL (1 << IP_CT_DIR_REPLY)
10
11 #define NF_CT_DEFAULT_ZONE_DIR (NF_CT_ZONE_DIR_ORIG | NF_CT_ZONE_DIR_REPL)
12
13 struct nf_conntrack_zone {
14 u16 id;
15 u16 dir;
16 };
17
18 extern const struct nf_conntrack_zone nf_ct_zone_dflt;
19
20 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
21 #include <net/netfilter/nf_conntrack_extend.h>
22
23 static inline const struct nf_conntrack_zone *
24 nf_ct_zone(const struct nf_conn *ct)
25 {
26 const struct nf_conntrack_zone *nf_ct_zone = NULL;
27
28 #ifdef CONFIG_NF_CONNTRACK_ZONES
29 nf_ct_zone = nf_ct_ext_find(ct, NF_CT_EXT_ZONE);
30 #endif
31 return nf_ct_zone ? nf_ct_zone : &nf_ct_zone_dflt;
32 }
33
34 static inline const struct nf_conntrack_zone *
35 nf_ct_zone_tmpl(const struct nf_conn *tmpl)
36 {
37 return tmpl ? nf_ct_zone(tmpl) : &nf_ct_zone_dflt;
38 }
39
40 static inline bool nf_ct_zone_matches_dir(const struct nf_conntrack_zone *zone,
41 enum ip_conntrack_dir dir)
42 {
43 return zone->dir & (1 << dir);
44 }
45
46 static inline u16 nf_ct_zone_id(const struct nf_conntrack_zone *zone,
47 enum ip_conntrack_dir dir)
48 {
49 return nf_ct_zone_matches_dir(zone, dir) ?
50 zone->id : NF_CT_DEFAULT_ZONE_ID;
51 }
52
53 static inline bool nf_ct_zone_equal(const struct nf_conn *a,
54 const struct nf_conntrack_zone *b,
55 enum ip_conntrack_dir dir)
56 {
57 return nf_ct_zone_id(nf_ct_zone(a), dir) ==
58 nf_ct_zone_id(b, dir);
59 }
60
61 static inline bool nf_ct_zone_equal_any(const struct nf_conn *a,
62 const struct nf_conntrack_zone *b)
63 {
64 return nf_ct_zone(a)->id == b->id;
65 }
66 #endif /* IS_ENABLED(CONFIG_NF_CONNTRACK) */
67 #endif /* _NF_CONNTRACK_ZONES_H */
This page took 0.042883 seconds and 4 git commands to generate.