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