]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - include/net/netfilter/nf_conntrack_extend.h
Merge branches 'release' and 'doc' into release
[linux-2.6-omap-h63xx.git] / include / net / netfilter / nf_conntrack_extend.h
1 #ifndef _NF_CONNTRACK_EXTEND_H
2 #define _NF_CONNTRACK_EXTEND_H
3
4 #include <net/netfilter/nf_conntrack.h>
5
6 enum nf_ct_ext_id
7 {
8         NF_CT_EXT_HELPER,
9         NF_CT_EXT_NAT,
10         NF_CT_EXT_NUM,
11 };
12
13 #define NF_CT_EXT_HELPER_TYPE struct nf_conn_help
14 #define NF_CT_EXT_NAT_TYPE struct nf_conn_nat
15
16 /* Extensions: optional stuff which isn't permanently in struct. */
17 struct nf_ct_ext {
18         u8 offset[NF_CT_EXT_NUM];
19         u8 len;
20         char data[0];
21 };
22
23 static inline int nf_ct_ext_exist(const struct nf_conn *ct, u8 id)
24 {
25         return (ct->ext && ct->ext->offset[id]);
26 }
27
28 static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id)
29 {
30         if (!nf_ct_ext_exist(ct, id))
31                 return NULL;
32
33         return (void *)ct->ext + ct->ext->offset[id];
34 }
35 #define nf_ct_ext_find(ext, id) \
36         ((id##_TYPE *)__nf_ct_ext_find((ext), (id)))
37
38 /* Destroy all relationships */
39 extern void __nf_ct_ext_destroy(struct nf_conn *ct);
40 static inline void nf_ct_ext_destroy(struct nf_conn *ct)
41 {
42         if (ct->ext)
43                 __nf_ct_ext_destroy(ct);
44 }
45
46 /* Free operation. If you want to free a object referred from private area,
47  * please implement __nf_ct_ext_free() and call it.
48  */
49 static inline void nf_ct_ext_free(struct nf_conn *ct)
50 {
51         if (ct->ext)
52                 kfree(ct->ext);
53 }
54
55 /* Add this type, returns pointer to data or NULL. */
56 void *
57 __nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp);
58 #define nf_ct_ext_add(ct, id, gfp) \
59         ((id##_TYPE *)__nf_ct_ext_add((ct), (id), (gfp)))
60
61 #define NF_CT_EXT_F_PREALLOC    0x0001
62
63 struct nf_ct_ext_type
64 {
65         /* Destroys relationships (can be NULL). */
66         void (*destroy)(struct nf_conn *ct);
67         /* Called when realloacted (can be NULL).
68            Contents has already been moved. */
69         void (*move)(void *new, void *old);
70
71         enum nf_ct_ext_id id;
72
73         unsigned int flags;
74
75         /* Length and min alignment. */
76         u8 len;
77         u8 align;
78         /* initial size of nf_ct_ext. */
79         u8 alloc_size;
80 };
81
82 int nf_ct_extend_register(struct nf_ct_ext_type *type);
83 void nf_ct_extend_unregister(struct nf_ct_ext_type *type);
84 #endif /* _NF_CONNTRACK_EXTEND_H */