1 #ifndef _NF_CONNTRACK_ZONES_H
2 #define _NF_CONNTRACK_ZONES_H
4 #include <linux/netfilter/nf_conntrack_zones_common.h>
6 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
7 #include <net/netfilter/nf_conntrack_extend.h>
9 static inline const struct nf_conntrack_zone *
10 nf_ct_zone(const struct nf_conn *ct)
12 #ifdef CONFIG_NF_CONNTRACK_ZONES
15 return &nf_ct_zone_dflt;
19 static inline const struct nf_conntrack_zone *
20 nf_ct_zone_init(struct nf_conntrack_zone *zone, u16 id, u8 dir, u8 flags)
29 static inline const struct nf_conntrack_zone *
30 nf_ct_zone_tmpl(const struct nf_conn *tmpl, const struct sk_buff *skb,
31 struct nf_conntrack_zone *tmp)
33 #ifdef CONFIG_NF_CONNTRACK_ZONES
35 return &nf_ct_zone_dflt;
37 if (tmpl->zone.flags & NF_CT_FLAG_MARK)
38 return nf_ct_zone_init(tmp, skb->mark, tmpl->zone.dir, 0);
40 return nf_ct_zone(tmpl);
43 static inline void nf_ct_zone_add(struct nf_conn *ct,
44 const struct nf_conntrack_zone *zone)
46 #ifdef CONFIG_NF_CONNTRACK_ZONES
51 static inline bool nf_ct_zone_matches_dir(const struct nf_conntrack_zone *zone,
52 enum ip_conntrack_dir dir)
54 return zone->dir & (1 << dir);
57 static inline u16 nf_ct_zone_id(const struct nf_conntrack_zone *zone,
58 enum ip_conntrack_dir dir)
60 #ifdef CONFIG_NF_CONNTRACK_ZONES
61 return nf_ct_zone_matches_dir(zone, dir) ?
62 zone->id : NF_CT_DEFAULT_ZONE_ID;
64 return NF_CT_DEFAULT_ZONE_ID;
68 static inline bool nf_ct_zone_equal(const struct nf_conn *a,
69 const struct nf_conntrack_zone *b,
70 enum ip_conntrack_dir dir)
72 #ifdef CONFIG_NF_CONNTRACK_ZONES
73 return nf_ct_zone_id(nf_ct_zone(a), dir) ==
74 nf_ct_zone_id(b, dir);
80 static inline bool nf_ct_zone_equal_any(const struct nf_conn *a,
81 const struct nf_conntrack_zone *b)
83 #ifdef CONFIG_NF_CONNTRACK_ZONES
84 return nf_ct_zone(a)->id == b->id;
89 #endif /* IS_ENABLED(CONFIG_NF_CONNTRACK) */
90 #endif /* _NF_CONNTRACK_ZONES_H */