1 #ifndef _NF_CONNTRACK_EXTEND_H 2 #define _NF_CONNTRACK_EXTEND_H 3 4 #include <linux/slab.h> 5 6 #include <net/netfilter/nf_conntrack.h> 7 8 enum nf_ct_ext_id { 9 NF_CT_EXT_HELPER, 10 NF_CT_EXT_NAT, 11 NF_CT_EXT_ACCT, 12 NF_CT_EXT_ECACHE, 13 NF_CT_EXT_ZONE, 14 NF_CT_EXT_NUM, 15 }; 16 17 #define NF_CT_EXT_HELPER_TYPE struct nf_conn_help 18 #define NF_CT_EXT_NAT_TYPE struct nf_conn_nat 19 #define NF_CT_EXT_ACCT_TYPE struct nf_conn_counter 20 #define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache 21 #define NF_CT_EXT_ZONE_TYPE struct nf_conntrack_zone 22 23 /* Extensions: optional stuff which isn't permanently in struct. */ 24 struct nf_ct_ext { 25 struct rcu_head rcu; 26 u8 offset[NF_CT_EXT_NUM]; 27 u8 len; 28 char data[0]; 29 }; 30 31 static inline int nf_ct_ext_exist(const struct nf_conn *ct, u8 id) 32 { 33 return (ct->ext && ct->ext->offset[id]); 34 } 35 36 static 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 */ 47 extern void __nf_ct_ext_destroy(struct nf_conn *ct); 48 static 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 */ 57 static 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. */ 64 void * 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 71 struct nf_ct_ext_type { 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. */ 76 void (*move)(void *new, void *old); 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 89 int nf_ct_extend_register(struct nf_ct_ext_type *type); 90 void nf_ct_extend_unregister(struct nf_ct_ext_type *type); 91 #endif /* _NF_CONNTRACK_EXTEND_H */ 92