1 #ifndef _NF_CONNTRACK_ZONES_WRAPPER_H
2 #define _NF_CONNTRACK_ZONES_WRAPPER_H
4 #include <linux/version.h>
6 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34)
7 #include_next <net/netfilter/nf_conntrack_zones.h>
10 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,3,0)
12 #include <linux/kconfig.h>
13 #include <linux/types.h>
14 #include <linux/netfilter/nf_conntrack_tuple_common.h>
16 #define NF_CT_DEFAULT_ZONE_ID 0
18 #define NF_CT_ZONE_DIR_ORIG (1 << IP_CT_DIR_ORIGINAL)
19 #define NF_CT_ZONE_DIR_REPL (1 << IP_CT_DIR_REPLY)
21 #define NF_CT_DEFAULT_ZONE_DIR (NF_CT_ZONE_DIR_ORIG | NF_CT_ZONE_DIR_REPL)
23 #define NF_CT_FLAG_MARK 1
25 struct rpl_nf_conntrack_zone {
30 #define nf_conntrack_zone rpl_nf_conntrack_zone
32 extern const struct nf_conntrack_zone nf_ct_zone_dflt;
34 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
35 #include <net/netfilter/nf_conntrack_extend.h>
37 static inline const struct nf_conntrack_zone *
38 rpl_nf_ct_zone(const struct nf_conn *ct)
40 const struct nf_conntrack_zone *nf_ct_zone = NULL;
42 #ifdef CONFIG_NF_CONNTRACK_ZONES
43 nf_ct_zone = nf_ct_ext_find(ct, NF_CT_EXT_ZONE);
45 return nf_ct_zone ? nf_ct_zone : &nf_ct_zone_dflt;
47 #define nf_ct_zone rpl_nf_ct_zone
49 static inline const struct nf_conntrack_zone *
50 nf_ct_zone_init(struct nf_conntrack_zone *zone, u16 id, u8 dir, u8 flags)
59 static inline int nf_ct_zone_add(struct nf_conn *ct, gfp_t flags,
60 const struct nf_conntrack_zone *info)
62 #ifdef CONFIG_NF_CONNTRACK_ZONES
63 struct nf_conntrack_zone *nf_ct_zone;
65 nf_ct_zone = nf_ct_ext_add(ct, NF_CT_EXT_ZONE, flags);
69 nf_ct_zone_init(nf_ct_zone, info->id, info->dir,
75 static inline bool nf_ct_zone_matches_dir(const struct nf_conntrack_zone *zone,
76 enum ip_conntrack_dir dir)
78 return zone->dir & (1 << dir);
81 static inline u16 nf_ct_zone_id(const struct nf_conntrack_zone *zone,
82 enum ip_conntrack_dir dir)
84 return nf_ct_zone_matches_dir(zone, dir) ?
85 zone->id : NF_CT_DEFAULT_ZONE_ID;
88 static inline bool nf_ct_zone_equal(const struct nf_conn *a,
89 const struct nf_conntrack_zone *b,
90 enum ip_conntrack_dir dir)
92 return nf_ct_zone_id(nf_ct_zone(a), dir) ==
93 nf_ct_zone_id(b, dir);
96 static inline bool nf_ct_zone_equal_any(const struct nf_conn *a,
97 const struct nf_conntrack_zone *b)
99 return nf_ct_zone(a)->id == b->id;
101 #endif /* IS_ENABLED(CONFIG_NF_CONNTRACK) */
102 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4,3,0) */
103 #endif /* _NF_CONNTRACK_ZONES_WRAPPER_H */