]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - include/net/netfilter/nf_conntrack_zones.h
Merge branch 'stable-4.8' of git://git.infradead.org/users/pcmoore/audit
[mirror_ubuntu-focal-kernel.git] / include / net / netfilter / nf_conntrack_zones.h
1 #ifndef _NF_CONNTRACK_ZONES_H
2 #define _NF_CONNTRACK_ZONES_H
3
4 #include <linux/netfilter/nf_conntrack_zones_common.h>
5
6 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
7 #include <net/netfilter/nf_conntrack_extend.h>
8
9 static inline const struct nf_conntrack_zone *
10 nf_ct_zone(const struct nf_conn *ct)
11 {
12 #ifdef CONFIG_NF_CONNTRACK_ZONES
13 return &ct->zone;
14 #else
15 return &nf_ct_zone_dflt;
16 #endif
17 }
18
19 static inline const struct nf_conntrack_zone *
20 nf_ct_zone_init(struct nf_conntrack_zone *zone, u16 id, u8 dir, u8 flags)
21 {
22 zone->id = id;
23 zone->flags = flags;
24 zone->dir = dir;
25
26 return zone;
27 }
28
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)
32 {
33 #ifdef CONFIG_NF_CONNTRACK_ZONES
34 if (!tmpl)
35 return &nf_ct_zone_dflt;
36
37 if (tmpl->zone.flags & NF_CT_FLAG_MARK)
38 return nf_ct_zone_init(tmp, skb->mark, tmpl->zone.dir, 0);
39 #endif
40 return nf_ct_zone(tmpl);
41 }
42
43 static inline void nf_ct_zone_add(struct nf_conn *ct,
44 const struct nf_conntrack_zone *zone)
45 {
46 #ifdef CONFIG_NF_CONNTRACK_ZONES
47 ct->zone = *zone;
48 #endif
49 }
50
51 static inline bool nf_ct_zone_matches_dir(const struct nf_conntrack_zone *zone,
52 enum ip_conntrack_dir dir)
53 {
54 return zone->dir & (1 << dir);
55 }
56
57 static inline u16 nf_ct_zone_id(const struct nf_conntrack_zone *zone,
58 enum ip_conntrack_dir dir)
59 {
60 #ifdef CONFIG_NF_CONNTRACK_ZONES
61 return nf_ct_zone_matches_dir(zone, dir) ?
62 zone->id : NF_CT_DEFAULT_ZONE_ID;
63 #else
64 return NF_CT_DEFAULT_ZONE_ID;
65 #endif
66 }
67
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)
71 {
72 #ifdef CONFIG_NF_CONNTRACK_ZONES
73 return nf_ct_zone_id(nf_ct_zone(a), dir) ==
74 nf_ct_zone_id(b, dir);
75 #else
76 return true;
77 #endif
78 }
79
80 static inline bool nf_ct_zone_equal_any(const struct nf_conn *a,
81 const struct nf_conntrack_zone *b)
82 {
83 #ifdef CONFIG_NF_CONNTRACK_ZONES
84 return nf_ct_zone(a)->id == b->id;
85 #else
86 return true;
87 #endif
88 }
89 #endif /* IS_ENABLED(CONFIG_NF_CONNTRACK) */
90 #endif /* _NF_CONNTRACK_ZONES_H */