]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/net/netfilter/nf_conntrack_zones.h
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>
7 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
8 #include <net/netfilter/nf_conntrack_extend.h>
10 static inline const struct nf_conntrack_zone
*
11 nf_ct_zone(const struct nf_conn
*ct
)
13 #ifdef CONFIG_NF_CONNTRACK_ZONES
16 return &nf_ct_zone_dflt
;
20 static inline const struct nf_conntrack_zone
*
21 nf_ct_zone_init(struct nf_conntrack_zone
*zone
, u16 id
, u8 dir
, u8 flags
)
30 static inline const struct nf_conntrack_zone
*
31 nf_ct_zone_tmpl(const struct nf_conn
*tmpl
, const struct sk_buff
*skb
,
32 struct nf_conntrack_zone
*tmp
)
34 #ifdef CONFIG_NF_CONNTRACK_ZONES
36 return &nf_ct_zone_dflt
;
38 if (tmpl
->zone
.flags
& NF_CT_FLAG_MARK
)
39 return nf_ct_zone_init(tmp
, skb
->mark
, tmpl
->zone
.dir
, 0);
41 return nf_ct_zone(tmpl
);
44 static inline void nf_ct_zone_add(struct nf_conn
*ct
,
45 const struct nf_conntrack_zone
*zone
)
47 #ifdef CONFIG_NF_CONNTRACK_ZONES
52 static inline bool nf_ct_zone_matches_dir(const struct nf_conntrack_zone
*zone
,
53 enum ip_conntrack_dir dir
)
55 return zone
->dir
& (1 << dir
);
58 static inline u16
nf_ct_zone_id(const struct nf_conntrack_zone
*zone
,
59 enum ip_conntrack_dir dir
)
61 #ifdef CONFIG_NF_CONNTRACK_ZONES
62 return nf_ct_zone_matches_dir(zone
, dir
) ?
63 zone
->id
: NF_CT_DEFAULT_ZONE_ID
;
65 return NF_CT_DEFAULT_ZONE_ID
;
69 static inline bool nf_ct_zone_equal(const struct nf_conn
*a
,
70 const struct nf_conntrack_zone
*b
,
71 enum ip_conntrack_dir dir
)
73 #ifdef CONFIG_NF_CONNTRACK_ZONES
74 return nf_ct_zone_id(nf_ct_zone(a
), dir
) ==
75 nf_ct_zone_id(b
, dir
);
81 static inline bool nf_ct_zone_equal_any(const struct nf_conn
*a
,
82 const struct nf_conntrack_zone
*b
)
84 #ifdef CONFIG_NF_CONNTRACK_ZONES
85 return nf_ct_zone(a
)->id
== b
->id
;
90 #endif /* IS_ENABLED(CONFIG_NF_CONNTRACK) */
91 #endif /* _NF_CONNTRACK_ZONES_H */