1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _NF_CONNTRACK_ZONES_H
3 #define _NF_CONNTRACK_ZONES_H
5 #include <linux/netfilter/nf_conntrack_zones_common.h>
6 #include <net/netfilter/nf_conntrack.h>
8 static inline const struct nf_conntrack_zone *
9 nf_ct_zone(const struct nf_conn *ct)
11 #ifdef CONFIG_NF_CONNTRACK_ZONES
14 return &nf_ct_zone_dflt;
18 static inline const struct nf_conntrack_zone *
19 nf_ct_zone_init(struct nf_conntrack_zone *zone, u16 id, u8 dir, u8 flags)
28 static inline const struct nf_conntrack_zone *
29 nf_ct_zone_tmpl(const struct nf_conn *tmpl, const struct sk_buff *skb,
30 struct nf_conntrack_zone *tmp)
32 #ifdef CONFIG_NF_CONNTRACK_ZONES
34 return &nf_ct_zone_dflt;
36 if (tmpl->zone.flags & NF_CT_FLAG_MARK)
37 return nf_ct_zone_init(tmp, skb->mark, tmpl->zone.dir, 0);
39 return nf_ct_zone(tmpl);
42 static inline void nf_ct_zone_add(struct nf_conn *ct,
43 const struct nf_conntrack_zone *zone)
45 #ifdef CONFIG_NF_CONNTRACK_ZONES
50 static inline bool nf_ct_zone_matches_dir(const struct nf_conntrack_zone *zone,
51 enum ip_conntrack_dir dir)
53 return zone->dir & (1 << dir);
56 static inline u16 nf_ct_zone_id(const struct nf_conntrack_zone *zone,
57 enum ip_conntrack_dir dir)
59 #ifdef CONFIG_NF_CONNTRACK_ZONES
60 return nf_ct_zone_matches_dir(zone, dir) ?
61 zone->id : NF_CT_DEFAULT_ZONE_ID;
63 return NF_CT_DEFAULT_ZONE_ID;
67 static inline bool nf_ct_zone_equal(const struct nf_conn *a,
68 const struct nf_conntrack_zone *b,
69 enum ip_conntrack_dir dir)
71 #ifdef CONFIG_NF_CONNTRACK_ZONES
72 return nf_ct_zone_id(nf_ct_zone(a), dir) ==
73 nf_ct_zone_id(b, dir);
79 static inline bool nf_ct_zone_equal_any(const struct nf_conn *a,
80 const struct nf_conntrack_zone *b)
82 #ifdef CONFIG_NF_CONNTRACK_ZONES
83 return nf_ct_zone(a)->id == b->id;
89 #endif /* _NF_CONNTRACK_ZONES_H */