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.

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