IxEthDBFirewall.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /**
  2. * @file IxEthDBFirewall.c
  3. *
  4. * @brief Implementation of the firewall 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. /**
  46. * @brief updates the NPE firewall operating mode and
  47. * firewall address table
  48. *
  49. * @param portID ID of the port
  50. * @param epDelta initial entry point for binary searches (NPE optimization)
  51. * @param address address of the firewall MAC address table
  52. *
  53. * This function will send a message to the NPE configuring the
  54. * firewall mode (white list or black list), invalid source
  55. * address filtering and downloading a new MAC address database
  56. * to be used for firewall matching.
  57. *
  58. * @return IX_ETH_DB_SUCCESS if the operation completed
  59. * successfully or IX_ETH_DB_FAIL otherwise
  60. *
  61. * @internal
  62. */
  63. IX_ETH_DB_PUBLIC
  64. IxEthDBStatus ixEthDBFirewallUpdate(IxEthDBPortId portID, void *address, UINT32 epDelta)
  65. {
  66. IxNpeMhMessage message;
  67. IX_STATUS result;
  68. UINT32 mode = 0;
  69. PortInfo *portInfo = &ixEthDBPortInfo[portID];
  70. mode = (portInfo->srcAddressFilterEnabled != FALSE) << 1 | (portInfo->firewallMode == IX_ETH_DB_FIREWALL_WHITE_LIST);
  71. FILL_SETFIREWALLMODE_MSG(message,
  72. IX_ETH_DB_PORT_ID_TO_NPE_LOGICAL_ID(portID),
  73. epDelta,
  74. mode,
  75. IX_OSAL_MMU_VIRT_TO_PHYS(address));
  76. IX_ETHDB_SEND_NPE_MSG(IX_ETH_DB_PORT_ID_TO_NPE(portID), message, result);
  77. return result;
  78. }
  79. /**
  80. * @brief configures the firewall white list/black list
  81. * access mode
  82. *
  83. * @param portID ID of the port
  84. * @param mode firewall filtering mode (IX_ETH_DB_FIREWALL_WHITE_LIST
  85. * or IX_ETH_DB_FIREWALL_BLACK_LIST)
  86. *
  87. * Note that this function is documented in the main component
  88. * header file, IxEthDB.h.
  89. *
  90. * @return IX_ETH_DB_SUCCESS if the operation completed
  91. * successfully or an appropriate error message otherwise
  92. */
  93. IX_ETH_DB_PUBLIC
  94. IxEthDBStatus ixEthDBFirewallModeSet(IxEthDBPortId portID, IxEthDBFirewallMode mode)
  95. {
  96. IX_ETH_DB_CHECK_PORT(portID);
  97. IX_ETH_DB_CHECK_SINGLE_NPE(portID);
  98. IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_FIREWALL);
  99. if (mode != IX_ETH_DB_FIREWALL_WHITE_LIST
  100. && mode != IX_ETH_DB_FIREWALL_BLACK_LIST)
  101. {
  102. return IX_ETH_DB_INVALID_ARG;
  103. }
  104. ixEthDBPortInfo[portID].firewallMode = mode;
  105. return ixEthDBFirewallTableDownload(portID);
  106. }
  107. /**
  108. * @brief enables or disables the invalid source MAC address filter
  109. *
  110. * @param portID ID of the port
  111. * @param enable TRUE to enable invalid source MAC address filtering
  112. * or FALSE to disable it
  113. *
  114. * The invalid source MAC address filter will discard, when enabled,
  115. * frames whose source MAC address is a multicast or the broadcast MAC
  116. * address.
  117. *
  118. * Note that this function is documented in the main component
  119. * header file, IxEthDB.h.
  120. *
  121. * @return IX_ETH_DB_SUCCESS if the operation completed
  122. * successfully or an appropriate error message otherwise
  123. */
  124. IX_ETH_DB_PUBLIC
  125. IxEthDBStatus ixEthDBFirewallInvalidAddressFilterEnable(IxEthDBPortId portID, BOOL enable)
  126. {
  127. IX_ETH_DB_CHECK_PORT(portID);
  128. IX_ETH_DB_CHECK_SINGLE_NPE(portID);
  129. IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_FIREWALL);
  130. ixEthDBPortInfo[portID].srcAddressFilterEnabled = enable;
  131. return ixEthDBFirewallTableDownload(portID);
  132. }
  133. /**
  134. * @brief adds a firewall record
  135. *
  136. * @param portID ID of the port
  137. * @param macAddr MAC address of the new record
  138. *
  139. * This function will add a new firewall record
  140. * on the specified port, using the specified
  141. * MAC address. If the record already exists this
  142. * function will silently return IX_ETH_DB_SUCCESS,
  143. * although no duplicate records are added.
  144. *
  145. * Note that this function is documented in the main
  146. * component header file, IxEthDB.h.
  147. *
  148. * @return IX_ETH_DB_SUCCESS if the operation completed
  149. * successfully or an appropriate error message otherwise
  150. */
  151. IX_ETH_DB_PUBLIC
  152. IxEthDBStatus ixEthDBFirewallEntryAdd(IxEthDBPortId portID, IxEthDBMacAddr *macAddr)
  153. {
  154. MacDescriptor recordTemplate;
  155. IX_ETH_DB_CHECK_PORT(portID);
  156. IX_ETH_DB_CHECK_SINGLE_NPE(portID);
  157. IX_ETH_DB_CHECK_REFERENCE(macAddr);
  158. IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_FIREWALL);
  159. memcpy(recordTemplate.macAddress, macAddr, sizeof (IxEthDBMacAddr));
  160. recordTemplate.type = IX_ETH_DB_FIREWALL_RECORD;
  161. recordTemplate.portID = portID;
  162. return ixEthDBAdd(&recordTemplate, NULL);
  163. }
  164. /**
  165. * @brief removes a firewall record
  166. *
  167. * @param portID ID of the port
  168. * @param macAddr MAC address of the record to remove
  169. *
  170. * This function will attempt to remove a firewall
  171. * record from the given port, using the specified
  172. * MAC address.
  173. *
  174. * Note that this function is documented in the main
  175. * component header file, IxEthDB.h.
  176. *
  177. * @return IX_ETH_DB_SUCCESS if the operation completed
  178. * successfully of an appropriate error message otherwise
  179. */
  180. IX_ETH_DB_PUBLIC
  181. IxEthDBStatus ixEthDBFirewallEntryRemove(IxEthDBPortId portID, IxEthDBMacAddr *macAddr)
  182. {
  183. MacDescriptor recordTemplate;
  184. IX_ETH_DB_CHECK_PORT(portID);
  185. IX_ETH_DB_CHECK_SINGLE_NPE(portID);
  186. IX_ETH_DB_CHECK_REFERENCE(macAddr);
  187. IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_FIREWALL);
  188. memcpy(recordTemplate.macAddress, macAddr, sizeof (IxEthDBMacAddr));
  189. recordTemplate.type = IX_ETH_DB_FIREWALL_RECORD;
  190. recordTemplate.portID = portID;
  191. return ixEthDBRemove(&recordTemplate, NULL);
  192. }
  193. /**
  194. * @brief downloads the firewall address table to an NPE
  195. *
  196. * @param portID ID of the port
  197. *
  198. * This function will download the firewall address table to
  199. * an NPE port.
  200. *
  201. * Note that this function is documented in the main
  202. * component header file, IxEthDB.h.
  203. *
  204. * @return IX_ETH_DB_SUCCESS if the operation completed
  205. * successfully or IX_ETH_DB_FAIL otherwise
  206. */
  207. IX_ETH_DB_PUBLIC
  208. IxEthDBStatus ixEthDBFirewallTableDownload(IxEthDBPortId portID)
  209. {
  210. IxEthDBPortMap query;
  211. IxEthDBStatus result;
  212. IX_ETH_DB_CHECK_PORT(portID);
  213. IX_ETH_DB_CHECK_SINGLE_NPE(portID);
  214. IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_FIREWALL);
  215. SET_DEPENDENCY_MAP(query, portID);
  216. ixEthDBUpdateLock();
  217. ixEthDBPortInfo[portID].updateMethod.searchTree = ixEthDBQuery(NULL, query, IX_ETH_DB_FIREWALL_RECORD, MAX_FW_SIZE);
  218. result = ixEthDBNPEUpdateHandler(portID, IX_ETH_DB_FIREWALL_RECORD);
  219. ixEthDBUpdateUnlock();
  220. return result;
  221. }