1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _NF_CONNTRACK_EXTEND_H
3 #define _NF_CONNTRACK_EXTEND_H
5 #include <linux/slab.h>
7 #include <net/netfilter/nf_conntrack.h>
11 #if IS_ENABLED(CONFIG_NF_NAT)
16 #ifdef CONFIG_NF_CONNTRACK_EVENTS
19 #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
22 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
25 #ifdef CONFIG_NF_CONNTRACK_LABELS
28 #if IS_ENABLED(CONFIG_NETFILTER_SYNPROXY)
31 #if IS_ENABLED(CONFIG_NET_ACT_CT)
37 /* Extensions: optional stuff which isn't permanently in struct. */
39 u8 offset[NF_CT_EXT_NUM];
42 char data[] __aligned(8);
45 static inline bool __nf_ct_ext_exist(const struct nf_ct_ext *ext, u8 id)
47 return !!ext->offset[id];
50 static inline bool nf_ct_ext_exist(const struct nf_conn *ct, u8 id)
52 return (ct->ext && __nf_ct_ext_exist(ct->ext, id));
55 void *__nf_ct_ext_find(const struct nf_ct_ext *ext, u8 id);
57 static inline void *nf_ct_ext_find(const struct nf_conn *ct, u8 id)
59 struct nf_ct_ext *ext = ct->ext;
61 if (!ext || !__nf_ct_ext_exist(ext, id))
64 if (unlikely(ext->gen_id))
65 return __nf_ct_ext_find(ext, id);
67 return (void *)ct->ext + ct->ext->offset[id];
70 /* Add this type, returns pointer to data or NULL. */
71 void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp);
73 /* ext genid. if ext->id != ext_genid, extensions cannot be used
74 * anymore unless conntrack has CONFIRMED bit set.
76 extern atomic_t nf_conntrack_ext_genid;
77 void nf_ct_ext_bump_genid(void);
79 #endif /* _NF_CONNTRACK_EXTEND_H */