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