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 defined(CONFIG_NF_NAT) || defined(CONFIG_NF_NAT_MODULE)
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)
34 #define NF_CT_EXT_HELPER_TYPE struct nf_conn_help
35 #define NF_CT_EXT_NAT_TYPE struct nf_conn_nat
36 #define NF_CT_EXT_SEQADJ_TYPE struct nf_conn_seqadj
37 #define NF_CT_EXT_ACCT_TYPE struct nf_conn_acct
38 #define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache
39 #define NF_CT_EXT_TSTAMP_TYPE struct nf_conn_tstamp
40 #define NF_CT_EXT_TIMEOUT_TYPE struct nf_conn_timeout
41 #define NF_CT_EXT_LABELS_TYPE struct nf_conn_labels
42 #define NF_CT_EXT_SYNPROXY_TYPE struct nf_conn_synproxy
44 /* Extensions: optional stuff which isn't permanently in struct. */
47 u8 offset[NF_CT_EXT_NUM];
52 static inline bool __nf_ct_ext_exist(const struct nf_ct_ext *ext, u8 id)
54 return !!ext->offset[id];
57 static inline bool nf_ct_ext_exist(const struct nf_conn *ct, u8 id)
59 return (ct->ext && __nf_ct_ext_exist(ct->ext, id));
62 static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id)
64 if (!nf_ct_ext_exist(ct, id))
67 return (void *)ct->ext + ct->ext->offset[id];
69 #define nf_ct_ext_find(ext, id) \
70 ((id##_TYPE *)__nf_ct_ext_find((ext), (id)))
72 /* Destroy all relationships */
73 void nf_ct_ext_destroy(struct nf_conn *ct);
75 /* Free operation. If you want to free a object referred from private area,
76 * please implement __nf_ct_ext_free() and call it.
78 static inline void nf_ct_ext_free(struct nf_conn *ct)
81 kfree_rcu(ct->ext, rcu);
84 /* Add this type, returns pointer to data or NULL. */
85 void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp);
87 struct nf_ct_ext_type {
88 /* Destroys relationships (can be NULL). */
89 void (*destroy)(struct nf_conn *ct);
93 /* Length and min alignment. */
98 int nf_ct_extend_register(const struct nf_ct_ext_type *type);
99 void nf_ct_extend_unregister(const struct nf_ct_ext_type *type);
100 #endif /* _NF_CONNTRACK_EXTEND_H */