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)
14 #ifdef CONFIG_NF_CONNTRACK_EVENTS
17 #ifdef CONFIG_NF_CONNTRACK_ZONES
20 #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
23 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
29 #define NF_CT_EXT_HELPER_TYPE struct nf_conn_help
30 #define NF_CT_EXT_NAT_TYPE struct nf_conn_nat
31 #define NF_CT_EXT_ACCT_TYPE struct nf_conn_counter
32 #define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache
33 #define NF_CT_EXT_ZONE_TYPE struct nf_conntrack_zone
34 #define NF_CT_EXT_TSTAMP_TYPE struct nf_conn_tstamp
35 #define NF_CT_EXT_TIMEOUT_TYPE struct nf_conn_timeout
37 /* Extensions: optional stuff which isn't permanently in struct. */
40 u8 offset
[NF_CT_EXT_NUM
];
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 static inline void *__nf_ct_ext_find(const struct nf_conn
*ct
, u8 id
)
57 if (!nf_ct_ext_exist(ct
, id
))
60 return (void *)ct
->ext
+ ct
->ext
->offset
[id
];
62 #define nf_ct_ext_find(ext, id) \
63 ((id##_TYPE *)__nf_ct_ext_find((ext), (id)))
65 /* Destroy all relationships */
66 extern void __nf_ct_ext_destroy(struct nf_conn
*ct
);
67 static inline void nf_ct_ext_destroy(struct nf_conn
*ct
)
70 __nf_ct_ext_destroy(ct
);
73 /* Free operation. If you want to free a object referred from private area,
74 * please implement __nf_ct_ext_free() and call it.
76 static inline void nf_ct_ext_free(struct nf_conn
*ct
)
82 /* Add this type, returns pointer to data or NULL. */
83 void *__nf_ct_ext_add_length(struct nf_conn
*ct
, enum nf_ct_ext_id id
,
84 size_t var_alloc_len
, gfp_t gfp
);
86 #define nf_ct_ext_add(ct, id, gfp) \
87 ((id##_TYPE *)__nf_ct_ext_add_length((ct), (id), 0, (gfp)))
88 #define nf_ct_ext_add_length(ct, id, len, gfp) \
89 ((id##_TYPE *)__nf_ct_ext_add_length((ct), (id), (len), (gfp)))
91 #define NF_CT_EXT_F_PREALLOC 0x0001
93 struct nf_ct_ext_type
{
94 /* Destroys relationships (can be NULL). */
95 void (*destroy
)(struct nf_conn
*ct
);
96 /* Called when realloacted (can be NULL).
97 Contents has already been moved. */
98 void (*move
)(void *new, void *old
);
100 enum nf_ct_ext_id id
;
104 /* Length and min alignment. */
107 /* initial size of nf_ct_ext. */
111 int nf_ct_extend_register(struct nf_ct_ext_type
*type
);
112 void nf_ct_extend_unregister(struct nf_ct_ext_type
*type
);
113 #endif /* _NF_CONNTRACK_EXTEND_H */