1 #ifndef _NF_CONNTRACK_EXTEND_H
2 #define _NF_CONNTRACK_EXTEND_H
4 #include <linux/slab.h>
6 #include <net/netfilter/nf_conntrack.h>
10 #if defined(CONFIG_NF_NAT) || defined(CONFIG_NF_NAT_MODULE)
15 #ifdef CONFIG_NF_CONNTRACK_EVENTS
18 #ifdef CONFIG_NF_CONNTRACK_ZONES
21 #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
24 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
27 #ifdef CONFIG_NF_CONNTRACK_LABELS
33 #define NF_CT_EXT_HELPER_TYPE struct nf_conn_help
34 #define NF_CT_EXT_NAT_TYPE struct nf_conn_nat
35 #define NF_CT_EXT_SEQADJ_TYPE struct nf_conn_seqadj
36 #define NF_CT_EXT_ACCT_TYPE struct nf_conn_counter
37 #define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache
38 #define NF_CT_EXT_ZONE_TYPE struct nf_conntrack_zone
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
43 /* 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 extern void __nf_ct_ext_destroy(struct nf_conn *ct);
73 static inline void nf_ct_ext_destroy(struct nf_conn *ct)
76 __nf_ct_ext_destroy(ct);
79 /* Free operation. If you want to free a object referred from private area,
80 * please implement __nf_ct_ext_free() and call it.
82 static inline void nf_ct_ext_free(struct nf_conn *ct)
88 /* Add this type, returns pointer to data or NULL. */
89 void *__nf_ct_ext_add_length(struct nf_conn *ct, enum nf_ct_ext_id id,
90 size_t var_alloc_len, gfp_t gfp);
92 #define nf_ct_ext_add(ct, id, gfp) \
93 ((id##_TYPE *)__nf_ct_ext_add_length((ct), (id), 0, (gfp)))
94 #define nf_ct_ext_add_length(ct, id, len, gfp) \
95 ((id##_TYPE *)__nf_ct_ext_add_length((ct), (id), (len), (gfp)))
97 #define NF_CT_EXT_F_PREALLOC 0x0001
99 struct nf_ct_ext_type {
100 /* Destroys relationships (can be NULL). */
101 void (*destroy)(struct nf_conn *ct);
102 /* Called when realloacted (can be NULL).
103 Contents has already been moved. */
104 void (*move)(void *new, void *old);
106 enum nf_ct_ext_id id;
110 /* Length and min alignment. */
113 /* initial size of nf_ct_ext. */
117 int nf_ct_extend_register(struct nf_ct_ext_type *type);
118 void nf_ct_extend_unregister(struct nf_ct_ext_type *type);
119 #endif /* _NF_CONNTRACK_EXTEND_H */