Skip to content

Commit 6e3f72c

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 <guevenc.guelce@sap.com>
1 parent d8cd68b commit 6e3f72c

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/dp_nat.c

Lines changed: 15 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,32 @@ 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;
286289
break;
287290
case IPPROTO_UDP:
288291
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;
291292
m->l4_len = sizeof(struct rte_udp_hdr);
293+
udp_hdr->dgram_cksum = 0;
294+
if (unlikely(calc_cksum))
295+
udp_hdr->dgram_cksum = rte_ipv4_udptcp_cksum(ipv4_hdr, udp_hdr);
296+
else
297+
m->ol_flags |= RTE_MBUF_F_TX_UDP_CKSUM;
292298
break;
293299
case IPPROTO_ICMP:
294300
m->l4_len = sizeof(struct rte_icmp_hdr);
295301
break;
296302
default:
297303
break;
298304
}
305+
if (unlikely(calc_cksum))
306+
ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
307+
else
308+
m->ol_flags |= RTE_MBUF_F_TX_IP_CKSUM;
299309
}
300310

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

0 commit comments

Comments
 (0)