#include "vnf_common.h"
#include "lib_sip_alg.h"
#include "lib_icmpv6.h"
+#include "gateway.h"
#include "pipeline_common_fe.h"
#ifdef CT_CGNAT
/* 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;
/* To know egress or ingress port */
static uint8_t cgnapt_in_port_egress_prv[PIPELINE_MAX_PORT_IN];
};
/***** 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
0x00, 0x00, 0x00, 0x00
};
-static uint32_t local_get_nh_ipv4(
- uint32_t ip,
- 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);
-
-static uint32_t local_get_nh_ipv6(
- uint8_t *ip,
- uint32_t *port,
- uint8_t nhip[],
- struct pipeline_cgnapt *p_nat);
-
-static void do_local_nh_ipv6_cache(
- uint32_t dest_if,
- struct pipeline_cgnapt *p_nat);
-
static uint8_t check_arp_icmp(
struct rte_mbuf *pkt,
uint64_t pkt_mask,
return n;
}
-/**
- * Function to get MAC addr of local link
- *
- * @params out_port
- * Physical port number
- *
- * @return
- * Outport Link MAC addr
- */
-
-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
- *
- * @params out_port
- * Physical port number
- *
- * @return
- * Outport Link MAC addr
- */
-
-uint8_t local_dest_mac_present(uint8_t out_port)
-{
- return link_hw_laddr_valid[out_port];
-}
-
-/**
- * Function to get IPv4-IP NH from thread local array
- *
- * @params ip
- * IPv4 - IP
- * @params port
- * NH port number
- * @params nhip
- * NHIP of IPv4 type
- * @params p_nat
- * CGNAPT pipeline ptr
- *
- * @return
- * 1 on success, 0 for failure
- */
-
-static uint32_t local_get_nh_ipv4(
- uint32_t ip,
- uint32_t *port,
- uint32_t *nhip,
- struct pipeline_cgnapt *p_nat)
-{
- int i;
- for (i = 0; i < p_nat->local_lib_arp_route_ent_cnt; i++) {
- if (((p_nat->local_lib_arp_route_table[i].ip &
- p_nat->local_lib_arp_route_table[i].mask) ==
- (ip & p_nat->local_lib_arp_route_table[i].mask))) {
- *port = p_nat->local_lib_arp_route_table[i].port;
-
- *nhip = p_nat->local_lib_arp_route_table[i].nh;
- return 1;
- }
- }
- return 0;
-}
-
-/**
- * Function to make local copy for NH of type IPv4
- *
- * @params dest_if
- * Physical port number
- * @params p_nat
- * CGNAPT pipeline ptr
- *
- */
-
-static void do_local_nh_ipv4_cache(
- uint32_t dest_if,
- struct pipeline_cgnapt *p_nat)
-{
-
- /* Search for the entry and do local copy */
- int i;
-
- for (i = 0; i < MAX_ARP_RT_ENTRY; i++) {
- if (lib_arp_route_table[i].port == dest_if) {
-
- struct lib_arp_route_table_entry *lentry =
- &p_nat->local_lib_arp_route_table
- [p_nat->local_lib_arp_route_ent_cnt];
-
- lentry->ip = lib_arp_route_table[i].ip;
- lentry->mask = lib_arp_route_table[i].mask;
- lentry->port = lib_arp_route_table[i].port;
- lentry->nh = lib_arp_route_table[i].nh;
-
- p_nat->local_lib_arp_route_ent_cnt++;
- break;
- }
- }
-}
-
-
-/**
- * Function to get IPv6-IP NH from thread local array
- *
- * @params ip
- * Pointer to starting addr of IPv6
- * @params port
- * NH port number
- * @params nhip
- * NHIP of IPv6 type
- * @params p_nat
- * CGNAPT pipeline ptr
- *
- * @return
- * 1 on success, 0 for failure
- */
-
-static uint32_t local_get_nh_ipv6(
- uint8_t *ip,
- uint32_t *port,
- uint8_t nhip[],
- struct pipeline_cgnapt *p_nat)
-{
- int i = 0;
- uint8_t netmask_ipv6[16];
- uint8_t k = 0, l = 0, depthflags = 0, depthflags1 = 0;
-
- for (i = 0; i < p_nat->local_lib_nd_route_ent_cnt; i++) {
-
- convert_prefixlen_to_netmask_ipv6(
- p_nat->local_lib_nd_route_table[i].depth,
- netmask_ipv6);
-
- for (k = 0; k < 16; k++)
- if (p_nat->local_lib_nd_route_table[i].ipv6[k] &
- netmask_ipv6[k])
- depthflags++;
-
- for (l = 0; l < 16; l++)
- if (ip[l] & netmask_ipv6[l])
- depthflags1++;
-
- int j = 0;
- if (depthflags == depthflags1) {
- *port = p_nat->local_lib_nd_route_table[i].port;
-
- for (j = 0; j < 16; j++)
- nhip[j] = p_nat->local_lib_nd_route_table[i].
- nhipv6[j];
- return 1;
- }
-
- depthflags = 0;
- depthflags1 = 0;
- }
- return 0;
-}
-
-
-/**
- * Function to make local copy for NH of type IPv6
- *
- * @params dest_if
- * Physical port number
- * @params p_nat
- * CGNAPT pipeline ptr
- *
- */
-
-static void do_local_nh_ipv6_cache(
- uint32_t dest_if,
- struct pipeline_cgnapt *p_nat)
-{
- /* Search for the entry and do local copy */
- int i, l;
- for (i = 0; i < MAX_ND_RT_ENTRY; i++) {
-
- if (lib_nd_route_table[i].port == dest_if) {
-
- struct lib_nd_route_table_entry *lentry =
- &p_nat->local_lib_nd_route_table
- [p_nat->local_lib_nd_route_ent_cnt];
-
- for (l = 0; l < 16; l++) {
- lentry->ipv6[l] =
- lib_nd_route_table[i].ipv6[l];
- lentry->nhipv6[l] =
- lib_nd_route_table[i].nhipv6[l];
- }
- lentry->depth = lib_nd_route_table[i].depth;
- lentry->port = lib_nd_route_table[i].port;
-
- p_nat->local_lib_nd_route_ent_cnt++;
- break;
- } //if
- } //for
-}
-
#ifdef SIP_ALG
/* Commented code may be required for future usage, Please keep it*/
#if 0
prot_offset = PROT_OFST_IP4 + temp;
break;
default:
- printf("hw_checksum: pkt version is invalid\n");
+ printf("hw_checksum: pkt version is invalid\n");
}
protocol = (uint8_t *) RTE_MBUF_METADATA_UINT8_PTR(pkt,
prot_offset);
break;
default:
- printf("hw_checksum() : Neither TCP or UDP pkt\n");
+ #ifdef CGNAPT_DEBUGGING
+ printf("hw_checksum() : Neither TCP or UDP pkt\n");
+ #endif
break;
}
}
prot_offset = PROT_OFST_IP4 + temp;
break;
default:
- printf("sw_checksum: pkt version is invalid\n");
+ printf("sw_checksum: pkt version is invalid\n");
}
protocol = (uint8_t *) RTE_MBUF_METADATA_UINT8_PTR(pkt,
prot_offset);
break;
default:
- printf("sw_checksum() : Neither TCP or UDP pkt\n");
+ #ifdef CGNAPT_DEBUGGING
+ printf("sw_checksum() : Neither TCP or UDP pkt\n");
+ #endif
break;
}
}
+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,
/* ARP outport number */
uint16_t out_port = p_nat->p.n_ports_out - 1;
-
uint8_t *protocol;
uint32_t prot_offset;
uint32_t vnf_set_num = p_nat->vnf_set;
/*uint32_t vnf_set_num = get_vnf_set_num(p_nat->pipeline_num); */
- printf("VNF set number for CGNAPT %d is %d.\n", p_nat->pipeline_num,
- vnf_set_num);
+ #ifdef CGNAPT_DBG_PRNT
+ printf("VNF set number for CGNAPT %d is %d.\n", p_nat->pipeline_num,
+ vnf_set_num);
+ #endif
if (vnf_set_num == 0xFF) {
printf("VNF set number for CGNAPT %d is invalid %d.\n",
p_nat->pipeline_num, vnf_set_num);
* @return
* int that is not checked by caller
*/
-
static int cgnapt_in_port_ah_mix(struct rte_pipeline *rte_p,
struct rte_mbuf **pkts,
uint32_t n_pkts, void *arg)
uint8_t nh_ipv6[16];
uint32_t nhip = 0;
- uint32_t dest_if = 0xff;
+ uint32_t dest_if = INVALID_DESTIF;
uint32_t ret;
uint16_t *outport_id =
&& rte_be_to_cpu_16(*dst_port) == 53) {
p_nat->invalid_packets |= 1LLU << pkt_index;
p_nat->naptDroppedPktCount++;
- #ifdef CGNAPT_DEBUGGING
+#ifdef CGNAPT_DEBUGGING
p_nat->naptDroppedPktCount6++;
- #endif
+#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 |=
- 1LLU << pkt_index;
- p_nat->naptDroppedPktCount++;
- #ifdef CGNAPT_DEBUGGING
- p_nat->naptDroppedPktCount6++;
- #endif
- continue;
- }
- do_local_nh_ipv4_cache(dest_if, p_nat);
+ /* Gateway Proc Starts */
+
+ struct arp_entry_data *ret_arp_data = NULL;
+ uint32_t src_phy_port = *src_port;
+
+ gw_get_nh_port_ipv4(dest_address,
+ &dest_if, &nhip);
+
+ if (dest_if == INVALID_DESTIF) {
+ p_nat->invalid_packets |=
+ 1LLU << pkt_index;
+ p_nat->naptDroppedPktCount++;
+#ifdef CGNAPT_DEBUGGING
+ p_nat->naptDroppedPktCount6++;
+#endif
+ continue;
}
- *outport_id = p_nat->outport_id[dest_if];
- int ret;
- ret = get_dest_mac_addr_port(dest_address,
- &dest_if, &hw_addr);
+ *outport_id = p_nat->outport_id[dest_if];
+
+ ret_arp_data = get_dest_mac_addr_ipv4(nhip, dest_if, &hw_addr);
+
+ if (unlikely(ret_arp_data == NULL)) {
+
+ #ifdef CGNAPT_DEBUGGING
+ printf("%s: NHIP Not Found, nhip: %x, "
+ "outport_id: %d\n", __func__, nhip,
+ *outport_id);
+ #endif
+ /* Drop the pkt */
+ p_nat->invalid_packets |= pkt_mask;
+ p_nat->naptDroppedPktCount++;
+
+ #ifdef CGNAPT_DEBUGGING
+ p_nat->naptDroppedPktCount4++;
+ #endif
+ continue;
+ }
+
+ /* Gateway Proc Ends */
+
+ 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),
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
memcpy((uint8_t *) &dst_addr[0],
&entry->data.u.prv_ipv6[0], 16);
memset(nh_ipv6, 0, 16);
+ struct nd_entry_data *ret_nd_data = NULL;
- ret = local_get_nh_ipv6((uint8_t *)&dst_addr[0],
- &dest_if, &nh_ipv6[0], p_nat);
+ dest_if = INVALID_DESTIF;
- if (!ret) {
- dest_if = get_prv_to_pub_port(
- &dst_addr[0],
- IP_VERSION_6);
- if (dest_if == INVALID_DESTIF) {
- p_nat->invalid_packets |=
- 1LLU << pkt_index;
+ uint32_t src_phy_port = pkts[pkt_index]->port;
+
+ gw_get_nh_port_ipv6((uint8_t *) &dst_addr[0],
+ &dest_if, &nh_ipv6[0]);
+
+ ret_nd_data = get_dest_mac_addr_ipv6(&nh_ipv6[0],
+ dest_if, &hw_addr);
+ *outport_id = p_nat->outport_id[dest_if];
+
+ if (nd_cache_dest_mac_present(dest_if)) {
+ ether_addr_copy(get_link_hw_addr(dest_if),
+ (struct ether_addr *)eth_src);
+ update_nhip_access(dest_if);
+
+ if (unlikely(ret_nd_data && ret_nd_data->num_pkts)) {
+ p_nat->naptedPktCount += ret_nd_data->num_pkts;
+ nd_send_buffered_pkts(ret_nd_data,
+ (struct ether_addr *)eth_dest,
+ *outport_id);
+ }
+ } else {
+ if (unlikely(ret_nd_data == NULL)) {
+
+ #ifdef CGNAPT_DEBUGGING
+ printf("%s: NHIP Not Found, "
+ "outport_id: %d\n", __func__,
+ *outport_id);
+ #endif
+
+ /* Drop the pkt */
+ p_nat->invalid_packets |= pkt_mask;
p_nat->naptDroppedPktCount++;
+
#ifdef CGNAPT_DEBUGGING
- p_nat->naptDroppedPktCount6++;
+ p_nat->naptDroppedPktCount4++;
#endif
continue;
}
- do_local_nh_ipv6_cache(dest_if, p_nat);
- }
- *outport_id = p_nat->outport_id[dest_if];
-
- if (get_dest_mac_address_ipv6_port((uint8_t *)
- &dst_addr[0], &dest_if,
- &hw_addr, &nh_ipv6[0])){
-
- #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]);
+ if (ret_nd_data->status == INCOMPLETE ||
+ ret_nd_data->status == PROBE) {
+ if (ret_nd_data->num_pkts >= NUM_DESC) {
+ /* Drop the pkt */
+ p_nat->invalid_packets |= pkt_mask;
+ p_nat->naptDroppedPktCount++;
+
+ #ifdef CGNAPT_DEBUGGING
+ p_nat->naptDroppedPktCount4++;
+ #endif
+ continue;
+ } else {
+ arp_pkts_mask |= pkt_mask;
+ nd_queue_unresolved_packet(ret_nd_data,
+ pkts[pkt_index]);
+ continue;
+ }
}
- #endif
- 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("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 > 4)
- print_pkt(pkts[pkt_index]);
- #endif
- } else {
-
- p_nat->invalid_packets |= pkt_mask;
- p_nat->naptDroppedPktCount++;
- #ifdef CGNAPT_DEBUGGING
- p_nat->naptDroppedPktCount4++;
- #endif
- continue;
}
#ifdef NAT_ONLY_CONFIG_REQ
} else {
*dst_addr = rte_bswap32(entry->data.u.prv_ip);
dest_address = entry->data.u.prv_ip;
- ret = local_get_nh_ipv4(dest_address, &dest_if,
- &nhip, p_nat);
- if (!ret) {
- dest_if = get_pub_to_prv_port(
- &dest_address, IP_VERSION_4);
+ /* Gateway Proc Starts */
+
+ struct arp_entry_data *ret_arp_data = NULL;
+ dest_if = INVALID_DESTIF;
+ uint32_t src_phy_port = *src_port;
+
+ gw_get_nh_port_ipv4(dest_address,
+ &dest_if, &nhip);
+
if (dest_if == INVALID_DESTIF) {
p_nat->invalid_packets |=
1LLU << pkt_index;
p_nat->naptDroppedPktCount++;
- #ifdef CGNAPT_DEBUGGING
+#ifdef CGNAPT_DEBUGGING
p_nat->naptDroppedPktCount6++;
- #endif
+#endif
continue;
}
- do_local_nh_ipv4_cache(dest_if, p_nat);
- };
*outport_id = p_nat->outport_id[dest_if];
- int ret;
- ret = get_dest_mac_addr_port(dest_address,
- &dest_if, &hw_addr);
- if (ret == ARP_FOUND) {
+ ret_arp_data = get_dest_mac_addr_ipv4(nhip,
+ dest_if, (struct ether_addr *)eth_dest);
+
+ if (unlikely(ret_arp_data == NULL)) {
+
+#ifdef CGNAPT_DEBUGGING
+ printf("%s: NHIP Not Found, nhip: %x, "
+ "outport_id: %d\n", __func__, nhip,
+ *outport_id);
+#endif
+ /* Drop the pkt */
+ p_nat->invalid_packets |= pkt_mask;
+ p_nat->naptDroppedPktCount++;
+
+#ifdef CGNAPT_DEBUGGING
+ p_nat->naptDroppedPktCount4++;
+#endif
+ continue;
+ }
+
+ /* Gateway Proc Ends */
+
+ 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);
+ }
+
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
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);
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;
}
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);
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);
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;
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);
* A pointer to main CGNAPT structure
*
*/
+uint64_t last_update;
void
pkt_work_cgnapt_ipv4_prv(
struct rte_mbuf **pkts,
uint8_t protocol = RTE_MBUF_METADATA_UINT8(pkt, PROT_OFST_IP4);
- uint32_t dest_if = 0xff; /* Added for Multiport */
+ uint32_t dest_if = INVALID_DESTIF; /* Added for Multiport */
uint16_t *outport_id =
RTE_MBUF_METADATA_UINT16_PTR(pkt, cgnapt_meta_offset);
if (entry->data.ttl == NAPT_ENTRY_STALE)
entry->data.ttl = NAPT_ENTRY_VALID;
- struct ether_addr hw_addr;
uint32_t dest_address = 0;
/* Egress */
#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);
+ struct arp_entry_data *ret_arp_data = NULL;
- if (dest_if == INVALID_DESTIF) {
- p_nat->invalid_packets |= pkt_mask;
- p_nat->naptDroppedPktCount++;
- #ifdef CGNAPT_DEBUGGING
- p_nat->naptDroppedPktCount6++;
- #endif
- return;
- }
+ uint32_t src_phy_port = *src_port;
- do_local_nh_ipv4_cache(dest_if, p_nat);
- }
+ gw_get_nh_port_ipv4(dest_address, &dest_if, &nhip);
+
+ ret_arp_data = get_dest_mac_addr_ipv4(nhip, 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);
+ update_nhip_access(dest_if);
+ if (unlikely(ret_arp_data && ret_arp_data->num_pkts)) {
+ 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)) {
- //request_arp(*outport_id, nhip, p_nat->p.p);
- printf("%s: ARP Not Found, nhip: %x, "
- "outport_id: %d\n", __func__, nhip,
- *outport_id);
- }
+ #ifdef CGNAPT_DEBUGGING
+ printf("%s: NHIP Not Found, nhip:%x , "
+ "outport_id: %d\n", __func__, nhip,
+ *outport_id);
+ #endif
/* Drop the pkt */
p_nat->invalid_packets |= pkt_mask;
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));
}
{
uint8_t protocol = RTE_MBUF_METADATA_UINT8(pkt, PROT_OFST_IP4);
- uint32_t dest_if = 0xff; /* Added for Multiport */
+ uint32_t dest_if = INVALID_DESTIF; /* Added for Multiport */
uint16_t *outport_id =
RTE_MBUF_METADATA_UINT16_PTR(pkt, cgnapt_meta_offset);
if (entry->data.ttl == NAPT_ENTRY_STALE)
entry->data.ttl = NAPT_ENTRY_VALID;
- struct ether_addr hw_addr;
uint32_t dest_address = 0;
/* Multiport Changes */
#endif
return;
}
+ }
dest_address = entry->data.u.prv_ip;
+ struct arp_entry_data *ret_arp_data = NULL;
- 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);
+ uint32_t src_phy_port = *src_port;
- if (dest_if == INVALID_DESTIF) {
- p_nat->invalid_packets |= pkt_mask;
- p_nat->naptDroppedPktCount++;
- #ifdef CGNAPT_DEBUGGING
- p_nat->naptDroppedPktCount6++;
- #endif
- return;
- }
+ gw_get_nh_port_ipv4(dest_address, &dest_if, &nhip);
- do_local_nh_ipv4_cache(dest_if, p_nat);
- }
+ ret_arp_data = get_dest_mac_addr_ipv4(nhip, dest_if,
+ (struct ether_addr *)eth_dest);
+ *outport_id = p_nat->outport_id[dest_if];
- *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);
+ update_nhip_access(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 (ret_arp_data && ret_arp_data->num_pkts) {
+ 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)) {
- /* 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);
+ /* Commented code may be required for debug
+ * and future use, Please keep it */
- }
+ #ifdef CGNAPT_DEBUGGING
+ printf("%s: NHIP Not Found, nhip: %x, "
+ "outport_id: %d\n", __func__, nhip,
+ *outport_id);
+ #endif
/* Drop the pkt */
p_nat->invalid_packets |= pkt_mask;
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));
}
{
if (ct_position < 0){
p_nat->invalid_packets |= pkt_mask;
- p_nat->naptDroppedPktCount++;
+ p_nat->naptDroppedPktCount++;
return;
}
#ifdef ALGDBG
__rte_unused void *arg,
struct pipeline_cgnapt *p_nat)
{
- uint32_t dest_if = 0xff; /* Added for Multiport */
+ uint32_t dest_if = INVALID_DESTIF; /* Added for Multiport */
struct rte_mbuf *pkt;
uint8_t i;
uint8_t pkt_num;
if (entry->data.ttl == NAPT_ENTRY_STALE)
entry->data.ttl = NAPT_ENTRY_VALID;
- struct ether_addr hw_addr;
uint32_t dest_address = 0;
/*Multiport Changes */
uint32_t nhip = 0;
#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;
+ uint32_t src_phy_port = *src_port;
+
+ gw_get_nh_port_ipv4(dest_address, &dest_if, &nhip);
+
+ ret_arp_data = get_dest_mac_addr_ipv4(nhip, 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);
+ update_nhip_access(dest_if);
+
+ if (ret_arp_data && ret_arp_data->num_pkts) {
+ 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)) {
+ #ifdef CGNAPT_DEBUGGING
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++;
+ #endif
- #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));
}
{
uint8_t protocol = RTE_MBUF_METADATA_UINT8(pkt, PROT_OFST_IP4);
- uint32_t dest_if = 0xff; /* Added for Multiport */
+ uint32_t dest_if = INVALID_DESTIF; /* Added for Multiport */
uint16_t *outport_id =
RTE_MBUF_METADATA_UINT16_PTR(pkt, cgnapt_meta_offset);
#ifdef CGNAPT_DEBUGGING
p_nat->naptDroppedPktCount3++;
#endif
-
continue;
}
if (entry->data.ttl == NAPT_ENTRY_STALE)
entry->data.ttl = NAPT_ENTRY_VALID;
- struct ether_addr hw_addr;
uint32_t dest_address = 0;
/* Multiport Changes */
uint32_t nhip = 0;
#endif
continue;
}
+ }
+ dest_address = entry->data.u.prv_ip;
+ struct arp_entry_data *ret_arp_data = NULL;
+ uint32_t src_phy_port = *src_port;
- 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);
+ gw_get_nh_port_ipv4(dest_address, &dest_if, &nhip);
- if (dest_if == INVALID_DESTIF) {
- p_nat->invalid_packets |= pkt_mask;
- p_nat->naptDroppedPktCount++;
- #ifdef CGNAPT_DEBUGGING
- p_nat->naptDroppedPktCount6++;
- #endif
- continue;
- }
+ ret_arp_data = get_dest_mac_addr_ipv4(nhip, dest_if,
+ (struct ether_addr *)eth_dest);
- do_local_nh_ipv4_cache(dest_if, p_nat);
- }
+ *outport_id = p_nat->outport_id[dest_if];
- *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);
+ update_nhip_access(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 (ret_arp_data && ret_arp_data->num_pkts) {
+ 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);
- }
+ #ifdef CGNAPT_DEBUGGING
+ printf("%s: NHIP Not Found, nhip: %x, "
+ "outport_id: %d\n", __func__, nhip,
+ *outport_id);
+ #endif
/* Drop the pkt */
p_nat->invalid_packets |= pkt_mask;
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 */
__rte_unused void *arg,
struct pipeline_cgnapt *p_nat)
{
-
/* index into hash table entries */
int hash_table_entry = p_nat->lkup_indx[pkt_num];
struct ipv6_hdr ipv6_hdr;
- struct ether_addr hw_addr;
uint32_t dest_address = 0;
uint32_t nhip = 0;
/* Egress */
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);
- }
- *outport_id = p_nat->outport_id[dest_if];
#ifdef CGNAPT_DBG_PRNT
if (CGNAPT_DEBUG > 2)
}
#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));
+ struct arp_entry_data *ret_arp_data;
+
+ uint32_t src_phy_port = *src_port;
+
+ gw_get_nh_port_ipv4(dest_address, &dest_if, &nhip);
+
+ ret_arp_data = get_dest_mac_addr_ipv4(nhip, 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);
+ update_nhip_access(dest_if);
+
+ if (unlikely(ret_arp_data && ret_arp_data->num_pkts)) {
+ 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)) {
- printf("%s: ARP Not Found, nhip: %x, "
- "outport_id: %d\n", __func__, nhip,
- *outport_id);
- //request_arp(*outport_id, nhip, p_nat->p.p);
- }
+ #ifdef CGNAPT_DEBUGGING
+ printf("%s: NHIP Not Found, nhip:%x , "
+ "outport_id: %d\n", __func__, nhip,
+ *outport_id);
+ #endif
/* Drop the pkt */
p_nat->invalid_packets |= pkt_mask;
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));
+ 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));
}
{
#endif
return;
}
+ }
+ memcpy(&dest_addr_ipv6[0], &entry->data.u.prv_ipv6[0], 16);
+ uint8_t nhipv6[16];
- memcpy(&dest_addr_ipv6[0], &entry->data.u.prv_ipv6[0], 16);
- uint8_t nhipv6[16];
- int ret;
- ret = local_get_nh_ipv6(&dest_addr_ipv6[0], &dest_if,
- &nhipv6[0], p_nat);
- if (!ret) {
- dest_if = get_prv_to_pub_port((uint32_t *)
- &dest_addr_ipv6[0],
- IP_VERSION_6);
-
- if (dest_if == INVALID_DESTIF) {
- p_nat->invalid_packets |= pkt_mask;
- p_nat->naptDroppedPktCount++;
- #ifdef CGNAPT_DEBUGGING
- p_nat->naptDroppedPktCount6++;
- #endif
- return;
- }
+ memset(nh_ipv6, 0, 16);
+ struct nd_entry_data *ret_nd_data = NULL;
- do_local_nh_ipv6_cache(dest_if, p_nat);
- }
- *outport_id = p_nat->outport_id[dest_if];
- }
+ dest_if = INVALID_DESTIF;
- #ifdef CGNAPT_DEBUGGING
- static int static_count;
+ uint32_t src_phy_port = pkt->port;
- if (static_count++ < 10) {
- print_pkt(pkt);
- my_print_entry(entry);
- printf("dest-offset:%d\n", DST_ADR_OFST_IP4);
- printf("dest_add:%x\n", entry->data.u.prv_ip);
- printf("DST_ADR_OFST_IP6:%d\n", DST_ADR_OFST_IP6);
- }
- #endif
+ gw_get_nh_port_ipv6((uint8_t *) &dest_addr_ipv6[0],
+ &dest_if, &nh_ipv6[0]);
- memset(nh_ipv6, 0, 16);
- if (get_dest_mac_address_ipv6_port(
- &dest_addr_ipv6[0],
- &dest_if,
- &hw_addr,
- &nh_ipv6[0])) {
+ ret_nd_data = get_dest_mac_addr_ipv6(&nh_ipv6[0],
+ dest_if, (struct ether_addr *)eth_dest);
+
+ *outport_id = p_nat->outport_id[dest_if];
+
+ if (nd_cache_dest_mac_present(dest_if)) {
+ ether_addr_copy(get_link_hw_addr(dest_if),
+ (struct ether_addr *)eth_src);
+ update_nhip_access(dest_if);
+
+ if (unlikely(ret_nd_data && ret_nd_data->num_pkts)) {
+ p_nat->naptedPktCount += ret_nd_data->num_pkts;
+ nd_send_buffered_pkts(ret_nd_data,
+ (struct ether_addr *)eth_dest, *outport_id);
- #ifdef CGNAPT_DBG_PRNT
- if (CGNAPT_DEBUG > 2) {
- printf("MAC found for ip 0x%x, port %d - "
- "%02x:%02x:%02x:%02x:%02x:%02x\n",
- *((uint32_t *)dest_addr_ipv6 + 12),
- *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
+ } else {
+ if (unlikely(ret_nd_data == NULL)) {
- memcpy(eth_dest, &hw_addr, sizeof(struct ether_addr));
+ #ifdef CGNAPT_DEBUGGING
+ printf("%s: NHIP Not Found, "
+ "outport_id: %d\n", __func__,
+ *outport_id);
+ #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]);
+ /* Drop the pkt */
+ p_nat->invalid_packets |= pkt_mask;
+ p_nat->naptDroppedPktCount++;
+
+ #ifdef CGNAPT_DEBUGGING
+ p_nat->naptDroppedPktCount4++;
+ #endif
+ return;
}
- #endif
- memcpy(eth_src, get_link_hw_addr(dest_if),
- sizeof(struct ether_addr));
- } else {
- p_nat->invalid_packets |= pkt_mask;
- p_nat->naptDroppedPktCount++;
+ if (ret_nd_data->status == INCOMPLETE ||
+ ret_nd_data->status == PROBE) {
+ if (ret_nd_data->num_pkts >= NUM_DESC) {
+ /* Drop the pkt */
+ p_nat->invalid_packets |= pkt_mask;
+ p_nat->naptDroppedPktCount++;
- #ifdef CGNAPT_DEBUGGING
- p_nat->naptDroppedPktCount4++;
- #endif
+ #ifdef CGNAPT_DEBUGGING
+ p_nat->naptDroppedPktCount4++;
+ #endif
+ return;
+ } else {
+ arp_pkts_mask |= pkt_mask;
+ nd_queue_unresolved_packet(ret_nd_data, pkt);
+ return;
+ }
+ }
- return;
}
+
/* Ingress */
{
p_nat->entries[pkt_num] = &(entry->head);
struct ipv6_hdr ipv6_hdr;
- struct ether_addr hw_addr;
uint32_t dest_address = 0;
uint8_t nh_ipv6[16];
uint32_t nhip = 0;
dest_address = rte_bswap32(*dst_addr);
uint32_t nhip;
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
- 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"
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;
+ uint32_t src_phy_port = *src_port;
- if (unlikely(ret != ARP_FOUND)) {
+ gw_get_nh_port_ipv4(dest_address, &dest_if, &nhip);
- 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);
- }
+ ret_arp_data = get_dest_mac_addr_ipv4(nhip, dest_if,
+ (struct ether_addr *)eth_dest);
+ *outport_id = p_nat->outport_id[dest_if];
- /* Drop the pkt */
- p_nat->invalid_packets |= pkt_mask;
- p_nat->naptDroppedPktCount++;
+ if (arp_cache_dest_mac_present(dest_if)) {
+ ether_addr_copy(get_link_hw_addr(dest_if),
+ (struct ether_addr *)eth_src);
+ update_nhip_access(dest_if);
+ if (unlikely(ret_arp_data && ret_arp_data->num_pkts)) {
+ p_nat->naptedPktCount += ret_arp_data->num_pkts;
+ arp_send_buffered_pkts(ret_arp_data,
+ (struct ether_addr *)eth_dest, *outport_id);
- #ifdef CGNAPT_DEBUGGING
- p_nat->naptDroppedPktCount4++;
- #endif
- continue;
+ }
+ } else {
- }
+ if (unlikely(ret_arp_data == NULL)) {
- #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
+ printf("%s: NHIP Not Found, nhip:%x , "
+ "outport_id: %d\n", __func__, nhip,
+ *outport_id);
+ #endif
- 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 */
+ p_nat->invalid_packets |= pkt_mask;
+ p_nat->naptDroppedPktCount++;
+
+ #ifdef CGNAPT_DEBUGGING
+ p_nat->naptDroppedPktCount4++;
+ #endif
+ return;
}
- #endif
- memcpy(eth_dest, &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));
}
+ }
{
/* Egress */
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)) {
memcpy(&dest_addr_ipv6[0], &entry->data.u.prv_ipv6[0],
16);
uint8_t nhipv6[16];
- int ret;
- ret = local_get_nh_ipv6(&dest_addr_ipv6[0], &dest_if,
- &nhipv6[0], p_nat);
- if (!ret) {
- dest_if = get_prv_to_pub_port((uint32_t *)
- &dest_addr_ipv6[0], IP_VERSION_6);
-
- 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_ipv6_cache(dest_if, p_nat);
- }
-
- *outport_id = p_nat->outport_id[dest_if];
- }
+ }/* end of ingress */
#ifdef CGNAPT_DEBUGGING
static int static_count;
#endif
memset(nh_ipv6, 0, 16);
- if (get_dest_mac_address_ipv6
- (&dest_addr_ipv6[0], &dest_if,
- &hw_addr, &nh_ipv6[0])) {
- #ifdef CGNAPT_DBG_PRNT
- if (CGNAPT_DEBUG > 2) {
- printf("MAC found for ip 0x%x, port %d - "
- "%02x:%02x:%02x:%02x:%02x:%02x\n",
- *((uint32_t *)dest_addr_ipv6 + 12),
- *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]);
+ struct nd_entry_data *ret_nd_data = NULL;
+ dest_if = INVALID_DESTIF;
- 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]);
+ uint32_t src_phy_port = pkt->port;
+
+ gw_get_nh_port_ipv6((uint8_t *) &dest_addr_ipv6[0],
+ &dest_if, &nh_ipv6[0]);
+
+ ret_nd_data = get_dest_mac_addr_ipv6(&nh_ipv6[0],
+ dest_if, (struct ether_addr *)eth_dest);
+ *outport_id = p_nat->outport_id[dest_if];
+
+ if (nd_cache_dest_mac_present(dest_if)) {
+ ether_addr_copy(get_link_hw_addr(dest_if),
+ (struct ether_addr *)eth_src);
+ update_nhip_access(dest_if);
+
+ if (unlikely(ret_nd_data && ret_nd_data->num_pkts)) {
+ p_nat->naptedPktCount += ret_nd_data->num_pkts;
+ nd_send_buffered_pkts(ret_nd_data,
+ (struct ether_addr *)eth_dest, *outport_id);
}
- #endif
+ } else {
+ if (unlikely(ret_nd_data == NULL)) {
- memcpy(eth_dest, &hw_addr, sizeof(struct ether_addr));
+ #ifdef CGNAPT_DEBUGGING
+ printf("%s: NHIP Not Found "
+ "outport_id: %d\n", __func__,
+ *outport_id);
+ #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]);
+ /* Drop the pkt */
+ p_nat->invalid_packets |= pkt_mask;
+ p_nat->naptDroppedPktCount++;
+
+ #ifdef CGNAPT_DEBUGGING
+ p_nat->naptDroppedPktCount4++;
+ #endif
+ continue;
}
- #endif
- memcpy(eth_src,
- get_link_hw_addr(dest_if),
- sizeof(struct ether_addr));
- } else {
- p_nat->invalid_packets |= pkt_mask;
- p_nat->naptDroppedPktCount++;
+ if (ret_nd_data->status == INCOMPLETE ||
+ ret_nd_data->status == PROBE) {
- #ifdef CGNAPT_DEBUGGING
- p_nat->naptDroppedPktCount4++;
- #endif
+ if (ret_nd_data->num_pkts >= NUM_DESC) {
+ /* Drop the pkt */
+ p_nat->invalid_packets |= pkt_mask;
+ p_nat->naptDroppedPktCount++;
+
+ #ifdef CGNAPT_DEBUGGING
+ p_nat->naptDroppedPktCount4++;
+ #endif
+ continue;
+ } else {
+ arp_pkts_mask |= pkt_mask;
+ nd_queue_unresolved_packet(ret_nd_data, pkt);
+ continue;
+ }
+ }
- continue;
}
{
- /* Ingress */
+ /* start of Ingress */
convert_ipv4_to_ipv6(pkt, &ipv4_hdr);
#endif
p_nat->inaptedPktCount++;
- }
+ } /* end of ingress */
p_nat->naptedPktCount++;
else
sw_checksum(pkt, pkt_type);
#endif
- }
+ } /* end of for loop */
}
/**
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)
p_nat->valid_packets &= ~(p_nat->invalid_packets);
+ if (arp_pkts_mask) {
+ p_nat->valid_packets &= ~(arp_pkts_mask);
+ rte_pipeline_ah_packet_hijack(rte_p, arp_pkts_mask);
+ }
+
if (unlikely(p_nat->valid_packets == 0)) {
/* no suitable packet for lookup */
rte_pipeline_ah_packet_drop(rte_p, p_nat->invalid_packets);
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)
p_nat->valid_packets &= ~(p_nat->invalid_packets);
+ if (arp_pkts_mask) {
+ p_nat->valid_packets &= ~(arp_pkts_mask);
+ rte_pipeline_ah_packet_hijack(rte_p, arp_pkts_mask);
+ }
+
if (unlikely(p_nat->valid_packets == 0)) {
/* no suitable packet for lookup */
rte_pipeline_ah_packet_drop(rte_p, p_nat->invalid_packets);
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)) {
return 0;
}
-
/**
* Function to initialize the pipeline
*
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;
printf("PhyPort %d, ttl %u,", rx_port, ttl);
printf("entry_type %d\n", type);
-
#ifdef NAT_ONLY_CONFIG_REQ
if (nat_only_config_flag) {
if (!p_nat->is_static_cgnapt) {
return msg;
}
+ #ifdef CGNAPT_DBG_PRNT
printf("Success - pipeline_cgnapt_msg_req_entry_addm_handler");
printf("added %d rule pairs.\n", count);
-
+ #endif
return msg;
}
#endif
}
+ #ifdef CGNAPT_DBG_PRNT
printf("\nSuccess - pipeline_cgnapt_msg_req_entry_add_handler "
"added\n");
-
+ #endif
return msg;
}
}
#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);
-
int32_t position = rte_hash_add_key(napt_common_table, &key);
if (position < 0) {
printf("PhyPort %d, ttl %u, NumUe %d,", rx_port, ttl, max_ue);
printf("mPrvPort %d, mPubPort %d,", max_src_port, max_dest_port);
printf("entry_type %d\n", type);
-
#ifdef NAT_ONLY_CONFIG_REQ
if (nat_only_config_flag) {
if (!p_nat->is_static_cgnapt) {
dest_ip++;
}
+ #ifdef CGNAPT_DBG_PRNT
printf("Success - pipeline_cgnapt_msg_req_entry_addm_handler");
printf("added %d rule pairs.\n", count);
+ #endif
return msg;
}
}
}
+ #ifdef CGNAPT_DBG_PRNT
printf("\nSuccess - pipeline_cgnapt_msg_req_entry_addm_handler added");
printf("%d rule pairs.\n", count);
-
+ #endif
return msg;
}
* Function to show CGNAPT stats
*
*/
-void all_cgnapt_stats(void)
+void all_cgnapt_stats(char *buf)
{
- int i;
+ int i, len = 0;
struct pipeline_cgnapt *p_nat;
uint64_t receivedPktCount = 0;
uint64_t missedPktCount = 0;
uint64_t enaptedPktCount = 0;
uint64_t arpicmpPktCount = 0;
- printf("\nCG-NAPT Packet Stats:\n");
+ len += sprintf(buf + len, "\nCG-NAPT Packet Stats:\n");
for (i = 0; i < n_cgnapt_pipeline; i++) {
p_nat = all_pipeline_cgnapt[i];
enaptedPktCount += p_nat->enaptedPktCount;
arpicmpPktCount += p_nat->arpicmpPktCount;
+ len += sprintf(buf + len, "pipeline %d stats:\n", p_nat->pipeline_num);
+ len += sprintf(buf + len, "Received %" PRIu64 ",", p_nat->receivedPktCount);
+ len += sprintf(buf + len, "Missed %" PRIu64 ",", p_nat->missedPktCount);
+ len += sprintf(buf + len, "Dropped %" PRIu64 ",", p_nat->naptDroppedPktCount);
+ len += sprintf(buf + len, "Translated %" PRIu64 ",", p_nat->naptedPktCount);
+ len += sprintf(buf + len, "ingress %" PRIu64 ",", p_nat->inaptedPktCount);
+ len += sprintf(buf + len, "egress %" PRIu64 "\n", p_nat->enaptedPktCount);
+ len += sprintf(buf + len, "arpicmp pkts %" PRIu64 "\n", p_nat->arpicmpPktCount);
+
printf("pipeline %d stats:\n", p_nat->pipeline_num);
printf("Received %" PRIu64 ",", p_nat->receivedPktCount);
printf("Missed %" PRIu64 ",", p_nat->missedPktCount);
printf("arpicmp pkts %" PRIu64 "\n", p_nat->arpicmpPktCount);
+
#ifdef CGNAPT_DEBUGGING
- printf("\n Drop detail 1:%" PRIu64 ",",
+ len += sprintf(buf + len, "\n Drop detail 1:%" PRIu64 ",",
p_nat->naptDroppedPktCount1);
- printf("\n Drop detail 2:%" PRIu64 ",",
+ len += sprintf(buf + len, "\n Drop detail 2:%" PRIu64 ",",
p_nat->naptDroppedPktCount2);
- printf("\n Drop detail 3:%" PRIu64 ",",
+ len += sprintf(buf + len, "\n Drop detail 3:%" PRIu64 ",",
p_nat->naptDroppedPktCount3);
- printf("\n Drop detail 4:%" PRIu64 ",",
+ len += sprintf(buf + len, "\n Drop detail 4:%" PRIu64 ",",
p_nat->naptDroppedPktCount4);
- printf("\n Drop detail 5:%" PRIu64 ",",
+ len += sprintf(buf + len, "\n Drop detail 5:%" PRIu64 ",",
p_nat->naptDroppedPktCount5);
- printf("\n Drop detail 6:%" PRIu64 "",
+ len += sprintf(buf + len, "\n Drop detail 6:%" PRIu64 "",
p_nat->naptDroppedPktCount6);
- printf("\nPkt_miss: %" PRIu64 " %" PRIu64 "",
+ len += sprintf(buf + len, "\nPkt_miss: %" PRIu64 " %" PRIu64 "",
p_nat->missedpktcount1,
p_nat->missedpktcount2);
- printf("\nPkt_miss: %" PRIu64 " %" PRIu64 "",
+ len += sprintf(buf + len, "\nPkt_miss: %" PRIu64 " %" PRIu64 "",
p_nat->missedpktcount3,
p_nat->missedpktcount4);
- printf("\nPkt_miss: %" PRIu64 " %" PRIu64 "",
+ len += sprintf(buf + len, "\nPkt_miss: %" PRIu64 " %" PRIu64 "",
p_nat->missedpktcount5,
p_nat->missedpktcount6);
- printf("\nPkt_miss: %" PRIu64 " %" PRIu64 "",
+ len += sprintf(buf + len, "\nPkt_miss: %" PRIu64 " %" PRIu64 "",
p_nat->missedpktcount7,
p_nat->missedpktcount8);
- printf("\nPkt_miss: %" PRIu64 " %" PRIu64 "",
+ len += sprintf(buf + len, "\nPkt_miss: %" PRIu64 " %" PRIu64 "",
p_nat->missedpktcount9,
p_nat->missedpktcount10);
}
- printf("\nTotal pipeline stats:\n");
+ len += sprintf(buf + len, "\nTotal pipeline stats:\n");
+ len += sprintf(buf + len, "Received %" PRIu64 ",", receivedPktCount);
+ len += sprintf(buf + len, "Missed %" PRIu64 ",", missedPktCount);
+ len += sprintf(buf + len, "Dropped %" PRIu64 ",", naptDroppedPktCount);
+ len += sprintf(buf + len, "Translated %" PRIu64 ",", naptedPktCount);
+ len += sprintf(buf + len, "ingress %" PRIu64 ",", inaptedPktCount);
+ len += sprintf(buf + len, "egress %" PRIu64 "\n", enaptedPktCount);
+ len += sprintf(buf + len, "arpicmp pkts %" PRIu64 "\n", arpicmpPktCount);
+
+ printf("\nTotal pipeline stats:\n");
printf("Received %" PRIu64 ",", receivedPktCount);
printf("Missed %" PRIu64 ",", missedPktCount);
printf("Dropped %" PRIu64 ",", naptDroppedPktCount);
printf("ingress %" PRIu64 ",", inaptedPktCount);
printf("egress %" PRIu64 "\n", enaptedPktCount);
printf("arpicmp pkts %" PRIu64 "\n", arpicmpPktCount);
+
+ if (!rest_api_supported())
+ printf("%s\n", buf);
}
-void all_cgnapt_clear_stats(void)
+void all_cgnapt_clear_stats(char *buf)
{
- int i;
+ int i, len = 0;
struct pipeline_cgnapt *p_nat;
- printf("\nCG-NAPT Packet Stats:\n");
+ len += sprintf(buf + len, "\nCG-NAPT Packet Stats:\n");
for (i = 0; i < n_cgnapt_pipeline; i++) {
p_nat = all_pipeline_cgnapt[i];
- printf("pipeline %d stats:\n", p_nat->pipeline_num);
- printf("Received %" PRIu64 ",", p_nat->receivedPktCount);
- printf("Missed %" PRIu64 ",", p_nat->missedPktCount);
- printf("Dropped %" PRIu64 ",", p_nat->naptDroppedPktCount);
- printf("Translated %" PRIu64 ",", p_nat->naptedPktCount);
- printf("ingress %" PRIu64 ",", p_nat->inaptedPktCount);
- printf("egress %" PRIu64 "\n", p_nat->enaptedPktCount);
- printf("arpicmp pkts %" PRIu64 "\n", p_nat->arpicmpPktCount);
+ len += sprintf(buf + len, "pipeline %d stats:\n", p_nat->pipeline_num);
+ len += sprintf(buf + len, "Received %" PRIu64 ",", p_nat->receivedPktCount);
+ len += sprintf(buf + len, "Missed %" PRIu64 ",", p_nat->missedPktCount);
+ len += sprintf(buf + len, "Dropped %" PRIu64 ",", p_nat->naptDroppedPktCount);
+ len += sprintf(buf + len, "Translated %" PRIu64 ",", p_nat->naptedPktCount);
+ len += sprintf(buf + len, "ingress %" PRIu64 ",", p_nat->inaptedPktCount);
+ len += sprintf(buf + len, "egress %" PRIu64 "\n", p_nat->enaptedPktCount);
+ len += sprintf(buf + len, "arpicmp pkts %" PRIu64 "\n", p_nat->arpicmpPktCount);
p_nat->receivedPktCount = 0;
p_nat->missedPktCount = 0;
p_nat->arpicmpPktCount = 0;
#ifdef CGNAPT_DEBUGGING
- printf("\n Drop detail 1:%" PRIu64 ",",
+ len += sprintf(buf + len, "\n Drop detail 1:%" PRIu64 ",",
p_nat->naptDroppedPktCount1);
- printf("\n Drop detail 2:%" PRIu64 ",",
+ len += sprintf(buf + len, "\n Drop detail 2:%" PRIu64 ",",
p_nat->naptDroppedPktCount2);
- printf("\n Drop detail 3:%" PRIu64 ",",
+ len += sprintf(buf + len, "\n Drop detail 3:%" PRIu64 ",",
p_nat->naptDroppedPktCount3);
- printf("\n Drop detail 4:%" PRIu64 ",",
+ len += sprintf(buf + len, "\n Drop detail 4:%" PRIu64 ",",
p_nat->naptDroppedPktCount4);
- printf("\n Drop detail 5:%" PRIu64 ",",
+ len += sprintf(buf + len, "\n Drop detail 5:%" PRIu64 ",",
p_nat->naptDroppedPktCount5);
- printf("\n Drop detail 6:%" PRIu64 "",
+ len += sprintf(buf + len, "\n Drop detail 6:%" PRIu64 "",
p_nat->naptDroppedPktCount6);
- printf("\nPkt_miss: %" PRIu64 " %" PRIu64 "",
+ len += sprintf(buf + len, "\nPkt_miss: %" PRIu64 " %" PRIu64 "",
p_nat->missedpktcount1,
p_nat->missedpktcount2);
- printf("\nPkt_miss: %" PRIu64 " %" PRIu64 "",
+ len += sprintf(buf + len, "\nPkt_miss: %" PRIu64 " %" PRIu64 "",
p_nat->missedpktcount3,
p_nat->missedpktcount4);
- printf("\nPkt_miss: %" PRIu64 " %" PRIu64 "",
+ len += sprintf(buf + len, "\nPkt_miss: %" PRIu64 " %" PRIu64 "",
p_nat->missedpktcount5,
p_nat->missedpktcount6);
- printf("\nPkt_miss: %" PRIu64 " %" PRIu64 "",
+ len += sprintf(buf + len, "\nPkt_miss: %" PRIu64 " %" PRIu64 "",
p_nat->missedpktcount7,
p_nat->missedpktcount8);
- printf("\nPkt_miss: %" PRIu64 " %" PRIu64 "",
+ len += sprintf(buf + len, "\nPkt_miss: %" PRIu64 " %" PRIu64 "",
p_nat->missedpktcount9,
p_nat->missedpktcount10);
#endif
}
+
+ if (!rest_api_supported())
+ printf("%s\n", buf);
}
/**