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.

1106 lines
34 KiB

  1. /*++
  2. Copyright (c) 1999, Microsoft Corporation
  3. Module Name:
  4. routing\netsh\ip\protocols\msdpcfg.c
  5. Abstract:
  6. Multicast Source Discovery Protocol configuration implementation.
  7. This module contains configuration routines which are relied upon
  8. by msdpopt.c. The routines retrieve, update, and display
  9. the configuration for the MSDP protocol.
  10. This file also contains default configuration settings
  11. for MSDP.
  12. N.B. The display routines require special attention since display
  13. may result in a list of commands sent to a 'dump' file, or in a
  14. textual presentation of the configuration to a console window.
  15. In the latter case, we use non-localizable output routines to generate
  16. a script-like description of the configuration. In the former case,
  17. we use localizable routines to generate a human-readable description.
  18. Author:
  19. Dave Thaler (dthaler) 21-May-1999
  20. Revision History:
  21. --*/
  22. #include "precomp.h"
  23. #pragma hdrstop
  24. #ifndef HAVE_INTSOCK
  25. # include <nhapi.h>
  26. # include <rpc.h>
  27. #endif
  28. #define MSDP_DEFAULT_KEEPALIVE 30 // suggested value in RFC 1771
  29. #define MSDP_DEFAULT_SAHOLDDOWN 30 // should be 30 per MSDP spec
  30. #define MSDP_DEFAULT_CONNECTRETRY 120 // suggested value in RFC 1771
  31. #define MSDP_DEFAULT_CACHE_LIFETIME 120 // should be >=90 seconds per MSDP spec
  32. #define MSDP_DEFAULT_ENCAPSULATION MSDP_ENCAPS_NONE // XXX
  33. #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
  34. #define REALLOC(x,y) HeapReAlloc(GetProcessHeap(), 0, (x), (y))
  35. #define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
  36. static MSDP_GLOBAL_CONFIG g_MsdpGlobalDefault =
  37. {
  38. MSDP_LOGGING_ERROR,
  39. 0, // flags
  40. MSDP_DEFAULT_KEEPALIVE,
  41. MSDP_DEFAULT_CONNECTRETRY,
  42. MSDP_DEFAULT_CACHE_LIFETIME,
  43. MSDP_DEFAULT_SAHOLDDOWN
  44. };
  45. typedef enum {
  46. CommonLoggingIndex = 0,
  47. CommonBooleanIndex,
  48. MsdpEncapsIndex
  49. } DISPLAY_VALUE_INDEX;
  50. VALUE_STRING MsdpEncapsStringArray[] = {
  51. MSDP_ENCAPS_NONE, STRING_NONE,
  52. };
  53. VALUE_TOKEN MsdpEncapsTokenArray[] = {
  54. MSDP_ENCAPS_NONE, TOKEN_OPT_VALUE_NONE,
  55. };
  56. static PUCHAR g_pMsdpGlobalDefault = (PUCHAR)&g_MsdpGlobalDefault;
  57. static MSDP_IPV4_PEER_CONFIG g_MsdpPeerDefault =
  58. {
  59. 0, 0, 0, 0, 0, MSDP_ENCAPS_DEFAULT
  60. };
  61. //
  62. // Forward declarations
  63. //
  64. ULONG
  65. ValidateMsdpPeerInfo(
  66. PMSDP_IPV4_PEER_CONFIG PeerInfo
  67. );
  68. //
  69. // What follows are the arrays used to map values to strings and
  70. // to map values to tokens. These, respectively, are used in the case
  71. // where we are displaying to a 'dump' file and to a console window.
  72. //
  73. VALUE_STRING MsdpGlobalLoggingStringArray[] = {
  74. MSDP_LOGGING_NONE, STRING_LOGGING_NONE,
  75. MSDP_LOGGING_ERROR, STRING_LOGGING_ERROR,
  76. MSDP_LOGGING_WARN, STRING_LOGGING_WARN,
  77. MSDP_LOGGING_INFO, STRING_LOGGING_INFO
  78. };
  79. VALUE_TOKEN MsdpGlobalLoggingTokenArray[] = {
  80. MSDP_LOGGING_NONE, TOKEN_OPT_VALUE_NONE,
  81. MSDP_LOGGING_ERROR, TOKEN_OPT_VALUE_ERROR,
  82. MSDP_LOGGING_WARN, TOKEN_OPT_VALUE_WARN,
  83. MSDP_LOGGING_INFO, TOKEN_OPT_VALUE_INFO
  84. };
  85. //
  86. // Allocate a global info block containing the default information
  87. //
  88. // Called by: HandleMsdpInstall()
  89. //
  90. ULONG
  91. MakeMsdpGlobalConfig(
  92. OUT PUCHAR* ppGlobalInfo,
  93. OUT PULONG pulGlobalInfoSize
  94. )
  95. {
  96. *pulGlobalInfoSize = sizeof(MSDP_GLOBAL_CONFIG);
  97. *ppGlobalInfo = MALLOC(*pulGlobalInfoSize);
  98. if (!*ppGlobalInfo) {
  99. DisplayMessage(g_hModule, EMSG_NOT_ENOUGH_MEMORY);
  100. return ERROR_NOT_ENOUGH_MEMORY;
  101. }
  102. CopyMemory(*ppGlobalInfo, g_pMsdpGlobalDefault, sizeof(MSDP_GLOBAL_CONFIG));
  103. return NO_ERROR;
  104. }
  105. #if 0
  106. //
  107. // Update global parameters
  108. //
  109. // Called by: HandleMsdpSetGlobal()
  110. //
  111. ULONG
  112. CreateMsdpGlobalInfo(
  113. OUT PMSDP_GLOBAL_CONFIG* pGlobalInfo,
  114. IN DWORD dwLoggingLevel
  115. )
  116. {
  117. DWORD dwGlobalInfoSize;
  118. dwGlobalInfoSize = sizeof(PMSDP_GLOBAL_CONFIG);
  119. *pGlobalInfo = MALLOC(dwGlobalInfoSize);
  120. if (!*pGlobalInfo) {
  121. DisplayMessage(g_hModule, EMSG_NOT_ENOUGH_MEMORY);
  122. return ERROR_NOT_ENOUGH_MEMORY;
  123. }
  124. CopyMemory(*pGlobalInfo, g_pMsdpGlobalDefault, dwGlobalInfoSize);
  125. (*pGlobalInfo)->dwLoggingLevel = dwLoggingLevel;
  126. return NO_ERROR;
  127. }
  128. #endif
  129. //
  130. // Called by: MsdpHandleAddPeer()
  131. //
  132. ULONG
  133. MakeMsdpIPv4PeerConfig(
  134. OUT PMSDP_IPV4_PEER_CONFIG *ppPeer
  135. )
  136. {
  137. ULONG ulSize = sizeof(MSDP_IPV4_PEER_CONFIG);
  138. *ppPeer = MALLOC(ulSize);
  139. if (!*ppPeer) {
  140. return ERROR_NOT_ENOUGH_MEMORY;
  141. }
  142. CopyMemory(*ppPeer, &g_MsdpPeerDefault, ulSize);
  143. return NO_ERROR;
  144. }
  145. DWORD
  146. MsdpAddIPv4PeerInterface(
  147. IN LPCWSTR pwszMachineName,
  148. IN LPCWSTR pwszInterfaceName,
  149. IN PMSDP_IPV4_PEER_CONFIG pPeer
  150. )
  151. {
  152. DWORD dwErr = NO_ERROR;
  153. do {
  154. dwErr = IpmontrCreateInterface(pwszMachineName, pwszInterfaceName,
  155. pPeer->ipLocalAddress,
  156. pPeer->ipRemoteAddress,
  157. 1);
  158. if (dwErr isnot NO_ERROR)
  159. {
  160. break;
  161. }
  162. dwErr = SetMsdpInterfaceConfig( pwszInterfaceName, pPeer );
  163. } while (FALSE);
  164. return dwErr;
  165. }
  166. #if 0
  167. DWORD
  168. MsdpAddIPv4PeerConfig(
  169. IN PMSDP_IPV4_PEER_CONFIG pPeer
  170. )
  171. {
  172. PMSDP_GLOBAL_CONFIG pGlobal = NULL, pNewGlobal;
  173. DWORD dwErr;
  174. ULONG ulV4PeerCount, ulSize, i;
  175. PMSDP_FAMILY_CONFIG pFamily;
  176. do {
  177. dwErr = GetMsdpGlobalConfig( &pGlobal );
  178. if (dwErr isnot NO_ERROR)
  179. {
  180. break;
  181. }
  182. pFamily = MSDP_FIRST_FAMILY(pGlobal);
  183. // Check for duplicate
  184. for (i=0; (i<pFamily->usNumPeers) and
  185. (pFamily->pPeer[i].ipRemoteAddress isnot pPeer->ipRemoteAddress); i++);
  186. if (i<pFamily->usNumPeers)
  187. {
  188. dwErr = ERROR_OBJECT_ALREADY_EXISTS;
  189. break;
  190. }
  191. ulV4PeerCount = pFamily->usNumPeers++;
  192. ulSize = MSDP_GLOBAL_CONFIG_SIZE(ulV4PeerCount+1);
  193. pNewGlobal = REALLOC( pGlobal, ulSize );
  194. if (!pNewGlobal)
  195. {
  196. dwErr = GetLastError();
  197. break;
  198. }
  199. pGlobal = pNewGlobal;
  200. pFamily = MSDP_FIRST_FAMILY(pGlobal);
  201. memcpy( &pFamily->pPeer[ulV4PeerCount],
  202. pPeer,
  203. sizeof(MSDP_IPV4_PEER_CONFIG) );
  204. // DisplayMessageT(L"remoteaddr=%1!x!\n",
  205. // pFamily->pPeer[ulV4PeerCount].ipRemoteAddress);
  206. dwErr = SetMsdpGlobalConfig( pGlobal );
  207. } while (FALSE);
  208. if (pGlobal)
  209. {
  210. FREE(pGlobal);
  211. }
  212. return dwErr;
  213. }
  214. #endif
  215. #if 0
  216. //
  217. // Called by: XXX
  218. //
  219. ULONG
  220. MakeMsdpFamilyInfo(
  221. IN OUT PUCHAR pFamily
  222. )
  223. {
  224. //
  225. // Always assume that the space has been preassigned
  226. //
  227. if (!pFamily) {
  228. return ERROR_INVALID_PARAMETER;
  229. }
  230. CopyMemory(pFamily,&g_MsdpFamilyDefault,sizeof(g_MsdpFamilyDefault));
  231. return NO_ERROR;
  232. }
  233. #endif
  234. PTCHAR
  235. MsdpQueryValueString(
  236. DWORD dwFormat,
  237. DISPLAY_VALUE_INDEX Index,
  238. ULONG Value
  239. )
  240. {
  241. ULONG Count;
  242. DWORD dwErr;
  243. PTCHAR String = NULL;
  244. PVALUE_STRING StringArray;
  245. PVALUE_TOKEN TokenArray;
  246. switch (Index) {
  247. case CommonLoggingIndex:
  248. Count = COMMON_LOGGING_SIZE;
  249. StringArray = CommonLoggingStringArray;
  250. TokenArray = CommonLoggingTokenArray;
  251. break;
  252. case CommonBooleanIndex:
  253. Count = COMMON_BOOLEAN_SIZE;
  254. StringArray = CommonBooleanStringArray;
  255. TokenArray = CommonBooleanTokenArray;
  256. break;
  257. case MsdpEncapsIndex:
  258. Count = MSDP_ENCAPS_SIZE;
  259. StringArray = MsdpEncapsStringArray;
  260. TokenArray = MsdpEncapsTokenArray;
  261. break;
  262. default:
  263. return NULL;
  264. }
  265. dwErr = GetAltDisplayString( g_hModule,
  266. (HANDLE)(dwFormat is FORMAT_DUMP),
  267. Value,
  268. TokenArray,
  269. StringArray,
  270. Count,
  271. &String );
  272. return (dwErr)? NULL : String;
  273. }
  274. DWORD
  275. GetMsdpInterfaceConfig(
  276. IN LPCWSTR pwszInterfaceName,
  277. OUT PMSDP_IPV4_PEER_CONFIG *ppConfigInfo
  278. )
  279. {
  280. DWORD dwErr, dwIfType;
  281. ULONG ulSize, ulCount;
  282. //
  283. // Retrieve the interface configuration for MSDP
  284. //
  285. dwErr = IpmontrGetInfoBlockFromInterfaceInfo( pwszInterfaceName,
  286. MS_IP_MSDP,
  287. (PUCHAR*)ppConfigInfo,
  288. &ulSize,
  289. &ulCount,
  290. &dwIfType );
  291. if (dwErr isnot NO_ERROR) {
  292. return dwErr;
  293. } else if (!(ulCount * ulSize)) {
  294. return ERROR_NOT_FOUND;
  295. }
  296. return NO_ERROR;
  297. }
  298. DWORD
  299. GetMsdpGlobalConfig(
  300. PMSDP_GLOBAL_CONFIG *ppGlobalInfo
  301. )
  302. {
  303. DWORD dwErr;
  304. ULONG ulSize, ulCount;
  305. //
  306. // Retrieve the global configuration for MSDP,
  307. //
  308. dwErr = IpmontrGetInfoBlockFromGlobalInfo( MS_IP_MSDP,
  309. (PUCHAR*)ppGlobalInfo,
  310. &ulSize,
  311. &ulCount );
  312. if (dwErr isnot NO_ERROR) {
  313. return dwErr;
  314. } else if (!(ulCount * ulSize)) {
  315. return ERROR_NOT_FOUND;
  316. }
  317. return NO_ERROR;
  318. }
  319. DWORD
  320. SetMsdpInterfaceConfig(
  321. PWCHAR pwszInterfaceName,
  322. PMSDP_IPV4_PEER_CONFIG pConfigInfo
  323. )
  324. {
  325. DWORD dwErr;
  326. ULONG ulSize, ulV4PeerCount;
  327. WCHAR wszIfName[MAX_INTERFACE_NAME_LEN+1];
  328. ulSize = sizeof(wszIfName);
  329. dwErr = IpmontrGetIfNameFromFriendlyName(pwszInterfaceName,
  330. wszIfName,
  331. &ulSize);
  332. if (dwErr isnot NO_ERROR)
  333. {
  334. return dwErr;
  335. }
  336. //
  337. // Save the interface configuration for MSDP
  338. //
  339. ulSize = sizeof(MSDP_IPV4_PEER_CONFIG);
  340. dwErr = IpmontrSetInfoBlockInInterfaceInfo( wszIfName,
  341. MS_IP_MSDP,
  342. (PUCHAR)pConfigInfo,
  343. ulSize,
  344. 1 );
  345. return dwErr;
  346. }
  347. DWORD
  348. SetMsdpGlobalConfig(
  349. PMSDP_GLOBAL_CONFIG pGlobalInfo
  350. )
  351. {
  352. DWORD dwErr;
  353. ULONG ulSize;
  354. //
  355. // Save the global configuration for MSDP,
  356. //
  357. ulSize = sizeof(MSDP_GLOBAL_CONFIG);
  358. dwErr = IpmontrSetInfoBlockInGlobalInfo( MS_IP_MSDP,
  359. (PUCHAR)pGlobalInfo,
  360. ulSize,
  361. 1 );
  362. return dwErr;
  363. }
  364. ULONG
  365. ShowMsdpGlobalInfo(
  366. DWORD dwFormat
  367. )
  368. {
  369. ULONG ulCount = 0;
  370. DWORD dwErr;
  371. PMSDP_GLOBAL_CONFIG pGlobalInfo = NULL;
  372. ULONG i;
  373. PWCHAR pwszLoggingLevel = NULL,
  374. pwszAcceptAll = NULL;
  375. ULONG ulSize;
  376. do {
  377. dwErr = GetMsdpGlobalConfig(&pGlobalInfo);
  378. if (dwErr) {
  379. break;
  380. }
  381. pwszLoggingLevel = MsdpQueryValueString( dwFormat,
  382. CommonLoggingIndex,
  383. pGlobalInfo->dwLoggingLevel );
  384. pwszAcceptAll = MsdpQueryValueString( dwFormat,
  385. CommonBooleanIndex,
  386. (pGlobalInfo->dwFlags & MSDP_GLOBAL_FLAG_ACCEPT_ALL) );
  387. if (dwFormat is FORMAT_DUMP)
  388. {
  389. DisplayMessageT( DMP_INSTALL );
  390. DisplayMessageT( DMP_MSDP_SET_GLOBAL );
  391. if (pwszLoggingLevel) {
  392. DisplayMessageT( DMP_MSDP_STRING_ARGUMENT,
  393. TOKEN_OPT_LOGGINGLEVEL, pwszLoggingLevel );
  394. }
  395. DisplayMessageT( DMP_MSDP_INTEGER_ARGUMENT,
  396. TOKEN_OPT_KEEPALIVE, pGlobalInfo->ulDefKeepAlive);
  397. DisplayMessageT( DMP_MSDP_INTEGER_ARGUMENT,
  398. TOKEN_OPT_SAHOLDDOWN,pGlobalInfo->ulSAHolddown);
  399. DisplayMessageT( DMP_MSDP_INTEGER_ARGUMENT,
  400. TOKEN_OPT_CONNECTRETRY,
  401. pGlobalInfo->ulDefConnectRetry);
  402. DisplayMessageT( DMP_MSDP_STRING_ARGUMENT,
  403. TOKEN_OPT_ACCEPTALL,
  404. pwszAcceptAll);
  405. DisplayMessageT( DMP_MSDP_INTEGER_ARGUMENT,
  406. TOKEN_OPT_CACHELIFETIME,
  407. pGlobalInfo->ulCacheLifetime);
  408. DisplayMessageT( MSG_NEWLINE );
  409. }
  410. else
  411. {
  412. DisplayMessage( g_hModule,
  413. MSG_MSDP_GLOBAL_INFO,
  414. pwszLoggingLevel,
  415. pGlobalInfo->ulDefKeepAlive,
  416. pGlobalInfo->ulSAHolddown,
  417. pGlobalInfo->ulDefConnectRetry,
  418. pwszAcceptAll,
  419. pGlobalInfo->ulCacheLifetime );
  420. }
  421. } while(FALSE);
  422. if (pwszLoggingLevel) { FREE(pwszLoggingLevel); }
  423. if (pGlobalInfo) { FREE(pGlobalInfo); }
  424. if ((dwFormat isnot FORMAT_DUMP) and (dwErr isnot NO_ERROR))
  425. {
  426. if (dwErr == ERROR_NOT_FOUND) {
  427. DisplayMessage(g_hModule, EMSG_PROTO_NO_GLOBAL_INFO);
  428. } else {
  429. DisplayError(g_hModule, dwErr);
  430. }
  431. }
  432. return dwErr;
  433. }
  434. ULONG
  435. MsdpPeerKeepAlive(
  436. IN PMSDP_GLOBAL_CONFIG pGlobal,
  437. IN PMSDP_IPV4_PEER_CONFIG pPeer
  438. )
  439. {
  440. if (pPeer->dwConfigFlags & MSDP_PEER_CONFIG_KEEPALIVE)
  441. {
  442. return pPeer->ulKeepAlive;
  443. }
  444. return pGlobal->ulDefKeepAlive;
  445. }
  446. ULONG
  447. MsdpPeerConnectRetry(
  448. IN PMSDP_GLOBAL_CONFIG pGlobal,
  449. IN PMSDP_IPV4_PEER_CONFIG pPeer
  450. )
  451. {
  452. if (pPeer->dwConfigFlags & MSDP_PEER_CONFIG_CONNECTRETRY)
  453. {
  454. return pPeer->ulConnectRetry;
  455. }
  456. return pGlobal->ulDefConnectRetry;
  457. }
  458. PWCHAR
  459. MsdpPeerFlags(
  460. IN PMSDP_IPV4_PEER_CONFIG pPeer
  461. )
  462. {
  463. static WCHAR wszString[33];
  464. wszString[0] = (pPeer->dwConfigFlags & MSDP_PEER_CONFIG_CONNECTRETRY)? L'R' : L' ';
  465. wszString[1] = (pPeer->dwConfigFlags & MSDP_PEER_CONFIG_KEEPALIVE) ? L'K' : L' ';
  466. wszString[2] = (pPeer->dwConfigFlags & MSDP_PEER_CONFIG_CACHING) ? L'C' : L' ';
  467. wszString[3] = (pPeer->dwConfigFlags & MSDP_PEER_CONFIG_DEFAULTPEER) ? L'D' : L' ';
  468. wszString[4] = (pPeer->dwConfigFlags & MSDP_PEER_CONFIG_PASSIVE) ? L'P' : L' ';
  469. wszString[5] = 0;
  470. return wszString;
  471. }
  472. //
  473. // Called by: HandleMsdpShowPeer()
  474. //
  475. DWORD
  476. ShowMsdpPeerInfo(
  477. IN DWORD dwFormat,
  478. IN LPCWSTR pwszPeerAddress OPTIONAL,
  479. IN LPCWSTR pwszPeerName OPTIONAL
  480. )
  481. {
  482. DWORD dwErr, dwTotal;
  483. PMSDP_IPV4_PEER_CONFIG pPeer;
  484. ULONG i, ulNumInterfaces, ulCount = 0;
  485. WCHAR wszRemoteAddress[20];
  486. WCHAR wszLocalAddress[20];
  487. PWCHAR pwszEncapsMethod;
  488. PMPR_INTERFACE_0 pmi0 = NULL;
  489. PMSDP_GLOBAL_CONFIG pGlobalInfo = NULL;
  490. WCHAR wszFriendlyName[MAX_INTERFACE_NAME_LEN+1];
  491. DWORD dwSize = sizeof(wszFriendlyName);
  492. dwErr = GetMsdpGlobalConfig(&pGlobalInfo);
  493. if (dwErr isnot NO_ERROR)
  494. {
  495. return dwErr;
  496. }
  497. do {
  498. //
  499. // Retrieve the peer's configuration
  500. // and format it to the output file or console.
  501. //
  502. dwErr = IpmontrInterfaceEnum((PBYTE *) &pmi0,
  503. &ulNumInterfaces,
  504. &dwTotal);
  505. if (dwErr isnot NO_ERROR)
  506. {
  507. return dwErr;
  508. }
  509. for (i=0; i<ulNumInterfaces; i++)
  510. {
  511. dwErr = IpmontrGetFriendlyNameFromIfName(pmi0[i].wszInterfaceName,
  512. wszFriendlyName, &dwSize);
  513. if (pwszPeerName
  514. and wcscmp(pwszPeerName, wszFriendlyName))
  515. {
  516. continue;
  517. }
  518. dwErr = GetMsdpInterfaceConfig(pmi0[i].wszInterfaceName, &pPeer);
  519. if (dwErr isnot NO_ERROR)
  520. {
  521. continue;
  522. }
  523. IP_TO_TSTR(wszRemoteAddress, &pPeer->ipRemoteAddress);
  524. if (pwszPeerAddress
  525. and wcscmp(pwszPeerAddress, wszRemoteAddress))
  526. {
  527. FREE(pPeer);
  528. continue;
  529. }
  530. if ((ulCount is 0) and (dwFormat is FORMAT_TABLE))
  531. {
  532. DisplayMessage( g_hModule, MSG_MSDP_PEER_HEADER );
  533. }
  534. IP_TO_TSTR(wszLocalAddress, &pPeer->ipLocalAddress);
  535. pwszEncapsMethod = MsdpQueryValueString( dwFormat,
  536. MsdpEncapsIndex,
  537. pPeer->dwEncapsMethod );
  538. if (dwFormat is FORMAT_DUMP) {
  539. DisplayMessageT(DMP_MSDP_ADD_PEER);
  540. DisplayMessageT(DMP_MSDP_STRING_ARGUMENT,
  541. TOKEN_OPT_NAME, wszFriendlyName);
  542. DisplayMessageT(DMP_MSDP_STRING_ARGUMENT,
  543. TOKEN_OPT_REMADDR, wszRemoteAddress);
  544. if (pPeer->ipLocalAddress)
  545. {
  546. DisplayMessageT(DMP_MSDP_STRING_ARGUMENT,
  547. TOKEN_OPT_LOCALADDR, wszLocalAddress);
  548. }
  549. if (pPeer->dwConfigFlags & MSDP_PEER_CONFIG_KEEPALIVE)
  550. {
  551. DisplayMessageT(DMP_MSDP_INTEGER_ARGUMENT,
  552. TOKEN_OPT_KEEPALIVE, pPeer->ulKeepAlive);
  553. }
  554. if (pPeer->dwConfigFlags & MSDP_PEER_CONFIG_CONNECTRETRY)
  555. {
  556. DisplayMessageT(DMP_MSDP_INTEGER_ARGUMENT,
  557. TOKEN_OPT_CONNECTRETRY,
  558. pPeer->ulConnectRetry);
  559. }
  560. if (pPeer->dwConfigFlags & MSDP_PEER_CONFIG_CACHING)
  561. {
  562. DisplayMessageT(DMP_MSDP_STRING_ARGUMENT,
  563. TOKEN_OPT_CACHING,
  564. TOKEN_OPT_VALUE_YES);
  565. }
  566. if (pPeer->dwConfigFlags & MSDP_PEER_CONFIG_DEFAULTPEER)
  567. {
  568. DisplayMessageT(DMP_MSDP_STRING_ARGUMENT,
  569. TOKEN_OPT_DEFAULTPEER,
  570. TOKEN_OPT_VALUE_YES);
  571. }
  572. if (pPeer->dwEncapsMethod isnot MSDP_DEFAULT_ENCAPSULATION)
  573. {
  574. DisplayMessageT(DMP_MSDP_STRING_ARGUMENT,
  575. TOKEN_OPT_ENCAPSMETHOD,
  576. pwszEncapsMethod);
  577. }
  578. DisplayMessageT(MSG_NEWLINE);
  579. } else {
  580. DWORD dwId = (dwFormat is FORMAT_TABLE)? MSG_MSDP_PEER_INFO :
  581. MSG_MSDP_PEER_INFO_EX;
  582. DisplayMessage( g_hModule,
  583. dwId,
  584. wszRemoteAddress,
  585. wszLocalAddress,
  586. MsdpPeerKeepAlive(pGlobalInfo, pPeer),
  587. MsdpPeerConnectRetry(pGlobalInfo, pPeer),
  588. MsdpPeerFlags(pPeer),
  589. pwszEncapsMethod,
  590. wszFriendlyName);
  591. }
  592. FREE(pPeer);
  593. ulCount++;
  594. }
  595. } while(FALSE);
  596. FREE(pGlobalInfo);
  597. if ((dwFormat isnot FORMAT_DUMP) && dwErr) {
  598. if (dwErr == ERROR_NOT_FOUND) {
  599. DisplayMessage(g_hModule, EMSG_PROTO_NO_IF_INFO);
  600. } else {
  601. DisplayError(g_hModule, dwErr);
  602. }
  603. }
  604. if (pmi0)
  605. {
  606. FREE(pmi0);
  607. }
  608. if ((dwFormat is FORMAT_TABLE) and (ulCount is 0) and (dwErr is NO_ERROR))
  609. {
  610. DisplayMessage(g_hModule, MSG_MSDP_NO_PEER_INFO);
  611. }
  612. return dwErr;
  613. }
  614. #if 0
  615. ULONG
  616. UpdateMsdpGlobalInfo(
  617. PMSDP_GLOBAL_CONFIG GlobalInfo
  618. )
  619. {
  620. ULONG Count;
  621. ULONG Error;
  622. PMSDP_GLOBAL_CONFIG NewGlobalInfo = NULL;
  623. PMSDP_GLOBAL_CONFIG OldGlobalInfo = NULL;
  624. ULONG Size;
  625. do {
  626. //
  627. // Retrieve the existing global configuration.
  628. //
  629. Error =
  630. IpmontrGetInfoBlockFromGlobalInfo(
  631. MS_IP_MSDP,
  632. (PUCHAR*)&OldGlobalInfo,
  633. &Size,
  634. &Count
  635. );
  636. if (Error) {
  637. break;
  638. } else if (!(Count * Size)) {
  639. Error = ERROR_NOT_FOUND; break;
  640. }
  641. //
  642. // Allocate a new structure, copy to it the original configuration,
  643. //
  644. NewGlobalInfo = MALLOC(Count * Size);
  645. if (!NewGlobalInfo) { Error = ERROR_NOT_ENOUGH_MEMORY; break; }
  646. CopyMemory(NewGlobalInfo, OldGlobalInfo, Count * Size);
  647. //
  648. // Based on the changes requested, change the NewGlobalInfo.
  649. // Since for MSDP there is only the logging level to change, we just set that.
  650. //
  651. NewGlobalInfo->dwLoggingLevel = GlobalInfo->dwLoggingLevel;
  652. Error =
  653. IpmontrSetInfoBlockInGlobalInfo(
  654. MS_IP_MSDP,
  655. (PUCHAR)NewGlobalInfo,
  656. FIELD_OFFSET(IP_NAT_GLOBAL_INFO, Header) +
  657. Size,
  658. 1
  659. );
  660. } while(FALSE);
  661. if (NewGlobalInfo) { FREE(NewGlobalInfo); }
  662. if (OldGlobalInfo) { FREE(OldGlobalInfo); }
  663. if (Error == ERROR_NOT_FOUND) {
  664. DisplayMessage(g_hModule, EMSG_PROTO_NO_GLOBAL_INFO);
  665. } else if (Error) {
  666. DisplayError(g_hModule, Error);
  667. }
  668. return Error;
  669. }
  670. #endif
  671. #if 0
  672. ULONG
  673. UpdateMsdpPeerInfo(
  674. PWCHAR PeerName,
  675. PMSDP_FAMILY_CONFIG pFamily,
  676. ULONG BitVector,
  677. BOOL AddPeer
  678. )
  679. {
  680. ULONG Count;
  681. ULONG Error;
  682. PMSDP_IPV4_PEER_CONFIG NewPeerInfo = NULL;
  683. PMSDP_IPV4_PEER_CONFIG OldPeerInfo = NULL;
  684. ULONG Size;
  685. ROUTER_INTERFACE_TYPE Type;
  686. ULONG i;
  687. if (!AddPeer && !BitVector) { return NO_ERROR; }
  688. do {
  689. //
  690. // Retrieve the existing interface configuration.
  691. // We will update this block below, as well as adding to or removing
  692. // from it depending on the flags specified in 'BitVector'.
  693. //
  694. Error =
  695. GetInfoBlockFromPeerInfo(
  696. PeerName,
  697. MS_IP_MSDP,
  698. (PUCHAR*)&OldPeerInfo,
  699. &Size,
  700. &Count,
  701. &Type
  702. );
  703. if (Error) {
  704. //
  705. // No existing configuration is found. This is an error unless
  706. // we are adding the interface anew, in which case we just
  707. // create for ourselves a block containing the default settings.
  708. //
  709. if (!AddPeer) {
  710. break;
  711. } else {
  712. Error = GetPeerType(PeerName, &Type);
  713. if (Error) {
  714. break;
  715. } else {
  716. Count = 1;
  717. Error =
  718. MakeMsdpPeerInfo(
  719. Type, (PUCHAR*)&OldPeerInfo, &Size
  720. );
  721. if (Error) { break; }
  722. }
  723. }
  724. } else {
  725. //
  726. // There is configuration on the interface. If it is empty this is
  727. // an error. If this is an add interface, and the info exists, it is
  728. // an error.
  729. //
  730. if (!(Count * Size) && !AddPeer) {
  731. Error = ERROR_NOT_FOUND; break;
  732. }
  733. else if (AddPeer) {
  734. //
  735. // We were asked to add an interface which already exists
  736. //
  737. DisplayMessage(g_hModule, EMSG_INTERFACE_EXISTS, PeerName);
  738. Error = ERROR_INVALID_PARAMETER;
  739. break;
  740. }
  741. }
  742. if (!BitVector) {
  743. //
  744. // Just add this interface without any additional info.
  745. //
  746. DWORD OldSize;
  747. if (NewPeerInfo == NULL){
  748. NewPeerInfo = MALLOC((OldSize=GetMsdpPeerInfoSize(OldPeerInfo))+
  749. sizeof(MSDP_VROUTER_CONFIG));
  750. if (!NewPeerInfo) {
  751. DisplayMessage(g_hModule, EMSG_NOT_ENOUGH_MEMORY);
  752. Error = ERROR_NOT_ENOUGH_MEMORY;
  753. break;
  754. }
  755. }
  756. CopyMemory(NewPeerInfo,OldPeerInfo,OldSize);
  757. }
  758. else{
  759. if (!AddPeer || (OldPeerInfo->VrouterCount != 0)) {
  760. //
  761. // There is a prexisting VRID set. Check for this VRID in the list and then
  762. // update it if required.
  763. //
  764. ASSERT(BitVector & MSDP_INTF_VRID_MASK);
  765. for (i = 0, PVrouter = MSDP_FIRST_VROUTER_CONFIG(OldPeerInfo);
  766. i < OldPeerInfo->VrouterCount;
  767. i++, PVrouter = MSDP_NEXT_VROUTER_CONFIG(PVrouter)) {
  768. if (PVrouter->VRID == VRouterInfo->VRID) {
  769. break;
  770. }
  771. }
  772. if (i == OldPeerInfo->VrouterCount) {
  773. //
  774. // This is a new VRID, Add it.
  775. //
  776. DWORD OldSize;
  777. //
  778. // The IP address should be valid or else this is a set op.
  779. //
  780. if (!(BitVector & MSDP_INTF_IPADDR_MASK)){
  781. DisplayMessage(
  782. g_hModule, EMSG_INVALID_VRID,
  783. VRouterInfo->VRID
  784. );
  785. Error = ERROR_INVALID_PARAMETER;
  786. break;
  787. }
  788. if (NewPeerInfo == NULL){
  789. NewPeerInfo = MALLOC((OldSize=GetMsdpPeerInfoSize(
  790. OldPeerInfo))+
  791. sizeof(MSDP_VROUTER_CONFIG));
  792. if (!NewPeerInfo) {
  793. DisplayMessage(g_hModule, EMSG_NOT_ENOUGH_MEMORY);
  794. Error = ERROR_NOT_ENOUGH_MEMORY;
  795. break;
  796. }
  797. }
  798. CopyMemory(NewPeerInfo, OldPeerInfo, OldSize);
  799. PVrouter = (PMSDP_VROUTER_CONFIG)((PBYTE)NewPeerInfo+OldSize);
  800. CopyMemory(PVrouter,VRouterInfo,sizeof(MSDP_VROUTER_CONFIG));
  801. NewPeerInfo->VrouterCount++;
  802. //
  803. // Check if we own the IP address given. If yes, set the priority.
  804. //
  805. PVrouter->ConfigPriority =
  806. FoundIpAddress(PVrouter->IPAddress[0]) ? 255 : 100;
  807. }
  808. else{
  809. //
  810. // This is an old VRID. Its priority should not need to be changed.
  811. //
  812. DWORD Offset, OldSize;
  813. if(BitVector & MSDP_INTF_IPADDR_MASK) {
  814. if ( ((PVrouter->ConfigPriority != 255) &&
  815. (FoundIpAddress(VRouterInfo->IPAddress[0]))
  816. )
  817. ||
  818. ((PVrouter->ConfigPriority == 255) &&
  819. (!FoundIpAddress(VRouterInfo->IPAddress[0])))
  820. ) {
  821. DisplayMessage(g_hModule, EMSG_BAD_OPTION_VALUE);
  822. Error = ERROR_INVALID_PARAMETER;
  823. break;
  824. }
  825. //
  826. // Add this IP address to the VRID specified.
  827. //
  828. if (NewPeerInfo == NULL){
  829. NewPeerInfo = MALLOC((OldSize = GetMsdpPeerInfoSize(
  830. OldPeerInfo))+
  831. sizeof(DWORD));
  832. if (!NewPeerInfo) {
  833. DisplayMessage(g_hModule, EMSG_NOT_ENOUGH_MEMORY);
  834. Error = ERROR_NOT_ENOUGH_MEMORY;
  835. break;
  836. }
  837. }
  838. //
  839. // Shift all the VROUTER configs after the PVrouter by 1 DWORD.
  840. //
  841. Offset = (PUCHAR) MSDP_NEXT_VROUTER_CONFIG(PVrouter) -
  842. (PUCHAR) OldPeerInfo;
  843. CopyMemory(NewPeerInfo, OldPeerInfo, OldSize);
  844. for (i = 0, PVrouter = MSDP_FIRST_VROUTER_CONFIG(NewPeerInfo);
  845. i < NewPeerInfo->VrouterCount;
  846. i++, PVrouter = MSDP_NEXT_VROUTER_CONFIG(PVrouter)) {
  847. if (PVrouter->VRID == VRouterInfo->VRID) {
  848. break;
  849. }
  850. }
  851. ASSERT(i < NewPeerInfo->VrouterCount);
  852. PVrouter->IPAddress[PVrouter->IPCount++] = VRouterInfo->IPAddress[0];
  853. ASSERT(((PUCHAR)NewPeerInfo+Offset+sizeof(DWORD)) ==
  854. (PUCHAR) MSDP_NEXT_VROUTER_CONFIG(PVrouter));
  855. CopyMemory(MSDP_NEXT_VROUTER_CONFIG(PVrouter),
  856. OldPeerInfo+Offset, OldSize-Offset);
  857. } else {
  858. //
  859. // Set the new info block as the old info block and point to the
  860. // vrouter block
  861. //
  862. if (NewPeerInfo == NULL){
  863. NewPeerInfo = MALLOC((OldSize = GetMsdpPeerInfoSize(
  864. OldPeerInfo)));
  865. if (!NewPeerInfo) {
  866. DisplayMessage(g_hModule, EMSG_NOT_ENOUGH_MEMORY);
  867. Error = ERROR_NOT_ENOUGH_MEMORY;
  868. break;
  869. }
  870. }
  871. CopyMemory(NewPeerInfo, OldPeerInfo, OldSize);
  872. for (i = 0, PVrouter = MSDP_FIRST_VROUTER_CONFIG(NewPeerInfo);
  873. i < NewPeerInfo->VrouterCount;
  874. i++, PVrouter = MSDP_NEXT_VROUTER_CONFIG(PVrouter)) {
  875. if (PVrouter->VRID == VRouterInfo->VRID) {
  876. break;
  877. }
  878. }
  879. ASSERT(i < NewPeerInfo->VrouterCount);
  880. }
  881. if (BitVector & MSDP_INTF_AUTH_MASK) {
  882. PVrouter->AuthenticationType = VRouterInfo->AuthenticationType;
  883. }
  884. if (BitVector & MSDP_INTF_PASSWD_MASK) {
  885. CopyMemory(PVrouter->AuthenticationData,
  886. VRouterInfo->AuthenticationData,
  887. MSDP_MAX_AUTHKEY_SIZE);
  888. }
  889. if (BitVector & MSDP_INTF_ADVT_MASK) {
  890. PVrouter->AdvertisementPeer= VRouterInfo->AdvertisementPeer
  891. }
  892. if (BitVector & MSDP_INTF_PRIO_MASK) {
  893. PVrouter->ConfigPriority = VRouterInfo->ConfigPriority;
  894. }
  895. if (BitVector & MSDP_INTF_PREEMPT_MASK) {
  896. PVrouter->PreemptMode = VRouterInfo->PreemptMode;
  897. }
  898. }
  899. }
  900. }
  901. ValidateMsdpPeerInfo(NewPeerInfo);
  902. Error =
  903. SetInfoBlockInPeerInfo(
  904. PeerName,
  905. MS_IP_MSDP,
  906. (PUCHAR)NewPeerInfo,
  907. GetMsdpPeerInfoSize(NewPeerInfo),
  908. 1
  909. );
  910. } while(FALSE);
  911. if (NewPeerInfo) { FREE(NewPeerInfo); }
  912. if (OldPeerInfo) { FREE(OldPeerInfo); }
  913. if (Error == ERROR_NOT_FOUND) {
  914. DisplayMessage(g_hModule, EMSG_PROTO_NO_IF_INFO);
  915. } else if (Error) {
  916. DisplayError(g_hModule, Error);
  917. }
  918. return Error;
  919. }
  920. #endif
  921. #if 0
  922. DWORD
  923. MsdpDeleteIPv4PeerConfig(
  924. IPV4_ADDRESS ipAddr
  925. )
  926. /*++
  927. Called by: HandleMsdpDeletePeer()
  928. --*/
  929. {
  930. DWORD dwErr = NO_ERROR;
  931. ULONG ulV4PeerCount;
  932. PMSDP_IPV4_PEER_CONFIG NewPeerInfo = NULL;
  933. PMSDP_IPV4_PEER_CONFIG OldPeerInfo = NULL;
  934. ULONG Size;
  935. ULONG i;
  936. do {
  937. dwErr = GetMsdpGlobalConfig(&pGlobal);
  938. if (dwErr isnot NO_ERROR) {
  939. break;
  940. }
  941. pFamily = MSDP_FIRST_FAMILY(pGlobal);
  942. for (i=0; (i < pFamily->usNumPeers)
  943. && (pFamily->pPeer[i].ipRemoteAddress isnot ipAddr); i++);
  944. if (i is pFamily->usNumPeers)
  945. {
  946. return ERROR_NOT_FOUND;
  947. }
  948. // Shift every after 'i' up one position (overlapping copy)
  949. i++;
  950. memcpy( &pFamily->pPeer[i-1],
  951. &pFamily->pPeer[i],
  952. (pFamily->usNumPeers-i) * sizeof(MSDP_IPV4_PEER_CONFIG) );
  953. pFamily->usNumPeers--;
  954. dwErr = SetMsdpGlobalConfig( pGlobal );
  955. } while (FALSE);
  956. if (pGlobal)
  957. {
  958. FREE(pGlobal);
  959. }
  960. return dwErr;
  961. }
  962. #endif
  963. ULONG
  964. ValidateMsdpPeerInfo(
  965. PMSDP_IPV4_PEER_CONFIG PeerInfo
  966. )
  967. {
  968. return NO_ERROR;
  969. }
  970. #if 0
  971. DWORD
  972. GetMsdpPeerInfoSize(
  973. PMSDP_IPV4_PEER_CONFIG PeerInfo
  974. )
  975. {
  976. DWORD Size = 0;
  977. ULONG i;
  978. PMSDP_VROUTER_CONFIG pvr;
  979. Size += sizeof(PeerInfo->VrouterCount);
  980. for (i = 0, pvr = MSDP_FIRST_VROUTER_CONFIG(PeerInfo);
  981. i < PeerInfo->VrouterCount;
  982. i++,pvr = MSDP_NEXT_VROUTER_CONFIG(pvr)) {
  983. Size += MSDP_VROUTER_CONFIG_SIZE(pvr);
  984. }
  985. return Size;
  986. }
  987. #endif