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 { 8 NF_CT_EXT_HELPER, 9 NF_CT_EXT_NAT, 10 NF_CT_EXT_NUM, 11 }; 12 13 #define NF_CT_EXT_HELPER_TYPE struct nf_conn_help 14 #define NF_CT_EXT_NAT_TYPE struct nf_conn_nat 15 16 /* Extensions: optional stuff which isn't permanently in struct. */ 17 struct nf_ct_ext { 18 struct rcu_head rcu; 19 u8 offset[NF_CT_EXT_NUM]; 20 u8 len; 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. */ 70 void (*move)(void *new, void *old); 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 */ 86