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.

315 lines
11 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) 2001-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dpnhpastdevice.h
  6. *
  7. * Content: Header for device object class.
  8. *
  9. * History:
  10. * Date By Reason
  11. * ======== ======== =========
  12. * 04/16/01 VanceO Split DPNATHLP into DPNHUPNP and DPNHPAST.
  13. *
  14. ***************************************************************************/
  15. //=============================================================================
  16. // Object flags
  17. //=============================================================================
  18. #define DEVICE_LOCALPASTSERVER_ICS 0x01 // the local PAST server is an Internet Connection Sharing server
  19. #define DEVICE_LOCALPASTSERVER_PFWONLY 0x02 // the local PAST server is a personal firewall server only
  20. #define DEVICE_LOCALPASTSERVER_PUBLICADDRESSAVAILABLE 0x04 // the local PAST server has public addresses available
  21. #define DEVICE_REMOTEPASTSERVER_PUBLICADDRESSAVAILABLE 0x08 // the remote PAST server has public addresses available
  22. #ifdef DBG
  23. #define DEVICE_PRIMARY 0x10 // this device appears to be the primary adapter with which its gateway should be reached
  24. #define DEVICE_SECONDARY 0x20 // this device appears to be a secondary adapter on a shared network
  25. #define DEVICE_NOGATEWAY 0x40 // this device does not currently have a gateway
  26. #endif // DBG
  27. //=============================================================================
  28. // Macros
  29. //=============================================================================
  30. #define DEVICE_FROM_BILINK(b) (CONTAINING_OBJECT(b, CDevice, m_blList))
  31. #define DEVICE_FROM_TEMP_BILINK(b) (CONTAINING_OBJECT(b, CDevice, m_blTempList))
  32. //=============================================================================
  33. // Typedefs
  34. //=============================================================================
  35. class CDevice;
  36. //=============================================================================
  37. // Device object class
  38. //=============================================================================
  39. class CDevice
  40. {
  41. public:
  42. #undef DPF_MODNAME
  43. #define DPF_MODNAME "CDevice::CDevice"
  44. CDevice(const DWORD dwLocalAddressV4)
  45. {
  46. this->m_blList.Initialize();
  47. this->m_blTempList.Initialize();
  48. this->m_blOwnedRegPorts.Initialize();
  49. this->m_Sig[0] = 'D';
  50. this->m_Sig[1] = 'E';
  51. this->m_Sig[2] = 'V';
  52. this->m_Sig[3] = 'I';
  53. this->m_dwFlags = 0;
  54. this->m_dwLocalAddressV4 = dwLocalAddressV4;
  55. this->m_sPASTSocket = INVALID_SOCKET;
  56. //ZeroMemory(&this->m_saddrinPASTSocketAddress, sizeof(this->m_saddrinPASTSocketAddress));
  57. this->m_dwFirstPASTDiscoveryTime = 0;
  58. this->m_dwLocalPASTClientID = 0;
  59. this->m_dwLocalPASTMsgID = 0;
  60. this->m_tuLocalPASTRetry = 0;
  61. this->m_blLocalPASTCachedMaps.Initialize();
  62. this->m_dwRemotePASTServerAddressV4 = 0;
  63. this->m_dwRemotePASTClientID = 0;
  64. this->m_dwRemotePASTMsgID = 0;
  65. this->m_tuRemotePASTRetry = 0;
  66. this->m_blRemotePASTCachedMaps.Initialize();
  67. #ifdef DBG
  68. this->m_dwNumLocalPASTServerFailures = 0;
  69. this->m_dwNumRemotePASTServerFailures = 0;
  70. #endif // DBG
  71. };
  72. #undef DPF_MODNAME
  73. #define DPF_MODNAME "CDevice::~CDevice"
  74. ~CDevice(void)
  75. {
  76. #ifdef DBG
  77. DPFX(DPFPREP, 7, "(0x%p) NumLocalPASTServerFailures = %u, NumRemotePASTServerFailures = %u",
  78. this, this->m_dwNumLocalPASTServerFailures,
  79. this->m_dwNumRemotePASTServerFailures);
  80. DNASSERT(this->m_blList.IsEmpty());
  81. DNASSERT(this->m_blTempList.IsEmpty());
  82. DNASSERT(this->m_blOwnedRegPorts.IsEmpty());
  83. DNASSERT(this->m_sPASTSocket == INVALID_SOCKET);
  84. DNASSERT(this->m_dwLocalPASTClientID == 0);
  85. DNASSERT(this->m_blLocalPASTCachedMaps.IsEmpty());
  86. DNASSERT(this->m_dwRemotePASTClientID == 0);
  87. DNASSERT(this->m_blRemotePASTCachedMaps.IsEmpty());
  88. #endif // DBG
  89. };
  90. inline BOOL HasLocalICSPASTServer(void) const { return ((this->m_dwFlags & DEVICE_LOCALPASTSERVER_ICS) ? TRUE : FALSE); };
  91. inline BOOL HasLocalPFWOnlyPASTServer(void) const { return ((this->m_dwFlags & DEVICE_LOCALPASTSERVER_PFWONLY) ? TRUE : FALSE); };
  92. inline BOOL IsPASTPublicAddressAvailable(const BOOL fRemote) const
  93. {
  94. if (fRemote)
  95. {
  96. return ((this->m_dwFlags & DEVICE_REMOTEPASTSERVER_PUBLICADDRESSAVAILABLE) ? TRUE : FALSE);
  97. }
  98. else
  99. {
  100. return ((this->m_dwFlags & DEVICE_LOCALPASTSERVER_PUBLICADDRESSAVAILABLE) ? TRUE : FALSE);
  101. }
  102. };
  103. #ifdef DBG
  104. inline BOOL IsPrimaryDevice(void) const { return ((this->m_dwFlags & DEVICE_PRIMARY) ? TRUE : FALSE); };
  105. inline BOOL IsSecondaryDevice(void) const { return ((this->m_dwFlags & DEVICE_SECONDARY) ? TRUE : FALSE); };
  106. inline BOOL HasNoGateway(void) const { return ((this->m_dwFlags & DEVICE_NOGATEWAY) ? TRUE : FALSE); };
  107. #endif // DBG
  108. inline DWORD GetLocalAddressV4(void) const { return this->m_dwLocalAddressV4; };
  109. inline SOCKET GetPASTSocket(void) const { return this->m_sPASTSocket; };
  110. //inline SOCKADDR_IN * GetPASTSocketAddressPtr(void) { return (&this->m_saddrinPASTSocketAddress); };
  111. inline DWORD GetFirstPASTDiscoveryTime(void) const { return this->m_dwFirstPASTDiscoveryTime; };
  112. inline DWORD GetPASTClientID(const BOOL fRemote) const
  113. {
  114. if (fRemote)
  115. {
  116. return (this->m_dwRemotePASTClientID);
  117. }
  118. else
  119. {
  120. return (this->m_dwLocalPASTClientID);
  121. }
  122. }
  123. inline CBilink * GetPASTCachedMaps(const BOOL fRemote)
  124. {
  125. if (fRemote)
  126. {
  127. return (&this->m_blLocalPASTCachedMaps);
  128. }
  129. else
  130. {
  131. return (&this->m_blRemotePASTCachedMaps);
  132. }
  133. }
  134. inline DWORD GetNextLocalPASTMsgID(void) { return (this->m_dwLocalPASTMsgID++); };
  135. inline DWORD * GetLocalPASTRetryTimeoutPtr(void) { return (&this->m_tuLocalPASTRetry); };
  136. inline DWORD GetRemotePASTServerAddressV4(void) const { return (this->m_dwRemotePASTServerAddressV4); };
  137. inline DWORD GetNextRemotePASTMsgID(void) { return (this->m_dwRemotePASTMsgID++); };
  138. inline DWORD * GetRemotePASTRetryTimeoutPtr(void) { return (&this->m_tuRemotePASTRetry); };
  139. #undef DPF_MODNAME
  140. #define DPF_MODNAME "CDevice::NoteLocalPASTServerIsICS"
  141. inline void NoteLocalPASTServerIsICS(void)
  142. {
  143. DNASSERT(this->m_dwLocalPASTClientID != 0);
  144. this->m_dwFlags &= ~DEVICE_LOCALPASTSERVER_PFWONLY;
  145. this->m_dwFlags |= DEVICE_LOCALPASTSERVER_ICS;
  146. };
  147. #undef DPF_MODNAME
  148. #define DPF_MODNAME "CDevice::NoteLocalPASTServerIsPFWOnly"
  149. inline void NoteLocalPASTServerIsPFWOnly(void)
  150. {
  151. DNASSERT(this->m_dwLocalPASTClientID != 0);
  152. this->m_dwFlags &= ~DEVICE_LOCALPASTSERVER_ICS;
  153. this->m_dwFlags |= DEVICE_LOCALPASTSERVER_PFWONLY;
  154. };
  155. #undef DPF_MODNAME
  156. #define DPF_MODNAME "CDevice::NotePASTPublicAddressAvailable"
  157. inline void NotePASTPublicAddressAvailable(const BOOL fRemote)
  158. {
  159. if (fRemote)
  160. {
  161. DNASSERT(this->m_dwRemotePASTClientID != 0);
  162. DNASSERT(! (this->m_dwFlags & DEVICE_REMOTEPASTSERVER_PUBLICADDRESSAVAILABLE));
  163. this->m_dwFlags |= DEVICE_REMOTEPASTSERVER_PUBLICADDRESSAVAILABLE;
  164. }
  165. else
  166. {
  167. DNASSERT(this->m_dwLocalPASTClientID != 0);
  168. DNASSERT(! (this->m_dwFlags & DEVICE_LOCALPASTSERVER_PUBLICADDRESSAVAILABLE));
  169. this->m_dwFlags |= DEVICE_LOCALPASTSERVER_PUBLICADDRESSAVAILABLE;
  170. }
  171. };
  172. inline void NoteNoLocalPASTServer(void) { this->m_dwFlags &= ~(DEVICE_LOCALPASTSERVER_ICS | DEVICE_LOCALPASTSERVER_PFWONLY); };
  173. inline void NoteNoPASTPublicAddressAvailable(const BOOL fRemote)
  174. {
  175. if (fRemote)
  176. {
  177. this->m_dwFlags &= ~DEVICE_REMOTEPASTSERVER_PUBLICADDRESSAVAILABLE;
  178. }
  179. else
  180. {
  181. this->m_dwFlags &= ~DEVICE_LOCALPASTSERVER_PUBLICADDRESSAVAILABLE;
  182. }
  183. };
  184. #ifdef DBG
  185. inline void NotePrimaryDevice(void) { this->m_dwFlags |= DEVICE_PRIMARY; };
  186. inline void NoteSecondaryDevice(void) { this->m_dwFlags |= DEVICE_SECONDARY; };
  187. inline void NoteNoGateway(void) { this->m_dwFlags |= DEVICE_NOGATEWAY; };
  188. inline void ClearGatewayFlags(void) { this->m_dwFlags &= ~(DEVICE_PRIMARY | DEVICE_SECONDARY | DEVICE_NOGATEWAY); };
  189. #endif // DBG
  190. inline void SetPASTSocket(const SOCKET sSocket) { this->m_sPASTSocket = sSocket; };
  191. inline void SetFirstPASTDiscoveryTime(const DWORD dwTime) { this->m_dwFirstPASTDiscoveryTime = dwTime; };
  192. inline void SetPASTClientID(const DWORD dwClientID, const BOOL fRemote)
  193. {
  194. if (fRemote)
  195. {
  196. this->m_dwRemotePASTClientID = dwClientID;
  197. }
  198. else
  199. {
  200. this->m_dwLocalPASTClientID = dwClientID;
  201. }
  202. }
  203. inline void ResetLocalPASTMsgIDAndRetryTimeout(const DWORD tuRetryTimeout)
  204. {
  205. this->m_dwLocalPASTMsgID = 0;
  206. this->m_tuLocalPASTRetry = tuRetryTimeout;
  207. };
  208. inline void SetRemotePASTServerAddressV4(const DWORD dwAddressV4) { this->m_dwRemotePASTServerAddressV4 = dwAddressV4; };
  209. inline void ResetRemotePASTMsgIDAndRetryTimeout(const DWORD tuRetryTimeout)
  210. {
  211. this->m_dwRemotePASTMsgID = 0;
  212. this->m_tuRemotePASTRetry = tuRetryTimeout;
  213. };
  214. #ifdef DBG
  215. inline void IncrementPASTServerFailures(const BOOL fRemote)
  216. {
  217. if (fRemote)
  218. {
  219. this->m_dwNumRemotePASTServerFailures++;
  220. }
  221. else
  222. {
  223. this->m_dwNumLocalPASTServerFailures++;
  224. }
  225. };
  226. #endif // DBG
  227. CBilink m_blList; // list of all the available devices
  228. CBilink m_blTempList; // temporary list of all the available devices
  229. CBilink m_blOwnedRegPorts; // list of all the ports registered using this device
  230. private:
  231. //
  232. // Note that all values here are protected by the global CNATHelpPAST lock.
  233. //
  234. BYTE m_Sig[4]; // debugging signature ('DEVI')
  235. DWORD m_dwFlags; // flags describing this object
  236. DWORD m_dwLocalAddressV4; // address this object represents (and the local PAST server's address, if present)
  237. SOCKET m_sPASTSocket; // socket opened for PAST communication on this device
  238. //SOCKADDR_IN m_saddrinPASTSocketAddress; // address (and port) of the PAST communications socket
  239. DWORD m_dwFirstPASTDiscoveryTime; // the time we first sent remote PAST discovery (registration) traffic from this particular port
  240. DWORD m_dwLocalPASTClientID; // client ID assigned by local PAST server
  241. DWORD m_dwLocalPASTMsgID; // next msg ID to be sent to local PAST server
  242. DWORD m_tuLocalPASTRetry; // current retry timeout for messages sent to local PAST server
  243. CBilink m_blLocalPASTCachedMaps; // list of cached mappings for query addresses performed on the local PAST server
  244. DWORD m_dwRemotePASTServerAddressV4; // address this object represents
  245. DWORD m_dwRemotePASTClientID; // client ID assigned by local PAST server
  246. DWORD m_dwRemotePASTMsgID; // next msg ID to be sent to remote PAST server
  247. DWORD m_tuRemotePASTRetry; // current retry timeout for messages sent to remote PAST server
  248. CBilink m_blRemotePASTCachedMaps; // list of cached mappings for query address performed on the remote PAST server
  249. #ifdef DBG
  250. DWORD m_dwNumLocalPASTServerFailures; // how many times a local PAST server returned an error or stopped responding and had to be cleared
  251. DWORD m_dwNumRemotePASTServerFailures; // how many times a remote PAST server returned an error or stopped responding and had to be cleared
  252. #endif // DBG
  253. };