diff mbox series

[API-NEXT,v2,3/4] linux-gen: pktio: dpdk: set L3/L4 checksum validation flags

Message ID 1510218017-21165-4-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v2,1/4] linux-gen: packet: add L3/L4 checksum validation flags | expand

Commit Message

Github ODP bot Nov. 9, 2017, 9 a.m. UTC
From: Bogdan Pricope <bogdan.pricope@linaro.org>


L3/L4 checksum validation flags are used to report L3/L4
checksum check status for the incoming packets.

Signed-off-by: Bogdan Pricope <bogdan.pricope@linaro.org>

---
/** Email created from pull request 269 (bogdanPricope:api_next_csum_status_pr)
 ** https://github.com/Linaro/odp/pull/269
 ** Patch: https://github.com/Linaro/odp/pull/269.patch
 ** Base sha: d22c949cc466bf28de559855a1cb525740578137
 ** Merge commit sha: 31b12178be4753494e806513020d7706600c8382
 **/
 platform/linux-generic/pktio/dpdk.c | 57 ++++++++++++++++++++++++++-----------
 1 file changed, 40 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c
index 9782d60c4..764ed37d4 100644
--- a/platform/linux-generic/pktio/dpdk.c
+++ b/platform/linux-generic/pktio/dpdk.c
@@ -337,9 +337,9 @@  static struct rte_mempool_ops ops_stack = {
 
 MEMPOOL_REGISTER_OPS(ops_stack);
 
-#define HAS_IP4_CSUM_FLAG(m, f) ((m->ol_flags & PKT_RX_IP_CKSUM_MASK) == f)
+#define IP4_CSUM_RESULT(m) (m->ol_flags & PKT_RX_IP_CKSUM_MASK)
+#define L4_CSUM_RESULT(m) (m->ol_flags & PKT_RX_L4_CKSUM_MASK)
 #define HAS_L4_PROTO(m, proto) ((m->packet_type & RTE_PTYPE_L4_MASK) == proto)
-#define HAS_L4_CSUM_FLAG(m, f) ((m->ol_flags & PKT_RX_L4_CKSUM_MASK) == f)
 
 #define PKTIN_CSUM_BITS 0x1C
 
@@ -347,29 +347,52 @@  static inline int pkt_set_ol_rx(odp_pktin_config_opt_t *pktin_cfg,
 				odp_packet_hdr_t *pkt_hdr,
 				struct rte_mbuf *mbuf)
 {
+	uint64_t packet_csum_result;
+
 	if (pktin_cfg->bit.ipv4_chksum &&
-	    RTE_ETH_IS_IPV4_HDR(mbuf->packet_type) &&
-	    HAS_IP4_CSUM_FLAG(mbuf, PKT_RX_IP_CKSUM_BAD)) {
-		if (pktin_cfg->bit.drop_ipv4_err)
-			return -1;
+	    RTE_ETH_IS_IPV4_HDR(mbuf->packet_type)) {
+		packet_csum_result = IP4_CSUM_RESULT(mbuf);
+
+		if (packet_csum_result == PKT_RX_IP_CKSUM_GOOD) {
+			pkt_hdr->p.input_flags.l3_chksum_done = 1;
+		} else if (packet_csum_result != PKT_RX_IP_CKSUM_UNKNOWN) {
+			if (pktin_cfg->bit.drop_ipv4_err)
+				return -1;
 
-		pkt_hdr->p.error_flags.ip_err = 1;
+			pkt_hdr->p.input_flags.l3_chksum_done = 1;
+			pkt_hdr->p.error_flags.ip_err = 1;
+			pkt_hdr->p.error_flags.l3_chksum = 1;
+		}
 	}
 
 	if (pktin_cfg->bit.udp_chksum &&
-	    HAS_L4_PROTO(mbuf, RTE_PTYPE_L4_UDP) &&
-	    HAS_L4_CSUM_FLAG(mbuf, PKT_RX_L4_CKSUM_BAD)) {
-		if (pktin_cfg->bit.drop_udp_err)
-			return -1;
+	    HAS_L4_PROTO(mbuf, RTE_PTYPE_L4_UDP)) {
+		packet_csum_result = L4_CSUM_RESULT(mbuf);
 
-		pkt_hdr->p.error_flags.udp_err = 1;
+		if (packet_csum_result == PKT_RX_L4_CKSUM_GOOD) {
+			pkt_hdr->p.input_flags.l4_chksum_done = 1;
+		} else if (packet_csum_result != PKT_RX_L4_CKSUM_UNKNOWN) {
+			if (pktin_cfg->bit.drop_udp_err)
+				return -1;
+
+			pkt_hdr->p.input_flags.l4_chksum_done = 1;
+			pkt_hdr->p.error_flags.udp_err = 1;
+			pkt_hdr->p.error_flags.l4_chksum = 1;
+		}
 	} else if (pktin_cfg->bit.tcp_chksum &&
-		   HAS_L4_PROTO(mbuf, RTE_PTYPE_L4_TCP)  &&
-		   HAS_L4_CSUM_FLAG(mbuf, PKT_RX_L4_CKSUM_BAD)) {
-		if (pktin_cfg->bit.drop_tcp_err)
-			return -1;
+		   HAS_L4_PROTO(mbuf, RTE_PTYPE_L4_TCP)) {
+		packet_csum_result = L4_CSUM_RESULT(mbuf);
 
-		pkt_hdr->p.error_flags.tcp_err = 1;
+		if (packet_csum_result == PKT_RX_L4_CKSUM_GOOD) {
+			pkt_hdr->p.input_flags.l4_chksum_done = 1;
+		} else if (packet_csum_result != PKT_RX_L4_CKSUM_UNKNOWN) {
+			if (pktin_cfg->bit.drop_tcp_err)
+				return -1;
+
+			pkt_hdr->p.input_flags.l4_chksum_done = 1;
+			pkt_hdr->p.error_flags.tcp_err = 1;
+			pkt_hdr->p.error_flags.l4_chksum = 1;
+		}
 	}
 
 	return 0;