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