Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/dp_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions src/dp_nat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -280,22 +280,32 @@ 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);
break;
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)
Expand Down
4 changes: 4 additions & 0 deletions src/dp_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh nice solution. So basically for TAP you accept the own mac here as you wanted and if we ever need a true neighbor mac it can be easily changed here, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would already accept true neighbor MAC. It just can not differentiate the "error case" anymore when it is in TAP mode. (Error case being "the router sending TAP device MAC as router MAC")

if (!DP_MAC_EQUAL(own_mac, neigh))
return DP_OK;
}
Expand Down
Loading