| /* |
| * Copyright (c) 2018 The Linux Foundation. All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions are |
| * met: |
| * * Redistributions of source code must retain the above copyright |
| * notice, this list of conditions and the following disclaimer. |
| * * Redistributions in binary form must reproduce the above |
| * copyright notice, this list of conditions and the following |
| * disclaimer in the documentation and/or other materials provided |
| * with the distribution. |
| * * Neither the name of The Linux Foundation nor the names of its |
| * contributors may be used to endorse or promote products derived |
| * from this software without specific prior written permission. |
| * |
| * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <unistd.h> |
| #include <string.h> |
| #include <stdint.h> |
| #include <cstring> // for memcpy |
| #include "hton.h" // for htonl |
| #include "InterfaceAbstraction.h" |
| #include "Constants.h" |
| #include "Logger.h" |
| #include "TestsUtils.h" |
| #include "Filtering.h" |
| #include "RoutingDriverWrapper.h" |
| #include "IPAFilteringTable.h" |
| extern "C" { |
| #include "ipa_ipv6ct.h" |
| } |
| |
| #define IPV6_SRC_PORT_OFFSET (40) |
| #define IPV6_SRC_ADDRESS_MSB_OFFSET (8) |
| #define IPV6_SRC_ADDRESS_LSB_OFFSET (16) |
| #define IPV6_DST_ADDRESS_MSB_OFFSET (24) |
| #define IPV6_DST_ADDRESS_LSB_OFFSET (32) |
| #define IPV6_DST_PORT_OFFSET (40+2) |
| |
| #define IPV6_LOW_32_MASK (0xFFFFFFFF) |
| #define IPV6_HIGH_32_MASK (0xFFFFFFFF00000000) |
| |
| #define IPV6_BITS_IN_BYTE 8 |
| |
| inline uint32_t GetHigh32(uint64_t in) |
| { |
| return static_cast<uint32_t>((in & IPV6_HIGH_32_MASK) >> 32); |
| } |
| |
| inline uint32_t GetLow32(uint64_t in) |
| { |
| return static_cast<uint32_t>(in & IPV6_LOW_32_MASK); |
| } |
| |
| template <typename T> |
| T HostToNetwork(T in) |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| if (1 == htons(1)) |
| { |
| return in; |
| } |
| |
| static const T mask = 0xff; |
| T ret; |
| uint8_t* p = reinterpret_cast<uint8_t*>(&ret + 1); |
| while (in) |
| { |
| *--p = static_cast<uint8_t>(in & mask); |
| in >>= IPV6_BITS_IN_BYTE; |
| } |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return ret; |
| } |
| |
| extern Logger g_Logger; |
| |
| class IpaIPv6CTBlockTestFixture : public TestBase |
| { |
| public: |
| |
| IpaIPv6CTBlockTestFixture() : |
| m_sendSize(BUFF_MAX_SIZE), |
| m_sendSize2(BUFF_MAX_SIZE), |
| m_sendSize3(BUFF_MAX_SIZE), |
| m_outbound_dst_addr_msb(0XFF02000000000000), |
| m_outbound_dst_addr_lsb(0x11223344556677AA), |
| m_outbound_dst_port(1000), |
| m_outbound_src_addr_msb(m_outbound_dst_addr_msb), |
| m_outbound_src_addr_lsb(0x11223344556677CC), |
| m_outbound_src_port(1001), |
| m_direction_settings(IPA_IPV6CT_DIRECTION_ALLOW_ALL), |
| m_tableHandle(0) |
| { |
| memset(m_sendBuffer, 0, sizeof(m_sendBuffer)); // First input file / IP packet |
| memset(m_sendBuffer2, 0, sizeof(m_sendBuffer2)); // Second input file / IP packet |
| memset(m_sendBuffer3, 0, sizeof(m_sendBuffer3)); // Third input file (default) / IP packet |
| m_minIPAHwType = IPA_HW_v4_0; |
| m_testSuiteName.push_back("IPv6CT"); |
| } |
| |
| static int SetupKernelModule(bool en_status = false, bool ct_suppress = false) |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| int retval; |
| struct ipa_channel_config from_ipa_channels[3]; |
| struct test_ipa_ep_cfg from_ipa_cfg[3]; |
| struct ipa_channel_config to_ipa_channels[1]; |
| struct test_ipa_ep_cfg to_ipa_cfg[1]; |
| |
| struct ipa_test_config_header header = { 0 }; |
| struct ipa_channel_config *to_ipa_array[1]; |
| struct ipa_channel_config *from_ipa_array[3]; |
| |
| /* From ipa configurations - 3 pipes */ |
| memset(&from_ipa_cfg[0], 0, sizeof(from_ipa_cfg[0])); |
| prepare_channel_struct(&from_ipa_channels[0], |
| header.from_ipa_channels_num++, |
| IPA_CLIENT_TEST2_CONS, |
| (void *)&from_ipa_cfg[0], |
| sizeof(from_ipa_cfg[0]), |
| en_status); |
| from_ipa_array[0] = &from_ipa_channels[0]; |
| |
| memset(&from_ipa_cfg[1], 0, sizeof(from_ipa_cfg[1])); |
| prepare_channel_struct(&from_ipa_channels[1], |
| header.from_ipa_channels_num++, |
| IPA_CLIENT_TEST3_CONS, |
| (void *)&from_ipa_cfg[1], |
| sizeof(from_ipa_cfg[1]), |
| en_status); |
| from_ipa_array[1] = &from_ipa_channels[1]; |
| |
| memset(&from_ipa_cfg[2], 0, sizeof(from_ipa_cfg[2])); |
| prepare_channel_struct(&from_ipa_channels[2], |
| header.from_ipa_channels_num++, |
| IPA_CLIENT_TEST4_CONS, |
| (void *)&from_ipa_cfg[2], |
| sizeof(from_ipa_cfg[2]), |
| en_status); |
| from_ipa_array[2] = &from_ipa_channels[2]; |
| |
| /* To ipa configurations - 1 pipes */ |
| memset(&to_ipa_cfg[0], 0, sizeof(to_ipa_cfg[0])); |
| to_ipa_cfg[0].nat.nat_exc_suppress = ct_suppress; |
| prepare_channel_struct(&to_ipa_channels[0], |
| header.to_ipa_channels_num++, |
| IPA_CLIENT_TEST_PROD, |
| (void *)&to_ipa_cfg[0], |
| sizeof(to_ipa_cfg[0])); |
| to_ipa_array[0] = &to_ipa_channels[0]; |
| |
| prepare_header_struct(&header, from_ipa_array, to_ipa_array); |
| |
| retval = GenericConfigureScenario(&header); |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return retval; |
| } |
| |
| bool Setup(bool en_status = false, bool ct_suppress = false) |
| { |
| bool bRetVal = true; |
| |
| if (SetupKernelModule(en_status,ct_suppress) != true) |
| return bRetVal; |
| |
| m_producer.Open(INTERFACE0_TO_IPA_DATA_PATH, INTERFACE0_FROM_IPA_DATA_PATH); |
| |
| m_consumer.Open(INTERFACE1_TO_IPA_DATA_PATH, INTERFACE1_FROM_IPA_DATA_PATH); |
| m_consumer2.Open(INTERFACE2_TO_IPA_DATA_PATH, INTERFACE2_FROM_IPA_DATA_PATH); |
| m_defaultConsumer.Open(INTERFACE3_TO_IPA_DATA_PATH, INTERFACE3_FROM_IPA_DATA_PATH); |
| |
| if (!m_routing.DeviceNodeIsOpened()) |
| { |
| printf("Routing block is not ready for immediate commands!\n"); |
| return false; |
| } |
| |
| if (!m_filtering.DeviceNodeIsOpened()) |
| { |
| printf("Filtering block is not ready for immediate commands!\n"); |
| return false; |
| } |
| m_routing.Reset(IPA_IP_v4); // This will issue a Reset command to the Filtering as well |
| m_routing.Reset(IPA_IP_v6); // This will issue a Reset command to the Filtering as well |
| return true; |
| } // Setup() |
| |
| bool Teardown() |
| { |
| ipa_ipv6ct_dump_table(m_tableHandle); |
| ipa_ipv6ct_del_tbl(m_tableHandle); |
| |
| m_producer.Close(); |
| m_consumer.Close(); |
| m_consumer2.Close(); |
| m_defaultConsumer.Close(); |
| |
| return true; |
| } // Teardown() |
| |
| bool LoadFiles() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| |
| if (!LoadDefaultPacket(IPA_IP_v6, m_extHdrType, m_sendBuffer, m_sendSize)) |
| { |
| LOG_MSG_ERROR("Failed default Packet\n"); |
| return false; |
| } |
| printf("Loaded %zu Bytes to Buffer 1\n", m_sendSize); |
| |
| if (!LoadDefaultPacket(IPA_IP_v6, m_extHdrType, m_sendBuffer2, m_sendSize2)) |
| { |
| LOG_MSG_ERROR("Failed default Packet\n"); |
| return false; |
| } |
| printf("Loaded %zu Bytes to Buffer 2\n", m_sendSize2); |
| |
| if (!LoadDefaultPacket(IPA_IP_v6, m_extHdrType, m_sendBuffer3, m_sendSize3)) |
| { |
| LOG_MSG_ERROR("Failed default Packet\n"); |
| return false; |
| } |
| printf("Loaded %zu Bytes to Buffer 3\n", m_sendSize3); |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| } |
| |
| // This function creates three IPv6 bypass routing entries and commits them. |
| bool CreateThreeIPv6BypassRoutingTables(const char * bypass0, const char * bypass1, const char * bypass2) |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| struct ipa_ioc_add_rt_rule *rt_rule0 = 0, *rt_rule1 = 0, *rt_rule2 = 0; |
| struct ipa_rt_rule_add *rt_rule_entry; |
| |
| rt_rule0 = (struct ipa_ioc_add_rt_rule *) |
| calloc(1, |
| sizeof(struct ipa_ioc_add_rt_rule) + |
| 1 * sizeof(struct ipa_rt_rule_add) |
| ); |
| if (!rt_rule0) { |
| printf("calloc failed to allocate rt_rule0 in %s\n", __FUNCTION__); |
| return false; |
| } |
| rt_rule1 = (struct ipa_ioc_add_rt_rule *) |
| calloc(1, |
| sizeof(struct ipa_ioc_add_rt_rule) + |
| 1 * sizeof(struct ipa_rt_rule_add) |
| ); |
| if (!rt_rule1) { |
| printf("calloc failed to allocate rt_rule1 in %s\n", __FUNCTION__); |
| Free(rt_rule0); |
| return false; |
| } |
| rt_rule2 = (struct ipa_ioc_add_rt_rule *) |
| calloc(1, |
| sizeof(struct ipa_ioc_add_rt_rule) + |
| 1 * sizeof(struct ipa_rt_rule_add) |
| ); |
| if (!rt_rule2) { |
| printf("calloc failed to allocate rt_rule2 in %s\n", __FUNCTION__); |
| Free(rt_rule0); |
| Free(rt_rule1); |
| return false; |
| } |
| |
| rt_rule0->num_rules = 1; |
| rt_rule0->ip = IPA_IP_v6; |
| rt_rule0->commit = true; |
| strlcpy(rt_rule0->rt_tbl_name, bypass0, sizeof(rt_rule0->rt_tbl_name)); |
| |
| rt_rule_entry = &rt_rule0->rules[0]; |
| rt_rule_entry->at_rear = false; |
| rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS; |
| rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0xaabbccdd; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0xeeff0011; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x22334455; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0x66778899; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0x00000000;// All Packets will get a "Hit" |
| rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0x00000000; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0x00000000; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0x00000000; |
| if (false == m_routing.AddRoutingRule(rt_rule0)) |
| { |
| printf("Routing rule addition(rt_rule0) failed!\n"); |
| Free(rt_rule2); |
| Free(rt_rule1); |
| Free(rt_rule0); |
| return false; |
| } |
| |
| |
| rt_rule1->num_rules = 1; |
| rt_rule1->ip = IPA_IP_v6; |
| rt_rule1->commit = true; |
| strlcpy(rt_rule1->rt_tbl_name, bypass1, sizeof(rt_rule1->rt_tbl_name)); |
| rt_rule_entry = &rt_rule1->rules[0]; |
| rt_rule_entry->at_rear = false; |
| rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS; |
| rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0xaabbccdd; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0xeeff0011; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x22334455; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0x66778899; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0x00000000;// All Packets will get a "Hit" |
| rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0x00000000; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0x00000000; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0x00000000; |
| if (false == m_routing.AddRoutingRule(rt_rule1)) |
| { |
| printf("Routing rule addition(rt_rule1) failed!\n"); |
| Free(rt_rule2); |
| Free(rt_rule1); |
| Free(rt_rule0); |
| return false; |
| } |
| |
| |
| rt_rule2->num_rules = 1; |
| rt_rule2->ip = IPA_IP_v6; |
| rt_rule2->commit = true; |
| strlcpy(rt_rule2->rt_tbl_name, bypass2, sizeof(rt_rule2->rt_tbl_name)); |
| rt_rule_entry = &rt_rule2->rules[0]; |
| rt_rule_entry->at_rear = false; |
| rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS; |
| rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0xaabbccdd; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0xeeff0011; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x22334455; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0x66778899; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0x00000000;// All Packets will get a "Hit" |
| rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0x00000000; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0x00000000; |
| rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0x00000000; |
| if (false == m_routing.AddRoutingRule(rt_rule2)) |
| { |
| printf("Routing rule addition(rt_rule2) failed!\n"); |
| Free(rt_rule2); |
| Free(rt_rule1); |
| Free(rt_rule0); |
| return false; |
| } |
| |
| |
| Free(rt_rule2); |
| Free(rt_rule1); |
| Free(rt_rule0); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| } |
| |
| bool GetThreeIPv6BypassRoutingTables(uint32_t *Hndl0, uint32_t *Hndl1, uint32_t *Hndl2) |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| const char bypass0[20] = "Bypass0"; |
| const char bypass1[20] = "Bypass1"; |
| const char bypass2[20] = "Bypass2"; |
| struct ipa_ioc_get_rt_tbl routing_table0, routing_table1, routing_table2; |
| |
| if (!CreateThreeIPv6BypassRoutingTables(bypass0, bypass1, bypass2)) |
| { |
| printf("CreateThreeBypassRoutingTables Failed\n"); |
| return false; |
| } |
| |
| printf("CreateThreeBypassRoutingTables completed successfully\n"); |
| routing_table0.ip = IPA_IP_v6; |
| strlcpy(routing_table0.name, bypass0, sizeof(routing_table0.name)); |
| if (!m_routing.GetRoutingTable(&routing_table0)) |
| { |
| printf("m_routing.GetRoutingTable(&routing_table0=0x%pK) Failed.\n", &routing_table0); |
| return false; |
| } |
| routing_table1.ip = IPA_IP_v6; |
| strlcpy(routing_table1.name, bypass1, sizeof(routing_table1.name)); |
| if (!m_routing.GetRoutingTable(&routing_table1)) |
| { |
| printf("m_routing.GetRoutingTable(&routing_table1=0x%pK) Failed.\n", &routing_table1); |
| return false; |
| } |
| |
| routing_table2.ip = IPA_IP_v6; |
| strlcpy(routing_table2.name, bypass2, sizeof(routing_table2.name)); |
| if (!m_routing.GetRoutingTable(&routing_table2)) |
| { |
| printf("m_routing.GetRoutingTable(&routing_table2=0x%pK) Failed.\n", &routing_table2); |
| return false; |
| } |
| |
| *Hndl0 = routing_table0.hdl; |
| *Hndl1 = routing_table1.hdl; |
| *Hndl2 = routing_table2.hdl; |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| } |
| |
| bool AddIpv6ctTable() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| const int total_entries = 20; |
| |
| int result = ipa_ipv6ct_add_tbl(total_entries, &m_tableHandle); |
| if (result) |
| { |
| printf("Leaving %s, %s(), failed creating IPvC6T table with result %d\n", __FUNCTION__, __FILE__, result); |
| return false; |
| } |
| |
| printf("IPv6CT table added, hdl %d\n", m_tableHandle); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| } |
| |
| bool AddIpv6ctRule(ipa_ipv6ct_rule& rule, uint32_t& rule_hdl) const |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| |
| int result = ipa_ipv6ct_add_rule(m_tableHandle, &rule, &rule_hdl); |
| if (result) |
| { |
| printf("Leaving %s, %s(), failed creating IPvC6T rule with result %d\n", __FUNCTION__, __FILE__, result); |
| return false; |
| } |
| printf("IPv6CT rule added:\ndest lsb %llX, dest msb %llX, dest port %d\ndir %d, proto %d\nsrc lsb 0x%llX, src msb 0x%llX, src port %d\n", |
| (long long unsigned int)rule.dest_ipv6_lsb, (long long unsigned int)rule.dest_ipv6_msb, |
| rule.dest_port, rule.direction_settings, |
| rule.protocol, (long long unsigned int)rule.src_ipv6_lsb, (long long unsigned int)rule.src_ipv6_msb, |
| rule.src_port); |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| } |
| |
| void InitIpv6ctRule(ipa_ipv6ct_rule& rule, uint64_t change_bit) const |
| { |
| rule.dest_ipv6_lsb = m_outbound_dst_addr_lsb ^ change_bit; |
| rule.dest_ipv6_msb = m_outbound_dst_addr_msb; |
| rule.dest_port = m_outbound_dst_port; |
| rule.direction_settings = m_direction_settings; |
| rule.protocol = IPPROTO_TCP; |
| rule.src_ipv6_lsb = m_outbound_src_addr_lsb ^ change_bit; |
| rule.src_ipv6_msb = m_outbound_src_addr_msb; |
| rule.src_port = m_outbound_src_port; |
| } |
| |
| virtual bool AddIpv6ctRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| |
| ipa_ipv6ct_rule rule; |
| InitIpv6ctRule(rule, 0); |
| |
| uint32_t rule_hdl; |
| bool result = AddIpv6ctRule(rule, rule_hdl); |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| |
| virtual bool ModifyPackets() = 0; |
| virtual bool AddRoutingFilteringRules() = 0; |
| virtual bool ReceivePacketsAndCompare() = 0; |
| |
| bool Run() |
| { |
| bool res = false; |
| bool isSuccess = false; |
| |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| |
| res = AddRoutingFilteringRules(); |
| if (false == res) { |
| printf("Failed adding routing and filtering rules.\n"); |
| return false; |
| } |
| |
| res = AddIpv6ctTable(); |
| if (false == res) |
| { |
| printf("Failed adding IPv6 connection tracking table.\n"); |
| return false; |
| } |
| |
| res = AddIpv6ctRules(); |
| if (false == res) |
| { |
| printf("Failed adding IPv6 connection tracking rules.\n"); |
| return false; |
| } |
| |
| res = LoadFiles(); |
| if (false == res) { |
| printf("Failed loading files.\n"); |
| return false; |
| } |
| |
| res = ModifyPackets(); |
| if (false == res) { |
| printf("Failed to modify packets.\n"); |
| return false; |
| } |
| |
| // Send first packet |
| isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize); |
| if (false == isSuccess) |
| { |
| printf("SendData failure.\n"); |
| return false; |
| } |
| |
| // Receive packets from the channels and compare results |
| isSuccess = ReceivePacketsAndCompare(); |
| |
| printf("Leaving %s, %s(), Returning %d\n", __FUNCTION__, __FILE__, isSuccess); |
| |
| return isSuccess; |
| } // Run() |
| |
| void ModifyPackets(uint64_t dstAddrLsb, uint64_t dstAddrMsb, uint16_t dstPort, |
| uint64_t srcAddrLsb, uint64_t srcAddrMsb, uint16_t srcPort) |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| |
| // destination |
| uint64_t address = HostToNetwork(dstAddrLsb); |
| memcpy(&m_sendBuffer[IPV6_DST_ADDRESS_LSB_OFFSET], &address, sizeof(address)); |
| |
| address = HostToNetwork(dstAddrMsb); |
| memcpy(&m_sendBuffer[IPV6_DST_ADDRESS_MSB_OFFSET], &address, sizeof(address)); |
| |
| uint16_t port = ntohs(dstPort); |
| memcpy(&m_sendBuffer[IPV6_DST_PORT_OFFSET], &port, sizeof(port)); |
| |
| // source |
| address = HostToNetwork(srcAddrLsb); |
| memcpy(&m_sendBuffer[IPV6_SRC_ADDRESS_LSB_OFFSET], &address, sizeof(address)); |
| |
| address = HostToNetwork(srcAddrMsb); |
| memcpy(&m_sendBuffer[IPV6_SRC_ADDRESS_MSB_OFFSET], &address, sizeof(address)); |
| |
| port = ntohs(srcPort); |
| memcpy(&m_sendBuffer[IPV6_SRC_PORT_OFFSET], &port, sizeof(port)); |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| }// ModifyPacktes () |
| |
| virtual bool AddRoutingFilteringRules(enum ipa_flt_action flt_action, uint64_t dst_addr_msb, uint64_t dst_addr_lsb) |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| const char bypass0[20] = "Bypass0"; |
| const char bypass1[20] = "Bypass1"; |
| const char bypass2[20] = "Bypass2"; |
| |
| if (!CreateThreeIPv6BypassRoutingTables(bypass0, bypass1, bypass2)) |
| { |
| printf("CreateThreeBypassRoutingTables Failed\n"); |
| return false; |
| } |
| printf("CreateThreeBypassRoutingTables completed successfully\n"); |
| |
| ipa_ioc_get_rt_tbl routing_table0; |
| routing_table0.ip = IPA_IP_v6; |
| strlcpy(routing_table0.name, bypass0, sizeof(routing_table0.name)); |
| if (!m_routing.GetRoutingTable(&routing_table0)) |
| { |
| printf("m_routing.GetRoutingTable(&routing_table0=0x%pK) Failed.\n", &routing_table0); |
| return false; |
| } |
| |
| ipa_ioc_get_rt_tbl routing_table1; |
| routing_table1.ip = IPA_IP_v6; |
| strlcpy(routing_table1.name, bypass1, sizeof(routing_table1.name)); |
| if (!m_routing.GetRoutingTable(&routing_table1)) |
| { |
| printf("m_routing.GetRoutingTable(&routing_table1=0x%pK) Failed.\n", &routing_table1); |
| return false; |
| } |
| |
| IPAFilteringTable FilterTable0; |
| ipa_flt_rule_add flt_rule_entry; |
| FilterTable0.Init(IPA_IP_v6, IPA_CLIENT_TEST_PROD, false, 1); |
| |
| // Configuring Filtering Rule No.0 |
| FilterTable0.GeneratePresetRule(1, flt_rule_entry); |
| flt_rule_entry.at_rear = true; |
| flt_rule_entry.flt_rule_hdl = -1; // return Value |
| flt_rule_entry.status = -1; // return value |
| flt_rule_entry.rule.action = flt_action; |
| flt_rule_entry.rule.rt_tbl_hdl = routing_table0.hdl; //put here the handle corresponding to Routing Rule 1 |
| flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR; |
| |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[0] = GetHigh32(dst_addr_msb); // Filter DST_IP |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[1] = GetLow32(dst_addr_msb); |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[2] = GetHigh32(dst_addr_lsb); |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[3] = GetLow32(dst_addr_lsb); |
| |
| printf("flt_rule_entry was set successfully, preparing for insertion....\n"); |
| |
| if (((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry)) || |
| !m_filtering.AddFilteringRule(FilterTable0.GetFilteringTable())) |
| { |
| printf("%s::Error Adding Rule to Filter Table, aborting...\n", __FUNCTION__); |
| return false; |
| } |
| else |
| { |
| printf("flt rule hdl0=0x%x, status=0x%x\n", |
| FilterTable0.ReadRuleFromTable(0)->flt_rule_hdl, FilterTable0.ReadRuleFromTable(0)->status); |
| } |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ReceivePacketsAndCompare(bool packetPassExpected) |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| |
| // Receive results |
| Byte rxBuff1[0x400]; |
| size_t receivedSize = m_consumer.ReceiveData(rxBuff1, 0x400); |
| printf("Received %zu bytes on %s.\n", receivedSize, m_consumer.m_fromChannelName.c_str()); |
| |
| bool isSuccess = true; |
| if (packetPassExpected) |
| { |
| // Compare results |
| if (!CompareResultVsGolden(m_sendBuffer, m_sendSize, rxBuff1, receivedSize)) |
| { |
| printf("Comparison of Buffer0 Failed!\n"); |
| isSuccess = false; |
| } |
| } |
| else |
| { |
| if (receivedSize) |
| { |
| isSuccess = false; |
| printf("got data while expected packet to be blocked, failing\n"); |
| } |
| } |
| |
| char recievedBuffer[256] = {0}; |
| char SentBuffer[256] = {0}; |
| size_t j; |
| |
| for (j = 0; j < m_sendSize; j++) |
| { |
| snprintf(&SentBuffer[3 * j], sizeof(SentBuffer)-(3 * j + 1), " %02X", m_sendBuffer[j]); |
| } |
| |
| for (j = 0; j < receivedSize; j++) |
| { |
| snprintf(&recievedBuffer[3 * j], sizeof(recievedBuffer)-(3 * j + 1), " %02X", rxBuff1[j]); |
| } |
| printf("Expected Value1 (%zu)\n%s\n, Received Value1(%zu)\n%s\n", |
| m_sendSize, SentBuffer, receivedSize, recievedBuffer); |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return isSuccess; |
| } |
| |
| protected: |
| |
| static Filtering m_filtering; |
| static RoutingDriverWrapper m_routing; |
| InterfaceAbstraction m_producer; |
| InterfaceAbstraction m_consumer; |
| InterfaceAbstraction m_consumer2; |
| InterfaceAbstraction m_defaultConsumer; |
| |
| static const size_t BUFF_MAX_SIZE = 1024; |
| |
| Byte m_sendBuffer[BUFF_MAX_SIZE]; // First input file / IP packet |
| Byte m_sendBuffer2[BUFF_MAX_SIZE]; // Second input file / IP packet |
| Byte m_sendBuffer3[BUFF_MAX_SIZE]; // Third input file (default) / IP packet |
| size_t m_sendSize; |
| size_t m_sendSize2; |
| size_t m_sendSize3; |
| static const ipv6_ext_hdr_type m_extHdrType = NONE; |
| |
| uint64_t m_outbound_dst_addr_msb; |
| uint64_t m_outbound_dst_addr_lsb; |
| uint16_t m_outbound_dst_port; |
| uint64_t m_outbound_src_addr_msb; |
| uint64_t m_outbound_src_addr_lsb; |
| uint16_t m_outbound_src_port; |
| ipa_ipv6_ct_direction_settings_type m_direction_settings; |
| |
| uint32_t m_tableHandle; |
| }; |
| |
| RoutingDriverWrapper IpaIPv6CTBlockTestFixture::m_routing; |
| Filtering IpaIPv6CTBlockTestFixture::m_filtering; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test001: IPv6CT send outbound packet */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest001 : public IpaIPv6CTBlockTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest001() |
| { |
| m_name = "IpaIPV6CTBlockTest001"; |
| m_description = |
| "IPv6CT block test 001 - IPv6CT passes successfully one packet in outbound direction\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add IPv6CT rule for the packet\n"; |
| Register(*this); |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT, |
| m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port, |
| m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test002: IPv6CT send inbound packet */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest002 : public IpaIPv6CTBlockTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest002() |
| { |
| m_name = "IpaIPV6CTBlockTest002"; |
| m_description = |
| "IPv6CT block test 002 - IPv6CT passes successfully one packet in inbound direction\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add IPv6CT rule for the packet\n"; |
| Register(*this); |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT, |
| m_outbound_src_addr_msb, m_outbound_src_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port, |
| m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test003: IPv6CT send outbound packet - without IPV6CT rule */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest003 : public IpaIPv6CTBlockTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest003() |
| { |
| m_name = "IpaIPV6CTBlockTest003"; |
| m_description = |
| "IPv6CT block test 003 - IPv6CT blocks one packet in outbound direction due to rule absence\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n"; |
| Register(*this); |
| } |
| |
| virtual bool AddIpv6ctRules() |
| { |
| printf("not adding IPv6CT rule for packet - blocking expected %s %s\n", __FUNCTION__, __FILE__); |
| return true; |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT, |
| m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port, |
| m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test004: IPv6CT send inbound packet - without IPV6CT rule */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest004 : public IpaIPv6CTBlockTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest004() |
| { |
| m_name = "IpaIPV6CTBlockTest004"; |
| m_description = |
| "IPv6CT block test 004 - IPv6CT blocks one packet in inbound direction due to rule absence\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n"; |
| Register(*this); |
| } |
| |
| virtual bool AddIpv6ctRules() |
| { |
| printf("not adding IPv6CT rule for packet - blocking expected %s %s\n", __FUNCTION__, __FILE__); |
| return true; |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT, |
| m_outbound_src_addr_msb, m_outbound_src_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port, |
| m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test005: IPv6CT send outbound packet with inbound filtering rule */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest005 : public IpaIPv6CTBlockTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest005() |
| { |
| m_name = "IpaIPV6CTBlockTest005"; |
| m_description = |
| "IPv6CT block test 005 - IPv6CT blocks one packet in outbound direction, because the filtering rule\n" |
| " action is inbound\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add IPv6CT rule for the packet\n"; |
| Register(*this); |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT, |
| m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port, |
| m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test006: IPv6CT send inbound packet with outbound filtering rule */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest006 : public IpaIPv6CTBlockTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest006() |
| { |
| m_name = "IpaIPV6CTBlockTest006"; |
| m_description = |
| "IPv6CT block test 006 - IPv6CT blocks one packet in inbound direction, because the filtering rule\n" |
| " action is outbound\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add IPv6CT rule for the packet\n"; |
| Register(*this); |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT, |
| m_outbound_src_addr_msb, m_outbound_src_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port, |
| m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test007: IPv6CT block outbound packet while disabled outbound direction */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest007 : public IpaIPv6CTBlockTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest007() |
| { |
| m_name = "IpaIPV6CTBlockTest007"; |
| m_description = |
| "IPv6CT block test 007 - IPv6CT blocks one packet in outbound direction, because the outbound direction\n" |
| " is disabled\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add IPv6CT rule for the packet with disabled outbound direction\n"; |
| m_direction_settings = IPA_IPV6CT_DIRECTION_ALLOW_IN; |
| Register(*this); |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT, |
| m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port, |
| m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test008: IPv6CT block inbound packet with disabled inbound direction */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest008 : public IpaIPv6CTBlockTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest008() |
| { |
| m_name = "IpaIPV6CTBlockTest008"; |
| m_description = |
| "IPv6CT block test 008 - IPv6CT blocks one packet in inbound direction, because the inbound direction\n" |
| " is disabled\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add IPv6CT rule for the packet with disabled inbound direction\n"; |
| m_direction_settings = IPA_IPV6CT_DIRECTION_ALLOW_OUT; |
| Register(*this); |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT, |
| m_outbound_src_addr_msb, m_outbound_src_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port, |
| m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| class IpaIPv6CTBlockExpansionTableTestFixture : public IpaIPv6CTBlockTestFixture |
| { |
| public: |
| |
| virtual bool AddIpv6ctRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| |
| ipa_ipv6ct_rule rule; |
| InitIpv6ctRule(rule, 8); |
| |
| uint32_t rule_hdl; |
| if (!AddIpv6ctRule(rule, rule_hdl)) |
| { |
| return false; |
| } |
| |
| bool result = IpaIPv6CTBlockTestFixture::AddIpv6ctRules(); |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test009: IPv6CT send outbound packet with rule in expansion table */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest009 : public IpaIPv6CTBlockExpansionTableTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest009() |
| { |
| m_name = "IpaIPV6CTBlockTest009"; |
| m_description = |
| "IPv6CT block test 009 - IPv6CT passes successfully one packet in outbound direction with rule in\n" |
| " expansion table\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add an IPv6CT rule to occupy base table. This rule is not supposed to match a packet\n" |
| "4. Add IPv6CT rule for the packet to the expansion table\n"; |
| Register(*this); |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT, |
| m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port, |
| m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test010: IPv6CT send inbound packet with rule in expansion table */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest010 : public IpaIPv6CTBlockExpansionTableTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest010() |
| { |
| m_name = "IpaIPV6CTBlockTest010"; |
| m_description = |
| "IPv6CT block test 010 - IPv6CT passes successfully one packet in inbound direction with rule in\n" |
| " expansion table\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add an IPv6CT rule to occupy base table. This rule is not supposed to match a packet\n" |
| "4. Add IPv6CT rule for the packet to the expansion table\n"; |
| Register(*this); |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT, |
| m_outbound_src_addr_msb, m_outbound_src_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port, |
| m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| class IpaIPv6CTBlockRuleDeleteTestFixture : public IpaIPv6CTBlockTestFixture |
| { |
| public: |
| |
| virtual bool AddIpv6ctRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| |
| ipa_ipv6ct_rule rule; |
| InitIpv6ctRule(rule, 0); |
| |
| uint32_t rule_hdl; |
| if (!AddIpv6ctRule(rule, rule_hdl)) |
| { |
| return false; |
| } |
| |
| int result = ipa_ipv6ct_del_rule(m_tableHandle, rule_hdl); |
| if (result) |
| { |
| printf("Leaving %s, %s(), failed delete IPvC6T rule %d with result %d\n", __FUNCTION__, __FILE__, |
| rule_hdl, result); |
| return false; |
| } |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test011: IPv6CT block outbound packet while the rule was deleted */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest011 : public IpaIPv6CTBlockRuleDeleteTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest011() |
| { |
| m_name = "IpaIPV6CTBlockTest011"; |
| m_description = |
| "IPv6CT block test 011 - IPv6CT blocks one packet in outbound direction due to the rule deletion\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add IPv6CT rule for the packet\n" |
| "4. Delete IPv6CT rule for the packet\n"; |
| Register(*this); |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT, |
| m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port, |
| m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test012: IPv6CT block inbound packet while the rule was deleted */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest012 : public IpaIPv6CTBlockRuleDeleteTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest012() |
| { |
| m_name = "IpaIPV6CTBlockTest012"; |
| m_description = |
| "IPv6CT block test 012 - IPv6CT blocks one packet in inbound direction due to the rule deletion\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add IPv6CT rule for the packet\n" |
| "4. Delete IPv6CT rule for the packet\n"; |
| Register(*this); |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT, |
| m_outbound_src_addr_msb, m_outbound_src_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port, |
| m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| class IpaIPv6CTBlockRuleDeleteExpansionTableTestFixture : public IpaIPv6CTBlockRuleDeleteTestFixture |
| { |
| public: |
| |
| virtual bool AddIpv6ctRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| |
| ipa_ipv6ct_rule rule; |
| InitIpv6ctRule(rule, 8); |
| |
| uint32_t rule_hdl; |
| if (!AddIpv6ctRule(rule, rule_hdl)) |
| { |
| return false; |
| } |
| |
| bool result = IpaIPv6CTBlockRuleDeleteTestFixture::AddIpv6ctRules(); |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test013: IPv6CT block outbound packet while the rule in expansion table was deleted */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest013 : public IpaIPv6CTBlockRuleDeleteExpansionTableTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest013() |
| { |
| m_name = "IpaIPV6CTBlockTest013"; |
| m_description = |
| "IPv6CT block test 013 - IPv6CT blocks one packet in outbound direction due to the rule deletion from\n" |
| " the expansion table\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add an IPv6CT rule to occupy base table. This rule is not supposed to match a packet\n" |
| "4. Add IPv6CT rule for the packet to the expansion table\n" |
| "5. Delete IPv6CT rule for the packet from the expansion table\n"; |
| Register(*this); |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT, |
| m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port, |
| m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test014: IPv6CT block inbound packet while the rule in expansion table was deleted */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest014 : public IpaIPv6CTBlockRuleDeleteExpansionTableTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest014() |
| { |
| m_name = "IpaIPV6CTBlockTest014"; |
| m_description = |
| "IPv6CT block test 014 - IPv6CT blocks one packet in inbound direction due to the rule deletion from\n" |
| " the expansion table\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add an IPv6CT rule to occupy base table. This rule is not supposed to match a packet\n" |
| "4. Add IPv6CT rule for the packet to the expansion table\n" |
| "5. Delete IPv6CT rule for the packet from the expansion table\n"; |
| Register(*this); |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT, |
| m_outbound_src_addr_msb, m_outbound_src_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port, |
| m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(false); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| class IpaIPv6CTBlockHeadRuleDeleteTestFixture : public IpaIPv6CTBlockTestFixture |
| { |
| public: |
| |
| virtual bool AddIpv6ctRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| |
| ipa_ipv6ct_rule rule; |
| InitIpv6ctRule(rule, 8); |
| |
| uint32_t rule_hdl; |
| if (!AddIpv6ctRule(rule, rule_hdl)) |
| { |
| return false; |
| } |
| |
| if (!IpaIPv6CTBlockTestFixture::AddIpv6ctRules()) |
| { |
| return false; |
| } |
| |
| int result = ipa_ipv6ct_del_rule(m_tableHandle, rule_hdl); |
| if (result) |
| { |
| printf("Leaving %s, %s(), failed delete IPvC6T rule %d with result %d\n", __FUNCTION__, __FILE__, |
| rule_hdl, result); |
| return false; |
| } |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------------------------*/ |
| /* Test015: IPv6CT send outbound packet with rule in expansion table while the rule in the list head was deleted */ |
| /*---------------------------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest015 : public IpaIPv6CTBlockHeadRuleDeleteTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest015() |
| { |
| m_name = "IpaIPV6CTBlockTest015"; |
| m_description = |
| "IPv6CT block test 015 - IPv6CT passes successfully one packet in outbound direction with rule in\n" |
| " expansion table, while the list head was deleted\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add an IPv6CT rule to occupy base table. This rule is not supposed to match a packet\n" |
| "4. Add IPv6CT rule for the packet to the expansion table\n" |
| "5. Delete IPv6CT rule in the list head\n"; |
| Register(*this); |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT, |
| m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port, |
| m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------------------------*/ |
| /* Test016: IPv6CT send inbound packet with rule in expansion table while the rule in the list head was deleted */ |
| /*---------------------------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest016 : public IpaIPv6CTBlockHeadRuleDeleteTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest016() |
| { |
| m_name = "IpaIPV6CTBlockTest016"; |
| m_description = |
| "IPv6CT block test 016 - IPv6CT passes successfully one packet in inbound direction with rule in\n" |
| " expansion table, while the list head was deleted\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add an IPv6CT rule to occupy base table. This rule is not supposed to match a packet\n" |
| "4. Add IPv6CT rule for the packet to the expansion table\n" |
| "5. Delete IPv6CT rule in the list head\n"; |
| Register(*this); |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT, |
| m_outbound_src_addr_msb, m_outbound_src_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port, |
| m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| class IpaIPv6CTBlockMiddleRuleDeleteTestFixture : public IpaIPv6CTBlockHeadRuleDeleteTestFixture |
| { |
| public: |
| |
| virtual bool AddIpv6ctRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| |
| ipa_ipv6ct_rule rule; |
| InitIpv6ctRule(rule, 1); |
| |
| uint32_t rule_hdl; |
| if (!AddIpv6ctRule(rule, rule_hdl)) |
| { |
| return false; |
| } |
| |
| bool result = IpaIPv6CTBlockHeadRuleDeleteTestFixture::AddIpv6ctRules(); |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*------------------------------------------------------------------------------------------------------------*/ |
| /* Test017: IPv6CT send outbound packet with rule in expansion table while the rule in the middle of the list */ |
| /* was deleted */ |
| /*------------------------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest017 : public IpaIPv6CTBlockMiddleRuleDeleteTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest017() |
| { |
| m_name = "IpaIPV6CTBlockTest017"; |
| m_description = |
| "IPv6CT block test 017 - IPv6CT passes successfully one packet in outbound direction with rule in\n" |
| " expansion table, while the rule in the middle of the list was deleted\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add two IPv6CT rules: one to base table and other to expansion table. These rules are not supposed\n" |
| " to match a packet\n" |
| "4. Add IPv6CT rule for the packet to the expansion table\n" |
| "5. Delete IPv6CT rule in the middle of the list\n"; |
| Register(*this); |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT, |
| m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port, |
| m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*------------------------------------------------------------------------------------------------------------*/ |
| /* Test018: IPv6CT send inbound packet with rule in expansion table while the rule in the middle of the list */ |
| /* was deleted */ |
| /*------------------------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest018 : public IpaIPv6CTBlockMiddleRuleDeleteTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest018() |
| { |
| m_name = "IpaIPV6CTBlockTest018"; |
| m_description = |
| "IPv6CT block test 018 - IPv6CT passes successfully one packet in inbound direction with rule in\n" |
| " expansion table, while the rule in the middle of the list was deleted\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add two IPv6CT rules to occupy base table and the middle of the list. These rules are not supposed\n" |
| " to match a packet\n" |
| "4. Add IPv6CT rule for the packet to the expansion table\n" |
| "5. Delete IPv6CT rule in the middle of the list\n"; |
| Register(*this); |
| } |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT, |
| m_outbound_src_addr_msb, m_outbound_src_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port, |
| m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test019: IPv6CT send outbound packet, suppression test */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest019 : public IpaIPv6CTBlockTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest019() |
| { |
| m_name = "IpaIPV6CTBlockTest019"; |
| m_description = |
| "IPv6CT block test 019 - IPv6CT passes successfully one packet in outbound direction\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add IPv6CT rule for the packet which doesn't match\n" |
| "4. Expect NAT supporession to kick in and packet is routed correctly\n"; |
| Register(*this); |
| } |
| |
| virtual bool Setup() |
| { |
| /* we want statuses on this test */ |
| return IpaIPv6CTBlockTestFixture::Setup(false, true); |
| } |
| |
| virtual bool AddRoutingFilteringRules(enum ipa_flt_action flt_action, uint64_t dst_addr_msb, uint64_t dst_addr_lsb) |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| const char bypass0[20] = "Bypass0"; |
| const char bypass1[20] = "Bypass1"; |
| const char bypass2[20] = "Bypass2"; |
| |
| if (!CreateThreeIPv6BypassRoutingTables(bypass0, bypass1, bypass2)) |
| { |
| printf("CreateThreeBypassRoutingTables Failed\n"); |
| return false; |
| } |
| printf("CreateThreeBypassRoutingTables completed successfully\n"); |
| |
| ipa_ioc_get_rt_tbl routing_table0; |
| routing_table0.ip = IPA_IP_v6; |
| strlcpy(routing_table0.name, bypass0, sizeof(routing_table0.name)); |
| if (!m_routing.GetRoutingTable(&routing_table0)) |
| { |
| printf("m_routing.GetRoutingTable(&routing_table0=0x%pK) Failed.\n", &routing_table0); |
| return false; |
| } |
| |
| /* Setup conntrack exception routing table. */ |
| if (!m_routing.SetNatConntrackExcRoutingTable(routing_table0.hdl, false)) |
| { |
| LOG_MSG_ERROR("m_routing.SetNatConntrackExcRoutingTable(routing_table0 hdl=%d) Failed.\n", |
| routing_table0.hdl); |
| return false; |
| } |
| |
| ipa_ioc_get_rt_tbl routing_table1; |
| routing_table1.ip = IPA_IP_v6; |
| strlcpy(routing_table1.name, bypass1, sizeof(routing_table1.name)); |
| if (!m_routing.GetRoutingTable(&routing_table1)) |
| { |
| printf("m_routing.GetRoutingTable(&routing_table1=0x%pK) Failed.\n", &routing_table1); |
| return false; |
| } |
| |
| IPAFilteringTable FilterTable0; |
| ipa_flt_rule_add flt_rule_entry; |
| FilterTable0.Init(IPA_IP_v6, IPA_CLIENT_TEST_PROD, false, 1); |
| |
| // Configuring Filtering Rule No.0 |
| FilterTable0.GeneratePresetRule(1, flt_rule_entry); |
| flt_rule_entry.at_rear = true; |
| flt_rule_entry.flt_rule_hdl = -1; // return Value |
| flt_rule_entry.status = -1; // return value |
| flt_rule_entry.rule.action = flt_action; |
| flt_rule_entry.rule.rt_tbl_hdl = routing_table0.hdl; //put here the handle corresponding to Routing Rule 1 |
| flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR; |
| |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[0] = GetHigh32(dst_addr_msb); // Filter DST_IP |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[1] = GetLow32(dst_addr_msb); |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[2] = GetHigh32(dst_addr_lsb); |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[3] = GetLow32(dst_addr_lsb); |
| |
| printf("flt_rule_entry was set successfully, preparing for insertion....\n"); |
| |
| if (((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry)) || |
| !m_filtering.AddFilteringRule(FilterTable0.GetFilteringTable())) |
| { |
| printf("%s::Error Adding Rule to Filter Table, aborting...\n", __FUNCTION__); |
| return false; |
| } |
| else |
| { |
| printf("flt rule hdl0=0x%x, status=0x%x\n", |
| FilterTable0.ReadRuleFromTable(0)->flt_rule_hdl, FilterTable0.ReadRuleFromTable(0)->status); |
| } |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT, |
| m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port, |
| m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port+1); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test020: IPv6CT send inbound packet for NAT suppression test */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest020 : public IpaIPv6CTBlockTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest020() |
| { |
| m_name = "IpaIPV6CTBlockTest020"; |
| m_description = |
| "IPv6CT block test 020 - IPv6CT passes successfully one packet in inbound direction on NAT suppression\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add IPv6CT rule for the packet\n"; |
| Register(*this); |
| } |
| |
| virtual bool Setup() |
| { |
| /* we want statuses on this test */ |
| return IpaIPv6CTBlockTestFixture::Setup(false, true); |
| } |
| |
| virtual bool AddRoutingFilteringRules(enum ipa_flt_action flt_action, uint64_t dst_addr_msb, uint64_t dst_addr_lsb) |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| const char bypass0[20] = "Bypass0"; |
| const char bypass1[20] = "Bypass1"; |
| const char bypass2[20] = "Bypass2"; |
| |
| if (!CreateThreeIPv6BypassRoutingTables(bypass0, bypass1, bypass2)) |
| { |
| printf("CreateThreeBypassRoutingTables Failed\n"); |
| return false; |
| } |
| printf("CreateThreeBypassRoutingTables completed successfully\n"); |
| |
| ipa_ioc_get_rt_tbl routing_table0; |
| routing_table0.ip = IPA_IP_v6; |
| strlcpy(routing_table0.name, bypass0, sizeof(routing_table0.name)); |
| if (!m_routing.GetRoutingTable(&routing_table0)) |
| { |
| printf("m_routing.GetRoutingTable(&routing_table0=0x%pK) Failed.\n", &routing_table0); |
| return false; |
| } |
| |
| /* Setup conntrack exception routing table. */ |
| if (!m_routing.SetNatConntrackExcRoutingTable(routing_table0.hdl, false)) |
| { |
| LOG_MSG_ERROR("m_routing.SetNatConntrackExcRoutingTable(routing_table0 hdl=%d) Failed.\n", |
| routing_table0.hdl); |
| return false; |
| } |
| |
| ipa_ioc_get_rt_tbl routing_table1; |
| routing_table1.ip = IPA_IP_v6; |
| strlcpy(routing_table1.name, bypass1, sizeof(routing_table1.name)); |
| if (!m_routing.GetRoutingTable(&routing_table1)) |
| { |
| printf("m_routing.GetRoutingTable(&routing_table1=0x%pK) Failed.\n", &routing_table1); |
| return false; |
| } |
| |
| IPAFilteringTable FilterTable0; |
| ipa_flt_rule_add flt_rule_entry; |
| FilterTable0.Init(IPA_IP_v6, IPA_CLIENT_TEST_PROD, false, 1); |
| |
| // Configuring Filtering Rule No.0 |
| FilterTable0.GeneratePresetRule(1, flt_rule_entry); |
| flt_rule_entry.at_rear = true; |
| flt_rule_entry.flt_rule_hdl = -1; // return Value |
| flt_rule_entry.status = -1; // return value |
| flt_rule_entry.rule.action = flt_action; |
| flt_rule_entry.rule.rt_tbl_hdl = routing_table0.hdl; //put here the handle corresponding to Routing Rule 1 |
| flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR; |
| |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[0] = GetHigh32(dst_addr_msb); // Filter DST_IP |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[1] = GetLow32(dst_addr_msb); |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[2] = GetHigh32(dst_addr_lsb); |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[3] = GetLow32(dst_addr_lsb); |
| |
| printf("flt_rule_entry was set successfully, preparing for insertion....\n"); |
| |
| if (((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry)) || |
| !m_filtering.AddFilteringRule(FilterTable0.GetFilteringTable())) |
| { |
| printf("%s::Error Adding Rule to Filter Table, aborting...\n", __FUNCTION__); |
| return false; |
| } |
| else |
| { |
| printf("flt rule hdl0=0x%x, status=0x%x\n", |
| FilterTable0.ReadRuleFromTable(0)->flt_rule_hdl, FilterTable0.ReadRuleFromTable(0)->status); |
| } |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT, |
| m_outbound_src_addr_msb, m_outbound_src_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port, |
| m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port+1); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::ReceivePacketsAndCompare(true); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test021: IPv6CT send outbound packet, suppression test with status enabled */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest021 : public IpaIPv6CTBlockTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest021() |
| { |
| m_name = "IpaIPV6CTBlockTest021"; |
| m_description = |
| "IPv6CT block test 021 - IPv6CT passes successfully one packet in outbound direction\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one outbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add IPv6CT rule for the packet which doesn't match\n" |
| "4. Expect NAT suppression to kick in and packet is routed correctly\n" |
| "5. Compare status and check if NAT suppression kicked in.\n"; |
| Register(*this); |
| } |
| |
| virtual bool Setup() |
| { |
| /* we want statuses on this test */ |
| return IpaIPv6CTBlockTestFixture::Setup(true, true); |
| } |
| |
| virtual bool AddRoutingFilteringRules(enum ipa_flt_action flt_action, uint64_t dst_addr_msb, uint64_t dst_addr_lsb) |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| const char bypass0[20] = "Bypass0"; |
| const char bypass1[20] = "Bypass1"; |
| const char bypass2[20] = "Bypass2"; |
| |
| if (!CreateThreeIPv6BypassRoutingTables(bypass0, bypass1, bypass2)) |
| { |
| printf("CreateThreeBypassRoutingTables Failed\n"); |
| return false; |
| } |
| printf("CreateThreeBypassRoutingTables completed successfully\n"); |
| |
| ipa_ioc_get_rt_tbl routing_table0; |
| routing_table0.ip = IPA_IP_v6; |
| strlcpy(routing_table0.name, bypass0, sizeof(routing_table0.name)); |
| if (!m_routing.GetRoutingTable(&routing_table0)) |
| { |
| printf("m_routing.GetRoutingTable(&routing_table0=0x%pK) Failed.\n", &routing_table0); |
| return false; |
| } |
| |
| /* Setup conntrack exception routing table. */ |
| if (!m_routing.SetNatConntrackExcRoutingTable(routing_table0.hdl, false)) |
| { |
| LOG_MSG_ERROR("m_routing.SetNatConntrackExcRoutingTable(routing_table0 hdl=%d) Failed.\n", |
| routing_table0.hdl); |
| return false; |
| } |
| |
| ipa_ioc_get_rt_tbl routing_table1; |
| routing_table1.ip = IPA_IP_v6; |
| strlcpy(routing_table1.name, bypass1, sizeof(routing_table1.name)); |
| if (!m_routing.GetRoutingTable(&routing_table1)) |
| { |
| printf("m_routing.GetRoutingTable(&routing_table1=0x%pK) Failed.\n", &routing_table1); |
| return false; |
| } |
| |
| IPAFilteringTable FilterTable0; |
| ipa_flt_rule_add flt_rule_entry; |
| FilterTable0.Init(IPA_IP_v6, IPA_CLIENT_TEST_PROD, false, 1); |
| |
| // Configuring Filtering Rule No.0 |
| FilterTable0.GeneratePresetRule(1, flt_rule_entry); |
| flt_rule_entry.at_rear = true; |
| flt_rule_entry.flt_rule_hdl = -1; // return Value |
| flt_rule_entry.status = -1; // return value |
| flt_rule_entry.rule.action = flt_action; |
| flt_rule_entry.rule.rt_tbl_hdl = routing_table0.hdl; //put here the handle corresponding to Routing Rule 1 |
| flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR; |
| |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[0] = GetHigh32(dst_addr_msb); // Filter DST_IP |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[1] = GetLow32(dst_addr_msb); |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[2] = GetHigh32(dst_addr_lsb); |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[3] = GetLow32(dst_addr_lsb); |
| |
| printf("flt_rule_entry was set successfully, preparing for insertion....\n"); |
| |
| if (((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry)) || |
| !m_filtering.AddFilteringRule(FilterTable0.GetFilteringTable())) |
| { |
| printf("%s::Error Adding Rule to Filter Table, aborting...\n", __FUNCTION__); |
| return false; |
| } |
| else |
| { |
| printf("flt rule hdl0=0x%x, status=0x%x\n", |
| FilterTable0.ReadRuleFromTable(0)->flt_rule_hdl, FilterTable0.ReadRuleFromTable(0)->status); |
| } |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = AddRoutingFilteringRules(IPA_PASS_TO_SRC_NAT, |
| m_outbound_dst_addr_msb, m_outbound_dst_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port, |
| m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port+1); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare(bool packetPassExpected) |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| |
| // Receive results |
| struct ipa3_hw_pkt_status_hw_v5_5 *status = NULL; |
| Byte rxBuff1[0x400]; |
| size_t receivedSize = m_consumer.ReceiveData(rxBuff1, 0x400); |
| printf("Received %zu bytes on %s.\n", receivedSize, m_consumer.m_fromChannelName.c_str()); |
| |
| bool isSuccess = true; |
| if (packetPassExpected) |
| { |
| // Compare results |
| if (!CompareResultVsGolden_w_Status(m_sendBuffer, m_sendSize, rxBuff1, receivedSize)) |
| { |
| printf("Comparison of Buffer0 Failed!\n"); |
| isSuccess = false; |
| } |
| } |
| else |
| { |
| if (receivedSize) |
| { |
| isSuccess = false; |
| printf("got data while expected packet to be blocked, failing\n"); |
| } |
| } |
| |
| status = (struct ipa3_hw_pkt_status_hw_v5_5 *)rxBuff1; |
| if (!status->nat_exc_suppress) |
| { |
| printf("NAT Suppression not hit!\n"); |
| isSuccess = false; |
| } |
| |
| char recievedBuffer[256] = {0}; |
| char SentBuffer[256] = {0}; |
| size_t j; |
| |
| for (j = 0; j < m_sendSize; j++) |
| { |
| snprintf(&SentBuffer[3 * j], sizeof(SentBuffer)-(3 * j + 1), " %02X", m_sendBuffer[j]); |
| } |
| |
| for (j = 0; j < receivedSize; j++) |
| { |
| snprintf(&recievedBuffer[3 * j], sizeof(recievedBuffer)-(3 * j + 1), " %02X", rxBuff1[j]); |
| } |
| printf("Expected Value1 (%zu)\n%s\n, Received Value1(%zu)\n%s\n", |
| m_sendSize, SentBuffer, receivedSize, recievedBuffer); |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return isSuccess; |
| } |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = ReceivePacketsAndCompare(true); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| /*---------------------------------------------------------------------------------------------*/ |
| /* Test022: IPv6CT send inbound packet for NAT suppression test with status enabled */ |
| /*---------------------------------------------------------------------------------------------*/ |
| class IpaIPV6CTBlockTest022 : public IpaIPv6CTBlockTestFixture |
| { |
| public: |
| |
| IpaIPV6CTBlockTest022() |
| { |
| m_name = "IpaIPV6CTBlockTest022"; |
| m_description = |
| "IPv6CT block test 022 - IPv6CT passes successfully one packet in inbound direction on NAT suppression\n" |
| "1. Generate and commit three routing tables.\n" |
| " Each table contains a single \"bypass\" rule (all data goes to output pipe 0, 1 and 2 (accordingly))\n" |
| "2. Generate and commit one inbound filtering rule: Destination IP Exactly Match.\n" |
| "3. Add IPv6CT rule for the packet\n" |
| "4. Send packet which doesn't match CT and expect NAT suppression to kick in.\n" |
| "5. Compare status and check if NAT suppression kicked in.\n"; |
| Register(*this); |
| } |
| |
| virtual bool Setup() |
| { |
| /* we want statuses on this test */ |
| return IpaIPv6CTBlockTestFixture::Setup(true, true); |
| } |
| |
| virtual bool AddRoutingFilteringRules(enum ipa_flt_action flt_action, uint64_t dst_addr_msb, uint64_t dst_addr_lsb) |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| const char bypass0[20] = "Bypass0"; |
| const char bypass1[20] = "Bypass1"; |
| const char bypass2[20] = "Bypass2"; |
| |
| if (!CreateThreeIPv6BypassRoutingTables(bypass0, bypass1, bypass2)) |
| { |
| printf("CreateThreeBypassRoutingTables Failed\n"); |
| return false; |
| } |
| printf("CreateThreeBypassRoutingTables completed successfully\n"); |
| |
| ipa_ioc_get_rt_tbl routing_table0; |
| routing_table0.ip = IPA_IP_v6; |
| strlcpy(routing_table0.name, bypass0, sizeof(routing_table0.name)); |
| if (!m_routing.GetRoutingTable(&routing_table0)) |
| { |
| printf("m_routing.GetRoutingTable(&routing_table0=0x%pK) Failed.\n", &routing_table0); |
| return false; |
| } |
| |
| /* Setup conntrack exception routing table. */ |
| if (!m_routing.SetNatConntrackExcRoutingTable(routing_table0.hdl, false)) |
| { |
| LOG_MSG_ERROR("m_routing.SetNatConntrackExcRoutingTable(routing_table0 hdl=%d) Failed.\n", |
| routing_table0.hdl); |
| return false; |
| } |
| |
| ipa_ioc_get_rt_tbl routing_table1; |
| routing_table1.ip = IPA_IP_v6; |
| strlcpy(routing_table1.name, bypass1, sizeof(routing_table1.name)); |
| if (!m_routing.GetRoutingTable(&routing_table1)) |
| { |
| printf("m_routing.GetRoutingTable(&routing_table1=0x%pK) Failed.\n", &routing_table1); |
| return false; |
| } |
| |
| IPAFilteringTable FilterTable0; |
| ipa_flt_rule_add flt_rule_entry; |
| FilterTable0.Init(IPA_IP_v6, IPA_CLIENT_TEST_PROD, false, 1); |
| |
| // Configuring Filtering Rule No.0 |
| FilterTable0.GeneratePresetRule(1, flt_rule_entry); |
| flt_rule_entry.at_rear = true; |
| flt_rule_entry.flt_rule_hdl = -1; // return Value |
| flt_rule_entry.status = -1; // return value |
| flt_rule_entry.rule.action = flt_action; |
| flt_rule_entry.rule.rt_tbl_hdl = routing_table0.hdl; //put here the handle corresponding to Routing Rule 1 |
| flt_rule_entry.rule.attrib.attrib_mask = IPA_FLT_DST_ADDR; |
| |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;// Exact Match |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[0] = GetHigh32(dst_addr_msb); // Filter DST_IP |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[1] = GetLow32(dst_addr_msb); |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[2] = GetHigh32(dst_addr_lsb); |
| flt_rule_entry.rule.attrib.u.v6.dst_addr[3] = GetLow32(dst_addr_lsb); |
| |
| printf("flt_rule_entry was set successfully, preparing for insertion....\n"); |
| |
| if (((uint8_t)-1 == FilterTable0.AddRuleToTable(flt_rule_entry)) || |
| !m_filtering.AddFilteringRule(FilterTable0.GetFilteringTable())) |
| { |
| printf("%s::Error Adding Rule to Filter Table, aborting...\n", __FUNCTION__); |
| return false; |
| } |
| else |
| { |
| printf("flt rule hdl0=0x%x, status=0x%x\n", |
| FilterTable0.ReadRuleFromTable(0)->flt_rule_hdl, FilterTable0.ReadRuleFromTable(0)->status); |
| } |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool AddRoutingFilteringRules() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = IpaIPv6CTBlockTestFixture::AddRoutingFilteringRules(IPA_PASS_TO_DST_NAT, |
| m_outbound_src_addr_msb, m_outbound_src_addr_lsb); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| }// AddRoutingFilteringRules() |
| |
| virtual bool ModifyPackets() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| IpaIPv6CTBlockTestFixture::ModifyPackets(m_outbound_src_addr_lsb, m_outbound_src_addr_msb, m_outbound_src_port, |
| m_outbound_dst_addr_lsb, m_outbound_dst_addr_msb, m_outbound_dst_port+1); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return true; |
| }// ModifyPackets() |
| |
| virtual bool ReceivePacketsAndCompare(bool packetPassExpected) |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| |
| // Receive results |
| struct ipa3_hw_pkt_status_hw_v5_5 *status = NULL; |
| Byte rxBuff1[0x400]; |
| size_t receivedSize = m_consumer.ReceiveData(rxBuff1, 0x400); |
| printf("Received %zu bytes on %s.\n", receivedSize, m_consumer.m_fromChannelName.c_str()); |
| |
| bool isSuccess = true; |
| if (packetPassExpected) |
| { |
| // Compare results |
| if (!CompareResultVsGolden_w_Status(m_sendBuffer, m_sendSize, rxBuff1, receivedSize)) |
| { |
| printf("Comparison of Buffer0 Failed!\n"); |
| isSuccess = false; |
| } |
| } |
| else |
| { |
| if (receivedSize) |
| { |
| isSuccess = false; |
| printf("got data while expected packet to be blocked, failing\n"); |
| } |
| } |
| |
| status = (struct ipa3_hw_pkt_status_hw_v5_5 *)rxBuff1; |
| if (!status->nat_exc_suppress) |
| { |
| printf("NAT Suppression not hit!\n"); |
| isSuccess = false; |
| } |
| |
| char recievedBuffer[256] = {0}; |
| char SentBuffer[256] = {0}; |
| size_t j; |
| |
| for (j = 0; j < m_sendSize; j++) |
| { |
| snprintf(&SentBuffer[3 * j], sizeof(SentBuffer)-(3 * j + 1), " %02X", m_sendBuffer[j]); |
| } |
| |
| for (j = 0; j < receivedSize; j++) |
| { |
| snprintf(&recievedBuffer[3 * j], sizeof(recievedBuffer)-(3 * j + 1), " %02X", rxBuff1[j]); |
| } |
| printf("Expected Value1 (%zu)\n%s\n, Received Value1(%zu)\n%s\n", |
| m_sendSize, SentBuffer, receivedSize, recievedBuffer); |
| |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return isSuccess; |
| } |
| |
| virtual bool ReceivePacketsAndCompare() |
| { |
| printf("Entering %s, %s()\n", __FUNCTION__, __FILE__); |
| bool result = ReceivePacketsAndCompare(true); |
| printf("Leaving %s, %s()\n", __FUNCTION__, __FILE__); |
| return result; |
| } |
| }; |
| |
| |
| // IPv6CT outbound packet test |
| static class IpaIPV6CTBlockTest001 IpaIPV6CTBlockTest001; |
| |
| // IPv6CT inbound packet test |
| static class IpaIPV6CTBlockTest002 IpaIPV6CTBlockTest002; |
| |
| // IPv6CT block outbound packet test |
| static class IpaIPV6CTBlockTest003 IpaIPV6CTBlockTest003; |
| |
| // IPv6CT block inbound packet test |
| static class IpaIPV6CTBlockTest004 IpaIPV6CTBlockTest004; |
| |
| // IPv6CT block outbound packet on inbound filtering rule test |
| static class IpaIPV6CTBlockTest005 IpaIPV6CTBlockTest005; |
| |
| // IPv6CT block inbound packet on outbound filtering rule test |
| static class IpaIPV6CTBlockTest006 IpaIPV6CTBlockTest006; |
| |
| // IPv6CT block outbound packet while disabled outbound direction |
| static class IpaIPV6CTBlockTest007 IpaIPV6CTBlockTest007; |
| |
| // IPv6CT block inbound packet with disabled inbound direction |
| static class IpaIPV6CTBlockTest008 IpaIPV6CTBlockTest008; |
| |
| // IPv6CT send outbound packet with rule in expansion table |
| static class IpaIPV6CTBlockTest009 IpaIPV6CTBlockTest009; |
| |
| // IPv6CT send inbound packet with rule in expansion table |
| static class IpaIPV6CTBlockTest010 IpaIPV6CTBlockTest010; |
| |
| // IPv6CT block outbound packet while the rule was deleted |
| static class IpaIPV6CTBlockTest011 IpaIPV6CTBlockTest011; |
| |
| // IPv6CT block inbound packet while the rule was deleted |
| static class IpaIPV6CTBlockTest012 IpaIPV6CTBlockTest012; |
| |
| // IPv6CT block outbound packet while the rule in expansion table was deleted |
| static class IpaIPV6CTBlockTest013 IpaIPV6CTBlockTest013; |
| |
| // IPv6CT block inbound packet while the rule in expansion table was deleted |
| static class IpaIPV6CTBlockTest014 IpaIPV6CTBlockTest014; |
| |
| // IPv6CT send outbound packet with rule in expansion table while the rule in list head was deleted |
| static class IpaIPV6CTBlockTest015 IpaIPV6CTBlockTest015; |
| |
| // IPv6CT send inbound packet with rule in expansion table while the rule in list head was deleted |
| static class IpaIPV6CTBlockTest016 IpaIPV6CTBlockTest016; |
| |
| // IPv6CT send outbound packet with rule in expansion table while the rule in the middle of the list was deleted |
| static class IpaIPV6CTBlockTest017 IpaIPV6CTBlockTest017; |
| |
| // IPv6CT send inbound packet with rule in expansion table while the rule in the middle of the list was deleted |
| static class IpaIPV6CTBlockTest018 IpaIPV6CTBlockTest018; |
| |
| // IPv6CT suppression test Outbound traffic |
| static class IpaIPV6CTBlockTest019 IpaIPV6CTBlockTest019; |
| |
| // IPv6CT suppression test Inbound traffic |
| static class IpaIPV6CTBlockTest020 IpaIPV6CTBlockTest020; |
| |
| // IPv6CT suppression test Outbound traffic with status |
| static class IpaIPV6CTBlockTest021 IpaIPV6CTBlockTest021; |
| |
| // IPv6CT suppression test Inbound traffic with status |
| static class IpaIPV6CTBlockTest022 IpaIPV6CTBlockTest022; |