📄 ixethdbnpeadaptor.c
字号:
* @param entryOffset: number of entries to offset * @param maxByteSize: maximum size of memory area to write to * * @return the byte offset of the next entry * * Used by @ref ixEthDBNPETreeWrite to liniarize a search tree * in NPE-readable format. * * @internal */IX_ETH_DB_PRIVATEUINT32 ixEthDBNPEFirewallMaskedNodeWrite(MacTreeNode *node, void *baseAddress, UINT32 entryOffset, UINT32 maxByteSize){ void *address = (void*) ((UINT32)baseAddress + (entryOffset * FW_M_ENTRY_SIZE)); UINT32 byteSize = (entryOffset+1) * FW_M_ENTRY_SIZE; /* if the size is greater than max, do nothing and return the max */ if(byteSize > maxByteSize) return byteSize; /* If node is NULL, zero out this record in memory */ if(NULL == node) { memset(address, 0, FW_M_ENTRY_SIZE); return byteSize; } /* set reserved fields */ NPE_NODE_BYTE(address, 0) = 0; NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_FW_RESERVED_OFFSET) = 0; NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_FW_RESERVED_OFFSET + 1) = 0; /* set flags */ NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_FW_FLAGS_OFFSET) = IX_EDB_FLAGS_VALID; /* copy mac address */ memcpy((void *) ((UINT32) address + IX_EDB_NPE_NODE_FW_ADDR_OFFSET), node->descriptor->macAddress, IX_IEEE803_MAC_ADDRESS_SIZE); /* copy address mask */ memcpy((void *) ((UINT32) address + IX_EDB_NPE_NODE_FW_MASK_OFFSET), node->descriptor->recordData.firewallData.addressMask, IX_IEEE803_MAC_ADDRESS_SIZE); return byteSize;}/** * @brief writes a firewall record in * NPE linear format * * @param node: node to be written * @param baseAddress: base memory address to write node to * @param entryOffset: number of entries to offset * @param maxByteSize: maximum size of memory area to write to * * @return the byte offset of the next entry * * Used by @ref ixEthDBNPETreeWrite to liniarize a search tree * in NPE-readable format. * * @internal */IX_ETH_DB_PRIVATEUINT32 ixEthDBNPEFirewallNodeWrite(MacTreeNode *node, void *baseAddress, UINT32 entryOffset, UINT32 maxByteSize){ void *address = (void*) ((UINT32)baseAddress + (entryOffset * FW_ENTRY_SIZE)); UINT32 byteSize = (entryOffset+1) * FW_ENTRY_SIZE; /* if the size is greater than max, do nothing and return the max */ if(byteSize > maxByteSize) return byteSize; /* If node is NULL, zero out this record in memory */ if(NULL == node) { memset(address, 0, FW_ENTRY_SIZE); return byteSize; } /* set reserved field */ NPE_NODE_BYTE(address, 0) = 0; /* set flags */ NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_FW_FLAGS_OFFSET) = IX_EDB_FLAGS_VALID; /* copy mac address */ memcpy((void *) ((UINT32) address + IX_EDB_NPE_NODE_FW_ADDR_OFFSET), node->descriptor->macAddress, IX_IEEE803_MAC_ADDRESS_SIZE); return byteSize;}/** * @brief registers the NPE serialization methods * * This functions registers NPE serialization methods * for writing the following types of records in NPE * readable linear format: * - filtering records * - WiFi header conversion records * - WiFi gateway header conversion records * - firewall records * * Note that this function should be called by the * component initialization function. * * @return number of registered record types * * @internal */IX_ETH_DB_PUBLICUINT32 ixEthDBRecordSerializeMethodsRegister(){ int i; /* safety - register a blank method for everybody first */ for ( i = 0 ; i < IX_ETH_DB_MAX_RECORD_TYPE_INDEX + 1 ; i++) { ixEthDBNPENodeWrite[i] = ixEthDBNullSerialize; } /* register real methods */ ixEthDBNPENodeWrite[IX_ETH_DB_FILTERING_RECORD] = ixEthDBNPELearningNodeWrite; ixEthDBNPENodeWrite[IX_ETH_DB_FILTERING_VLAN_RECORD] = ixEthDBNPELearningNodeWrite; ixEthDBNPENodeWrite[IX_ETH_DB_WIFI_RECORD] = ixEthDBNPEWiFiNodeWrite; ixEthDBNPENodeWrite[IX_ETH_DB_FIREWALL_RECORD] = ixEthDBNPEFirewallNodeWrite; ixEthDBNPENodeWrite[IX_ETH_DB_MASKED_FIREWALL_RECORD]= ixEthDBNPEFirewallMaskedNodeWrite; ixEthDBNPENodeWrite[IX_ETH_DB_GATEWAY_RECORD] = ixEthDBNPEGatewayNodeWrite; /* EP Delta arrays */ memset(ixEthDBEPDeltaOffset, 0, sizeof (ixEthDBEPDeltaOffset)); memset(ixEthDBEPDelta, 0, sizeof (ixEthDBEPDelta)); /* filtering records */ ixEthDBEPDeltaOffset[IX_ETH_DB_FILTERING_RECORD][0] = 1; ixEthDBEPDelta[IX_ETH_DB_FILTERING_RECORD][0] = 0; ixEthDBEPDeltaOffset[IX_ETH_DB_FILTERING_RECORD][1] = 3; ixEthDBEPDelta[IX_ETH_DB_FILTERING_RECORD][1] = 7; ixEthDBEPDeltaOffset[IX_ETH_DB_FILTERING_RECORD][2] = 511; ixEthDBEPDelta[IX_ETH_DB_FILTERING_RECORD][2] = 14; /* wifi records */ ixEthDBEPDeltaOffset[IX_ETH_DB_WIFI_RECORD][0] = 1; ixEthDBEPDelta[IX_ETH_DB_WIFI_RECORD][0] = 0; ixEthDBEPDeltaOffset[IX_ETH_DB_WIFI_RECORD][1] = 3; ixEthDBEPDelta[IX_ETH_DB_WIFI_RECORD][1] = 7; ixEthDBEPDeltaOffset[IX_ETH_DB_WIFI_RECORD][2] = 511; ixEthDBEPDelta[IX_ETH_DB_WIFI_RECORD][2] = 14; /* firewall records */ ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][0] = 0; ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][0] = 0; ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][1] = 1; ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][1] = 5; ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][2] = 3; ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][2] = 13; ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][3] = 7; ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][3] = 21; ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][4] = 15; ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][4] = 29; ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][5] = 31; ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][5] = 37; /* masked firewall records */ ixEthDBEPDeltaOffset[IX_ETH_DB_MASKED_FIREWALL_RECORD][0] = 0; ixEthDBEPDelta[IX_ETH_DB_MASKED_FIREWALL_RECORD][0] = 0; ixEthDBEPDeltaOffset[IX_ETH_DB_MASKED_FIREWALL_RECORD][1] = 1; ixEthDBEPDelta[IX_ETH_DB_MASKED_FIREWALL_RECORD][1] = 9; ixEthDBEPDeltaOffset[IX_ETH_DB_MASKED_FIREWALL_RECORD][2] = 3; ixEthDBEPDelta[IX_ETH_DB_MASKED_FIREWALL_RECORD][2] = 23; ixEthDBEPDeltaOffset[IX_ETH_DB_MASKED_FIREWALL_RECORD][3] = 7; ixEthDBEPDelta[IX_ETH_DB_MASKED_FIREWALL_RECORD][3] = 37; ixEthDBEPDeltaOffset[IX_ETH_DB_MASKED_FIREWALL_RECORD][4] = 15; ixEthDBEPDelta[IX_ETH_DB_MASKED_FIREWALL_RECORD][4] = 51; ixEthDBEPDeltaOffset[IX_ETH_DB_MASKED_FIREWALL_RECORD][5] = 31; ixEthDBEPDelta[IX_ETH_DB_MASKED_FIREWALL_RECORD][5] = 65; return 6; /* 6 methods registered */}#ifndef IX_NDEBUGIX_ETH_DB_PUBLIC UINT32 npeMsgHistory[IX_ETH_DB_NPE_MSG_HISTORY_DEPTH][2];IX_ETH_DB_PUBLIC UINT32 npeMsgHistoryLen = 0;/** * When compiled in DEBUG mode, this function can be used to display * the history of messages sent to the NPEs (up to 100). */IX_ETH_DB_PUBLICvoid ixEthDBShowNpeMsgHistory(){ UINT32 i = 0; UINT32 base, len; if (npeMsgHistoryLen <= IX_ETH_DB_NPE_MSG_HISTORY_DEPTH) { base = 0; len = npeMsgHistoryLen; } else { base = npeMsgHistoryLen % IX_ETH_DB_NPE_MSG_HISTORY_DEPTH; len = IX_ETH_DB_NPE_MSG_HISTORY_DEPTH; } printf("NPE message history [last %d messages, from least to most recent]:\n", len); for (; i < len ; i++) { UINT32 pos = (base + i) % IX_ETH_DB_NPE_MSG_HISTORY_DEPTH; printf("msg[%d]: 0x%08x:0x%08x\n", i, npeMsgHistory[pos][0], npeMsgHistory[pos][1]); }}IX_ETH_DB_PUBLICvoid ixEthDBELTShow(IxEthDBPortId portID){ IxNpeMhMessage message; IX_STATUS result; /* send EDB_GetMACAddressDatabase message */ FILL_GETMACADDRESSDATABASE(message, 0 /* reserved */, IX_OSAL_MMU_VIRT_TO_PHYS(ixEthDBPortInfo[portID].updateMethod.npeUpdateZone)); IX_ETHDB_SEND_NPE_MSG(IX_ETHNPE_PHYSICAL_ID_TO_NODE(portID), message, result); if (result == IX_SUCCESS) { /* analyze NPE copy */ UINT32 eltEntryOffset; UINT32 entryPortID; UINT32 eltBaseAddress = (UINT32) ixEthDBPortInfo[portID].updateMethod.npeUpdateZone; UINT32 eltSize = FULL_ELT_BYTE_SIZE; /* invalidate cache */ IX_OSAL_CACHE_INVALIDATE((void *) eltBaseAddress, eltSize); printf("Listing records in main learning tree for port %d\n", portID); for (eltEntryOffset = ELT_ROOT_OFFSET ; eltEntryOffset < eltSize ; eltEntryOffset += ELT_ENTRY_SIZE) { /* (eltBaseAddress + eltEntryOffset) points to a valid NPE tree node * * the format of the node is MAC[6 bytes]:PortID[1 byte]:Reserved[6 bits]:Active[1 bit]:Valid[1 bit] * therefore we can just use the pointer for database searches as only the first 6 bytes are checked */ void *eltNodeAddress = (void *) ((UINT32) eltBaseAddress + eltEntryOffset); if (IX_EDB_NPE_NODE_VALID(eltNodeAddress)) { HashNode *node; entryPortID = IX_ETHNPE_LOGICAL_ID_TO_PHYSICAL_ID(IX_EDB_NPE_NODE_PORT_ID(eltNodeAddress)); /* search record */ node = ixEthDBSearch((IxEthDBMacAddr *) eltNodeAddress, IX_ETH_DB_ALL_RECORD_TYPES); printf("%s - port %d - %s ", mac2string((unsigned char *) eltNodeAddress), entryPortID, IX_EDB_NPE_NODE_ACTIVE(eltNodeAddress) ? "active" : "inactive"); /* safety check, maybe user deleted record right before sync? */ if (node != NULL) { /* found record */ MacDescriptor *descriptor = (MacDescriptor *) node->data; printf("- %s ", descriptor->type == IX_ETH_DB_FILTERING_RECORD ? "filtering" : descriptor->type == IX_ETH_DB_FILTERING_VLAN_RECORD ? "vlan" : descriptor->type == IX_ETH_DB_WIFI_RECORD ? "wifi" : "other (check main DB)"); if (descriptor->type == IX_ETH_DB_FILTERING_RECORD) printf("- age %d - %s ", descriptor->recordData.filteringData.age, descriptor->recordData.filteringData.staticEntry ? "static" : "dynamic"); if (descriptor->type == IX_ETH_DB_FILTERING_VLAN_RECORD) printf("- age %d - %s - tci %d ", descriptor->recordData.filteringVlanData.age, descriptor->recordData.filteringVlanData.staticEntry ? "static" : "dynamic", descriptor->recordData.filteringVlanData.ieee802_1qTag); /* end transaction */ ixEthDBReleaseHashNode(node); } else { printf("- not synced"); } printf("\n"); } } } else { ixOsalLog(IX_OSAL_LOG_LVL_FATAL, IX_OSAL_LOG_DEV_STDOUT, "EthDB: (ShowELT) Could not complete action (communication failure)\n", portID, 0, 0, 0, 0, 0); }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -