diff --git a/include/dp_port.h b/include/dp_port.h index 793ce45a9..ef60e0679 100644 --- a/include/dp_port.h +++ b/include/dp_port.h @@ -196,6 +196,12 @@ struct dp_port *dp_get_port_by_pf_index(uint16_t index) return index < RTE_DIM(_dp_pf_ports) ? _dp_pf_ports[index] : NULL; } +static __rte_always_inline +bool dp_conf_is_tap_mode(void) +{ + return dp_conf_get_nic_type() == DP_CONF_NIC_TYPE_TAP; +} + #ifdef __cplusplus } #endif diff --git a/src/dp_nat.c b/src/dp_nat.c index 05db9a01d..74fadc332 100644 --- a/src/dp_nat.c +++ b/src/dp_nat.c @@ -268,10 +268,10 @@ void dp_nat_chg_ip(struct dp_flow *df, struct rte_ipv4_hdr *ipv4_hdr, { struct rte_udp_hdr *udp_hdr; struct rte_tcp_hdr *tcp_hdr; + bool is_tap = dp_conf_is_tap_mode(); ipv4_hdr->hdr_checksum = 0; m->ol_flags |= RTE_MBUF_F_TX_IPV4; - m->ol_flags |= RTE_MBUF_F_TX_IP_CKSUM; m->tx_offload = 0; m->l2_len = sizeof(struct rte_ether_hdr); m->l3_len = rte_ipv4_hdr_len(ipv4_hdr); @@ -280,15 +280,21 @@ void dp_nat_chg_ip(struct dp_flow *df, struct rte_ipv4_hdr *ipv4_hdr, switch (df->l4_type) { case IPPROTO_TCP: tcp_hdr = (struct rte_tcp_hdr *)(ipv4_hdr + 1); - tcp_hdr->cksum = 0; - m->ol_flags |= RTE_MBUF_F_TX_TCP_CKSUM; m->l4_len = DP_TCP_HDR_LEN(tcp_hdr); + tcp_hdr->cksum = 0; + if (unlikely(is_tap)) + tcp_hdr->cksum = rte_ipv4_udptcp_cksum(ipv4_hdr, tcp_hdr); + else + m->ol_flags |= RTE_MBUF_F_TX_TCP_CKSUM; break; case IPPROTO_UDP: udp_hdr = (struct rte_udp_hdr *)(ipv4_hdr + 1); - udp_hdr->dgram_cksum = 0; - m->ol_flags |= RTE_MBUF_F_TX_UDP_CKSUM; m->l4_len = sizeof(struct rte_udp_hdr); + udp_hdr->dgram_cksum = 0; + if (unlikely(is_tap)) + udp_hdr->dgram_cksum = rte_ipv4_udptcp_cksum(ipv4_hdr, udp_hdr); + else + m->ol_flags |= RTE_MBUF_F_TX_UDP_CKSUM; break; case IPPROTO_ICMP: m->l4_len = sizeof(struct rte_icmp_hdr); @@ -296,6 +302,10 @@ void dp_nat_chg_ip(struct dp_flow *df, struct rte_ipv4_hdr *ipv4_hdr, default: break; } + if (unlikely(is_tap)) + ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr); + else + m->ol_flags |= RTE_MBUF_F_TX_IP_CKSUM; } static void dp_calculate_icmp_checksum(struct rte_icmp_hdr *icmp_hdr, size_t icmp_len) diff --git a/src/dp_netlink.c b/src/dp_netlink.c index adbd4a8b4..821d30d07 100644 --- a/src/dp_netlink.c +++ b/src/dp_netlink.c @@ -13,6 +13,7 @@ #include "dp_log.h" #include "dp_netlink.h" #include "dp_util.h" +#include "dp_port.h" static int dp_read_neigh(struct nlmsghdr *nh, __u32 nll, struct rte_ether_addr *neigh, const struct rte_ether_addr *own_mac) @@ -33,6 +34,9 @@ static int dp_read_neigh(struct nlmsghdr *nh, __u32 nll, struct rte_ether_addr * if (rt_attr->rta_type == NDA_LLADDR) memcpy(&neigh->addr_bytes, RTA_DATA(rt_attr), sizeof(neigh->addr_bytes)); } + // If it is a tap device, we make an exception with own MAC address check. FeBOX case + if (dp_conf_is_tap_mode()) + return DP_OK; if (!DP_MAC_EQUAL(own_mac, neigh)) return DP_OK; }