Source code of Windows XP (NT5)
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.

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