Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
6.8 KiB

  1. // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil -*- (for GNU Emacs)
  2. //
  3. // Copyright (c) 1985-2000 Microsoft Corporation
  4. //
  5. // This file is part of the Microsoft Research IPv6 Network Protocol Stack.
  6. // You should have received a copy of the Microsoft End-User License Agreement
  7. // for this software along with this release; see the file "license.txt".
  8. // If not, please see http://www.research.microsoft.com/msripv6/license.htm,
  9. // or write to Microsoft Research, One Microsoft Way, Redmond, WA 98052-6399.
  10. //
  11. // Abstract:
  12. //
  13. // Definitions for using IPv4 as a link-layer for IPv6.
  14. //
  15. #ifndef TUNNEL_INCLUDED
  16. #define TUNNEL_INCLUDED 1
  17. //
  18. // A few IPv4 definitions that we need.
  19. // Including the v4 header files causes errors.
  20. // REVIEW: can we fix this?
  21. //
  22. #define INADDR_LOOPBACK 0x0100007f
  23. //
  24. // IP Header format.
  25. //
  26. typedef struct IPHeader {
  27. uchar iph_verlen; // Version and length.
  28. uchar iph_tos; // Type of service.
  29. ushort iph_length; // Total length of datagram.
  30. ushort iph_id; // Identification.
  31. ushort iph_offset; // Flags and fragment offset.
  32. uchar iph_ttl; // Time to live.
  33. uchar iph_protocol; // Protocol.
  34. ushort iph_xsum; // Header checksum.
  35. IPAddr iph_src; // Source address.
  36. IPAddr iph_dest; // Destination address.
  37. } IPHeader;
  38. //
  39. // ICMP Header format.
  40. //
  41. typedef struct ICMPHeader {
  42. uchar ich_type; // Type of ICMP packet.
  43. uchar ich_code; // Subcode of type.
  44. ushort ich_xsum; // Checksum of packet.
  45. ulong ich_param; // Type-specific parameter field.
  46. } ICMPHeader;
  47. #define ICMP_DEST_UNREACH 3
  48. #define ICMP_SOURCE_QUENCH 4
  49. #define ICMP_TIME_EXCEED 11
  50. #define ICMP_PARAM_PROBLEM 12
  51. #define ICMP_TTL_IN_TRANSIT 0
  52. #define ICMP_TTL_IN_REASSEM 1
  53. #define ICMP_NET_UNREACH 0
  54. #define ICMP_HOST_UNREACH 1
  55. #define ICMP_PROT_UNREACH 2
  56. #define ICMP_PORT_UNREACH 3
  57. #define ICMP_FRAG_NEEDED 4
  58. #define ICMP_SR_FAILED 5
  59. #define ICMP_DEST_NET_UNKNOWN 6
  60. #define ICMP_DEST_HOST_UNKNOWN 7
  61. #define ICMP_SRC_ISOLATED 8
  62. #define ICMP_DEST_NET_ADMIN 9
  63. #define ICMP_DEST_HOST_ADMIN 10
  64. #define ICMP_NET_UNREACH_TOS 11
  65. #define ICMP_HOST_UNREACH_TOS 12
  66. //
  67. // Tunnel protocol constants.
  68. //
  69. #define WideStr(x) L#x
  70. #define TUNNEL_DEVICE_NAME(proto) (DD_RAW_IP_DEVICE_NAME L"\\" WideStr(proto))
  71. #define TUNNEL_6OVER4_TTL 16
  72. //
  73. // We don't yet support Path MTU Discovery inside a tunnel,
  74. // so we use a single MTU for the tunnel.
  75. // Our buffer size for receiving IPv4 packets must be larger
  76. // than that MTU, because other implementations might use
  77. // a different value for their tunnel MTU.
  78. //
  79. #define TUNNEL_DEFAULT_MTU IPv6_MINIMUM_MTU
  80. #define TUNNEL_MAX_MTU (64 * 1024 - sizeof(IPHeader) - 1)
  81. #define TUNNEL_RECEIVE_BUFFER (64 * 1024)
  82. #define TUNNEL_DEFAULT_PREFERENCE 1
  83. //
  84. // Each tunnel interface (including the pseudo-interface)
  85. // provides a TunnelContext to the IPv6 code as its link-level context.
  86. //
  87. // Each tunnel interface uses a separate v4 TDI address object
  88. // for sending packets. This allows v4 attributes of the packets
  89. // (like source address and TTL) to be controlled individually
  90. // for each tunnel interface.
  91. //
  92. // The pseudo-tunnel interface does not control the v4 source address
  93. // of the packets that it sends; the v4 stack is free to chose
  94. // any v4 address. Note that this means a packet with a v4-compatible
  95. // v6 source address might be sent using a v4 source address
  96. // that is not derived from the v6 source address.
  97. //
  98. // The 6-over-4 and point-to-point virtual interfaces, however,
  99. // do strictly control the v4 source addresses of their packets.
  100. // As "real" interfaces, they participate in Neighbor Discovery
  101. // and their link-level (v4) address is important.
  102. //
  103. // In contrast to sending, the receive path uses a single address object
  104. // for all tunnel interfaces. We use the TDI address object
  105. // associated with the pseudo-interface; because it's bound to INADDR_ANY
  106. // it receives all encapsulated v6 packets sent to the machine.
  107. //
  108. typedef struct TunnelContext {
  109. struct TunnelContext *Prev, *Next;
  110. //
  111. // This DstAddr must follow SrcAddr in memory;
  112. // see BindInfo.lip_addr initialization.
  113. //
  114. IPAddr SrcAddr; // Our v4 address.
  115. IPAddr DstAddr; // Address of the other tunnel endpoint.
  116. // (Zero for 6-over-4 tunnels.)
  117. IPAddr TokenAddr; // The link-layer address. Same as
  118. // SrcAddr on interfaces except the ISATAP one.
  119. Interface *IF; // Holds a reference.
  120. //
  121. // This field is effectively locked by IF->WorkerLock.
  122. //
  123. int SetMCListOK; // Can TunnelSetMulticastAddressList proceed?
  124. //
  125. // Although we only use AOFile (the pointer version of AOHandle),
  126. // we must keep AOHandle open so AOFile will work. AOHandle
  127. // is in the kernel process context, so any open/close operations
  128. // must be done in the kernel process context.
  129. //
  130. PFILE_OBJECT AOFile;
  131. HANDLE AOHandle;
  132. } TunnelContext;
  133. //
  134. // Information we keep globally.
  135. //
  136. // The spinlock and the mutex are used together to protect
  137. // the chains of tunnel contexts rooted at Tunnel.List and Tunnel.AOList.
  138. // Both must be held to modify a list; either is sufficient for read.
  139. // If both are acquired, the order is mutex first then spinlock.
  140. //
  141. typedef struct TunnelGlobals {
  142. KSPIN_LOCK Lock;
  143. KMUTEX Mutex;
  144. PDEVICE_OBJECT V4Device; // Does not hold a reference.
  145. //
  146. // List.IF is NULL; it is not a context for an interface.
  147. // But the other fields (particularly AOFile and AOHandle)
  148. // do store global values.
  149. //
  150. TunnelContext List; // List of tunnel contexts.
  151. // Used by TunnelReceive/TunnelReceiveComplete.
  152. PIRP ReceiveIrp; // Protected by Tunnel.Lock.
  153. TDI_CONNECTION_INFORMATION ReceiveInputInfo;
  154. TDI_CONNECTION_INFORMATION ReceiveOutputInfo;
  155. PEPROCESS KernelProcess; // For later comparisons.
  156. HANDLE TdiHandle; // For unregistering.
  157. //
  158. // This is not actually a list of tunnels.
  159. // We use a list of TunnelContext structures
  160. // to track mappings from IPv4 address to TDI address object.
  161. // See TunnelTransmit for more information.
  162. //
  163. TunnelContext AOList; // List of address objects.
  164. //
  165. // For receiving ICMPv4 packets.
  166. //
  167. PFILE_OBJECT IcmpFile;
  168. HANDLE IcmpHandle;
  169. } TunnelGlobals;
  170. extern TunnelGlobals Tunnel;
  171. #endif // TUNNEL_INCLUDED