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.

1887 lines
58 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. tfflts.c
  5. Abstract:
  6. IPX Router Console Monitoring and Configuration tool.
  7. Traffic Filters configuration and monitoring.
  8. Author:
  9. Vadim Eydelman 06/07/1996
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #define OPERATION_DEL_TRAFFICFILTER (-1)
  14. #define OPERATION_SET_TRAFFICFILTER 0
  15. #define OPERATION_ADD_TRAFFICFILTER 1
  16. DWORD
  17. ReadTfFltDef (
  18. int argc,
  19. WCHAR *argv[],
  20. PIPX_TRAFFIC_FILTER_INFO pTfFlt
  21. );
  22. BOOL
  23. TfFltEqual (
  24. PVOID Info1,
  25. PVOID Info2
  26. );
  27. VOID
  28. PrintTrafficFilterInfo (
  29. PIPX_TRAFFIC_FILTER_GLOBAL_INFO pTfGlb,
  30. PIPX_TRAFFIC_FILTER_INFO pTfFlt,
  31. ULONG count,
  32. PWCHAR wszIfName,
  33. PWCHAR wszMode,
  34. BOOL bDump
  35. );
  36. DWORD
  37. AdmSetTfFlt (
  38. int operation,
  39. LPWSTR InterfaceNameW,
  40. ULONG Action,
  41. ULONG Mode,
  42. PIPX_TRAFFIC_FILTER_INFO TfFlt
  43. );
  44. DWORD
  45. CfgSetTfFlt (
  46. int operation,
  47. LPWSTR InterfaceNameW,
  48. ULONG Action,
  49. ULONG Mode,
  50. PIPX_TRAFFIC_FILTER_INFO TfFlt
  51. );
  52. int
  53. APIENTRY
  54. HelpTfFlt (
  55. IN int argc,
  56. IN WCHAR *argv[]
  57. )
  58. {
  59. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_TRAFFICFILTER);
  60. return 0;
  61. }
  62. int
  63. APIENTRY
  64. ShowTfFlt (
  65. IN int argc,
  66. IN WCHAR *argv[],
  67. IN BOOL bDump
  68. )
  69. {
  70. WCHAR IfName[ MAX_INTERFACE_NAME_LEN + 1 ];
  71. DWORD rc, dwSize = sizeof(IfName);
  72. if (argc > 0)
  73. {
  74. LPBYTE pIfBlock;
  75. BOOLEAN fRouter = FALSE, fClient = FALSE;
  76. ULONG mode = 0;
  77. PWCHAR buffer[2];
  78. unsigned count;
  79. #define InterfaceNameW argv[0]
  80. count = wcslen (InterfaceNameW);
  81. if ( ( count > 0 ) && ( count <= MAX_INTERFACE_NAME_LEN ) )
  82. {
  83. fClient = FALSE;
  84. }
  85. else
  86. {
  87. if ( !bDump )
  88. {
  89. DisplayIPXMessage (g_hModule, MSG_INVALID_INTERFACE_NAME);
  90. }
  91. rc = ERROR_INVALID_PARAMETER;
  92. goto Exit;
  93. }
  94. if (argc > 1)
  95. {
  96. UINT n;
  97. if ( (argc == 2) &&
  98. !MatchEnumTag(
  99. g_hModule, argv[1], NUM_TOKENS_IN_TABLE( FilterModes ),
  100. FilterModes, &mode
  101. ) )
  102. {
  103. NOTHING;
  104. }
  105. else
  106. {
  107. if ( !bDump )
  108. {
  109. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_TRAFFICFILTER );
  110. }
  111. rc = ERROR_INVALID_PARAMETER;
  112. goto Exit;
  113. }
  114. }
  115. if (g_hMprAdmin)
  116. {
  117. if (fClient)
  118. {
  119. DWORD sz;
  120. rc = MprAdminTransportGetInfo (
  121. g_hMprAdmin, PID_IPX, NULL, NULL, &pIfBlock, &sz
  122. );
  123. if (rc == NO_ERROR)
  124. {
  125. fRouter = TRUE;
  126. }
  127. else
  128. {
  129. if ( !bDump )
  130. {
  131. DisplayError( g_hModule, rc );
  132. }
  133. goto GetFromCfg;
  134. }
  135. }
  136. else
  137. {
  138. HANDLE hIfAdm;
  139. //======================================
  140. // Translate the Interface Name
  141. //======================================
  142. rc = IpmontrGetIfNameFromFriendlyName(
  143. InterfaceNameW, IfName, &dwSize
  144. );
  145. if ( rc == NO_ERROR )
  146. {
  147. //======================================
  148. rc = MprAdminInterfaceGetHandle(
  149. g_hMprAdmin, IfName, &hIfAdm, FALSE
  150. );
  151. if (rc == NO_ERROR)
  152. {
  153. DWORD sz;
  154. rc = MprAdminInterfaceTransportGetInfo(
  155. g_hMprAdmin, hIfAdm, PID_IPX, &pIfBlock, &sz
  156. );
  157. }
  158. if (rc == NO_ERROR)
  159. {
  160. fRouter = TRUE;
  161. }
  162. else
  163. {
  164. if ( !bDump )
  165. {
  166. DisplayError( g_hModule, rc);
  167. }
  168. goto GetFromCfg;
  169. }
  170. }
  171. else
  172. {
  173. if ( !bDump )
  174. {
  175. DisplayError( g_hModule, rc );
  176. }
  177. }
  178. }
  179. }
  180. else
  181. {
  182. GetFromCfg:
  183. if (fClient)
  184. {
  185. HANDLE hTrCfg;
  186. rc = MprConfigTransportGetHandle(
  187. g_hMprConfig, PID_IPX, &hTrCfg
  188. );
  189. if (rc == NO_ERROR)
  190. {
  191. DWORD sz;
  192. rc = MprConfigTransportGetInfo(
  193. g_hMprConfig, hTrCfg, NULL, NULL, &pIfBlock,
  194. &sz, NULL
  195. );
  196. }
  197. }
  198. else
  199. {
  200. HANDLE hIfCfg;
  201. //======================================
  202. // Translate the Interface Name
  203. //======================================
  204. rc = IpmontrGetIfNameFromFriendlyName(
  205. InterfaceNameW, IfName, &dwSize
  206. );
  207. if ( rc == NO_ERROR )
  208. {
  209. rc = MprConfigInterfaceGetHandle(
  210. g_hMprConfig, IfName, &hIfCfg
  211. );
  212. if (rc == NO_ERROR)
  213. {
  214. HANDLE hIfTrCfg;
  215. rc = MprConfigInterfaceTransportGetHandle(
  216. g_hMprConfig, hIfCfg, PID_IPX, &hIfTrCfg
  217. );
  218. if (rc == NO_ERROR)
  219. {
  220. DWORD sz;
  221. rc = MprConfigInterfaceTransportGetInfo(
  222. g_hMprConfig, hIfCfg, hIfTrCfg, &pIfBlock, &sz
  223. );
  224. }
  225. }
  226. }
  227. else
  228. {
  229. if ( !bDump )
  230. {
  231. DisplayError( g_hModule, rc );
  232. }
  233. }
  234. }
  235. }
  236. if ( rc == NO_ERROR )
  237. {
  238. PIPX_TOC_ENTRY pTfToc;
  239. PIPX_TOC_ENTRY pTfGlToc;
  240. if ((mode == 0) || (mode == OUTPUT_FILTER))
  241. {
  242. pTfToc = GetIPXTocEntry (
  243. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  244. IPX_OUT_TRAFFIC_FILTER_INFO_TYPE
  245. );
  246. pTfGlToc = GetIPXTocEntry (
  247. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  248. IPX_OUT_TRAFFIC_FILTER_GLOBAL_INFO_TYPE
  249. );
  250. if ((pTfToc != NULL) && (pTfGlToc != NULL))
  251. {
  252. PIPX_TRAFFIC_FILTER_GLOBAL_INFO pTfGlb =
  253. (PIPX_TRAFFIC_FILTER_GLOBAL_INFO)
  254. (pIfBlock + pTfGlToc->Offset);
  255. buffer[ 0 ] = GetEnumString(
  256. g_hModule, OUTPUT_FILTER,
  257. NUM_TOKENS_IN_TABLE( FilterModes ),
  258. FilterModes
  259. );
  260. buffer[ 1 ] = GetEnumString(
  261. g_hModule, pTfGlb->FilterAction,
  262. NUM_TOKENS_IN_TABLE( TfFilterActions ),
  263. TfFilterActions
  264. );
  265. if ( buffer[ 0 ] && buffer [ 1 ] )
  266. {
  267. if ( bDump )
  268. {
  269. DisplayMessageT(
  270. DMP_IPX_SET_FILTER, InterfaceNameW,
  271. buffer[0], buffer[1]
  272. );
  273. }
  274. else
  275. {
  276. DisplayIPXMessage (
  277. g_hModule, MSG_TRAFFICFILTER_TABLE_HDR,
  278. buffer[0], buffer[1]
  279. );
  280. }
  281. PrintTrafficFilterInfo (
  282. (PIPX_TRAFFIC_FILTER_GLOBAL_INFO)
  283. (pIfBlock + pTfGlToc->Offset),
  284. (PIPX_TRAFFIC_FILTER_INFO)
  285. (pIfBlock + pTfToc->Offset),
  286. pTfToc->Count,
  287. InterfaceNameW,
  288. buffer[ 0 ],
  289. bDump
  290. );
  291. }
  292. }
  293. else
  294. {
  295. buffer[ 0 ] = GetEnumString(
  296. g_hModule, OUTPUT_FILTER,
  297. NUM_TOKENS_IN_TABLE( FilterModes ),
  298. FilterModes
  299. );
  300. buffer[ 1 ] = VAL_DENY;
  301. if ( buffer[ 0 ] && buffer[ 1 ] )
  302. {
  303. if ( bDump )
  304. {
  305. DisplayMessageT(
  306. DMP_IPX_SET_FILTER, InterfaceNameW,
  307. buffer[ 0 ], buffer[ 1 ]
  308. );
  309. }
  310. else
  311. {
  312. DisplayIPXMessage(
  313. g_hModule, MSG_TRAFFICFILTER_TABLE_HDR,
  314. buffer[0], buffer[1]
  315. );
  316. }
  317. }
  318. }
  319. }
  320. if ((mode == 0) || (mode == INPUT_FILTER))
  321. {
  322. pTfToc = GetIPXTocEntry(
  323. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  324. IPX_IN_TRAFFIC_FILTER_INFO_TYPE
  325. );
  326. pTfGlToc = GetIPXTocEntry(
  327. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  328. IPX_IN_TRAFFIC_FILTER_GLOBAL_INFO_TYPE
  329. );
  330. if ((pTfToc != NULL) && (pTfGlToc != NULL))
  331. {
  332. PIPX_TRAFFIC_FILTER_GLOBAL_INFO pTfGlb =
  333. (PIPX_TRAFFIC_FILTER_GLOBAL_INFO)
  334. (pIfBlock + pTfGlToc->Offset);
  335. buffer[ 0 ] = GetEnumString(
  336. g_hModule, INPUT_FILTER,
  337. NUM_TOKENS_IN_TABLE( FilterModes ),
  338. FilterModes
  339. );
  340. buffer[ 1 ] = GetEnumString(
  341. g_hModule, pTfGlb->FilterAction,
  342. NUM_TOKENS_IN_TABLE( TfFilterActions ),
  343. TfFilterActions
  344. );
  345. if ( buffer[ 0 ] && buffer[ 1 ] )
  346. {
  347. if ( bDump )
  348. {
  349. DisplayMessageT(
  350. DMP_IPX_SET_FILTER, InterfaceNameW,
  351. buffer[0], buffer[1]
  352. );
  353. }
  354. else
  355. {
  356. DisplayIPXMessage(
  357. g_hModule, MSG_TRAFFICFILTER_TABLE_HDR,
  358. buffer[0], buffer[1]
  359. );
  360. }
  361. PrintTrafficFilterInfo (
  362. (PIPX_TRAFFIC_FILTER_GLOBAL_INFO)
  363. (pIfBlock + pTfGlToc->Offset),
  364. (PIPX_TRAFFIC_FILTER_INFO)
  365. (pIfBlock + pTfToc->Offset),
  366. pTfToc->Count,
  367. InterfaceNameW,
  368. buffer[ 0 ],
  369. bDump
  370. );
  371. }
  372. }
  373. else
  374. {
  375. buffer[ 0 ] = GetEnumString(
  376. g_hModule, INPUT_FILTER,
  377. NUM_TOKENS_IN_TABLE( FilterModes ),
  378. FilterModes
  379. );
  380. buffer[ 1 ] = VAL_DENY;
  381. if ( buffer[ 0 ] && buffer[ 1 ] )
  382. {
  383. if ( bDump )
  384. {
  385. DisplayMessageT(
  386. DMP_IPX_SET_FILTER, InterfaceNameW,
  387. buffer[ 0 ], buffer[ 1 ]
  388. );
  389. }
  390. else
  391. {
  392. DisplayIPXMessage(
  393. g_hModule, MSG_TRAFFICFILTER_TABLE_HDR,
  394. buffer[0], buffer[1]
  395. );
  396. }
  397. }
  398. }
  399. }
  400. if (fRouter)
  401. {
  402. MprAdminBufferFree (pIfBlock);
  403. }
  404. else
  405. {
  406. MprConfigBufferFree (pIfBlock);
  407. }
  408. }
  409. else
  410. {
  411. if ( !bDump )
  412. {
  413. DisplayError( g_hModule, rc);
  414. }
  415. }
  416. }
  417. else
  418. {
  419. if ( !bDump )
  420. {
  421. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_TRAFFICFILTER);
  422. }
  423. rc = ERROR_INVALID_PARAMETER;
  424. }
  425. Exit:
  426. return rc ;
  427. #undef InterfaceNameW
  428. }
  429. int
  430. APIENTRY
  431. SetTfFlt (
  432. IN int argc,
  433. IN WCHAR *argv[]
  434. )
  435. {
  436. DWORD rc = NO_ERROR;
  437. if (argc == 3)
  438. {
  439. BOOL fClient;
  440. ULONG mode, action;
  441. unsigned count;
  442. PWCHAR buffer;
  443. #define InterfaceNameW argv[0]
  444. count = wcslen (InterfaceNameW);
  445. #if 0 // Disable client interface filters for BETA
  446. if (_wcsicmp (argv[0],
  447. GetString (g_hModule, VAL_DIALINCLIENT, buffer)) == 0)
  448. {
  449. fClient = TRUE;
  450. }
  451. #endif
  452. if ( ( count > 0 ) && ( count <= MAX_INTERFACE_NAME_LEN ) )
  453. {
  454. fClient = FALSE;
  455. }
  456. else
  457. {
  458. DisplayIPXMessage (g_hModule, MSG_INVALID_INTERFACE_NAME);
  459. rc = ERROR_INVALID_PARAMETER;
  460. goto Exit;
  461. }
  462. if ( !MatchEnumTag(
  463. g_hModule, argv[1], NUM_TOKENS_IN_TABLE( FilterModes ),
  464. FilterModes, &mode
  465. ) &&
  466. !MatchEnumTag(
  467. g_hModule, argv[2], NUM_TOKENS_IN_TABLE( TfFilterActions ),
  468. TfFilterActions, &action
  469. ) )
  470. {
  471. if (g_hMprAdmin)
  472. {
  473. rc = AdmSetTfFlt(
  474. OPERATION_SET_TRAFFICFILTER,
  475. fClient ? NULL : InterfaceNameW, action,
  476. mode, NULL
  477. );
  478. }
  479. else
  480. {
  481. rc = NO_ERROR;
  482. }
  483. if (rc == NO_ERROR)
  484. {
  485. rc = CfgSetTfFlt(
  486. OPERATION_SET_TRAFFICFILTER,
  487. fClient ? NULL : InterfaceNameW, action,
  488. mode, NULL
  489. );
  490. }
  491. }
  492. else
  493. {
  494. rc = ERROR_INVALID_PARAMETER;
  495. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_TRAFFICFILTER);
  496. }
  497. }
  498. else
  499. {
  500. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_TRAFFICFILTER);
  501. rc = ERROR_INVALID_PARAMETER;
  502. }
  503. Exit:
  504. return (rc == NO_ERROR) ? 0 : 1;
  505. #undef InterfaceNameW
  506. }
  507. int
  508. APIENTRY
  509. CreateTfFlt (
  510. IN int argc,
  511. IN WCHAR *argv[]
  512. )
  513. {
  514. DWORD rc = NO_ERROR;
  515. if (argc > 1)
  516. {
  517. IPX_TRAFFIC_FILTER_INFO TfFlt;
  518. ULONG mode;
  519. BOOL fClient;
  520. PWCHAR buffer;
  521. unsigned count;
  522. #define InterfaceNameW argv[0]
  523. count = wcslen (InterfaceNameW);
  524. #if 0 // Disable client interface filters for BETA
  525. if (_wcsicmp (argv[0],
  526. GetString (g_hModule, VAL_DIALINCLIENT, buffer)) == 0)
  527. {
  528. fClient = TRUE;
  529. }
  530. else
  531. #endif
  532. if ((count > 0) && (count <= MAX_INTERFACE_NAME_LEN))
  533. {
  534. fClient = FALSE;
  535. }
  536. else
  537. {
  538. DisplayIPXMessage (g_hModule, MSG_INVALID_INTERFACE_NAME);
  539. rc = ERROR_INVALID_PARAMETER;
  540. goto Exit;
  541. }
  542. if ( !MatchEnumTag(
  543. g_hModule, argv[1], NUM_TOKENS_IN_TABLE( FilterModes ),
  544. FilterModes, &mode
  545. ) &&
  546. ( ReadTfFltDef( argc - 2, &argv[2], &TfFlt) == NO_ERROR ) )
  547. {
  548. if (g_hMprAdmin)
  549. {
  550. rc = AdmSetTfFlt(
  551. OPERATION_ADD_TRAFFICFILTER,
  552. fClient ? NULL : InterfaceNameW,
  553. IPX_TRAFFIC_FILTER_ACTION_DENY,
  554. mode, &TfFlt
  555. );
  556. }
  557. else
  558. {
  559. rc = NO_ERROR;
  560. }
  561. if (rc == NO_ERROR)
  562. {
  563. rc = CfgSetTfFlt(
  564. OPERATION_ADD_TRAFFICFILTER,
  565. fClient ? NULL : InterfaceNameW,
  566. IPX_TRAFFIC_FILTER_ACTION_DENY,
  567. mode, &TfFlt
  568. );
  569. }
  570. }
  571. else
  572. {
  573. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_TRAFFICFILTER);
  574. }
  575. }
  576. else
  577. {
  578. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_TRAFFICFILTER);
  579. rc = ERROR_INVALID_PARAMETER;
  580. }
  581. Exit:
  582. return rc ;
  583. #undef InterfaceNameW
  584. }
  585. int
  586. APIENTRY
  587. DeleteTfFlt (
  588. IN int argc,
  589. IN WCHAR *argv[]
  590. )
  591. {
  592. DWORD rc = NO_ERROR;
  593. if (argc > 1)
  594. {
  595. IPX_TRAFFIC_FILTER_INFO TfFlt;
  596. ULONG mode;
  597. BOOL fClient;
  598. PWCHAR buffer;
  599. unsigned count;
  600. #define InterfaceNameW argv[0]
  601. count = wcslen (InterfaceNameW);
  602. #if 0 // Disable client interface filters for BETA
  603. if (_tcsicmp (argv[0],
  604. GetString (g_hModule, VAL_DIALINCLIENT, buffer)) == 0)
  605. {
  606. fClient = TRUE;
  607. }
  608. #endif
  609. if ( (count > 0) && (count <= MAX_INTERFACE_NAME_LEN) )
  610. {
  611. fClient = FALSE;
  612. }
  613. else
  614. {
  615. DisplayIPXMessage (g_hModule, MSG_INVALID_INTERFACE_NAME);
  616. rc = ERROR_INVALID_PARAMETER;
  617. goto Exit;
  618. }
  619. if ( !MatchEnumTag(
  620. g_hModule, argv[1], NUM_TOKENS_IN_TABLE( FilterModes ),
  621. FilterModes, &mode
  622. ) &&
  623. ( ReadTfFltDef (argc - 2, &argv[2], &TfFlt) == NO_ERROR ) )
  624. {
  625. if (g_hMprAdmin)
  626. {
  627. rc = AdmSetTfFlt(
  628. OPERATION_DEL_TRAFFICFILTER,
  629. fClient ? NULL : InterfaceNameW,
  630. IPX_TRAFFIC_FILTER_ACTION_DENY,
  631. mode, &TfFlt
  632. );
  633. }
  634. else
  635. {
  636. rc = NO_ERROR;
  637. }
  638. if (rc == NO_ERROR)
  639. {
  640. rc = CfgSetTfFlt(
  641. OPERATION_DEL_TRAFFICFILTER,
  642. fClient ? NULL : InterfaceNameW,
  643. IPX_TRAFFIC_FILTER_ACTION_DENY,
  644. mode, &TfFlt
  645. );
  646. }
  647. }
  648. else
  649. {
  650. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_TRAFFICFILTER);
  651. }
  652. }
  653. else
  654. {
  655. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_TRAFFICFILTER);
  656. rc = ERROR_INVALID_PARAMETER;
  657. }
  658. Exit:
  659. return rc ;
  660. #undef InterfaceNameW
  661. }
  662. DWORD
  663. ReadTfFltDef (
  664. int argc,
  665. WCHAR *argv[],
  666. PIPX_TRAFFIC_FILTER_INFO pTfFlt
  667. )
  668. {
  669. UINT n;
  670. USHORT val2;
  671. ULONG val41, val42;
  672. ULONGLONG val8;
  673. int i;
  674. pTfFlt->FilterDefinition = 0;
  675. for (i = 0; i < argc; i++)
  676. {
  677. if ( !_wcsicmp( argv[i], TOKEN_SRCNET ) )
  678. {
  679. if (!(pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_SRCNET)
  680. && (i < argc - 2)
  681. && ( swscanf (argv[i+1], L"%8lx%n", &val41, &n) == 1)
  682. && (n == wcslen (argv[i+1]))
  683. && ( swscanf (argv[i+2], L"%8lx%n", &val42, &n) == 1)
  684. && (n == wcslen (argv[i+2]))
  685. && ((val41 & val42) == val41))
  686. {
  687. i += 2;
  688. pTfFlt->SourceNetwork[0] = (BYTE)(val41 >> 24);
  689. pTfFlt->SourceNetwork[1] = (BYTE)(val41 >> 16);
  690. pTfFlt->SourceNetwork[2] = (BYTE)(val41 >> 8);
  691. pTfFlt->SourceNetwork[3] = (BYTE)val41;
  692. pTfFlt->SourceNetworkMask[0] = (BYTE)(val42 >> 24);
  693. pTfFlt->SourceNetworkMask[1] = (BYTE)(val42 >> 16);
  694. pTfFlt->SourceNetworkMask[2] = (BYTE)(val42 >> 8);
  695. pTfFlt->SourceNetworkMask[3] = (BYTE)val42;
  696. pTfFlt->FilterDefinition |= IPX_TRAFFIC_FILTER_ON_SRCNET;
  697. }
  698. else
  699. {
  700. break;
  701. }
  702. }
  703. else if ( !_wcsicmp (argv[i], TOKEN_SRCNODE ) )
  704. {
  705. if (!(pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_SRCNODE)
  706. && (i < argc - 1)
  707. && (swscanf (argv[i+1], L"%I64x%n", &val8, &n) == 1)
  708. && (n == wcslen (argv[i+1])))
  709. {
  710. i += 1;
  711. pTfFlt->SourceNode[0] = (BYTE)(val8 >> 40);
  712. pTfFlt->SourceNode[1] = (BYTE)(val8 >> 32);
  713. pTfFlt->SourceNode[2] = (BYTE)(val8 >> 24);
  714. pTfFlt->SourceNode[3] = (BYTE)(val8 >> 16);
  715. pTfFlt->SourceNode[4] = (BYTE)(val8 >> 8);
  716. pTfFlt->SourceNode[5] = (BYTE)val8;
  717. pTfFlt->FilterDefinition |= IPX_TRAFFIC_FILTER_ON_SRCNODE;
  718. }
  719. else
  720. {
  721. break;
  722. }
  723. }
  724. else if ( !_wcsicmp (argv[i], TOKEN_SRCSOCKET ))
  725. {
  726. if (!(pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_SRCSOCKET)
  727. && (i < argc - 1)
  728. && (swscanf (argv[i+1], L"%4hx%n", &val2, &n) == 1)
  729. && (n == wcslen (argv[i+1])))
  730. {
  731. i += 1;
  732. pTfFlt->SourceSocket[0] = (BYTE)(val2 >> 8);
  733. pTfFlt->SourceSocket[1] = (BYTE)val2;
  734. pTfFlt->FilterDefinition |= IPX_TRAFFIC_FILTER_ON_SRCSOCKET;
  735. }
  736. else
  737. {
  738. break;
  739. }
  740. }
  741. else if ( !_wcsicmp (argv[i], TOKEN_DSTNET ) )
  742. {
  743. if (!(pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_DSTNET)
  744. && (i < argc - 2)
  745. && (swscanf (argv[i+1], L"%8lx%n", &val41, &n) == 1)
  746. && (n == wcslen (argv[i+1]))
  747. && (swscanf (argv[i+2], L"%8lx%n", &val42, &n) == 1)
  748. && (n == wcslen (argv[i+2]))
  749. && ((val41 & val42) == val41))
  750. {
  751. i += 2;
  752. pTfFlt->DestinationNetwork[0] = (BYTE)(val41 >> 24);
  753. pTfFlt->DestinationNetwork[1] = (BYTE)(val41 >> 16);
  754. pTfFlt->DestinationNetwork[2] = (BYTE)(val41 >> 8);
  755. pTfFlt->DestinationNetwork[3] = (BYTE)val41;
  756. pTfFlt->DestinationNetworkMask[0] = (BYTE)(val42 >> 24);
  757. pTfFlt->DestinationNetworkMask[1] = (BYTE)(val42 >> 16);
  758. pTfFlt->DestinationNetworkMask[2] = (BYTE)(val42 >> 8);
  759. pTfFlt->DestinationNetworkMask[3] = (BYTE)val42;
  760. pTfFlt->FilterDefinition |= IPX_TRAFFIC_FILTER_ON_DSTNET;
  761. }
  762. else
  763. {
  764. break;
  765. }
  766. }
  767. else if ( !_wcsicmp( argv[i], TOKEN_DSTNODE ) )
  768. {
  769. if (!(pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_DSTNODE)
  770. && (swscanf (argv[i+1], L"%I64x%n", &val8, &n) == 1)
  771. && (n == wcslen (argv[i+1])))
  772. {
  773. i += 1;
  774. pTfFlt->DestinationNode[0] = (BYTE)(val8 >> 40);
  775. pTfFlt->DestinationNode[1] = (BYTE)(val8 >> 32);
  776. pTfFlt->DestinationNode[2] = (BYTE)(val8 >> 24);
  777. pTfFlt->DestinationNode[3] = (BYTE)(val8 >> 16);
  778. pTfFlt->DestinationNode[4] = (BYTE)(val8 >> 8);
  779. pTfFlt->DestinationNode[5] = (BYTE)val8;
  780. pTfFlt->FilterDefinition |= IPX_TRAFFIC_FILTER_ON_DSTNODE;
  781. }
  782. else
  783. {
  784. break;
  785. }
  786. }
  787. else if ( !_wcsicmp (argv[i], TOKEN_DSTSOCKET ))
  788. {
  789. if (!(pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_DSTSOCKET)
  790. && (i < argc - 1)
  791. && (swscanf (argv[i+1], L"%4hx%n", &val2, &n) == 1)
  792. && (n == wcslen (argv[i+1])))
  793. {
  794. i += 1;
  795. pTfFlt->DestinationSocket[0] = (BYTE)(val2 >> 8);
  796. pTfFlt->DestinationSocket[1] = (BYTE)val2;
  797. pTfFlt->FilterDefinition |= IPX_TRAFFIC_FILTER_ON_DSTSOCKET;
  798. }
  799. else
  800. {
  801. break;
  802. }
  803. }
  804. else if ( !_wcsicmp (argv[i], TOKEN_PKTTYPE))
  805. {
  806. if (!(pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_PKTTYPE)
  807. && (i < argc - 1)
  808. && (swscanf (argv[i+1], L"%2hx%n", &val2, &n) == 1)
  809. && (n == wcslen (argv[i+1])))
  810. {
  811. i += 1;
  812. pTfFlt->PacketType = (BYTE)val2;
  813. pTfFlt->FilterDefinition |= IPX_TRAFFIC_FILTER_ON_PKTTYPE;
  814. }
  815. else
  816. {
  817. break;
  818. }
  819. }
  820. else if ( !_wcsicmp (argv[i], TOKEN_LOGPACKETS ))
  821. {
  822. if (!(pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_LOG_MATCHES))
  823. {
  824. pTfFlt->FilterDefinition |= IPX_TRAFFIC_FILTER_LOG_MATCHES;
  825. }
  826. else
  827. {
  828. break;
  829. }
  830. }
  831. else if (!(pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_SRCNET))
  832. {
  833. if ((i < argc - 1)
  834. && (swscanf (argv[i], L"%8lx%n", &val41, &n) == 1)
  835. && (n == wcslen (argv[i]))
  836. && (swscanf (argv[i+1], L"%8lx%n", &val42, &n) == 1)
  837. && (n == wcslen (argv[i+1]))
  838. && ((val41 & val42) == val41))
  839. {
  840. i += 1;
  841. pTfFlt->SourceNetwork[0] = (BYTE)(val41 >> 24);
  842. pTfFlt->SourceNetwork[1] = (BYTE)(val41 >> 16);
  843. pTfFlt->SourceNetwork[2] = (BYTE)(val41 >> 8);
  844. pTfFlt->SourceNetwork[3] = (BYTE)val41;
  845. pTfFlt->SourceNetworkMask[0] = (BYTE)(val42 >> 24);
  846. pTfFlt->SourceNetworkMask[1] = (BYTE)(val42 >> 16);
  847. pTfFlt->SourceNetworkMask[2] = (BYTE)(val42 >> 8);
  848. pTfFlt->SourceNetworkMask[3] = (BYTE)val42;
  849. pTfFlt->FilterDefinition |= IPX_TRAFFIC_FILTER_ON_SRCNET;
  850. }
  851. else
  852. {
  853. break;
  854. }
  855. }
  856. else if (!(pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_SRCNODE))
  857. {
  858. if ((swscanf (argv[i], L"%12I64x%n", &val8, &n) == 1)
  859. && (n == wcslen (argv[i])))
  860. {
  861. pTfFlt->SourceNode[0] = (BYTE)(val8 >> 40);
  862. pTfFlt->SourceNode[1] = (BYTE)(val8 >> 32);
  863. pTfFlt->SourceNode[2] = (BYTE)(val8 >> 24);
  864. pTfFlt->SourceNode[3] = (BYTE)(val8 >> 16);
  865. pTfFlt->SourceNode[4] = (BYTE)(val8 >> 8);
  866. pTfFlt->SourceNode[5] = (BYTE)val8;
  867. pTfFlt->FilterDefinition |= IPX_TRAFFIC_FILTER_ON_SRCNODE;
  868. }
  869. else
  870. {
  871. break;
  872. }
  873. }
  874. else if (!(pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_SRCSOCKET))
  875. {
  876. if ((swscanf (argv[i], L"%4hx%n", &val2, &n) == 1)
  877. && (n == wcslen (argv[i])))
  878. {
  879. pTfFlt->SourceSocket[0] = (BYTE)(val2 >> 8);
  880. pTfFlt->SourceSocket[1] = (BYTE)val2;
  881. pTfFlt->FilterDefinition |= IPX_TRAFFIC_FILTER_ON_SRCSOCKET;
  882. }
  883. else
  884. {
  885. break;
  886. }
  887. }
  888. else if (!(pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_DSTNET))
  889. {
  890. if ((i < argc - 1)
  891. && (swscanf (argv[i], L"%8lx%n", &val41, &n) == 1)
  892. && (n == wcslen (argv[i]))
  893. && (swscanf (argv[i+1], L"%8lx%n", &val42, &n) == 1)
  894. && (n == wcslen (argv[i+1]))
  895. && ((val41 & val42) == val41))
  896. {
  897. i += 1;
  898. pTfFlt->DestinationNetwork[0] = (BYTE)(val41 >> 24);
  899. pTfFlt->DestinationNetwork[1] = (BYTE)(val41 >> 16);
  900. pTfFlt->DestinationNetwork[2] = (BYTE)(val41 >> 8);
  901. pTfFlt->DestinationNetwork[3] = (BYTE)val41;
  902. pTfFlt->DestinationNetworkMask[0] = (BYTE)(val42 >> 24);
  903. pTfFlt->DestinationNetworkMask[1] = (BYTE)(val42 >> 16);
  904. pTfFlt->DestinationNetworkMask[2] = (BYTE)(val42 >> 8);
  905. pTfFlt->DestinationNetworkMask[3] = (BYTE)val42;
  906. pTfFlt->FilterDefinition |= IPX_TRAFFIC_FILTER_ON_DSTNET;
  907. }
  908. else
  909. {
  910. break;
  911. }
  912. }
  913. else if (!(pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_DSTNODE))
  914. {
  915. if ((swscanf (argv[i], L"%12I64x%n", &val8, &n) == 1)
  916. && (n == wcslen (argv[i])))
  917. {
  918. pTfFlt->DestinationNode[0] = (BYTE)(val8 >> 40);
  919. pTfFlt->DestinationNode[1] = (BYTE)(val8 >> 32);
  920. pTfFlt->DestinationNode[2] = (BYTE)(val8 >> 24);
  921. pTfFlt->DestinationNode[3] = (BYTE)(val8 >> 16);
  922. pTfFlt->DestinationNode[4] = (BYTE)(val8 >> 8);
  923. pTfFlt->DestinationNode[5] = (BYTE)val8;
  924. pTfFlt->FilterDefinition |= IPX_TRAFFIC_FILTER_ON_DSTNODE;
  925. }
  926. else
  927. {
  928. break;
  929. }
  930. }
  931. else if (!(pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_DSTSOCKET))
  932. {
  933. if ((swscanf (argv[i], L"%4hx%n", &val2, &n) == 1)
  934. && (n == wcslen (argv[i])))
  935. {
  936. pTfFlt->DestinationSocket[0] = (BYTE)(val2 >> 8);
  937. pTfFlt->DestinationSocket[1] = (BYTE)val2;
  938. pTfFlt->FilterDefinition |= IPX_TRAFFIC_FILTER_ON_DSTSOCKET;
  939. }
  940. else
  941. {
  942. break;
  943. }
  944. }
  945. else if (!(pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_PKTTYPE))
  946. {
  947. if ((swscanf (argv[i], L"%2hx%n", &val2, &n) == 1)
  948. && (n == wcslen (argv[i])))
  949. {
  950. pTfFlt->PacketType = (BYTE)val2;
  951. pTfFlt->FilterDefinition |= IPX_TRAFFIC_FILTER_ON_PKTTYPE;
  952. }
  953. else
  954. {
  955. break;
  956. }
  957. }
  958. else
  959. {
  960. break;
  961. }
  962. }
  963. if (i == argc)
  964. {
  965. return NO_ERROR;
  966. }
  967. else
  968. {
  969. return ERROR_INVALID_PARAMETER;
  970. }
  971. }
  972. VOID
  973. PrintTrafficFilterInfo (
  974. PIPX_TRAFFIC_FILTER_GLOBAL_INFO pTfGlb,
  975. PIPX_TRAFFIC_FILTER_INFO pTfFlt,
  976. ULONG count,
  977. PWCHAR wszIfName,
  978. PWCHAR wszMode,
  979. BOOL bDump
  980. )
  981. {
  982. WCHAR wszDumpString[ 512 ];
  983. WCHAR wszDumpBuffer[ 64 ];
  984. WCHAR buffer[10][128];
  985. PWCHAR pBuffer[ 10 ];
  986. UINT i, j;
  987. for ( i = 0; i < count; i++, pTfFlt++ )
  988. {
  989. ZeroMemory( pBuffer, 10 * sizeof( PWCHAR ) );
  990. ZeroMemory( wszDumpString, 512 * sizeof( WCHAR ) );
  991. swprintf( wszDumpString, L"\"%s\" %s ", wszIfName, wszMode );
  992. if (pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_SRCNET)
  993. {
  994. pBuffer[ 0 ] = &buffer[ 0 ][ 0 ];
  995. pBuffer[ 1 ] = &buffer[ 1 ][ 0 ];
  996. swprintf (pBuffer[0], L"%.2x%.2x%.2x%.2x",
  997. pTfFlt->SourceNetwork[0], pTfFlt->SourceNetwork[1],
  998. pTfFlt->SourceNetwork[2], pTfFlt->SourceNetwork[3]
  999. );
  1000. swprintf (pBuffer[1], L"%.2x%.2x%.2x%.2x",
  1001. pTfFlt->SourceNetworkMask[0], pTfFlt->SourceNetworkMask[1],
  1002. pTfFlt->SourceNetworkMask[2], pTfFlt->SourceNetworkMask[3]
  1003. );
  1004. if ( bDump )
  1005. {
  1006. swprintf( wszDumpBuffer, L"srcnet = 0x%s 0x%s ", pBuffer[0], pBuffer[1] );
  1007. wcscat( wszDumpString, wszDumpBuffer );
  1008. }
  1009. }
  1010. else
  1011. {
  1012. pBuffer[ 0 ] = VAL_ANYNETWORK ;
  1013. pBuffer[ 1 ] = VAL_ANYNETWORK ;
  1014. }
  1015. if (pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_SRCNODE)
  1016. {
  1017. pBuffer[ 2 ] = &buffer[ 2 ][ 0 ];
  1018. swprintf (pBuffer[2], L"%.2x%.2x%.2x%.2x%.2x%.2x",
  1019. pTfFlt->SourceNode[0], pTfFlt->SourceNode[1],
  1020. pTfFlt->SourceNode[2], pTfFlt->SourceNode[3],
  1021. pTfFlt->SourceNode[4], pTfFlt->SourceNode[5]
  1022. );
  1023. if ( bDump )
  1024. {
  1025. swprintf( wszDumpBuffer, L"srcnode = 0x%s ", pBuffer[2] );
  1026. wcscat( wszDumpString, wszDumpBuffer );
  1027. }
  1028. }
  1029. else
  1030. {
  1031. pBuffer[ 2 ] = VAL_ANYNODE;
  1032. }
  1033. if (pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_SRCSOCKET)
  1034. {
  1035. pBuffer[ 3 ] = &buffer[ 3 ][ 0 ];
  1036. swprintf (pBuffer[3], L"%.2x%.2x",
  1037. pTfFlt->SourceSocket[0], pTfFlt->SourceSocket[1]
  1038. );
  1039. if ( bDump )
  1040. {
  1041. swprintf( wszDumpBuffer, L"srcsocket = 0x%s ", pBuffer[3] );
  1042. wcscat( wszDumpString, wszDumpBuffer );
  1043. }
  1044. }
  1045. else
  1046. {
  1047. pBuffer[ 3 ] = VAL_ANYSOCKET ;
  1048. }
  1049. if (pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_DSTNET)
  1050. {
  1051. pBuffer[ 4 ] = &buffer[ 4 ][ 0 ];
  1052. pBuffer[ 5 ] = &buffer[ 5 ][ 0 ];
  1053. swprintf(
  1054. pBuffer[4], L"%.2x%.2x%.2x%.2x",
  1055. pTfFlt->DestinationNetwork[0], pTfFlt->DestinationNetwork[1],
  1056. pTfFlt->DestinationNetwork[2], pTfFlt->DestinationNetwork[3]
  1057. );
  1058. swprintf (pBuffer[5], L"%.2x%.2x%.2x%.2x",
  1059. pTfFlt->DestinationNetworkMask[0], pTfFlt->DestinationNetworkMask[1],
  1060. pTfFlt->DestinationNetworkMask[2], pTfFlt->DestinationNetworkMask[3]
  1061. );
  1062. if ( bDump )
  1063. {
  1064. swprintf( wszDumpBuffer, L"dstnet = 0x%s 0x%s ", pBuffer[4], pBuffer[5] );
  1065. wcscat( wszDumpString, wszDumpBuffer );
  1066. }
  1067. }
  1068. else
  1069. {
  1070. pBuffer[ 4 ] = VAL_ANYNETWORK;
  1071. pBuffer[ 5 ] = VAL_ANYNETWORK;
  1072. }
  1073. if (pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_DSTNODE)
  1074. {
  1075. pBuffer[ 6 ] = &buffer[ 6 ][ 0 ];
  1076. swprintf (pBuffer[6], L"%.2x%.2x%.2x%.2x%.2x%.2x",
  1077. pTfFlt->DestinationNode[0], pTfFlt->DestinationNode[1],
  1078. pTfFlt->DestinationNode[2], pTfFlt->DestinationNode[3],
  1079. pTfFlt->DestinationNode[4], pTfFlt->DestinationNode[5]
  1080. );
  1081. if ( bDump )
  1082. {
  1083. swprintf( wszDumpBuffer, L"dstnode = 0x%s ", pBuffer[6] );
  1084. wcscat( wszDumpString, wszDumpBuffer );
  1085. }
  1086. }
  1087. else
  1088. {
  1089. pBuffer[ 6 ] = VAL_ANYNODE;
  1090. }
  1091. if (pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_DSTSOCKET)
  1092. {
  1093. pBuffer[ 7 ] = &buffer[ 7 ][ 0 ];
  1094. swprintf(pBuffer[7], L"%.2x%.2x",
  1095. pTfFlt->DestinationSocket[0], pTfFlt->DestinationSocket[1]
  1096. );
  1097. if ( bDump )
  1098. {
  1099. swprintf( wszDumpBuffer, L"dstsocket = 0x%s ", pBuffer[7] );
  1100. wcscat( wszDumpString, wszDumpBuffer );
  1101. }
  1102. }
  1103. else
  1104. {
  1105. pBuffer[ 7 ] = VAL_ANYSOCKET;
  1106. }
  1107. if (pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_ON_PKTTYPE)
  1108. {
  1109. pBuffer[ 8 ] = &buffer[ 8 ][ 0 ];
  1110. swprintf (pBuffer[8], L"%.2x", pTfFlt->PacketType);
  1111. if ( bDump )
  1112. {
  1113. swprintf( wszDumpBuffer, L"pkttype = 0x%s ", pBuffer[8] );
  1114. wcscat( wszDumpString, wszDumpBuffer );
  1115. }
  1116. }
  1117. else
  1118. {
  1119. pBuffer[ 8 ] = VAL_ANYPKTTYPE;
  1120. }
  1121. if (pTfFlt->FilterDefinition & IPX_TRAFFIC_FILTER_LOG_MATCHES)
  1122. {
  1123. pBuffer[ 9 ] = VAL_YES;
  1124. if ( bDump )
  1125. {
  1126. swprintf( wszDumpBuffer, L"log" );
  1127. wcscat( wszDumpString, wszDumpBuffer );
  1128. }
  1129. }
  1130. else
  1131. {
  1132. pBuffer[ 9 ] = VAL_NO;
  1133. }
  1134. if ( bDump )
  1135. {
  1136. DisplayMessageT( DMP_IPX_ADD_FILTER, wszDumpString );
  1137. }
  1138. else
  1139. {
  1140. DisplayIPXMessage (
  1141. g_hModule, MSG_TRAFFICFILTER_TABLE_FMT,
  1142. pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3], pBuffer[4], pBuffer[5],
  1143. pBuffer[6], pBuffer[7], pBuffer[8], pBuffer[9]
  1144. );
  1145. }
  1146. }
  1147. }
  1148. DWORD
  1149. AdmSetTfFlt (
  1150. int operation,
  1151. LPWSTR InterfaceNameW,
  1152. ULONG Action,
  1153. ULONG Mode,
  1154. PIPX_TRAFFIC_FILTER_INFO TfFlt
  1155. )
  1156. {
  1157. DWORD rc;
  1158. HANDLE hIfAdm;
  1159. LPBYTE pIfBlock;
  1160. DWORD sz;
  1161. WCHAR IfName[ MAX_INTERFACE_NAME_LEN + 1 ];
  1162. DWORD dwSize = sizeof(IfName);
  1163. if ( InterfaceNameW != NULL )
  1164. {
  1165. //======================================
  1166. // Translate the Interface Name
  1167. //======================================
  1168. rc = IpmontrGetIfNameFromFriendlyName(
  1169. InterfaceNameW, IfName, &dwSize
  1170. );
  1171. if ( rc == NO_ERROR )
  1172. {
  1173. rc = MprAdminInterfaceGetHandle(
  1174. g_hMprAdmin, IfName, &hIfAdm, FALSE
  1175. );
  1176. if (rc == NO_ERROR)
  1177. {
  1178. rc = MprAdminInterfaceTransportGetInfo(
  1179. g_hMprAdmin, hIfAdm, PID_IPX, &pIfBlock, &sz
  1180. );
  1181. }
  1182. }
  1183. }
  1184. else
  1185. {
  1186. rc = MprAdminTransportGetInfo (
  1187. g_hMprAdmin, PID_IPX, NULL, NULL, &pIfBlock, &sz
  1188. );
  1189. }
  1190. if (rc == NO_ERROR)
  1191. {
  1192. UINT msg;
  1193. LPBYTE pNewBlock = NULL;
  1194. switch (operation)
  1195. {
  1196. case OPERATION_ADD_TRAFFICFILTER:
  1197. rc = AddIPXInfoEntry (
  1198. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  1199. (Mode == OUTPUT_FILTER) ? IPX_OUT_TRAFFIC_FILTER_INFO_TYPE :
  1200. IPX_IN_TRAFFIC_FILTER_INFO_TYPE,
  1201. sizeof (*TfFlt),
  1202. TfFlt,
  1203. TfFltEqual,
  1204. (PIPX_INFO_BLOCK_HEADER * ) & pNewBlock
  1205. );
  1206. if (rc == NO_ERROR)
  1207. {
  1208. if (GetIPXTocEntry ((PIPX_INFO_BLOCK_HEADER)pIfBlock,
  1209. (Mode == OUTPUT_FILTER)
  1210. ? IPX_OUT_TRAFFIC_FILTER_GLOBAL_INFO_TYPE
  1211. : IPX_IN_TRAFFIC_FILTER_GLOBAL_INFO_TYPE) == NULL)
  1212. {
  1213. IPX_TRAFFIC_FILTER_GLOBAL_INFO GlInfo;
  1214. LPBYTE pNewNewBlock;
  1215. GlInfo.FilterAction = IPX_TRAFFIC_FILTER_ACTION_DENY;
  1216. rc = AddIPXInfoEntry (
  1217. (PIPX_INFO_BLOCK_HEADER)pNewBlock,
  1218. (Mode == OUTPUT_FILTER) ? IPX_OUT_TRAFFIC_FILTER_GLOBAL_INFO_TYPE :
  1219. IPX_IN_TRAFFIC_FILTER_GLOBAL_INFO_TYPE,
  1220. sizeof (GlInfo),
  1221. &GlInfo,
  1222. NULL,
  1223. (PIPX_INFO_BLOCK_HEADER * ) & pNewNewBlock
  1224. );
  1225. if (rc == NO_ERROR)
  1226. {
  1227. if (pNewBlock != pNewNewBlock)
  1228. {
  1229. if (pNewBlock != pIfBlock)
  1230. {
  1231. GlobalFree (pNewBlock);
  1232. }
  1233. pNewBlock = pNewNewBlock;
  1234. }
  1235. }
  1236. else
  1237. {
  1238. if (pNewBlock != pIfBlock)
  1239. {
  1240. GlobalFree (pNewBlock);
  1241. }
  1242. }
  1243. }
  1244. }
  1245. if (InterfaceNameW != NULL)
  1246. {
  1247. msg = MSG_TRAFFICFILTER_CREATED_ADM;
  1248. }
  1249. else
  1250. {
  1251. msg = MSG_CLIENT_TRAFFICFILTER_CREATED_ADM;
  1252. }
  1253. break;
  1254. case OPERATION_SET_TRAFFICFILTER:
  1255. {
  1256. PIPX_TOC_ENTRY pTfGlToc;
  1257. pTfGlToc = GetIPXTocEntry (
  1258. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  1259. (Mode == OUTPUT_FILTER)
  1260. ? IPX_OUT_TRAFFIC_FILTER_GLOBAL_INFO_TYPE
  1261. : IPX_IN_TRAFFIC_FILTER_GLOBAL_INFO_TYPE
  1262. );
  1263. if (pTfGlToc != NULL)
  1264. {
  1265. PIPX_TRAFFIC_FILTER_GLOBAL_INFO pTfGlb;
  1266. pTfGlb = (PIPX_TRAFFIC_FILTER_GLOBAL_INFO)
  1267. (pIfBlock + pTfGlToc->Offset);
  1268. pTfGlb->FilterAction = Action;
  1269. }
  1270. if (InterfaceNameW != NULL)
  1271. {
  1272. msg = MSG_TRAFFICFILTER_SET_ADM;
  1273. }
  1274. else
  1275. {
  1276. msg = MSG_CLIENT_TRAFFICFILTER_SET_ADM;
  1277. }
  1278. pNewBlock = pIfBlock;
  1279. break;
  1280. }
  1281. case OPERATION_DEL_TRAFFICFILTER:
  1282. rc = DeleteIPXInfoEntry (
  1283. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  1284. (Mode == OUTPUT_FILTER)
  1285. ? IPX_OUT_TRAFFIC_FILTER_INFO_TYPE
  1286. : IPX_IN_TRAFFIC_FILTER_INFO_TYPE,
  1287. sizeof (*TfFlt),
  1288. TfFlt,
  1289. TfFltEqual,
  1290. (PIPX_INFO_BLOCK_HEADER * ) & pNewBlock
  1291. );
  1292. if (InterfaceNameW != NULL)
  1293. {
  1294. msg = MSG_TRAFFICFILTER_DELETED_ADM;
  1295. }
  1296. else
  1297. {
  1298. msg = MSG_CLIENT_TRAFFICFILTER_DELETED_ADM;
  1299. }
  1300. // Whistler bug 247549 netsh routing ipx set/add filter produces
  1301. // error, "Cannot complete function"
  1302. //
  1303. pNewBlock = pIfBlock;
  1304. break;
  1305. }
  1306. if (rc == NO_ERROR)
  1307. {
  1308. if ( InterfaceNameW != NULL )
  1309. {
  1310. if (pNewBlock)
  1311. {
  1312. rc = MprAdminInterfaceTransportSetInfo (
  1313. g_hMprAdmin, hIfAdm, PID_IPX, pNewBlock,
  1314. ((PIPX_INFO_BLOCK_HEADER)pNewBlock)->Size
  1315. );
  1316. }
  1317. else
  1318. {
  1319. rc = ERROR_CAN_NOT_COMPLETE;
  1320. }
  1321. }
  1322. else
  1323. {
  1324. if (pNewBlock)
  1325. {
  1326. rc = MprAdminTransportSetInfo (
  1327. g_hMprAdmin, PID_IPX, NULL, 0, pNewBlock,
  1328. ((PIPX_INFO_BLOCK_HEADER)pNewBlock)->Size
  1329. );
  1330. }
  1331. else
  1332. {
  1333. rc = ERROR_CAN_NOT_COMPLETE;
  1334. }
  1335. }
  1336. if (pNewBlock != pIfBlock)
  1337. {
  1338. GlobalFree (pNewBlock);
  1339. }
  1340. if (rc == NO_ERROR)
  1341. {
  1342. DisplayIPXMessage (g_hModule, msg, InterfaceNameW);
  1343. }
  1344. else
  1345. {
  1346. DisplayError( g_hModule, rc);
  1347. }
  1348. }
  1349. else
  1350. {
  1351. DisplayError( g_hModule, rc);
  1352. }
  1353. MprAdminBufferFree (pIfBlock);
  1354. }
  1355. else
  1356. {
  1357. DisplayError( g_hModule, rc);
  1358. }
  1359. return rc;
  1360. }
  1361. DWORD
  1362. CfgSetTfFlt (
  1363. int operation,
  1364. LPWSTR InterfaceNameW,
  1365. ULONG Action,
  1366. ULONG Mode,
  1367. PIPX_TRAFFIC_FILTER_INFO TfFlt
  1368. )
  1369. {
  1370. DWORD rc;
  1371. HANDLE hIfCfg;
  1372. HANDLE hIfTrCfg;
  1373. HANDLE hTrCfg;
  1374. LPBYTE pIfBlock;
  1375. DWORD sz;
  1376. WCHAR IfName[ MAX_INTERFACE_NAME_LEN + 1 ];
  1377. DWORD dwSize = sizeof(IfName);
  1378. if (InterfaceNameW != NULL)
  1379. {
  1380. //======================================
  1381. // Translate the Interface Name
  1382. //======================================
  1383. rc = IpmontrGetIfNameFromFriendlyName(
  1384. InterfaceNameW, IfName, &dwSize
  1385. );
  1386. if ( rc == NO_ERROR )
  1387. {
  1388. rc = MprConfigInterfaceGetHandle (
  1389. g_hMprConfig, IfName, &hIfCfg
  1390. );
  1391. if (rc == NO_ERROR)
  1392. {
  1393. rc = MprConfigInterfaceTransportGetHandle (
  1394. g_hMprConfig, hIfCfg, PID_IPX, &hIfTrCfg
  1395. );
  1396. if (rc == NO_ERROR)
  1397. {
  1398. rc = MprConfigInterfaceTransportGetInfo (
  1399. g_hMprConfig, hIfCfg, hIfTrCfg, &pIfBlock, &sz
  1400. );
  1401. }
  1402. }
  1403. }
  1404. }
  1405. else
  1406. {
  1407. rc = MprConfigTransportGetHandle (
  1408. g_hMprConfig, PID_IPX, &hTrCfg
  1409. );
  1410. if (rc == NO_ERROR)
  1411. {
  1412. rc = MprConfigTransportGetInfo (
  1413. g_hMprConfig, hTrCfg, NULL, NULL, &pIfBlock, &sz, NULL
  1414. );
  1415. }
  1416. }
  1417. if (rc == NO_ERROR)
  1418. {
  1419. UINT msg;
  1420. LPBYTE pNewBlock = NULL;
  1421. switch (operation)
  1422. {
  1423. case OPERATION_ADD_TRAFFICFILTER:
  1424. rc = AddIPXInfoEntry (
  1425. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  1426. (Mode == OUTPUT_FILTER)
  1427. ? IPX_OUT_TRAFFIC_FILTER_INFO_TYPE
  1428. : IPX_IN_TRAFFIC_FILTER_INFO_TYPE,
  1429. sizeof (*TfFlt),
  1430. TfFlt,
  1431. TfFltEqual,
  1432. (PIPX_INFO_BLOCK_HEADER * ) & pNewBlock
  1433. );
  1434. if (rc == NO_ERROR)
  1435. {
  1436. if (GetIPXTocEntry ((PIPX_INFO_BLOCK_HEADER)pIfBlock,
  1437. (Mode == OUTPUT_FILTER)
  1438. ? IPX_OUT_TRAFFIC_FILTER_GLOBAL_INFO_TYPE
  1439. : IPX_IN_TRAFFIC_FILTER_GLOBAL_INFO_TYPE) == NULL)
  1440. {
  1441. IPX_TRAFFIC_FILTER_GLOBAL_INFO GlInfo;
  1442. LPBYTE pNewNewBlock;
  1443. GlInfo.FilterAction = IPX_TRAFFIC_FILTER_ACTION_DENY;
  1444. rc = AddIPXInfoEntry (
  1445. (PIPX_INFO_BLOCK_HEADER)pNewBlock,
  1446. (Mode == OUTPUT_FILTER)
  1447. ? IPX_OUT_TRAFFIC_FILTER_GLOBAL_INFO_TYPE
  1448. : IPX_IN_TRAFFIC_FILTER_GLOBAL_INFO_TYPE,
  1449. sizeof (GlInfo),
  1450. &GlInfo,
  1451. NULL,
  1452. (PIPX_INFO_BLOCK_HEADER * ) & pNewNewBlock
  1453. );
  1454. if (rc == NO_ERROR)
  1455. {
  1456. if (pNewBlock != pNewNewBlock)
  1457. {
  1458. if (pNewBlock != pIfBlock)
  1459. {
  1460. GlobalFree (pNewBlock);
  1461. }
  1462. pNewBlock = pNewNewBlock;
  1463. }
  1464. }
  1465. else
  1466. {
  1467. if (pNewBlock != pIfBlock)
  1468. {
  1469. GlobalFree (pNewBlock);
  1470. }
  1471. }
  1472. }
  1473. }
  1474. if (InterfaceNameW != NULL)
  1475. {
  1476. msg = MSG_TRAFFICFILTER_CREATED_CFG;
  1477. }
  1478. else
  1479. {
  1480. msg = MSG_CLIENT_TRAFFICFILTER_CREATED_CFG;
  1481. }
  1482. break;
  1483. case OPERATION_SET_TRAFFICFILTER:
  1484. {
  1485. PIPX_TOC_ENTRY pTfGlToc;
  1486. pTfGlToc = GetIPXTocEntry (
  1487. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  1488. (Mode == OUTPUT_FILTER)
  1489. ? IPX_OUT_TRAFFIC_FILTER_GLOBAL_INFO_TYPE
  1490. : IPX_IN_TRAFFIC_FILTER_GLOBAL_INFO_TYPE
  1491. );
  1492. if (pTfGlToc != NULL)
  1493. {
  1494. PIPX_TRAFFIC_FILTER_GLOBAL_INFO pTfGlb;
  1495. pTfGlb = (PIPX_TRAFFIC_FILTER_GLOBAL_INFO)
  1496. (pIfBlock + pTfGlToc->Offset);
  1497. pTfGlb->FilterAction = Action;
  1498. }
  1499. if (InterfaceNameW != NULL)
  1500. {
  1501. msg = MSG_TRAFFICFILTER_SET_CFG;
  1502. }
  1503. else
  1504. {
  1505. msg = MSG_CLIENT_TRAFFICFILTER_SET_CFG;
  1506. }
  1507. pNewBlock = pIfBlock;
  1508. break;
  1509. }
  1510. case OPERATION_DEL_TRAFFICFILTER:
  1511. rc = DeleteIPXInfoEntry (
  1512. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  1513. (Mode == OUTPUT_FILTER)
  1514. ? IPX_OUT_TRAFFIC_FILTER_INFO_TYPE
  1515. : IPX_IN_TRAFFIC_FILTER_INFO_TYPE,
  1516. sizeof (*TfFlt),
  1517. TfFlt,
  1518. TfFltEqual,
  1519. (PIPX_INFO_BLOCK_HEADER * ) & pNewBlock
  1520. );
  1521. if (InterfaceNameW != NULL)
  1522. {
  1523. msg = MSG_TRAFFICFILTER_DELETED_CFG;
  1524. }
  1525. else
  1526. {
  1527. msg = MSG_CLIENT_TRAFFICFILTER_DELETED_CFG;
  1528. }
  1529. // Whistler bug 247549 netsh routing ipx set/add filter produces
  1530. // error, "Cannot complete function"
  1531. //
  1532. pNewBlock = pIfBlock;
  1533. break;
  1534. }
  1535. if (rc == NO_ERROR)
  1536. {
  1537. if (InterfaceNameW != NULL)
  1538. {
  1539. // Whistler bug 247549 netsh routing ipx set/add filter produces
  1540. // error, "Cannot complete function"
  1541. //
  1542. if (pNewBlock)
  1543. {
  1544. rc = MprConfigInterfaceTransportSetInfo (
  1545. g_hMprConfig, hIfCfg, hIfTrCfg, pNewBlock,
  1546. ((PIPX_INFO_BLOCK_HEADER)pNewBlock)->Size
  1547. );
  1548. }
  1549. else
  1550. {
  1551. rc = ERROR_CAN_NOT_COMPLETE;
  1552. }
  1553. }
  1554. else
  1555. {
  1556. // Whistler bug 247549 netsh routing ipx set/add filter produces
  1557. // error, "Cannot complete function"
  1558. //
  1559. if (pNewBlock)
  1560. {
  1561. rc = MprConfigTransportSetInfo (
  1562. g_hMprConfig, hTrCfg, NULL, 0, pNewBlock,
  1563. ((PIPX_INFO_BLOCK_HEADER)pNewBlock)->Size,
  1564. NULL
  1565. );
  1566. }
  1567. else
  1568. {
  1569. rc = ERROR_CAN_NOT_COMPLETE;
  1570. }
  1571. }
  1572. if (pNewBlock != pIfBlock)
  1573. {
  1574. GlobalFree (pNewBlock);
  1575. }
  1576. if (rc == NO_ERROR)
  1577. {
  1578. DisplayIPXMessage (g_hModule, msg, InterfaceNameW);
  1579. }
  1580. else
  1581. {
  1582. DisplayError( g_hModule, rc);
  1583. }
  1584. }
  1585. else
  1586. {
  1587. DisplayError( g_hModule, rc);
  1588. }
  1589. MprConfigBufferFree (pIfBlock);
  1590. }
  1591. else
  1592. {
  1593. DisplayError( g_hModule, rc);
  1594. }
  1595. return rc;
  1596. }
  1597. BOOL
  1598. TfFltEqual (
  1599. PVOID Info1,
  1600. PVOID Info2
  1601. )
  1602. {
  1603. #define f1 ((PIPX_TRAFFIC_FILTER_INFO)Info1)
  1604. #define f2 ((PIPX_TRAFFIC_FILTER_INFO)Info2)
  1605. ULONG fd;
  1606. return ((fd = f1->FilterDefinition) == f2->FilterDefinition)
  1607. && (!(fd & IPX_TRAFFIC_FILTER_ON_SRCNET)
  1608. || ((memcmp (f1->SourceNetwork, f2->SourceNetwork, 4) == 0)
  1609. && (memcmp (f1->SourceNetworkMask, f2->SourceNetworkMask, 4) == 0)))
  1610. && (!(fd & IPX_TRAFFIC_FILTER_ON_SRCNODE)
  1611. || (memcmp (f1->SourceNode, f2->SourceNode, 6) == 0))
  1612. && (!(fd & IPX_TRAFFIC_FILTER_ON_SRCSOCKET)
  1613. || (memcmp (f1->SourceSocket, f2->SourceSocket, 2) == 0))
  1614. && (!(fd & IPX_TRAFFIC_FILTER_ON_DSTNET)
  1615. || ((memcmp (f1->DestinationNetwork, f2->DestinationNetwork, 4) == 0)
  1616. && (memcmp (f1->DestinationNetworkMask, f2->DestinationNetworkMask,
  1617. 4) == 0)))
  1618. && (!(fd & IPX_TRAFFIC_FILTER_ON_DSTNODE)
  1619. || (memcmp (f1->DestinationNode, f2->DestinationNode, 6) == 0))
  1620. && (!(fd & IPX_TRAFFIC_FILTER_ON_DSTSOCKET)
  1621. || (memcmp (f1->DestinationSocket, f2->DestinationSocket, 2) == 0))
  1622. && (!(fd & IPX_TRAFFIC_FILTER_ON_PKTTYPE)
  1623. || (f1->PacketType == f2->PacketType));
  1624. #undef f2
  1625. #undef f1
  1626. }