]>
Commit | Line | Data |
---|---|---|
5d0aa2cc PM |
1 | #ifndef _NF_CONNTRACK_ZONES_H |
2 | #define _NF_CONNTRACK_ZONES_H | |
3 | ||
deedb590 DB |
4 | #include <linux/netfilter/nf_conntrack_tuple_common.h> |
5 | ||
308ac914 | 6 | #define NF_CT_DEFAULT_ZONE_ID 0 |
37ee3d5b | 7 | |
deedb590 DB |
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 | ||
5d0aa2cc PM |
13 | struct nf_conntrack_zone { |
14 | u16 id; | |
deedb590 | 15 | u16 dir; |
5d0aa2cc PM |
16 | }; |
17 | ||
308ac914 DB |
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) | |
5d0aa2cc | 25 | { |
308ac914 DB |
26 | const struct nf_conntrack_zone *nf_ct_zone = NULL; |
27 | ||
5d0aa2cc | 28 | #ifdef CONFIG_NF_CONNTRACK_ZONES |
5d0aa2cc | 29 | nf_ct_zone = nf_ct_ext_find(ct, NF_CT_EXT_ZONE); |
5d0aa2cc | 30 | #endif |
308ac914 | 31 | return nf_ct_zone ? nf_ct_zone : &nf_ct_zone_dflt; |
5d0aa2cc PM |
32 | } |
33 | ||
308ac914 DB |
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 | ||
deedb590 DB |
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 | ||
308ac914 | 53 | static inline bool nf_ct_zone_equal(const struct nf_conn *a, |
deedb590 DB |
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) | |
308ac914 DB |
63 | { |
64 | return nf_ct_zone(a)->id == b->id; | |
65 | } | |
66 | #endif /* IS_ENABLED(CONFIG_NF_CONNTRACK) */ | |
5d0aa2cc | 67 | #endif /* _NF_CONNTRACK_ZONES_H */ |