nf_conntrack_timeout.h 2.4 KB

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