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.

443 lines
18 KiB

  1. /********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990-1992 **/
  4. /********************************************************************/
  5. /* :ts=4 */
  6. //** IP.H - IP public definitions.
  7. //
  8. // This file contains all of the definitions that are exported
  9. // out of the IP module to other VxDs. Some other information (such
  10. // as error codes and the IPOptInfo structure) is define in ipexport.h
  11. #pragma once
  12. #ifndef IP_H_INCLUDED
  13. #define IP_H_INCLUDED
  14. #ifndef IP_EXPORT_INCLUDED
  15. #include "ipexport.h"
  16. #endif
  17. #if !MILLEN
  18. #define TCP_NAME L"TCPIP"
  19. #else // !MILLEN
  20. #define TCP_NAME L"MSTCP"
  21. #endif // MILLEN
  22. #define IP_NET_STATUS 0
  23. #define IP_HW_STATUS 1
  24. #define IP_RECONFIG_STATUS 2
  25. #define MASK_NET 0
  26. #define MASK_SUBNET 1
  27. #define IP_DRIVER_VERSION 1
  28. #define TOS_DEFAULT 0x00
  29. #define TOS_MASK 0x03
  30. //* IP offload capability flags (OffloadFlags)
  31. #define TCP_XMT_CHECKSUM_OFFLOAD 0x00000001
  32. #define IP_XMT_CHECKSUM_OFFLOAD 0x00000002
  33. #define TCP_RCV_CHECKSUM_OFFLOAD 0x00000004
  34. #define IP_RCV_CHECKSUM_OFFLOAD 0x00000008
  35. #define TCP_LARGE_SEND_OFFLOAD 0x00000010
  36. #define IP_CHECKSUM_OPT_OFFLOAD 0x00000020
  37. #define TCP_CHECKSUM_OPT_OFFLOAD 0x00000040
  38. #define TCP_LARGE_SEND_TCPOPT_OFFLOAD 0x00000080
  39. #define TCP_LARGE_SEND_IPOPT_OFFLOAD 0x00000100
  40. #define TCP_IP_OFFLOAD_TYPES (TCP_XMT_CHECKSUM_OFFLOAD | \
  41. IP_XMT_CHECKSUM_OFFLOAD | \
  42. TCP_RCV_CHECKSUM_OFFLOAD | \
  43. IP_RCV_CHECKSUM_OFFLOAD | \
  44. TCP_LARGE_SEND_OFFLOAD | \
  45. IP_CHECKSUM_OPT_OFFLOAD | \
  46. TCP_CHECKSUM_OPT_OFFLOAD | \
  47. TCP_LARGE_SEND_TCPOPT_OFFLOAD | \
  48. TCP_LARGE_SEND_IPOPT_OFFLOAD)
  49. //* IPSec offload capability flags (IPSecOffloadFlags)
  50. //
  51. // IPSEC General Xmit\Recv capabilities
  52. //
  53. #define IPSEC_OFFLOAD_CRYPTO_ONLY 0x00000001 // Raw crypto mode supported
  54. #define IPSEC_OFFLOAD_AH_ESP 0x00000002 // Combined AH+ESP supported
  55. #define IPSEC_OFFLOAD_TPT_TUNNEL 0x00000004 // Combined Tpt+Tunnel supported
  56. #define IPSEC_OFFLOAD_V4_OPTIONS 0x00000008 // IPV4 Options supported
  57. #define IPSEC_OFFLOAD_QUERY_SPI 0x00000010 // Get SPI supported
  58. //
  59. // IPSEC AH Xmit\Recv capabilities
  60. //
  61. #define IPSEC_OFFLOAD_AH_XMT 0x00000020 // IPSEC supported on Xmit
  62. #define IPSEC_OFFLOAD_AH_RCV 0x00000040 // IPSEC supported on Rcv
  63. #define IPSEC_OFFLOAD_AH_TPT 0x00000080 // IPSEC transport mode supported
  64. #define IPSEC_OFFLOAD_AH_TUNNEL 0x00000100 // IPSEC tunnel mode supported
  65. #define IPSEC_OFFLOAD_AH_MD5 0x00000200 // MD5 supported as AH and ESP algo
  66. #define IPSEC_OFFLOAD_AH_SHA_1 0x00000400 // SHA_1 supported as AH and ESP algo
  67. //
  68. // IPSEC ESP Xmit\Recv capabilities
  69. //
  70. #define IPSEC_OFFLOAD_ESP_XMT 0x00000800 // IPSEC supported on Xmit
  71. #define IPSEC_OFFLOAD_ESP_RCV 0x00001000 // IPSEC supported on Rcv
  72. #define IPSEC_OFFLOAD_ESP_TPT 0x00002000 // IPSEC transport mode supported
  73. #define IPSEC_OFFLOAD_ESP_TUNNEL 0x00004000 // IPSEC tunnel mode supported
  74. #define IPSEC_OFFLOAD_ESP_DES 0x00008000 // DES supported as ESP algo
  75. #define IPSEC_OFFLOAD_ESP_DES_40 0x00010000 // DES40 supported as ESP algo
  76. #define IPSEC_OFFLOAD_ESP_3_DES 0x00020000 // 3DES supported as ESP algo
  77. #define IPSEC_OFFLOAD_ESP_NONE 0x00040000 // Null ESP supported as ESP algo
  78. #define IPSEC_OFFLOAD_TPT_UDPESP_IKE 0x00080000
  79. #define IPSEC_OFFLOAD_TUNNEL_UDPESP_IKE 0x00100000
  80. #define IPSEC_OFFLOAD_TPT_OVER_TUNNEL_UDPESP_IKE 0x00200000
  81. #define IPSEC_OFFLOAD_TPT_UDPESP_OVER_PURE_TUNNEL_IKE 0x00400000
  82. #define IPSEC_OFFLOAD_TPT_UDPESP_OTHER 0x00800000
  83. #define IPSEC_OFFLOAD_TUNNEL_UDPESP_OTHER 0x01000000
  84. #define IPSEC_OFFLOAD_TPT_OVER_TUNNEL_UDPESP_OTHER 0x02000000
  85. #define IPSEC_OFFLOAD_TPT_UDPESP_OVER_PURE_TUNNEL_OTHER 0x04000000
  86. #define PROTOCOL_ANY 0
  87. // IP interface characteristics
  88. #define IF_FLAGS_P2P 1 // Point to point interface
  89. #define IF_FLAGS_DELETING 2 // Interface is in the process of going away
  90. #define IF_FLAGS_NOIPADDR 4 // unnumbered interface
  91. #define IF_FLAGS_P2MP 8 // Point to multi-point
  92. #define IF_FLAGS_REMOVING_POWER 0x10 // interface power is about to go away.
  93. #define IF_FLAGS_POWER_DOWN 0x20 // interface power is gone.
  94. #define IF_FLAGS_REMOVING_DEVICE 0x40 // query remove was indicated to us.
  95. #define IF_FLAGS_NOLINKBCST 0x80 // Needed for P2MP
  96. #define IF_FLAGS_UNI 0x100 // Uni-direction interface.
  97. #define IF_FLAGS_MEDIASENSE 0x200 // Indicates mediasense enabled on IF.
  98. typedef enum _IP_DF_ENCAP {
  99. CopyDfEncap,
  100. DefaultDfEncap = CopyDfEncap,
  101. SetDfEncap,
  102. ClearDfEncap,
  103. MaxDfEncap
  104. } IP_DF_ENCAP, *PIP_DF_ENCAP;
  105. //* IP Header format.
  106. typedef struct IPHeader {
  107. uchar iph_verlen; // Version and length.
  108. uchar iph_tos; // Type of service.
  109. ushort iph_length; // Total length of datagram.
  110. ushort iph_id; // Identification.
  111. ushort iph_offset; // Flags and fragment offset.
  112. uchar iph_ttl; // Time to live.
  113. uchar iph_protocol; // Protocol.
  114. ushort iph_xsum; // Header checksum.
  115. IPAddr iph_src; // Source address.
  116. IPAddr iph_dest; // Destination address.
  117. } IPHeader;
  118. /*NOINC*/
  119. #define NULL_IP_ADDR 0
  120. #define IP_ADDR_EQUAL(x,y) ((x) == (y))
  121. #define IP_LOOPBACK_ADDR(x) (((x) & 0xff) == 0x7f)
  122. #define CLASSD_ADDR(a) (( (*((uchar *)&(a))) & 0xf0) == 0xe0)
  123. typedef void *IPContext; // An IP context value.
  124. //* Structure of a route cache entry. A route cache entry functions as a pointer
  125. // to some routing info. There is one per remote destination, and the memory
  126. // is owned by the IP layer.
  127. //
  128. #define RCE_CONTEXT_SIZE (sizeof(void *) * 2) // Right now we use two contexts.
  129. typedef struct RouteCacheEntry {
  130. struct RouteCacheEntry *rce_next; // Next RCE in list.
  131. struct RouteTableEntry *rce_rte; // Back pointer to owning RTE.
  132. IPAddr rce_dest; // Destination address being cached.
  133. IPAddr rce_src; // Source address for this RCE.
  134. uchar rce_flags; // Valid flags.
  135. uchar rce_dtype; // Type of destination address.
  136. uchar rce_TcpDelAckTicks;
  137. uchar rce_TcpAckFrequency;
  138. uint rce_usecnt; // Count of people using it.
  139. uchar rce_context[RCE_CONTEXT_SIZE]; // Space for lower layer context
  140. //
  141. // DEFINE_LOCK_STRUCTURE resolves to NULL on retail builds.
  142. // Moved this down so that debug ARP modules can co-exist with retail IP.
  143. //
  144. DEFINE_LOCK_STRUCTURE(rce_lock) // Lock for this RCE
  145. uint rce_OffloadFlags; // interface chksum capability flags
  146. NDIS_TASK_TCP_LARGE_SEND rce_TcpLargeSend;
  147. uint rce_TcpWindowSize;
  148. uint rce_TcpInitialRTT;
  149. uint rce_cnt;
  150. uint rce_mediaspeed; // for initial options selection.
  151. uint rce_newmtu;
  152. } RouteCacheEntry;
  153. //
  154. // Definiton for a rt table change callout.
  155. // TODO - pass a rt table entry and action - add, delete, update
  156. // In case of delete, it means that this route went away
  157. //
  158. typedef void (*IPRtChangePtr)( VOID );
  159. #define RCE_VALID 0x1
  160. #define RCE_CONNECTED 0x2
  161. #define RCE_REFERENCED 0x4
  162. #define RCE_DEADGW 0x8
  163. #define RCE_LINK_DELETED 0x10
  164. #define RCE_ALL_VALID (RCE_VALID | RCE_CONNECTED | RCE_REFERENCED)
  165. /*INC*/
  166. //* Structure of option info.
  167. typedef struct IPOptInfo {
  168. uchar *ioi_options; // Pointer to options (NULL if none).
  169. IPAddr ioi_addr; // First hop address, if this is source routed.
  170. uchar ioi_optlength; // Length (in bytes) of options.
  171. uchar ioi_ttl; // Time to live of this packet.
  172. uchar ioi_tos; // Type of service for packet.
  173. uchar ioi_flags; // Flags for this packet.
  174. uchar ioi_hdrincl : 1; // use IP header coming from the user
  175. uchar ioi_TcpChksum : 1;
  176. uchar ioi_UdpChksum : 1;
  177. uchar ioi_limitbcasts : 2;
  178. uint ioi_uni; // UN numbered interface index
  179. uint ioi_ucastif; // strong host routing
  180. uint ioi_mcastif; // mcastif on unnumbered interface
  181. int ioi_GPCHandle;
  182. } IPOptInfo;
  183. #define IP_FLAG_SSRR 0x80 // There options have a SSRR in them.
  184. #define IP_FLAG_IPSEC 0x40 // Set if reinjected from IPSEC.
  185. typedef enum _IP_LIMIT_BCASTS {
  186. DisableSendOnSource,
  187. EnableSendOnSource,
  188. OnlySendOnSource
  189. } IP_LIMIT_BCASTS, *PIP_LIMIT_BCASTS;
  190. /*NOINC*/
  191. //* Structure of a packet context.
  192. typedef struct PacketContext {
  193. struct PCCommon {
  194. PNDIS_PACKET pc_link; // Link on chain of packets.
  195. uchar pc_owner; // Owner of packet.
  196. uchar pc_flags; // Flags concerning this packet.
  197. ushort pc_pad; // Pad to 32 bit boundary.
  198. PVOID pc_IpsecCtx; // send complete ctx for IPSEC
  199. } pc_common;
  200. struct BufferReference *pc_br; // Pointer to buffer reference structure.
  201. struct ProtInfo *pc_pi; // Protocol info structure for this packet.
  202. void *pc_context; // Protocol context to be passed back on send cmplt.
  203. struct Interface *pc_if; // Interface this packet was sent on.
  204. PNDIS_BUFFER pc_hdrincl;
  205. PNDIS_BUFFER pc_firewall;
  206. struct IPRcvBuf *pc_firewall2;
  207. struct LinkEntry *pc_iflink;
  208. uchar pc_ipsec_flags; // for ipsec fragment path
  209. } PacketContext;
  210. // Different Modes we pass to ipsetndisrequest
  211. #define CLEAR_IF 0 // clear the option on the netcard plus the interface
  212. #define SET_IF 1 // set the option on the netcard plus the interface
  213. #define CLEAR_CARD 2 // clear the option only on the card
  214. // Flags passed to ipi_checkroute
  215. #define CHECK_RCE_ONLY 0x00000001
  216. //* The structure of configuration information passed to an upper layer.
  217. //
  218. typedef struct IPInfo {
  219. uint ipi_version; // Version of the IP driver.
  220. uint ipi_hsize; // Size of the header.
  221. IP_STATUS (*ipi_xmit)(void *, void *, PNDIS_BUFFER, uint, IPAddr, IPAddr,
  222. IPOptInfo *, RouteCacheEntry *, uchar, IRP *);
  223. void *(*ipi_protreg)(uchar, void *, void *, void *, void *, void *, void *);
  224. IPAddr (*ipi_openrce)(IPAddr, IPAddr, RouteCacheEntry **, uchar *,
  225. ushort *, IPOptInfo *);
  226. void (*ipi_closerce)(RouteCacheEntry *);
  227. uchar (*ipi_getaddrtype)(IPAddr);
  228. uchar (*ipi_getlocalmtu)(IPAddr, ushort *);
  229. IP_STATUS (*ipi_getpinfo)(IPAddr, IPAddr, uint *, uint *, RouteCacheEntry *);
  230. void (*ipi_checkroute)(IPAddr, IPAddr, RouteCacheEntry *, IPOptInfo *, uint);
  231. void (*ipi_initopts)(struct IPOptInfo *);
  232. IP_STATUS (*ipi_updateopts)(struct IPOptInfo *, struct IPOptInfo *, IPAddr, IPAddr);
  233. IP_STATUS (*ipi_copyopts)(uchar *, uint, struct IPOptInfo *);
  234. IP_STATUS (*ipi_freeopts)(struct IPOptInfo *);
  235. long (*ipi_qinfo)(struct TDIObjectID *ID, PNDIS_BUFFER Buffer,
  236. uint *Size, void *Context);
  237. long (*ipi_setinfo)(struct TDIObjectID *ID, void *Buffer, uint Size);
  238. long (*ipi_getelist)(void *, uint *);
  239. IP_STATUS (*ipi_setmcastaddr)(IPAddr, IPAddr, uint, uint, IPAddr *,
  240. uint, IPAddr *);
  241. uint (*ipi_invalidsrc)(IPAddr);
  242. uint (*ipi_isdhcpinterface)(void *IPContext);
  243. ulong (*ipi_setndisrequest)(IPAddr, NDIS_OID, uint, uint);
  244. IP_STATUS (*ipi_largexmit)(void *, void *, PNDIS_BUFFER, uint, IPAddr, IPAddr,
  245. IPOptInfo *, RouteCacheEntry *, uchar,uint *, uint);
  246. ulong (*ipi_absorbrtralert)(IPAddr Addr, uchar Protocol, uint IfIndex);
  247. IPAddr (*ipi_isvalidindex)(uint Index);
  248. uint (*ipi_getifindexfromnte)(void *NTE, uint Capabilities);
  249. BOOLEAN (*ipi_isrtralertpacket)(IPHeader UNALIGNED *Header);
  250. ulong (*ipi_getifindexfromaddr)(IPAddr Addr, uint Capabilities);
  251. void (*ipi_cancelpackets)(void *, void *);
  252. IP_STATUS (*ipi_setmcastinclude)(IPAddr, IPAddr, uint, IPAddr *,
  253. uint, IPAddr *);
  254. IP_STATUS (*ipi_setmcastexclude)(IPAddr, IPAddr, uint, IPAddr *,
  255. uint, IPAddr *);
  256. IPAddr (*ipi_getmcastifaddr)();
  257. ushort (*ipi_getipid)();
  258. void *(*ipi_protdereg)(uchar);
  259. uint (*ipi_getifindexfromindicatecontext)(void *NTE);
  260. } IPInfo;
  261. /*INC*/
  262. #define MCAST_INCLUDE 0
  263. #define MCAST_EXCLUDE 1
  264. #define PACKET_OWNER_LINK 0
  265. #define PACKET_OWNER_IP 1
  266. // Definition of destination types. We use the low bit to indicate that a type is a broadcast
  267. // type. All local types must be less than DEST_REMOTE.
  268. //
  269. // The various bits for this are set as follows:
  270. //
  271. // |--------|
  272. // MOB
  273. //
  274. // B Broadcast bit
  275. // O Offnet bit
  276. // M Multicast bit --> must also have the B bit set
  277. //
  278. #define DEST_LOCAL 0 // Destination is local.
  279. #define DEST_BCAST 1 // Destination is net or local bcast.
  280. #define DEST_SN_BCAST 3 // A subnet bcast.
  281. #define DEST_MCAST 5 // A local mcast.
  282. #define DEST_REMOTE 8 // Destination is remote.
  283. #define DEST_REM_BCAST 11 // Destination is a remote broadcast
  284. #define DEST_REM_MCAST 13 // Destination is a remote mcast.
  285. #define DEST_INVALID 0xff // Invalid destination
  286. #define DEST_PROMIS 32 // Dest is promiscuous(32=0x20)
  287. #define DEST_BCAST_BIT 1
  288. #define DEST_OFFNET_BIT 0x10 // Destination is offnet -
  289. // used only by upper layer
  290. // callers.
  291. #define DEST_MCAST_BIT 5
  292. /*NOINC*/
  293. #define IS_BCAST_DEST(D) ((D) & DEST_BCAST_BIT)
  294. // The following macro is to be used ONLY on the destination returned from
  295. // OpenRCE, and only by upper layer callers.
  296. #define IS_OFFNET_DEST(D) ((D) & DEST_OFFNET_BIT)
  297. #define IS_MCAST_DEST(D) (((D) & DEST_MCAST_BIT) == DEST_MCAST_BIT)
  298. /*INC*/
  299. // Definition of an IP receive buffer chain.
  300. typedef struct IPRcvBuf {
  301. struct IPRcvBuf *ipr_next; // Next buffer descriptor in chain.
  302. uint ipr_owner; // Owner of buffer.
  303. uchar *ipr_buffer; // Pointer to buffer.
  304. uint ipr_size; // Buffer size.
  305. PMDL ipr_pMdl;
  306. uint *ipr_pClientCnt;
  307. uchar *ipr_RcvContext;
  308. uint ipr_RcvOffset;
  309. ulong ipr_flags;
  310. } IPRcvBuf;
  311. #define IPR_OWNER_IP 0
  312. #define IPR_OWNER_ICMP 1
  313. #define IPR_OWNER_UDP 2
  314. #define IPR_OWNER_TCP 3
  315. #define IPR_OWNER_FIREWALL 4
  316. #define IPR_OWNER_STACK 5
  317. #define MIN_FIRST_SIZE 200 // Minimum size of first buffer.
  318. #define IPR_FLAG_PROMISCUOUS 0x00000001
  319. #define IPR_FLAG_CHECKSUM_OFFLOAD 0x00000002
  320. #define IPR_FLAG_IPSEC_TRANSFORMED 0x00000004
  321. #define IPR_FLAG_BUFFER_UNCHANGED 0x00000008
  322. #define IPR_FLAG_LOOPBACK_PACKET 0x00000010
  323. // Flags that characterize receive indications to the transports.
  324. #define IS_BROADCAST 0x01 // Indicates a broadcast packet.
  325. #define IS_BOUND 0x02 // Receive happened on the same
  326. // processor as the previous one.
  327. //* Structure of context info. passed down for query entity list.
  328. typedef struct QEContext {
  329. uint qec_count; // Number of IDs currently in
  330. // buffer.
  331. struct TDIEntityID *qec_buffer; // Pointer to buffer.
  332. } QEContext;
  333. //
  334. // Function to get time ticks value to save in if_lastchange.
  335. //
  336. __inline
  337. ULONG
  338. GetTimeTicks()
  339. {
  340. LARGE_INTEGER Time;
  341. KeQuerySystemTime(&Time);
  342. //
  343. // Convert to 100ns (10^-7 seconds) to centaseconds (10^-2 seconds)
  344. //
  345. Time.QuadPart /= 100000;
  346. //
  347. // Return the result (mod 2^32)
  348. //
  349. return Time.LowPart;
  350. }
  351. //
  352. // Functions exported in NT by the IP driver for use by transport
  353. // layer drivers.
  354. //
  355. IP_STATUS
  356. IPGetInfo(
  357. IPInfo *Buffer,
  358. int Size
  359. );
  360. void *
  361. IPRegisterProtocol(
  362. uchar Protocol,
  363. void *RcvHandler,
  364. void *XmitHandler,
  365. void *StatusHandler,
  366. void *RcvCmpltHandler,
  367. void *PnPHandler,
  368. void *ElistHandler
  369. );
  370. void *
  371. IPDeregisterProtocol(
  372. uchar Protocol
  373. );
  374. #endif // IP_H_INCLUDED