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 #define NF_CT_FLAG_MARK 1
15 struct nf_conntrack_zone
{
21 extern const struct nf_conntrack_zone nf_ct_zone_dflt
;
23 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
24 #include <net/netfilter/nf_conntrack_extend.h>
26 static inline const struct nf_conntrack_zone
*
27 nf_ct_zone(const struct nf_conn
*ct
)
29 const struct nf_conntrack_zone
*nf_ct_zone
= NULL
;
31 #ifdef CONFIG_NF_CONNTRACK_ZONES
32 nf_ct_zone
= nf_ct_ext_find(ct
, NF_CT_EXT_ZONE
);
34 return nf_ct_zone
? nf_ct_zone
: &nf_ct_zone_dflt
;
37 static inline const struct nf_conntrack_zone
*
38 nf_ct_zone_init(struct nf_conntrack_zone
*zone
, u16 id
, u8 dir
, u8 flags
)
47 static inline const struct nf_conntrack_zone
*
48 nf_ct_zone_tmpl(const struct nf_conn
*tmpl
, const struct sk_buff
*skb
,
49 struct nf_conntrack_zone
*tmp
)
51 const struct nf_conntrack_zone
*zone
;
54 return &nf_ct_zone_dflt
;
56 zone
= nf_ct_zone(tmpl
);
57 if (zone
->flags
& NF_CT_FLAG_MARK
)
58 zone
= nf_ct_zone_init(tmp
, skb
->mark
, zone
->dir
, 0);
63 static inline int nf_ct_zone_add(struct nf_conn
*ct
, gfp_t flags
,
64 const struct nf_conntrack_zone
*info
)
66 #ifdef CONFIG_NF_CONNTRACK_ZONES
67 struct nf_conntrack_zone
*nf_ct_zone
;
69 nf_ct_zone
= nf_ct_ext_add(ct
, NF_CT_EXT_ZONE
, flags
);
73 nf_ct_zone_init(nf_ct_zone
, info
->id
, info
->dir
,
79 static inline bool nf_ct_zone_matches_dir(const struct nf_conntrack_zone
*zone
,
80 enum ip_conntrack_dir dir
)
82 return zone
->dir
& (1 << dir
);
85 static inline u16
nf_ct_zone_id(const struct nf_conntrack_zone
*zone
,
86 enum ip_conntrack_dir dir
)
88 return nf_ct_zone_matches_dir(zone
, dir
) ?
89 zone
->id
: NF_CT_DEFAULT_ZONE_ID
;
92 static inline bool nf_ct_zone_equal(const struct nf_conn
*a
,
93 const struct nf_conntrack_zone
*b
,
94 enum ip_conntrack_dir dir
)
96 return nf_ct_zone_id(nf_ct_zone(a
), dir
) ==
97 nf_ct_zone_id(b
, dir
);
100 static inline bool nf_ct_zone_equal_any(const struct nf_conn
*a
,
101 const struct nf_conntrack_zone
*b
)
103 return nf_ct_zone(a
)->id
== b
->id
;
105 #endif /* IS_ENABLED(CONFIG_NF_CONNTRACK) */
106 #endif /* _NF_CONNTRACK_ZONES_H */