diff mbox series

[4/6] dpdk: RX - process checksum validation offload flags

Message ID 1496241660-27492-5-git-send-email-bogdan.pricope@linaro.org
State New
Headers show
Series dpdk pktio: enable hardware checksum support | expand

Commit Message

Bogdan Pricope May 31, 2017, 2:40 p.m. UTC
Signed-off-by: Bogdan Pricope <bogdan.pricope@linaro.org>

---
 platform/linux-generic/pktio/dpdk.c | 38 +++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

-- 
1.9.1
diff mbox series

Patch

diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c
index 94d2abe..58e6db0 100644
--- a/platform/linux-generic/pktio/dpdk.c
+++ b/platform/linux-generic/pktio/dpdk.c
@@ -649,6 +649,8 @@  static int dpdk_stop(pktio_entry_t *pktio_entry)
 	return 0;
 }
 
+#define HAS_L4_PROTO(m, proto) ((m->packet_type & RTE_PTYPE_L4_MASK) == proto)
+
 static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry,
 			      odp_packet_t pkt_table[],
 			      struct rte_mbuf *mbuf_table[],
@@ -663,9 +665,11 @@  static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry,
 	int nb_pkts = 0;
 	int alloc_len, num;
 	odp_pool_t pool = pktio_entry->s.pkt_dpdk.pool;
+	odp_pktin_config_opt_t *pktin_cfg;
 
 	/* Allocate maximum sized packets */
 	alloc_len = pktio_entry->s.pkt_dpdk.data_room;
+	pktin_cfg = &pktio_entry->s.config.pktin;
 
 	num = packet_alloc_multi(pool, alloc_len, pkt_table, mbuf_num);
 	if (num != mbuf_num) {
@@ -718,6 +722,40 @@  static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry,
 
 		packet_set_ts(pkt_hdr, ts);
 
+		if (pktin_cfg->bit.ipv4_chksum &&
+		    (mbuf->packet_type & RTE_PTYPE_L3_IPV4) &&
+		    mbuf->ol_flags & PKT_RX_IP_CKSUM_BAD) {
+			if (pktin_cfg->bit.drop_ipv4_err) {
+				odp_packet_free(pkt);
+				rte_pktmbuf_free(mbuf);
+				continue;
+			} else {
+				pkt_hdr->p.error_flags.ip_err = 1;
+			}
+		}
+
+		if (pktin_cfg->bit.udp_chksum &&
+		    HAS_L4_PROTO(mbuf, RTE_PTYPE_L4_UDP) &&
+		    mbuf->ol_flags & PKT_RX_L4_CKSUM_BAD) {
+			if (pktin_cfg->bit.drop_udp_err) {
+				odp_packet_free(pkt);
+				rte_pktmbuf_free(mbuf);
+				continue;
+			} else {
+				pkt_hdr->p.error_flags.udp_err = 1;
+			}
+		} else if (pktin_cfg->bit.tcp_chksum &&
+			   HAS_L4_PROTO(mbuf, RTE_PTYPE_L4_TCP)  &&
+			   mbuf->ol_flags & PKT_RX_L4_CKSUM_BAD) {
+			if (pktin_cfg->bit.drop_tcp_err) {
+				odp_packet_free(pkt);
+				rte_pktmbuf_free(mbuf);
+				continue;
+			} else {
+				pkt_hdr->p.error_flags.tcp_err = 1;
+			}
+		}
+
 		pkt_table[nb_pkts++] = pkt;
 
 		rte_pktmbuf_free(mbuf);