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