]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - include/net/netfilter/nf_conntrack_zones.h
Merge branch 'core-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[mirror_ubuntu-zesty-kernel.git] / include / net / netfilter / nf_conntrack_zones.h
CommitLineData
5d0aa2cc
PM
1#ifndef _NF_CONNTRACK_ZONES_H
2#define _NF_CONNTRACK_ZONES_H
3
62da9865 4#include <linux/netfilter/nf_conntrack_zones_common.h>
308ac914
DB
5
6#if IS_ENABLED(CONFIG_NF_CONNTRACK)
7#include <net/netfilter/nf_conntrack_extend.h>
8
9static inline const struct nf_conntrack_zone *
10nf_ct_zone(const struct nf_conn *ct)
5d0aa2cc
PM
11{
12#ifdef CONFIG_NF_CONNTRACK_ZONES
6c8dee98
FW
13 return &ct->zone;
14#else
15 return &nf_ct_zone_dflt;
5d0aa2cc 16#endif
5d0aa2cc
PM
17}
18
308ac914 19static inline const struct nf_conntrack_zone *
5e8018fc
DB
20nf_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
29static inline const struct nf_conntrack_zone *
30nf_ct_zone_tmpl(const struct nf_conn *tmpl, const struct sk_buff *skb,
31 struct nf_conntrack_zone *tmp)
32{
6c8dee98 33#ifdef CONFIG_NF_CONNTRACK_ZONES
5e8018fc
DB
34 if (!tmpl)
35 return &nf_ct_zone_dflt;
36
6c8dee98
FW
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);
5e8018fc
DB
41}
42
6c8dee98
FW
43static inline void nf_ct_zone_add(struct nf_conn *ct,
44 const struct nf_conntrack_zone *zone)
308ac914 45{
5e8018fc 46#ifdef CONFIG_NF_CONNTRACK_ZONES
6c8dee98 47 ct->zone = *zone;
5e8018fc 48#endif
308ac914
DB
49}
50
deedb590
DB
51static 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
57static inline u16 nf_ct_zone_id(const struct nf_conntrack_zone *zone,
58 enum ip_conntrack_dir dir)
59{
506e65df 60#ifdef CONFIG_NF_CONNTRACK_ZONES
deedb590
DB
61 return nf_ct_zone_matches_dir(zone, dir) ?
62 zone->id : NF_CT_DEFAULT_ZONE_ID;
506e65df
FW
63#else
64 return NF_CT_DEFAULT_ZONE_ID;
65#endif
deedb590
DB
66}
67
308ac914 68static inline bool nf_ct_zone_equal(const struct nf_conn *a,
deedb590
DB
69 const struct nf_conntrack_zone *b,
70 enum ip_conntrack_dir dir)
71{
506e65df 72#ifdef CONFIG_NF_CONNTRACK_ZONES
deedb590
DB
73 return nf_ct_zone_id(nf_ct_zone(a), dir) ==
74 nf_ct_zone_id(b, dir);
506e65df
FW
75#else
76 return true;
77#endif
deedb590
DB
78}
79
80static inline bool nf_ct_zone_equal_any(const struct nf_conn *a,
81 const struct nf_conntrack_zone *b)
308ac914 82{
506e65df 83#ifdef CONFIG_NF_CONNTRACK_ZONES
308ac914 84 return nf_ct_zone(a)->id == b->id;
506e65df
FW
85#else
86 return true;
87#endif
308ac914
DB
88}
89#endif /* IS_ENABLED(CONFIG_NF_CONNTRACK) */
5d0aa2cc 90#endif /* _NF_CONNTRACK_ZONES_H */