Merge branch 'for-2.6.36' of git://git.kernel.dk/linux-2.6-block
[pandora-kernel.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         NF_CT_EXT_NAT,
11         NF_CT_EXT_ACCT,
12         NF_CT_EXT_ECACHE,
13         NF_CT_EXT_ZONE,
14         NF_CT_EXT_NUM,
15 };
16
17 #define NF_CT_EXT_HELPER_TYPE struct nf_conn_help
18 #define NF_CT_EXT_NAT_TYPE struct nf_conn_nat
19 #define NF_CT_EXT_ACCT_TYPE struct nf_conn_counter
20 #define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache
21 #define NF_CT_EXT_ZONE_TYPE struct nf_conntrack_zone
22
23 /* Extensions: optional stuff which isn't permanently in struct. */
24 struct nf_ct_ext {
25         struct rcu_head rcu;
26         u8 offset[NF_CT_EXT_NUM];
27         u8 len;
28         char data[0];
29 };
30
31 static inline bool __nf_ct_ext_exist(const struct nf_ct_ext *ext, u8 id)
32 {
33         return !!ext->offset[id];
34 }
35
36 static inline bool nf_ct_ext_exist(const struct nf_conn *ct, u8 id)
37 {
38         return (ct->ext && __nf_ct_ext_exist(ct->ext, id));
39 }
40
41 static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id)
42 {
43         if (!nf_ct_ext_exist(ct, id))
44                 return NULL;
45
46         return (void *)ct->ext + ct->ext->offset[id];
47 }
48 #define nf_ct_ext_find(ext, id) \
49         ((id##_TYPE *)__nf_ct_ext_find((ext), (id)))
50
51 /* Destroy all relationships */
52 extern void __nf_ct_ext_destroy(struct nf_conn *ct);
53 static inline void nf_ct_ext_destroy(struct nf_conn *ct)
54 {
55         if (ct->ext)
56                 __nf_ct_ext_destroy(ct);
57 }
58
59 /* Free operation. If you want to free a object referred from private area,
60  * please implement __nf_ct_ext_free() and call it.
61  */
62 static inline void nf_ct_ext_free(struct nf_conn *ct)
63 {
64         if (ct->ext)
65                 kfree(ct->ext);
66 }
67
68 /* Add this type, returns pointer to data or NULL. */
69 void *
70 __nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp);
71 #define nf_ct_ext_add(ct, id, gfp) \
72         ((id##_TYPE *)__nf_ct_ext_add((ct), (id), (gfp)))
73
74 #define NF_CT_EXT_F_PREALLOC    0x0001
75
76 struct nf_ct_ext_type {
77         /* Destroys relationships (can be NULL). */
78         void (*destroy)(struct nf_conn *ct);
79         /* Called when realloacted (can be NULL).
80            Contents has already been moved. */
81         void (*move)(void *new, void *old);
82
83         enum nf_ct_ext_id id;
84
85         unsigned int flags;
86
87         /* Length and min alignment. */
88         u8 len;
89         u8 align;
90         /* initial size of nf_ct_ext. */
91         u8 alloc_size;
92 };
93
94 int nf_ct_extend_register(struct nf_ct_ext_type *type);
95 void nf_ct_extend_unregister(struct nf_ct_ext_type *type);
96 #endif /* _NF_CONNTRACK_EXTEND_H */