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.

133 lines
4.5 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) 2001 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dpnhupnpcachemap.h
  6. *
  7. * Content: Header for cached mapping 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 CACHEMAPOBJ_TCP DPNHQUERYADDRESS_TCP // a TCP port instead of UDP
  19. #define CACHEMAPOBJ_NOTFOUND DPNHQUERYADDRESS_CACHENOTFOUND // the address was actually not found
  20. #define CACHEMAPOBJ_PRIVATEBUTUNMAPPED DPNHQUERYADDRESS_CHECKFORPRIVATEBUTUNMAPPED // the address is private, but was not mapped on the Internet gateway
  21. //=============================================================================
  22. // Macros
  23. //=============================================================================
  24. #define CACHEMAP_FROM_BILINK(b) (CONTAINING_OBJECT(b, CCacheMap, m_blList))
  25. //
  26. // TCP queries need to match TCP mappings, (and UDP needs to match UDP).
  27. //
  28. #define QUERYFLAGSMASK(dwFlags) (dwFlags & DPNHQUERYADDRESS_TCP)
  29. //=============================================================================
  30. // Forward declarations
  31. //=============================================================================
  32. class CCacheMap;
  33. //=============================================================================
  34. // Main interface object class
  35. //=============================================================================
  36. class CCacheMap
  37. {
  38. public:
  39. #undef DPF_MODNAME
  40. #define DPF_MODNAME "CCacheMap::CCacheMap"
  41. CCacheMap(const SOCKADDR_IN * const psaddrinQueryAddress,
  42. const DWORD dwExpirationTime,
  43. const DWORD dwFlags)
  44. {
  45. this->m_blList.Initialize();
  46. this->m_Sig[0] = 'C';
  47. this->m_Sig[1] = 'M';
  48. this->m_Sig[2] = 'A';
  49. this->m_Sig[3] = 'P';
  50. this->m_dwQueryAddressV4 = psaddrinQueryAddress->sin_addr.S_un.S_addr;
  51. this->m_wQueryPort = psaddrinQueryAddress->sin_port;
  52. this->m_dwFlags = dwFlags; // works because CACHEMAPOBJ_xxx == DPNHQUERYADDRESS_xxx.
  53. this->m_dwExpirationTime = dwExpirationTime;
  54. };
  55. #undef DPF_MODNAME
  56. #define DPF_MODNAME "CCacheMap::~CCacheMap"
  57. ~CCacheMap(void)
  58. {
  59. DNASSERT(this->m_blList.IsEmpty());
  60. };
  61. inline BOOL DoesMatchQuery(const SOCKADDR_IN * const psaddrinQueryAddress,
  62. const DWORD dwFlags) const
  63. {
  64. //
  65. // Is this even the right address?
  66. //
  67. if ((this->m_dwQueryAddressV4 != psaddrinQueryAddress->sin_addr.S_un.S_addr) ||
  68. (this->m_wQueryPort != psaddrinQueryAddress->sin_port))
  69. {
  70. return FALSE;
  71. }
  72. //
  73. // Of the ones that matter (QUERYFLAGSMASK), make sure all
  74. // required flags are present, and all flags that aren't
  75. // required are not present.
  76. // Remember CACHEMAPOBJ_xxx == DPNHQUERYADDRESS_xxx.
  77. //
  78. return ((QUERYFLAGSMASK(this->m_dwFlags) == QUERYFLAGSMASK(dwFlags)) ? TRUE : FALSE);
  79. };
  80. inline BOOL IsNotFound(void) const { return ((this->m_dwFlags & CACHEMAPOBJ_NOTFOUND) ? TRUE : FALSE); };
  81. inline BOOL IsPrivateButUnmapped(void) const { return ((this->m_dwFlags & CACHEMAPOBJ_PRIVATEBUTUNMAPPED) ? TRUE : FALSE); };
  82. inline void GetResponseAddressV4(SOCKADDR_IN * const psaddrinAddress) const
  83. {
  84. ZeroMemory(psaddrinAddress, sizeof(*psaddrinAddress));
  85. psaddrinAddress->sin_family = AF_INET;
  86. psaddrinAddress->sin_addr.S_un.S_addr = this->m_dwResponseAddressV4;
  87. psaddrinAddress->sin_port = this->m_wResponsePort;
  88. };
  89. inline DWORD GetExpirationTime(void) const { return this->m_dwExpirationTime; };
  90. inline void SetResponseAddressV4(const DWORD dwAddressV4,
  91. const WORD wPort)
  92. {
  93. this->m_dwResponseAddressV4 = dwAddressV4;
  94. this->m_wResponsePort = wPort;
  95. };
  96. CBilink m_blList; // list of all the mappings cached
  97. private:
  98. BYTE m_Sig[4]; // debugging signature ('CMAP')
  99. DWORD m_dwFlags; // flags for this object
  100. DWORD m_dwQueryAddressV4; // IPv4 address searched
  101. WORD m_wQueryPort; // IPv4 port searched
  102. DWORD m_dwResponseAddressV4; // IPv4 address mapping corresponding to query
  103. WORD m_wResponsePort; // IPv4 port mapping corresponding to query
  104. DWORD m_dwExpirationTime; // time when this cached mapping expires
  105. };