Merge tag 'linux-kselftest-5.4-rc1.1' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-block.git] / include / net / netfilter / nf_conntrack_zones.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
5d0aa2cc
PM
2#ifndef _NF_CONNTRACK_ZONES_H
3#define _NF_CONNTRACK_ZONES_H
4
62da9865 5#include <linux/netfilter/nf_conntrack_zones_common.h>
40d102cd 6#include <net/netfilter/nf_conntrack.h>
308ac914
DB
7
8static inline const struct nf_conntrack_zone *
9nf_ct_zone(const struct nf_conn *ct)
5d0aa2cc
PM
10{
11#ifdef CONFIG_NF_CONNTRACK_ZONES
6c8dee98
FW
12 return &ct->zone;
13#else
14 return &nf_ct_zone_dflt;
5d0aa2cc 15#endif
5d0aa2cc
PM
16}
17
308ac914 18static inline const struct nf_conntrack_zone *
5e8018fc
DB
19nf_ct_zone_init(struct nf_conntrack_zone *zone, u16 id, u8 dir, u8 flags)
20{
21 zone->id = id;
22 zone->flags = flags;
23 zone->dir = dir;
24
25 return zone;
26}
27
28static inline const struct nf_conntrack_zone *
29nf_ct_zone_tmpl(const struct nf_conn *tmpl, const struct sk_buff *skb,
30 struct nf_conntrack_zone *tmp)
31{
6c8dee98 32#ifdef CONFIG_NF_CONNTRACK_ZONES
5e8018fc
DB
33 if (!tmpl)
34 return &nf_ct_zone_dflt;
35
6c8dee98
FW
36 if (tmpl->zone.flags & NF_CT_FLAG_MARK)
37 return nf_ct_zone_init(tmp, skb->mark, tmpl->zone.dir, 0);
38#endif
39 return nf_ct_zone(tmpl);
5e8018fc
DB
40}
41
6c8dee98
FW
42static inline void nf_ct_zone_add(struct nf_conn *ct,
43 const struct nf_conntrack_zone *zone)
308ac914 44{
5e8018fc 45#ifdef CONFIG_NF_CONNTRACK_ZONES
6c8dee98 46 ct->zone = *zone;
5e8018fc 47#endif
308ac914
DB
48}
49
deedb590
DB
50static inline bool nf_ct_zone_matches_dir(const struct nf_conntrack_zone *zone,
51 enum ip_conntrack_dir dir)
52{
53 return zone->dir & (1 << dir);
54}
55
56static inline u16 nf_ct_zone_id(const struct nf_conntrack_zone *zone,
57 enum ip_conntrack_dir dir)
58{
506e65df 59#ifdef CONFIG_NF_CONNTRACK_ZONES
deedb590
DB
60 return nf_ct_zone_matches_dir(zone, dir) ?
61 zone->id : NF_CT_DEFAULT_ZONE_ID;
506e65df
FW
62#else
63 return NF_CT_DEFAULT_ZONE_ID;
64#endif
deedb590
DB
65}
66
308ac914 67static inline bool nf_ct_zone_equal(const struct nf_conn *a,
deedb590
DB
68 const struct nf_conntrack_zone *b,
69 enum ip_conntrack_dir dir)
70{
506e65df 71#ifdef CONFIG_NF_CONNTRACK_ZONES
deedb590
DB
72 return nf_ct_zone_id(nf_ct_zone(a), dir) ==
73 nf_ct_zone_id(b, dir);
506e65df
FW
74#else
75 return true;
76#endif
deedb590
DB
77}
78
79static inline bool nf_ct_zone_equal_any(const struct nf_conn *a,
80 const struct nf_conntrack_zone *b)
308ac914 81{
506e65df 82#ifdef CONFIG_NF_CONNTRACK_ZONES
308ac914 83 return nf_ct_zone(a)->id == b->id;
506e65df
FW
84#else
85 return true;
86#endif
308ac914 87}
1f1475f3 88
5d0aa2cc 89#endif /* _NF_CONNTRACK_ZONES_H */