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)
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. */
46 u8 offset[NF_CT_EXT_NUM];
51 static inline bool __nf_ct_ext_exist(const struct nf_ct_ext *ext, u8 id)
53 return !!ext->offset[id];
56 static inline bool nf_ct_ext_exist(const struct nf_conn *ct, u8 id)
58 return (ct->ext && __nf_ct_ext_exist(ct->ext, id));
61 static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id)
63 if (!nf_ct_ext_exist(ct, id))
66 return (void *)ct->ext + ct->ext->offset[id];
68 #define nf_ct_ext_find(ext, id) \
69 ((id##_TYPE *)__nf_ct_ext_find((ext), (id)))
71 /* Destroy all relationships */
72 void nf_ct_ext_destroy(struct nf_conn *ct);
74 /* Add this type, returns pointer to data or NULL. */
75 void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp);
77 struct nf_ct_ext_type {
78 /* Destroys relationships (can be NULL). */
79 void (*destroy)(struct nf_conn *ct);
83 /* Length and min alignment. */
88 int nf_ct_extend_register(const struct nf_ct_ext_type *type);
89 void nf_ct_extend_unregister(const struct nf_ct_ext_type *type);
90 #endif /* _NF_CONNTRACK_EXTEND_H */