1#ifndef _NF_CONNTRACK_TIMEOUT_H 2#define _NF_CONNTRACK_TIMEOUT_H 3 4#include <net/net_namespace.h> 5#include <linux/netfilter/nf_conntrack_common.h> 6#include <linux/netfilter/nf_conntrack_tuple_common.h> 7#include <net/netfilter/nf_conntrack.h> 8#include <net/netfilter/nf_conntrack_extend.h> 9 10#define CTNL_TIMEOUT_NAME_MAX 32 11 12struct ctnl_timeout { 13 struct list_head head; 14 struct rcu_head rcu_head; 15 atomic_t refcnt; 16 char name[CTNL_TIMEOUT_NAME_MAX]; 17 __u16 l3num; 18 struct nf_conntrack_l4proto *l4proto; 19 char data[0]; 20}; 21 22struct nf_conn_timeout { 23 struct ctnl_timeout __rcu *timeout; 24}; 25 26static inline unsigned int * 27nf_ct_timeout_data(struct nf_conn_timeout *t) 28{ 29 struct ctnl_timeout *timeout; 30 31 timeout = rcu_dereference(t->timeout); 32 if (timeout == NULL) 33 return NULL; 34 35 return (unsigned int *)timeout->data; 36} 37 38static inline 39struct nf_conn_timeout *nf_ct_timeout_find(const struct nf_conn *ct) 40{ 41#ifdef CONFIG_NF_CONNTRACK_TIMEOUT 42 return nf_ct_ext_find(ct, NF_CT_EXT_TIMEOUT); 43#else 44 return NULL; 45#endif 46} 47 48static inline 49struct nf_conn_timeout *nf_ct_timeout_ext_add(struct nf_conn *ct, 50 struct ctnl_timeout *timeout, 51 gfp_t gfp) 52{ 53#ifdef CONFIG_NF_CONNTRACK_TIMEOUT 54 struct nf_conn_timeout *timeout_ext; 55 56 timeout_ext = nf_ct_ext_add(ct, NF_CT_EXT_TIMEOUT, gfp); 57 if (timeout_ext == NULL) 58 return NULL; 59 60 rcu_assign_pointer(timeout_ext->timeout, timeout); 61 62 return timeout_ext; 63#else 64 return NULL; 65#endif 66}; 67 68static inline unsigned int * 69nf_ct_timeout_lookup(struct net *net, struct nf_conn *ct, 70 struct nf_conntrack_l4proto *l4proto) 71{ 72#ifdef CONFIG_NF_CONNTRACK_TIMEOUT 73 struct nf_conn_timeout *timeout_ext; 74 unsigned int *timeouts; 75 76 timeout_ext = nf_ct_timeout_find(ct); 77 if (timeout_ext) { 78 timeouts = nf_ct_timeout_data(timeout_ext); 79 if (unlikely(!timeouts)) 80 timeouts = l4proto->get_timeouts(net); 81 } else { 82 timeouts = l4proto->get_timeouts(net); 83 } 84 85 return timeouts; 86#else 87 return l4proto->get_timeouts(net); 88#endif 89} 90 91#ifdef CONFIG_NF_CONNTRACK_TIMEOUT 92int nf_conntrack_timeout_init(void); 93void nf_conntrack_timeout_fini(void); 94#else 95static inline int nf_conntrack_timeout_init(void) 96{ 97 return 0; 98} 99 100static inline void nf_conntrack_timeout_fini(void) 101{ 102 return; 103} 104#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ 105 106#ifdef CONFIG_NF_CONNTRACK_TIMEOUT 107extern struct ctnl_timeout *(*nf_ct_timeout_find_get_hook)(struct net *net, const char *name); 108extern void (*nf_ct_timeout_put_hook)(struct ctnl_timeout *timeout); 109#endif 110 111#endif /* _NF_CONNTRACK_TIMEOUT_H */ 112