Skip to content

Commit 709b4e5

Browse files
committed
Calculate nat packet checksum manually for TAP devices
Python Checksum checks seem to fail. Will ignore for the time-being. Signed-off-by: Guvenc Gulce <[email protected]>
1 parent d32fb51 commit 709b4e5

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/dp_nat.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ void dp_nat_chg_ip(struct dp_flow *df, struct rte_ipv4_hdr *ipv4_hdr,
268268
{
269269
struct rte_udp_hdr *udp_hdr;
270270
struct rte_tcp_hdr *tcp_hdr;
271+
bool calc_cksum = dp_conf_get_nic_type() == DP_CONF_NIC_TYPE_TAP;
271272

272273
ipv4_hdr->hdr_checksum = 0;
273274
m->ol_flags |= RTE_MBUF_F_TX_IPV4;
274-
m->ol_flags |= RTE_MBUF_F_TX_IP_CKSUM;
275275
m->tx_offload = 0;
276276
m->l2_len = sizeof(struct rte_ether_hdr);
277277
m->l3_len = rte_ipv4_hdr_len(ipv4_hdr);
@@ -280,22 +280,34 @@ void dp_nat_chg_ip(struct dp_flow *df, struct rte_ipv4_hdr *ipv4_hdr,
280280
switch (df->l4_type) {
281281
case IPPROTO_TCP:
282282
tcp_hdr = (struct rte_tcp_hdr *)(ipv4_hdr + 1);
283-
tcp_hdr->cksum = 0;
284-
m->ol_flags |= RTE_MBUF_F_TX_TCP_CKSUM;
285283
m->l4_len = DP_TCP_HDR_LEN(tcp_hdr);
284+
tcp_hdr->cksum = 0;
285+
if (unlikely(calc_cksum)) {
286+
tcp_hdr->cksum = rte_ipv4_udptcp_cksum(ipv4_hdr, tcp_hdr);
287+
} else {
288+
m->ol_flags |= RTE_MBUF_F_TX_TCP_CKSUM;
289+
}
286290
break;
287291
case IPPROTO_UDP:
288292
udp_hdr = (struct rte_udp_hdr *)(ipv4_hdr + 1);
289-
udp_hdr->dgram_cksum = 0;
290-
m->ol_flags |= RTE_MBUF_F_TX_UDP_CKSUM;
291293
m->l4_len = sizeof(struct rte_udp_hdr);
294+
udp_hdr->dgram_cksum = 0;
295+
if (unlikely(calc_cksum)) {
296+
udp_hdr->dgram_cksum = rte_ipv4_udptcp_cksum(ipv4_hdr, udp_hdr);
297+
} else {
298+
m->ol_flags |= RTE_MBUF_F_TX_UDP_CKSUM;
299+
}
292300
break;
293301
case IPPROTO_ICMP:
294302
m->l4_len = sizeof(struct rte_icmp_hdr);
295303
break;
296304
default:
297305
break;
298306
}
307+
if (unlikely(calc_cksum))
308+
ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
309+
else
310+
m->ol_flags |= RTE_MBUF_F_TX_IP_CKSUM;
299311
}
300312

301313
static void dp_calculate_icmp_checksum(struct rte_icmp_hdr *icmp_hdr, size_t icmp_len)

0 commit comments

Comments
 (0)