1 #ifndef _NF_CONNTRACK_ZONES_H
2 #define _NF_CONNTRACK_ZONES_H
4 #include <linux/netfilter/nf_conntrack_tuple_common.h>
6 #define NF_CT_DEFAULT_ZONE_ID 0
8 #define NF_CT_ZONE_DIR_ORIG (1 << IP_CT_DIR_ORIGINAL)
9 #define NF_CT_ZONE_DIR_REPL (1 << IP_CT_DIR_REPLY)
11 #define NF_CT_DEFAULT_ZONE_DIR (NF_CT_ZONE_DIR_ORIG | NF_CT_ZONE_DIR_REPL)
13 struct nf_conntrack_zone
{
18 extern const struct nf_conntrack_zone nf_ct_zone_dflt
;
20 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
21 #include <net/netfilter/nf_conntrack_extend.h>
23 static inline const struct nf_conntrack_zone
*
24 nf_ct_zone(const struct nf_conn
*ct
)
26 const struct nf_conntrack_zone
*nf_ct_zone
= NULL
;
28 #ifdef CONFIG_NF_CONNTRACK_ZONES
29 nf_ct_zone
= nf_ct_ext_find(ct
, NF_CT_EXT_ZONE
);
31 return nf_ct_zone
? nf_ct_zone
: &nf_ct_zone_dflt
;
34 static inline const struct nf_conntrack_zone
*
35 nf_ct_zone_tmpl(const struct nf_conn
*tmpl
)
37 return tmpl
? nf_ct_zone(tmpl
) : &nf_ct_zone_dflt
;
40 static inline bool nf_ct_zone_matches_dir(const struct nf_conntrack_zone
*zone
,
41 enum ip_conntrack_dir dir
)
43 return zone
->dir
& (1 << dir
);
46 static inline u16
nf_ct_zone_id(const struct nf_conntrack_zone
*zone
,
47 enum ip_conntrack_dir dir
)
49 return nf_ct_zone_matches_dir(zone
, dir
) ?
50 zone
->id
: NF_CT_DEFAULT_ZONE_ID
;
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
)
57 return nf_ct_zone_id(nf_ct_zone(a
), dir
) ==
58 nf_ct_zone_id(b
, dir
);
61 static inline bool nf_ct_zone_equal_any(const struct nf_conn
*a
,
62 const struct nf_conntrack_zone
*b
)
64 return nf_ct_zone(a
)->id
== b
->id
;
66 #endif /* IS_ENABLED(CONFIG_NF_CONNTRACK) */
67 #endif /* _NF_CONNTRACK_ZONES_H */