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.

333 lines
6.9 KiB

  1. //============================================================================
  2. // Copyright (c) 1995, Microsoft Corporation
  3. //
  4. // File: riptest.h
  5. //
  6. // History:
  7. // Abolade Gbadegesin Oct-16-1995 Created
  8. //
  9. // Declarations for the RIP test program.
  10. //============================================================================
  11. //
  12. // These strings are used to access the registry
  13. //
  14. #define STR_SERVICES "System\\CurrentControlSet\\Services\\"
  15. #define STR_RIPTEST "RipTest"
  16. #define STR_PARAMSTCP "\\Parameters\\Tcpip"
  17. #define STR_ENABLEDHCP "EnableDhcp"
  18. #define STR_ADDRESS "IPAddress"
  19. #define STR_NETMASK "SubnetMask"
  20. #define STR_DHCPADDR "DhcpIPAddress"
  21. #define STR_DHCPMASK "DhcpSubnetMask"
  22. #define STR_ROUTECOUNT "RouteCount"
  23. #define STR_ROUTESTART "RouteStart"
  24. #define STR_ROUTEMASK "RouteMask"
  25. #define STR_ROUTENEXTHOP "RouteNexthop"
  26. #define STR_ROUTETAG "RouteTag"
  27. #define STR_ROUTETARGET "RouteTarget"
  28. #define STR_ROUTETIMEOUT "RouteTimeout"
  29. #define STR_PACKETVERSION "PacketVersion"
  30. #define STR_PACKETENTRYCOUNT "PacketEntryCount"
  31. #define STR_PACKETGAP "PacketGap"
  32. #define STR_AUTHKEY "AuthKey"
  33. #define STR_AUTHTYPE "AuthType"
  34. #define STR_SOCKBUFSIZE "SockBufSize"
  35. //
  36. // these definitions are used for socket setup
  37. //
  38. #define RIP_PORT 520
  39. #define RIPTEST_PORT 521
  40. //
  41. // the field ire_metric5 is used as a status field, with these values
  42. //
  43. #define ROUTE_STATUS_OK 0
  44. #define ROUTE_STATUS_METRIC 1
  45. #define ROUTE_STATUS_MISSING 2
  46. //
  47. //
  48. //
  49. typedef MIB_IPFORWARDROW IPForwardEntry;
  50. //
  51. // This type is for a generic registry-access function.
  52. // Such a function reads the given key, and if the option
  53. // specified is found, it reads it. Otherwise, it uses the default
  54. // and writes the default value to the registry.
  55. //
  56. struct _REG_OPTION;
  57. typedef
  58. DWORD
  59. (*REG_GETOPT_FUNCTION)(
  60. HKEY hKey,
  61. struct _REG_OPTION *pOpt
  62. );
  63. //
  64. // This type is for a generic RIPTEST option.
  65. //
  66. // RO_Name used to retrieve the value from its registry key
  67. // RO_Size for strings and binary values; gives maximum size
  68. // RO_OptVal contains the option's value
  69. // RO_DefVal contains the default value for the option
  70. // RO_GetOpt contains the function used to retrieve this value
  71. //
  72. typedef struct _REG_OPTION {
  73. PSTR RO_Name;
  74. DWORD RO_Size;
  75. PVOID RO_OptVal;
  76. PVOID RO_DefVal;
  77. REG_GETOPT_FUNCTION RO_GetOpt;
  78. } REG_OPTION, *PREG_OPTION;
  79. //
  80. // This type is used to hold all RIPTEST's parameters for a given interface
  81. //
  82. typedef struct _RIPTEST_IF_CONFIG {
  83. DWORD RIC_RouteCount;
  84. DWORD RIC_RouteStart;
  85. DWORD RIC_RouteMask;
  86. DWORD RIC_RouteNexthop;
  87. DWORD RIC_RouteTag;
  88. DWORD RIC_RouteTarget;
  89. DWORD RIC_RouteTimeout;
  90. DWORD RIC_PacketVersion;
  91. DWORD RIC_PacketEntryCount;
  92. DWORD RIC_PacketGap;
  93. BYTE RIC_AuthKey[IPRIP_MAX_AUTHKEY_SIZE];
  94. DWORD RIC_AuthType;
  95. DWORD RIC_SockBufSize;
  96. } RIPTEST_IF_CONFIG, *PRIPTEST_IF_CONFIG;
  97. //
  98. // structure used to store binding for an interface
  99. //
  100. typedef struct _RIPTEST_IF_BINDING {
  101. DWORD RIB_Address;
  102. DWORD RIB_Netmask;
  103. WCHAR RIB_Netcard[128];
  104. } RIPTEST_IF_BINDING, *PRIPTEST_IF_BINDING;
  105. //
  106. // struct used to store information for a responding router
  107. //
  108. typedef struct _RIPTEST_ROUTER_INFO {
  109. DWORD RRS_Address;
  110. CHAR RRS_DnsName[64];
  111. LIST_ENTRY RRS_Link;
  112. } RIPTEST_ROUTER_INFO, *PRIPTEST_ROUTER_INFO;
  113. //
  114. // macros used to compute prefix length of a network mask:
  115. // the prefix length is the nubmer of bits set in the mask, assuming
  116. // that the mask is contiguous
  117. //
  118. #define PREFIX_LENGTH(a) PREFIX_LENGTH32(a)
  119. #define PREFIX_LENGTH32(a) \
  120. (((a) & 0x00000100) ? PREFIX_LENGTH16((a) >> 16) + 16 \
  121. : PREFIX_LENGTH16(a))
  122. #define PREFIX_LENGTH16(a) \
  123. (((a) & 0x0001) ? PREFIX_LENGTH8((a) >> 8) + 8 \
  124. : PREFIX_LENGTH8(a))
  125. #define PREFIX_LENGTH8(a) \
  126. (((a) & 0x01) ? 8 : \
  127. (((a) & 0x02) ? 7 : \
  128. (((a) & 0x04) ? 6 : \
  129. (((a) & 0x08) ? 5 : \
  130. (((a) & 0x10) ? 4 : \
  131. (((a) & 0x20) ? 3 : \
  132. (((a) & 0x40) ? 2 : \
  133. (((a) & 0x80) ? 1 : 0))))))))
  134. //
  135. //
  136. //
  137. #define NTH_ADDRESS(addr, preflen, n) \
  138. htonl(((ntohl(addr) >> (32 - (preflen))) + (n)) << (32 - (preflen)))
  139. //
  140. //
  141. //
  142. #if 1
  143. #define RANDOM(seed, min, max) \
  144. ((min) + \
  145. (DWORD)((DOUBLE)rand() / ((DOUBLE)RAND_MAX + 1) * \
  146. ((max) - (min) + 1)))
  147. #else
  148. #define RANDOM(seed, min, max) \
  149. ((min) + \
  150. (DWORD)((DOUBLE)RtlRandom(seed) / ((DOUBLE)MAXLONG + 1) * \
  151. ((max) - (min) + 1)))
  152. #endif
  153. //
  154. // IP address conversion macro
  155. //
  156. #define INET_NTOA(addr) inet_ntoa( *(PIN_ADDR)&(addr) )
  157. //
  158. // macros used to generate tracing output
  159. //
  160. #ifdef RTUTILS
  161. #define PRINTREGISTER(a) TraceRegister(a)
  162. #define PRINTDEREGISTER(a) TraceDeregister(a)
  163. #define PRINT0(a) \
  164. TracePrintf(g_TraceID,a)
  165. #define PRINT1(a,b) \
  166. TracePrintf(g_TraceID,a,b)
  167. #define PRINT2(a,b,c) \
  168. TracePrintf(g_TraceID,a,b,c)
  169. #define PRINT3(a,b,c,d) \
  170. TracePrintf(g_TraceID,a,b,c,d)
  171. #define PRINT4(a,b,c,d,e) \
  172. TracePrintf(g_TraceID,a,b,c,d,e)
  173. #define PRINT5(a,b,c,d,e,f) \
  174. TracePrintf(g_TraceID,a,b,c,d,e,f)
  175. #else
  176. #define PRINTREGISTER(a) INVALID_TRACEID
  177. #define PRINTDEREGISTER(a)
  178. #define PRINT0(a) \
  179. printf("\n"a)
  180. #define PRINT1(a,b) \
  181. printf("\n"a,b)
  182. #define PRINT2(a,b,c) \
  183. printf("\n"a,b,c)
  184. #define PRINT3(a,b,c,d) \
  185. printf("\n"a,b,c,d)
  186. #define PRINT4(a,b,c,d,e) \
  187. printf("\n"a,b,c,d,e)
  188. #define PRINT5(a,b,c,d,e,f) \
  189. printf("\n"a,b,c,d,e,f)
  190. #endif
  191. //
  192. // functions used to access options in the registry
  193. //
  194. DWORD
  195. RegGetConfig(
  196. VOID
  197. );
  198. DWORD
  199. RegGetAddress(
  200. HKEY hKey,
  201. PREG_OPTION pOpt
  202. );
  203. DWORD
  204. RegGetDWORD(
  205. HKEY hKey,
  206. PREG_OPTION pOpt
  207. );
  208. DWORD
  209. RegGetBinary(
  210. HKEY hKey,
  211. PREG_OPTION pOpt
  212. );
  213. DWORD
  214. RegGetIfBinding(
  215. VOID
  216. );
  217. DWORD
  218. InitializeSocket(
  219. SOCKET *psock,
  220. WORD wPort
  221. );
  222. DWORD
  223. GenerateRoutes(
  224. IPForwardEntry **pifelist
  225. );
  226. DWORD
  227. DiscoverRouters(
  228. SOCKET sock,
  229. PLIST_ENTRY rtrlist
  230. );
  231. DWORD
  232. TransmitRoutes(
  233. SOCKET sock,
  234. DWORD dwMetric,
  235. IPForwardEntry *ifelist
  236. );
  237. DWORD
  238. VerifyRouteTables(
  239. DWORD dwMetric,
  240. PLIST_ENTRY rtrlist,
  241. IPForwardEntry *ifelist
  242. );
  243. DWORD
  244. CreateRouterStatsEntry(
  245. PLIST_ENTRY rtrlist,
  246. DWORD dwAddress,
  247. PRIPTEST_ROUTER_INFO *pprrs
  248. );
  249. DWORD
  250. PrintUsage(
  251. VOID
  252. );
  253. DWORD
  254. RipTest(
  255. VOID
  256. );