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.

267 lines
6.3 KiB

  1. //=============================================================================
  2. // Copyright (c) 1997 Microsoft Corporation
  3. //
  4. // File: packet.c
  5. //
  6. // Abstract:
  7. // This module contains declarations for packet.c
  8. //
  9. // Author: K.S.Lokesh (lokeshs@) 11-1-97
  10. //
  11. // Revision History:
  12. //=============================================================================
  13. #ifndef _PACKET_H_
  14. #define _PACKET_H_
  15. DWORD
  16. SendPacket (
  17. PIF_TABLE_ENTRY pite,
  18. PGI_ENTRY pgie,
  19. DWORD PacketType, //MSG_GEN_QUERY, MSG_GROUP_QUERY_V2(v3),SOURCES_Q
  20. DWORD Group //destination McastGrp
  21. );
  22. DWORD
  23. JoinMulticastGroup (
  24. SOCKET Sock,
  25. DWORD dwGroup,
  26. DWORD IfIndex,
  27. DWORD dwIpAddr,
  28. IPADDR Source
  29. );
  30. DWORD
  31. LeaveMulticastGroup (
  32. SOCKET Sock,
  33. DWORD dwGroup,
  34. DWORD IfIndex,
  35. DWORD dwIpAddr,
  36. IPADDR Source
  37. );
  38. DWORD
  39. BlockSource (
  40. SOCKET Sock,
  41. DWORD dwGroup,
  42. DWORD IfIndex,
  43. IPADDR IpAddr,
  44. IPADDR Source
  45. );
  46. DWORD
  47. UnBlockSource (
  48. SOCKET Sock,
  49. DWORD dwGroup,
  50. DWORD IfIndex,
  51. IPADDR IpAddr,
  52. IPADDR Source
  53. );
  54. DWORD
  55. McastSetTtl(
  56. SOCKET sock,
  57. UCHAR ttl
  58. );
  59. //
  60. // packet context struct
  61. //
  62. typedef struct _PACKET_CONTEXT {
  63. DWORD IfIndex;
  64. DWORD DstnMcastAddr;
  65. DWORD InputSrc;
  66. DWORD Length;
  67. DWORD Flags;
  68. BYTE Packet[1];
  69. } PACKET_CONTEXT, *PPACKET_CONTEXT;
  70. #define CREATE_PACKET_CONTEXT(ptr, pktLen, Error) {\
  71. ptr = IGMP_ALLOC(sizeof(PACKET_CONTEXT)+(pktLen)-1,0xa0000,0xaaaa);\
  72. if (ptr==NULL) { \
  73. Error = ERROR_NOT_ENOUGH_MEMORY; \
  74. Trace2(ANY, "Error %d allocating %d bytes for Work context", \
  75. Error, sizeof(PACKET_CONTEXT)+(pktLen)-1); \
  76. Logerr0(HEAP_ALLOC_FAILED, Error); \
  77. } \
  78. }
  79. #pragma pack(1)
  80. // Structure of an IGMP header.
  81. typedef struct _IGMP_HEADER {
  82. UCHAR Vertype; // Type of igmp message
  83. UCHAR ResponseTime; // max. resp. time for igmpv2 messages; will be 0
  84. USHORT Xsum;
  85. union {
  86. DWORD Group;
  87. struct {
  88. USHORT Reserved;
  89. USHORT NumGroupRecords;
  90. };
  91. };
  92. } IGMP_HEADER, *PIGMP_HEADER;
  93. #define MIN_PACKET_SIZE sizeof(IGMP_HEADER)
  94. #define INPUT_PACKET_SZ 1000
  95. #define IPVERSION 4
  96. typedef struct _IGMP_HEADER_V3_EXT {
  97. BYTE QRV :3;
  98. BYTE SFlag :1;
  99. BYTE Reserved :4;
  100. BYTE QQIC;
  101. USHORT NumSources;
  102. IPADDR Sources[0];
  103. } IGMP_HEADER_V3_EXT, *PIGMP_HEADER_V3_EXT;
  104. #define GET_QQIC_FROM_CODE(qqic) qqic <= 127? qqic : ((qqic&0x0f) + 16) << ((qqic&0x70) + 3)
  105. //
  106. // GROUP_RECORD
  107. //
  108. typedef struct _GROUP_RECORD {
  109. UCHAR RecordType;
  110. UCHAR AuxDataLength;
  111. USHORT NumSources;
  112. IPADDR Group;
  113. IPADDR Sources[0];
  114. } GROUP_RECORD, *PGROUP_RECORD;
  115. #define GET_GROUP_RECORD_SIZE(pGroupRecord) \
  116. (pGroupRecord->NumSources+2)*sizeof(IPADDR))
  117. #define GET_FIRST_GROUP_RECORD(pHdr) \
  118. (PGROUP_RECORD)((PCHAR)(pHdr)+MIN_PACKET_SIZE)
  119. #define GET_NEXT_GROUP_RECORD(pGroupRecord) \
  120. ((PGROUP_RECORD) ((UCHAR)pGroupRecord + \
  121. GET_GROUP_RECORD_SIZE(pGroupRecord)))
  122. #define IS_IN 1
  123. #define IS_EX 2
  124. #define TO_IN 3
  125. #define TO_EX 4
  126. #define ALLOW 5
  127. #define BLOCK 6
  128. typedef struct _IP_HEADER {
  129. UCHAR Hl; // Version and length.
  130. UCHAR Tos; // Type of service.
  131. USHORT Len; // Total length of datagram.
  132. USHORT Id; // Identification.
  133. USHORT Offset; // Flags and fragment offset.
  134. UCHAR Ttl; // Time to live.
  135. UCHAR Protocol; // Protocol.
  136. USHORT Xsum; // Header checksum.
  137. struct in_addr Src; // Source address.
  138. struct in_addr Dstn; // Destination address.
  139. } IP_HEADER, *PIP_HEADER;
  140. #pragma pack()
  141. //
  142. // MACROS
  143. //
  144. //
  145. // message types// work types
  146. //
  147. #define MSG_GEN_QUERY 1
  148. #define MSG_GROUP_QUERY_V2 2
  149. #define MSG_REPORT 3
  150. #define MSG_LEAVE 4
  151. #define MSG_SOURCES_QUERY 5
  152. #define MSG_GROUP_QUERY_V3 6
  153. #define DELETE_MEMBERSHIP 11
  154. #define DELETE_SOURCE 12
  155. #define SHIFT_TO_V3 13
  156. #define MOVE_SOURCE_TO_EXCL 14
  157. #define PROXY_PRUNE 100
  158. #define PROXY_JOIN 101
  159. //
  160. // igmp type field
  161. //
  162. #define IGMP_QUERY 0x11 //Membership query
  163. #define IGMP_REPORT_V1 0x12 //Version 1 membership report
  164. #define IGMP_REPORT_V2 0x16 //Version 2 membership report
  165. #define IGMP_LEAVE 0x17 //Leave Group
  166. #define IGMP_REPORT_V3 0x22 //Version 3 membership report
  167. //
  168. // igmp version
  169. //
  170. #define IGMPV1 2 //IGMP version 1
  171. #define IGMPV2 3 //IGMP version 2
  172. //
  173. // igmp multicast groups
  174. //
  175. #define ALL_HOSTS_MCAST 0x010000E0
  176. #define ALL_ROUTERS_MCAST 0x020000E0
  177. #define ALL_IGMP_ROUTERS_MCAST 0x160000E0
  178. //
  179. // message macros
  180. //
  181. #define SEND_GEN_QUERY(pite) \
  182. SendPacket(pite, NULL, MSG_GEN_QUERY, 0)
  183. #define SEND_GROUP_QUERY_V2(pite, pgie, Group) \
  184. SendPacket(pite, pgie, MSG_GROUP_QUERY_V2, Group)
  185. #define SEND_GROUP_QUERY_V3(pite, pgie, Group) \
  186. SendPacket(pite, pgie, MSG_GROUP_QUERY_V3, Group)
  187. #define SEND_SOURCES_QUERY(pgie) \
  188. SendPacket((pgie)->pIfTableEntry, pgie, MSG_SOURCES_QUERY, (pgie)->pGroupTableEntry->Group)
  189. // 224.0.0.0 < group <240.0.0.0
  190. //
  191. #define IS_MCAST_ADDR(Group) \
  192. ( (0x000000E0!=(Group)) \
  193. && (0x000000E0 <= ((Group)&0x000000FF) ) \
  194. && (0x000000F0 > ((Group)&0x000000FF) ) )
  195. //
  196. // is the group 224.0.0.x
  197. //
  198. #define LOCAL_MCAST_GROUP(Group) \
  199. (((Group)&0x00FFFFFF) == 0x000000E0)
  200. #define SSM_MCAST_GROUP(Group) \
  201. (((Group)&0x000000FF) == 0x000000E8)
  202. USHORT
  203. xsum(
  204. PVOID Buffer,
  205. INT Size
  206. );
  207. #endif //_PACKET_H_