📄 ixethdbcore.c
字号:
if (newRecordTemplate->type == IX_ETH_DB_WIFI_RECORD) { /* increment the wifi records counter when entry is added into the database for the port */ portInfo->wifiRecordsCount = portInfo->wifiRecordsCount + 1; } if (newRecordTemplate->type == IX_ETH_DB_FIREWALL_RECORD || newRecordTemplate->type == IX_ETH_DB_MASKED_FIREWALL_RECORD) { /* increment the firewall records counter when entry is added into the database for the port */ portInfo->fwRecordsCount = portInfo->fwRecordsCount + 1; } } else { /* a node with the same key exists, will update node */ newDescriptor = (MacDescriptor *) node->data; /* save original port id */ originalPortID = newDescriptor->portID; } /* copy/update fields into new record */ memcpy(newDescriptor->macAddress, newRecordTemplate->macAddress, IX_IEEE803_MAC_ADDRESS_SIZE); memcpy(&newDescriptor->recordData, &newRecordTemplate->recordData, sizeof (IxEthDBRecordData)); newDescriptor->type = newRecordTemplate->type; newDescriptor->portID = newRecordTemplate->portID; newDescriptor->user = newRecordTemplate->user; if (node == NULL) { /* new record, insert into hashtable */ BUSY_RETRY_WITH_RESULT(ixEthDBAddHashEntry(&dbHashtable, newDescriptor), result); if (result != IX_ETH_DB_SUCCESS) { ixEthDBFreeMacDescriptor(newDescriptor); return result; /* insertion failed */ } } if (node != NULL) { /* release access */ ixEthDBReleaseHashNode(node); } /* trigger add/remove update if required by type */ if (updateTrigger != NULL && ixEthDBPortUpdateRequired[newRecordTemplate->type]) { /* add new port to update list */ JOIN_PORT_TO_MAP(updateTrigger, newRecordTemplate->portID); /* check if record has moved, we'll need to update the old port as well */ if (originalPortID != newDescriptor->portID) { JOIN_PORT_TO_MAP(updateTrigger, originalPortID); } } return IX_ETH_DB_SUCCESS;}/** * @brief remove a record from the Ethernet database * * @param templateRecord template record used to determine * what record is to be removed * @param updateTrigger port map containing the update triggers * resulting from this update operation * * This function will examine the template record it receives * and attempts to delete a record of the same type and containing * the same keys as the template record. If deletion is successful * and the record type is registered for automatic port updates the * port will also be set in the updateTrigger port map, so that the * client can perform an update of the port. * * @retval IX_ETH_DB_SUCCESS removal was successful * @retval IX_ETH_DB_NO_SUCH_ADDR the record with the given MAC address was not found * @retval IX_ETH_DB_BUSY database busy, cannot remove due to locking * * @internal */IX_ETH_DB_PUBLICIxEthDBStatus ixEthDBRemove(MacDescriptor *templateRecord, IxEthDBPortMap updateTrigger){ IxEthDBStatus result; PortInfo *portInfo; TEST_FIXTURE_INCREMENT_DB_CORE_ACCESS_COUNTER; BUSY_RETRY_WITH_RESULT(ixEthDBRemoveHashEntry(&dbHashtable, ixEthDBKeyType[templateRecord->type], templateRecord), result); if (result != IX_ETH_DB_SUCCESS) { return IX_ETH_DB_NO_SUCH_ADDR; /* not found */ } portInfo = &ixEthDBPortInfo[templateRecord->portID]; if (templateRecord->type == IX_ETH_DB_WIFI_RECORD) { /* decrement the wifi records counter when entry is deleted from the database for the port */ portInfo->wifiRecordsCount = portInfo->wifiRecordsCount - 1; } if (templateRecord->type == IX_ETH_DB_FIREWALL_RECORD || templateRecord->type == IX_ETH_DB_MASKED_FIREWALL_RECORD) { /* decrement the firewall records counter when entry is deleted from the database for the port */ portInfo->fwRecordsCount = portInfo->fwRecordsCount - 1; } /* trigger add/remove update if required by type */ if (updateTrigger != NULL &&ixEthDBPortUpdateRequired[templateRecord->type]) { /* add new port to update list */ JOIN_PORT_TO_MAP(updateTrigger, templateRecord->portID); } return IX_ETH_DB_SUCCESS;}/** * @brief register record key types * * This function registers the appropriate key types, * depending on record types. * * All filtering records use the MAC address as the key. * WiFi records use a compound key consisting * in both the MAC address and the port ID. * Firewall records use a compound key consisting * of the masked MAC address, the mask and the port ID. * * @return the number of registered record types */IX_ETH_DB_PUBLICUINT32 ixEthDBKeyTypeRegister(UINT32 *keyType){ /* safety */ memset(keyType, 0, sizeof (keyType)); /* register all known record types */ keyType[IX_ETH_DB_FILTERING_RECORD] = IX_ETH_DB_MAC_KEY; keyType[IX_ETH_DB_FILTERING_VLAN_RECORD] = IX_ETH_DB_MAC_KEY; keyType[IX_ETH_DB_ALL_FILTERING_RECORDS] = IX_ETH_DB_MAC_KEY; keyType[IX_ETH_DB_WIFI_RECORD] = IX_ETH_DB_MAC_PORT_KEY; keyType[IX_ETH_DB_FIREWALL_RECORD] = IX_ETH_DB_MAC_PORT_KEY; keyType[IX_ETH_DB_MASKED_FIREWALL_RECORD]= IX_ETH_DB_MAC_MASK_PORT_KEY; return 6;}/** * @brief Sets a user-defined field into a database record * * Note that this function is fully documented in the main component * header file. */IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBUserFieldSet(IxEthDBRecordType recordType, IxEthDBMacAddr *macAddr, IxEthDBPortId portID, IxEthDBVlanId vlanID, void *field){ HashNode *result = NULL; if (macAddr == NULL) { return IX_ETH_DB_INVALID_ARG; } if (recordType == IX_ETH_DB_FILTERING_RECORD) { result = ixEthDBSearch(macAddr, recordType); } else if (recordType == IX_ETH_DB_FILTERING_VLAN_RECORD) { result = ixEthDBVlanSearch(macAddr, vlanID, recordType); } else if (recordType == IX_ETH_DB_WIFI_RECORD || recordType == IX_ETH_DB_FIREWALL_RECORD) { IX_ETH_DB_CHECK_PORT_EXISTS(portID); result = ixEthDBPortSearch(macAddr, portID, recordType); } else { return IX_ETH_DB_INVALID_ARG; } if (result == NULL) { return IX_ETH_DB_NO_SUCH_ADDR; } ((MacDescriptor *) result->data)->user = field; ixEthDBReleaseHashNode(result); return IX_ETH_DB_SUCCESS;}/** * @brief Retrieves a user-defined field from a database record * * Note that this function is fully documented in the main component * header file. */IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBUserFieldGet(IxEthDBRecordType recordType, IxEthDBMacAddr *macAddr, IxEthDBPortId portID, IxEthDBVlanId vlanID, void **field){ HashNode *result = NULL; if (macAddr == NULL || field == NULL) { return IX_ETH_DB_INVALID_ARG; } if (recordType == IX_ETH_DB_FILTERING_RECORD) { result = ixEthDBSearch(macAddr, recordType); } else if (recordType == IX_ETH_DB_FILTERING_VLAN_RECORD) { result = ixEthDBVlanSearch(macAddr, vlanID, recordType); } else if (recordType == IX_ETH_DB_WIFI_RECORD || recordType == IX_ETH_DB_FIREWALL_RECORD) { IX_ETH_DB_CHECK_PORT_EXISTS(portID); result = ixEthDBPortSearch(macAddr, portID, recordType); } else { return IX_ETH_DB_INVALID_ARG; } if (result == NULL) { return IX_ETH_DB_NO_SUCH_ADDR; } *field = ((MacDescriptor *) result->data)->user; ixEthDBReleaseHashNode(result); return IX_ETH_DB_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -