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