Merge tag 'firewire-updates' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee139...
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / net / netfilter / nf_conntrack_extend.h
CommitLineData
ecfab2c9
YK
1#ifndef _NF_CONNTRACK_EXTEND_H
2#define _NF_CONNTRACK_EXTEND_H
3
5a0e3ad6
TH
4#include <linux/slab.h>
5
ecfab2c9
YK
6#include <net/netfilter/nf_conntrack.h>
7
fd2c3ef7 8enum nf_ct_ext_id {
ceceae1b 9 NF_CT_EXT_HELPER,
e0e76c83 10#if defined(CONFIG_NF_NAT) || defined(CONFIG_NF_NAT_MODULE)
2d59e5ca 11 NF_CT_EXT_NAT,
e0e76c83 12#endif
58401572 13 NF_CT_EXT_ACCT,
e0e76c83 14#ifdef CONFIG_NF_CONNTRACK_EVENTS
a0891aa6 15 NF_CT_EXT_ECACHE,
e0e76c83
CG
16#endif
17#ifdef CONFIG_NF_CONNTRACK_ZONES
5d0aa2cc 18 NF_CT_EXT_ZONE,
a992ca2a
PNA
19#endif
20#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
21 NF_CT_EXT_TSTAMP,
dd705072
PNA
22#endif
23#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
24 NF_CT_EXT_TIMEOUT,
e0e76c83 25#endif
ecfab2c9
YK
26 NF_CT_EXT_NUM,
27};
28
ceceae1b 29#define NF_CT_EXT_HELPER_TYPE struct nf_conn_help
2d59e5ca 30#define NF_CT_EXT_NAT_TYPE struct nf_conn_nat
58401572 31#define NF_CT_EXT_ACCT_TYPE struct nf_conn_counter
a0891aa6 32#define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache
5d0aa2cc 33#define NF_CT_EXT_ZONE_TYPE struct nf_conntrack_zone
a992ca2a 34#define NF_CT_EXT_TSTAMP_TYPE struct nf_conn_tstamp
dd705072 35#define NF_CT_EXT_TIMEOUT_TYPE struct nf_conn_timeout
ceceae1b 36
ecfab2c9
YK
37/* Extensions: optional stuff which isn't permanently in struct. */
38struct nf_ct_ext {
68b80f11 39 struct rcu_head rcu;
ecfab2c9
YK
40 u8 offset[NF_CT_EXT_NUM];
41 u8 len;
ecfab2c9
YK
42 char data[0];
43};
44
ee92d378 45static inline bool __nf_ct_ext_exist(const struct nf_ct_ext *ext, u8 id)
ecfab2c9 46{
ee92d378
CG
47 return !!ext->offset[id];
48}
49
50static inline bool nf_ct_ext_exist(const struct nf_conn *ct, u8 id)
51{
52 return (ct->ext && __nf_ct_ext_exist(ct->ext, id));
ecfab2c9
YK
53}
54
55static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id)
56{
57 if (!nf_ct_ext_exist(ct, id))
58 return NULL;
59
60 return (void *)ct->ext + ct->ext->offset[id];
61}
62#define nf_ct_ext_find(ext, id) \
63 ((id##_TYPE *)__nf_ct_ext_find((ext), (id)))
64
65/* Destroy all relationships */
66extern void __nf_ct_ext_destroy(struct nf_conn *ct);
67static inline void nf_ct_ext_destroy(struct nf_conn *ct)
68{
69 if (ct->ext)
70 __nf_ct_ext_destroy(ct);
71}
72
73/* Free operation. If you want to free a object referred from private area,
74 * please implement __nf_ct_ext_free() and call it.
75 */
76static inline void nf_ct_ext_free(struct nf_conn *ct)
77{
78 if (ct->ext)
79 kfree(ct->ext);
80}
81
82/* Add this type, returns pointer to data or NULL. */
3cf4c7e3
PNA
83void *__nf_ct_ext_add_length(struct nf_conn *ct, enum nf_ct_ext_id id,
84 size_t var_alloc_len, gfp_t gfp);
85
ecfab2c9 86#define nf_ct_ext_add(ct, id, gfp) \
3cf4c7e3
PNA
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)))
ecfab2c9
YK
90
91#define NF_CT_EXT_F_PREALLOC 0x0001
92
fd2c3ef7 93struct nf_ct_ext_type {
ecfab2c9
YK
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. */
86577c66 98 void (*move)(void *new, void *old);
ecfab2c9
YK
99
100 enum nf_ct_ext_id id;
101
102 unsigned int flags;
103
104 /* Length and min alignment. */
105 u8 len;
106 u8 align;
107 /* initial size of nf_ct_ext. */
108 u8 alloc_size;
109};
110
111int nf_ct_extend_register(struct nf_ct_ext_type *type);
112void nf_ct_extend_unregister(struct nf_ct_ext_type *type);
113#endif /* _NF_CONNTRACK_EXTEND_H */