change console=tty0 to enable linux framebuffer console
[jz_uboot.git] / cpu / ixp / npe / IxEthDBFirewall.c
blobeb46174b6c5a6188286bbe5c82a29b99cbd034b5
1 /**
2 * @file IxEthDBFirewall.c
4 * @brief Implementation of the firewall API
5 *
6 * @par
7 * IXP400 SW Release version 2.0
8 *
9 * -- Copyright Notice --
11 * @par
12 * Copyright 2001-2005, Intel Corporation.
13 * All rights reserved.
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.
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.
41 * @par
42 * -- End of Copyright Notice --
46 #include "IxEthDB_p.h"
48 /**
49 * @brief updates the NPE firewall operating mode and
50 * firewall address table
52 * @param portID ID of the port
53 * @param epDelta initial entry point for binary searches (NPE optimization)
54 * @param address address of the firewall MAC address table
56 * This function will send a message to the NPE configuring the
57 * firewall mode (white list or black list), invalid source
58 * address filtering and downloading a new MAC address database
59 * to be used for firewall matching.
61 * @return IX_ETH_DB_SUCCESS if the operation completed
62 * successfully or IX_ETH_DB_FAIL otherwise
64 * @internal
66 IX_ETH_DB_PUBLIC
67 IxEthDBStatus ixEthDBFirewallUpdate(IxEthDBPortId portID, void *address, UINT32 epDelta)
69 IxNpeMhMessage message;
70 IX_STATUS result;
72 UINT32 mode = 0;
73 PortInfo *portInfo = &ixEthDBPortInfo[portID];
75 mode = (portInfo->srcAddressFilterEnabled != FALSE) << 1 | (portInfo->firewallMode == IX_ETH_DB_FIREWALL_WHITE_LIST);
77 FILL_SETFIREWALLMODE_MSG(message,
78 IX_ETH_DB_PORT_ID_TO_NPE_LOGICAL_ID(portID),
79 epDelta,
80 mode,
81 IX_OSAL_MMU_VIRT_TO_PHYS(address));
83 IX_ETHDB_SEND_NPE_MSG(IX_ETH_DB_PORT_ID_TO_NPE(portID), message, result);
85 return result;
88 /**
89 * @brief configures the firewall white list/black list
90 * access mode
92 * @param portID ID of the port
93 * @param mode firewall filtering mode (IX_ETH_DB_FIREWALL_WHITE_LIST
94 * or IX_ETH_DB_FIREWALL_BLACK_LIST)
96 * Note that this function is documented in the main component
97 * header file, IxEthDB.h.
99 * @return IX_ETH_DB_SUCCESS if the operation completed
100 * successfully or an appropriate error message otherwise
102 IX_ETH_DB_PUBLIC
103 IxEthDBStatus ixEthDBFirewallModeSet(IxEthDBPortId portID, IxEthDBFirewallMode mode)
105 IX_ETH_DB_CHECK_PORT(portID);
107 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
109 IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_FIREWALL);
111 if (mode != IX_ETH_DB_FIREWALL_WHITE_LIST
112 && mode != IX_ETH_DB_FIREWALL_BLACK_LIST)
114 return IX_ETH_DB_INVALID_ARG;
117 ixEthDBPortInfo[portID].firewallMode = mode;
119 return ixEthDBFirewallTableDownload(portID);
123 * @brief enables or disables the invalid source MAC address filter
125 * @param portID ID of the port
126 * @param enable TRUE to enable invalid source MAC address filtering
127 * or FALSE to disable it
129 * The invalid source MAC address filter will discard, when enabled,
130 * frames whose source MAC address is a multicast or the broadcast MAC
131 * address.
133 * Note that this function is documented in the main component
134 * header file, IxEthDB.h.
136 * @return IX_ETH_DB_SUCCESS if the operation completed
137 * successfully or an appropriate error message otherwise
139 IX_ETH_DB_PUBLIC
140 IxEthDBStatus ixEthDBFirewallInvalidAddressFilterEnable(IxEthDBPortId portID, BOOL enable)
142 IX_ETH_DB_CHECK_PORT(portID);
144 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
146 IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_FIREWALL);
148 ixEthDBPortInfo[portID].srcAddressFilterEnabled = enable;
150 return ixEthDBFirewallTableDownload(portID);
154 * @brief adds a firewall record
156 * @param portID ID of the port
157 * @param macAddr MAC address of the new record
159 * This function will add a new firewall record
160 * on the specified port, using the specified
161 * MAC address. If the record already exists this
162 * function will silently return IX_ETH_DB_SUCCESS,
163 * although no duplicate records are added.
165 * Note that this function is documented in the main
166 * component header file, IxEthDB.h.
168 * @return IX_ETH_DB_SUCCESS if the operation completed
169 * successfully or an appropriate error message otherwise
171 IX_ETH_DB_PUBLIC
172 IxEthDBStatus ixEthDBFirewallEntryAdd(IxEthDBPortId portID, IxEthDBMacAddr *macAddr)
174 MacDescriptor recordTemplate;
176 IX_ETH_DB_CHECK_PORT(portID);
178 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
180 IX_ETH_DB_CHECK_REFERENCE(macAddr);
182 IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_FIREWALL);
184 memcpy(recordTemplate.macAddress, macAddr, sizeof (IxEthDBMacAddr));
186 recordTemplate.type = IX_ETH_DB_FIREWALL_RECORD;
187 recordTemplate.portID = portID;
189 return ixEthDBAdd(&recordTemplate, NULL);
193 * @brief removes a firewall record
195 * @param portID ID of the port
196 * @param macAddr MAC address of the record to remove
198 * This function will attempt to remove a firewall
199 * record from the given port, using the specified
200 * MAC address.
202 * Note that this function is documented in the main
203 * component header file, IxEthDB.h.
205 * @return IX_ETH_DB_SUCCESS if the operation completed
206 * successfully of an appropriate error message otherwise
208 IX_ETH_DB_PUBLIC
209 IxEthDBStatus ixEthDBFirewallEntryRemove(IxEthDBPortId portID, IxEthDBMacAddr *macAddr)
211 MacDescriptor recordTemplate;
213 IX_ETH_DB_CHECK_PORT(portID);
215 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
217 IX_ETH_DB_CHECK_REFERENCE(macAddr);
219 IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_FIREWALL);
221 memcpy(recordTemplate.macAddress, macAddr, sizeof (IxEthDBMacAddr));
223 recordTemplate.type = IX_ETH_DB_FIREWALL_RECORD;
224 recordTemplate.portID = portID;
226 return ixEthDBRemove(&recordTemplate, NULL);
230 * @brief downloads the firewall address table to an NPE
232 * @param portID ID of the port
234 * This function will download the firewall address table to
235 * an NPE port.
237 * Note that this function is documented in the main
238 * component header file, IxEthDB.h.
240 * @return IX_ETH_DB_SUCCESS if the operation completed
241 * successfully or IX_ETH_DB_FAIL otherwise
243 IX_ETH_DB_PUBLIC
244 IxEthDBStatus ixEthDBFirewallTableDownload(IxEthDBPortId portID)
246 IxEthDBPortMap query;
247 IxEthDBStatus result;
249 IX_ETH_DB_CHECK_PORT(portID);
251 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
253 IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_FIREWALL);
255 SET_DEPENDENCY_MAP(query, portID);
257 ixEthDBUpdateLock();
259 ixEthDBPortInfo[portID].updateMethod.searchTree = ixEthDBQuery(NULL, query, IX_ETH_DB_FIREWALL_RECORD, MAX_FW_SIZE);
261 result = ixEthDBNPEUpdateHandler(portID, IX_ETH_DB_FIREWALL_RECORD);
263 ixEthDBUpdateUnlock();
265 return result;