ip_conntrack.h
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:5k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. #ifndef _IP_CONNTRACK_H
  2. #define _IP_CONNTRACK_H
  3. /* Connection state tracking for netfilter.  This is separated from,
  4.    but required by, the NAT layer; it can also be used by an iptables
  5.    extension. */
  6. #include <linux/config.h>
  7. #include <linux/netfilter_ipv4/ip_conntrack_tuple.h>
  8. enum ip_conntrack_info
  9. {
  10. /* Part of an established connection (either direction). */
  11. IP_CT_ESTABLISHED,
  12. /* Like NEW, but related to an existing connection, or ICMP error
  13.    (in either direction). */
  14. IP_CT_RELATED,
  15. /* Started a new connection to track (only
  16.            IP_CT_DIR_ORIGINAL); may be a retransmission. */
  17. IP_CT_NEW,
  18. /* >= this indicates reply direction */
  19. IP_CT_IS_REPLY,
  20. /* Number of distinct IP_CT types (no NEW in reply dirn). */
  21. IP_CT_NUMBER = IP_CT_IS_REPLY * 2 - 1
  22. };
  23. /* Bitset representing status of connection. */
  24. enum ip_conntrack_status {
  25. /* It's an expected connection: bit 0 set.  This bit never changed */
  26. IPS_EXPECTED_BIT = 0,
  27. IPS_EXPECTED = (1 << IPS_EXPECTED_BIT),
  28. /* We've seen packets both ways: bit 1 set.  Can be set, not unset. */
  29. IPS_SEEN_REPLY_BIT = 1,
  30. IPS_SEEN_REPLY = (1 << IPS_SEEN_REPLY_BIT),
  31. /* Conntrack should never be early-expired. */
  32. IPS_ASSURED_BIT = 2,
  33. IPS_ASSURED = (1 << IPS_ASSURED_BIT),
  34. };
  35. #ifdef __KERNEL__
  36. #include <linux/types.h>
  37. #include <linux/skbuff.h>
  38. #include <linux/netfilter_ipv4/ip_conntrack_tcp.h>
  39. #include <linux/netfilter_ipv4/ip_conntrack_icmp.h>
  40. #ifdef CONFIG_NF_DEBUG
  41. #define IP_NF_ASSERT(x)
  42. do {
  43. if (!(x))
  44. /* Wooah!  I'm tripping my conntrack in a frenzy of
  45.    netplay... */
  46. printk("NF_IP_ASSERT: %s:%i(%s)n",
  47.        __FILE__, __LINE__, __FUNCTION__);
  48. } while(0)
  49. #else
  50. #define IP_NF_ASSERT(x)
  51. #endif
  52. struct ip_conntrack_expect
  53. {
  54. /* Internal linked list */
  55. struct list_head list;
  56. /* We expect this tuple, with the following mask */
  57. struct ip_conntrack_tuple tuple, mask;
  58. /* Function to call after setup and insertion */
  59. int (*expectfn)(struct ip_conntrack *new);
  60. /* The conntrack we are part of (set iff we're live) */
  61. struct ip_conntrack *expectant;
  62. };
  63. #ifdef CONFIG_IP_NF_NAT_NEEDED
  64. #include <linux/netfilter_ipv4/ip_nat.h>
  65. #endif
  66. #include <linux/netfilter_ipv4/ip_conntrack_ftp.h>
  67. #include <linux/netfilter_ipv4/ip_conntrack_irc.h>
  68. struct ip_conntrack
  69. {
  70. /* Usage count in here is 1 for hash table/destruct timer, 1 per skb,
  71.            plus 1 for any connection(s) we are `master' for */
  72. struct nf_conntrack ct_general;
  73. /* These are my tuples; original and reply */
  74. struct ip_conntrack_tuple_hash tuplehash[IP_CT_DIR_MAX];
  75. /* Have we seen traffic both ways yet? (bitset) */
  76. volatile unsigned long status;
  77. /* Timer function; drops refcnt when it goes off. */
  78. struct timer_list timeout;
  79. /* If we're expecting another related connection, this will be
  80.            in expected linked list */
  81. struct ip_conntrack_expect expected;
  82. /* If we were expected by another connection, this will be it */
  83. struct nf_ct_info master;
  84. /* Helper, if any. */
  85. struct ip_conntrack_helper *helper;
  86. /* Our various nf_ct_info structs specify *what* relation this
  87.            packet has to the conntrack */
  88. struct nf_ct_info infos[IP_CT_NUMBER];
  89. /* Storage reserved for other modules: */
  90. union {
  91. struct ip_ct_tcp tcp;
  92. struct ip_ct_icmp icmp;
  93. } proto;
  94. union {
  95. struct ip_ct_ftp ct_ftp_info;
  96. struct ip_ct_irc ct_irc_info;
  97. } help;
  98. #ifdef CONFIG_IP_NF_NAT_NEEDED
  99. struct {
  100. struct ip_nat_info info;
  101. union {
  102. /* insert nat helper private data here */
  103. } help;
  104. #if defined(CONFIG_IP_NF_TARGET_MASQUERADE) || 
  105. defined(CONFIG_IP_NF_TARGET_MASQUERADE_MODULE)
  106. int masq_index;
  107. #endif
  108. } nat;
  109. #endif /* CONFIG_IP_NF_NAT_NEEDED */
  110. };
  111. /* Alter reply tuple (maybe alter helper).  If it's already taken,
  112.    return 0 and don't do alteration. */
  113. extern int
  114. ip_conntrack_alter_reply(struct ip_conntrack *conntrack,
  115.  const struct ip_conntrack_tuple *newreply);
  116. /* Is this tuple taken? (ignoring any belonging to the given
  117.    conntrack). */
  118. extern int
  119. ip_conntrack_tuple_taken(const struct ip_conntrack_tuple *tuple,
  120.  const struct ip_conntrack *ignored_conntrack);
  121. /* Return conntrack_info and tuple hash for given skb. */
  122. extern struct ip_conntrack *
  123. ip_conntrack_get(struct sk_buff *skb, enum ip_conntrack_info *ctinfo);
  124. extern struct module *ip_conntrack_module;
  125. extern int invert_tuplepr(struct ip_conntrack_tuple *inverse,
  126.   const struct ip_conntrack_tuple *orig);
  127. /* Refresh conntrack for this many jiffies */
  128. extern void ip_ct_refresh(struct ip_conntrack *ct,
  129.   unsigned long extra_jiffies);
  130. /* These are for NAT.  Icky. */
  131. /* Call me when a conntrack is destroyed. */
  132. extern void (*ip_conntrack_destroyed)(struct ip_conntrack *conntrack);
  133. /* Returns new sk_buff, or NULL */
  134. struct sk_buff *
  135. ip_ct_gather_frags(struct sk_buff *skb);
  136. /* Delete all conntracks which match. */
  137. extern void
  138. ip_ct_selective_cleanup(int (*kill)(const struct ip_conntrack *i, void *data),
  139. void *data);
  140. /* It's confirmed if it is, or has been in the hash table. */
  141. static inline int is_confirmed(struct ip_conntrack *ct)
  142. {
  143. return ct->tuplehash[IP_CT_DIR_ORIGINAL].list.next != NULL;
  144. }
  145. extern unsigned int ip_conntrack_htable_size;
  146. #endif /* __KERNEL__ */
  147. #endif /* _IP_CONNTRACK_H */