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.

142 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. iislbh.hxx
  5. Abstract:
  6. Definition of Kernel Load balancing structures
  7. Author:
  8. Philippe Choquier (phillich)
  9. --*/
  10. #if !defined( _IISLBH_HXX )
  11. #define _IISLBH_HXX
  12. #define LOADBAL_SAMPLES 6
  13. #define LOADBAL_NORMALIZED_TOTAL 10000
  14. #define DEFAULT_STICKY_DURATION (60*10) // in seconds
  15. #pragma warning( disable:4200 )
  16. #pragma pack(1)
  17. struct CKernelIpEndpoint {
  18. DWORD m_dwIpAddress;
  19. USHORT m_usPort;
  20. };
  21. struct CKernelIpEndpointEx {
  22. DWORD m_dwIpAddress;
  23. USHORT m_usPort;
  24. USHORT m_usUniquePort; // non-zero only once in list for given port
  25. DWORD m_dwRefCount; // used as refcount for user>kernel IOCTL
  26. DWORD m_dwIndex; // used as old cnfg -> new cnfg index in kernel
  27. DWORD m_dwNotifyPort; // used by driver to build notify/unnotify list
  28. DWORD m_dwSticky; // sticky duration ( in seconds ), only for public IP addr
  29. LPVOID m_pvDirectorHandle; // NAT handle after register port
  30. } ;
  31. typedef DWORD IPREF;
  32. struct CKernelServerDescription {
  33. DWORD m_dwLoadAvail;
  34. INT m_LoadbalancedLoadAvail;
  35. float m_flLoadAvailAvg;
  36. float m_flLoadAvail[LOADBAL_SAMPLES];
  37. DWORD m_cNbSamplesAvail;
  38. DWORD m_dwHeartbeat;
  39. BYTE m_bArray[0];
  40. // array of IPREF[m_dwPublicIpCount]
  41. } ;
  42. #define UNAVAIL_HEARTBEAT 0x56349812
  43. struct CKernelIpMap {
  44. DWORD m_dwServerCount;
  45. DWORD m_dwPublicIpCount;
  46. DWORD m_dwPrivateIpCount;
  47. DWORD m_dwStickyDuration;
  48. BYTE m_bArray[0];
  49. // array of CKernelIpEndpointEx[m_dwPublicIpCount]
  50. // array of CKernelIpEndpointEx[m_dwPrivateIpCount]
  51. // array of CKernelServerDescription[m_dwServerCount]
  52. };
  53. #pragma pack()
  54. class CKernelIpMapMinHelper {
  55. public:
  56. CKernelIpMapMinHelper()
  57. { m_pKernelIpMap = NULL; }
  58. VOID SetBuffer( LPVOID pV )
  59. { m_pKernelIpMap = (CKernelIpMap*)pV; }
  60. LPVOID GetBuffer()
  61. { return (LPVOID)m_pKernelIpMap; }
  62. UINT ServerCount()
  63. { return m_pKernelIpMap->m_dwServerCount; }
  64. UINT PublicIpCount()
  65. { return m_pKernelIpMap->m_dwPublicIpCount; }
  66. UINT PrivateIpCount()
  67. { return m_pKernelIpMap->m_dwPrivateIpCount; }
  68. BOOL SetStickyDuration(DWORD dw)
  69. { m_pKernelIpMap->m_dwStickyDuration = dw; return TRUE; }
  70. DWORD GetStickyDuration()
  71. { return m_pKernelIpMap->m_dwStickyDuration; }
  72. CKernelIpEndpointEx* GetPublicIpPtr( UINT i )
  73. { return (CKernelIpEndpointEx*)(m_pKernelIpMap->m_bArray + sizeof(CKernelIpEndpointEx)*i); }
  74. CKernelServerDescription* GetServerPtr( UINT i, LPBYTE pBase = NULL, DWORD dwPub = -1, DWORD dwPriv = -1 )
  75. {
  76. if ( pBase == NULL ) pBase = (LPBYTE)m_pKernelIpMap;
  77. if ( dwPub == -1 ) dwPub = m_pKernelIpMap->m_dwPublicIpCount;
  78. if ( dwPriv == -1 ) dwPriv = m_pKernelIpMap->m_dwPrivateIpCount;
  79. return (CKernelServerDescription*)(pBase + sizeof(CKernelIpMap) +
  80. dwPub * sizeof(CKernelIpEndpointEx) +
  81. dwPriv * sizeof(CKernelIpEndpointEx) +
  82. i * (sizeof(CKernelServerDescription) + dwPub * sizeof(IPREF) ));
  83. }
  84. CKernelIpEndpointEx* GetPrivateIpEndpoint( DWORD dw, LPBYTE pBase = NULL )
  85. {
  86. if ( pBase == NULL ) pBase = (LPBYTE)m_pKernelIpMap;
  87. return (CKernelIpEndpointEx*)((LPBYTE)pBase + sizeof(CKernelIpMap) +
  88. ((CKernelIpMap*)pBase)->m_dwPublicIpCount * sizeof(CKernelIpEndpointEx) +
  89. dw * sizeof(CKernelIpEndpointEx) ); };
  90. IPREF* GetPrivateIpRef( CKernelServerDescription* pS, DWORD dw)
  91. { return (IPREF*)(pS->m_bArray+dw*sizeof(IPREF)); }
  92. //CKernelIpEndpointEx* GetPrivateIpPtr( CKernelServerDescription* pS, DWORD dw)
  93. // { return GetPrivateIpEndpoint( *GetPrivateIpRef( pS, dw) ); }
  94. DWORD GetKernelServerDescriptionSize()
  95. { return sizeof(CKernelServerDescription) + m_pKernelIpMap->m_dwPublicIpCount * sizeof(IPREF); }
  96. DWORD GetSize( DWORD dwServer, DWORD dwPublicIp, DWORD dwPrivateIp )
  97. { return sizeof(CKernelIpMap) +
  98. dwPublicIp * sizeof(CKernelIpEndpointEx) +
  99. dwPrivateIp * sizeof(CKernelIpEndpointEx) +
  100. dwServer * ( sizeof(CKernelServerDescription) + dwPublicIp * sizeof(IPREF) ); }
  101. DWORD GetSize()
  102. { return GetSize( ServerCount(), PublicIpCount(), PrivateIpCount() ); }
  103. protected:
  104. CKernelIpMap* m_pKernelIpMap;
  105. } ;
  106. #endif