aboutsummaryrefslogtreecommitdiffstats
path: root/include/net
diff options
context:
space:
mode:
authorYasuyuki Kozakai <yasuyuki.kozakai@toshiba.co.jp>2007-07-08 01:23:21 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-07-11 01:17:17 -0400
commitecfab2c9fe5597221c2b30dec48634a2361a0d08 (patch)
tree5640796c698074105430c1c1bc24df87f4d0a6b4 /include/net
parent4ba887790ce2015e8c464809c0be902fb813ad15 (diff)
[NETFILTER]: nf_conntrack: introduce extension infrastructure
Old space allocator of conntrack had problems about extensibility. - It required slab cache per combination of extensions. - It expected what extensions would be assigned, but it was impossible to expect that completely, then we allocated bigger memory object than really required. - It needed to search helper twice due to lock issue. Now basic informations of a connection are stored in 'struct nf_conn'. And a storage for extension (helper, NAT) is allocated by kmalloc. Signed-off-by: Yasuyuki Kozakai <yasuyuki.kozakai@toshiba.co.jp> Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net')
-rw-r--r--include/net/netfilter/nf_conntrack.h3
-rw-r--r--include/net/netfilter/nf_conntrack_extend.h80
2 files changed, 83 insertions, 0 deletions
diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
index 12a0e793cc0b..c31382d3ef11 100644
--- a/include/net/netfilter/nf_conntrack.h
+++ b/include/net/netfilter/nf_conntrack.h
@@ -131,6 +131,9 @@ struct nf_conn
131 /* Storage reserved for other modules: */ 131 /* Storage reserved for other modules: */
132 union nf_conntrack_proto proto; 132 union nf_conntrack_proto proto;
133 133
134 /* Extensions */
135 struct nf_ct_ext *ext;
136
134 /* features dynamically at the end: helper, nat (both optional) */ 137 /* features dynamically at the end: helper, nat (both optional) */
135 char data[0]; 138 char data[0];
136}; 139};
diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
new file mode 100644
index 000000000000..8a988d136465
--- /dev/null
+++ b/include/net/netfilter/nf_conntrack_extend.h
@@ -0,0 +1,80 @@
1#ifndef _NF_CONNTRACK_EXTEND_H
2#define _NF_CONNTRACK_EXTEND_H
3
4#include <net/netfilter/nf_conntrack.h>
5
6enum nf_ct_ext_id
7{
8 NF_CT_EXT_NUM,
9};
10
11/* Extensions: optional stuff which isn't permanently in struct. */
12struct nf_ct_ext {
13 u8 offset[NF_CT_EXT_NUM];
14 u8 len;
15 u8 real_len;
16 char data[0];
17};
18
19static inline int nf_ct_ext_exist(const struct nf_conn *ct, u8 id)
20{
21 return (ct->ext && ct->ext->offset[id]);
22}
23
24static 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 */
35extern void __nf_ct_ext_destroy(struct nf_conn *ct);
36static 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 */
45static 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. */
52void *
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
59struct 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
78int nf_ct_extend_register(struct nf_ct_ext_type *type);
79void nf_ct_extend_unregister(struct nf_ct_ext_type *type);
80#endif /* _NF_CONNTRACK_EXTEND_H */