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.

535 lines
19 KiB

  1. /*++
  2. Copyright(c) 1998,99 Microsoft Corporation
  3. Module Name:
  4. wlbsip.h
  5. Abstract:
  6. Windows Load Balancing Service (WLBS)
  7. IP/TCP/UDP support
  8. Author:
  9. kyrilf
  10. Environment:
  11. Revision History:
  12. --*/
  13. #ifndef _Tcpip_h_
  14. #define _Tcpip_h_
  15. #ifdef KERNEL_MODE
  16. #include <ndis.h>
  17. #endif
  18. #pragma pack(1)
  19. /* type structures for basic protocols */
  20. typedef struct
  21. {
  22. UCHAR byte [20];
  23. }
  24. IP_HDR, * PIP_HDR;
  25. typedef struct
  26. {
  27. UCHAR byte [24];
  28. }
  29. TCP_HDR, * PTCP_HDR;
  30. typedef struct
  31. {
  32. UCHAR byte [8];
  33. }
  34. UDP_HDR, * PUDP_HDR;
  35. typedef struct
  36. {
  37. UCHAR byte [28];
  38. }
  39. ARP_HDR, * PARP_HDR;
  40. #define TCPIP_BCAST_ADDR 0xffffffff /* IP broadcast address */
  41. #define TCPIP_CLASSC_MASK 0x00ffffff /* IP address Class C mask */
  42. /* protocol type signatures carried in the length field of Ethernet frame */
  43. #define TCPIP_IP_SIG 0x0800 /* IP protocol */
  44. #define TCPIP_ARP_SIG 0x0806 /* ARP/RARP protocol */
  45. /* supported IP version */
  46. #define TCPIP_VERSION 4 /* current IP version */
  47. /* protocol types as encoded in IP header */
  48. #define TCPIP_PROTOCOL_IP 0 /* Internet protocol id */
  49. #define TCPIP_PROTOCOL_ICMP 1 /* Internet control message protocol id */
  50. #define TCPIP_PROTOCOL_IGMP 2 /* Internet gateway message protocol id */
  51. #define TCPIP_PROTOCOL_GGP 3 /* Gateway-gateway protocol id */
  52. #define TCPIP_PROTOCOL_TCP 6 /* Transmission control protocol id */
  53. #define TCPIP_PROTOCOL_EGP 8 /* Exterior gateway protocol id */
  54. #define TCPIP_PROTOCOL_PUP 12 /* PARC universal packet protocol id */
  55. #define TCPIP_PROTOCOL_UDP 17 /* user datagram protocol id */
  56. #define TCPIP_PROTOCOL_HMP 20 /* Host monitoring protocol id */
  57. #define TCPIP_PROTOCOL_XNS_IDP 22 /* Xerox NS IDP protocol id */
  58. #define TCPIP_PROTOCOL_RDP 27 /* Reliable datagram protocol id */
  59. #define TCPIP_PROTOCOL_RVD 66 /* MIT remote virtual disk protocol id */
  60. #define TCPIP_PROTOCOL_RAW_IP 255 /* raw IP protocol id */
  61. #define TCPIP_PROTOCOL_GRE 47 /* PPTP's GRE stream */
  62. #define TCPIP_PROTOCOL_IPSEC1 50 /* IPSEC's data stream */
  63. #define TCPIP_PROTOCOL_IPSEC2 51 /* IPSEC's data stream */
  64. #define IP_ADDR_LEN 4 /* in bytes */
  65. #if defined (NLB_SESSION_SUPPORT)
  66. /* Stolen from net\ipsec\oakley\ikedef.h and net\ipsec\oakley\isakmp.h. */
  67. #if defined (SBH)
  68. #define COOKIE_LEN 8
  69. typedef struct isakmp_hdr_ {
  70. unsigned char init_cookie[COOKIE_LEN];
  71. unsigned char resp_cookie[COOKIE_LEN];
  72. unsigned char next_payload;
  73. #ifdef ISAKMP_i386
  74. unsigned char minver:4,
  75. majver:4;
  76. #else
  77. unsigned char majver:4,
  78. minver:4;
  79. #endif
  80. unsigned char exch;
  81. unsigned char flags;
  82. unsigned long mess_id;
  83. unsigned long len;
  84. } isakmp_hdr;
  85. typedef struct generic_payload_ {
  86. unsigned char next_payload;
  87. unsigned char reserved;
  88. unsigned short payload_len;
  89. } generic_payload;
  90. typedef struct vendor_payload_ {
  91. unsigned char next_payload;
  92. unsigned char reserved;
  93. unsigned short payload_len;
  94. unsigned char vendor_id[1];
  95. } generic_payload;
  96. typedef struct notify_payload_ {
  97. unsigned char next_payload;
  98. unsigned char reserved;
  99. unsigned short payload_len;
  100. unsigned long doi;
  101. unsigned char protocol_id;
  102. unsigned char spi_size;
  103. unsigned short notify_message;
  104. }
  105. #endif
  106. /* IPSec/IKE header macros. */
  107. #define IPSEC_ISAKMP_SA 1
  108. #define IPSEC_ISAKMP_VENDOR_ID 13
  109. #define IPSEC_ISAKMP_NOTIFY 11
  110. #define IPSEC_ISAKMP_MAIN_MODE_RCOOKIE {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
  111. #define IPSEC_ISAKMP_ENCAPSULATED_IPSEC_ICOOKIE {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
  112. #define IPSEC_ISAKMP_HEADER_LENGTH 28
  113. #define IPSEC_ISAKMP_HEADER_ICOOKIE_OFFSET 0
  114. #define IPSEC_ISAKMP_HEADER_ICOOKIE_LENGTH 8
  115. #define IPSEC_ISAKMP_HEADER_RCOOKIE_OFFSET 8
  116. #define IPSEC_ISAKMP_HEADER_RCOOKIE_LENGTH 8
  117. #define IPSEC_ISAKMP_HEADER_NEXT_PAYLOAD_OFFSET 16
  118. #define IPSEC_ISAKMP_HEADER_PACKET_LENGTH_OFFSET 24
  119. typedef struct {
  120. UCHAR byte[IPSEC_ISAKMP_HEADER_LENGTH];
  121. } IPSEC_ISAKMP_HDR, * PIPSEC_ISAKMP_HDR;
  122. #define IPSEC_ISAKMP_GET_ICOOKIE_POINTER(isakmp_hdrp) ((PUCHAR)isakmp_hdrp + IPSEC_ISAKMP_HEADER_ICOOKIE_OFFSET)
  123. #define IPSEC_ISAKMP_GET_RCOOKIE_POINTER(isakmp_hdrp) ((PUCHAR)isakmp_hdrp + IPSEC_ISAKMP_HEADER_RCOOKIE_OFFSET)
  124. #define IPSEC_ISAKMP_GET_NEXT_PAYLOAD(isakmp_hdrp) ((UCHAR)((isakmp_hdrp)->byte[IPSEC_ISAKMP_HEADER_NEXT_PAYLOAD_OFFSET]))
  125. #define IPSEC_ISAKMP_GET_PACKET_LENGTH(isakmp_hdrp) ((ULONG)(((isakmp_hdrp)->byte[IPSEC_ISAKMP_HEADER_PACKET_LENGTH_OFFSET] << 24) | \
  126. ((isakmp_hdrp)->byte[IPSEC_ISAKMP_HEADER_PACKET_LENGTH_OFFSET + 1] << 16) | \
  127. ((isakmp_hdrp)->byte[IPSEC_ISAKMP_HEADER_PACKET_LENGTH_OFFSET + 2] << 8) | \
  128. ((isakmp_hdrp)->byte[IPSEC_ISAKMP_HEADER_PACKET_LENGTH_OFFSET + 3] << 0)))
  129. #define IPSEC_GENERIC_HEADER_LENGTH 4
  130. #define IPSEC_GENERIC_HEADER_NEXT_PAYLOAD_OFFSET 0
  131. #define IPSEC_GENERIC_HEADER_PAYLOAD_LENGTH_OFFSET 2
  132. typedef struct {
  133. UCHAR byte[IPSEC_GENERIC_HEADER_LENGTH];
  134. } IPSEC_GENERIC_HDR, * PIPSEC_GENERIC_HDR;
  135. #define IPSEC_GENERIC_GET_NEXT_PAYLOAD(generic_hdrp) ((UCHAR)((generic_hdrp)->byte[IPSEC_GENERIC_HEADER_NEXT_PAYLOAD_OFFSET]))
  136. #define IPSEC_GENERIC_GET_PAYLOAD_LENGTH(generic_hdrp) ((USHORT)(((generic_hdrp)->byte[IPSEC_GENERIC_HEADER_PAYLOAD_LENGTH_OFFSET] << 8) | \
  137. ((generic_hdrp)->byte[IPSEC_GENERIC_HEADER_PAYLOAD_LENGTH_OFFSET + 1] << 0)))
  138. #define IPSEC_VENDOR_ID_MICROSOFT {0x1E, 0x2B, 0x51, 0x69, 0x05, 0x99, 0x1C, 0x7D, 0x7C, 0x96, 0xFC, 0xBF, 0xB5, 0x87, 0xE4, 0x61}
  139. #define IPSEC_VENDOR_ID_MICROSOFT_MIN_VERSION 0x00000004
  140. #define IPSEC_VENDOR_ID_PAYLOAD_LENGTH 20
  141. #define IPSEC_VENDOR_HEADER_VENDOR_ID_OFFSET 4
  142. #define IPSEC_VENDOR_HEADER_VENDOR_ID_LENGTH 16
  143. #define IPSEC_VENDOR_HEADER_VENDOR_VERSION_OFFSET 20
  144. #define IPSEC_VENDOR_HEADER_VENDOR_VERSION_LENGTH 4
  145. typedef struct {
  146. UCHAR byte[IPSEC_GENERIC_HEADER_LENGTH + IPSEC_VENDOR_ID_PAYLOAD_LENGTH];
  147. } IPSEC_VENDOR_HDR, * PIPSEC_VENDOR_HDR;
  148. #define IPSEC_VENDOR_ID_GET_ID_POINTER(vendor_hdrp) ((PUCHAR)vendor_hdrp + IPSEC_VENDOR_HEADER_VENDOR_ID_OFFSET)
  149. #define IPSEC_VENDOR_ID_GET_VERSION(vendor_hdrp) ((ULONG)(((vendor_hdrp)->byte[IPSEC_VENDOR_HEADER_VENDOR_VERSION_OFFSET] << 24) | \
  150. ((vendor_hdrp)->byte[IPSEC_VENDOR_HEADER_VENDOR_VERSION_OFFSET + 1] << 16) | \
  151. ((vendor_hdrp)->byte[IPSEC_VENDOR_HEADER_VENDOR_VERSION_OFFSET + 2] << 8) | \
  152. ((vendor_hdrp)->byte[IPSEC_VENDOR_HEADER_VENDOR_VERSION_OFFSET + 3] << 0)))
  153. #define IPSEC_NOTIFY_INITIAL_CONTACT 24578
  154. #define IPSEC_NOTIFY_PAYLOAD_LENGTH 8
  155. #define IPSEC_NOTIFY_HEADER_NOTIFY_MESSAGE_OFFSET 10
  156. typedef struct {
  157. UCHAR byte[IPSEC_GENERIC_HEADER_LENGTH + IPSEC_NOTIFY_PAYLOAD_LENGTH];
  158. } IPSEC_NOTIFY_HDR, * PIPSEC_NOTIFY_HDR;
  159. #define IPSEC_NOTIFY_GET_NOTIFY_MESSAGE(notify_hdrp) ((USHORT)(((notify_hdrp)->byte[IPSEC_NOTIFY_HEADER_NOTIFY_MESSAGE_OFFSET] << 8) | \
  160. ((notify_hdrp)->byte[IPSEC_NOTIFY_HEADER_NOTIFY_MESSAGE_OFFSET + 1] << 0)))
  161. #endif
  162. /* ARP header macros - note address locations assume 6 byte MAC (Ethernet)
  163. and 4 byte protocol (IP) sizes */
  164. /* type of hardware address */
  165. #define ARP_GET_MAC_TYPE(p) (((ULONG) ((p) -> byte[0]) << 8) | (ULONG) ((p) -> byte[1]))
  166. /* higher layer addressing protocol */
  167. #define ARP_GET_PROT_TYPE(p) (((ULONG) ((p) -> byte[2]) << 8) | (ULONG) ((p) -> byte[3]))
  168. /* length of hardware address */
  169. #define ARP_GET_MAC_LEN(p) ((ULONG) ((p) -> byte[4]))
  170. /* length of higher layer address */
  171. #define ARP_GET_PROT_LEN(p) ((ULONG) ((p) -> byte[5]))
  172. /* type of message */
  173. #define ARP_GET_MSG_TYPE(p) (((ULONG) ((p) -> byte[6]) << 8) | (ULONG) ((p) -> byte[7]))
  174. /* source hardware address */
  175. #define ARP_GET_SRC_MAC_PTR(p) (&((p) -> byte[8]))
  176. #define ARP_GET_SRC_MAC(p,n) ((ULONG) ((p) -> byte[8 + (n)]))
  177. /* source higher layer address */
  178. #define ARP_GET_SRC_PROT(p,n) ((ULONG) ((p) -> byte[14 + (n)]))
  179. #define ARP_GET_SRC_FPROT(p) (* ((PULONG) &((p) -> byte[14])))
  180. /* 64-bit -- ramkrish */
  181. #define ARP_GET_SRC_PROT_64(p) ((ULONG) (((p) -> byte[14] << 0) | ((p) -> byte[15] << 8) | \
  182. ((p) -> byte[16] << 16) | ((p) -> byte[17] << 24)))
  183. /* destination hardware address */
  184. #define ARP_GET_DST_MAC_PTR(p) (&((p) -> byte[18]))
  185. #define ARP_GET_DST_MAC(p,n) ((ULONG) ((p) -> byte[18 + (n)]))
  186. /* destination higher layer address */
  187. #define ARP_GET_DST_PROT(p,n) ((ULONG) ((p) -> byte[24 + (n)]))
  188. #define ARP_GET_DST_FPROT(p) (* ((PULONG) &((p) -> byte[24])))
  189. /* 64-bit -- ramkrish */
  190. #define ARP_GET_DST_PROT_64(p) ((ULONG) (((p) -> byte[18] << 0) | ((p) -> byte[19] << 8) | \
  191. ((p) -> byte[20] << 16) | ((p) -> byte[21] << 24)))
  192. #define ARP_MAC_TYPE_ETH 0x0001
  193. #define ARP_PROT_TYPE_IP 0x0800
  194. #define ARP_MAC_LEN_ETH 6
  195. #define ARP_PROT_LEN_IP 4
  196. #define ARP_MSG_TYPE_REQ 0x1
  197. #define ARP_MSG_TYPE_RSP 0x2
  198. /* IP datagram header macros */
  199. /* IP version number */
  200. #define IP_GET_VERS(p) ((ULONG) ((((p) -> byte[0]) >> 4) & 0xf))
  201. /* header length in 32-bit words */
  202. #define IP_GET_HLEN(p) ((ULONG) (((p) -> byte[0]) & 0xf))
  203. /* service type */
  204. #define IP_GET_SRVC(p) ((ULONG) ((p) -> byte[1]))
  205. /* total datagram packet length in bytes */
  206. #define IP_GET_PLEN(p) (((ULONG) ((p) -> byte[2]) << 8) | (ULONG) ((p) -> byte[3]))
  207. /* fragmentation identification - this one seems to have bytes swaped within
  208. the short word ??? */
  209. #define IP_GET_FRAG_ID(p) (((ULONG) ((p) -> byte[5]) << 8) | (ULONG) ((p) -> byte[4]))
  210. /* fragmentation flags */
  211. #define IP_GET_FRAG_FLGS(p) ((ULONG) ((((p) -> byte[6]) >> 5) & 0x7))
  212. /* fragmentation offset */
  213. #define IP_GET_FRAG_OFF(p) (((ULONG) ((p) -> byte[6] & 0x1f) << 8) | (ULONG) ((p) -> byte[7]))
  214. /* Time To Live in seconds */
  215. #define IP_GET_TTL(p) ((ULONG) ((p) -> byte[8]))
  216. /* higher level protocol id */
  217. #define IP_GET_PROT(p) ((ULONG) ((p) -> byte[9]))
  218. /* header checksum - this one seems to have bytes swaped within
  219. the short word ??? */
  220. #define IP_GET_CHKSUM(p) (((USHORT) ((p) -> byte[10]) << 8) | (USHORT) ((p) -> byte[11]))
  221. #define IP_SET_CHKSUM(p,c) (((p) -> byte[10] = (c) >> 8), ((p) -> byte[11] = (c) & 0xff))
  222. /* source IP address */
  223. #define IP_GET_SRC_ADDR(p,n) ((ULONG) ((p) -> byte[12 + (n)]))
  224. #define IP_GET_SRC_ADDR_PTR(p) (&((p) -> byte[12]))
  225. #define IP_GET_SRC_FADDR(p) (* ((PULONG) &((p) -> byte[12]))) /* 64-bit -- ramkrish */
  226. #ifdef _WIN64
  227. #define IP_GET_SRC_ADDR_64(p) ((ULONG) (((p) -> byte[12] << 0) | ((p) -> byte[13] << 8) | \
  228. ((p) -> byte[14] << 16) | ((p) -> byte[15] << 24)))
  229. #else
  230. // This is faster than the one above. This function is called in critical receiving path
  231. #define IP_GET_SRC_ADDR_64(p) (* ((PULONG) &((p) -> byte[12])))
  232. #endif
  233. /* destination IP address */
  234. #define IP_GET_DST_ADDR(p,n) ((ULONG) ((p) -> byte[16 + (n)]))
  235. #ifdef _WIN64
  236. #define IP_GET_DST_ADDR_64(p) ((ULONG) (((p) -> byte[16] << 0) | ((p) -> byte[17] << 8) | \
  237. ((p) -> byte[18] << 16) | ((p) -> byte[19] << 24)))
  238. #else
  239. // This is faster than the one above. This function is called in critical receiving path
  240. #define IP_GET_DST_ADDR_64(p) (* ((PULONG) &((p) -> byte[16])))
  241. #endif
  242. /* 64-bit -- ramkrish */
  243. #define IP_SET_SRC_ADDR_64(p,c) { \
  244. PUCHAR tmp = (PUCHAR) (&(c)); \
  245. (p) -> byte[12] = tmp[0]; (p) -> byte[13] = tmp[1]; \
  246. (p) -> byte[14] = tmp[2]; (p) -> byte[15] = tmp[3]; \
  247. }
  248. #define IP_SET_DST_ADDR_64(p,c) { \
  249. PUCHAR tmp = (PUCHAR) (&(c)); \
  250. (p) -> byte[16] = tmp[0]; (p) -> byte[17] = tmp[1]; \
  251. (p) -> byte[18] = tmp[2]; (p) -> byte[19] = tmp[3]; \
  252. }
  253. /* create IP address from 4 bytes */
  254. #define IP_SET_ADDR(p,b0,b1,b2,b3) (* (p) = (((b0) << 0) | ((b1) << 8) | ((b2) << 16) | ((b3) << 24)))
  255. /* compute broadcast address from IP address and netmask */
  256. #define IP_SET_BCAST(p,a,m) (* (p) = ((a) & (m)) | (~(m)))
  257. /* TCP header macros */
  258. /* pointer to TCP header from IP header pointer */
  259. #define TCP_PTR(p) ((PTCP_HDR)(((ULONG *)(p)) + ((ULONG)IP_GET_HLEN(p))))
  260. /* source port */
  261. #define TCP_GET_SRC_PORT(p) (((ULONG) ((p) -> byte[0]) << 8) | (ULONG) ((p) -> byte[1]))
  262. #define TCP_GET_SRC_PORT_PTR(p) (& ((p) -> byte[0])) /* 64-bit -- ramkrish */
  263. /* destination port */
  264. #define TCP_GET_DST_PORT(p) (((ULONG) ((p) -> byte[2]) << 8) | (ULONG) ((p) -> byte[3]))
  265. #define TCP_GET_DST_PORT_PTR(p) (& ((p) -> byte[2])) /* 64-bit -- ramkrish */
  266. /* sequence number */
  267. #define TCP_GET_SEQ_NO(p) (((ULONG) ((p) -> byte[4]) << 24) | ((ULONG) ((p) -> byte[5]) << 16) | \
  268. ((ULONG) ((p) -> byte[6]) << 8) | (ULONG) ((p) -> byte[7]))
  269. /* acknowledgement number */
  270. #define TCP_GET_ACK_NO(p) (((ULONG) ((p) -> byte[8]) << 24) | ((ULONG) ((p) -> byte[9]) << 16) | \
  271. ((ULONG) ((p) -> byte[10]) << 8) | (ULONG) ((p) -> byte[11]))
  272. /* flags */
  273. #define TCP_GET_FLAGS(p) (((ULONG) ((p) -> byte[13])) & 0x3f)
  274. /* header length in 32-bit words */
  275. #define TCP_GET_HLEN(p) ((ULONG) (((p) -> byte[12]) >> 4))
  276. /* datagram length */
  277. #define TCP_GET_DGRAM_LEN(i,t) (IP_GET_PLEN (i) - ((IP_GET_HLEN (i) + TCP_GET_HLEN (t)) * sizeof (ULONG)))
  278. /* pointer to datagram */
  279. #define TCP_GET_DGRAM_PTR(p) ((PUCHAR)(((ULONG *)(p)) + ((ULONG) TCP_GET_HLEN(p))))
  280. /* checksum field */
  281. #define TCP_GET_CHKSUM(p) ((((USHORT)((p) -> byte[16])) << 8) | (USHORT)((p) -> byte[17]))
  282. #define TCP_SET_CHKSUM(p,c) (((p) -> byte[16] = (c) >> 8), ((p) -> byte[17] = (c) & 0xff))
  283. #define TCP_FLAG_URG 0x20
  284. #define TCP_FLAG_ACK 0x10
  285. #define TCP_FLAG_PSH 0x8
  286. #define TCP_FLAG_RST 0x4
  287. #define TCP_FLAG_SYN 0x2
  288. #define TCP_FLAG_FIN 0x1
  289. /* UDP header macros */
  290. /* pointer to TCP header from IP header pointer */
  291. #define UDP_PTR(p) ((PUDP_HDR)(((ULONG *)(p)) + ((ULONG)IP_GET_HLEN(p))))
  292. /* source port */
  293. #define UDP_GET_SRC_PORT(p) (((ULONG) ((p) -> byte[0]) << 8) | (ULONG) ((p) -> byte[1]))
  294. #define UDP_GET_SRC_PORT_PTR(p) (& ((p) -> byte[0]))
  295. #define UDP_GET_SRC_FPORT(p) (* ((PUSHORT) &((p) -> byte[0])))
  296. /* 64-bit -- ramkrish */
  297. #define UDP_SET_SRC_PORT_64(p,v) (((p) -> byte[0] = v >> 8), ((p) -> byte[1] = v & 0xff))
  298. /* destination port */
  299. #define UDP_GET_DST_PORT(p) (((ULONG) ((p) -> byte[2]) << 8) | (ULONG) ((p) -> byte[3]))
  300. #define UDP_GET_DST_PORT_PTR(p) (& ((p) -> byte[2]))
  301. #define UDP_GET_DST_FPORT(p) (* ((PUSHORT) &((p) -> byte[2])))
  302. /* 64-bit -- ramkrish */
  303. #define UDP_SET_DST_PORT_64(p,v) (((p) -> byte[2] = v >> 8), ((p) -> byte[3] = v & 0xff))
  304. /* packet length */
  305. #define UDP_GET_LEN(p) (((ULONG) ((p) -> byte[4]) << 8) | (ULONG) ((p) -> byte[5]))
  306. /* packet length */
  307. #define UDP_GET_CHKSUM(p) (((USHORT) ((p) -> byte[6]) << 8) | (USHORT) ((p) -> byte[7]))
  308. #define UDP_SET_CHKSUM(p,c) (((p) -> byte[6] = (c) >> 8), ((p) -> byte[7] = (c) & 0xff))
  309. /* pointer to datagram */
  310. #define UDP_GET_DGRAM_PTR(p) ((PUCHAR)(p) + sizeof (UDP_HDR))
  311. /* V1.11 NetBIOS name cluster name support */
  312. #define NBT_NAME_LEN 16
  313. #define NBT_ENCODED_NAME_LEN (2 * NBT_NAME_LEN) /* multiplier HAS to be 2 */
  314. #define NBT_ENCODED_NAME_BASE 'A'
  315. #define NBT_NAME_SHADOW "*SMBSERVER "
  316. #define NBT_ENCODED_NAME_SHADOW \
  317. { \
  318. 'C', 'K', 'F', 'D', 'E', 'N', 'E', 'C', 'F', 'D', 'E', 'F', 'F', 'C', 'F', 'G', \
  319. 'E', 'F', 'F', 'C', 'C', 'A', 'C', 'A', 'C', 'A', 'C', 'A', 'C', 'A', 'C', 'A' \
  320. }
  321. #define NBT_ENCODE_FIRST(c) (((c) >> 4) + NBT_ENCODED_NAME_BASE)
  322. #define NBT_ENCODE_SECOND(c) (((c) & 0xf) + NBT_ENCODED_NAME_BASE)
  323. #define NBT_SESSION_PORT 139
  324. #define NBT_SESSION_REQUEST 0x81 /* packet type */
  325. typedef struct
  326. {
  327. UCHAR byte[72]; /* only the session request packet */
  328. }
  329. NBT_HDR, * PNBT_HDR;
  330. /* pointer to NBT header from TCP header */
  331. #define NBT_PTR(p) ((PNBT_HDR)(((ULONG *)(p)) + ((ULONG) TCP_GET_HLEN(p))))
  332. /* packet type */
  333. #define NBT_GET_PKT_TYPE(p) ((ULONG) ((p) -> byte[0]))
  334. /* packet length */
  335. #define NBT_GET_PKT_LEN(p) ((ULONG) ((p) -> byte[3]))
  336. /* called name */
  337. #define NBT_GET_CALLED_NAME(p) ((PUCHAR) & ((p) -> byte[4])) /* server's name */
  338. /* calling name */
  339. #define NBT_GET_CALLING_NAME(p) ((PUCHAR) & ((p) -> byte[36])) /* client's name */
  340. /* PPTP/IPSEC support */
  341. #define PPTP_CTRL_PORT 1723
  342. #define IPSEC_CTRL_PORT 500
  343. #pragma pack()
  344. /* TCPIP module context */
  345. typedef struct
  346. {
  347. UCHAR nbt_encoded_cluster_name [NBT_ENCODED_NAME_LEN]; /* V1.2 */
  348. }
  349. TCPIP_CTXT, * PTCPIP_CTXT;
  350. /* PROCEDURES */
  351. extern BOOLEAN Tcpip_init (
  352. PTCPIP_CTXT ctxtp,
  353. PVOID params);
  354. /*
  355. Initialize module
  356. returns BOOLEAN:
  357. TRUE => success
  358. FALSE => failure
  359. function:
  360. */
  361. extern VOID Tcpip_nbt_handle (
  362. PTCPIP_CTXT ctxtp,
  363. PIP_HDR ip_hdrp,
  364. PTCP_HDR tcp_hdrp,
  365. ULONG len,
  366. PNBT_HDR nbt_hdrp);
  367. /*
  368. Process NBT header and mask cluster name with shadow name
  369. returns VOID:
  370. function:
  371. */
  372. extern USHORT Tcpip_chksum (
  373. PTCPIP_CTXT ctxtp,
  374. PIP_HDR ip_hdrp,
  375. PUCHAR prot_hdrp,
  376. ULONG prot);
  377. /*
  378. Produce IP, TCP or UDL checksums for specified protocol header
  379. returns USHORT:
  380. <checksum>
  381. function:
  382. */
  383. #endif /* _Tcpip_h_ */