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.

406 lines
11 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. ServStat.cpp
  7. The server statistics dialog
  8. FILE HISTORY:
  9. */
  10. #include <afx.h>
  11. #include "dbgutil.h"
  12. #include "stdafx.h"
  13. #include "stats.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. /*---------------------------------------------------------------------------
  20. CIpsecStats implementation
  21. ---------------------------------------------------------------------------*/
  22. UINT QmStatsItems[] = {
  23. IDS_STATS_QM_ACTIVE_SA,
  24. IDS_STATS_QM_OFFLOAD_SA,
  25. IDS_STATS_QM_PENDING_KEY_OPS,
  26. IDS_STATS_QM_KEY_ADDITION,
  27. IDS_STATS_QM_KEY_DELETION,
  28. IDS_STATS_QM_REKEYS,
  29. IDS_STATS_QM_ACTIVE_TNL,
  30. IDS_STATS_QM_BAD_SPI,
  31. IDS_STATS_QM_PKT_NOT_DECRYPT,
  32. IDS_STATS_QM_PKT_NOT_AUTH,
  33. IDS_STATS_QM_PKT_REPLAY,
  34. IDS_STATS_QM_ESP_BYTE_SENT,
  35. IDS_STATS_QM_ESP_BYTE_RCV,
  36. IDS_STATS_QM_AUTH_BYTE_SENT,
  37. IDS_STATS_QM_ATTH_BYTE_RCV,
  38. IDS_STATS_QM_XPORT_BYTE_SENT,
  39. IDS_STATS_QM_XPORT_BYTE_RCV,
  40. IDS_STATS_QM_TNL_BYTE_SENT,
  41. IDS_STATS_QM_TNL_BYTE_RCV,
  42. IDS_STATS_QM_OFFLOAD_BYTE_SENT,
  43. IDS_STATS_QM_OFFLOAD_BYTE_RCV
  44. };
  45. UINT MmStatsItems[] = {
  46. IDS_STATS_MM_ACTIVE_ACQUIRE,
  47. IDS_STATS_MM_ACTIVE_RCV,
  48. IDS_STATS_MM_ACQUIRE_FAIL,
  49. IDS_STATS_MM_RCV_FAIL,
  50. IDS_STATS_MM_SEND_FAIL,
  51. IDS_STATS_MM_ACQUIRE_HEAP_SIZE,
  52. IDS_STATS_MM_RCV_HEAP_SIZE,
  53. IDS_STATS_MM_NEG_FAIL,
  54. IDS_STATS_MM_INVALID_COOKIE,
  55. IDS_STATS_MM_TOTAL_ACQUIRE,
  56. IDS_STATS_MM_TOTAL_GETSPI,
  57. IDS_STATS_MM_TOTAL_KEY_ADD,
  58. IDS_STATS_MM_TOTAL_KEY_UPDATE,
  59. IDS_STATS_MM_GET_SPI_FAIL,
  60. IDS_STATS_MM_KEY_ADD_FAIL,
  61. IDS_STATS_MM_KEY_UPDATE_FAIL,
  62. IDS_STATS_MM_ISADB_LIST_SIZE,
  63. IDS_STATS_MM_CONN_LIST_SIZE,
  64. IDS_STATS_MM_OAKLEY_MM,
  65. IDS_STATS_MM_OAKLEY_QM,
  66. IDS_STATS_MM_SOFT_ASSOCIATIONS,
  67. IDS_STATS_MM_INVALID_PACKETS
  68. };
  69. /*---------------------------------------------------------------------------
  70. CIpsecStats::CIpsecStats()
  71. Constructor
  72. ---------------------------------------------------------------------------*/
  73. CIpsecStats::CIpsecStats()
  74. : CModelessDlg()
  75. {
  76. }
  77. /*---------------------------------------------------------------------------
  78. CIpsecStats::CIpsecStats()
  79. Destructor
  80. ---------------------------------------------------------------------------*/
  81. CIpsecStats::~CIpsecStats()
  82. {
  83. }
  84. void CIpsecStats::DoDataExchange(CDataExchange* pDX)
  85. {
  86. CBaseDialog::DoDataExchange(pDX);
  87. //{{AFX_DATA_MAP(CIpsecStats)
  88. DDX_Control(pDX, IDC_STATS_MM_LIST, m_listIkeStats);
  89. DDX_Control(pDX, IDC_STATS_QM_LIST, m_listIpsecStats);
  90. //}}AFX_DATA_MAP
  91. }
  92. BEGIN_MESSAGE_MAP(CIpsecStats, CBaseDialog)
  93. //{{AFX_MSG_MAP(CIpsecStats)
  94. ON_MESSAGE(WM_UPDATE_STATS, OnUpdateStats)
  95. ON_BN_CLICKED(IDC_STATS_REFRESH, OnRefresh)
  96. //}}AFX_MSG_MAP
  97. END_MESSAGE_MAP()
  98. BOOL CIpsecStats::OnInitDialog()
  99. {
  100. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  101. CBaseDialog::OnInitDialog();
  102. CString st;
  103. CString stComputerName;
  104. m_spSpdInfo->GetComputerName(&stComputerName);
  105. AfxFormatString1(st, IDS_STATS_TITLE, stComputerName);
  106. SetWindowText((LPCTSTR) st);
  107. SetColumns(&m_listIkeStats);
  108. SetColumns(&m_listIpsecStats);
  109. int nRows = 0;
  110. for (int i = 0; i < DimensionOf(QmStatsItems); i++)
  111. {
  112. nRows = m_listIpsecStats.InsertItem(nRows, _T(""));
  113. if (-1 != nRows)
  114. {
  115. st.LoadString(QmStatsItems[i]);
  116. m_listIpsecStats.SetItemText(nRows, 0, st);
  117. m_listIpsecStats.SetItemData(nRows, QmStatsItems[i]);
  118. }
  119. nRows++;
  120. }
  121. nRows = 0;
  122. for (i = 0; i < DimensionOf(MmStatsItems); i++)
  123. {
  124. nRows = m_listIkeStats.InsertItem(nRows, _T(""));
  125. if (-1 != nRows)
  126. {
  127. st.LoadString(MmStatsItems[i]);
  128. m_listIkeStats.SetItemText(nRows, 0, st);
  129. m_listIkeStats.SetItemData(nRows, MmStatsItems[i]);
  130. }
  131. nRows++;
  132. }
  133. OnRefresh();
  134. {
  135. DWORD dwInitInfo;
  136. HRESULT hr;
  137. dwInitInfo=m_spSpdInfo->GetInitInfo();
  138. if (!(dwInitInfo & MON_STATS)) {
  139. CORg(m_spSpdInfo->LoadStatistics());
  140. m_spSpdInfo->SetInitInfo(dwInitInfo | MON_STATS);
  141. }
  142. m_spSpdInfo->SetActiveInfo(MON_STATS);
  143. }
  144. return TRUE; // return TRUE unless you set the focus to a control
  145. // EXCEPTION: OCX Property Pages should return FALSE
  146. COM_PROTECT_ERROR_LABEL;
  147. return TRUE;
  148. }
  149. void CIpsecStats::OnRefresh()
  150. {
  151. HRESULT hr = hrOK;
  152. CIkeStatistics IkeStats;
  153. CIpsecStatistics IpsecStats;
  154. CORg(m_spSpdInfo->LoadStatistics());
  155. m_spSpdInfo->GetLoadedStatistics(&IkeStats, &IpsecStats);
  156. UpdateStatistics(IkeStats, IpsecStats);
  157. Error:
  158. if (FAILED(hr))
  159. {
  160. //TODO bring up a error pop up here
  161. }
  162. return;
  163. }
  164. /*---------------------------------------------------------------------------
  165. CIpsecStats::OnUpdateStats(UINT wParam, LONG lParam)
  166. called in response to the message WM_UPDATE_STATS
  167. The background thread updates the stats, now we need to update
  168. the UI on the correct thread.
  169. Author: NSun
  170. ---------------------------------------------------------------------------*/
  171. afx_msg long
  172. CIpsecStats::OnUpdateStats(UINT wParam, LONG lParam)
  173. {
  174. CIkeStatistics IkeStats;
  175. CIpsecStatistics IpsecStats;
  176. //The new statistics was loaded by the server query object in the background thread
  177. m_spSpdInfo->GetLoadedStatistics(&IkeStats, &IpsecStats);
  178. UpdateStatistics(IkeStats, IpsecStats);
  179. return 0;
  180. }
  181. /*---------------------------------------------------------------------------
  182. CIpsecStats::UpdateWindow(PWINSINTF_RESULTS_T pwrResults)
  183. Updates the contents of the dialog
  184. ---------------------------------------------------------------------------*/
  185. void
  186. CIpsecStats::UpdateStatistics(const CIkeStatistics & IkeStats,
  187. const CIpsecStatistics & IpsecStats)
  188. {
  189. LONG_PTR uData;
  190. CString st;
  191. int i;
  192. //Populate the IKE statistics
  193. for (i = 0; i < m_listIkeStats.GetItemCount(); i++)
  194. {
  195. uData = m_listIkeStats.GetItemData(i);
  196. st.Empty();
  197. switch (uData)
  198. {
  199. case IDS_STATS_MM_ACTIVE_ACQUIRE:
  200. st.Format(_T("%u"), IkeStats.m_dwActiveAcquire);
  201. break;
  202. case IDS_STATS_MM_ACTIVE_RCV:
  203. st.Format(_T("%u"), IkeStats.m_dwActiveReceive);
  204. break;
  205. case IDS_STATS_MM_ACQUIRE_FAIL:
  206. st.Format(_T("%u"), IkeStats.m_dwAcquireFail);
  207. break;
  208. case IDS_STATS_MM_RCV_FAIL:
  209. st.Format(_T("%u"), IkeStats.m_dwReceiveFail);
  210. break;
  211. case IDS_STATS_MM_SEND_FAIL:
  212. st.Format(_T("%u"), IkeStats.m_dwSendFail);
  213. break;
  214. case IDS_STATS_MM_ACQUIRE_HEAP_SIZE:
  215. st.Format(_T("%u"), IkeStats.m_dwAcquireHeapSize);
  216. break;
  217. case IDS_STATS_MM_RCV_HEAP_SIZE:
  218. st.Format(_T("%u"), IkeStats.m_dwReceiveHeapSize);
  219. break;
  220. case IDS_STATS_MM_NEG_FAIL:
  221. st.Format(_T("%u"), IkeStats.m_dwNegotiationFailures);
  222. break;
  223. case IDS_STATS_MM_INVALID_COOKIE:
  224. st.Format(_T("%u"), IkeStats.m_dwInvalidCookiesReceived);
  225. break;
  226. case IDS_STATS_MM_TOTAL_ACQUIRE:
  227. st.Format(_T("%u"), IkeStats.m_dwTotalAcquire);
  228. break;
  229. case IDS_STATS_MM_TOTAL_GETSPI:
  230. st.Format(_T("%u"), IkeStats.m_dwTotalGetSpi);
  231. break;
  232. case IDS_STATS_MM_TOTAL_KEY_ADD:
  233. st.Format(_T("%u"), IkeStats.m_dwTotalKeyAdd);
  234. break;
  235. case IDS_STATS_MM_TOTAL_KEY_UPDATE:
  236. st.Format(_T("%u"), IkeStats.m_dwTotalKeyUpdate);
  237. break;
  238. case IDS_STATS_MM_GET_SPI_FAIL:
  239. st.Format(_T("%u"), IkeStats.m_dwGetSpiFail);
  240. break;
  241. case IDS_STATS_MM_KEY_ADD_FAIL:
  242. st.Format(_T("%u"), IkeStats.m_dwKeyAddFail);
  243. break;
  244. case IDS_STATS_MM_KEY_UPDATE_FAIL:
  245. st.Format(_T("%u"), IkeStats.m_dwKeyUpdateFail);
  246. break;
  247. case IDS_STATS_MM_ISADB_LIST_SIZE:
  248. st.Format(_T("%u"), IkeStats.m_dwIsadbListSize);
  249. break;
  250. case IDS_STATS_MM_CONN_LIST_SIZE:
  251. st.Format(_T("%u"), IkeStats.m_dwConnListSize);
  252. break;
  253. case IDS_STATS_MM_OAKLEY_MM:
  254. st.Format(_T("%u"), IkeStats.m_dwOakleyMainModes);
  255. break;
  256. case IDS_STATS_MM_OAKLEY_QM:
  257. st.Format(_T("%u"), IkeStats.m_dwOakleyQuickModes);
  258. break;
  259. case IDS_STATS_MM_SOFT_ASSOCIATIONS:
  260. st.Format(_T("%u"), IkeStats.m_dwSoftAssociations);
  261. break;
  262. case IDS_STATS_MM_INVALID_PACKETS:
  263. st.Format(_T("%u"), IkeStats.m_dwInvalidPacketsReceived);
  264. break;
  265. }
  266. m_listIkeStats.SetItemText(i, 1, (LPCTSTR) st);
  267. }
  268. //Populate the IPSec statistics
  269. for (i = 0; i < m_listIpsecStats.GetItemCount(); i++)
  270. {
  271. uData = m_listIpsecStats.GetItemData(i);
  272. st.Empty();
  273. switch(uData)
  274. {
  275. case IDS_STATS_QM_ACTIVE_SA:
  276. st.Format(_T("%u"), IpsecStats.m_dwNumActiveAssociations);
  277. break;
  278. case IDS_STATS_QM_OFFLOAD_SA:
  279. st.Format(_T("%u"), IpsecStats.m_dwNumOffloadedSAs);
  280. break;
  281. case IDS_STATS_QM_PENDING_KEY_OPS:
  282. st.Format(_T("%u"), IpsecStats.m_dwNumPendingKeyOps);
  283. break;
  284. case IDS_STATS_QM_KEY_ADDITION:
  285. st.Format(_T("%u"), IpsecStats.m_dwNumKeyAdditions);
  286. break;
  287. case IDS_STATS_QM_KEY_DELETION:
  288. st.Format(_T("%u"), IpsecStats.m_dwNumKeyDeletions);
  289. break;
  290. case IDS_STATS_QM_REKEYS:
  291. st.Format(_T("%u"), IpsecStats.m_dwNumReKeys);
  292. break;
  293. case IDS_STATS_QM_ACTIVE_TNL:
  294. st.Format(_T("%u"), IpsecStats.m_dwNumActiveTunnels);
  295. break;
  296. case IDS_STATS_QM_BAD_SPI:
  297. st.Format(_T("%u"), IpsecStats.m_dwNumBadSPIPackets);
  298. break;
  299. case IDS_STATS_QM_PKT_NOT_DECRYPT:
  300. st.Format(_T("%u"), IpsecStats.m_dwNumPacketsNotDecrypted);
  301. break;
  302. case IDS_STATS_QM_PKT_NOT_AUTH:
  303. st.Format(_T("%u"), IpsecStats.m_dwNumPacketsNotAuthenticated);
  304. break;
  305. case IDS_STATS_QM_PKT_REPLAY:
  306. st.Format(_T("%u"), IpsecStats.m_dwNumPacketsWithReplayDetection);
  307. break;
  308. case IDS_STATS_QM_ESP_BYTE_SENT:
  309. st.Format(_T("%I64u"), IpsecStats.m_uConfidentialBytesSent);
  310. break;
  311. case IDS_STATS_QM_ESP_BYTE_RCV:
  312. st.Format(_T("%I64u"), IpsecStats.m_uConfidentialBytesReceived);
  313. break;
  314. case IDS_STATS_QM_AUTH_BYTE_SENT:
  315. st.Format(_T("%I64u"), IpsecStats.m_uAuthenticatedBytesSent);
  316. break;
  317. case IDS_STATS_QM_ATTH_BYTE_RCV:
  318. st.Format(_T("%I64u"), IpsecStats.m_uAuthenticatedBytesReceived);
  319. break;
  320. case IDS_STATS_QM_XPORT_BYTE_SENT:
  321. st.Format(_T("%I64u"), IpsecStats.m_uTransportBytesSent);
  322. break;
  323. case IDS_STATS_QM_XPORT_BYTE_RCV:
  324. st.Format(_T("%I64u"), IpsecStats.m_uTransportBytesReceived);
  325. break;
  326. case IDS_STATS_QM_TNL_BYTE_SENT:
  327. st.Format(_T("%I64u"), IpsecStats.m_uBytesSentInTunnels);
  328. break;
  329. case IDS_STATS_QM_TNL_BYTE_RCV:
  330. st.Format(_T("%I64u"), IpsecStats.m_uBytesReceivedInTunnels);
  331. break;
  332. case IDS_STATS_QM_OFFLOAD_BYTE_SENT:
  333. st.Format(_T("%I64u"), IpsecStats.m_uOffloadedBytesSent);
  334. break;
  335. case IDS_STATS_QM_OFFLOAD_BYTE_RCV:
  336. st.Format(_T("%I64u"), IpsecStats.m_uOffloadedBytesReceived);
  337. break;
  338. }
  339. m_listIpsecStats.SetItemText(i, 1, (LPCTSTR) st);
  340. }
  341. }
  342. void
  343. CIpsecStats::SetColumns(CListCtrl * plistCtrl)
  344. {
  345. CString st;
  346. int nWidth;
  347. st.LoadString(IDS_STATS_DATA);
  348. nWidth = plistCtrl->GetStringWidth(st) + 15;
  349. plistCtrl->InsertColumn(1, st, LVCFMT_LEFT, nWidth);
  350. RECT rect;
  351. plistCtrl->GetWindowRect(&rect);
  352. nWidth = rect.right - rect.left - nWidth - 20;
  353. st.LoadString(IDS_STATS_NAME);
  354. plistCtrl->InsertColumn(0, st, LVCFMT_LEFT, nWidth);
  355. }