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