IxEthDBReports.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. /**
  2. * @file IxEthDBAPI.c
  3. *
  4. * @brief Implementation of the public API
  5. *
  6. * @par
  7. * IXP400 SW Release version 2.0
  8. *
  9. * -- Copyright Notice --
  10. *
  11. * @par
  12. * Copyright 2001-2005, Intel Corporation.
  13. * All rights reserved.
  14. *
  15. * @par
  16. * Redistribution and use in source and binary forms, with or without
  17. * modification, are permitted provided that the following conditions
  18. * are met:
  19. * 1. Redistributions of source code must retain the above copyright
  20. * notice, this list of conditions and the following disclaimer.
  21. * 2. Redistributions in binary form must reproduce the above copyright
  22. * notice, this list of conditions and the following disclaimer in the
  23. * documentation and/or other materials provided with the distribution.
  24. * 3. Neither the name of the Intel Corporation nor the names of its contributors
  25. * may be used to endorse or promote products derived from this software
  26. * without specific prior written permission.
  27. *
  28. * @par
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
  30. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  32. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  33. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  34. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  35. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  36. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  37. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  38. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  39. * SUCH DAMAGE.
  40. *
  41. * @par
  42. * -- End of Copyright Notice --
  43. */
  44. #include "IxEthDB_p.h"
  45. extern HashTable dbHashtable;
  46. IX_ETH_DB_PRIVATE void ixEthDBPortInfoShow(IxEthDBPortId portID, IxEthDBRecordType recordFilter);
  47. IX_ETH_DB_PRIVATE IxEthDBStatus ixEthDBHeaderShow(IxEthDBRecordType recordFilter);
  48. IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBDependencyPortMapShow(IxEthDBPortId portID, IxEthDBPortMap map);
  49. /**
  50. * @brief displays a port dependency map
  51. *
  52. * @param portID ID of the port
  53. * @param map port map to display
  54. *
  55. * @return IX_ETH_DB_SUCCESS if the operation completed
  56. * successfully
  57. */
  58. IX_ETH_DB_PUBLIC
  59. IxEthDBStatus ixEthDBDependencyPortMapShow(IxEthDBPortId portID, IxEthDBPortMap map)
  60. {
  61. UINT32 portIndex;
  62. BOOL mapSelf = TRUE, mapNone = TRUE, firstPort = TRUE;
  63. /* dependency port maps */
  64. printf("Dependency port map: ");
  65. /* browse the port map */
  66. for (portIndex = 0 ; portIndex < IX_ETH_DB_NUMBER_OF_PORTS ; portIndex++)
  67. {
  68. if (IS_PORT_INCLUDED(portIndex, map))
  69. {
  70. mapNone = FALSE;
  71. if (portIndex != portID)
  72. {
  73. mapSelf = FALSE;
  74. }
  75. printf("%s%d", firstPort ? "{" : ", ", portIndex);
  76. firstPort = FALSE;
  77. }
  78. }
  79. if (mapNone)
  80. {
  81. mapSelf = FALSE;
  82. }
  83. printf("%s (%s)\n", firstPort ? "" : "}", mapSelf ? "self" : mapNone ? "none" : "group");
  84. return IX_ETH_DB_SUCCESS;
  85. }
  86. /**
  87. * @brief displays all the filtering records belonging to a port
  88. *
  89. * @param portID ID of the port to display
  90. *
  91. * Note that this function is documented in the main component
  92. * header file, IxEthDB.h.
  93. *
  94. * @warning deprecated, use @ref ixEthDBFilteringDatabaseShowRecords()
  95. * instead. Calling this function is equivalent to calling
  96. * ixEthDBFilteringDatabaseShowRecords(portID, IX_ETH_DB_FILTERING_RECORD)
  97. */
  98. IX_ETH_DB_PUBLIC
  99. IxEthDBStatus ixEthDBFilteringDatabaseShow(IxEthDBPortId portID)
  100. {
  101. IxEthDBStatus local_result;
  102. HashIterator iterator;
  103. PortInfo *portInfo;
  104. UINT32 recordCount = 0;
  105. IX_ETH_DB_CHECK_PORT(portID);
  106. IX_ETH_DB_CHECK_SINGLE_NPE(portID);
  107. portInfo = &ixEthDBPortInfo[portID];
  108. /* display table header */
  109. printf("Ethernet database records for port ID [%d]\n", portID);
  110. ixEthDBDependencyPortMapShow(portID, portInfo->dependencyPortMap);
  111. if (ixEthDBPortDefinitions[portID].type == IX_ETH_NPE)
  112. {
  113. printf("NPE updates are %s\n\n", portInfo->updateMethod.updateEnabled ? "enabled" : "disabled");
  114. }
  115. else
  116. {
  117. printf("updates disabled (not an NPE)\n\n");
  118. }
  119. printf(" MAC address | Age | Type \n");
  120. printf("___________________________________\n");
  121. /* browse database */
  122. BUSY_RETRY(ixEthDBInitHashIterator(&dbHashtable, &iterator));
  123. while (IS_ITERATOR_VALID(&iterator))
  124. {
  125. MacDescriptor *descriptor = (MacDescriptor *) iterator.node->data;
  126. if (descriptor->portID == portID && descriptor->type == IX_ETH_DB_FILTERING_RECORD)
  127. {
  128. recordCount++;
  129. /* display entry */
  130. printf(" %02X:%02X:%02X:%02X:%02X:%02X | %5d | %s\n",
  131. descriptor->macAddress[0],
  132. descriptor->macAddress[1],
  133. descriptor->macAddress[2],
  134. descriptor->macAddress[3],
  135. descriptor->macAddress[4],
  136. descriptor->macAddress[5],
  137. descriptor->recordData.filteringData.age,
  138. descriptor->recordData.filteringData.staticEntry ? "static" : "dynamic");
  139. }
  140. /* move to the next record */
  141. BUSY_RETRY_WITH_RESULT(ixEthDBIncrementHashIterator(&dbHashtable, &iterator), local_result);
  142. /* debug */
  143. if (local_result == IX_ETH_DB_BUSY)
  144. {
  145. return IX_ETH_DB_FAIL;
  146. }
  147. }
  148. /* display number of records */
  149. printf("\nFound %d records\n", recordCount);
  150. return IX_ETH_DB_SUCCESS;
  151. }
  152. /**
  153. * @brief displays all the filtering records belonging to all the ports
  154. *
  155. * Note that this function is documented in the main component
  156. * header file, IxEthDB.h.
  157. *
  158. * @warning deprecated, use @ref ixEthDBFilteringDatabaseShowRecords()
  159. * instead. Calling this function is equivalent to calling
  160. * ixEthDBFilteringDatabaseShowRecords(IX_ETH_DB_ALL_PORTS, IX_ETH_DB_FILTERING_RECORD)
  161. */
  162. IX_ETH_DB_PUBLIC
  163. void ixEthDBFilteringDatabaseShowAll()
  164. {
  165. IxEthDBPortId portIndex;
  166. printf("\nEthernet learning/filtering database: listing %d ports\n\n", (UINT32) IX_ETH_DB_NUMBER_OF_PORTS);
  167. for (portIndex = 0 ; portIndex < IX_ETH_DB_NUMBER_OF_PORTS ; portIndex++)
  168. {
  169. ixEthDBFilteringDatabaseShow(portIndex);
  170. if (portIndex < IX_ETH_DB_NUMBER_OF_PORTS - 1)
  171. {
  172. printf("\n");
  173. }
  174. }
  175. }
  176. /**
  177. * @brief displays one record in a format depending on the record filter
  178. *
  179. * @param descriptor pointer to the record
  180. * @param recordFilter format filter
  181. *
  182. * This function will display the fields in a record depending on the
  183. * selected record filter.
  184. *
  185. * @internal
  186. */
  187. IX_ETH_DB_PRIVATE
  188. void ixEthDBRecordShow(MacDescriptor *descriptor, IxEthDBRecordType recordFilter)
  189. {
  190. if (recordFilter == IX_ETH_DB_FILTERING_VLAN_RECORD
  191. || recordFilter == (IX_ETH_DB_FILTERING_RECORD | IX_ETH_DB_FILTERING_VLAN_RECORD))
  192. {
  193. /* display VLAN record header - leave this commented code in place, its purpose is to align the print format with the header
  194. printf(" MAC address | Age | Type | VLAN ID | CFI | QoS class \n");
  195. printf("___________________________________________________________________\n"); */
  196. if (descriptor->type == IX_ETH_DB_FILTERING_VLAN_RECORD)
  197. {
  198. printf("%02X:%02X:%02X:%02X:%02X:%02X | %3d | %s | %d | %d | %d\n",
  199. descriptor->macAddress[0],
  200. descriptor->macAddress[1],
  201. descriptor->macAddress[2],
  202. descriptor->macAddress[3],
  203. descriptor->macAddress[4],
  204. descriptor->macAddress[5],
  205. descriptor->recordData.filteringVlanData.age,
  206. descriptor->recordData.filteringVlanData.staticEntry ? "static" : "dynamic",
  207. IX_ETH_DB_GET_VLAN_ID(descriptor->recordData.filteringVlanData.ieee802_1qTag),
  208. (descriptor->recordData.filteringVlanData.ieee802_1qTag & 0x1000) >> 12,
  209. IX_ETH_DB_GET_QOS_PRIORITY(descriptor->recordData.filteringVlanData.ieee802_1qTag));
  210. }
  211. else if (descriptor->type == IX_ETH_DB_FILTERING_RECORD)
  212. {
  213. printf("%02X:%02X:%02X:%02X:%02X:%02X | %3d | %s | - | - | -\n",
  214. descriptor->macAddress[0],
  215. descriptor->macAddress[1],
  216. descriptor->macAddress[2],
  217. descriptor->macAddress[3],
  218. descriptor->macAddress[4],
  219. descriptor->macAddress[5],
  220. descriptor->recordData.filteringData.age,
  221. descriptor->recordData.filteringData.staticEntry ? "static" : "dynamic");
  222. }
  223. }
  224. else if (recordFilter == IX_ETH_DB_FILTERING_RECORD)
  225. {
  226. /* display filtering record header - leave this commented code in place, its purpose is to align the print format with the header
  227. printf(" MAC address | Age | Type \n");
  228. printf("_______________________________________\n"); */
  229. if (descriptor->type == IX_ETH_DB_FILTERING_RECORD)
  230. {
  231. printf("%02X:%02X:%02X:%02X:%02X:%02X | %3d | %s \n",
  232. descriptor->macAddress[0],
  233. descriptor->macAddress[1],
  234. descriptor->macAddress[2],
  235. descriptor->macAddress[3],
  236. descriptor->macAddress[4],
  237. descriptor->macAddress[5],
  238. descriptor->recordData.filteringData.age,
  239. descriptor->recordData.filteringData.staticEntry ? "static" : "dynamic");
  240. }
  241. }
  242. else if (recordFilter == IX_ETH_DB_WIFI_RECORD)
  243. {
  244. /* display WiFi record header - leave this commented code in place, its purpose is to align the print format with the header
  245. printf(" MAC address | GW MAC address \n");
  246. printf("_______________________________________\n"); */
  247. if (descriptor->type == IX_ETH_DB_WIFI_RECORD)
  248. {
  249. if (descriptor->recordData.wifiData.type == IX_ETH_DB_WIFI_AP_TO_AP)
  250. {
  251. /* gateway address present */
  252. printf("%02X:%02X:%02X:%02X:%02X:%02X | %02X:%02X:%02X:%02X:%02X:%02X \n",
  253. descriptor->macAddress[0],
  254. descriptor->macAddress[1],
  255. descriptor->macAddress[2],
  256. descriptor->macAddress[3],
  257. descriptor->macAddress[4],
  258. descriptor->macAddress[5],
  259. descriptor->recordData.wifiData.gwMacAddress[0],
  260. descriptor->recordData.wifiData.gwMacAddress[1],
  261. descriptor->recordData.wifiData.gwMacAddress[2],
  262. descriptor->recordData.wifiData.gwMacAddress[3],
  263. descriptor->recordData.wifiData.gwMacAddress[4],
  264. descriptor->recordData.wifiData.gwMacAddress[5]);
  265. }
  266. else
  267. {
  268. /* no gateway */
  269. printf("%02X:%02X:%02X:%02X:%02X:%02X | ----no gateway----- \n",
  270. descriptor->macAddress[0],
  271. descriptor->macAddress[1],
  272. descriptor->macAddress[2],
  273. descriptor->macAddress[3],
  274. descriptor->macAddress[4],
  275. descriptor->macAddress[5]);
  276. }
  277. }
  278. }
  279. else if (recordFilter == IX_ETH_DB_FIREWALL_RECORD)
  280. {
  281. /* display Firewall record header - leave this commented code in place, its purpose is to align the print format with the header
  282. printf(" MAC address \n");
  283. printf("__________________\n"); */
  284. if (descriptor->type == IX_ETH_DB_FIREWALL_RECORD)
  285. {
  286. printf("%02X:%02X:%02X:%02X:%02X:%02X \n",
  287. descriptor->macAddress[0],
  288. descriptor->macAddress[1],
  289. descriptor->macAddress[2],
  290. descriptor->macAddress[3],
  291. descriptor->macAddress[4],
  292. descriptor->macAddress[5]);
  293. }
  294. }
  295. else if (recordFilter == IX_ETH_DB_ALL_RECORD_TYPES)
  296. {
  297. /* display composite record header - leave this commented code in place, its purpose is to align the print format with the header
  298. printf(" MAC address | Record | Age| Type | VLAN |CFI| QoS | GW MAC address \n");
  299. printf("_______________________________________________________________________________\n"); */
  300. if (descriptor->type == IX_ETH_DB_FILTERING_VLAN_RECORD)
  301. {
  302. printf("%02X:%02X:%02X:%02X:%02X:%02X | VLAN | %2d | %s | %4d | %1d | %1d | -----------------\n",
  303. descriptor->macAddress[0],
  304. descriptor->macAddress[1],
  305. descriptor->macAddress[2],
  306. descriptor->macAddress[3],
  307. descriptor->macAddress[4],
  308. descriptor->macAddress[5],
  309. descriptor->recordData.filteringVlanData.age,
  310. descriptor->recordData.filteringVlanData.staticEntry ? "static " : "dynamic",
  311. IX_ETH_DB_GET_VLAN_ID(descriptor->recordData.filteringVlanData.ieee802_1qTag),
  312. (descriptor->recordData.filteringVlanData.ieee802_1qTag & 0x1000) >> 12,
  313. IX_ETH_DB_GET_QOS_PRIORITY(descriptor->recordData.filteringVlanData.ieee802_1qTag));
  314. }
  315. else if (descriptor->type == IX_ETH_DB_FILTERING_RECORD)
  316. {
  317. printf("%02X:%02X:%02X:%02X:%02X:%02X | Filter | %2d | %s | ---- | - | --- | -----------------\n",
  318. descriptor->macAddress[0],
  319. descriptor->macAddress[1],
  320. descriptor->macAddress[2],
  321. descriptor->macAddress[3],
  322. descriptor->macAddress[4],
  323. descriptor->macAddress[5],
  324. descriptor->recordData.filteringData.age,
  325. descriptor->recordData.filteringData.staticEntry ? "static " : "dynamic");
  326. }
  327. else if (descriptor->type == IX_ETH_DB_WIFI_RECORD)
  328. {
  329. if (descriptor->recordData.wifiData.type == IX_ETH_DB_WIFI_AP_TO_AP)
  330. {
  331. /* gateway address present */
  332. printf("%02X:%02X:%02X:%02X:%02X:%02X | WiFi | -- | AP=>AP | ---- | - | --- | %02X:%02X:%02X:%02X:%02X:%02X\n",
  333. descriptor->macAddress[0],
  334. descriptor->macAddress[1],
  335. descriptor->macAddress[2],
  336. descriptor->macAddress[3],
  337. descriptor->macAddress[4],
  338. descriptor->macAddress[5],
  339. descriptor->recordData.wifiData.gwMacAddress[0],
  340. descriptor->recordData.wifiData.gwMacAddress[1],
  341. descriptor->recordData.wifiData.gwMacAddress[2],
  342. descriptor->recordData.wifiData.gwMacAddress[3],
  343. descriptor->recordData.wifiData.gwMacAddress[4],
  344. descriptor->recordData.wifiData.gwMacAddress[5]);
  345. }
  346. else
  347. {
  348. /* no gateway */
  349. printf("%02X:%02X:%02X:%02X:%02X:%02X | WiFi | -- | AP=>ST | ---- | - | --- | -- no gateway -- \n",
  350. descriptor->macAddress[0],
  351. descriptor->macAddress[1],
  352. descriptor->macAddress[2],
  353. descriptor->macAddress[3],
  354. descriptor->macAddress[4],
  355. descriptor->macAddress[5]);
  356. }
  357. }
  358. else if (descriptor->type == IX_ETH_DB_FIREWALL_RECORD)
  359. {
  360. printf("%02X:%02X:%02X:%02X:%02X:%02X | FW | -- | ------- | ---- | - | --- | -----------------\n",
  361. descriptor->macAddress[0],
  362. descriptor->macAddress[1],
  363. descriptor->macAddress[2],
  364. descriptor->macAddress[3],
  365. descriptor->macAddress[4],
  366. descriptor->macAddress[5]);
  367. }
  368. }
  369. else
  370. {
  371. printf("invalid record filter\n");
  372. }
  373. }
  374. /**
  375. * @brief displays the status, records and configuration information of a port
  376. *
  377. * @param portID ID of the port
  378. * @param recordFilter record filter to display
  379. *
  380. * @internal
  381. */
  382. IX_ETH_DB_PRIVATE
  383. void ixEthDBPortInfoShow(IxEthDBPortId portID, IxEthDBRecordType recordFilter)
  384. {
  385. PortInfo *portInfo = &ixEthDBPortInfo[portID];
  386. UINT32 recordCount = 0;
  387. HashIterator iterator;
  388. IxEthDBStatus local_result;
  389. /* display port status */
  390. printf("== Port ID %d ==\n", portID);
  391. /* display capabilities */
  392. printf("- Capabilities: ");
  393. if ((portInfo->featureCapability & IX_ETH_DB_LEARNING) != 0)
  394. {
  395. printf("Learning (%s) ", ((portInfo->featureStatus & IX_ETH_DB_LEARNING) != 0) ? "on" : "off");
  396. }
  397. if ((portInfo->featureCapability & IX_ETH_DB_VLAN_QOS) != 0)
  398. {
  399. printf("VLAN/QoS (%s) ", ((portInfo->featureStatus & IX_ETH_DB_VLAN_QOS) != 0) ? "on" : "off");
  400. }
  401. if ((portInfo->featureCapability & IX_ETH_DB_FIREWALL) != 0)
  402. {
  403. printf("Firewall (%s) ", ((portInfo->featureStatus & IX_ETH_DB_FIREWALL) != 0) ? "on" : "off");
  404. }
  405. if ((portInfo->featureCapability & IX_ETH_DB_WIFI_HEADER_CONVERSION) != 0)
  406. {
  407. printf("WiFi (%s) ", ((portInfo->featureStatus & IX_ETH_DB_WIFI_HEADER_CONVERSION) != 0) ? "on" : "off");
  408. }
  409. if ((portInfo->featureCapability & IX_ETH_DB_SPANNING_TREE_PROTOCOL) != 0)
  410. {
  411. printf("STP (%s) ", ((portInfo->featureStatus & IX_ETH_DB_SPANNING_TREE_PROTOCOL) != 0) ? "on" : "off");
  412. }
  413. printf("\n");
  414. /* dependency map */
  415. ixEthDBDependencyPortMapShow(portID, portInfo->dependencyPortMap);
  416. /* NPE dynamic updates */
  417. if (ixEthDBPortDefinitions[portID].type == IX_ETH_NPE)
  418. {
  419. printf(" - NPE dynamic update is %s\n", portInfo->updateMethod.updateEnabled ? "enabled" : "disabled");
  420. }
  421. else
  422. {
  423. printf(" - dynamic update disabled (not an NPE)\n");
  424. }
  425. if ((portInfo->featureCapability & IX_ETH_DB_WIFI_HEADER_CONVERSION) != 0)
  426. {
  427. if ((portInfo->featureStatus & IX_ETH_DB_WIFI_HEADER_CONVERSION) != 0)
  428. {
  429. /* WiFi header conversion */
  430. if ((portInfo->frameControlDurationID
  431. + portInfo->bbsid[0]
  432. + portInfo->bbsid[1]
  433. + portInfo->bbsid[2]
  434. + portInfo->bbsid[3]
  435. + portInfo->bbsid[4]
  436. + portInfo->bbsid[5]) == 0)
  437. {
  438. printf(" - WiFi header conversion not configured\n");
  439. }
  440. else
  441. {
  442. printf(" - WiFi header conversion: BBSID [%02X:%02X:%02X:%02X:%02X:%02X], Frame Control 0x%X, Duration/ID 0x%X\n",
  443. portInfo->bbsid[0],
  444. portInfo->bbsid[1],
  445. portInfo->bbsid[2],
  446. portInfo->bbsid[3],
  447. portInfo->bbsid[4],
  448. portInfo->bbsid[5],
  449. portInfo->frameControlDurationID >> 16,
  450. portInfo->frameControlDurationID & 0xFFFF);
  451. }
  452. }
  453. else
  454. {
  455. printf(" - WiFi header conversion not enabled\n");
  456. }
  457. }
  458. /* Firewall */
  459. if ((portInfo->featureCapability & IX_ETH_DB_FIREWALL) != 0)
  460. {
  461. if ((portInfo->featureStatus & IX_ETH_DB_FIREWALL) != 0)
  462. {
  463. printf(" - Firewall is in %s-list mode\n", portInfo->firewallMode == IX_ETH_DB_FIREWALL_BLACK_LIST ? "black" : "white");
  464. printf(" - Invalid source MAC address filtering is %s\n", portInfo->srcAddressFilterEnabled ? "enabled" : "disabled");
  465. }
  466. else
  467. {
  468. printf(" - Firewall not enabled\n");
  469. }
  470. }
  471. /* browse database if asked to display records */
  472. if (recordFilter != IX_ETH_DB_NO_RECORD_TYPE)
  473. {
  474. printf("\n");
  475. ixEthDBHeaderShow(recordFilter);
  476. BUSY_RETRY(ixEthDBInitHashIterator(&dbHashtable, &iterator));
  477. while (IS_ITERATOR_VALID(&iterator))
  478. {
  479. MacDescriptor *descriptor = (MacDescriptor *) iterator.node->data;
  480. if (descriptor->portID == portID && (descriptor->type & recordFilter) != 0)
  481. {
  482. recordCount++;
  483. /* display entry */
  484. ixEthDBRecordShow(descriptor, recordFilter);
  485. }
  486. /* move to the next record */
  487. BUSY_RETRY_WITH_RESULT(ixEthDBIncrementHashIterator(&dbHashtable, &iterator), local_result);
  488. /* debug */
  489. if (local_result == IX_ETH_DB_BUSY)
  490. {
  491. printf("EthDB (API): Error, database browser failed (no access), giving up\n");
  492. }
  493. }
  494. printf("\nFound %d records\n\n", recordCount);
  495. }
  496. }
  497. /**
  498. * @brief displays a record header
  499. *
  500. * @param recordFilter record type filter
  501. *
  502. * This function displays a record header, depending on
  503. * the given record type filter. It is useful when used
  504. * in conjunction with ixEthDBRecordShow which will display
  505. * record fields formatted for the header, provided the same
  506. * record filter is used.
  507. *
  508. * @return IX_ETH_DB_SUCCESS if the operation completed
  509. * successfully or IX_ETH_DB_INVALID_ARG if the recordFilter
  510. * parameter is invalid or not supported
  511. *
  512. * @internal
  513. */
  514. IX_ETH_DB_PRIVATE
  515. IxEthDBStatus ixEthDBHeaderShow(IxEthDBRecordType recordFilter)
  516. {
  517. if (recordFilter == IX_ETH_DB_FILTERING_VLAN_RECORD
  518. || recordFilter == (IX_ETH_DB_FILTERING_RECORD | IX_ETH_DB_FILTERING_VLAN_RECORD))
  519. {
  520. /* display VLAN record header */
  521. printf(" MAC address | Age | Type | VLAN ID | CFI | QoS class \n");
  522. printf("___________________________________________________________________\n");
  523. }
  524. else if (recordFilter == IX_ETH_DB_FILTERING_RECORD)
  525. {
  526. /* display filtering record header */
  527. printf(" MAC address | Age | Type \n");
  528. printf("_______________________________________\n");
  529. }
  530. else if (recordFilter == IX_ETH_DB_WIFI_RECORD)
  531. {
  532. /* display WiFi record header */
  533. printf(" MAC address | GW MAC address \n");
  534. printf("_______________________________________\n");
  535. }
  536. else if (recordFilter == IX_ETH_DB_FIREWALL_RECORD)
  537. {
  538. /* display Firewall record header */
  539. printf(" MAC address \n");
  540. printf("__________________\n");
  541. }
  542. else if (recordFilter == IX_ETH_DB_ALL_RECORD_TYPES)
  543. {
  544. /* display composite record header */
  545. printf(" MAC address | Record | Age| Type | VLAN |CFI| QoS | GW MAC address \n");
  546. printf("_______________________________________________________________________________\n");
  547. }
  548. else
  549. {
  550. return IX_ETH_DB_INVALID_ARG;
  551. }
  552. return IX_ETH_DB_SUCCESS;
  553. }
  554. /**
  555. * @brief displays database information (records and port information)
  556. *
  557. * @param portID ID of the port to display (or IX_ETH_DB_ALL_PORTS for all the ports)
  558. * @param recordFilter record filter (use IX_ETH_DB_NO_RECORD_TYPE to display only
  559. * port information)
  560. *
  561. * Note that this function is documented in the main component header
  562. * file, IxEthDB.h.
  563. *
  564. * @return IX_ETH_DB_SUCCESS if the operation completed successfully or
  565. * an appropriate error code otherwise
  566. *
  567. */
  568. IX_ETH_DB_PUBLIC
  569. IxEthDBStatus ixEthDBFilteringDatabaseShowRecords(IxEthDBPortId portID, IxEthDBRecordType recordFilter)
  570. {
  571. IxEthDBPortId currentPort;
  572. BOOL showAllPorts = (portID == IX_ETH_DB_ALL_PORTS);
  573. IX_ETH_DB_CHECK_PORT_ALL(portID);
  574. printf("\nEthernet learning/filtering database: listing %d port(s)\n\n", showAllPorts ? (UINT32) IX_ETH_DB_NUMBER_OF_PORTS : 1);
  575. currentPort = showAllPorts ? 0 : portID;
  576. while (currentPort != IX_ETH_DB_NUMBER_OF_PORTS)
  577. {
  578. /* display port info */
  579. ixEthDBPortInfoShow(currentPort, recordFilter);
  580. /* next port */
  581. currentPort = showAllPorts ? currentPort + 1 : IX_ETH_DB_NUMBER_OF_PORTS;
  582. }
  583. return IX_ETH_DB_SUCCESS;
  584. }