diff options
-rw-r--r-- | VNFs/vACL/pipeline/pipeline_acl_be.c | 265 | ||||
-rw-r--r-- | VNFs/vCGNAPT/init.c | 2 | ||||
-rw-r--r-- | VNFs/vCGNAPT/pipeline/pipeline_cgnapt_be.c | 782 | ||||
-rw-r--r-- | VNFs/vCGNAPT/pipeline/pipeline_cgnapt_be.h | 1 | ||||
-rw-r--r-- | VNFs/vFW/init.c | 3 | ||||
-rw-r--r-- | VNFs/vFW/pipeline/pipeline_vfw_be.c | 251 | ||||
-rw-r--r-- | common/VIL/l2l3_stack/interface.c | 2 | ||||
-rw-r--r-- | common/VIL/l2l3_stack/interface.h | 2 | ||||
-rw-r--r-- | common/VIL/l2l3_stack/l3fwd_lpm4.c | 2 | ||||
-rw-r--r-- | common/VIL/l2l3_stack/lib_arp.c | 1008 | ||||
-rw-r--r-- | common/VIL/l2l3_stack/lib_arp.h | 68 | ||||
-rw-r--r-- | common/VIL/pipeline_arpicmp/pipeline_arpicmp.c | 44 | ||||
-rw-r--r-- | common/VIL/pipeline_arpicmp/pipeline_arpicmp_be.c | 2502 | ||||
-rw-r--r-- | common/VIL/pipeline_loadb/pipeline_loadb.c | 28 | ||||
-rw-r--r-- | common/VIL/pipeline_txrx/pipeline_txrx_be.c | 21 | ||||
-rw-r--r-- | common/vnf_common/vnf_common.c | 6 |
16 files changed, 1272 insertions, 3715 deletions
diff --git a/VNFs/vACL/pipeline/pipeline_acl_be.c b/VNFs/vACL/pipeline/pipeline_acl_be.c index 039d6d59..b9386e61 100644 --- a/VNFs/vACL/pipeline/pipeline_acl_be.c +++ b/VNFs/vACL/pipeline/pipeline_acl_be.c @@ -144,6 +144,7 @@ static void *pipeline_acl_msg_req_dbg_handler(struct pipeline *p, void *msg); static pipeline_msg_req_handler custom_handlers[] = { [PIPELINE_ACL_MSG_REQ_DBG] = pipeline_acl_msg_req_dbg_handler, }; +uint64_t arp_pkts_mask; uint8_t ACL_DEBUG; uint32_t local_get_nh_ipv4(uint32_t ip, @@ -154,8 +155,8 @@ uint32_t local_get_nh_ipv4(uint32_t ip, for (i = 0; i < p_acl->local_lib_arp_route_ent_cnt; i++) { if (((p_acl->local_lib_arp_route_table[i].ip & - p_acl->local_lib_arp_route_table[i].mask) == - (ip & p_acl->local_lib_arp_route_table[i].mask))) { + p_acl->local_lib_arp_route_table[i].mask) == + (ip & p_acl->local_lib_arp_route_table[i].mask))) { *port = p_acl->local_lib_arp_route_table[i].port; *nhip = p_acl->local_lib_arp_route_table[i].nh; @@ -175,8 +176,8 @@ static void do_local_nh_ipv4_cache(uint32_t dest_if, struct pipeline_acl *p_acl) if (lib_arp_route_table[i].port == dest_if) { struct lib_arp_route_table_entry *lentry = - &p_acl->local_lib_arp_route_table - [p_acl->local_lib_arp_route_ent_cnt]; + &p_acl->local_lib_arp_route_table + [p_acl->local_lib_arp_route_ent_cnt]; lentry->ip = lib_arp_route_table[i].ip; lentry->mask = lib_arp_route_table[i].mask; @@ -463,6 +464,7 @@ pkt_work_acl_key(struct rte_pipeline *p, uint64_t conntrack_mask = 0; uint64_t connexist_mask = 0; uint32_t dest_address = 0; + arp_pkts_mask = 0; int dest_if = 0; int status; uint64_t pkts_drop_mask, pkts_mask = RTE_LEN2MASK(n_pkts, uint64_t); @@ -918,103 +920,57 @@ pkt_work_acl_key(struct rte_pipeline *p, nhip)); uint32_t packet_length = rte_pktmbuf_pkt_len(pkt); *nhip = 0; - if (is_phy_port_privte(phy_port)) { - dest_address = rte_bswap32(*dst_addr); - ret = - local_get_nh_ipv4(dest_address, &dest_if, - nhip, p_acl); - if (!ret) { - dest_if = - get_prv_to_pub_port(&dest_address, - IP_VERSION_4); - do_local_nh_ipv4_cache(dest_if, p_acl); + struct arp_entry_data *ret_arp_data = NULL; + ret_arp_data = get_dest_mac_addr_port + (dest_address, &dest_if, (struct ether_addr *) eth_dest); + *port_out_id = p_acl->port_out_id[dest_if]; + if (arp_cache_dest_mac_present(dest_if)) { + ether_addr_copy(get_link_hw_addr(dest_if), (struct ether_addr *)eth_src); + arp_data_ptr[dest_if]->n_last_update = time(NULL); + + if (unlikely(ret_arp_data && ret_arp_data->num_pkts)) { + printf("sending buffered packets\n"); + arp_send_buffered_pkts(ret_arp_data, + (struct ether_addr *)eth_dest, *port_out_id); + } - *port_out_id = p_acl->port_out_id[dest_if]; } else { - dest_address = rte_bswap32(*dst_addr); - - ret = local_get_nh_ipv4(dest_address, &dest_if, - nhip, p_acl); - if (!ret) { - dest_if = - get_pub_to_prv_port(&dest_address, - IP_VERSION_4); - do_local_nh_ipv4_cache(dest_if, p_acl); - }; - *port_out_id = p_acl->port_out_id[dest_if]; - } - /* port = ACL_PRV_PORT_ID; */ + if (unlikely(ret_arp_data == NULL)) { - int ret_mac = 0; + printf("%s: NHIP Not Found, " + "outport_id: %d\n", __func__, + *port_out_id); - ret_mac = get_dest_mac_addr_port - (dest_address, &dest_if, &hw_addr); - if (ret_mac == ARP_FOUND) { - if (ACL_DEBUG) { - printf("MAC found for ip 0x%x, " - "port %d - %02x:%02x:%02x:%02x:%02x:%02x\n", - dest_address, phy_port, - hw_addr.addr_bytes[0], - hw_addr.addr_bytes[1], - hw_addr.addr_bytes[2], - hw_addr.addr_bytes[3], - hw_addr.addr_bytes[4], - hw_addr.addr_bytes[5]); - printf("Dest MAC before - " - "%02x:%02x:%02x:%02x:%02x:%02x\n", - eth_dest[0], eth_dest[1], - eth_dest[2], eth_dest[3], - eth_dest[4], eth_dest[5]); + /* Drop the pkt */ + pkts_mask &= ~(1LLU << pos); + if (ACL_DEBUG) + printf("ACL after drop pkt_mask " + "%lu, pkt_num %d\n", + pkts_mask, pos); + p_acl->counters->pkts_drop++; + continue; } - memcpy(eth_dest, &hw_addr, - sizeof(struct ether_addr)); - if (ACL_DEBUG) { - printf("PktP %p, dest_macP %p\n", pkt, - eth_dest); - printf("Dest MAC after - " - "%02x:%02x:%02x:%02x:%02x:%02x\n", - eth_dest[0], eth_dest[1], - eth_dest[2], eth_dest[3], - eth_dest[4], eth_dest[5]); + if (ret_arp_data->status == INCOMPLETE || + ret_arp_data->status == PROBE) { + if (ret_arp_data->num_pkts >= NUM_DESC) { + /* Drop the pkt */ + pkts_mask &= ~(1LLU << pos); + if (ACL_DEBUG) + printf("ACL after drop pkt_mask " + "%lu, pkt_num %d\n", + pkts_mask, pos); + p_acl->counters->pkts_drop++; + continue; + } else { + arp_pkts_mask |= pkt_mask; + arp_queue_unresolved_packet(ret_arp_data, pkt); + continue; + } } - if (is_phy_port_privte(phy_port)) - memcpy(eth_src, - get_link_hw_addr(dest_if), - sizeof(struct ether_addr)); - else - memcpy(eth_src, - get_link_hw_addr(dest_if), - sizeof(struct ether_addr)); - p_acl->counters->tpkts_processed++; - p_acl->counters->bytes_processed += - packet_length; } - else { - if (*nhip != 0) { - if (ACL_DEBUG) - printf("ACL requesting ARP for " - "ip %x, port %d\n", - dest_address, phy_port); - if (ret_mac == ARP_NOT_FOUND) - request_arp(dest_if, *nhip); - - /* request_arp(p_acl->links_map[phy_port], *nhip); */ - } - /* Drop packet by changing the mask */ - if (ACL_DEBUG) - printf("ACL before drop pkt_mask " - "%lu, pkt_num %d\n", - pkts_mask, pos); - pkts_mask &= ~(1LLU << pos); - if (ACL_DEBUG) - printf("ACL after drop pkt_mask " - "%lu, pkt_num %d\n", - pkts_mask, pos); - p_acl->counters->pkts_drop++; - } - } + } /* end of if (hdr_chk == IPv4_HDR_VERSION) */ if (hdr_chk == IPv6_HDR_VERSION) { @@ -1053,7 +1009,7 @@ pkt_work_acl_key(struct rte_pipeline *p, uint8_t nhip[16]; nhip[0] = - RTE_MBUF_METADATA_UINT8(pkt, + RTE_MBUF_METADATA_UINT8(pkt, META_DATA_OFFSET + offsetof(struct mbuf_acl_meta_data, @@ -1176,6 +1132,11 @@ pkt_work_acl_key(struct rte_pipeline *p, rte_pipeline_ah_packet_drop(p, pkts_drop_mask); keep_mask = pkts_mask; + if (arp_pkts_mask) { + keep_mask &= ~(arp_pkts_mask); + rte_pipeline_ah_packet_hijack(p, arp_pkts_mask); + } + /* don't bother measuring if traffic very low, might skew stats */ uint32_t packets_this_iteration = __builtin_popcountll(pkts_mask); @@ -1238,6 +1199,7 @@ pkt_work_acl_ipv4_key(struct rte_pipeline *p, uint64_t conntrack_mask = 0; uint64_t connexist_mask = 0; uint32_t dest_address = 0; + arp_pkts_mask = 0; int dest_if = 0; int status; uint64_t pkts_drop_mask, pkts_mask = RTE_LEN2MASK(n_pkts, uint64_t); @@ -1711,76 +1673,56 @@ pkt_work_acl_ipv4_key(struct rte_pipeline *p, *port_out_id = p_acl->port_out_id[dest_if]; } /* port = ACL_PRV_PORT_ID; */ - int ret_mac = 0; - ret_mac = get_dest_mac_addr_port - (dest_address, &dest_if, &hw_addr); + struct arp_entry_data *ret_arp_data = NULL; + ret_arp_data = get_dest_mac_addr_port + (dest_address, &dest_if, (struct ether_addr *)eth_dest); + *port_out_id = p_acl->port_out_id[dest_if]; - if (ret_mac == ARP_FOUND) { - if (ACL_DEBUG) { - printf("MAC found for ip 0x%x, port " - "%d - %02x:%02x:%02x:%02x:%02x:%02x\n", - dest_address, phy_port, - hw_addr.addr_bytes[0], - hw_addr.addr_bytes[1], - hw_addr.addr_bytes[2], - hw_addr.addr_bytes[3], - hw_addr.addr_bytes[4], - hw_addr.addr_bytes[5]); - printf("Dest MAC before - " - "%02x:%02x:%02x:%02x:%02x:%02x\n", - eth_dest[0], eth_dest[1], - eth_dest[2], eth_dest[3], - eth_dest[4], eth_dest[5]); - } + if (arp_cache_dest_mac_present(dest_if)) { + ether_addr_copy(get_link_hw_addr(dest_if), (struct ether_addr *)eth_src); + arp_data_ptr[dest_if]->n_last_update = time(NULL); + + if (unlikely(ret_arp_data && ret_arp_data->num_pkts)) { + printf("sending buffered packets\n"); + arp_send_buffered_pkts(ret_arp_data, + (struct ether_addr *)eth_dest, *port_out_id); - memcpy(eth_dest, &hw_addr, - sizeof(struct ether_addr)); - if (ACL_DEBUG) { - printf("PktP %p, dest_macP %p\n", pkt, - eth_dest); - printf("Dest MAC after - " - "%02x:%02x:%02x:%02x:%02x:%02x\n", - eth_dest[0], eth_dest[1], - eth_dest[2], eth_dest[3], - eth_dest[4], eth_dest[5]); } - if (is_phy_port_privte(phy_port)) - memcpy(eth_src, - get_link_hw_addr(dest_if), - sizeof(struct ether_addr)); - else - memcpy(eth_src, - get_link_hw_addr(dest_if), - sizeof(struct ether_addr)); - p_acl->counters->tpkts_processed++; - p_acl->counters->bytes_processed += - packet_length; - } + } else { + if (unlikely(ret_arp_data == NULL)) { - else { - if (*nhip != 0) { - if (ACL_DEBUG) - printf("ACL requesting ARP for " - "ip %x, port %d\n", - dest_address, phy_port); - if (ret_mac == ARP_NOT_FOUND) - request_arp(dest_if, *nhip); + printf("%s: NHIP Not Found, " + "outport_id: %d\n", __func__, + *port_out_id); - /* request_arp(p_acl->links_map[phy_port], *nhip); */ + /* Drop the pkt */ + pkts_mask &= ~(1LLU << pos); + if (ACL_DEBUG) + printf("ACL after drop pkt_mask " + "%lu, pkt_num %d\n", + pkts_mask, pos); + p_acl->counters->pkts_drop++; + continue; } - /* Drop packet by changing the mask */ - if (ACL_DEBUG) - printf - ("ACL before drop pkt_mask " - "%lu, pkt_num %d\n", - pkts_mask, pos); - pkts_mask &= ~(1LLU << pos); - if (ACL_DEBUG) - printf("ACL after drop pkt_mask " + + if (ret_arp_data->status == INCOMPLETE || + ret_arp_data->status == PROBE) { + if (ret_arp_data->num_pkts >= NUM_DESC) { + /* Drop the pkt */ + pkts_mask &= ~(1LLU << pos); + if (ACL_DEBUG) + printf("ACL after drop pkt_mask " "%lu, pkt_num %d\n", - pkts_mask, pos); - p_acl->counters->pkts_drop++; + pkts_mask, pos); + p_acl->counters->pkts_drop++; + continue; + } else { + arp_pkts_mask |= pkt_mask; + arp_queue_unresolved_packet(ret_arp_data, pkt); + continue; + } + } } } #if 0 @@ -1923,6 +1865,11 @@ pkt_work_acl_ipv4_key(struct rte_pipeline *p, rte_pipeline_ah_packet_drop(p, pkts_drop_mask); keep_mask = pkts_mask; + if (arp_pkts_mask) { + keep_mask &= ~(arp_pkts_mask); + rte_pipeline_ah_packet_hijack(p, arp_pkts_mask); + } + /* don't bother measuring if traffic very low, might skew stats */ uint32_t packets_this_iteration = __builtin_popcountll(pkts_mask); @@ -1934,7 +1881,7 @@ pkt_work_acl_ipv4_key(struct rte_pipeline *p, } if (ACL_DEBUG) printf("Leaving pkt_work_acl_key pkts_mask = %p\n", - (void *)pkts_mask); + (void *)pkts_mask); return 0; } @@ -1983,6 +1930,7 @@ pkt_work_acl_ipv6_key(struct rte_pipeline *p, uint64_t conntrack_mask = 0; uint64_t connexist_mask = 0; uint32_t dest_address = 0; + arp_pkts_mask = 0; int dest_if = 0; int status; uint64_t pkts_drop_mask, pkts_mask = RTE_LEN2MASK(n_pkts, uint64_t); @@ -2691,6 +2639,11 @@ pkt_work_acl_ipv6_key(struct rte_pipeline *p, rte_pipeline_ah_packet_drop(p, pkts_drop_mask); keep_mask = pkts_mask; + if (arp_pkts_mask) { + keep_mask &= ~(arp_pkts_mask); + rte_pipeline_ah_packet_hijack(p, arp_pkts_mask); + } + /* don't bother measuring if traffic very low, might skew stats */ uint32_t packets_this_iteration = __builtin_popcountll(pkts_mask); diff --git a/VNFs/vCGNAPT/init.c b/VNFs/vCGNAPT/init.c index aa3868d8..3e731839 100644 --- a/VNFs/vCGNAPT/init.c +++ b/VNFs/vCGNAPT/init.c @@ -1729,11 +1729,13 @@ int app_init(struct app_params *app) app_init_pipelines(app); app_init_threads(app); + #ifdef L3_STACK_SUPPORT l3fwd_init(); create_arp_table(); create_nd_table(); populate_lpm_routes(); print_interface_details(); + #endif return 0; } diff --git a/VNFs/vCGNAPT/pipeline/pipeline_cgnapt_be.c b/VNFs/vCGNAPT/pipeline/pipeline_cgnapt_be.c index 2da8b5e4..2fbc71d8 100644 --- a/VNFs/vCGNAPT/pipeline/pipeline_cgnapt_be.c +++ b/VNFs/vCGNAPT/pipeline/pipeline_cgnapt_be.c @@ -80,7 +80,10 @@ /* To maintain all cgnapt pipeline pointers used for all stats */ struct pipeline_cgnapt *all_pipeline_cgnapt[128]; uint8_t n_cgnapt_pipeline; +struct pipeline_cgnapt *global_pnat; +uint64_t arp_pkts_mask; +extern struct arp_entry_data *arp_data_ptr[16]; /* To know egress or ingress port */ static uint8_t cgnapt_in_port_egress_prv[PIPELINE_MAX_PORT_IN]; static uint8_t cgnapt_prv_que_port_index[PIPELINE_MAX_PORT_IN]; @@ -140,6 +143,7 @@ struct rte_hash_parameters napt_common_table_hash_params = { }; /***** ARP local cache *****/ + uint8_t link_hw_laddr_valid[MAX_NUM_LOCAL_MAC_ADDRESS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 @@ -178,7 +182,6 @@ static uint32_t local_get_nh_ipv4( uint32_t *port, uint32_t *nhip, struct pipeline_cgnapt *p_nat); - static void do_local_nh_ipv4_cache( uint32_t dest_if, struct pipeline_cgnapt *p_nat); @@ -220,6 +223,11 @@ uint64_t nextPowerOf2(uint64_t n) return n; } +void remove_local_cache(uint8_t port) +{ + link_hw_laddr_valid[port] = 0; +} + /** * Function to get MAC addr of local link * @@ -230,10 +238,10 @@ uint64_t nextPowerOf2(uint64_t n) * Outport Link MAC addr */ -struct ether_addr *get_local_link_hw_addr(uint8_t out_port) -{ - return &link_hw_laddr[out_port]; -} +//struct ether_addr *get_local_link_hw_addr(uint8_t out_port) +//{ +// return &link_hw_laddr[out_port]; +//} /** * Function to get MAC addr from array instead of hash table @@ -910,6 +918,33 @@ void sw_checksum(struct rte_mbuf *pkt, enum PKT_TYPE ver) } } +void print_pkt_info(uint8_t *eth_dest, struct ether_addr *hw_addr, + uint32_t dest_address, uint32_t port_id, struct rte_mbuf *pkt) +{ + +if (CGNAPT_DEBUG > 2) { + printf("MAC Found ip 0x%x, port %d - %02x:%02x:%02x:%02x:%02x:%02x \n", + dest_address, port_id, hw_addr->addr_bytes[0], hw_addr->addr_bytes[1], + hw_addr->addr_bytes[2], hw_addr->addr_bytes[3], hw_addr->addr_bytes[4], + hw_addr->addr_bytes[5]); + + printf("Dest MAC before - %02x:%02x:%02x:%02x:%02x:%02x \n", + eth_dest[0], eth_dest[1], eth_dest[2], eth_dest[3], eth_dest[4], + eth_dest[5]); +} + +if (CGNAPT_DEBUG > 2) { + printf("Dest MAC after - " + "%02x:%02x:%02x:%02x:%02x:%02x \n", + eth_dest[0], eth_dest[1], + eth_dest[2], eth_dest[3], + eth_dest[4], eth_dest[5]); +} + +if (CGNAPT_DEBUG > 4) + print_pkt(pkt); +} + static uint8_t check_arp_icmp( struct rte_mbuf *pkt, uint64_t pkt_mask, @@ -925,7 +960,7 @@ static uint8_t check_arp_icmp( /* ARP outport number */ uint16_t out_port = p_nat->p.n_ports_out - 1; - + printf("check_arp_icmp called*****\n"); uint8_t *protocol; uint32_t prot_offset; @@ -2169,11 +2204,34 @@ static int cgnapt_in_port_ah_mix(struct rte_pipeline *rte_p, } *outport_id = p_nat->outport_id[dest_if]; - int ret; - ret = get_dest_mac_addr_port(dest_address, - &dest_if, &hw_addr); + struct arp_entry_data *ret_arp_data; + ret_arp_data = get_dest_mac_addr_port(dest_address, + &dest_if, (struct ether_addr *)&hw_addr); + + if (unlikely(ret_arp_data == NULL)) { + + printf("%s: NHIP Not Found, nhip: %x, " + "outport_id: %d\n", __func__, nhip, + *outport_id); + + /* Drop the pkt */ + p_nat->invalid_packets |= pkt_mask; + p_nat->naptDroppedPktCount++; + + #ifdef CGNAPT_DEBUGGING + p_nat->naptDroppedPktCount4++; + #endif + continue; + } + + if (ret_arp_data->status == COMPLETE) { + + if (ret_arp_data->num_pkts) { + p_nat->naptedPktCount += ret_arp_data->num_pkts; + arp_send_buffered_pkts(ret_arp_data, + &hw_addr, *outport_id); + } - if (ret == ARP_FOUND) { memcpy(eth_dest, &hw_addr, sizeof(struct ether_addr)); memcpy(eth_src, get_link_hw_addr(dest_if), @@ -2208,23 +2266,22 @@ static int cgnapt_in_port_ah_mix(struct rte_pipeline *rte_p, print_pkt(pkts[pkt_index]); #endif - } else{ - if (ret == ARP_NOT_FOUND) { - /* Commented code may be required - * for future use, Please keep it */ - //request_arp(*outport_id, nhip, - // p_nat->p.p); - printf("%s: ARP Not Found, nhip: %x, " - "outport_id: %d\n", __func__, nhip, - *outport_id); - } + } else if (ret_arp_data->status == INCOMPLETE || + ret_arp_data->status == PROBE) { + if (ret_arp_data->num_pkts >= NUM_DESC) { + /* Drop the pkt */ + p_nat->invalid_packets |= pkt_mask; + p_nat->naptDroppedPktCount++; - p_nat->invalid_packets |= pkt_mask; - p_nat->naptDroppedPktCount++; - #ifdef CGNAPT_DEBUGGING - p_nat->naptDroppedPktCount4++; - #endif - continue; + #ifdef CGNAPT_DEBUGGING + p_nat->naptDroppedPktCount4++; + #endif + continue; + } else { + arp_queue_unresolved_packet(ret_arp_data, + pkts[pkt_index]); + continue; + } } #ifdef CGNAPT_DBG_PRNT @@ -2396,61 +2453,76 @@ static int cgnapt_in_port_ah_mix(struct rte_pipeline *rte_p, }; *outport_id = p_nat->outport_id[dest_if]; - int ret; - ret = get_dest_mac_addr_port(dest_address, - &dest_if, &hw_addr); + struct arp_entry_data *ret_arp_data; + ret_arp_data = get_dest_mac_addr_port(dest_address, + &dest_if, (struct ether_addr *)&hw_addr); + + if (unlikely(ret_arp_data == NULL)) { + + printf("%s: NHIP Not Found, nhip: %x, " + "outport_id: %d\n", __func__, nhip, + *outport_id); + + /* Drop the pkt */ + p_nat->invalid_packets |= pkt_mask; + p_nat->naptDroppedPktCount++; + + #ifdef CGNAPT_DEBUGGING + p_nat->naptDroppedPktCount4++; + #endif + continue; + } + + if (ret_arp_data->status == COMPLETE) { + + if (ret_arp_data->num_pkts) { + p_nat->naptedPktCount += + ret_arp_data->num_pkts; + arp_send_buffered_pkts(ret_arp_data, + &hw_addr, *outport_id); + } - if (ret == ARP_FOUND) { memcpy(eth_dest, &hw_addr, sizeof(struct ether_addr)); memcpy(eth_src, get_link_hw_addr( dest_if), sizeof(struct ether_addr)); - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 2) { - printf("MAC found for ip 0x%x, port %d - " - "%02x:%02x:%02x:%02x:%02x:%02x\n", - dest_address, *outport_id, - hw_addr.addr_bytes[0], hw_addr.addr_bytes[1], - hw_addr.addr_bytes[2], hw_addr.addr_bytes[3], - hw_addr.addr_bytes[4], hw_addr.addr_bytes[5]); + #ifdef CGNAPT_DBG_PRNT + if (CGNAPT_DEBUG > 2) { + printf("MAC found for ip 0x%x, port %d - " + "%02x:%02x:%02x:%02x:%02x:%02x\n", + dest_address, *outport_id, + hw_addr.addr_bytes[0], hw_addr.addr_bytes[1], + hw_addr.addr_bytes[2], hw_addr.addr_bytes[3], + hw_addr.addr_bytes[4], hw_addr.addr_bytes[5]); - printf("Dest MAC before - " - "%02x:%02x:%02x:%02x:%02x:%02x\n", + printf("Dest MAC before - " + "%02x:%02x:%02x:%02x:%02x:%02x\n", eth_dest[0], eth_dest[1], eth_dest[2], eth_dest[3], eth_dest[4], eth_dest[5]); - } - #endif + } + #endif - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 2) { - printf("Dest MAC after - " - "%02x:%02x:%02x:%02x:%02x:%02x\n", + #ifdef CGNAPT_DBG_PRNT + if (CGNAPT_DEBUG > 2) { + printf("Dest MAC after - " + "%02x:%02x:%02x:%02x:%02x:%02x\n", eth_dest[0], eth_dest[1], eth_dest[2], eth_dest[3], eth_dest[4], eth_dest[5]); - } - #endif + } + #endif - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 4) - print_pkt(pkts[pkt_index]); - #endif + #ifdef CGNAPT_DBG_PRNT + if (CGNAPT_DEBUG > 4) + print_pkt(pkts[pkt_index]); + #endif - } else { - if (ret == ARP_NOT_FOUND) { - printf("%s: ARP Not Found, nhip: %x, " - "outport_id: %d\n", __func__, nhip, - *outport_id); - } - //request_arp(*outport_id, - // nhip, p_nat->p.p); - p_nat->invalid_packets |= pkt_mask; - p_nat->naptDroppedPktCount++; - #ifdef CGNAPT_DEBUGGING - p_nat->naptDroppedPktCount4++; - #endif - continue; - } + } else if (ret_arp_data->status == INCOMPLETE || + ret_arp_data->status == PROBE) { + arp_queue_unresolved_packet(ret_arp_data, + pkts[pkt_index]); + continue; + } if (*protocol == IP_PROTOCOL_ICMP) { // Query ID reverse translation done here @@ -2547,7 +2619,7 @@ static int cgnapt_in_port_ah_ipv4_prv(struct rte_pipeline *rte_p, p_nat->pkt_burst_cnt = 0; /* for dynamic napt */ p_nat->valid_packets = rte_p->pkts_mask; /*n_pkts; */ p_nat->invalid_packets = 0; - + arp_pkts_mask = 0; #ifdef CGNAPT_DBG_PRNT if (CGNAPT_DEBUG > 1) printf("cgnapt_key hit fn: %" PRIu32 "\n", n_pkts); @@ -2567,6 +2639,7 @@ static int cgnapt_in_port_ah_ipv4_prv(struct rte_pipeline *rte_p, if (unlikely(p_nat->valid_packets == 0)) { /* no suitable packet for lookup */ + printf("no suitable valid packets\n"); rte_pipeline_ah_packet_drop(rte_p, p_nat->invalid_packets); return p_nat->valid_packets; } @@ -2600,12 +2673,20 @@ static int cgnapt_in_port_ah_ipv4_prv(struct rte_pipeline *rte_p, [p_nat->lkup_indx[j]]); } + //prefetch(); + + for (i = 0; i < (n_pkts & (~0x3LLU)); i += 4) pkt4_work_cgnapt_ipv4_prv(pkts, i, arg, p_nat); for (; i < n_pkts; i++) pkt_work_cgnapt_ipv4_prv(pkts, i, arg, p_nat); + if (arp_pkts_mask) { + p_nat->valid_packets &= ~(arp_pkts_mask); + rte_pipeline_ah_packet_hijack(rte_p, arp_pkts_mask); + } + if (p_nat->invalid_packets) { /* get rid of invalid packets */ rte_pipeline_ah_packet_drop(rte_p, p_nat->invalid_packets); @@ -2682,7 +2763,7 @@ static int cgnapt_in_port_ah_ipv4_pub(struct rte_pipeline *rte_p, p_nat->pkt_burst_cnt = 0; /* for dynamic napt */ p_nat->valid_packets = rte_p->pkts_mask; /*n_pkts; */ p_nat->invalid_packets = 0; - + arp_pkts_mask = 0; #ifdef CGNAPT_DBG_PRNT if (CGNAPT_DEBUG > 1) printf("cgnapt_key hit fn: %" PRIu32 "\n", n_pkts); @@ -2701,6 +2782,7 @@ static int cgnapt_in_port_ah_ipv4_pub(struct rte_pipeline *rte_p, p_nat->valid_packets &= ~(p_nat->invalid_packets); if (unlikely(p_nat->valid_packets == 0)) { + printf("no valid packets in pub\n"); /* no suitable packet for lookup */ rte_pipeline_ah_packet_drop(rte_p, p_nat->invalid_packets); return p_nat->valid_packets; @@ -2741,6 +2823,11 @@ static int cgnapt_in_port_ah_ipv4_pub(struct rte_pipeline *rte_p, for (; i < n_pkts; i++) pkt_work_cgnapt_ipv4_pub(pkts, i, arg, p_nat); + if (arp_pkts_mask) { + rte_pipeline_ah_packet_hijack(rte_p, arp_pkts_mask); + p_nat->valid_packets &= ~(arp_pkts_mask); + } + if (p_nat->invalid_packets) { /* get rid of invalid packets */ rte_pipeline_ah_packet_drop(rte_p, p_nat->invalid_packets); @@ -3706,6 +3793,7 @@ pkt_work_cgnapt_key_ipv4_pub( * A pointer to main CGNAPT structure * */ +uint64_t last_update; void pkt_work_cgnapt_ipv4_prv( struct rte_mbuf **pkts, @@ -3849,54 +3937,31 @@ pkt_work_cgnapt_ipv4_prv( #endif return; } - + last_update = rte_rdtsc(); dest_address = rte_bswap32(*dst_addr); - /*Multiport Changes */ uint32_t nhip = 0; - uint32_t ret; - ret = local_get_nh_ipv4(dest_address, &dest_if, &nhip, p_nat); - if (!ret) { - dest_if = get_prv_to_pub_port(&dest_address, IP_VERSION_4); - - if (dest_if == INVALID_DESTIF) { - p_nat->invalid_packets |= pkt_mask; - p_nat->naptDroppedPktCount++; - #ifdef CGNAPT_DEBUGGING - p_nat->naptDroppedPktCount6++; - #endif - return; - } - - do_local_nh_ipv4_cache(dest_if, p_nat); - } - + struct arp_entry_data *ret_arp_data = NULL; + ret_arp_data = get_dest_mac_addr_port(dest_address, &dest_if, (struct ether_addr *)eth_dest); *outport_id = p_nat->outport_id[dest_if]; - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 2) - printf("Egress: \tphy_port:%d\t get_prv_to_pub():%d " - "\tout_port:%d\n", pkt->port, dest_if, - *outport_id); - #endif + if (arp_cache_dest_mac_present(dest_if)) { + ether_addr_copy(get_link_hw_addr(dest_if),(struct ether_addr *)eth_src); + arp_data_ptr[dest_if]->n_last_update = time(NULL); - if (local_dest_mac_present(dest_if)) { - memcpy(eth_dest, - get_local_link_hw_addr(dest_if), - sizeof(struct ether_addr)); - memcpy(eth_src, get_link_hw_addr(dest_if), - sizeof(struct ether_addr)); + if (unlikely(ret_arp_data && ret_arp_data->num_pkts)) { + printf("sending buffered packets\n"); + p_nat->naptedPktCount += ret_arp_data->num_pkts; + arp_send_buffered_pkts(ret_arp_data, + (struct ether_addr *)eth_dest, *outport_id); + + } } else { - int ret; - ret = get_dest_mac_addr_port(dest_address, &dest_if, &hw_addr); - if (unlikely(ret != ARP_FOUND)) { + if (unlikely(ret_arp_data == NULL)) { - if (unlikely(ret == ARP_NOT_FOUND)) { - //request_arp(*outport_id, nhip, p_nat->p.p); - printf("%s: ARP Not Found, nhip: %x, " - "outport_id: %d\n", __func__, nhip, - *outport_id); - } + printf("%s: NHIP Not Found, nhip:%x , " + "outport_id: %d\n", __func__, nhip, + *outport_id); /* Drop the pkt */ p_nat->invalid_packets |= pkt_mask; @@ -3906,41 +3971,26 @@ pkt_work_cgnapt_ipv4_prv( p_nat->naptDroppedPktCount4++; #endif return; - - } - - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 2) { - printf("MAC found for ip 0x%x, port %d - %02x:%02x: " - "%02x:%02x:%02x:%02x\n", dest_address, - *outport_id, - hw_addr.addr_bytes[0], hw_addr.addr_bytes[1], - hw_addr.addr_bytes[2], hw_addr.addr_bytes[3], - hw_addr.addr_bytes[4], hw_addr.addr_bytes[5]); - - printf("Dest MAC before - %02x:%02x:%02x: " - "%02x:%02x:%02x\n", eth_dest[0], eth_dest[1], - eth_dest[2], eth_dest[3], eth_dest[4], eth_dest[5]); } - #endif - - memcpy(eth_dest, &hw_addr, sizeof(struct ether_addr)); - - link_hw_laddr_valid[dest_if] = 1; - memcpy(&link_hw_laddr[dest_if], &hw_addr, - sizeof(struct ether_addr)); + if (ret_arp_data->status == INCOMPLETE || + ret_arp_data->status == PROBE) { + if (ret_arp_data->num_pkts >= NUM_DESC) { + /* Drop the pkt */ + p_nat->invalid_packets |= pkt_mask; + p_nat->naptDroppedPktCount++; - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 2) { - printf("Dest MAC after - %02x:%02x:%02x:%02x:%02x" - ":%02x\n", eth_dest[0], eth_dest[1], eth_dest[2], - eth_dest[3], eth_dest[4], eth_dest[5]); + #ifdef CGNAPT_DEBUGGING + p_nat->naptDroppedPktCount4++; + #endif + return; + } else { + arp_pkts_mask |= pkt_mask; + arp_queue_unresolved_packet(ret_arp_data, pkt); + return; + } } - #endif - memcpy(eth_src, get_link_hw_addr(dest_if), - sizeof(struct ether_addr)); } { @@ -4234,55 +4284,33 @@ pkt_work_cgnapt_ipv4_pub( #endif return; } + } dest_address = entry->data.u.prv_ip; + struct arp_entry_data *ret_arp_data = NULL; + ret_arp_data = get_dest_mac_addr_port(dest_address, &dest_if, (struct ether_addr *)eth_dest); + *outport_id = p_nat->outport_id[dest_if]; - ret = local_get_nh_ipv4(dest_address, &dest_if, &nhip, p_nat); - if (!ret) { - dest_if = get_prv_to_pub_port(&dest_address, IP_VERSION_4); + if (arp_cache_dest_mac_present(dest_if)) { + ether_addr_copy(get_link_hw_addr(dest_if), (struct ether_addr *)eth_src); + arp_data_ptr[dest_if]->n_last_update = time(NULL); - if (dest_if == INVALID_DESTIF) { - p_nat->invalid_packets |= pkt_mask; - p_nat->naptDroppedPktCount++; - #ifdef CGNAPT_DEBUGGING - p_nat->naptDroppedPktCount6++; - #endif - return; + if (ret_arp_data && ret_arp_data->num_pkts) { + printf("sending buffered packets\n"); + p_nat->naptedPktCount += ret_arp_data->num_pkts; + arp_send_buffered_pkts(ret_arp_data, + (struct ether_addr *)eth_dest, *outport_id); } - do_local_nh_ipv4_cache(dest_if, p_nat); - } - - *outport_id = p_nat->outport_id[dest_if]; - - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 2) - printf("Ingress: \tphy_port:%d\t get_pub_to_prv():%d " - "\tout_port%d\n", pkt->port, dest_if, *outport_id); - #endif - } - - if (local_dest_mac_present(dest_if)) { - memcpy(eth_dest, - get_local_link_hw_addr(dest_if), - sizeof(struct ether_addr)); - memcpy(eth_src, get_link_hw_addr(dest_if), - sizeof(struct ether_addr)); } else { - int ret; - ret = get_dest_mac_addr_port(dest_address, &dest_if, &hw_addr); - if (unlikely(ret != ARP_FOUND)) { - - if (unlikely(ret == ARP_NOT_FOUND)) { - /* Commented code may be required for debug - * and future use, Please keep it */ - //request_arp(*outport_id, nhip, p_nat->p.p); - printf("%s: ARP Not Found, nhip: %x, " - "outport_id: %d\n", __func__, nhip, - *outport_id); + if (unlikely(ret_arp_data == NULL)) { - } + /* Commented code may be required for debug + * and future use, Please keep it */ + printf("%s: NHIP Not Found, nhip: %x, " + "outport_id: %d\n", __func__, nhip, + *outport_id); /* Drop the pkt */ p_nat->invalid_packets |= pkt_mask; @@ -4294,42 +4322,24 @@ pkt_work_cgnapt_ipv4_pub( return; } - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 2) { - printf - ("MAC found for ip 0x%x, port %d - %02x:%02x: " - "%02x:%02x:%02x:%02x\n", dest_address, - *outport_id, - hw_addr.addr_bytes[0], hw_addr.addr_bytes[1], - hw_addr.addr_bytes[2], hw_addr.addr_bytes[3], - hw_addr.addr_bytes[4], hw_addr.addr_bytes[5] - ); - - printf - ("Dest MAC before - %02x:%02x:%02x:%02x " - ":%02x:%02x\n", eth_dest[0], eth_dest[1], - eth_dest[2], eth_dest[3], eth_dest[4], - eth_dest[5]); - } - #endif - memcpy(eth_dest, &hw_addr, sizeof(struct ether_addr)); - - link_hw_laddr_valid[dest_if] = 1; - memcpy(&link_hw_laddr[dest_if], &hw_addr, - sizeof(struct ether_addr)); + if (ret_arp_data->status == INCOMPLETE || + ret_arp_data->status == PROBE) { + if (ret_arp_data->num_pkts >= NUM_DESC) { + /* Drop the pkt */ + p_nat->invalid_packets |= pkt_mask; + p_nat->naptDroppedPktCount++; - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 2) { - printf("Dest MAC after - " - "%02x:%02x:%02x:%02x:%02x:%02x\n", - eth_dest[0], eth_dest[1], eth_dest[2], eth_dest[3], - eth_dest[4], eth_dest[5]); + #ifdef CGNAPT_DEBUGGING + p_nat->naptDroppedPktCount4++; + #endif + return; + } else { + arp_pkts_mask |= pkt_mask; + arp_queue_unresolved_packet(ret_arp_data, pkt); + return; + } } - #endif - - memcpy(eth_src, get_link_hw_addr(dest_if), - sizeof(struct ether_addr)); } { @@ -4466,7 +4476,7 @@ pkt_work_cgnapt_ipv4_pub( if (ct_position < 0){ p_nat->invalid_packets |= pkt_mask; - p_nat->naptDroppedPktCount++; + p_nat->naptDroppedPktCount++; return; } #ifdef ALGDBG @@ -4708,101 +4718,60 @@ pkt4_work_cgnapt_ipv4_prv( #endif continue; } - - dest_address = rte_bswap32(*dst_addr); - ret = local_get_nh_ipv4(dest_address, &dest_if, &nhip, p_nat); - if (!ret) { - dest_if = get_prv_to_pub_port(&dest_address, - IP_VERSION_4); - if (dest_if == INVALID_DESTIF) { - p_nat->invalid_packets |= pkt_mask; - p_nat->naptDroppedPktCount++; - #ifdef CGNAPT_DEBUGGING - p_nat->naptDroppedPktCount6++; - #endif - continue; - } - do_local_nh_ipv4_cache(dest_if, p_nat); } - *outport_id = p_nat->outport_id[dest_if]; - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 2) - printf("Egress: \tphy_port:%d\t " - "get_prv_to_pub():%d \tout_port:%d\n", - pkt->port, dest_if, *outport_id); - #endif - } + dest_address = rte_bswap32(*dst_addr); + struct arp_entry_data *ret_arp_data = NULL; + uint64_t start, end; + ret_arp_data = get_dest_mac_addr_port(dest_address, &dest_if, (struct ether_addr *)eth_dest); + *outport_id = p_nat->outport_id[dest_if]; + if (arp_cache_dest_mac_present(dest_if)) { + ether_addr_copy(get_link_hw_addr(dest_if), (struct ether_addr *)eth_src); + arp_data_ptr[dest_if]->n_last_update = time(NULL); + + if (ret_arp_data && ret_arp_data->num_pkts) { + printf("sending buffered packets\n"); + p_nat->naptedPktCount += ret_arp_data->num_pkts; + arp_send_buffered_pkts(ret_arp_data, + (struct ether_addr *)eth_dest, *outport_id); + } - if (local_dest_mac_present(dest_if)) { - memcpy(eth_dest, - get_local_link_hw_addr(dest_if), - sizeof(struct ether_addr)); - memcpy(eth_src, - get_link_hw_addr(dest_if), - sizeof(struct ether_addr)); } else { - int ret; - ret = get_dest_mac_addr_port(dest_address, &dest_if, &hw_addr); - if (unlikely(ret != ARP_FOUND)) { + if (unlikely(ret_arp_data == NULL)) { - if (unlikely(ret == ARP_NOT_FOUND)) { printf("%s: ARP Not Found, nhip: %x, " "outport_id: %d\n", __func__, nhip, *outport_id); - //request_arp(*outport_id, nhip, p_nat->p.p); - } - /* Drop the pkt */ - p_nat->invalid_packets |= pkt_mask; - p_nat->naptDroppedPktCount++; - - #ifdef CGNAPT_DEBUGGING - p_nat->naptDroppedPktCount4++; - #endif - continue; + /* Drop the pkt */ + p_nat->invalid_packets |= pkt_mask; + p_nat->naptDroppedPktCount++; - } - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 2) { - printf("MAC found for ip 0x%x, port %d - " - "%02x:%02x:%02x:%02x:%02x:%02x\n", - dest_address, - *outport_id, - hw_addr.addr_bytes[0], - hw_addr.addr_bytes[1], - hw_addr.addr_bytes[2], - hw_addr.addr_bytes[3], - hw_addr.addr_bytes[4], - hw_addr.addr_bytes[5] - ); + #ifdef CGNAPT_DEBUGGING + p_nat->naptDroppedPktCount4++; + #endif + continue; - printf("Dest MAC before - " - "%02x:%02x:%02x:%02x:%02x:%02x\n", - eth_dest[0], eth_dest[1], eth_dest[2], - eth_dest[3], eth_dest[4], eth_dest[5]); } - #endif - - memcpy(eth_dest, &hw_addr, sizeof(struct ether_addr)); - link_hw_laddr_valid[dest_if] = 1; - memcpy(&link_hw_laddr[dest_if], &hw_addr, - sizeof(struct ether_addr)); + if (ret_arp_data->status == INCOMPLETE || + ret_arp_data->status == PROBE) { + if (ret_arp_data->num_pkts >= NUM_DESC) { + /* Drop the pkt */ + p_nat->invalid_packets |= pkt_mask; + p_nat->naptDroppedPktCount++; - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 2) { - printf("Dest MAC after - " - "%02x:%02x:%02x:%02x:%02x:%02x\n", - eth_dest[0], eth_dest[1], eth_dest[2], - eth_dest[3], eth_dest[4], eth_dest[5]); + #ifdef CGNAPT_DEBUGGING + p_nat->naptDroppedPktCount4++; + #endif + continue; + } else { + arp_pkts_mask |= pkt_mask; + arp_queue_unresolved_packet(ret_arp_data, pkt); + continue; + } } - #endif - - memcpy(eth_src, - get_link_hw_addr(dest_if), - sizeof(struct ether_addr)); } { @@ -5050,7 +5019,7 @@ pkt4_work_cgnapt_ipv4_pub( #ifdef CGNAPT_DEBUGGING p_nat->naptDroppedPktCount3++; #endif - + printf("causing p_nat->naptDroppedPktCount3\n"); continue; } @@ -5114,54 +5083,30 @@ pkt4_work_cgnapt_ipv4_pub( #endif continue; } - - dest_address = entry->data.u.prv_ip; - ret = local_get_nh_ipv4(dest_address, &dest_if, &nhip, p_nat); - if (!ret) { - dest_if = get_prv_to_pub_port(&dest_address, IP_VERSION_4); - - if (dest_if == INVALID_DESTIF) { - p_nat->invalid_packets |= pkt_mask; - p_nat->naptDroppedPktCount++; - #ifdef CGNAPT_DEBUGGING - p_nat->naptDroppedPktCount6++; - #endif - continue; } + dest_address = entry->data.u.prv_ip; + struct arp_entry_data *ret_arp_data = NULL; + ret_arp_data = get_dest_mac_addr_port(dest_address, &dest_if, (struct ether_addr *)eth_dest); + *outport_id = p_nat->outport_id[dest_if]; - do_local_nh_ipv4_cache(dest_if, p_nat); - } - - *outport_id = p_nat->outport_id[dest_if]; - - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 2) - printf("Ingress: \tphy_port:%d\t " - "get_pub_to_prv():%d \tout_port%d\n", - pkt->port, dest_if, - *outport_id); - #endif + if (arp_cache_dest_mac_present(dest_if)) { + ether_addr_copy(get_link_hw_addr(dest_if), (struct ether_addr *)eth_src); + arp_data_ptr[dest_if]->n_last_update = time(NULL); + + if (ret_arp_data && ret_arp_data->num_pkts) { + printf("sending buffered packets\n"); + p_nat->naptedPktCount += ret_arp_data->num_pkts; + arp_send_buffered_pkts(ret_arp_data, + (struct ether_addr *)eth_dest, *outport_id); } - if (local_dest_mac_present(dest_if)) { - memcpy(eth_dest, - get_local_link_hw_addr(dest_if), - sizeof(struct ether_addr)); - memcpy(eth_src, - get_link_hw_addr(dest_if), - sizeof(struct ether_addr)); - } else { - int ret; - ret = get_dest_mac_addr_port(dest_address, &dest_if, &hw_addr); + } else { - if (unlikely(ret != ARP_FOUND)) { + if (unlikely(ret_arp_data == NULL)) { - if (unlikely(ret == ARP_NOT_FOUND)) { - printf("%s: ARP Not Found, nhip: %x, " - "outport_id: %d\n", __func__, nhip, - *outport_id); - //request_arp(*outport_id, nhip, p_nat->p.p); - } + printf("%s: NHIP Not Found, nhip: %x, " + "outport_id: %d\n", __func__, nhip, + *outport_id); /* Drop the pkt */ p_nat->invalid_packets |= pkt_mask; @@ -5171,47 +5116,26 @@ pkt4_work_cgnapt_ipv4_pub( p_nat->naptDroppedPktCount4++; #endif continue; - } - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 2) { - printf("MAC found for ip 0x%x, port %d - " - "%02x:%02x:%02x:%02x:%02x:%02x\n", - dest_address, *outport_id, - hw_addr.addr_bytes[0], - hw_addr.addr_bytes[1], - hw_addr.addr_bytes[2], - hw_addr.addr_bytes[3], - hw_addr.addr_bytes[4], - hw_addr.addr_bytes[5] - ); - - printf("Dest MAC before - " - "%02x:%02x:%02x:%02x:%02x:%02x\n", - eth_dest[0], eth_dest[1], eth_dest[2], - eth_dest[3], eth_dest[4], eth_dest[5]); - } - #endif - - memcpy(eth_dest, &hw_addr, sizeof(struct ether_addr)); - link_hw_laddr_valid[dest_if] = 1; - memcpy(&link_hw_laddr[dest_if], - &hw_addr, sizeof(struct ether_addr)); + if (ret_arp_data->status == INCOMPLETE || + ret_arp_data->status == PROBE) { + if (ret_arp_data->num_pkts >= NUM_DESC) { + /* Drop the pkt */ + p_nat->invalid_packets |= pkt_mask; + p_nat->naptDroppedPktCount++; - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 2) { - printf("Dest MAC after - %02x:%02x:%02x: " - "%02x:%02x:%02x\n", - eth_dest[0], eth_dest[1], eth_dest[2], - eth_dest[3], eth_dest[4], eth_dest[5]); + #ifdef CGNAPT_DEBUGGING + p_nat->naptDroppedPktCount4++; + #endif + continue; + } else { + arp_pkts_mask |= pkt_mask; + arp_queue_unresolved_packet(ret_arp_data, pkt); + continue; } - #endif - - memcpy(eth_src, - get_link_hw_addr(dest_if), - sizeof(struct ether_addr)); } + } { /* Ingress */ @@ -6159,7 +6083,6 @@ pkt_work_cgnapt_ipv6_prv( __rte_unused void *arg, struct pipeline_cgnapt *p_nat) { - /* index into hash table entries */ int hash_table_entry = p_nat->lkup_indx[pkt_num]; @@ -6351,23 +6274,17 @@ pkt_work_cgnapt_ipv6_prv( #endif if (local_dest_mac_present(dest_if)) { - memcpy(eth_dest, - get_local_link_hw_addr(dest_if), - sizeof(struct ether_addr)); memcpy(eth_src, get_link_hw_addr(dest_if), sizeof(struct ether_addr)); } else { - int ret; - ret = get_dest_mac_addr_port(dest_address, &dest_if, &hw_addr); + struct arp_entry_data *ret_arp_data; + ret_arp_data = get_dest_mac_addr_port(dest_address, &dest_if, (struct ether_addr *)&hw_addr); - if (unlikely(ret != ARP_FOUND)) { + if (unlikely(ret_arp_data == NULL)) { - if (unlikely(ret == ARP_NOT_FOUND)) { - printf("%s: ARP Not Found, nhip: %x, " - "outport_id: %d\n", __func__, nhip, - *outport_id); - //request_arp(*outport_id, nhip, p_nat->p.p); - } + printf("%s: NHIP Not Found, nhip: %x, " + "outport_id: %d\n", __func__, nhip, + *outport_id); /* Drop the pkt */ p_nat->invalid_packets |= pkt_mask; @@ -6377,10 +6294,12 @@ pkt_work_cgnapt_ipv6_prv( p_nat->naptDroppedPktCount4++; #endif return; - } - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 2) { + + if (ret_arp_data->status == COMPLETE) { + + #ifdef CGNAPT_DBG_PRNT + if (CGNAPT_DEBUG > 2) { printf("MAC found for ip 0x%x, port %d - %02x:%02x: " "%02x:%02x:%02x:%02x\n", dest_address, *outport_id, @@ -6392,22 +6311,28 @@ pkt_work_cgnapt_ipv6_prv( "%02x:%02x\n", eth_dest[0], eth_dest[1], eth_dest[2], eth_dest[3], eth_dest[4], eth_dest[5]); - } - #endif + } + #endif - memcpy(eth_dest, &hw_addr, sizeof(struct ether_addr)); + //memcpy(eth_dest, &hw_addr, sizeof(struct ether_addr)); - #ifdef CGNAPT_DBG_PRNT - if (CGNAPT_DEBUG > 2) { - printf("Dest MAC after - " - "%02x:%02x:%02x:%02x:%02x:%02x\n", - eth_dest[0], eth_dest[1], eth_dest[2], eth_dest[3], - eth_dest[4], eth_dest[5]); - } - #endif + #ifdef CGNAPT_DBG_PRNT + if (CGNAPT_DEBUG > 2) { + printf("Dest MAC after - " + "%02x:%02x:%02x:%02x:%02x:%02x\n", + eth_dest[0], eth_dest[1], eth_dest[2], eth_dest[3], + eth_dest[4], eth_dest[5]); + } + #endif - memcpy(eth_src, get_link_hw_addr(dest_if), + memcpy(eth_src, get_link_hw_addr(dest_if), sizeof(struct ether_addr)); + } else if (ret_arp_data->status == INCOMPLETE || + ret_arp_data->status == PROBE) { + arp_queue_unresolved_packet(ret_arp_data, + pkt); + return; + } } { @@ -6874,20 +6799,15 @@ pkt4_work_cgnapt_ipv6_prv( memset(nh_ipv6, 0, 16); - { - int ret; - ret = get_dest_mac_addr_port(dest_address, &dest_if, &hw_addr); + { + struct arp_entry_data *ret_arp_data; + ret_arp_data = get_dest_mac_addr_port(dest_address, &dest_if, (struct ether_addr *)&hw_addr); - if (unlikely(ret != ARP_FOUND)) { + if (unlikely(ret_arp_data == NULL)) { - if (unlikely(ret == ARP_NOT_FOUND)) { - /* Commented code may be required for debug - * and future use, Please keep it */ - //request_arp(*outport_id, nhip, p_nat->p.p); - printf("%s: ARP Not Found, nhip: %x, " - "outport_id: %d\n", __func__, nhip, - *outport_id); - } + printf("%s: NHIP Not Found, nhip: %x, " + "outport_id: %d\n", __func__, nhip, + *outport_id); /* Drop the pkt */ p_nat->invalid_packets |= pkt_mask; @@ -6897,9 +6817,10 @@ pkt4_work_cgnapt_ipv6_prv( p_nat->naptDroppedPktCount4++; #endif continue; - } + if (ret_arp_data->status == COMPLETE) { + #ifdef CGNAPT_DBG_PRNT if (CGNAPT_DEBUG > 2) { printf("MAC found for ip 0x%x, port %d - " @@ -6920,7 +6841,7 @@ pkt4_work_cgnapt_ipv6_prv( } #endif - memcpy(eth_dest, &hw_addr, sizeof(struct ether_addr)); + //memcpy(eth_dest, &hw_addr, sizeof(struct ether_addr)); #ifdef CGNAPT_DBG_PRNT if (CGNAPT_DEBUG > 2) { @@ -6931,10 +6852,15 @@ pkt4_work_cgnapt_ipv6_prv( } #endif - memcpy(eth_src, - get_link_hw_addr(dest_if), + memcpy(eth_src, get_link_hw_addr(dest_if), sizeof(struct ether_addr)); + } else if (ret_arp_data->status == INCOMPLETE || + ret_arp_data->status == PROBE) { + arp_queue_unresolved_packet(ret_arp_data, + pkt); + continue; } + } { /* Egress */ @@ -7050,8 +6976,7 @@ pkt4_work_cgnapt_ipv6_pub( uint8_t dest_addr_ipv6[16]; uint8_t nh_ipv6[16]; uint32_t dest_if = INVALID_DESTIF; - /* Ingress */ - { + { /*start of Ingress */ if (unlikely(protocol == IP_PROTOCOL_UDP && rte_be_to_cpu_16(*src_port) == 53)) { @@ -7086,7 +7011,7 @@ pkt4_work_cgnapt_ipv6_pub( } *outport_id = p_nat->outport_id[dest_if]; - } + }/* end of ingress */ #ifdef CGNAPT_DEBUGGING static int static_count; @@ -7147,7 +7072,7 @@ pkt4_work_cgnapt_ipv6_pub( } { - /* Ingress */ + /* start of Ingress */ convert_ipv4_to_ipv6(pkt, &ipv4_hdr); @@ -7175,7 +7100,7 @@ pkt4_work_cgnapt_ipv6_pub( #endif p_nat->inaptedPktCount++; - } + } /* end of ingress */ p_nat->naptedPktCount++; @@ -7185,7 +7110,7 @@ pkt4_work_cgnapt_ipv6_pub( else sw_checksum(pkt, pkt_type); #endif - } + } /* end of for loop */ } /** @@ -7891,12 +7816,11 @@ pkt_miss_cgnapt(struct pipeline_cgnapt_entry_key *key, printf("Add Dynamic NAT entry failed " "in pkt!!!\n"); #endif - } else { + } else { #ifdef CGNAPT_DEBUGGING p_nat->missedpktcount11++; #endif - } - + } } } else if (!is_phy_port_privte(phy_port)) { @@ -8389,7 +8313,6 @@ pipeline_cgnapt_parse_args(struct pipeline_cgnapt *p, return 0; } - /** * Function to initialize the pipeline * @@ -8417,6 +8340,7 @@ static void *pipeline_cgnapt_init(struct pipeline_params *params, void *arg) size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct pipeline_cgnapt)); p = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE); p_nat = (struct pipeline_cgnapt *)p; + global_pnat = p_nat; if (p == NULL) return NULL; @@ -9260,10 +9184,10 @@ pipeline_cgnapt_msg_req_entry_addm_pair( } #endif - if (CGNAPT_DEBUG > 2) - printf("key.ip %x, key.port %d", key.ip, key.port); - printf("key.pid %d, in_type %d,", key.pid, type); - printf("entry_type %d\n", entry.data.type); + //if (CGNAPT_DEBUG > 2) + //printf("key.ip %x, key.port %d", key.ip, key.port); + //printf("key.pid %d, in_type %d,", key.pid, type); + //printf("entry_type %d\n", entry.data.type); int32_t position = rte_hash_add_key(napt_common_table, &key); diff --git a/VNFs/vCGNAPT/pipeline/pipeline_cgnapt_be.h b/VNFs/vCGNAPT/pipeline/pipeline_cgnapt_be.h index 34031192..a5c83bf1 100644 --- a/VNFs/vCGNAPT/pipeline/pipeline_cgnapt_be.h +++ b/VNFs/vCGNAPT/pipeline/pipeline_cgnapt_be.h @@ -780,7 +780,6 @@ void calculate_hw_checksum( uint8_t protocol); uint64_t nextPowerOf2(uint64_t n); -struct ether_addr *get_local_link_hw_addr(uint8_t out_port); uint8_t local_dest_mac_present(uint8_t out_port); enum PKT_TYPE { diff --git a/VNFs/vFW/init.c b/VNFs/vFW/init.c index 979e1050..f5d457a4 100644 --- a/VNFs/vFW/init.c +++ b/VNFs/vFW/init.c @@ -1368,12 +1368,13 @@ int app_init(struct app_params *app) app_init_pipelines(app); app_init_threads(app); + #ifdef L3_STACK_SUPPORT l3fwd_init(); create_arp_table(); create_nd_table(); populate_lpm_routes(); print_interface_details(); - + #endif return 0; } diff --git a/VNFs/vFW/pipeline/pipeline_vfw_be.c b/VNFs/vFW/pipeline/pipeline_vfw_be.c index 97508a77..a654c3fc 100644 --- a/VNFs/vFW/pipeline/pipeline_vfw_be.c +++ b/VNFs/vFW/pipeline/pipeline_vfw_be.c @@ -177,6 +177,7 @@ __rte_cache_aligned; * to avoid useless table lookup */ /***** ARP local cache *****/ +#if 0 uint8_t link_hw_laddr_valid[MAX_NUM_LOCAL_MAC_ADDRESS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 @@ -200,6 +201,8 @@ static struct ether_addr link_hw_laddr[MAX_NUM_LOCAL_MAC_ADDRESS] = { {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} } }; +#endif +uint64_t arp_pkts_mask; /* Start TSC measurement */ /* Prefetch counters and pipe before this function */ @@ -228,11 +231,11 @@ static inline void end_tsc_measure( } } -static struct ether_addr *get_local_link_hw_addr(uint8_t out_port) -{ - return &link_hw_laddr[out_port]; -} - +//static struct ether_addr *get_local_link_hw_addr(uint8_t out_port) +//{ +// return &link_hw_laddr[out_port]; +//} +#if 0 static uint8_t local_dest_mac_present(uint8_t out_port) { return link_hw_laddr_valid[out_port]; @@ -284,6 +287,7 @@ static void do_local_nh_ipv4_cache(uint32_t dest_if, } } } +#endif static uint32_t local_get_nh_ipv6( uint8_t *ip, uint32_t *port, @@ -895,15 +899,11 @@ pkt4_work_vfw_arp_ipv4_packets(struct rte_mbuf **pkts, struct pipeline_vfw *vfw_pipe) { - uint32_t ret; - int ret_mac; uint8_t i; - struct ether_addr hw_addr; struct mbuf_tcp_meta_data *meta_data_addr; struct ether_hdr *ehdr; struct rte_mbuf *pkt; - uint16_t phy_port; for (i = 0; i < 4; i++) { uint32_t dest_if = INVALID_DESTIF; @@ -917,7 +917,6 @@ pkt4_work_vfw_arp_ipv4_packets(struct rte_mbuf **pkts, int must_reverse = ((synproxy_reply_mask & pkt_mask) != 0); - phy_port = pkt->port; meta_data_addr = (struct mbuf_tcp_meta_data *) RTE_MBUF_METADATA_UINT32_PTR(pkt, META_DATA_OFFSET); ehdr = rte_vfw_get_ether_addr(pkt); @@ -928,7 +927,9 @@ pkt4_work_vfw_arp_ipv4_packets(struct rte_mbuf **pkts, uint32_t nhip = 0; uint32_t dest_address = rte_bswap32(ihdr->dst_addr); - + if (must_reverse) + rte_sp_exchange_mac_addresses(ehdr); +#if 0 ret = local_get_nh_ipv4(dest_address, &dest_if, &nhip, vfw_pipe); if (must_reverse) { @@ -993,55 +994,52 @@ pkt4_work_vfw_arp_ipv4_packets(struct rte_mbuf **pkts, ether_addr_copy(get_link_hw_addr(dest_if), &ehdr->s_addr); } else { - ret_mac = get_dest_mac_addr_port(dest_address, - &dest_if, &hw_addr); - if (ret_mac == ARP_FOUND) { +#endif + struct arp_entry_data *ret_arp_data = NULL; + ret_arp_data = get_dest_mac_addr_port(dest_address, + &dest_if, &ehdr->d_addr); + meta_data_addr->output_port = vfw_pipe->outport_id[dest_if]; - link_hw_laddr_valid[dest_if] = 1; - memcpy(&link_hw_laddr[dest_if], &hw_addr, - sizeof(struct ether_addr)); + if (arp_cache_dest_mac_present(dest_if)) { - ether_addr_copy(&hw_addr, &ehdr->d_addr); - ether_addr_copy(get_link_hw_addr(dest_if), - &ehdr->s_addr); + ether_addr_copy(get_link_hw_addr(dest_if), &ehdr->s_addr); + arp_data_ptr[dest_if]->n_last_update = time(NULL); - if (vfw_debug >= DEBUG_LEVEL_4) { - char buf[HW_ADDR_SIZE]; + if (unlikely(ret_arp_data && ret_arp_data->num_pkts)) { + + printf("sending buffered packets\n"); + arp_send_buffered_pkts(ret_arp_data, + &ehdr->d_addr, vfw_pipe->outport_id[dest_if]); - ether_format_addr(buf, sizeof(buf), - &hw_addr); - printf("MAC found for ip 0x%" - PRIx32", dest_if %d: %s, ", - dest_address, - dest_if, buf); - ether_format_addr(buf, sizeof(buf), - &ehdr->s_addr); - printf("new eth hdr src: %s, ", buf); - ether_format_addr(buf, sizeof(buf), - &ehdr->d_addr); - printf("new eth hdr dst: %s\n", buf); } } else { + if (unlikely(ret_arp_data == NULL)) { - if (vfw_debug >= DEBUG_LEVEL_4) { - char buf[HW_ADDR_SIZE]; + printf("%s: NHIP Not Found, nhip:%x , " + "outport_id: %d\n", __func__, nhip, + vfw_pipe->outport_id[dest_if]); - ether_format_addr(buf, sizeof(buf), - &hw_addr); - printf("MAC NOT FOUND for ip 0x%" - PRIx32", dest_if %" - PRId16": %s, ", - dest_address, - dest_if, buf); + /* Drop the pkt */ + vfw_pipe->counters-> + pkts_drop_without_arp_entry++; + continue; } + if (ret_arp_data->status == INCOMPLETE || + ret_arp_data->status == PROBE) { + if (ret_arp_data->num_pkts >= NUM_DESC) { /* ICMP req sent, drop packet by * changing the mask */ - *pkts_mask &= ~pkt_mask; - vfw_pipe-> - counters->pkts_drop_without_arp_entry++; + vfw_pipe->counters-> + pkts_drop_without_arp_entry++; + continue; + } else { + arp_pkts_mask |= pkt_mask; + arp_queue_unresolved_packet(ret_arp_data, pkt); + continue; } } + } } } @@ -1072,15 +1070,11 @@ pkt_work_vfw_arp_ipv4_packets(struct rte_mbuf *pkts, struct pipeline_vfw *vfw_pipe) { - uint32_t ret; uint32_t dest_if = INVALID_DESTIF; - int ret_mac; - struct ether_addr hw_addr; struct mbuf_tcp_meta_data *meta_data_addr; struct ether_hdr *ehdr; struct rte_mbuf *pkt; - uint16_t phy_port; uint64_t pkt_mask = 1LLU << pkt_num; pkt = pkts; @@ -1089,7 +1083,6 @@ pkt_work_vfw_arp_ipv4_packets(struct rte_mbuf *pkts, int must_reverse = ((synproxy_reply_mask & pkt_mask) != 0); - phy_port = pkt->port; meta_data_addr = (struct mbuf_tcp_meta_data *) RTE_MBUF_METADATA_UINT32_PTR(pkt, META_DATA_OFFSET); ehdr = rte_vfw_get_ether_addr(pkt); @@ -1100,7 +1093,10 @@ pkt_work_vfw_arp_ipv4_packets(struct rte_mbuf *pkts, uint32_t nhip = 0; uint32_t dest_address = rte_bswap32(ihdr->dst_addr); + if (must_reverse) + rte_sp_exchange_mac_addresses(ehdr); +#if 0 ret = local_get_nh_ipv4(dest_address, &dest_if, &nhip, vfw_pipe); if (must_reverse) { @@ -1165,53 +1161,50 @@ pkt_work_vfw_arp_ipv4_packets(struct rte_mbuf *pkts, ether_addr_copy(get_link_hw_addr(dest_if), &ehdr->s_addr); } else { - ret_mac = get_dest_mac_addr_port(dest_address, - &dest_if, &hw_addr); - if (ret_mac) { - link_hw_laddr_valid[dest_if] = 1; - memcpy(&link_hw_laddr[dest_if], &hw_addr, - sizeof(struct ether_addr)); - - ether_addr_copy(&hw_addr, &ehdr->d_addr); - ether_addr_copy(get_link_hw_addr(dest_if), - &ehdr->s_addr); +#endif + struct arp_entry_data *ret_arp_data = NULL; + ret_arp_data = get_dest_mac_addr_port(dest_address, + &dest_if, &ehdr->d_addr); + meta_data_addr->output_port = vfw_pipe->outport_id[dest_if]; + if (arp_cache_dest_mac_present(dest_if)) { - if (vfw_debug >= DEBUG_LEVEL_4) { - char buf[HW_ADDR_SIZE]; + ether_addr_copy(get_link_hw_addr(dest_if), &ehdr->s_addr); + arp_data_ptr[dest_if]->n_last_update = time(NULL); + + if (unlikely(ret_arp_data && ret_arp_data->num_pkts)) { + + printf("sending buffered packets\n"); + arp_send_buffered_pkts(ret_arp_data, + &ehdr->d_addr, vfw_pipe->outport_id[dest_if]); - ether_format_addr(buf, sizeof(buf), - &hw_addr); - printf("MAC found for ip 0x%" - PRIx32", dest_if %d: %s, ", - dest_address, - dest_if, buf); - ether_format_addr(buf, sizeof(buf), - &ehdr->s_addr); - printf("new eth hdr src: %s, ", buf); - ether_format_addr(buf, sizeof(buf), - &ehdr->d_addr); - printf("new eth hdr dst: %s\n", buf); } } else { - if (vfw_debug >= DEBUG_LEVEL_4) { - char buf[HW_ADDR_SIZE]; - - ether_format_addr(buf, sizeof(buf), - &hw_addr); - printf("MAC NOT FOUND for ip 0x%" - PRIx32", dest_if %" - PRId16": %s, ", - dest_address, - dest_if, buf); + if (unlikely(ret_arp_data == NULL)) { + + printf("%s: NHIP Not Found, nhip:%x , " + "outport_id: %d\n", __func__, nhip, + vfw_pipe->outport_id[dest_if]); + + vfw_pipe->counters-> + pkts_drop_without_arp_entry++; + return; } + if (ret_arp_data->status == INCOMPLETE || + ret_arp_data->status == PROBE) { + if (ret_arp_data->num_pkts >= NUM_DESC) { /* ICMP req sent, drop packet by * changing the mask */ - *pkts_mask &= ~pkt_mask; - vfw_pipe-> - counters->pkts_drop_without_arp_entry++; + vfw_pipe->counters-> + pkts_drop_without_arp_entry++; + return; + } else { + arp_pkts_mask |= pkt_mask; + arp_queue_unresolved_packet(ret_arp_data, pkt); + return; } } + } } } @@ -1567,7 +1560,6 @@ rte_vfw_arp_ipv4_packets(struct rte_mbuf **pkts, uint32_t ret; uint32_t dest_if = INVALID_DESTIF; - int ret_mac; for (; pkts_to_arp;) { struct ether_addr hw_addr; struct mbuf_tcp_meta_data *meta_data_addr; @@ -1594,7 +1586,9 @@ rte_vfw_arp_ipv4_packets(struct rte_mbuf **pkts, uint32_t nhip = 0; uint32_t dest_address = rte_bswap32(ihdr->dst_addr); - + if (must_reverse) + rte_sp_exchange_mac_addresses(ehdr); +#if 0 ret = local_get_nh_ipv4(dest_address, &dest_if, &nhip, vfw_pipe); if (must_reverse) { @@ -1659,57 +1653,52 @@ rte_vfw_arp_ipv4_packets(struct rte_mbuf **pkts, ether_addr_copy(get_link_hw_addr(dest_if), &ehdr->s_addr); } else { - ret_mac = get_dest_mac_addr_port(dest_address, - &dest_if, &hw_addr); - if (ret_mac) { - link_hw_laddr_valid[dest_if] = 1; - memcpy(&link_hw_laddr[dest_if], &hw_addr, - sizeof(struct ether_addr)); - - ether_addr_copy(&hw_addr, &ehdr->d_addr); - ether_addr_copy(get_link_hw_addr(dest_if), - &ehdr->s_addr); +#endif + struct arp_entry_data *ret_arp_data = NULL; + ret_arp_data = get_dest_mac_addr_port(dest_address, + &dest_if, &ehdr->d_addr); + meta_data_addr->output_port = vfw_pipe->outport_id[dest_if]; + if (arp_cache_dest_mac_present(dest_if)) { - if (vfw_debug >= DEBUG_LEVEL_4) { - char buf[HW_ADDR_SIZE]; + ether_addr_copy(get_link_hw_addr(dest_if), &ehdr->s_addr); + arp_data_ptr[dest_if]->n_last_update = time(NULL); + + if (unlikely(ret_arp_data && ret_arp_data->num_pkts)) { + + printf("sending buffered packets\n"); + p_nat->naptedPktCount += ret_arp_data->num_pkts; + arp_send_buffered_pkts(ret_arp_data, + &ehdr->d_addr, vfw_pipe->outport_id[dest_if]); - ether_format_addr(buf, sizeof(buf), - &hw_addr); - printf("MAC found for ip 0x%" - PRIx32", dest_if %d: %s, ", - dest_address, - dest_if, buf); - ether_format_addr(buf, sizeof(buf), - &ehdr->s_addr); - printf("new eth hdr src: %s, ", buf); - ether_format_addr(buf, sizeof(buf), - &ehdr->d_addr); - printf("new eth hdr dst: %s\n", buf); } } else { - if (unlikely(ret_mac == 0)) - request_arp(meta_data_addr->output_port, - nhip); + if (unlikely(ret_arp_data == NULL)) { - if (vfw_debug >= DEBUG_LEVEL_4) { - char buf[HW_ADDR_SIZE]; + printf("%s: NHIP Not Found, nhip:%x , " + "outport_id: %d\n", __func__, nhip, + vfw_pipe->outport_id[dest_if]); - ether_format_addr(buf, sizeof(buf), - &hw_addr); - printf("MAC NOT FOUND for ip 0x%" - PRIx32", dest_if %" - PRId16": %s, ", - dest_address, - dest_if, buf); + /* Drop the pkt */ + vfw_pipe->counters-> + pkts_drop_without_arp_entry++; + continue; } + if (ret_arp_data->status == INCOMPLETE || + ret_arp_data->status == PROBE) { + if (ret_arp_data->num_pkts >= NUM_DESC) { /* ICMP req sent, drop packet by * changing the mask */ - pkts_mask &= ~pkt_mask; - vfw_pipe-> - counters->pkts_drop_without_arp_entry++; + vfw_pipe->counters-> + pkts_drop_without_arp_entry++; + continue; + } else { + arp_pkts_mask |= pkt_mask; + arp_queue_unresolved_packet(ret_arp_data, pkt); + continue; } } + } } @@ -2070,6 +2059,7 @@ vfw_port_in_action_ipv4(struct rte_pipeline *p, uint64_t packet_mask_in = RTE_LEN2MASK(n_pkts, uint64_t); uint64_t pkts_drop_mask; uint64_t hijack_mask = 0; + arp_pkts_mask = 0; uint64_t synproxy_reply_mask = 0; /* for synproxy */ uint64_t keep_mask = packet_mask_in; @@ -2204,6 +2194,9 @@ vfw_port_in_action_ipv4(struct rte_pipeline *p, } /* Update mask before returning, so that bad packets are dropped */ + if (arp_pkts_mask) { + rte_pipeline_ah_packet_hijack(p, arp_pkts_mask); + } pkts_drop_mask = packet_mask_in & ~keep_mask; diff --git a/common/VIL/l2l3_stack/interface.c b/common/VIL/l2l3_stack/interface.c index bd4c4e92..627423b4 100644 --- a/common/VIL/l2l3_stack/interface.c +++ b/common/VIL/l2l3_stack/interface.c @@ -453,6 +453,7 @@ void ifm_update_linkstatus(uint8_t port_id, uint16_t linkstatus) rte_eth_link_get(port_id, &link); if (linkstatus == IFM_ETH_LINK_UP) { port->admin_status = IFM_ETH_LINK_UP; + port->link_status = IFM_ETH_LINK_UP; if(!link.link_status) { if (rte_eth_dev_set_link_up(port_id) < 0) { RTE_LOG(INFO, IFM, @@ -481,6 +482,7 @@ void ifm_update_linkstatus(uint8_t port_id, uint16_t linkstatus) { int status; port->admin_status = IFM_ETH_LINK_DOWN; + port->link_status = IFM_ETH_LINK_DOWN; /* need to check the following if */ if(link.link_status) { status = rte_eth_dev_set_link_down(port_id); diff --git a/common/VIL/l2l3_stack/interface.h b/common/VIL/l2l3_stack/interface.h index 0f654fa1..f8d35cb2 100644 --- a/common/VIL/l2l3_stack/interface.h +++ b/common/VIL/l2l3_stack/interface.h @@ -102,7 +102,7 @@ #define IFM_QUEUE_STAT_CNTRS 16 #define IFM_TX_DEFAULT_Q 0 #define IFM_RX_DEFAULT_Q 0 -#define IFM_RX_DESC_DEFAULT 128 +#define IFM_RX_DESC_DEFAULT 512 #define IFM_TX_DESC_DEFAULT 512 #define IFM_BURST_SIZE 32 #define IFM_BURST_TX_WAIT_US 1 diff --git a/common/VIL/l2l3_stack/l3fwd_lpm4.c b/common/VIL/l2l3_stack/l3fwd_lpm4.c index 081038b6..8b3aab19 100644 --- a/common/VIL/l2l3_stack/l3fwd_lpm4.c +++ b/common/VIL/l2l3_stack/l3fwd_lpm4.c @@ -491,7 +491,7 @@ get_dest_mac_for_nexthop(uint32_t next_hop_ip, arp_key.port_id = out_phy_port; arp_key.ip = next_hop_ip; - arp_data = retrieve_arp_entry(arp_key); + arp_data = retrieve_arp_entry(arp_key, DYNAMIC_ARP); if (arp_data == NULL) { printf("ARP entry is not found for ip %x, port %d\n", next_hop_ip, out_phy_port); diff --git a/common/VIL/l2l3_stack/lib_arp.c b/common/VIL/l2l3_stack/lib_arp.c index 0162f820..43d0c8e5 100644 --- a/common/VIL/l2l3_stack/lib_arp.c +++ b/common/VIL/l2l3_stack/lib_arp.c @@ -34,6 +34,7 @@ #include <rte_jhash.h> #include <rte_cycles.h> #include <rte_timer.h> +#include <tsx.h> #include "interface.h" #include "l2_proto.h" #include "lib_arp.h" @@ -59,14 +60,19 @@ extern uint8_t prv_in_port_a[PIPELINE_MAX_PORT_IN]; extern uint32_t timer_lcore; +extern int USE_RTM_LOCKS; uint32_t arp_timeout = ARP_TIMER_EXPIRY; +uint32_t arp_buffer = ARP_BUF_DEFAULT; /*ND IPV6 */ #define INADDRSZ 4 #define IN6ADDRSZ 16 +#define MAX_PORTS 32 + static int my_inet_pton_ipv6(int af, const char *src, void *dst); static int inet_pton_ipv6(const char *src, unsigned char *dst); static int inet_pton_ipv4(const char *src, unsigned char *dst); +static void local_arp_cache_init(void); extern void convert_prefixlen_to_netmask_ipv6(uint32_t depth, uint8_t netmask_ipv6[]); @@ -101,12 +107,71 @@ uint32_t lib_nd_duplicate_found; struct rte_mempool *lib_arp_pktmbuf_tx_pool; struct rte_mempool *lib_nd_pktmbuf_tx_pool; -struct rte_mbuf *lib_arp_pkt; +struct rte_mbuf *lib_arp_pkt[MAX_PORTS]; struct rte_mbuf *lib_nd_pkt; uint8_t default_ether_addr[6] = { 0, 0, 0, 0, 1, 1 }; uint8_t default_ip[4] = { 0, 0, 1, 1 }; +uint64_t start_tsc[4]; +uint64_t end_tsc[4]; +#define ticks_per_ms (rte_get_tsc_hz()/1000) + +#define MAX_NUM_ARP_CACHE_MAC_ADDRESS 16 + +/***** ARP local cache *****/ +struct arp_data *p_arp_data; +//struct arp_cache arp_local_cache[MAX_PORTS]; +uint8_t arp_cache_hw_laddr_valid[MAX_NUM_ARP_CACHE_MAC_ADDRESS] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 +}; + +void prefetch(void) +{ + rte_prefetch0(p_arp_data); +} + +struct arp_entry_data *arp_data_ptr[MAX_NUM_ARP_CACHE_MAC_ADDRESS]; + +struct ether_addr arp_cache_hw_laddr[MAX_NUM_ARP_CACHE_MAC_ADDRESS] = { + {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, + {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, + {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, + {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, + {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, + {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, + {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, + {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, + {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, + {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, + {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, + {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, + {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, + {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, + {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, + {.addr_bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} } +}; + +/** + * A structure defining the mbuf meta data for VFW. + */ +struct mbuf_arp_meta_data { +/* output port stored for RTE_PIPELINE_ACTION_PORT_META */ + uint32_t output_port; + struct rte_mbuf *next; /* next pointer for chained buffers */ +} __rte_cache_aligned; + +static struct arp_entry_data arp_entry_data_default = { + .status = COMPLETE, + .num_pkts = 0, +}; + +/** + * memory pool for queued up user pkts. + */ +struct rte_mempool *arp_icmp_pktmbuf_tx_pool; + static struct rte_hash_parameters arp_hash_params = { .name = "ARP", .entries = 64, @@ -125,6 +190,24 @@ static struct rte_hash_parameters nd_hash_params = { .hash_func_init_val = 0, }; +struct ether_addr broadcast_ether_addr = { + .addr_bytes[0] = 0xFF, + .addr_bytes[1] = 0xFF, + .addr_bytes[2] = 0xFF, + .addr_bytes[3] = 0xFF, + .addr_bytes[4] = 0xFF, + .addr_bytes[5] = 0xFF, +}; + +static const struct ether_addr null_ether_addr = { + .addr_bytes[0] = 0x00, + .addr_bytes[1] = 0x00, + .addr_bytes[2] = 0x00, + .addr_bytes[3] = 0x00, + .addr_bytes[4] = 0x00, + .addr_bytes[5] = 0x00, +}; + struct rte_hash *arp_hash_handle; struct rte_hash *nd_hash_handle; @@ -150,18 +233,18 @@ int timer_objs_mempool_count = 70000; #define MAX_NUM_ARP_ENTRIES 64 #define MAX_NUM_ND_ENTRIES 64 -uint32_t get_nh(uint32_t, uint32_t *); +inline uint32_t get_nh(uint32_t, uint32_t *, struct ether_addr *addr); void get_nh_ipv6(uint8_t ipv6[], uint32_t *port, uint8_t nhipv6[]); #define MAX_ARP_DATA_ENTRY_TABLE 7 struct table_arp_entry_data arp_entry_data_table[MAX_ARP_DATA_ENTRY_TABLE] = { - {{0, 0, 0, 0, 0, 1}, 1, INCOMPLETE, IPv4(192, 168, 0, 2)}, - {{0, 0, 0, 0, 0, 2}, 0, INCOMPLETE, IPv4(192, 168, 0, 3)}, - {{0, 0, 0, 0, 0, 1}, 1, INCOMPLETE, IPv4(30, 40, 50, 60)}, - {{0, 0, 0, 0, 0, 1}, 1, INCOMPLETE, IPv4(120, 0, 0, 2)}, - {{0, 0, 0, 0, 0, 4}, 3, INCOMPLETE, IPv4(1, 1, 1, 4)}, - {{0, 0, 0, 0, 0, 5}, 4, INCOMPLETE, IPv4(1, 1, 1, 5)}, + {{0, 0, 0, 0, 0, 1}, 1, INCOMPLETE, IPv4(1, 1, 1, 1)}, + {{0, 0, 0, 0, 0, 2}, 0, INCOMPLETE, IPv4(1, 1, 1, 2)}, + {{0, 0, 0, 0, 0, 1}, 1, INCOMPLETE, IPv4(1, 1, 1, 3)}, + {{0, 0, 0, 0, 0, 1}, 1, INCOMPLETE, IPv4(1, 1, 1, 4)}, + {{0, 0, 0, 0, 0, 4}, 1, INCOMPLETE, IPv4(1, 1, 1, 5)}, + {{0, 0, 0, 0, 0, 5}, 0, INCOMPLETE, IPv4(1, 1, 1, 6)}, {{0, 0, 0, 0, 0, 6}, 1, INCOMPLETE, IPv4(1, 1, 1, 7)}, }; @@ -252,42 +335,52 @@ struct lib_nd_route_table_entry lib_nd_route_table[MAX_ND_RT_ENTRY] = { }; struct lib_arp_route_table_entry lib_arp_route_table[MAX_ARP_RT_ENTRY] = { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0} + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0} }; void print_trace(void); +uint32_t get_arp_buf(void) +{ + return arp_buffer; +} + +uint8_t arp_cache_dest_mac_present(uint32_t out_port) +{ + return p_arp_data->arp_cache_hw_laddr_valid[out_port]; +} + /* Obtain a backtrace and print it to stdout. */ void print_trace(void) { @@ -307,30 +400,19 @@ void print_trace(void) free(strings); } -uint32_t get_nh(uint32_t ip, uint32_t *port) +uint32_t get_nh(uint32_t ip, uint32_t *port, struct ether_addr *addr) { int i = 0; - for (i = 0; i < MAX_ARP_RT_ENTRY; i++) { - if (((lib_arp_route_table[i]. - ip & lib_arp_route_table[i].mask) == - (ip & lib_arp_route_table[i].mask))) { - - *port = lib_arp_route_table[i].port; - lib_arp_nh_found++; - return lib_arp_route_table[i].nh; + for (i = 0; i < p_arp_data->lib_arp_route_ent_cnt; i++) { + if ((p_arp_data->lib_arp_route_table[i].nh_mask) == + (ip & p_arp_data->lib_arp_route_table[i].mask)) { + + *port = p_arp_data->lib_arp_route_table[i].port; + if (arp_cache_dest_mac_present(*port)) + ether_addr_copy(get_local_link_hw_addr(*port, p_arp_data->lib_arp_route_table[i].nh), addr); + return p_arp_data->lib_arp_route_table[i].nh; } - if (ARPICMP_DEBUG) - printf("No nh match ip 0x%x, port %u, t_ip " - "0x%x, t_port %u, mask 0x%x, r1 %x, r2 %x\n", - ip, *port, lib_arp_route_table[i].ip, - lib_arp_route_table[i].port, - lib_arp_route_table[i].mask, - (lib_arp_route_table[i].ip & - lib_arp_route_table[i].mask), - (ip & lib_arp_route_table[i].mask)); } - if (ARPICMP_DEBUG) - printf("No NH - ip 0x%x, port %u\n", ip, *port); lib_arp_no_nh_found++; return 0; } @@ -388,22 +470,30 @@ void get_nh_ipv6(uint8_t ipv6[], uint32_t *port, uint8_t nhipv6[]) } /* Added for Multiport changes*/ -int get_dest_mac_addr_port(const uint32_t ipaddr, +struct arp_entry_data *get_dest_mac_addr_port(const uint32_t ipaddr, uint32_t *phy_port, struct ether_addr *hw_addr) { - lib_arp_get_mac_req++; + struct arp_entry_data *ret_arp_data = NULL; uint32_t nhip = 0; + uint8_t index; - nhip = get_nh(ipaddr, phy_port); - if (nhip == 0) { + //lib_arp_get_mac_req++; + nhip = get_nh(ipaddr, phy_port, hw_addr); + if (unlikely(nhip == 0)) { if (ARPICMP_DEBUG) printf("ARPICMP no nh found for ip %x, port %d\n", ipaddr, *phy_port); - //return 0; - return NH_NOT_FOUND; + return ret_arp_data; + } + + /* as part of optimization we store mac address in cache + * & thus can be sent without having to retrieve + */ + if (arp_cache_dest_mac_present(*phy_port)) { + //arp_data_ptr[*phy_port]->n_last_update = time(NULL); + return &arp_entry_data_default; } - struct arp_entry_data *ret_arp_data = NULL; struct arp_key_ipv4 tmp_arp_key; tmp_arp_key.port_id = *phy_port; /* Changed for Multi Port */ tmp_arp_key.ip = nhip; @@ -412,117 +502,35 @@ int get_dest_mac_addr_port(const uint32_t ipaddr, printf("%s: nhip: %x, phyport: %d\n", __FUNCTION__, nhip, *phy_port); - ret_arp_data = retrieve_arp_entry(tmp_arp_key); + ret_arp_data = retrieve_arp_entry(tmp_arp_key, DYNAMIC_ARP); if (ret_arp_data == NULL) { - if (ARPICMP_DEBUG) { - printf - ("ARPICMP no arp entry found for ip %x, port %d\n", - ipaddr, *phy_port); - print_arp_table(); - } - if (nhip != 0) { - if (ARPICMP_DEBUG) - printf("CG-NAPT requesting ARP for ip %x, " - "port %d\n", nhip, *phy_port); - request_arp(*phy_port, nhip); //Changed for Multiport - - } + if (ARPICMP_DEBUG && ipaddr) + { + RTE_LOG(INFO, LIBARP,"ARPICMP no arp entry found for ip %x, port %u\n", ipaddr, *phy_port); + print_arp_table(); + } lib_arp_no_arp_entry_found++; - return ARP_NOT_FOUND; - } - ether_addr_copy(&ret_arp_data->eth_addr, hw_addr); - lib_arp_arp_entry_found++; - if (ARPICMP_DEBUG) - printf("%s: ARPICMP hwaddr found\n", __FUNCTION__); - return ARP_FOUND; -} - -int get_dest_mac_address(const uint32_t ipaddr, uint32_t *phy_port, - struct ether_addr *hw_addr, uint32_t *nhip) -{ - lib_arp_get_mac_req++; - - *nhip = get_nh(ipaddr, phy_port); - if (*nhip == 0) { - if (ARPICMP_DEBUG && ipaddr) - RTE_LOG(INFO, LIBARP, - "ARPICMP no nh found for ip %x, port %d\n", - ipaddr, *phy_port); - return 0; - } - - struct arp_entry_data *ret_arp_data = NULL; - struct arp_key_ipv4 tmp_arp_key; - tmp_arp_key.port_id = *phy_port; - tmp_arp_key.ip = *nhip; - - ret_arp_data = retrieve_arp_entry(tmp_arp_key); - if (ret_arp_data == NULL) { - if (ARPICMP_DEBUG && ipaddr) { - RTE_LOG(INFO, LIBARP, - "ARPICMP no arp entry found for ip %x, port %d\n", - ipaddr, *phy_port); - print_arp_table(); - } - lib_arp_no_arp_entry_found++; - return 0; - } - ether_addr_copy(&ret_arp_data->eth_addr, hw_addr); - lib_arp_arp_entry_found++; - return 1; - -} + } else if (ret_arp_data->status == COMPLETE) { + ether_addr_copy(&ret_arp_data->eth_addr, hw_addr); + printf("Setting mac found for port:%d\n", *phy_port); + p_arp_data->arp_cache_hw_laddr_valid[*phy_port] = 1; + arp_data_ptr[*phy_port] = ret_arp_data; + //memcpy(&arp_cache_hw_laddr[*phy_port], hw_addr, + // sizeof(struct ether_addr)); + index = p_arp_data->arp_local_cache[*phy_port].num_nhip; + p_arp_data->arp_local_cache[*phy_port].nhip[index] = nhip; + ether_addr_copy(hw_addr, &p_arp_data->arp_local_cache[*phy_port].link_hw_laddr[index]); + p_arp_data->arp_local_cache[*phy_port].num_nhip++; + lib_arp_arp_entry_found++; -int get_dest_mac_addr(const uint32_t ipaddr, - uint32_t *phy_port, struct ether_addr *hw_addr) -{ - lib_arp_get_mac_req++; - uint32_t nhip = 0; - - nhip = get_nh(ipaddr, phy_port); - if (nhip == 0) { - if (ARPICMP_DEBUG && ipaddr) - RTE_LOG(INFO, LIBARP, - "ARPICMP no nh found for ip %x, port %d\n", - ipaddr, *phy_port); - return 0; - } - - struct arp_entry_data *ret_arp_data = NULL; - struct arp_key_ipv4 tmp_arp_key; - tmp_arp_key.port_id = *phy_port; - tmp_arp_key.ip = nhip; - - ret_arp_data = retrieve_arp_entry(tmp_arp_key); - if (ret_arp_data == NULL) { - if (ARPICMP_DEBUG && ipaddr) { - printf - ("ARPICMP no arp entry found for ip %x, port %d\n", - ipaddr, *phy_port); - print_arp_table(); - } + if (ARPICMP_DEBUG) + printf("%s: ARPICMP hwaddr found\n", __FUNCTION__); + } - if (nhip != 0) { - if (ARPICMP_DEBUG > 4) - printf - ("CG-NAPT requesting ARP for ip %x, port %d\n", - nhip, *phy_port); - if (ifm_chk_port_ipv4_enabled(*phy_port)) { - request_arp(*phy_port, nhip); - } else { - if (ARPICMP_DEBUG) - RTE_LOG(INFO, LIBARP, - "%s: IP is not enabled on port %u, not sending ARP REQ\n\r", - __FUNCTION__, *phy_port); - } + if (ret_arp_data) + ret_arp_data->n_last_update = time(NULL); - } - lib_arp_no_arp_entry_found++; - return 0; - } - ether_addr_copy(&ret_arp_data->eth_addr, hw_addr); - lib_arp_arp_entry_found++; - return 1; + return ret_arp_data; } int get_dest_mac_address_ipv6_port(uint8_t ipv6addr[], uint32_t *phy_port, @@ -775,7 +783,7 @@ print_mbuf(const char *rx_tx, uint8_t portid, struct rte_mbuf *mbuf, fflush(stdout); } -struct arp_entry_data *retrieve_arp_entry(struct arp_key_ipv4 arp_key) +struct arp_entry_data *retrieve_arp_entry(struct arp_key_ipv4 arp_key, uint8_t mode) { struct arp_entry_data *ret_arp_data = NULL; arp_key.filler1 = 0; @@ -784,29 +792,85 @@ struct arp_entry_data *retrieve_arp_entry(struct arp_key_ipv4 arp_key) int ret = rte_hash_lookup_data(arp_hash_handle, &arp_key, (void **)&ret_arp_data); - if (ret < 0) { - // RTE_LOG(INFO, LIBARP,"arp-hash lookup failed ret %d, EINVAL %d, ENOENT %d\n", ret, EINVAL, ENOENT); + if (ret < 0 && (mode == DYNAMIC_ARP)) { + if (ARPICMP_DEBUG) + RTE_LOG(INFO, LIBARP, "ARP entry not found for ip 0x%x\n",arp_key.ip); + + /* add INCOMPLETE arp entry */ + ret_arp_data = rte_malloc_socket(NULL, sizeof(struct arp_entry_data), + RTE_CACHE_LINE_SIZE, rte_socket_id()); + ether_addr_copy(&null_ether_addr, &ret_arp_data->eth_addr); + ret_arp_data->status = INCOMPLETE; + ret_arp_data->port = arp_key.port_id; + ret_arp_data->ip = arp_key.ip; + ret_arp_data->mode = mode; + ret_arp_data->num_pkts = 0; + ret_arp_data->buffered_pkt_list_head = NULL; + ret_arp_data->buffered_pkt_list_tail = NULL; + rte_rwlock_init(&ret_arp_data->queue_lock); + rte_rwlock_write_lock(&ret_arp_data->queue_lock); + + if (rte_mempool_get(timer_mempool_arp, + (void **) &(ret_arp_data->timer) ) < 0) { + RTE_LOG(INFO, LIBARP,"Error in getting timer alloc buf\n"); + return NULL; + } + + ret_arp_data->buf_pkts = (struct rte_mbuf **)rte_zmalloc_socket( + NULL, sizeof(struct rte_mbuf *) * arp_buffer, + RTE_CACHE_LINE_SIZE, rte_socket_id()); + + rte_hash_add_key_data(arp_hash_handle, &arp_key, ret_arp_data); + + rte_timer_init(ret_arp_data->timer); + struct arp_timer_key * callback_key = + (struct arp_timer_key*) rte_malloc(NULL, + sizeof(struct arp_timer_key*),RTE_CACHE_LINE_SIZE); + callback_key->port_id = arp_key.port_id; + callback_key->ip = arp_key.ip; + if(ARPICMP_DEBUG) + RTE_LOG(INFO, LIBARP,"TIMER STARTED FOR %u seconds\n",ARP_TIMER_EXPIRY); + if(rte_timer_reset(ret_arp_data->timer, + (PROBE_TIME * rte_get_tsc_hz() / 1000), + SINGLE,timer_lcore, + arp_timer_callback, + callback_key) < 0) + if(ARPICMP_DEBUG) + RTE_LOG(INFO, LIBARP,"Err : Timer already running\n"); + + ret_arp_data->timer_key = callback_key; + + /* send arp request */ + request_arp(arp_key.port_id, arp_key.ip); } else { - - if (ret_arp_data->mode == DYNAMIC_ARP) { - struct arp_timer_key callback_key; - callback_key.port_id = ret_arp_data->port; - callback_key.ip = ret_arp_data->ip; - /*lcore need to check which parameter need to be put */ - if (rte_timer_reset(ret_arp_data->timer, - (arp_timeout * rte_get_tsc_hz()), - SINGLE, timer_lcore, - arp_timer_callback, - &callback_key) < 0) - if (ARPICMP_DEBUG) - RTE_LOG(INFO, LIBARP, - "Err : Timer already running\n"); + if (ret_arp_data && + ret_arp_data->mode == DYNAMIC_ARP && ret_arp_data->status == STALE) { + ether_addr_copy(&null_ether_addr, &ret_arp_data->eth_addr); + ret_arp_data->status = PROBE; + struct arp_timer_key * callback_key = + (struct arp_timer_key*) rte_malloc(NULL, + sizeof(struct arp_timer_key*),RTE_CACHE_LINE_SIZE); + callback_key->port_id = arp_key.port_id; + callback_key->ip = arp_key.ip; + if(ARPICMP_DEBUG) + RTE_LOG(INFO, LIBARP,"TIMER STARTED FOR %u seconds\n",ARP_TIMER_EXPIRY); + if(rte_timer_reset(ret_arp_data->timer, + (arp_timeout * rte_get_tsc_hz()), + SINGLE,timer_lcore, + arp_timer_callback, + callback_key) < 0) + if(ARPICMP_DEBUG) + RTE_LOG(INFO, LIBARP,"Err : Timer already running\n"); + + ret_arp_data->timer_key = callback_key; + + /* send arp request */ + request_arp(arp_key.port_id, arp_key.ip); } - return ret_arp_data; } - return NULL; + return ret_arp_data; } struct nd_entry_data *retrieve_nd_entry(struct nd_key_ipv6 nd_key) @@ -847,6 +911,8 @@ struct nd_entry_data *retrieve_nd_entry(struct nd_key_ipv6 nd_key) return NULL; } +static const char* arp_status[] = {"INCOMPLETE", "COMPLETE", "PROBE", "STALE"}; + void print_arp_table(void) { const void *next_key; @@ -876,8 +942,7 @@ void print_arp_table(void) tmp_arp_data->eth_addr.addr_bytes[3], tmp_arp_data->eth_addr.addr_bytes[4], tmp_arp_data->eth_addr.addr_bytes[5], - tmp_arp_data->status == - COMPLETE ? "COMPLETE" : "INCOMPLETE", + arp_status[tmp_arp_data->status], (tmp_arp_data->ip >> 24), ((tmp_arp_data->ip & 0x00ff0000) >> 16), ((tmp_arp_data->ip & 0x0000ff00) >> 8), @@ -885,13 +950,13 @@ void print_arp_table(void) } uint32_t i = 0; - printf("\nARP routing table has %d entries\n", arp_route_tbl_index); + printf("\nARP routing table has %d entries\n", p_arp_data->lib_arp_route_ent_cnt); printf("\nIP_Address Mask Port NH_IP_Address\n"); - for (i = 0; i < arp_route_tbl_index; i++) { + for (i = 0; i < p_arp_data->lib_arp_route_ent_cnt; i++) { printf("0x%x 0x%x %d 0x%x\n", - lib_arp_route_table[i].ip, - lib_arp_route_table[i].mask, - lib_arp_route_table[i].port, lib_arp_route_table[i].nh); + p_arp_data->lib_arp_route_table[i].ip, + p_arp_data->lib_arp_route_table[i].mask, + p_arp_data->lib_arp_route_table[i].port, p_arp_data->lib_arp_route_table[i].nh); } printf @@ -974,80 +1039,29 @@ void print_nd_table(void) printf("ND table key len is %lu\n\n", sizeof(struct nd_key_ipv6)); } -void remove_arp_entry(uint32_t ipaddr, uint8_t portid, void *arg) +void remove_arp_entry(struct arp_entry_data *ret_arp_data, void *arg) { - struct arp_key_ipv4 arp_key; - arp_key.port_id = portid; - arp_key.ip = ipaddr; - arp_key.filler1 = 0; - arp_key.filler2 = 0; - arp_key.filler3 = 0; - + struct arp_timer_key *arp_key = (struct arp_timer_key *)arg; lib_arp_delete_called++; - struct arp_entry_data *ret_arp_data = NULL; - - int ret = rte_hash_lookup_data(arp_hash_handle, &arp_key, - (void **)&ret_arp_data); - if (ret < 0) { -// RTE_LOG(INFO, LIBARP,"arp-hash lookup failed ret %d, EINVAL %d, ENOENT %d\n", ret, EINVAL, ENOENT); - return; - } else { - if (ret_arp_data->mode == DYNAMIC_ARP) { - if (ret_arp_data->retry_count == 3) { - rte_timer_stop(ret_arp_data->timer); - rte_free(ret_arp_data->timer_key); - if (ARPICMP_DEBUG) { - RTE_LOG(INFO, LIBARP, - "ARP Entry Deleted for IP :%d.%d.%d.%d , port %d\n", - (arp_key.ip >> 24), - ((arp_key.ip & 0x00ff0000) >> - 16), - ((arp_key.ip & 0x0000ff00) >> - 8), - ((arp_key.ip & 0x000000ff)), - arp_key.port_id); - } - rte_hash_del_key(arp_hash_handle, &arp_key); - //print_arp_table(); - } else { - ret_arp_data->retry_count++; - if (ARPICMP_DEBUG) - RTE_LOG(INFO, LIBARP, - "RETRY ARP..retry count : %u\n", - ret_arp_data->retry_count); - //print_arp_table(); - if (ARPICMP_DEBUG) - RTE_LOG(INFO, LIBARP, - "TIMER STARTED FOR %u seconds\n", - ARP_TIMER_EXPIRY); - if (ifm_chk_port_ipv4_enabled - (ret_arp_data->port)) { - request_arp(ret_arp_data->port, - ret_arp_data->ip); - } else { - if (ARPICMP_DEBUG) - RTE_LOG(INFO, LIBARP, - "%s: IP is not enabled on port %u, not sending GARP\n\r", - __FUNCTION__, - ret_arp_data->port); - } - if (rte_timer_reset(ret_arp_data->timer, - (arp_timeout * - rte_get_tsc_hz()), SINGLE, - timer_lcore, - arp_timer_callback, - arg) < 0) - if (ARPICMP_DEBUG) - RTE_LOG(INFO, LIBARP, - "Err : Timer already running\n"); - - } - } else { - rte_hash_del_key(arp_hash_handle, &arp_key); - } - } + rte_timer_stop(ret_arp_data->timer); + rte_free(ret_arp_data->timer_key); + rte_free(ret_arp_data->buf_pkts); + ret_arp_data->buf_pkts = NULL; + if (ARPICMP_DEBUG) { + RTE_LOG(INFO, LIBARP, + "ARP Entry Deleted for IP :%d.%d.%d.%d , port %d\n", + (arp_key->ip >> 24), + ((arp_key->ip & 0x00ff0000) >> + 16), + ((arp_key->ip & 0x0000ff00) >> + 8), + ((arp_key->ip & 0x000000ff)), + arp_key->port_id); + } + rte_hash_del_key(arp_hash_handle, arp_key); + print_arp_table(); } /* ND IPv6 */ @@ -1097,11 +1111,51 @@ void remove_nd_entry_ipv6(uint8_t ipv6addr[], uint8_t portid) rte_hash_del_key(nd_hash_handle, &nd_key); } +int +arp_queue_unresolved_packet(struct arp_entry_data *ret_arp_data, struct rte_mbuf *pkt) +{ + if (ret_arp_data->num_pkts == NUM_DESC) { + return 0; + } + ret_arp_data->buf_pkts[ret_arp_data->num_pkts++] = pkt; + return 0; +} + +void +arp_send_buffered_pkts(struct arp_entry_data *ret_arp_data,struct ether_addr *hw_addr, uint8_t port_id) +{ + l2_phy_interface_t *port = ifm_get_port(port_id); + struct rte_mbuf *pkt, *tmp; + uint8_t *eth_dest, *eth_src; + int i; + + + if (!hw_addr || !ret_arp_data) + return; + + for (i=0;i<(int)ret_arp_data->num_pkts;i++) { + pkt = ret_arp_data->buf_pkts[i]; + eth_dest = RTE_MBUF_METADATA_UINT8_PTR(pkt, MBUF_HDR_ROOM); + eth_src = RTE_MBUF_METADATA_UINT8_PTR(pkt, MBUF_HDR_ROOM + 6); + + memcpy(eth_dest, &hw_addr, sizeof(struct ether_addr)); + memcpy(eth_src, get_link_hw_addr(port_id), + sizeof(struct ether_addr)); + port->transmit_single_pkt(port, pkt); + tmp = pkt; + rte_pktmbuf_free(tmp); + } + ret_arp_data->num_pkts = 0; + ret_arp_data->buffered_pkt_list_head = NULL; + +} + void populate_arp_entry(const struct ether_addr *hw_addr, uint32_t ipaddr, uint8_t portid, uint8_t mode) { struct arp_key_ipv4 arp_key; + struct arp_entry_data *new_arp_data; arp_key.port_id = portid; arp_key.ip = ipaddr; arp_key.filler1 = 0; @@ -1109,25 +1163,29 @@ populate_arp_entry(const struct ether_addr *hw_addr, uint32_t ipaddr, arp_key.filler3 = 0; lib_arp_populate_called++; + printf("populate_arp_entry ip %x, port %d\n", arp_key.ip, arp_key.port_id); if (ARPICMP_DEBUG) RTE_LOG(INFO, LIBARP, "populate_arp_entry ip %x, port %d\n", arp_key.ip, arp_key.port_id); - struct arp_entry_data *new_arp_data = retrieve_arp_entry(arp_key); + new_arp_data = retrieve_arp_entry(arp_key, mode); if (new_arp_data && ((new_arp_data->mode == STATIC_ARP - && mode == DYNAMIC_ARP) || (new_arp_data->mode == DYNAMIC_ARP - && mode == STATIC_ARP))) { - if (ARPICMP_DEBUG) - RTE_LOG(INFO, LIBARP,"populate_arp_entry: ARP entry already exists(%d %d)\n", - new_arp_data->mode, mode); + && mode == DYNAMIC_ARP) || (new_arp_data->mode == DYNAMIC_ARP + && mode == STATIC_ARP))) { + if (ARPICMP_DEBUG) + RTE_LOG(INFO, LIBARP,"populate_arp_entry: ARP entry already exists(%d %d)\n", + new_arp_data->mode, mode); - return; - } + return; + } if (mode == DYNAMIC_ARP) { + if (new_arp_data && is_same_ether_addr(&new_arp_data->eth_addr, hw_addr)) { + printf("entry exists\n"); + if (ARPICMP_DEBUG) { RTE_LOG(INFO, LIBARP, "arp_entry exists ip :%d.%d.%d.%d , port %d\n", @@ -1139,67 +1197,57 @@ populate_arp_entry(const struct ether_addr *hw_addr, uint32_t ipaddr, } lib_arp_duplicate_found++; new_arp_data->retry_count = 0; // Reset + if (new_arp_data->status == STALE) { + new_arp_data->status = PROBE; + if (ifm_chk_port_ipv4_enabled + (new_arp_data->port)) { + request_arp(new_arp_data->port, + new_arp_data->ip); + } else { + if (ARPICMP_DEBUG) + RTE_LOG(INFO, LIBARP, + "%s: IP is not enabled on port %u, not sending GARP\n\r", + __FUNCTION__, + new_arp_data->port); + } + } + if (rte_timer_reset(new_arp_data->timer, - (arp_timeout * rte_get_tsc_hz()), - SINGLE, timer_lcore, - arp_timer_callback, - new_arp_data->timer_key) < 0) + (arp_timeout * rte_get_tsc_hz()), + SINGLE, timer_lcore, + arp_timer_callback, + new_arp_data->timer_key) < 0) { if (ARPICMP_DEBUG) RTE_LOG(INFO, LIBARP, "Err : Timer already running\n"); + } return; - } - - uint32_t size = - RTE_CACHE_LINE_ROUNDUP(sizeof(struct arp_entry_data)); - new_arp_data = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE); - new_arp_data->eth_addr = *hw_addr; - new_arp_data->status = COMPLETE; - new_arp_data->port = portid; - new_arp_data->ip = ipaddr; - new_arp_data->mode = mode; - if (rte_mempool_get - (timer_mempool_arp, (void **)&(new_arp_data->timer)) < 0) { - RTE_LOG(INFO, LIBARP, - "TIMER - Error in getting timer alloc buffer\n"); + } else { + ether_addr_copy(hw_addr, &new_arp_data->eth_addr); + if ((new_arp_data->status == INCOMPLETE) || + (new_arp_data->status == PROBE)) { + new_arp_data->status = COMPLETE; + new_arp_data->mode = mode; + new_arp_data->n_confirmed = time(NULL); + //end_tsc[new_arp_data->port] = rte_rdtsc(); + //printf("confirmed val is %x %dms\n",new_arp_data->ip, (end_tsc[new_arp_data->port] - start_tsc[new_arp_data->port] + ticks_per_ms/2)/ticks_per_ms); + new_arp_data->retry_count = 0; + if (rte_timer_reset(new_arp_data->timer, + (arp_timeout * rte_get_tsc_hz()), + SINGLE, timer_lcore, + arp_timer_callback, + new_arp_data->timer_key) < 0) { + if (ARPICMP_DEBUG) + RTE_LOG(INFO, LIBARP, + "Err : Timer already running\n"); + } + } return; } - - rte_hash_add_key_data(arp_hash_handle, &arp_key, new_arp_data); - if (ARPICMP_DEBUG) { - RTE_LOG(INFO, LIBARP, - "arp_entry exists ip :%d.%d.%d.%d , port %d\n", - (arp_key.ip >> 24), - ((arp_key.ip & 0x00ff0000) >> 16), - ((arp_key.ip & 0x0000ff00) >> 8), - ((arp_key.ip & 0x000000ff)), arp_key.port_id); - } - // Call l3fwd module for resolving 2_adj structure. - resolve_l2_adj(ipaddr, portid, hw_addr); - - rte_timer_init(new_arp_data->timer); - struct arp_timer_key *callback_key = - (struct arp_timer_key *)rte_malloc(NULL, - sizeof(struct - arp_timer_key *), - RTE_CACHE_LINE_SIZE); - callback_key->port_id = portid; - callback_key->ip = ipaddr; - - if (ARPICMP_DEBUG) - RTE_LOG(INFO, LIBARP, "TIMER STARTED FOR %u seconds\n", - ARP_TIMER_EXPIRY); - if (rte_timer_reset - (new_arp_data->timer, (arp_timeout * rte_get_tsc_hz()), - SINGLE, timer_lcore, arp_timer_callback, callback_key) < 0) - if (ARPICMP_DEBUG) - RTE_LOG(INFO, LIBARP, - "Err : Timer already running\n"); - - new_arp_data->timer_key = callback_key; } else { if (new_arp_data - && is_same_ether_addr(&new_arp_data->eth_addr, hw_addr)) { + && is_same_ether_addr(&new_arp_data->eth_addr, hw_addr)) { + if (ARPICMP_DEBUG) { RTE_LOG(INFO, LIBARP, "arp_entry exists ip :%d.%d.%d.%d , port %d\n", @@ -1221,7 +1269,10 @@ populate_arp_entry(const struct ether_addr *hw_addr, uint32_t ipaddr, new_arp_data->port = portid; new_arp_data->ip = ipaddr; new_arp_data->mode = mode; - + new_arp_data->buffered_pkt_list_head = NULL; + new_arp_data->buffered_pkt_list_tail = NULL; + new_arp_data->num_pkts = 0; + rte_hash_add_key_data(arp_hash_handle, &arp_key, new_arp_data); if (ARPICMP_DEBUG) { @@ -1233,10 +1284,13 @@ populate_arp_entry(const struct ether_addr *hw_addr, uint32_t ipaddr, ((arp_key.ip & 0x000000ff)), arp_key.port_id); } + #ifdef L3_STACK_SUPPORT // Call l3fwd module for resolving 2_adj structure. resolve_l2_adj(ipaddr, portid, hw_addr); + #endif } } + if (ARPICMP_DEBUG) { /* print entire hash table */ RTE_LOG(INFO, LIBARP, @@ -1428,29 +1482,11 @@ void print_pkt1(struct rte_mbuf *pkt) RTE_LOG(INFO, LIBARP, "\nPacket Contents...\n"); for (i = 0; i < 20; i++) { for (j = 0; j < 20; j++) - RTE_LOG(INFO, LIBARP, "%02x ", rd[(20 * i) + j]); + printf("%02x ", rd[(20 * i) + j]); RTE_LOG(INFO, LIBARP, "\n"); } } -struct ether_addr broadcast_ether_addr = { - .addr_bytes[0] = 0xFF, - .addr_bytes[1] = 0xFF, - .addr_bytes[2] = 0xFF, - .addr_bytes[3] = 0xFF, - .addr_bytes[4] = 0xFF, - .addr_bytes[5] = 0xFF, -}; - -static const struct ether_addr null_ether_addr = { - .addr_bytes[0] = 0x00, - .addr_bytes[1] = 0x00, - .addr_bytes[2] = 0x00, - .addr_bytes[3] = 0x00, - .addr_bytes[4] = 0x00, - .addr_bytes[5] = 0x00, -}; - #define MAX_NUM_MAC_ADDRESS 16 struct ether_addr link_hw_addr[MAX_NUM_MAC_ADDRESS] = { {.addr_bytes = {0x90, 0xe2, 0xba, 0x54, 0x67, 0xc8} }, @@ -1473,7 +1509,7 @@ struct ether_addr link_hw_addr[MAX_NUM_MAC_ADDRESS] = { struct ether_addr *get_link_hw_addr(uint8_t out_port) { - return &link_hw_addr[out_port]; + return &p_arp_data->link_hw_addr[out_port]; } void request_arp(uint8_t port_id, uint32_t ip) @@ -1484,7 +1520,7 @@ void request_arp(uint8_t port_id, uint32_t ip) l2_phy_interface_t *link; link = ifm_get_port(port_id); - struct rte_mbuf *arp_pkt = lib_arp_pkt; + struct rte_mbuf *arp_pkt = lib_arp_pkt[port_id]; if (arp_pkt == NULL) { if (ARPICMP_DEBUG) @@ -1492,7 +1528,6 @@ void request_arp(uint8_t port_id, uint32_t ip) "Error allocating arp_pkt rte_mbuf\n"); return; } - eth_h = rte_pktmbuf_mtod(arp_pkt, struct ether_hdr *); ether_addr_copy(&broadcast_ether_addr, ð_h->d_addr); @@ -1507,12 +1542,12 @@ void request_arp(uint8_t port_id, uint32_t ip) arp_h->arp_pln = sizeof(uint32_t); arp_h->arp_op = CHECK_ENDIAN_16(ARP_OP_REQUEST); - ether_addr_copy((struct ether_addr *) - &link->macaddr[0], &arp_h->arp_data.arp_sha); if (link && link->ipv4_list) { arp_h->arp_data.arp_sip = (((ipv4list_t *) (link->ipv4_list))->ipaddr); } + ether_addr_copy((struct ether_addr *) + &link->macaddr[0], &arp_h->arp_data.arp_sha); ether_addr_copy(&null_ether_addr, &arp_h->arp_data.arp_tha); arp_h->arp_data.arp_tip = rte_cpu_to_be_32(ip); if (ARPICMP_DEBUG) @@ -1528,6 +1563,8 @@ void request_arp(uint8_t port_id, uint32_t ip) } if (link) link->transmit_single_pkt(link, arp_pkt); +// start_tsc[port_id] = rte_rdtsc(); + printf("Sent ARP Request %x \n", arp_h->arp_data.arp_tip); } struct rte_mbuf *request_echo(uint32_t port_id, uint32_t ip) @@ -1537,7 +1574,7 @@ struct rte_mbuf *request_echo(uint32_t port_id, uint32_t ip) struct icmp_hdr *icmp_h; l2_phy_interface_t *port = ifm_get_port(port_id); - struct rte_mbuf *icmp_pkt = lib_arp_pkt; + struct rte_mbuf *icmp_pkt = lib_arp_pkt[port_id]; if (icmp_pkt == NULL) { if (ARPICMP_DEBUG) RTE_LOG(INFO, LIBARP, @@ -1583,57 +1620,6 @@ struct rte_mbuf *request_echo(uint32_t port_id, uint32_t ip) return icmp_pkt; } -#if 0 -/** - * Function to send ICMP dest unreachable msg - * - */ -struct rte_mbuf *send_icmp_dest_unreachable_msg(uint32_t src_ip, - uint32_t dest_ip) -{ - struct ether_hdr *eth_h; - struct ipv4_hdr *ip_h; - struct icmp_hdr *icmp_h; - struct rte_mbuf *icmp_pkt = lib_arp_pkt; - - if (icmp_pkt == NULL) { - if (ARPICMP_DEBUG) - RTE_LOG(INFO, LIBARP, - "Error allocating icmp_pkt rte_mbuf\n"); - return NULL; - } - - eth_h = rte_pktmbuf_mtod(icmp_pkt, struct ether_hdr *); - ip_h = (struct ipv4_hdr *)((char *)eth_h + sizeof(struct ether_hdr)); - icmp_h = (struct icmp_hdr *)((char *)ip_h + sizeof(struct ipv4_hdr)); - - ip_h->version_ihl = IP_VHL_DEF; - ip_h->type_of_service = 0; - ip_h->total_length = - rte_cpu_to_be_16(sizeof(struct ipv4_hdr) + sizeof(struct icmp_hdr)); - ip_h->packet_id = 0xaabb; - ip_h->fragment_offset = 0x0000; - ip_h->time_to_live = 64; - ip_h->next_proto_id = 1; - - ip_h->dst_addr = rte_bswap32(dest_ip); - ip_h->src_addr = rte_bswap32(src_ip); - - ip_h->hdr_checksum = 0; - ip_h->hdr_checksum = rte_ipv4_cksum(ip_h); - - icmp_h->icmp_type = 3; /* Destination Unreachable */ - icmp_h->icmp_code = 13; /* Communication administratively prohibited */ - - icmp_h->icmp_cksum = ~rte_raw_cksum(icmp_h, sizeof(struct icmp_hdr)); - - icmp_pkt->pkt_len = sizeof(struct ether_hdr) + sizeof(struct ipv4_hdr) + - sizeof(struct icmp_hdr); - icmp_pkt->data_len = icmp_pkt->pkt_len; - - return icmp_pkt; -} -#endif void process_arpicmp_pkt_parse(struct rte_mbuf **pkt, uint16_t pkt_num, uint64_t pkt_mask, l2_phy_interface_t *port) @@ -1671,7 +1657,6 @@ void process_arpicmp_pkt(struct rte_mbuf *pkt, l2_phy_interface_t *port) uint32_t ip_addr; uint32_t req_tip; - eth_h = rte_pktmbuf_mtod(pkt, struct ether_hdr *); if (eth_h->ether_type == rte_cpu_to_be_16(ETHER_TYPE_ARP)) { @@ -1703,6 +1688,7 @@ void process_arpicmp_pkt(struct rte_mbuf *pkt, l2_phy_interface_t *port) if (arp_h->arp_data.arp_tip != ((ipv4list_t *) (port->ipv4_list))->ipaddr) { if (arp_h->arp_data.arp_tip == arp_h->arp_data.arp_sip) { + printf("gratuitous arp received\n"); populate_arp_entry( (struct ether_addr *)&arp_h->arp_data.arp_sha, rte_cpu_to_be_32(arp_h->arp_data.arp_sip), @@ -1731,7 +1717,6 @@ void process_arpicmp_pkt(struct rte_mbuf *pkt, l2_phy_interface_t *port) print_mbuf("RX", in_port_id, pkt, __LINE__); } - populate_arp_entry((struct ether_addr *) &arp_h->arp_data.arp_sha, rte_cpu_to_be_32 @@ -1750,7 +1735,6 @@ void process_arpicmp_pkt(struct rte_mbuf *pkt, l2_phy_interface_t *port) arp_h->arp_data.arp_sip = req_tip; ether_addr_copy(ð_h->d_addr, &arp_h->arp_data.arp_tha); - if (ARPICMP_DEBUG) print_mbuf("TX ARP REPLY PKT", port->pmdid, pkt, __LINE__); @@ -1758,7 +1742,8 @@ void process_arpicmp_pkt(struct rte_mbuf *pkt, l2_phy_interface_t *port) if (ARPICMP_DEBUG) print_mbuf("TX", port->pmdid, pkt, __LINE__); - + printf("replying arp pkt done\n"); + //rte_pktmbuf_free(pkt); return; } else if (arp_h->arp_op == rte_cpu_to_be_16(ARP_OP_REPLY)) { @@ -1774,6 +1759,7 @@ void process_arpicmp_pkt(struct rte_mbuf *pkt, l2_phy_interface_t *port) arp_data.arp_sip), in_port_id, DYNAMIC_ARP); + //rte_pktmbuf_free(pkt); return; } else { if (ARPICMP_DEBUG) @@ -1901,7 +1887,7 @@ void process_arpicmp_pkt(struct rte_mbuf *pkt, l2_phy_interface_t *port) arp_key.filler3 = 0; struct arp_entry_data *arp_entry = - retrieve_arp_entry(arp_key); + retrieve_arp_entry(arp_key, DYNAMIC_ARP); if (arp_entry == NULL) { if (ARPICMP_DEBUG) RTE_LOG(INFO, LIBARP, @@ -1917,6 +1903,7 @@ void process_arpicmp_pkt(struct rte_mbuf *pkt, l2_phy_interface_t *port) rte_pktmbuf_free(pkt); } + printf("reached end of process_arpicmp\n"); } /* int @@ -2175,6 +2162,10 @@ static int arp_parse_args(struct pipeline_params *params) continue; } + if (strcmp(arg_name, "arp_buf") == 0) { + arp_buffer = atoi(arg_value); + } + /* prv_to_pub_map */ if (strcmp(arg_name, "prv_to_pub_map") == 0) { if (prv_to_pub_map_present) { @@ -2291,11 +2282,9 @@ static int arp_parse_args(struct pipeline_params *params) } //Populate the static arp_route_table for (i = 0; i < MAC_NUM_BYTES; i++) - link_hw_addr - [link_hw_addr_array_idx].addr_bytes - [i] = byte[i]; + p_arp_data->link_hw_addr[p_arp_data->link_hw_addr_array_idx].addr_bytes[i] = byte[i]; - link_hw_addr_array_idx++; + p_arp_data->link_hw_addr_array_idx++; token = strtok(NULL, " "); } @@ -2373,15 +2362,15 @@ static int arp_parse_args(struct pipeline_params *params) } */ //Populate the static arp_route_table - lib_arp_route_table[arp_route_tbl_index].ip = - dest_ip; - lib_arp_route_table[arp_route_tbl_index].mask = - mask; - lib_arp_route_table[arp_route_tbl_index].port = - tx_port; - lib_arp_route_table[arp_route_tbl_index].nh = - nh_ip; - arp_route_tbl_index++; + struct lib_arp_route_table_entry *lentry = + &p_arp_data->lib_arp_route_table + [p_arp_data->lib_arp_route_ent_cnt]; + lentry->ip = dest_ip; + lentry->mask = mask; + lentry->port = tx_port; + lentry->nh = nh_ip; + lentry->nh_mask = nh_ip & mask; + p_arp_data->lib_arp_route_ent_cnt++; token = strtok(NULL, "("); } @@ -2481,12 +2470,50 @@ static int arp_parse_args(struct pipeline_params *params) return 0; } +static void local_arp_cache_init(void) +{ + int i, j, k; + for (i=0; i<MAX_PORTS;i++) { + for (j=0; j<MAX_LOCAL_MAC_ADDRESS;j++) { + p_arp_data->arp_local_cache[i].nhip[j] = 0; + for (k=0;k<6;k++) + p_arp_data->arp_local_cache[i].link_hw_laddr[j].addr_bytes[k] = 0; + p_arp_data->arp_local_cache[i].num_nhip = 0; + } + } +} + +struct ether_addr *get_local_link_hw_addr(uint8_t out_port, uint32_t nhip) +{ + int i, limit; + uint32_t tmp; + struct ether_addr *x = NULL; + limit = p_arp_data->arp_local_cache[out_port].num_nhip; + for (i=0; i < limit; i++) { + tmp = p_arp_data->arp_local_cache[out_port].nhip[i]; + if (tmp == nhip) { + x = &p_arp_data->arp_local_cache[out_port].link_hw_laddr[i]; + return x; + } + } + return x; +} + void lib_arp_init(struct pipeline_params *params, __rte_unused struct app_params *app) { + int i; + uint32_t size; + struct pipeline_cgnapt *p; + RTE_LOG(INFO, LIBARP, "ARP initialization ...\n"); + /* create arp data for table entries */ + size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct arp_data)); + p = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE); + p_arp_data = (struct arp_data *)p; + /* Parse arguments */ if (arp_parse_args(params)) { RTE_LOG(INFO, LIBARP, "arp_parse_args failed ...\n"); @@ -2504,9 +2531,20 @@ void lib_arp_init(struct pipeline_params *params, return; } - lib_arp_pkt = rte_pktmbuf_alloc(lib_arp_pktmbuf_tx_pool); - if (lib_arp_pkt == NULL) { - RTE_LOG(INFO, LIBARP, "ARP lib_arp_pkt alloc failed.\n"); + for (i=0; i<MAX_PORTS; i++) { + lib_arp_pkt[i] = rte_pktmbuf_alloc(lib_arp_pktmbuf_tx_pool); + if (lib_arp_pkt[i] == NULL) { + RTE_LOG(INFO, LIBARP, "ARP lib_arp_pkt alloc failed.\n"); + return; + } + } + /* create the arp_icmp mbuf rx pool */ + arp_icmp_pktmbuf_tx_pool = rte_pktmbuf_pool_create("arp_icmp_mbuf_tx_pool", + NB_ARPICMP_MBUF, 32, 0, + RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); + + if (arp_icmp_pktmbuf_tx_pool == NULL) { + RTE_LOG(INFO, LIBARP, "icmp_pktmbuf pool creation failed\n"); return; } @@ -2552,24 +2590,113 @@ void lib_arp_init(struct pipeline_params *params, (void *)nd_hash_handle); } + /* Initialize the local arp cache */ + local_arp_cache_init(); + return; } void arp_timer_callback(struct rte_timer *timer, void *arg) { - struct arp_timer_key *remove_key = (struct arp_timer_key *)arg; - if (ARPICMP_DEBUG) - RTE_LOG(INFO, LIBARP, "ARP TIMER callback : expire :%d\n", - (int)timer->expire); + struct arp_timer_key *timer_key = (struct arp_timer_key *)arg; + struct arp_key_ipv4 arp_key; + arp_key.port_id = timer_key->port_id; + arp_key.ip = timer_key->ip; + arp_key.filler1 = 0; + arp_key.filler2 = 0; + arp_key.filler3 = 0; + + struct arp_entry_data *ret_arp_data = NULL; + time_t now; + if (ARPICMP_DEBUG) { + RTE_LOG(INFO, LIBARP, "arp_timer_callback ip %x, port %d\n", + arp_key.ip, arp_key.port_id); + } + + int ret = rte_hash_lookup_data(arp_hash_handle, &arp_key, + (void **)&ret_arp_data); + now = time(NULL); + if (ARPICMP_DEBUG) - RTE_LOG(INFO, LIBARP, - "Remove ARP Entry for IP :%d.%d.%d.%d , port %d\n", - (remove_key->ip >> 24), - ((remove_key->ip & 0x00ff0000) >> 16), - ((remove_key->ip & 0x0000ff00) >> 8), - ((remove_key->ip & 0x000000ff)), remove_key->port_id); - remove_arp_entry((uint32_t) remove_key->ip, - (uint8_t) remove_key->port_id, arg); + RTE_LOG(INFO, LIBARP, "ARP TIMER callback : expire :%d now:%ld\n", + (int)timer->expire, now); + if (ret < 0) { + printf("Should not have come here\n"); + return; + } else { + if (ret_arp_data->mode == DYNAMIC_ARP) { + if (ret_arp_data->status == PROBE || + ret_arp_data->status == INCOMPLETE) { + if (ret_arp_data->retry_count == 3) { + remove_arp_entry(ret_arp_data, arg); + } else { + ret_arp_data->retry_count++; + + if (ARPICMP_DEBUG) { + RTE_LOG(INFO, LIBARP, + "RETRY ARP..retry count : %u\n", + ret_arp_data->retry_count); + + RTE_LOG(INFO, LIBARP, + "TIMER STARTED FOR %u seconds\n", + ARP_TIMER_EXPIRY); + } + + if (ifm_chk_port_ipv4_enabled + (ret_arp_data->port)) { + //printf("inside arp timer callback numpkts:%d\n", ret_arp_data->num_pkts); + request_arp(ret_arp_data->port, + ret_arp_data->ip); + } else { + if (ARPICMP_DEBUG) + RTE_LOG(INFO, LIBARP, + "%s: IP is not enabled on port %u, not sending GARP\n\r", + __FUNCTION__, + ret_arp_data->port); + } + + if (rte_timer_reset(ret_arp_data->timer, + (PROBE_TIME * + rte_get_tsc_hz()/ 1000), + SINGLE, + timer_lcore, + arp_timer_callback, + arg) < 0) + if (ARPICMP_DEBUG) + RTE_LOG(INFO, LIBARP, + "Err : Timer already running\n"); + + } + } else if (ret_arp_data->status == COMPLETE) { + if (now <= (ret_arp_data->n_confirmed + arp_timeout)) { + if (rte_timer_reset(ret_arp_data->timer, + (arp_timeout * + rte_get_tsc_hz()), SINGLE, + timer_lcore, + arp_timer_callback, + arg) < 0) + if (ARPICMP_DEBUG) + RTE_LOG(INFO, LIBARP, + "Err : Timer already running\n"); + } else if (now <= (ret_arp_data->n_last_update + USED_TIME)) { + if (rte_timer_reset(ret_arp_data->timer, + (arp_timeout * + rte_get_tsc_hz()), SINGLE, + timer_lcore, + arp_timer_callback, + arg) < 0) + if (ARPICMP_DEBUG) + RTE_LOG(INFO, LIBARP, + "Err : Timer already running\n"); + } else { + ret_arp_data->status = STALE; + p_arp_data->arp_cache_hw_laddr_valid[ret_arp_data->port] = 0; + } + } + } else { + rte_hash_del_key(arp_hash_handle, &arp_key); + } + } return; } @@ -2595,6 +2722,7 @@ void create_arp_table(void) STATIC_ARP); } print_arp_table(); + return; } @@ -2618,7 +2746,7 @@ void send_gratuitous_arp(l2_phy_interface_t *port) struct ether_hdr *eth_h; struct arp_hdr *arp_h; - struct rte_mbuf *arp_pkt = lib_arp_pkt; + struct rte_mbuf *arp_pkt = lib_arp_pkt[port->pmdid]; if (port == NULL) { RTE_LOG(INFO, LIBARP, "PORT ID DOWN.. %s\n", __FUNCTION__); diff --git a/common/VIL/l2l3_stack/lib_arp.h b/common/VIL/l2l3_stack/lib_arp.h index e2d38419..e7fcb421 100644 --- a/common/VIL/l2l3_stack/lib_arp.h +++ b/common/VIL/l2l3_stack/lib_arp.h @@ -24,11 +24,15 @@ #define ND_IPV6_ADDR_SIZE 16 /**< 16 Byte of IPv6 Address. */ #define ND_IPV6_TIMER_EXPIRY 300 /**< in Seconds, Timer for ND IPv6 Expiry */ -#define ARP_TIMER_EXPIRY 1800 /**< in Seconds, TIMER for ARP Expiry */ +#define ARP_TIMER_EXPIRY 20 /**< in Seconds, TIMER for ARP Expiry */ #define TIMER_MILLISECOND 1 #define RTE_LOGTYPE_LIBARP RTE_LOGTYPE_USER1 #define MAX_ND_RT_ENTRY 32 #define MAX_ARP_RT_ENTRY 32 +#define NUM_DESC (get_arp_buf()) +#define ARP_BUF_DEFAULT 30000 +#define PROBE_TIME 500 +#undef L3_STACK_SUPPORT /** * A structure for Route table entries of IPv4 @@ -39,6 +43,15 @@ struct lib_arp_route_table_entry { uint32_t mask; /**< mask */ uint32_t port; /**< Physical port */ uint32_t nh; /**< next hop */ + uint32_t nh_mask; +}; + +#define MAX_LOCAL_MAC_ADDRESS 32 +#define MAX_PORTS 32 +struct arp_cache { + uint32_t nhip[MAX_LOCAL_MAC_ADDRESS]; + struct ether_addr link_hw_laddr[MAX_LOCAL_MAC_ADDRESS]; + uint32_t num_nhip; }; /** @@ -52,8 +65,28 @@ struct lib_nd_route_table_entry { uint8_t nhipv6[16]; /**< next hop Ipv6 */ }; +struct arp_data { + struct lib_arp_route_table_entry + lib_arp_route_table[MAX_ARP_RT_ENTRY]; + uint8_t lib_arp_route_ent_cnt; + struct lib_nd_route_table_entry + lib_nd_route_table[MAX_ARP_RT_ENTRY]; + uint8_t lib_nd_route_ent_cnt; + struct arp_cache arp_local_cache[MAX_PORTS]; + struct ether_addr link_hw_addr[MAX_LOCAL_MAC_ADDRESS]; + uint32_t link_hw_addr_array_idx; + uint8_t arp_cache_hw_laddr_valid[MAX_LOCAL_MAC_ADDRESS]; +} __rte_cache_aligned; + +uint8_t arp_cache_dest_mac_present(uint32_t out_port); + extern struct lib_nd_route_table_entry lib_nd_route_table[MAX_ND_RT_ENTRY]; extern struct lib_arp_route_table_entry lib_arp_route_table[MAX_ARP_RT_ENTRY]; +extern struct ether_addr *get_local_link_hw_addr(uint8_t out_port, uint32_t nhip); +extern struct arp_cache arp_local_cache[MAX_PORTS]; +extern void prefetch(void); +extern struct arp_entry_data *arp_data_ptr[16]; +uint32_t get_arp_buf(void); enum { ARP_FOUND, @@ -116,8 +149,15 @@ struct arp_timer_key { extern uint32_t ARPICMP_DEBUG; -#define COMPLETE 1 /**< ARP entry populated and echo reply recieved. */ -#define INCOMPLETE 0 /**< ARP entry populated and either awaiting echo reply or stale entry. */ +enum { + INCOMPLETE, + COMPLETE, + PROBE, + STALE +}; +#define USED_TIME 5 +//#define COMPLETE 1 /**< ARP entry populated and echo reply recieved. */ +//#define INCOMPLETE 0 /**< ARP entry populated and either awaiting echo reply or stale entry. */ extern uint32_t NDIPV6_DEBUG; /**< ND IPv6 */ @@ -142,6 +182,14 @@ struct arp_entry_data { uint8_t retry_count; /**< retry count for ARP*/ struct rte_timer *timer; /**< Timer Associated with ARP*/ struct arp_timer_key *timer_key; + struct rte_ring *queue; /** pkts queued */ + rte_rwlock_t queue_lock; /** queue lock */ + struct rte_mbuf **buf_pkts; + struct rte_mbuf *buffered_pkt_list_head; + struct rte_mbuf *buffered_pkt_list_tail; + uint32_t num_pkts; + uint32_t n_confirmed; + uint32_t n_last_update; } __attribute__ ((packed)); /** @@ -198,8 +246,7 @@ struct table_nd_entry_data { * 0 if failure, and 1 if success */ -int get_dest_mac_address(const uint32_t ipaddr, uint32_t *phy_port, - struct ether_addr *hw_addr, uint32_t *nhip); +struct arp_entry_data *get_dest_mac_address(const uint32_t ipaddr, uint32_t *phy_port, struct ether_addr *hw_addr, uint32_t *nhip); /** * To get the destination MAC address andnext hop for the ip address and outgoing port * @param1 ip addr @@ -213,7 +260,7 @@ int get_dest_mac_address(const uint32_t ipaddr, uint32_t *phy_port, * @return * 0 if failure, and 1 if success */ -int get_dest_mac_addr_port(const uint32_t ipaddr, +struct arp_entry_data *get_dest_mac_addr_port(const uint32_t ipaddr, uint32_t *phy_port, struct ether_addr *hw_addr); /** @@ -262,6 +309,9 @@ int get_dest_mac_address_ipv6(uint8_t ipv6addr[], uint32_t *phy_port, int get_dest_mac_address_ipv6_port(uint8_t ipv6addr[], uint32_t *phy_port, struct ether_addr *hw_addr, uint8_t nhipv6[]); +int arp_queue_unresolved_packet(struct arp_entry_data * arp_data, + struct rte_mbuf * m); +extern void arp_send_buffered_pkts(struct arp_entry_data *ret_arp_data,struct ether_addr *hw_addr, uint8_t port_id); /** * To get hardware link address @@ -292,7 +342,7 @@ void print_nd_table(void); * @param portid * Port id */ -void remove_arp_entry(uint32_t ipaddr, uint8_t portid, void *arg); +void remove_arp_entry(struct arp_entry_data *ret_arp_data, void *arg); /** * Removes ND entry from Nd Table @@ -387,7 +437,7 @@ void process_arpicmp_pkt(struct rte_mbuf *pkt, l2_phy_interface_t *port); * @Param arp_key * Arp key to validate entry */ -struct arp_entry_data *retrieve_arp_entry(const struct arp_key_ipv4 arp_key); +struct arp_entry_data *retrieve_arp_entry(const struct arp_key_ipv4 arp_key, uint8_t mode); /** * ND IPv6 @@ -492,7 +542,7 @@ void set_arptimeout(uint32_t timeout_val); * @Param * timeout_val to set */ -uint32_t get_nh(uint32_t, uint32_t *); +uint32_t get_nh(uint32_t, uint32_t *, struct ether_addr *addr); /** * To get nexthop for ipv6 * @Param ipv6 diff --git a/common/VIL/pipeline_arpicmp/pipeline_arpicmp.c b/common/VIL/pipeline_arpicmp/pipeline_arpicmp.c index 1ea9e749..43e0be2d 100644 --- a/common/VIL/pipeline_arpicmp/pipeline_arpicmp.c +++ b/common/VIL/pipeline_arpicmp/pipeline_arpicmp.c @@ -92,9 +92,7 @@ cmd_arp_add_parsed(void *parsed_result, rte_cpu_to_be_32(params->ip.addr. ipv4.s_addr), params->port_id - #ifndef VNF_ACL , STATIC_ARP - #endif ); } else { memcpy(ipv6, params->ip.addr.ipv6.s6_addr, 16); @@ -167,13 +165,17 @@ cmd_arp_del_parsed(void *parsed_result, remove_arp_entry(rte_bswap32(req->key.key.ipv4.ip), req->key.key.ipv4.port_id); #endif + struct arp_key_ipv4 arp_key; + arp_key.port_id = params->port_id; + arp_key.ip = rte_cpu_to_be_32(params->ip.addr.ipv4.s_addr); + arp_key.filler1 = 0; + arp_key.filler2 = 0; + arp_key.filler3 = 0; + + struct arp_entry_data *new_arp_data = retrieve_arp_entry(arp_key, STATIC_ARP); + if (params->ip.family == AF_INET) { - remove_arp_entry(rte_cpu_to_be_32(params->ip.addr.ipv4.s_addr), - params->port_id - #ifndef VNF_ACL - , NULL - #endif - ); + remove_arp_entry(new_arp_data, &arp_key); } else { memcpy(ipv6, params->ip.addr.ipv6.s6_addr, 16); remove_nd_entry_ipv6(ipv6, params->port_id); @@ -235,7 +237,7 @@ cmd_arp_req_parsed(void *parsed_result, key.filler2 = 0; key.filler3 = 0; - struct arp_entry_data *arp_data = retrieve_arp_entry(key); + struct arp_entry_data *arp_data = retrieve_arp_entry(key, STATIC_ARP); if (arp_data) { if (ARPICMP_DEBUG) @@ -318,22 +320,24 @@ struct cmd_arp_ls_result { cmdline_fixed_string_t p_string; uint32_t p; cmdline_fixed_string_t arp_string; + uint32_t ip_type; }; static void cmd_arp_ls_parsed(__rte_unused void *parsed_result, __rte_unused struct cmdline *cl, __rte_unused void *data) { - printf("\nARP table ...\n"); - printf("-------------\n"); - print_arp_table(); - - printf - ("............................................................\n"); + struct cmd_arp_ls_result *params = parsed_result; - printf("\nND IPv6 table:\n"); - printf("--------------\n"); - print_nd_table(); + if (!params->ip_type) { + printf("\nARP table ...\n"); + printf("-------------\n"); + print_arp_table(); + } else { + printf("\nND IPv6 table:\n"); + printf("--------------\n"); + print_nd_table(); + } } static cmdline_parse_token_string_t cmd_arp_ls_p_string = @@ -347,6 +351,9 @@ static cmdline_parse_token_string_t cmd_arp_ls_arp_string = TOKEN_STRING_INITIALIZER(struct cmd_arp_ls_result, arp_string, "arpls"); +static cmdline_parse_token_num_t cmd_arp_ls_ip_type = +TOKEN_NUM_INITIALIZER(struct cmd_arp_ls_result, ip_type, UINT32); + static cmdline_parse_inst_t cmd_arp_ls = { .f = cmd_arp_ls_parsed, .data = NULL, @@ -355,6 +362,7 @@ static cmdline_parse_inst_t cmd_arp_ls = { (void *)&cmd_arp_ls_p_string, (void *)&cmd_arp_ls_p, (void *)&cmd_arp_ls_arp_string, + (void *)&cmd_arp_ls_ip_type, NULL, }, }; diff --git a/common/VIL/pipeline_arpicmp/pipeline_arpicmp_be.c b/common/VIL/pipeline_arpicmp/pipeline_arpicmp_be.c index 4ec544db..1dbf34a3 100644 --- a/common/VIL/pipeline_arpicmp/pipeline_arpicmp_be.c +++ b/common/VIL/pipeline_arpicmp/pipeline_arpicmp_be.c @@ -47,107 +47,16 @@ #include "app.h" #include"pipeline_common_fe.h" -#ifndef VNF_ACL #include "lib_arp.h" #include "lib_icmpv6.h" #include "interface.h" -#endif - -#ifdef VNF_ACL - -#define NB_ARPICMP_MBUF 64 -#define NB_NDICMP_MBUF 64 -#define IP_VERSION_4 0x40 -/* default IP header length == five 32-bits words. */ -#define IP_HDRLEN 0x05 -#define IP_VHL_DEF (IP_VERSION_4 | IP_HDRLEN) - -#define is_multicast_ipv4_addr(ipv4_addr) \ - (((rte_be_to_cpu_32((ipv4_addr)) >> 24) & 0x000000FF) == 0xE0) - - -/*ND IPV6 */ -#define INADDRSZ 4 -#define IN6ADDRSZ 16 -static int my_inet_pton_ipv6(int af, const char *src, void *dst); -static int inet_pton_ipv6(const char *src, unsigned char *dst); -static int inet_pton_ipv4(const char *src, unsigned char *dst); - -uint8_t vnf_common_arp_lib_init; -uint8_t vnf_common_nd_lib_init; -uint8_t loadb_pipeline_count; - -uint32_t ARPICMP_DEBUG; -uint32_t NDIPV6_DEBUG; - -uint32_t arp_route_tbl_index; -uint32_t nd_route_tbl_index; -uint32_t link_hw_addr_array_idx; - -uint32_t lib_arp_get_mac_req; -uint32_t lib_arp_nh_found; -uint32_t lib_arp_no_nh_found; -uint32_t lib_arp_arp_entry_found; -uint32_t lib_arp_no_arp_entry_found; -uint32_t lib_arp_populate_called; -uint32_t lib_arp_delete_called; -uint32_t lib_arp_duplicate_found; - -uint32_t lib_nd_get_mac_req; -uint32_t lib_nd_nh_found; -uint32_t lib_nd_no_nh_found; -uint32_t lib_nd_nd_entry_found; -uint32_t lib_nd_no_arp_entry_found; -uint32_t lib_nd_populate_called; -uint32_t lib_nd_delete_called; -uint32_t lib_nd_duplicate_found; - -struct rte_mempool *lib_arp_pktmbuf_tx_pool; -struct rte_mempool *lib_nd_pktmbuf_tx_pool; - -struct rte_mbuf *lib_arp_pkt; -struct rte_mbuf *lib_nd_pkt; - -static struct rte_hash_parameters arp_hash_params = { - .name = "ARP", - .entries = 64, - .reserved = 0, - .key_len = sizeof(struct arp_key_ipv4), - .hash_func = rte_jhash, - .hash_func_init_val = 0, -}; - -static struct rte_hash_parameters nd_hash_params = { - .name = "ND", - .entries = 64, - .reserved = 0, - .key_len = sizeof(struct nd_key_ipv6), - .hash_func = rte_jhash, - .hash_func_init_val = 0, -}; - -struct rte_hash *arp_hash_handle; -struct rte_hash *nd_hash_handle; -#endif /* Shared among all VNFs including LB */ struct app_params *myApp; struct rte_pipeline *myP; struct pipeline_arpicmp *gp_arp; uint8_t num_vnf_threads; -#ifdef VNF_ACL - -struct arp_port_address { - uint32_t ip; - uint64_t mac_addr; -}; - -struct arp_port_address arp_port_addresses[RTE_MAX_ETHPORTS]; - -uint16_t arp_meta_offset; -#endif - struct pipeline_arpicmp { struct pipeline p; pipeline_msg_req_handler @@ -160,118 +69,6 @@ struct pipeline_arpicmp { uint8_t pipeline_num; } __rte_cache_aligned; -#ifdef VNF_ACL - -#define MAX_NUM_ARP_ENTRIES 64 -#define MAX_NUM_ND_ENTRIES 64 - - -struct lib_nd_route_table_entry lib_nd_route_table[MAX_ND_RT_ENTRY] = { - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} } -}; - -struct lib_arp_route_table_entry lib_arp_route_table[MAX_ARP_RT_ENTRY] = { -// {0xac102814, 1, 0xac102814}, -// {0xac106414, 0, 0xac106414}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0} -}; - -#endif - void pipelines_port_info(void) { struct app_params *app = myApp; @@ -648,1727 +445,6 @@ void set_phy_inport_id(uint8_t pipeline_num, struct pipeline *p, uint8_t *map) } } -#ifdef VNF_ACL - -uint32_t get_nh(uint32_t ip, uint32_t *port) -{ - int i = 0; - for (i = 0; i < MAX_ARP_RT_ENTRY; i++) { - if (((lib_arp_route_table[i]. - ip & lib_arp_route_table[i].mask) == - (ip & lib_arp_route_table[i].mask))) { - - *port = lib_arp_route_table[i].port; - lib_arp_nh_found++; - return lib_arp_route_table[i].nh; - } - if (ARPICMP_DEBUG > 1) - printf("No nh match ip 0x%x, port %u, t_ip " - "0x%x, t_port %u, mask 0x%x, r1 %x, r2 %x\n", - ip, *port, lib_arp_route_table[i].ip, - lib_arp_route_table[i].port, - lib_arp_route_table[i].mask, - (lib_arp_route_table[i].ip & - lib_arp_route_table[i].mask), - (ip & lib_arp_route_table[i].mask)); - } - if (ARPICMP_DEBUG && ip) - printf("No NH - ip 0x%x, port %u\n", ip, *port); - lib_arp_no_nh_found++; - return 0; -} - -/*ND IPv6 */ -void get_nh_ipv6(uint8_t ipv6[], uint32_t *port, uint8_t nhipv6[]) -{ - int i = 0; - uint8_t netmask_ipv6[16], netip_nd[16], netip_in[16]; - uint8_t k = 0, l = 0, depthflags = 0, depthflags1 = 0; - memset(netmask_ipv6, 0, sizeof(netmask_ipv6)); - memset(netip_nd, 0, sizeof(netip_nd)); - memset(netip_in, 0, sizeof(netip_in)); - if (!ipv6) - return; - for (i = 0; i < MAX_ARP_RT_ENTRY; i++) { - - convert_prefixlen_to_netmask_ipv6( - lib_nd_route_table[i].depth, - netmask_ipv6); - - for (k = 0; k < 16; k++) { - if (lib_nd_route_table[i].ipv6[k] & netmask_ipv6[k]) { - depthflags++; - netip_nd[k] = lib_nd_route_table[i].ipv6[k]; - } - } - - for (l = 0; l < 16; l++) { - if (ipv6[l] & netmask_ipv6[l]) { - depthflags1++; - netip_in[l] = ipv6[l]; - } - } - int j = 0; - if ((depthflags == depthflags1) - && (memcmp(netip_nd, netip_in, - sizeof(netip_nd)) == 0)) { - //&& (lib_nd_route_table[i].port == port)) - *port = lib_nd_route_table[i].port; - lib_nd_nh_found++; - - for (j = 0; j < 16; j++) - nhipv6[j] = lib_nd_route_table[i].nhipv6[j]; - - return; - } - - if (NDIPV6_DEBUG > 1) - printf("No nh match\n"); - depthflags = 0; - depthflags1 = 0; - } - if (NDIPV6_DEBUG && ipv6) - printf("No NH - ip 0x%x, port %u\n", ipv6[0], *port); - lib_nd_no_nh_found++; -} - -/* Added for Multiport changes*/ -int get_dest_mac_addr_port(const uint32_t ipaddr, - uint32_t *phy_port, struct ether_addr *hw_addr) -{ - lib_arp_get_mac_req++; - uint32_t nhip = 0; - - nhip = get_nh(ipaddr, phy_port); - if (nhip == 0) { - if (ARPICMP_DEBUG && ipaddr) - printf("ARPICMP no nh found for ip %x, port %d\n", - ipaddr, *phy_port); - //return 0; - return NH_NOT_FOUND; - } - - struct arp_entry_data *ret_arp_data = NULL; - struct arp_key_ipv4 tmp_arp_key; - tmp_arp_key.port_id = *phy_port;/* Changed for Multi Port*/ - tmp_arp_key.ip = nhip; - - ret_arp_data = retrieve_arp_entry(tmp_arp_key); - if (ret_arp_data == NULL) { - if (ARPICMP_DEBUG && ipaddr) { - printf - ("ARPICMP no arp entry found for ip %x, port %d\n", - ipaddr, *phy_port); - print_arp_table(); - } - lib_arp_no_arp_entry_found++; - return ARP_NOT_FOUND; - } - ether_addr_copy(&ret_arp_data->eth_addr, hw_addr); - lib_arp_arp_entry_found++; - return ARP_FOUND; -} - -/*ND IPv6 */ -int get_dest_mac_address_ipv6(uint8_t ipv6addr[], uint32_t phy_port, - struct ether_addr *hw_addr, uint8_t nhipv6[]) -{ - int i = 0, j = 0, flag = 0; - lib_nd_get_mac_req++; - - if (ipv6addr) - get_nh_ipv6(ipv6addr, &phy_port, nhipv6); - for (j = 0; j < 16; j++) { - if (nhipv6[j]) - flag++; - } - if (flag == 0) { - if (ipv6addr) { - if (NDIPV6_DEBUG && ipv6addr) - printf("NDIPV6 no nh found for ipv6 " - "%02x%02x%02x%02x%02x%02x%02x%02x%02x" - "%02x%02x%02x%02x%02x%02x%02x, port %d\n", - ipv6addr[0], ipv6addr[1], ipv6addr[2], ipv6addr[3], - ipv6addr[4], ipv6addr[5], ipv6addr[6], ipv6addr[7], - ipv6addr[8], ipv6addr[9], ipv6addr[10], - ipv6addr[11], ipv6addr[12], ipv6addr[13], - ipv6addr[14], ipv6addr[15], phy_port); - return 0; - } - } - - struct nd_entry_data *ret_nd_data = NULL; - struct nd_key_ipv6 tmp_nd_key; - tmp_nd_key.port_id = phy_port; - - for (i = 0; i < 16; i++) - tmp_nd_key.ipv6[i] = nhipv6[i]; - - ret_nd_data = retrieve_nd_entry(tmp_nd_key); - if (ret_nd_data == NULL) { - if (NDIPV6_DEBUG && ipv6addr) { - printf("NDIPV6 no nd entry found for ip %x, port %d\n", - ipv6addr[0], phy_port); - } - lib_nd_no_arp_entry_found++; - return 0; - } - ether_addr_copy(&ret_nd_data->eth_addr, hw_addr); - lib_nd_nd_entry_found++; - return 1; - -} - -/*ND IPv6 */ -int get_dest_mac_address_ipv6_port(uint8_t ipv6addr[], uint32_t *phy_port, - struct ether_addr *hw_addr, uint8_t nhipv6[]) -{ - int i = 0, j = 0, flag = 0; - lib_nd_get_mac_req++; - - get_nh_ipv6(ipv6addr, phy_port, nhipv6); - for (j = 0; j < 16; j++) { - if (nhipv6[j]) - flag++; - } - if (flag == 0) { - if (NDIPV6_DEBUG && ipv6addr) - printf("NDIPV6 no nh found for ipv6 " - "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" - "%02x%02x%02x%02x%02x%02x, port %d\n", - ipv6addr[0], ipv6addr[1], ipv6addr[2], ipv6addr[3], - ipv6addr[4], ipv6addr[5], ipv6addr[6], ipv6addr[7], - ipv6addr[8], ipv6addr[9], ipv6addr[10], - ipv6addr[11], ipv6addr[12], ipv6addr[13], - ipv6addr[14], ipv6addr[15], *phy_port); - return 0; - } - - struct nd_entry_data *ret_nd_data = NULL; - struct nd_key_ipv6 tmp_nd_key; - tmp_nd_key.port_id = *phy_port; - - for (i = 0; i < 16; i++) - tmp_nd_key.ipv6[i] = nhipv6[i]; - - ret_nd_data = retrieve_nd_entry(tmp_nd_key); - if (ret_nd_data == NULL) { - if (NDIPV6_DEBUG && ipv6addr) { - printf("NDIPV6 no nd entry found for ip %x, port %d\n", - ipv6addr[0], *phy_port); - } - lib_nd_no_arp_entry_found++; - return 0; - } - ether_addr_copy(&ret_nd_data->eth_addr, hw_addr); - lib_nd_nd_entry_found++; - return 1; - -} - -/* - * ARP table - */ -struct lib_arp_arp_table_entry { - struct rte_pipeline_table_entry head; - uint64_t macaddr; -}; - -static const char *arp_op_name(uint16_t arp_op) -{ - switch (CHECK_ENDIAN_16(arp_op)) { - case (ARP_OP_REQUEST): - return "ARP Request"; - case (ARP_OP_REPLY): - return "ARP Reply"; - case (ARP_OP_REVREQUEST): - return "Reverse ARP Request"; - case (ARP_OP_REVREPLY): - return "Reverse ARP Reply"; - case (ARP_OP_INVREQUEST): - return "Peer Identify Request"; - case (ARP_OP_INVREPLY): - return "Peer Identify Reply"; - default: - break; - } - return "Unkwown ARP op"; -} - -static void print_icmp_packet(struct icmp_hdr *icmp_h) -{ - printf(" ICMP: type=%d (%s) code=%d id=%d seqnum=%d\n", - icmp_h->icmp_type, - (icmp_h->icmp_type == IP_ICMP_ECHO_REPLY ? "Reply" : - (icmp_h->icmp_type == - IP_ICMP_ECHO_REQUEST ? "Reqest" : "Undef")), icmp_h->icmp_code, - CHECK_ENDIAN_16(icmp_h->icmp_ident), - CHECK_ENDIAN_16(icmp_h->icmp_seq_nb)); -} - -static void print_ipv4_h(struct ipv4_hdr *ip_h) -{ - struct icmp_hdr *icmp_h = - (struct icmp_hdr *)((char *)ip_h + sizeof(struct ipv4_hdr)); - printf(" IPv4: Version=%d HLEN=%d Type=%d Length=%d\n", - (ip_h->version_ihl & 0xf0) >> 4, (ip_h->version_ihl & 0x0f), - ip_h->type_of_service, rte_cpu_to_be_16(ip_h->total_length)); - if (ip_h->next_proto_id == IPPROTO_ICMP) - print_icmp_packet(icmp_h); -} - -static void print_arp_packet(struct arp_hdr *arp_h) -{ - printf(" ARP: hrd=%d proto=0x%04x hln=%d " - "pln=%d op=%u (%s)\n", - CHECK_ENDIAN_16(arp_h->arp_hrd), - CHECK_ENDIAN_16(arp_h->arp_pro), arp_h->arp_hln, - arp_h->arp_pln, CHECK_ENDIAN_16(arp_h->arp_op), - arp_op_name(arp_h->arp_op)); - - if (CHECK_ENDIAN_16(arp_h->arp_hrd) != ARP_HRD_ETHER) { - printf("incorrect arp_hrd format for IPv4 ARP (%d)\n", - (arp_h->arp_hrd)); - } else if (CHECK_ENDIAN_16(arp_h->arp_pro) != ETHER_TYPE_IPv4) { - printf("incorrect arp_pro format for IPv4 ARP (%d)\n", - (arp_h->arp_pro)); - } else if (arp_h->arp_hln != 6) { - printf("incorrect arp_hln format for IPv4 ARP (%d)\n", - arp_h->arp_hln); - } else if (arp_h->arp_pln != 4) { - printf("incorrect arp_pln format for IPv4 ARP (%d)\n", - arp_h->arp_pln); - } else { - // print remainder of ARP request - printf(" sha=%02X:%02X:%02X:%02X:%02X:%02X", - arp_h->arp_data.arp_sha.addr_bytes[0], - arp_h->arp_data.arp_sha.addr_bytes[1], - arp_h->arp_data.arp_sha.addr_bytes[2], - arp_h->arp_data.arp_sha.addr_bytes[3], - arp_h->arp_data.arp_sha.addr_bytes[4], - arp_h->arp_data.arp_sha.addr_bytes[5]); - printf(" sip=%d.%d.%d.%d\n", - (CHECK_ENDIAN_32(arp_h->arp_data.arp_sip) >> 24) & 0xFF, - (CHECK_ENDIAN_32(arp_h->arp_data.arp_sip) >> 16) & 0xFF, - (CHECK_ENDIAN_32(arp_h->arp_data.arp_sip) >> 8) & 0xFF, - CHECK_ENDIAN_32(arp_h->arp_data.arp_sip) & 0xFF); - printf(" tha=%02X:%02X:%02X:%02X:%02X:%02X", - arp_h->arp_data.arp_tha.addr_bytes[0], - arp_h->arp_data.arp_tha.addr_bytes[1], - arp_h->arp_data.arp_tha.addr_bytes[2], - arp_h->arp_data.arp_tha.addr_bytes[3], - arp_h->arp_data.arp_tha.addr_bytes[4], - arp_h->arp_data.arp_tha.addr_bytes[5]); - printf(" tip=%d.%d.%d.%d\n", - (CHECK_ENDIAN_32(arp_h->arp_data.arp_tip) >> 24) & 0xFF, - (CHECK_ENDIAN_32(arp_h->arp_data.arp_tip) >> 16) & 0xFF, - (CHECK_ENDIAN_32(arp_h->arp_data.arp_tip) >> 8) & 0xFF, - CHECK_ENDIAN_32(arp_h->arp_data.arp_tip) & 0xFF); - } -} - -static void print_eth(struct ether_hdr *eth_h) -{ - printf(" ETH: src=%02X:%02X:%02X:%02X:%02X:%02X", - eth_h->s_addr.addr_bytes[0], - eth_h->s_addr.addr_bytes[1], - eth_h->s_addr.addr_bytes[2], - eth_h->s_addr.addr_bytes[3], - eth_h->s_addr.addr_bytes[4], eth_h->s_addr.addr_bytes[5]); - printf(" dst=%02X:%02X:%02X:%02X:%02X:%02X\n", - eth_h->d_addr.addr_bytes[0], - eth_h->d_addr.addr_bytes[1], - eth_h->d_addr.addr_bytes[2], - eth_h->d_addr.addr_bytes[3], - eth_h->d_addr.addr_bytes[4], eth_h->d_addr.addr_bytes[5]); - -} - -static void -print_mbuf(const char *rx_tx, unsigned int portid, struct rte_mbuf *mbuf, - unsigned int line) -{ - struct ether_hdr *eth_h = rte_pktmbuf_mtod(mbuf, struct ether_hdr *); - struct arp_hdr *arp_h = - (struct arp_hdr *)((char *)eth_h + sizeof(struct ether_hdr)); - struct ipv4_hdr *ipv4_h = - (struct ipv4_hdr *)((char *)eth_h + sizeof(struct ether_hdr)); - - printf("%s(%d): on port %d pkt-len=%u nb-segs=%u\n", - rx_tx, line, portid, mbuf->pkt_len, mbuf->nb_segs); - print_eth(eth_h); - switch (rte_cpu_to_be_16(eth_h->ether_type)) { - case ETHER_TYPE_IPv4: - print_ipv4_h(ipv4_h); - break; - case ETHER_TYPE_ARP: - print_arp_packet(arp_h); - break; - default: - printf(" unknown packet type\n"); - break; - } - fflush(stdout); -} - -struct arp_entry_data *retrieve_arp_entry(struct arp_key_ipv4 arp_key) -{ - struct arp_entry_data *ret_arp_data = NULL; - arp_key.filler1 = 0; - arp_key.filler2 = 0; - arp_key.filler3 = 0; - - int ret = rte_hash_lookup_data(arp_hash_handle, &arp_key, - (void **)&ret_arp_data); - if (ret < 0) { - if (ARPICMP_DEBUG) - printf("arp-hash lookup failed ret %d, " - "EINVAL %d, ENOENT %d\n", - ret, EINVAL, ENOENT); - } else { - return ret_arp_data; - } - - return NULL; -} - -/* -* ND IPv6 -* Validate if key-value pair already exists in the hash table -* for given key - ND IPv6 -* -*/ -struct nd_entry_data *retrieve_nd_entry(struct nd_key_ipv6 nd_key) -{ - struct nd_entry_data *ret_nd_data = NULL; - nd_key.filler1 = 0; - nd_key.filler2 = 0; - nd_key.filler3 = 0; - - /*Find a nd IPv6 key-data pair in the hash table for ND IPv6 */ - int ret = rte_hash_lookup_data(nd_hash_handle, &nd_key, - (void **)&ret_nd_data); - if (ret < 0) { - if (NDIPV6_DEBUG) - printf("nd-hash: no lookup Entry Found - " - "ret %d, EINVAL %d, ENOENT %d\n", - ret, EINVAL, ENOENT); - } else { - return ret_nd_data; - } - - return NULL; -} - -void print_arp_table(void) -{ - const void *next_key; - void *next_data; - uint32_t iter = 0; - - printf("\tport hw addr status ip addr\n"); - - while (rte_hash_iterate(arp_hash_handle, &next_key, &next_data, &iter) - >= 0) { - - struct arp_entry_data *tmp_arp_data = - (struct arp_entry_data *)next_data; - struct arp_key_ipv4 tmp_arp_key; - memcpy(&tmp_arp_key, next_key, sizeof(struct arp_key_ipv4)); - printf - ("\t%4d %02X:%02X:%02X:%02X:%02X:%02X %10s %d.%d.%d.%d\n", - tmp_arp_data->port, tmp_arp_data->eth_addr.addr_bytes[0], - tmp_arp_data->eth_addr.addr_bytes[1], - tmp_arp_data->eth_addr.addr_bytes[2], - tmp_arp_data->eth_addr.addr_bytes[3], - tmp_arp_data->eth_addr.addr_bytes[4], - tmp_arp_data->eth_addr.addr_bytes[5], - tmp_arp_data->status == - COMPLETE ? "COMPLETE" : "INCOMPLETE", - (tmp_arp_data->ip >> 24), - ((tmp_arp_data->ip & 0x00ff0000) >> 16), - ((tmp_arp_data->ip & 0x0000ff00) >> 8), - ((tmp_arp_data->ip & 0x000000ff))); - } - - uint32_t i = 0; - printf("\nARP routing table has %d entries\n", arp_route_tbl_index); - printf("\nIP_Address Mask Port NH_IP_Address\n"); - for (i = 0; i < arp_route_tbl_index; i++) { - printf("0x%x 0x%x %d 0x%x\n", - lib_arp_route_table[i].ip, - lib_arp_route_table[i].mask, - lib_arp_route_table[i].port, lib_arp_route_table[i].nh); - } - - printf("\nARP Stats: Total Queries %u, ok_NH %u, no_NH %u, " - "ok_Entry %u, no_Entry %u, PopulateCall %u, Del %u, Dup %u\n", - lib_arp_get_mac_req, lib_arp_nh_found, lib_arp_no_nh_found, - lib_arp_arp_entry_found, lib_arp_no_arp_entry_found, - lib_arp_populate_called, lib_arp_delete_called, - lib_arp_duplicate_found); - - printf("ARP table key len is %lu\n", sizeof(struct arp_key_ipv4)); -} - -/* ND IPv6 */ -void print_nd_table(void) -{ - const void *next_key; - void *next_data; - uint32_t iter = 0; - uint8_t ii = 0, j = 0, k = 0; - - printf("\tport hw addr status ip addr\n"); - - while (rte_hash_iterate(nd_hash_handle, &next_key, &next_data, &iter) >= - 0) { - - struct nd_entry_data *tmp_nd_data = - (struct nd_entry_data *)next_data; - struct nd_key_ipv6 tmp_nd_key; - memcpy(&tmp_nd_key, next_key, sizeof(struct nd_key_ipv6)); - printf("\t%4d %02X:%02X:%02X:%02X:%02X:%02X %10s\n", - tmp_nd_data->port, - tmp_nd_data->eth_addr.addr_bytes[0], - tmp_nd_data->eth_addr.addr_bytes[1], - tmp_nd_data->eth_addr.addr_bytes[2], - tmp_nd_data->eth_addr.addr_bytes[3], - tmp_nd_data->eth_addr.addr_bytes[4], - tmp_nd_data->eth_addr.addr_bytes[5], - tmp_nd_data->status == - COMPLETE ? "COMPLETE" : "INCOMPLETE"); - printf("\t\t\t\t\t\t"); - for (ii = 0; ii < ND_IPV6_ADDR_SIZE; ii += 2) { - printf("%02X%02X ", tmp_nd_data->ipv6[ii], - tmp_nd_data->ipv6[ii + 1]); - } - printf("\n"); - } - - uint32_t i = 0; - printf("\n\nND IPV6 routing table has %d entries\n", - nd_route_tbl_index); - printf("\nIP_Address Depth Port NH_IP_Address\n"); - for (i = 0; i < nd_route_tbl_index; i++) { - printf("\n"); - - for (j = 0; j < ND_IPV6_ADDR_SIZE; j += 2) { - printf("%02X%02X ", lib_nd_route_table[i].ipv6[j], - lib_nd_route_table[i].ipv6[j + 1]); - } - - printf - ("\n\t\t\t %d %d\n", - lib_nd_route_table[i].depth, lib_nd_route_table[i].port); - printf("\t\t\t\t\t\t\t\t\t"); - for (k = 0; k < ND_IPV6_ADDR_SIZE; k += 2) { - printf("%02X%02X ", lib_nd_route_table[i].nhipv6[k], - lib_nd_route_table[i].ipv6[k + 1]); - } - } - printf("\nND IPV6 Stats:\nTotal Queries %u, ok_NH %u, no_NH %u," - "ok_Entry %u, no_Entry %u, PopulateCall %u, Del %u, Dup %u\n", - lib_nd_get_mac_req, lib_nd_nh_found, lib_nd_no_nh_found, - lib_nd_nd_entry_found, lib_nd_no_arp_entry_found, - lib_nd_populate_called, lib_nd_delete_called, - lib_nd_duplicate_found); - printf("ND table key len is %lu\n\n", sizeof(struct nd_key_ipv6)); -} - -void remove_arp_entry(uint32_t ipaddr, uint8_t portid) -{ - - /* need to lock here if multi-threaded... */ - /* rte_hash_del_key is not thread safe */ - struct arp_key_ipv4 arp_key; - arp_key.port_id = portid; - arp_key.ip = ipaddr; - arp_key.filler1 = 0; - arp_key.filler2 = 0; - arp_key.filler3 = 0; - - lib_arp_delete_called++; - - if (ARPICMP_DEBUG) - printf("remove_arp_entry ip %x, port %d\n", arp_key.ip, - arp_key.port_id); - rte_hash_del_key(arp_hash_handle, &arp_key); -} - -/* ND IPv6 */ -void remove_nd_entry_ipv6(uint8_t ipv6addr[], uint8_t portid) -{ - /* need to lock here if multi-threaded */ - /* rte_hash_del_key is not thread safe */ - int i = 0; - struct nd_key_ipv6 nd_key; - nd_key.port_id = portid; - /* arp_key.ip = rte_bswap32(ipaddr); */ - - for (i = 0; i < ND_IPV6_ADDR_SIZE; i++) - nd_key.ipv6[i] = ipv6addr[i]; - - nd_key.filler1 = 0; - nd_key.filler2 = 0; - nd_key.filler3 = 0; - - lib_nd_delete_called++; - - if (NDIPV6_DEBUG) { - printf("Deletes rte hash table nd entry for port %d ipv6=", - nd_key.port_id); - for (i = 0; i < ND_IPV6_ADDR_SIZE; i += 2) - printf("%02X%02X ", nd_key.ipv6[i], nd_key.ipv6[i + 1]); - } - rte_hash_del_key(nd_hash_handle, &nd_key); -} - -void -populate_arp_entry(const struct ether_addr *hw_addr, uint32_t ipaddr, - uint8_t portid) -{ - /* need to lock here if multi-threaded */ - /* rte_hash_add_key_data is not thread safe */ - struct arp_key_ipv4 arp_key; - arp_key.port_id = portid; - arp_key.ip = ipaddr; - arp_key.filler1 = 0; - arp_key.filler2 = 0; - arp_key.filler3 = 0; - - lib_arp_populate_called++; - - if (ARPICMP_DEBUG) - printf("populate_arp_entry ip %x, port %d\n", arp_key.ip, - arp_key.port_id); - struct arp_entry_data *new_arp_data = retrieve_arp_entry(arp_key); - if (new_arp_data - && is_same_ether_addr(&new_arp_data->eth_addr, hw_addr)) { - if (ARPICMP_DEBUG) - printf("arp_entry exists ip%x, port %d\n", arp_key.ip, - arp_key.port_id); - lib_arp_duplicate_found++; - return; - } - new_arp_data = (struct arp_entry_data *) - malloc(sizeof(struct arp_entry_data)); - if (new_arp_data == NULL) { - printf("populate_arp_entry:new_arp_data is NULL\n"); - return; - } - new_arp_data->eth_addr = *hw_addr; - new_arp_data->status = INCOMPLETE; - new_arp_data->port = portid; - new_arp_data->ip = ipaddr; - rte_hash_add_key_data(arp_hash_handle, &arp_key, new_arp_data); - - if (ARPICMP_DEBUG) { - // print entire hash table - printf("\tARP: table update - hwaddr= " - "%02x:%02x:%02x:%02x:%02x:%02x ip=%d.%d.%d.%d " - "on port=%d\n", - new_arp_data->eth_addr.addr_bytes[0], - new_arp_data->eth_addr.addr_bytes[1], - new_arp_data->eth_addr.addr_bytes[2], - new_arp_data->eth_addr.addr_bytes[3], - new_arp_data->eth_addr.addr_bytes[4], - new_arp_data->eth_addr.addr_bytes[5], - (arp_key.ip >> 24), - ((arp_key.ip & 0x00ff0000) >> 16), - ((arp_key.ip & 0x0000ff00) >> 8), - ((arp_key.ip & 0x000000ff)), portid); - /* print_arp_table(); */ - puts(""); - } -} - -/* -* ND IPv6 -* -* Install key - data pair in Hash table - From Pipeline Configuration -* -*/ -int -populate_nd_entry(const struct ether_addr *hw_addr, uint8_t ipv6[], - uint8_t portid) -{ - - /* need to lock here if multi-threaded */ - /* rte_hash_add_key_data is not thread safe */ - uint8_t i; - struct nd_key_ipv6 nd_key; - nd_key.port_id = portid; - - for (i = 0; i < ND_IPV6_ADDR_SIZE; i++ /*i+=2 */) - nd_key.ipv6[i] = ipv6[i]; - - printf("\n"); - nd_key.filler1 = 0; - nd_key.filler2 = 0; - nd_key.filler3 = 0; - - lib_nd_populate_called++; - - /*Validate if key-value pair already - * exists in the hash table for ND IPv6 - */ - struct nd_entry_data *new_nd_data = retrieve_nd_entry(nd_key); - - if (new_nd_data && is_same_ether_addr(&new_nd_data->eth_addr, - hw_addr)) { - - if (NDIPV6_DEBUG) { - printf("nd_entry exists port %d ipv6 = ", - nd_key.port_id); - for (i = 0; i < ND_IPV6_ADDR_SIZE; i += 2) { - - printf("%02X%02X ", nd_key.ipv6[i], - nd_key.ipv6[i + 1]); - } - } - - lib_nd_duplicate_found++; - if (NDIPV6_DEBUG) - printf("nd_entry exists\n"); - return 0; - } - - new_nd_data = (struct nd_entry_data *) - malloc(sizeof(struct nd_entry_data)); - if (new_nd_data == NULL) { - printf("populate_nd_entry: new_nd_data is NULL\n"); - return 0; - } - new_nd_data->eth_addr = *hw_addr; - new_nd_data->status = COMPLETE; - new_nd_data->port = portid; - - if (NDIPV6_DEBUG) - printf("populate_nd_entry ipv6="); - - for (i = 0; i < ND_IPV6_ADDR_SIZE; i++ /*i+=2 */) - new_nd_data->ipv6[i] = ipv6[i]; - - if (NDIPV6_DEBUG) { - for (i = 0; i < ND_IPV6_ADDR_SIZE; i += 2) { - - printf("%02X%02X ", new_nd_data->ipv6[i], - new_nd_data->ipv6[i + 1]); - } - } - - /*Add a key-data pair at hash table for ND IPv6 static routing */ - rte_hash_add_key_data(nd_hash_handle, &nd_key, new_nd_data); - - if (NDIPV6_DEBUG) - printf("\n....Added a key-data pair at rte hash table " - "for ND IPv6 static routing\n"); - - if (NDIPV6_DEBUG) { - /* print entire hash table */ - printf("\tND: table update - hwaddr= " - "%02x:%02x:%02x:%02x:%02x:%02x on port=%d\n", - new_nd_data->eth_addr.addr_bytes[0], - new_nd_data->eth_addr.addr_bytes[1], - new_nd_data->eth_addr.addr_bytes[2], - new_nd_data->eth_addr.addr_bytes[3], - new_nd_data->eth_addr.addr_bytes[4], - new_nd_data->eth_addr.addr_bytes[5], portid); - printf("\tipv6="); - for (i = 0; i < ND_IPV6_ADDR_SIZE; i += 2) { - new_nd_data->ipv6[i] = ipv6[i]; - printf("%02X%02X ", new_nd_data->ipv6[i], - new_nd_data->ipv6[i + 1]); - } - - printf("\n"); - - puts(""); - } - return 1; -} - -void print_pkt1(struct rte_mbuf *pkt) -{ - uint8_t *rd = RTE_MBUF_METADATA_UINT8_PTR(pkt, 0); - int i = 0, j = 0; - printf("\nPacket Contents...\n"); - for (i = 0; i < 20; i++) { - for (j = 0; j < 20; j++) - printf("%02x ", rd[(20 * i) + j]); - printf("\n"); - } -} - -struct ether_addr broadcast_ether_addr = { - .addr_bytes[0] = 0xFF, - .addr_bytes[1] = 0xFF, - .addr_bytes[2] = 0xFF, - .addr_bytes[3] = 0xFF, - .addr_bytes[4] = 0xFF, - .addr_bytes[5] = 0xFF, -}; - -static const struct ether_addr null_ether_addr = { - .addr_bytes[0] = 0x00, - .addr_bytes[1] = 0x00, - .addr_bytes[2] = 0x00, - .addr_bytes[3] = 0x00, - .addr_bytes[4] = 0x00, - .addr_bytes[5] = 0x00, -}; - -#define MAX_NUM_MAC_ADDRESS 16 -struct ether_addr link_hw_addr[MAX_NUM_MAC_ADDRESS] = { -{.addr_bytes = {0x90, 0xe2, 0xba, 0x54, 0x67, 0xc8} }, -{.addr_bytes = {0x90, 0xe2, 0xba, 0x54, 0x67, 0xc9} }, -{.addr_bytes = {0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11} }, -{.addr_bytes = {0x12, 0x13, 0x14, 0x15, 0x16, 0x17} }, -{.addr_bytes = {0x22, 0x33, 0x44, 0x55, 0x66, 0x77} }, -{.addr_bytes = {0x12, 0x13, 0x14, 0x15, 0x16, 0x17} }, -{.addr_bytes = {0x22, 0x33, 0x44, 0x55, 0x66, 0x77} }, -{.addr_bytes = {0x90, 0xe2, 0xba, 0x54, 0x67, 0xc9} }, -{.addr_bytes = {0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11} }, -{.addr_bytes = {0x12, 0x13, 0x14, 0x15, 0x16, 0x17} }, -{.addr_bytes = {0x22, 0x33, 0x44, 0x55, 0x66, 0x77} }, -{.addr_bytes = {0x12, 0x13, 0x14, 0x15, 0x16, 0x17} }, -{.addr_bytes = {0x22, 0x33, 0x44, 0x55, 0x66, 0x77} }, -{.addr_bytes = {0x12, 0x13, 0x14, 0x15, 0x16, 0x17} }, -{.addr_bytes = {0x22, 0x33, 0x44, 0x55, 0x66, 0x77} }, -{.addr_bytes = {0x18, 0x19, 0x1a, 0x1b, 0xcd, 0xef} } -}; - -struct ether_addr *get_link_hw_addr(uint8_t out_port) -{ - return &link_hw_addr[out_port]; -} - -static void -request_icmp_echo(unsigned int port_id, uint32_t ip, struct ether_addr *gw_addr) -{ - struct ether_hdr *eth_h; - struct ipv4_hdr *ip_h; - struct icmp_hdr *icmp_h; - - struct app_link_params *link; - link = &myApp->link_params[port_id]; - arp_port_addresses[port_id].ip = link->ip; - arp_port_addresses[port_id].mac_addr = link->mac_addr; - - struct rte_mbuf *icmp_pkt = lib_arp_pkt; - if (icmp_pkt == NULL) { - if (ARPICMP_DEBUG) - printf("Error allocating icmp_pkt rte_mbuf\n"); - return; - } - - eth_h = rte_pktmbuf_mtod(icmp_pkt, struct ether_hdr *); - ether_addr_copy(gw_addr, ð_h->d_addr); - ether_addr_copy((struct ether_addr *) - &arp_port_addresses[port_id].mac_addr, ð_h->s_addr); - eth_h->ether_type = CHECK_ENDIAN_16(ETHER_TYPE_IPv4); - - ip_h = (struct ipv4_hdr *)((char *)eth_h + sizeof(struct ether_hdr)); - icmp_h = (struct icmp_hdr *)((char *)ip_h + sizeof(struct ipv4_hdr)); - - ip_h->version_ihl = IP_VHL_DEF; - ip_h->type_of_service = 0; - ip_h->total_length = - rte_cpu_to_be_16(sizeof(struct ipv4_hdr) + sizeof(struct icmp_hdr)); - ip_h->packet_id = 0xaabb; - ip_h->fragment_offset = 0x0000; - ip_h->time_to_live = 64; - ip_h->next_proto_id = IPPROTO_ICMP; - ip_h->src_addr = rte_bswap32(arp_port_addresses[port_id].ip); - ip_h->dst_addr = ip; - - ip_h->hdr_checksum = 0; - ip_h->hdr_checksum = rte_ipv4_cksum(ip_h); - - icmp_h->icmp_type = IP_ICMP_ECHO_REQUEST; - icmp_h->icmp_code = 0; - icmp_h->icmp_ident = 0xdead; - icmp_h->icmp_seq_nb = 0xbeef; - - icmp_h->icmp_cksum = ~rte_raw_cksum(icmp_h, sizeof(struct icmp_hdr)); - - icmp_pkt->pkt_len = - sizeof(struct ether_hdr) + sizeof(struct ipv4_hdr) + - sizeof(struct icmp_hdr); - icmp_pkt->data_len = icmp_pkt->pkt_len; - - if (ARPICMP_DEBUG) { - printf("Sending echo request\n"); - print_mbuf("TX", port_id, icmp_pkt, __LINE__); - } - - rte_pipeline_port_out_packet_insert(gp_arp->p.p, - gp_arp->outport_id[port_id], icmp_pkt); - gp_arp->sentPktCount++; -} - -void request_echo(unsigned int port_id, uint32_t ip) -{ - (void)port_id; - (void)ip; - - struct ether_addr gw_addr; - uint32_t dest_ip = rte_bswap32(ip); - uint32_t phy_port; - - if (get_dest_mac_addr_port(dest_ip, &phy_port, &gw_addr) == ARP_FOUND) { - request_icmp_echo(phy_port, ip, &gw_addr); - return; - } - - if (ARPICMP_DEBUG) - printf("Sending echo request ... get mac failed.\n"); -} - -void request_arp(uint8_t port_id, uint32_t ip, struct rte_pipeline *rte_p) -{ - (void)port_id; - (void)ip; - - struct ether_hdr *eth_h; - struct arp_hdr *arp_h; - - struct app_link_params *link; - link = &myApp->link_params[port_id]; - arp_port_addresses[port_id].ip = link->ip; - arp_port_addresses[port_id].mac_addr = link->mac_addr; - - struct rte_mbuf *arp_pkt = lib_arp_pkt; - - if (arp_pkt == NULL) { - if (ARPICMP_DEBUG) - printf("Error allocating arp_pkt rte_mbuf\n"); - return; - } - - eth_h = rte_pktmbuf_mtod(arp_pkt, struct ether_hdr *); - - ether_addr_copy(&broadcast_ether_addr, ð_h->d_addr); - ether_addr_copy((struct ether_addr *) - &arp_port_addresses[port_id].mac_addr, ð_h->s_addr); - eth_h->ether_type = CHECK_ENDIAN_16(ETHER_TYPE_ARP); - - arp_h = (struct arp_hdr *)((char *)eth_h + sizeof(struct ether_hdr)); - arp_h->arp_hrd = CHECK_ENDIAN_16(ARP_HRD_ETHER); - arp_h->arp_pro = CHECK_ENDIAN_16(ETHER_TYPE_IPv4); - arp_h->arp_hln = ETHER_ADDR_LEN; - arp_h->arp_pln = sizeof(uint32_t); - arp_h->arp_op = CHECK_ENDIAN_16(ARP_OP_REQUEST); - - ether_addr_copy((struct ether_addr *) - &arp_port_addresses[port_id].mac_addr, - &arp_h->arp_data.arp_sha); - arp_h->arp_data.arp_sip = - rte_cpu_to_be_32(arp_port_addresses[port_id].ip); - ether_addr_copy(&null_ether_addr, &arp_h->arp_data.arp_tha); - arp_h->arp_data.arp_tip = rte_cpu_to_be_32(ip); - printf("arp tip:%x arp sip :%x\n", arp_h->arp_data.arp_tip, - arp_h->arp_data.arp_sip); - /* mmcd changed length from 60 to 42 - - * real length of arp request, no padding on ethernet needed - - * looks now like linux arp - */ - - arp_pkt->pkt_len = 42; - arp_pkt->data_len = 42; - - if (ARPICMP_DEBUG) { - printf("Sending arp request\n"); - print_mbuf("TX", port_id, arp_pkt, __LINE__); - } - - rte_pipeline_port_out_packet_insert(rte_p, port_id, arp_pkt); - gp_arp->sentPktCount++; - -} - -void request_arp_wrap(uint8_t port_id, uint32_t ip) -{ - request_arp(port_id, ip, gp_arp->p.p); -} - -void process_arpicmp_pkt( - struct rte_mbuf *pkt, - uint32_t out_port, - uint32_t pkt_mask) -{ - uint8_t in_port_id = pkt->port; - struct app_link_params *link; - struct ether_hdr *eth_h; - struct arp_hdr *arp_h; - struct ipv4_hdr *ip_h; - struct icmp_hdr *icmp_h; - uint32_t cksum; - uint32_t ip_addr; - uint32_t req_tip; - - - eth_h = rte_pktmbuf_mtod(pkt, struct ether_hdr *); - - if (eth_h->ether_type == rte_cpu_to_be_16(ETHER_TYPE_ARP)) { - arp_h = - (struct arp_hdr *)((char *)eth_h + - sizeof(struct ether_hdr)); - if (CHECK_ENDIAN_16(arp_h->arp_hrd) != ARP_HRD_ETHER) - printf - ("Invalid hardware format of hardware address - " - "not processing ARP req\n"); - else if (CHECK_ENDIAN_16(arp_h->arp_pro) != ETHER_TYPE_IPv4) - printf - ("Invalid protocol address format - " - "not processing ARP req\n"); - else if (arp_h->arp_hln != 6) - printf - ("Invalid hardware address length - " - "not processing ARP req\n"); - else if (arp_h->arp_pln != 4) - printf - ("Invalid protocol address length - " - "not processing ARP req\n"); - else { - link = &myApp->link_params[in_port_id]; - arp_port_addresses[in_port_id].ip = link->ip; - arp_port_addresses[in_port_id].mac_addr = - link->mac_addr; - - if (arp_h->arp_data.arp_tip != - rte_bswap32(arp_port_addresses[in_port_id].ip)) { - printf - ("ARP requested IP address mismatches " - "interface IP - discarding\n"); - printf("arp_tip = %x\n", - arp_h->arp_data.arp_tip); - printf("arp_port_addresses = %x\n", - arp_port_addresses[in_port_id].ip); - printf("in_port_id = %x\n", in_port_id); - printf("arp_port_addresses[0] = %x\n", - arp_port_addresses[0].ip); - - rte_pipeline_ah_packet_drop(gp_arp->p.p, - pkt_mask); - gp_arp->droppedPktCount++; - - } - /* revise conditionals to allow processing of - * requests with target ip = this ip and - * processing of replies to destination ip = this ip - */ - else if (arp_h->arp_op == - rte_cpu_to_be_16(ARP_OP_REQUEST)) { - - if (ARPICMP_DEBUG) { - printf("arp_op %d, ARP_OP_REQUEST %d\n", - arp_h->arp_op, - rte_cpu_to_be_16(ARP_OP_REQUEST)); - print_mbuf("RX", in_port_id, pkt, __LINE__); - } - - populate_arp_entry((struct ether_addr *) - &arp_h->arp_data.arp_sha, - rte_cpu_to_be_32 - (arp_h->arp_data.arp_sip), - in_port_id); - - /* build reply */ - req_tip = arp_h->arp_data.arp_tip; - ether_addr_copy(ð_h->s_addr, ð_h->d_addr); - - // set sender mac address - - ether_addr_copy((struct ether_addr *)& - arp_port_addresses[in_port_id].mac_addr, - ð_h->s_addr); - - arp_h->arp_op = rte_cpu_to_be_16(ARP_OP_REPLY); - ether_addr_copy(ð_h->s_addr, - &arp_h->arp_data.arp_sha); - arp_h->arp_data.arp_tip = - arp_h->arp_data.arp_sip; - arp_h->arp_data.arp_sip = req_tip; - ether_addr_copy(ð_h->d_addr, - &arp_h->arp_data.arp_tha); - - rte_pipeline_port_out_packet_insert(gp_arp->p.p, - out_port, pkt); - gp_arp->sentPktCount++; - - } else if (arp_h->arp_op == - rte_cpu_to_be_16(ARP_OP_REPLY)) { - // TODO: be sure that ARP request - //was actually sent!!! - if (ARPICMP_DEBUG) { - printf("ARP_OP_REPLY received"); - print_mbuf("RX", in_port_id, pkt, - __LINE__); - } - populate_arp_entry((struct ether_addr *) - &arp_h->arp_data.arp_sha, - rte_bswap32(arp_h-> - arp_data.arp_sip), - in_port_id); - - /* To drop the packet from LB */ - rte_pipeline_ah_packet_drop(gp_arp->p.p, - pkt_mask); - gp_arp->droppedPktCount++; - - } else { - if (ARPICMP_DEBUG) - printf("Invalid ARP opcode - not " - "processing ARP req %x\n", - arp_h->arp_op); - } - } - } else { - ip_h = - (struct ipv4_hdr *)((char *)eth_h + - sizeof(struct ether_hdr)); - icmp_h = - (struct icmp_hdr *)((char *)ip_h + sizeof(struct ipv4_hdr)); - - if (eth_h->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) { - - link = &myApp->link_params[in_port_id]; - arp_port_addresses[in_port_id].ip = link->ip; - arp_port_addresses[in_port_id].mac_addr = - link->mac_addr; - - if (!is_same_ether_addr((struct ether_addr *) - &arp_port_addresses[in_port_id]. - mac_addr, ð_h->d_addr)) { - - if (ARPICMP_DEBUG) - printf("Ethernet frame not destined " - "for MAC address of received network " - "interface - discarding\n"); - - } else if (ip_h->next_proto_id != IPPROTO_ICMP) { - if (ARPICMP_DEBUG) - printf("IP protocol ID is not set to " - "ICMP - discarding\n"); - - } else if ((ip_h->version_ihl & 0xf0) != IP_VERSION_4) { - if (ARPICMP_DEBUG) - printf("IP version other than 4 - " - "discarding\n"); - - } else if ((ip_h->version_ihl & 0x0f) != IP_HDRLEN) { - if (ARPICMP_DEBUG) - printf("Unknown IHL - discarding\n"); - - } else { - if (icmp_h->icmp_type == IP_ICMP_ECHO_REQUEST - && icmp_h->icmp_code == 0) { - if (ARPICMP_DEBUG) - print_mbuf("RX", in_port_id, - pkt, __LINE__); - - ip_addr = ip_h->src_addr; - ether_addr_copy(ð_h->s_addr, - ð_h->d_addr); - ether_addr_copy((struct ether_addr *) - &arp_port_addresses - [in_port_id].mac_addr, - ð_h->s_addr); - - if (ip_h->dst_addr != - rte_bswap32(arp_port_addresses - [in_port_id].ip)) { - if (ARPICMP_DEBUG) { - printf("IPv4 packet not destined for " - "configured IP on RX port - " - "discarding\n"); - printf("ip_h->dst_addr = %u, " - "in_port_id = %u, " - "arp_port_addresses.ip = %u\n", - ip_h->dst_addr, in_port_id, - arp_port_addresses[in_port_id].ip); - } - } else { - - if (is_multicast_ipv4_addr - (ip_h->dst_addr)) { - uint32_t ip_src; - - ip_src = rte_be_to_cpu_32 - (ip_addr); - if ((ip_src & 0x00000003) == 1) - ip_src = (ip_src & - 0xFFFFFFFC) - | 0x00000002; - else - ip_src = (ip_src & - 0xFFFFFFFC) - | 0x00000001; - - ip_h->src_addr = - rte_cpu_to_be_32(ip_src); - ip_h->dst_addr = ip_addr; - - ip_h->hdr_checksum = 0; - ip_h->hdr_checksum = ~rte_raw_cksum( - ip_h, sizeof(struct - ipv4_hdr)); - } else { - ip_h->src_addr = ip_h->dst_addr; - ip_h->dst_addr = ip_addr; - } - - icmp_h->icmp_type = - IP_ICMP_ECHO_REPLY; - cksum = ~icmp_h->icmp_cksum & 0xffff; - cksum += ~htons(IP_ICMP_ECHO_REQUEST << 8) & 0xffff; - cksum += htons(IP_ICMP_ECHO_REPLY << 8); - cksum = (cksum & 0xffff) + (cksum >> 16); - cksum = (cksum & 0xffff) + (cksum >> 16); - icmp_h->icmp_cksum = ~cksum; - - if (ARPICMP_DEBUG) - print_mbuf("TX", in_port_id, pkt, __LINE__); - - rte_pipeline_port_out_packet_insert(gp_arp->p.p, - out_port, pkt); - gp_arp->sentPktCount++; - - } - } - else if (icmp_h->icmp_type == IP_ICMP_ECHO_REPLY - && icmp_h->icmp_code == 0) { - if (ARPICMP_DEBUG) - print_mbuf("RX", in_port_id, - pkt, __LINE__); - - struct arp_key_ipv4 arp_key; - arp_key.port_id = in_port_id; - arp_key.ip = - rte_bswap32(ip_h->src_addr); - arp_key.filler1 = 0; - arp_key.filler2 = 0; - arp_key.filler3 = 0; - - struct arp_entry_data *arp_entry = - retrieve_arp_entry(arp_key); - if (arp_entry == NULL) { - printf("Received unsolicited " - "ICMP echo reply from ip%x, " - "port %d\n", - arp_key.ip, - arp_key.port_id); - return; - } - - arp_entry->status = COMPLETE; - /* To drop the packet from LB */ - rte_pipeline_ah_packet_drop(gp_arp->p.p, - pkt_mask); - gp_arp->droppedPktCount++; - } - } - } - } -} - - - -/* int - * inet_pton(af, src, dst) - * convert from presentation format (which usually means ASCII printable) - * to network format (which is usually some kind of binary format). - * return: - * 1 if the address was valid for the specified address family - * 0 if the address wasn't valid (`dst' is untouched in this case) - * -1 if some other error occurred (`dst' is untouched in this case, too) - * author: - * Paul Vixie, 1996. - */ -static int my_inet_pton_ipv6(int af, const char *src, void *dst) -{ - switch (af) { - case AF_INET: - return inet_pton_ipv4(src, dst); - case AF_INET6: - return inet_pton_ipv6(src, dst); - default: - errno = EAFNOSUPPORT; - return -1; - } - /* NOTREACHED */ -} - -/* int - * inet_pton_ipv4(src, dst) - * like inet_aton() but without all the hexadecimal and shorthand. - * return: - * 1 if `src' is a valid dotted quad, else 0. - * notice: - * does not touch `dst' unless it's returning 1. - * author: - * Paul Vixie, 1996. - */ -static int inet_pton_ipv4(const char *src, unsigned char *dst) -{ - static const char digits[] = "0123456789"; - int saw_digit, octets, ch; - unsigned char tmp[INADDRSZ], *tp; - - saw_digit = 0; - octets = 0; - *(tp = tmp) = 0; - while ((ch = *src++) != '\0') { - const char *pch; - - pch = strchr(digits, ch); - if (pch != NULL) { - unsigned int new = *tp * 10 + (pch - digits); - - if (new > 255) - return 0; - if (!saw_digit) { - if (++octets > 4) - return 0; - saw_digit = 1; - } - *tp = (unsigned char)new; - } else if (ch == '.' && saw_digit) { - if (octets == 4) - return 0; - *++tp = 0; - saw_digit = 0; - } else - return 0; - } - if (octets < 4) - return 0; - - memcpy(dst, tmp, INADDRSZ); - return 1; -} - -/* int - * inet_pton_ipv6(src, dst) - * convert presentation level address to network order binary form. - * return: - * 1 if `src' is a valid [RFC1884 2.2] address, else 0. - * notice: - * (1) does not touch `dst' unless it's returning 1. - * (2) :: in a full address is silently ignored. - * credit: - * inspired by Mark Andrews. - * author: - * Paul Vixie, 1996. - */ -static int inet_pton_ipv6(const char *src, unsigned char *dst) -{ - static const char xdigits_l[] = "0123456789abcdef", - xdigits_u[] = "0123456789ABCDEF"; - unsigned char tmp[IN6ADDRSZ], *tp = 0, *endp = 0, *colonp = 0; - const char *xdigits = 0, *curtok = 0; - int ch = 0, saw_xdigit = 0, count_xdigit = 0; - unsigned int val = 0; - unsigned int dbloct_count = 0; - - memset((tp = tmp), '\0', IN6ADDRSZ); - endp = tp + IN6ADDRSZ; - colonp = NULL; - /* Leading :: requires some special handling. */ - if (*src == ':') - if (*++src != ':') - return 0; - curtok = src; - saw_xdigit = count_xdigit = 0; - val = 0; - - while ((ch = *src++) != '\0') { - const char *pch; - - pch = strchr((xdigits = xdigits_l), ch); - if (pch == NULL) - pch = strchr((xdigits = xdigits_u), ch); - if (pch != NULL) { - if (count_xdigit >= 4) - return 0; - val <<= 4; - val |= (pch - xdigits); - if (val > 0xffff) - return 0; - saw_xdigit = 1; - count_xdigit++; - continue; - } - if (ch == ':') { - curtok = src; - if (!saw_xdigit) { - if (colonp) - return 0; - colonp = tp; - continue; - } else if (*src == '\0') { - return 0; - } - if (tp + sizeof(int16_t) > endp) - return 0; - *tp++ = (unsigned char)((val >> 8) & 0xff); - *tp++ = (unsigned char)(val & 0xff); - saw_xdigit = 0; - count_xdigit = 0; - val = 0; - dbloct_count++; - continue; - } - if (ch == '.' && ((tp + INADDRSZ) <= endp) && - inet_pton_ipv4(curtok, tp) > 0) { - tp += INADDRSZ; - saw_xdigit = 0; - dbloct_count += 2; - break; /* '\0' was seen by inet_pton4(). */ - } - return 0; - } - if (saw_xdigit) { - if (tp + sizeof(int16_t) > endp) - return 0; - *tp++ = (unsigned char)((val >> 8) & 0xff); - *tp++ = (unsigned char)(val & 0xff); - dbloct_count++; - } - if (colonp != NULL) { - /* if we already have 8 double octets, - * having a colon means error - */ - if (dbloct_count == 8) - return 0; - - /* - * Since some memmove()'s erroneously fail to handle - * overlapping regions, we'll do the shift by hand. - */ - const int n = tp - colonp; - int i; - - for (i = 1; i <= n; i++) { - endp[-i] = colonp[n - i]; - colonp[n - i] = 0; - } - tp = endp; - } - if (tp != endp) - return 0; - memcpy(dst, tmp, IN6ADDRSZ); - return 1; -} - -/** - * Function to classify ICMPv6 Packets based on NextHeader field in IPv6 Header. - * Updates ND Cache table with link layer addresses as received from Neighbor. - * Processes ICMPv6 Echo destined to local port and replys. - * - * @param pkt - * A pointer to the packet received from Loadbalancer pipeline - * @param out_port - * A pointer to the output port action - * @param pkt_num - * A packet number - * - * @return - * NULL - */ - -void -process_icmpv6_pkt( - struct rte_mbuf *pkt, - uint32_t out_port, - __rte_unused uint32_t pkt_num) -{ - - uint8_t in_port_id = pkt->port; - struct app_link_params *link; - struct ether_hdr *eth_h; - struct ipv6_hdr *ipv6_h; - struct icmpv6_hdr *icmpv6_h; - struct icmpv6_nd_hdr *icmpv6_nd_h; - uint8_t ipv6_addr[16]; - uint8_t i = 0, flag = 1; - uint8_t req_tipv6[16]; - - eth_h = rte_pktmbuf_mtod(pkt, struct ether_hdr *); - ipv6_h = (struct ipv6_hdr *)((char *)eth_h + sizeof(struct ether_hdr)); - icmpv6_h = - (struct icmpv6_hdr *)((char *)ipv6_h + sizeof(struct ipv6_hdr)); - struct rte_mbuf *icmpv6_pkt = pkt; - - link = &myApp->link_params[in_port_id]; - icmpv6_port_addresses[in_port_id].mac_addr = link->mac_addr; - - if (!is_same_ether_addr - ((struct ether_addr *)&icmpv6_port_addresses[in_port_id].mac_addr, - ð_h->d_addr)) { - if (ARPICMP_DEBUG) { - printf("Ethernet frame not destined for MAC address " - "of received network interface - discarding\n"); - } - } else { - if ((icmpv6_h->icmpv6_type == ICMPV6_ECHO_REQUEST) - && (icmpv6_h->icmpv6_code == 0)) { - for (i = 0; i < 16; i++) - ipv6_addr[i] = ipv6_h->src_addr[i]; - - for (i = 0; i < 16; i++) { - if (ipv6_h->dst_addr[i] != - icmpv6_port_addresses[in_port_id].ipv6[i]) { - flag++; - } - } - if (!flag) { - printf("IPv6 packet not destined for " - "configured IP on RX port - discarding\n"); - } else { - { - - ether_addr_copy(ð_h->s_addr, - ð_h->d_addr); - ether_addr_copy((struct ether_addr *) - &icmpv6_port_addresses - [in_port_id].mac_addr, - ð_h->s_addr); - - for (i = 0; i < 16; i++) - ipv6_h->src_addr[i] = - ipv6_h->dst_addr[i]; - for (i = 0; i < 16; i++) - ipv6_h->dst_addr[i] = - ipv6_addr[i]; - - icmpv6_h->icmpv6_type = - ICMPV6_ECHO_REPLY; - - rte_pipeline_port_out_packet_insert - (gp_arp->p.p, out_port, icmpv6_pkt); - gp_arp->sentPktCount++; - } - } - - } else if ((icmpv6_h->icmpv6_type == ICMPV6_ECHO_REPLY) - && (icmpv6_h->icmpv6_code == 0)) { - struct nd_key_ipv6 nd_key; - nd_key.port_id = in_port_id; - - for (i = 0; i < ND_IPV6_ADDR_SIZE; i++) - nd_key.ipv6[i] = ipv6_h->src_addr[i]; - - nd_key.filler1 = 0; - nd_key.filler2 = 0; - nd_key.filler3 = 0; - - /* Validate if key-value pair already - * exists in the hash table for ND IPv6 - */ - struct nd_entry_data *new_nd_data = - retrieve_nd_entry(nd_key); - - if (new_nd_data == NULL) { - printf("Received unsolicited ICMPv6 echo " - "reply on port %d\n", - nd_key.port_id); - for (i = 0; i < ND_IPV6_ADDR_SIZE; i += 2) { - printf("%02X%02X ", nd_key.ipv6[i], - nd_key.ipv6[i + 1]); - } - return; - } - - new_nd_data->status = COMPLETE; - - } else - if ((icmpv6_h->icmpv6_type == ICMPV6_NEIGHBOR_SOLICITATION) - && (icmpv6_h->icmpv6_code == 0)) { - - icmpv6_nd_h = - (struct icmpv6_nd_hdr *)((char *)icmpv6_h + - sizeof(struct icmpv6_hdr)); - struct ether_addr *src_hw_addr = ð_h->s_addr; - uint8_t src_ipv6[16], dst_ipv6[16]; - - for (i = 0; i < ND_IPV6_ADDR_SIZE; i++) - src_ipv6[i] = ipv6_h->src_addr[i]; - for (i = 0; i < ND_IPV6_ADDR_SIZE; i++) - dst_ipv6[i] = ipv6_h->dst_addr[i]; - - // Check for Multicast Address - if ((IPV6_MULTICAST - && ((dst_ipv6[0] << 8) | dst_ipv6[1]))) { - if (populate_nd_entry - (src_hw_addr, src_ipv6, in_port_id)) { - - //build a Neighbor Advertisement message - for (i = 0; i < ND_IPV6_ADDR_SIZE; i++) - req_tipv6[i] = - icmpv6_nd_h->target_ipv6[i]; - - ether_addr_copy(ð_h->s_addr, - ð_h->d_addr); - ether_addr_copy((struct ether_addr *) - &icmpv6_port_addresses - [in_port_id].mac_addr, - ð_h->s_addr); - - // set sender mac address - ether_addr_copy(ð_h->s_addr, - &icmpv6_nd_h-> - link_layer_address); - for (i = 0; i < ND_IPV6_ADDR_SIZE; i++) - ipv6_h->dst_addr[i] = - ipv6_h->src_addr[i]; - for (i = 0; i < ND_IPV6_ADDR_SIZE; i++) - ipv6_h->src_addr[i] = - req_tipv6[i]; - icmpv6_h->icmpv6_type = - ICMPV6_NEIGHBOR_ADVERTISEMENT; - icmpv6_nd_h->type = - e_Target_Link_Layer_Address; - icmpv6_nd_h->icmpv6_reserved |= - rte_cpu_to_be_32 - (NEIGHBOR_SOLICITATION_SET); - - rte_pipeline_port_out_packet_insert - (gp_arp->p.p, out_port, icmpv6_pkt); - gp_arp->sentPktCount++; - } - } else { - if (ARPICMP_DEBUG) { - printf("Non-Multicasted Neighbor " - "Solicitation Message Received, " - "can't do Address Resolution\n"); - printf("............Some one else " - "is the target host here !!!\n"); - } - } - - } else - if ((icmpv6_h->icmpv6_type == ICMPV6_NEIGHBOR_ADVERTISEMENT) - && (icmpv6_h->icmpv6_code == 0)) { - struct ether_addr *src_hw_addr = ð_h->s_addr; - uint8_t ipv6[16]; - for (i = 0; i < ND_IPV6_ADDR_SIZE; i++) - ipv6[i] = ipv6_h->src_addr[i]; - - if (populate_nd_entry(src_hw_addr, ipv6, in_port_id)) - if (ARPICMP_DEBUG) - printf("Now on, unicast IPv6 traffic " - "is possible\n"); - // Now on, unicast IPv6 traffic is possible - } else { - if (ARPICMP_DEBUG) { - printf("ICMPv6 Type %d Not Supported yet !!!\n", - icmpv6_h->icmpv6_type); - } - } - - } - -} - -void request_icmpv6_echo(uint32_t port_id, uint8_t ipv6[]) -{ - (void)port_id; - (void)ipv6; - int i; - - struct ether_addr gw_addr; - uint8_t nhipv6[16]; - uint8_t dest_ipv6[16]; - uint32_t phy_port; - - for (i = 0; i < ND_IPV6_ADDR_SIZE; i++) - dest_ipv6[i] = ipv6[i]; - - if (get_dest_mac_address_ipv6_port(dest_ipv6, &phy_port, - &gw_addr, nhipv6)) { - request_icmpv6_echo_message(phy_port, ipv6, &gw_addr); - return; - } - - if (ARPICMP_DEBUG) - printf("Sending icmpv6 echo request ... get mac failed.\n"); -} - -void -request_icmpv6_echo_message(uint16_t port_id, uint8_t ipv6[], - struct ether_addr *gw_addr) -{ - struct ether_hdr *eth_h; - struct ipv6_hdr *ipv6_h; - struct icmpv6_hdr *icmpv6_h; - struct icmpv6_info_hdr *icmpv6_info_h; - int i; - struct app_link_params *link; - link = &mylink[port_id]; - - for (i = 0; i < 16; i++) - icmpv6_port_addresses[port_id].ipv6[i] = link->ipv6[i]; - - icmpv6_port_addresses[port_id].mac_addr = link->mac_addr; - - struct rte_mbuf *icmpv6_pkt = lib_icmpv6_pkt; - if (icmpv6_pkt == NULL) { - if (ARPICMP_DEBUG) - printf("Error allocating icmpv6_pkt rte_mbuf\n"); - return; - } - - eth_h = rte_pktmbuf_mtod(icmpv6_pkt, struct ether_hdr *); - ether_addr_copy(gw_addr, ð_h->d_addr); - ether_addr_copy((struct ether_addr *)&icmpv6_port_addresses[port_id]. - mac_addr, ð_h->s_addr); - eth_h->ether_type = CHECK_ENDIAN_16(ETHER_TYPE_IPv6); - - ipv6_h = (struct ipv6_hdr *)((char *)eth_h + sizeof(struct ether_hdr)); - icmpv6_h = - (struct icmpv6_hdr *)((char *)ipv6_h + sizeof(struct ipv6_hdr)); - icmpv6_info_h = - (struct icmpv6_info_hdr *)((char *)icmpv6_h + - sizeof(struct icmpv6_hdr)); - - ipv6_h->vtc_flow = 0x60000000; - ipv6_h->payload_len = 64; - ipv6_h->proto = 58; - ipv6_h->hop_limits = 64; - - for (i = 0; i < 16; i++) { - ipv6_h->src_addr[i] = icmpv6_port_addresses[port_id].ipv6[i]; - ipv6_h->dst_addr[i] = ipv6[i]; - } - - icmpv6_h->icmpv6_type = ICMPV6_ECHO_REQUEST; - icmpv6_h->icmpv6_code = 0; - icmpv6_info_h->icmpv6_ident = 0x5151; - icmpv6_info_h->icmpv6_seq_nb = 0x1; - - icmpv6_h->icmpv6_cksum = - ~rte_raw_cksum(icmpv6_h, sizeof(struct icmpv6_hdr)); - - icmpv6_pkt->pkt_len = - sizeof(struct ether_hdr) + sizeof(struct ipv6_hdr) + - sizeof(struct icmpv6_hdr); - icmpv6_pkt->data_len = icmpv6_pkt->pkt_len; - - if (ARPICMP_DEBUG) - printf("Sending icmpv6 echo request\n"); - - rte_pipeline_port_out_packet_insert(gp_arp->p.p, - gp_arp->outport_id[port_id], - icmpv6_pkt); - - gp_arp->sentPktCount++; -} - - -#endif - static void *pipeline_arpicmp_msg_req_custom_handler(struct pipeline *p, void *msg); @@ -2432,400 +508,6 @@ void *pipeline_arpicmp_msg_req_custom_handler(struct pipeline *p, void *msg) return f_handle(p, req); } -#ifdef VNF_ACL - -/* Not needed as no arguments are needed for TxRX - * ARP arguments are handled in ARP module - */ -int -pipeline_arpicmp_parse_args(struct pipeline_arpicmp *p, - struct pipeline_params *params); -int -pipeline_arpicmp_parse_args( - __rte_unused struct pipeline_arpicmp *p, - struct pipeline_params *params) -{ - - uint32_t i; - uint32_t arp_meta_offset_present = 0; - - uint32_t arp_route_tbl_present = 0; - uint32_t nd_route_tbl_present = 0; - uint32_t ports_mac_list_present = 0; - uint32_t pktq_in_prv_present = 0; - uint32_t prv_to_pub_map_present = 0; - - uint8_t n_prv_in_port = 0; - for (i = 0; i < PIPELINE_MAX_PORT_IN; i++) { - in_port_dir_a[i] = 0; //make all RX ports ingress initially - prv_to_pub_map[i] = 0xff; - pub_to_prv_map[i] = 0xff; - } - - for (i = 0; i < params->n_args; i++) { - char *arg_name = params->args_name[i]; - char *arg_value = params->args_value[i]; - - if (ARPICMP_DEBUG > 2) { - printf("ARP args[%d]: %s %d, %s\n", i, arg_name, - atoi(arg_value), arg_value); - } - if (strcmp(arg_name, "arp_meta_offset") == 0) { - if (arp_meta_offset_present) { - printf("arp_meta_offset " - "initialized already\n"); - return -1; - } - arp_meta_offset_present = 1; - arp_meta_offset = atoi(arg_value); - continue; - } - /* pktq_in_prv */ - if (strcmp(arg_name, "pktq_in_prv") == 0) { - if (pktq_in_prv_present) { - printf("Duplicate pktq_in_prv ... " - "parse failed..\n\n"); - return -1; - } - pktq_in_prv_present = 1; - - int rxport = 0, j = 0; - char phy_port_num[5]; - char *token = strtok(arg_value, "RXQ"); - while (token) { - j = 0; - while ((j < 4) && (token[j] != '.')) { - phy_port_num[j] = token[j]; - j++; - } - phy_port_num[j] = '\0'; - rxport = atoi(phy_port_num); - printf("token: %s, phy_port_str: %s, " - "phy_port_num %d\n", - token, phy_port_num, rxport); - - prv_in_port_a[n_prv_in_port++] = rxport; - // set rxport egress - if(rxport < PIPELINE_MAX_PORT_IN) - in_port_dir_a[rxport] = 1; - token = strtok(NULL, "RXQ"); - } - - if (n_prv_in_port == 0) { - printf - ("VNF common parse error - " - "no prv RX phy port\n"); - return -1; - } - continue; - } - - /* prv_to_pub_map */ - if (strcmp(arg_name, "prv_to_pub_map") == 0) { - if (prv_to_pub_map_present) { - printf - ("Duplicated prv_to_pub_map ... " - "parse failed ...\n"); - return -1; - } - prv_to_pub_map_present = 1; - - int rxport = 0, txport = 0, j = 0, k = 0; - char rx_phy_port_num[5]; - char tx_phy_port_num[5]; - char *token = strtok(arg_value, "("); - while (token) { - j = 0; - while ((j < 4) && (token[j] != ',')) { - rx_phy_port_num[j] = token[j]; - j++; - } - rx_phy_port_num[j] = '\0'; - rxport = atoi(rx_phy_port_num); - - j++; - k = 0; - while ((k < 4) && (token[j + k] != ')')) { - tx_phy_port_num[k] = token[j + k]; - k++; - } - tx_phy_port_num[k] = '\0'; - txport = atoi(tx_phy_port_num); - if (rxport < PIPELINE_MAX_PORT_IN && txport < PIPELINE_MAX_PORT_IN){ - printf("token: %s," - "rx_phy_port_str: %s, phy_port_num %d," - "tx_phy_port_str: %s, tx_phy_port_num %d\n", - token, rx_phy_port_num, rxport, - tx_phy_port_num, txport); - } - else - return -1; - if ((rxport >= PIPELINE_MAX_PORT_IN) || - (txport >= PIPELINE_MAX_PORT_IN) || - (in_port_dir_a[rxport] != 1)) { - printf("CG-NAPT parse error - " - "incorrect prv-pub translation. " - "Rx %d, Tx %d, Rx Dir %d\n", - rxport, txport, in_port_dir_a[rxport]); - return -1; - } - - prv_to_pub_map[rxport] = txport; - pub_to_prv_map[txport] = rxport; - token = strtok(NULL, "("); - } - - continue; - } - - /* lib_arp_debug */ - if (strcmp(arg_name, "lib_arp_debug") == 0) { - ARPICMP_DEBUG = atoi(arg_value); - - continue; - } - - /* ports_mac_list */ - if (strcmp(arg_name, "ports_mac_list") == 0) { - ports_mac_list_present = 1; - - uint32_t i = 0, j = 0, k = 0, MAC_NUM_BYTES = 6; - - char byteStr[MAC_NUM_BYTES][3]; - uint32_t byte[MAC_NUM_BYTES]; - - char *token = strtok(arg_value, " "); - while (token) { - k = 0; - for (i = 0; i < MAC_NUM_BYTES; i++) { - for (j = 0; j < 2; j++) - byteStr[i][j] = token[k++]; - byteStr[i][j] = '\0'; - k++; - } - - for (i = 0; i < MAC_NUM_BYTES; i++) - byte[i] = strtoul(byteStr[i], NULL, 16); - - if (ARPICMP_DEBUG) { - printf("token: %s", token); - for (i = 0; i < MAC_NUM_BYTES; i++) - printf(", byte[%u] %u", i, - byte[i]); - printf("\n"); - } - //Populate the static arp_route_table - for (i = 0; i < MAC_NUM_BYTES; i++) - link_hw_addr - [link_hw_addr_array_idx].addr_bytes - [i] = byte[i]; - - link_hw_addr_array_idx++; - token = strtok(NULL, " "); - } - - continue; - } - - /* arp_route_tbl */ - if (strcmp(arg_name, "arp_route_tbl") == 0) { - arp_route_tbl_present = 1; - - uint32_t dest_ip = 0, mask = 0, tx_port = 0, nh_ip = - 0, i = 0, j = 0, k = 0, l = 0; - uint32_t arp_route_tbl_str_max_len = 10; - char dest_ip_str[arp_route_tbl_str_max_len]; - char mask_str[arp_route_tbl_str_max_len]; - char tx_port_str[arp_route_tbl_str_max_len]; - char nh_ip_str[arp_route_tbl_str_max_len]; - char *token = strtok(arg_value, "("); - while (token) { - i = 0; - while ((i < (arp_route_tbl_str_max_len - 1)) - && (token[i] != ',')) { - dest_ip_str[i] = token[i]; - i++; - } - dest_ip_str[i] = '\0'; - dest_ip = strtoul(dest_ip_str, NULL, 16); - - i++; - j = 0; - while ((j < (arp_route_tbl_str_max_len - 1)) - && (token[i + j] != ',')) { - mask_str[j] = token[i + j]; - j++; - } - mask_str[j] = '\0'; - mask = strtoul(mask_str, NULL, 16); - - j++; - k = 0; - while ((k < (arp_route_tbl_str_max_len - 1)) - && (token[i + j + k] != ',')) { - tx_port_str[k] = token[i + j + k]; - k++; - } - tx_port_str[k] = '\0'; - //atoi(tx_port_str); - tx_port = strtoul(tx_port_str, NULL, 16); - - k++; - l = 0; - while ((l < (arp_route_tbl_str_max_len - 1)) - && (token[i + j + k + l] != ')')) { - nh_ip_str[l] = token[i + j + k + l]; - l++; - } - nh_ip_str[l] = '\0'; - //atoi(nh_ip_str); - nh_ip = strtoul(nh_ip_str, NULL, 16); - - if (ARPICMP_DEBUG) { - printf("token: %s, " - "dest_ip_str: %s, dest_ip %u, " - "mask_str: %s, mask %u, " - "tx_port_str: %s, tx_port %u, " - "nh_ip_str: %s, nh_ip %u\n", - token, dest_ip_str, dest_ip, - mask_str, mask, tx_port_str, - tx_port, nh_ip_str, nh_ip); - } - #if 0 - if (tx_port >= params->n_ports_out) { - printf("ARP-ICMP parse error - " - "incorrect tx_port %d, max %d\n", - tx_port, params->n_ports_out); - return -1; - } - #endif - - //Populate the static arp_route_table - lib_arp_route_table[arp_route_tbl_index].ip = - dest_ip; - lib_arp_route_table[arp_route_tbl_index].mask = - mask; - lib_arp_route_table[arp_route_tbl_index].port = - tx_port; - lib_arp_route_table[arp_route_tbl_index].nh = - nh_ip; - arp_route_tbl_index++; - token = strtok(NULL, "("); - } - - continue; - } - /*ND IPv6 */ - /* nd_route_tbl */ - if (strcmp(arg_name, "nd_route_tbl") == 0) { - nd_route_tbl_present = 1; - - uint8_t dest_ipv6[16], depth = 0, tx_port = - 0, nh_ipv6[16], i = 0, j = 0, k = 0, l = 0; - uint8_t nd_route_tbl_str_max_len = 128; //64; - char dest_ipv6_str[nd_route_tbl_str_max_len]; - char depth_str[nd_route_tbl_str_max_len]; - char tx_port_str[nd_route_tbl_str_max_len]; - char nh_ipv6_str[nd_route_tbl_str_max_len]; - char *token = strtok(arg_value, "("); - while (token) { - i = 0; - while ((i < (nd_route_tbl_str_max_len - 1)) - && (token[i] != ',')) { - dest_ipv6_str[i] = token[i]; - i++; - } - dest_ipv6_str[i] = '\0'; - my_inet_pton_ipv6(AF_INET6, dest_ipv6_str, - &dest_ipv6); - - i++; - j = 0; - while ((j < (nd_route_tbl_str_max_len - 1)) - && (token[i + j] != ',')) { - depth_str[j] = token[i + j]; - j++; - } - depth_str[j] = '\0'; - //converting string char to integer - int s; - for (s = 0; depth_str[s] != '\0'; ++s) - depth = depth * 10 + depth_str[s] - '0'; - - j++; - k = 0; - while ((k < (nd_route_tbl_str_max_len - 1)) - && (token[i + j + k] != ',')) { - tx_port_str[k] = token[i + j + k]; - k++; - } - tx_port_str[k] = '\0'; - //atoi(tx_port_str); - tx_port = strtoul(tx_port_str, NULL, 16); - - k++; - l = 0; - while ((l < (nd_route_tbl_str_max_len - 1)) - && (token[i + j + k + l] != ')')) { - nh_ipv6_str[l] = token[i + j + k + l]; - l++; - } - nh_ipv6_str[l] = '\0'; - my_inet_pton_ipv6(AF_INET6, nh_ipv6_str, - &nh_ipv6); - - //Populate the static arp_route_table - for (i = 0; i < 16; i++) { - lib_nd_route_table - [nd_route_tbl_index].ipv6[i] = - dest_ipv6[i]; - lib_nd_route_table - [nd_route_tbl_index].nhipv6[i] = - nh_ipv6[i]; - } - lib_nd_route_table[nd_route_tbl_index].depth = - depth; - lib_nd_route_table[nd_route_tbl_index].port = - tx_port; - - nd_route_tbl_index++; - token = strtok(NULL, "("); - } //while - - continue; - } - /* any other */ - - } - - #if 0 - if (!arp_meta_offset_present) { - printf("ARPICMP: arp_meta_offset not initialized\n"); - return -1; - } - #endif - - if (!arp_route_tbl_present && !nd_route_tbl_present) { - printf("Neither arp_route_tbl_present nor " - "nd_route_tbl_present declared\n"); - return -1; - } - - if (!pktq_in_prv_present) { - printf("pktq_in_prv not declared\n"); - return -1; - } - - if (!ports_mac_list_present) { - printf("ports_mac_list not declared\n"); - return -1; - } - - return 0; -} - -#endif - uint32_t arpicmp_pkt_print_count; static inline void pkt_key_arpicmp(struct rte_mbuf *pkt, uint32_t pkt_num, void *arg) @@ -2837,9 +519,6 @@ pkt_key_arpicmp(struct rte_mbuf *pkt, uint32_t pkt_num, void *arg) p_arp->receivedPktCount++; uint8_t in_port_id = pkt->port; - #ifdef VNF_ACL - struct app_link_params *link; - #endif uint8_t *protocol; uint32_t pkt_mask = 1 << pkt_num; uint32_t eth_proto_offset = MBUF_HDR_ROOM + 12; @@ -2847,20 +526,10 @@ pkt_key_arpicmp(struct rte_mbuf *pkt, uint32_t pkt_num, void *arg) uint32_t prot_offset = MBUF_HDR_ROOM + ETH_HDR_SIZE + IP_HDR_PROTOCOL_OFST; - #ifdef VNF_ACL - uint32_t out_port; - #endif - uint16_t *eth_proto = RTE_MBUF_METADATA_UINT16_PTR(pkt, eth_proto_offset); /* header room + eth hdr size + src_aadr offset in ip header */ - #ifdef VNF_ACL - uint32_t dst_addr_offset = - MBUF_HDR_ROOM + ETH_HDR_SIZE + IP_HDR_DST_ADR_OFST; - uint32_t *dst_addr = RTE_MBUF_METADATA_UINT32_PTR(pkt, dst_addr_offset); - #endif - #ifdef IPV6 uint32_t prot_offset_ipv6 = MBUF_HDR_ROOM + ETH_HDR_SIZE + IPV6_HDR_PROTOCOL_OFST; @@ -2873,7 +542,6 @@ pkt_key_arpicmp(struct rte_mbuf *pkt, uint32_t pkt_num, void *arg) protocol = RTE_MBUF_METADATA_UINT8_PTR(pkt, prot_offset); #endif - if ((ARPICMP_DEBUG > 2) && (arpicmp_pkt_print_count < 10)) { print_pkt1(pkt); arpicmp_pkt_print_count++; @@ -2883,37 +551,18 @@ pkt_key_arpicmp(struct rte_mbuf *pkt, uint32_t pkt_num, void *arg) ETH_TYPE_IPV4, IP_PROTOCOL_ICMP); } - #ifdef VNF_ACL - link = &myApp->link_params[in_port_id]; - #endif - /* Classifier for ICMP pass-through*/ if ((rte_be_to_cpu_16(*eth_proto) == ETH_TYPE_ARP) || ((rte_be_to_cpu_16(*eth_proto) == ETH_TYPE_IPV4) && (*protocol == IP_PROTOCOL_ICMP) - #ifdef VNF_ACL - && (link->ip == rte_be_to_cpu_32(*dst_addr)) - #endif )) { - - #ifdef VNF_ACL - out_port = p_arp->outport_id[in_port_id]; - process_arpicmp_pkt(pkt, out_port, pkt_mask); - #else process_arpicmp_pkt(pkt, ifm_get_port(in_port_id)); - #endif return; } #ifdef IPV6 else if ((rte_be_to_cpu_16(*eth_proto) == ETH_TYPE_IPV6) && (*protocol == ICMPV6_PROTOCOL_ID)) { - #ifdef VNF_ACL - out_port = p_arp->outport_id[in_port_id]; - process_icmpv6_pkt(pkt, out_port, pkt_mask); - #else process_icmpv6_pkt(pkt, ifm_get_port(in_port_id)); - #endif - return; } #endif @@ -2930,7 +579,6 @@ pkt4_key_arpicmp(struct rte_mbuf **pkt, uint32_t pkt_num, void *arg) struct pipeline_arpicmp_in_port_h_arg *ap = arg; struct pipeline_arpicmp *p_arp = (struct pipeline_arpicmp *)ap->p; - p_arp->receivedPktCount += 4; uint32_t eth_proto_offset = MBUF_HDR_ROOM + 12; @@ -2940,23 +588,11 @@ pkt4_key_arpicmp(struct rte_mbuf **pkt, uint32_t pkt_num, void *arg) MBUF_HDR_ROOM + ETH_HDR_SIZE + IP_HDR_PROTOCOL_OFST; /* header room + eth hdr size + src_aadr offset in ip header */ - #ifdef VNF_ACL - uint32_t dst_addr_offset = - MBUF_HDR_ROOM + ETH_HDR_SIZE + IP_HDR_DST_ADR_OFST; - #endif - uint32_t pkt_mask0 = 1 << pkt_num; uint32_t pkt_mask1 = 1 << (pkt_num + 1); uint32_t pkt_mask2 = 1 << (pkt_num + 2); uint32_t pkt_mask3 = 1 << (pkt_num + 3); - #ifdef VNF_ACL - uint32_t out_port0; - uint32_t out_port1; - uint32_t out_port2; - uint32_t out_port3; - #endif - uint16_t *eth_proto0 = RTE_MBUF_METADATA_UINT16_PTR(pkt[0], eth_proto_offset); uint16_t *eth_proto1 = @@ -2971,27 +607,6 @@ pkt4_key_arpicmp(struct rte_mbuf **pkt, uint32_t pkt_num, void *arg) uint8_t *protocol2; uint8_t *protocol3; - #ifdef VNF_ACL - uint32_t *dst_addr0 = - RTE_MBUF_METADATA_UINT32_PTR(pkt[0], dst_addr_offset); - uint32_t *dst_addr1 = - RTE_MBUF_METADATA_UINT32_PTR(pkt[1], dst_addr_offset); - uint32_t *dst_addr2 = - RTE_MBUF_METADATA_UINT32_PTR(pkt[2], dst_addr_offset); - uint32_t *dst_addr3 = - RTE_MBUF_METADATA_UINT32_PTR(pkt[3], dst_addr_offset); - - struct app_link_params *link0; - struct app_link_params *link1; - struct app_link_params *link2; - struct app_link_params *link3; - - link0 = &myApp->link_params[pkt[0]->port]; - link1 = &myApp->link_params[pkt[1]->port]; - link2 = &myApp->link_params[pkt[2]->port]; - link3 = &myApp->link_params[pkt[3]->port]; - #endif - #ifdef IPV6 uint32_t prot_offset_ipv6 = MBUF_HDR_ROOM + ETH_HDR_SIZE + IPV6_HDR_PROTOCOL_OFST; @@ -3046,30 +661,15 @@ pkt4_key_arpicmp(struct rte_mbuf **pkt, uint32_t pkt_num, void *arg) if ((rte_be_to_cpu_16(*eth_proto0) == ETH_TYPE_ARP) || ((rte_be_to_cpu_16(*eth_proto0) == ETH_TYPE_IPV4) && (*protocol0 == IP_PROTOCOL_ICMP) - #ifdef VNF_ACL - && (link0->ip == rte_be_to_cpu_32(*dst_addr0)) - #endif )) { - - #ifdef VNF_ACL - out_port0 = p_arp->outport_id[pkt[0]->port]; - process_arpicmp_pkt(pkt[0], out_port0, pkt_mask0); - #else process_arpicmp_pkt(pkt[0], ifm_get_port(in_port_id)); - #endif goto PKT1; } #ifdef IPV6 else if ((rte_be_to_cpu_16(*eth_proto0) == ETH_TYPE_IPV6) && (*protocol0 == ICMPV6_PROTOCOL_ID)) { - - #ifdef VNF_ACL - out_port0 = p_arp->outport_id[pkt[0]->port]; - process_icmpv6_pkt(pkt[0], out_port0, pkt_mask0); - #else process_icmpv6_pkt(pkt[0], ifm_get_port(in_port_id)); - #endif goto PKT1; } @@ -3092,29 +692,14 @@ PKT1: if ((rte_be_to_cpu_16(*eth_proto1) == ETH_TYPE_ARP) || ((rte_be_to_cpu_16(*eth_proto1) == ETH_TYPE_IPV4) && (*protocol1 == IP_PROTOCOL_ICMP) - #ifdef VNF_ACL - && (link1->ip == rte_be_to_cpu_32(*dst_addr1)) - #endif )) { - - #ifdef VNF_ACL - out_port1 = p_arp->outport_id[pkt[1]->port]; - process_arpicmp_pkt(pkt[1], out_port1, pkt_mask1); - #else process_arpicmp_pkt(pkt[1], ifm_get_port(in_port_id)); - #endif goto PKT2; } #ifdef IPV6 else if ((rte_be_to_cpu_16(*eth_proto1) == ETH_TYPE_IPV6) && (*protocol1 == ICMPV6_PROTOCOL_ID)) { - - #ifdef VNF_ACL - out_port1 = p_arp->outport_id[pkt[1]->port]; - process_icmpv6_pkt(pkt[1], out_port1, pkt_mask1); - #else process_icmpv6_pkt(pkt[1], ifm_get_port(in_port_id)); - #endif goto PKT2; } @@ -3137,30 +722,14 @@ PKT2: if ((rte_be_to_cpu_16(*eth_proto2) == ETH_TYPE_ARP) || ((rte_be_to_cpu_16(*eth_proto2) == ETH_TYPE_IPV4) && (*protocol2 == IP_PROTOCOL_ICMP) - #ifdef VNF_ACL - && (link2->ip == rte_be_to_cpu_32(*dst_addr2)) - #endif )) { - - #ifdef VNF_ACL - out_port2 = p_arp->outport_id[pkt[2]->port]; - process_arpicmp_pkt(pkt[2], out_port2, pkt_mask2); - #else process_arpicmp_pkt(pkt[2], ifm_get_port(in_port_id)); - #endif - goto PKT3; } #ifdef IPV6 else if ((rte_be_to_cpu_16(*eth_proto2) == ETH_TYPE_IPV6) && (*protocol2 == ICMPV6_PROTOCOL_ID)) { - - #ifdef VNF_ACL - out_port2 = p_arp->outport_id[pkt[2]->port]; - process_icmpv6_pkt(pkt[2], out_port2, pkt_mask2); - #else process_icmpv6_pkt(pkt[2], ifm_get_port(in_port_id)); - #endif goto PKT3; } @@ -3183,18 +752,9 @@ PKT3: if ((rte_be_to_cpu_16(*eth_proto3) == ETH_TYPE_ARP) || ((rte_be_to_cpu_16(*eth_proto3) == ETH_TYPE_IPV4) && (*protocol3 == IP_PROTOCOL_ICMP) - - #ifdef VNF_ACL - && (link3->ip == rte_be_to_cpu_32(*dst_addr3)) - #endif )) { - #ifdef VNF_ACL - out_port3 = p_arp->outport_id[pkt[3]->port]; - process_arpicmp_pkt(pkt[3], out_port3, pkt_mask3); - #else process_arpicmp_pkt(pkt[3], ifm_get_port(in_port_id)); - #endif return; } @@ -3202,12 +762,7 @@ PKT3: else if ((rte_be_to_cpu_16(*eth_proto3) == ETH_TYPE_IPV6) && (*protocol3 == ICMPV6_PROTOCOL_ID)) { - #ifdef VNF_ACL - out_port3 = p_arp->outport_id[pkt[3]->port]; - process_icmpv6_pkt(pkt[3], out_port3, pkt_mask3); - #else process_icmpv6_pkt(pkt[3], ifm_get_port(in_port_id)); - #endif return; } #endif @@ -3257,19 +812,7 @@ static void *pipeline_arpicmp_init(struct pipeline_params *params, p_arp->receivedPktCount = 0; p_arp->droppedPktCount = 0; -#ifdef VNF_ACL - for (i = 0; i < PIPELINE_MAX_PORT_IN; i++) - p_arp->links_map[i] = 0xff; - - p_arp->pipeline_num = 0; - - /* Parse arguments */ - if (pipeline_arpicmp_parse_args(p_arp, params)) - return NULL; -#endif - #ifndef VNF_ACL lib_arp_init(params, app); - #endif /* Pipeline */ { @@ -3438,51 +981,6 @@ static void *pipeline_arpicmp_init(struct pipeline_params *params, /* Message handlers */ memcpy(p->handlers, handlers, sizeof(p->handlers)); -#ifdef VNF_ACL - - /* create the arpicmp mbuf rx pool */ - lib_arp_pktmbuf_tx_pool = rte_pktmbuf_pool_create( - "lib_arp_mbuf_tx_pool", - NB_ARPICMP_MBUF, 32, - 0, RTE_MBUF_DEFAULT_BUF_SIZE, - rte_socket_id()); - - if (lib_arp_pktmbuf_tx_pool == NULL) { - printf("ARP mbuf pool create failed.\n"); - return NULL; - } - - lib_arp_pkt = rte_pktmbuf_alloc(lib_arp_pktmbuf_tx_pool); - if (lib_arp_pkt == NULL) { - printf("ARP lib_arp_pkt alloc failed.\n"); - return NULL; - } - - /* ARP Table */ - arp_hash_params.socket_id = rte_socket_id(); - arp_hash_params.entries = MAX_NUM_ARP_ENTRIES; - arp_hash_handle = rte_hash_create(&arp_hash_params); - - if (arp_hash_handle == NULL) { - printf("ARP rte_hash_create failed. socket %d ...\n", - arp_hash_params.socket_id); - return NULL; - } - printf("arp_hash_handle %p\n\n", (void *)arp_hash_handle); - - /* ND IPv6 */ - nd_hash_params.socket_id = rte_socket_id(); - nd_hash_params.entries = MAX_NUM_ND_ENTRIES; - nd_hash_handle = rte_hash_create(&nd_hash_params); - - if (nd_hash_handle == NULL) { - printf("ND rte_hash_create failed. socket %d ...\n", - nd_hash_params.socket_id); - return NULL; - } - - printf("nd_hash_handle %p\n\n", (void *)nd_hash_handle); -#endif return p; } diff --git a/common/VIL/pipeline_loadb/pipeline_loadb.c b/common/VIL/pipeline_loadb/pipeline_loadb.c index fdcc17ae..cd49ca5b 100644 --- a/common/VIL/pipeline_loadb/pipeline_loadb.c +++ b/common/VIL/pipeline_loadb/pipeline_loadb.c @@ -318,7 +318,7 @@ cmd_arp_req_parsed(void *parsed_result, key.filler2 = 0; key.filler3 = 0; - struct arp_entry_data *arp_data = retrieve_arp_entry(key); + struct arp_entry_data *arp_data = retrieve_arp_entry(key, STATIC_ARP); if (arp_data) { if (ARPICMP_DEBUG) @@ -399,22 +399,24 @@ struct cmd_arp_ls_result { cmdline_fixed_string_t p_string; uint32_t p; cmdline_fixed_string_t arp_string; + uint32_t ip_type; }; static void -cmd_arp_ls_parsed(__rte_unused void *parsed_result, +cmd_arp_ls_parsed(void *parsed_result, __rte_unused struct cmdline *cl, __rte_unused void *data) { - printf("\nARP table ...\n"); - printf("-------------\n"); - print_arp_table(); + struct cmd_arp_ls_result *params = parsed_result; - printf - ("............................................................\n"); - - printf("\nND IPv6 table:\n"); - printf("--------------\n"); - print_nd_table(); + if (!params->ip_type) { + printf("\nARP table ...\n"); + printf("-------------\n"); + print_arp_table(); + } else { + printf("\nND IPv6 table:\n"); + printf("--------------\n"); + print_nd_table(); + } } static cmdline_parse_token_string_t cmd_arp_ls_p_string = @@ -428,6 +430,9 @@ static cmdline_parse_token_string_t cmd_arp_ls_arp_string = TOKEN_STRING_INITIALIZER(struct cmd_arp_ls_result, arp_string, "arpls"); +static cmdline_parse_token_num_t cmd_arp_ls_ip_type = +TOKEN_NUM_INITIALIZER(struct cmd_arp_ls_result, ip_type, UINT32); + static cmdline_parse_inst_t cmd_arp_ls = { .f = cmd_arp_ls_parsed, .data = NULL, @@ -436,6 +441,7 @@ static cmdline_parse_inst_t cmd_arp_ls = { (void *)&cmd_arp_ls_p_string, (void *)&cmd_arp_ls_p, (void *)&cmd_arp_ls_arp_string, + (void *)&cmd_arp_ls_ip_type, NULL, }, }; diff --git a/common/VIL/pipeline_txrx/pipeline_txrx_be.c b/common/VIL/pipeline_txrx/pipeline_txrx_be.c index 9e7645dd..b47ee98e 100644 --- a/common/VIL/pipeline_txrx/pipeline_txrx_be.c +++ b/common/VIL/pipeline_txrx/pipeline_txrx_be.c @@ -37,6 +37,7 @@ uint8_t TXRX_DEBUG; int pkt_burst_cnt; + struct pipeline_txrx { struct pipeline p; pipeline_msg_req_handler @@ -55,7 +56,6 @@ TYPE_RXRX, }; static void *pipeline_txrx_msg_req_custom_handler(struct pipeline *p, void *msg); - static pipeline_msg_req_handler handlers[] = { [PIPELINE_MSG_REQ_PING] = pipeline_msg_req_ping_handler, @@ -240,7 +240,7 @@ pkt_work_txrx(struct rte_mbuf *pkt, uint32_t pkt_num, void *arg) case ETH_TYPE_ARP: rte_pipeline_port_out_packet_insert(p_txrx->p.p, out_port, pkt); - rte_pipeline_ah_packet_drop(p_txrx->p.p, pkt_mask); + rte_pipeline_ah_packet_hijack(p_txrx->p.p, pkt_mask); break; case ETH_TYPE_IPV4: @@ -261,19 +261,15 @@ pkt_work_txrx(struct rte_mbuf *pkt, uint32_t pkt_num, void *arg) #ifdef IPV6 case ETH_TYPE_IPV6: if (*protocol == ICMPV6_PROTOCOL_ID) { - #ifndef VNF_ACL if (!memcmp(ipv6_h->dst_addr, link->ipv6, 16) || !memcmp(ipv6_h->dst_addr, solicited_node_multicast_addr, 13)) { - #endif rte_pipeline_port_out_packet_insert(p_txrx->p.p, out_port, pkt); rte_pipeline_ah_packet_drop(p_txrx->p.p, pkt_mask); - #ifndef VNF_ACL } else { printf("Dropping the IPv6 pkt\n"); rte_pipeline_ah_packet_drop(p_txrx->p.p, pkt_mask); } - #endif } break; #endif @@ -395,7 +391,7 @@ pkt4_work_txrx(struct rte_mbuf **pkt, uint32_t pkt_num, void *arg) case ETH_TYPE_ARP: rte_pipeline_port_out_packet_insert(p_txrx->p.p, out_port, pkt[0]); - rte_pipeline_ah_packet_drop(p_txrx->p.p, pkt_mask0); + rte_pipeline_ah_packet_hijack(p_txrx->p.p, pkt_mask0); break; case ETH_TYPE_IPV4: @@ -414,20 +410,15 @@ pkt4_work_txrx(struct rte_mbuf **pkt, uint32_t pkt_num, void *arg) #ifdef IPV6 case ETH_TYPE_IPV6: if (*protocol0 == ICMPV6_PROTOCOL_ID) { - #ifndef VNF_ACL if (!memcmp(ipv6_h0->dst_addr, link->ipv6, 16) || !memcmp(ipv6_h0->dst_addr, solicited_node_multicast_addr, 13)) { - #endif rte_pipeline_port_out_packet_insert(p_txrx->p.p, out_port, pkt[0]); rte_pipeline_ah_packet_drop(p_txrx->p.p, pkt_mask0); - #ifndef VNF_ACL } else { - printf("Dropping the IPv6 pkt\n"); rte_pipeline_ah_packet_drop(p_txrx->p.p, pkt_mask0); } - #endif } break; #endif @@ -461,7 +452,7 @@ pkt4_work_txrx(struct rte_mbuf **pkt, uint32_t pkt_num, void *arg) case ETH_TYPE_ARP: rte_pipeline_port_out_packet_insert(p_txrx->p.p, out_port, pkt[1]); - rte_pipeline_ah_packet_drop(p_txrx->p.p, pkt_mask1); + rte_pipeline_ah_packet_hijack(p_txrx->p.p, pkt_mask1); break; case ETH_TYPE_IPV4: @@ -527,7 +518,7 @@ pkt4_work_txrx(struct rte_mbuf **pkt, uint32_t pkt_num, void *arg) case ETH_TYPE_ARP: rte_pipeline_port_out_packet_insert(p_txrx->p.p, out_port, pkt[2]); - rte_pipeline_ah_packet_drop(p_txrx->p.p, pkt_mask2); + rte_pipeline_ah_packet_hijack(p_txrx->p.p, pkt_mask2); break; case ETH_TYPE_IPV4: @@ -593,7 +584,7 @@ pkt4_work_txrx(struct rte_mbuf **pkt, uint32_t pkt_num, void *arg) case ETH_TYPE_ARP: rte_pipeline_port_out_packet_insert(p_txrx->p.p, out_port, pkt[3]); - rte_pipeline_ah_packet_drop(p_txrx->p.p, pkt_mask3); + rte_pipeline_ah_packet_hijack(p_txrx->p.p, pkt_mask3); break; case ETH_TYPE_IPV4: diff --git a/common/vnf_common/vnf_common.c b/common/vnf_common/vnf_common.c index 6ce815be..a40d4d84 100644 --- a/common/vnf_common/vnf_common.c +++ b/common/vnf_common/vnf_common.c @@ -47,12 +47,13 @@ uint8_t is_port_index_privte(uint16_t phy_port) uint32_t get_prv_to_pub_port(uint32_t *ip_addr, uint8_t type) { uint32_t dest_if = 0xff; + struct ether_addr addr; switch (type) { case 4: { uint32_t nhip; - nhip = get_nh(ip_addr[0], &dest_if); + nhip = get_nh(ip_addr[0], &dest_if, &addr); if (nhip) return dest_if; @@ -75,12 +76,13 @@ uint32_t get_prv_to_pub_port(uint32_t *ip_addr, uint8_t type) uint32_t get_pub_to_prv_port(uint32_t *ip_addr, uint8_t type) { uint32_t dest_if = 0xff; + struct ether_addr addr; switch (type) { case 4: { uint32_t nhip; - nhip = get_nh(ip_addr[0], &dest_if); + nhip = get_nh(ip_addr[0], &dest_if, &addr); if (nhip) return dest_if; |