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