From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 424C7A0C41; Fri, 8 Oct 2021 17:51:24 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 29EDF4067B; Fri, 8 Oct 2021 17:51:24 +0200 (CEST) Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by mails.dpdk.org (Postfix) with ESMTP id D26F240140 for ; Fri, 8 Oct 2021 17:51:22 +0200 (CEST) Received: by mail-wr1-f42.google.com with SMTP id o20so31084730wro.3 for ; Fri, 08 Oct 2021 08:51:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=re2Jnt4P+HCJAlcNLiTUZflrLSoitqRWps8/ywA8A8Y=; b=QBKqeHsDyW24IbZXlgbB+ME0iqWprK8dmTe1M+mHjrEjagnCTeRkFzcETBpuTJoVdC BrdLFnU5y2SadzsKxaLm3e3aW2M3U9vjKTYBXSy6ij6ahmaGuizAbCvagOKIyrvOWN6Z jK+qAO7vKrXo9wNBMCieXMnCgBGMukWwygMsZgHCTLy8f2t16yWy360DkCVZ5z8yPNhu YrN5EkifGTmoDwxIMeNClOl22Z2cUkqH3YPi/G8ibD98025RshsYXKgb/as2OPlfutzs O6FfC3bqL8mOQQlqe3oXXGQ3S+iz+MQ3nhoQWUiPCztCB8h30lwE04/MeKnpWnIqrED1 55dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=re2Jnt4P+HCJAlcNLiTUZflrLSoitqRWps8/ywA8A8Y=; b=OGB8ZJjMSIDlCqFaUMyJJBuIn/iLb4NDskxyU8zaGCtR5FTC3VFMyw4Z6uMDkiH2Wk wNszKjGPCaMUeSr8ILMp3Jt4x9ip2yNZyoMVg/rDoUQ9p4nSNgiU3HDp5z6W3QAYN0hc DssxNHAlSpGn5C8jnhctdVzSgMCXfHVhqmW+Pp97Q/HAaBP/icNCCwZL4QHRA40m1Ea+ ySA0BGrm0MBaxRfj+zCD7AH//nLJR4n7aPjYmq0cC7nSU79hQaaYWsNv5yBw/4GBvWFa BCoC8N2iUzMJY/xUa1IH0tS+dUiC7lsk5fJo5KX5Oe4MiAZQwYjbSpXL2mzDEMEuX7l0 2scw== X-Gm-Message-State: AOAM533CZyFYa+JOiMTC568VVv+SIoHaB9OuAJO+09g2zfWGwoDo/txv xluJ01qplNEOMMHgUIJBlxkoJcl3MMTLyeW2Yw== X-Google-Smtp-Source: ABdhPJyU8MYDivuU8zPtWd9k24LeWEgwMMIXEbJscRhz1T6CND3vfKVfoQEW91ljs6L2xfhh5VMWRA== X-Received: by 2002:adf:a556:: with SMTP id j22mr4986158wrb.431.1633708282595; Fri, 08 Oct 2021 08:51:22 -0700 (PDT) Received: from localhost.localdomain ([182.191.83.208]) by smtp.gmail.com with ESMTPSA id c204sm12559583wme.11.2021.10.08.08.51.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 08:51:22 -0700 (PDT) From: Usama Nadeem To: thomas@monjalon.net Cc: dev@dpdk.org, Usama Nadeem Date: Fri, 8 Oct 2021 20:51:11 +0500 Message-Id: <20211008155111.125786-1-usama.nadeem@emumba.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210914180827.184123-1-usama.nadeem@emumba.com> References: <20210914180827.184123-1-usama.nadeem@emumba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3] ipv4 and udp/tcp cksum verification through software X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" checks if ipv4 and udptcp cksum offload capability available If not available, cksum is verified through software If cksum is corrupt, packet is dropped, rest of the packets are forwarded back. Bugzilla ID:545 Signed-off-by: Usama Nadeem --- examples/l3fwd/l3fwd.h | 6 ++++ examples/l3fwd/l3fwd_lpm.c | 71 ++++++++++++++++++++++++++++++++++++-- examples/l3fwd/main.c | 32 +++++++++++++++-- 3 files changed, 103 insertions(+), 6 deletions(-) diff --git a/examples/l3fwd/l3fwd.h b/examples/l3fwd/l3fwd.h index a808d60247..b0b6a906d4 100644 --- a/examples/l3fwd/l3fwd.h +++ b/examples/l3fwd/l3fwd.h @@ -55,6 +55,8 @@ #define L3FWD_HASH_ENTRIES (1024*1024*1) #endif #define HASH_ENTRY_NUMBER_DEFAULT 4 +bool l3_sft_cksum; +bool l4_sft_cksum; struct mbuf_table { uint16_t len; @@ -210,6 +212,10 @@ em_main_loop(__rte_unused void *dummy); int lpm_main_loop(__rte_unused void *dummy); +int +check_software_cksum(struct rte_mbuf **pkts_burst, +struct rte_mbuf **pkts_burst_to_send, int nb_rx); + int fib_main_loop(__rte_unused void *dummy); diff --git a/examples/l3fwd/l3fwd_lpm.c b/examples/l3fwd/l3fwd_lpm.c index 232b606b54..e237ca6bc4 100644 --- a/examples/l3fwd/l3fwd_lpm.c +++ b/examples/l3fwd/l3fwd_lpm.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "l3fwd.h" #include "l3fwd_event.h" @@ -139,16 +140,65 @@ lpm_get_dst_port_with_ipv4(const struct lcore_conf *qconf, struct rte_mbuf *pkt, #include "l3fwd_lpm.h" #endif + +int check_software_cksum(struct rte_mbuf **pkts_burst, +struct rte_mbuf **pkts_burst_to_send, int nb_rx) +{ + int j; + int i = 0; + struct rte_net_hdr_lens hdr_lens; + struct rte_ipv4_hdr *ipv4_hdr; + void *l3_hdr; + void *l4_hdr; + rte_be16_t prev_cksum; + int dropped_pkts_udp_tcp = 0; + int dropped_pkts_ipv4 = 0; + bool dropped; + for (j = 0; j < nb_rx; j++) { + dropped = false; + rte_net_get_ptype(pkts_burst[j], &hdr_lens, RTE_PTYPE_ALL_MASK); + l3_hdr = rte_pktmbuf_mtod_offset(pkts_burst[j], + void *, hdr_lens.l2_len); + l4_hdr = rte_pktmbuf_mtod_offset(pkts_burst[j], + void *, hdr_lens.l2_len + hdr_lens.l3_len); + ipv4_hdr = l3_hdr; + prev_cksum = ipv4_hdr->hdr_checksum; + ipv4_hdr->hdr_checksum = 0; + ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr); + + if (l3_sft_cksum && prev_cksum != ipv4_hdr->hdr_checksum) { + rte_pktmbuf_free(pkts_burst[j]); + dropped_pkts_ipv4++; + dropped = true; + } else if (l4_sft_cksum && + rte_ipv4_udptcp_cksum_verify + (l3_hdr, l4_hdr) != 0) { + + rte_pktmbuf_free(pkts_burst[j]); + dropped_pkts_udp_tcp++; + dropped = true; + } + if (dropped == false) { + pkts_burst_to_send[i] = pkts_burst[j]; + i++; + } + + } + return dropped_pkts_udp_tcp+dropped_pkts_ipv4; +} + /* main processing loop */ int lpm_main_loop(__rte_unused void *dummy) { struct rte_mbuf *pkts_burst[MAX_PKT_BURST]; + struct rte_mbuf *pkts_burst_to_send[MAX_PKT_BURST]; unsigned lcore_id; uint64_t prev_tsc, diff_tsc, cur_tsc; int i, nb_rx; uint16_t portid; uint8_t queueid; + int dropped; struct lcore_conf *qconf; const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US; @@ -208,20 +258,35 @@ lpm_main_loop(__rte_unused void *dummy) MAX_PKT_BURST); if (nb_rx == 0) continue; + if (l3_sft_cksum || l4_sft_cksum) { + dropped = check_software_cksum(pkts_burst, + pkts_burst_to_send, nb_rx); + + nb_rx = nb_rx-dropped; + } + #if defined RTE_ARCH_X86 || defined __ARM_NEON \ || defined RTE_ARCH_PPC_64 + if (l3_sft_cksum == false && l4_sft_cksum == false) l3fwd_lpm_send_packets(nb_rx, pkts_burst, portid, qconf); + else + l3fwd_lpm_send_packets(nb_rx, pkts_burst_to_send, + portid, qconf); + #else - l3fwd_lpm_no_opt_send_packets(nb_rx, pkts_burst, + if (l3_sft_cksum == false && l4_sft_cksum == false) + l3fwd_lpm_no_opt_send_packets(nb_rx, pkts_burst, portid, qconf); + else + l3fwd_lpm_no_opt_send_packets(nb_rx, + pkts_burst_to_send, portid, qconf); + #endif /* X86 */ } - cur_tsc = rte_rdtsc(); } - return 0; } diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c index 00ac267af1..68248fd189 100644 --- a/examples/l3fwd/main.c +++ b/examples/l3fwd/main.c @@ -123,7 +123,6 @@ static struct rte_eth_conf port_conf = { .mq_mode = ETH_MQ_RX_RSS, .max_rx_pkt_len = RTE_ETHER_MAX_LEN, .split_hdr_size = 0, - .offloads = DEV_RX_OFFLOAD_CHECKSUM, }, .rx_adv_conf = { .rss_conf = { @@ -981,6 +980,7 @@ prepare_ptype_parser(uint16_t portid, uint16_t queueid) return 0; } + static void l3fwd_poll_resource_setup(void) { @@ -993,7 +993,8 @@ l3fwd_poll_resource_setup(void) unsigned int nb_ports; unsigned int lcore_id; int ret; - + l3_sft_cksum = false; + l4_sft_cksum = false; if (check_lcore_params() < 0) rte_exit(EXIT_FAILURE, "check_lcore_params failed\n"); @@ -1034,11 +1035,36 @@ l3fwd_poll_resource_setup(void) rte_exit(EXIT_FAILURE, "Error during getting device (port %u) info: %s\n", portid, strerror(-ret)); - if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE) local_port_conf.txmode.offloads |= DEV_TX_OFFLOAD_MBUF_FAST_FREE; + if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) + local_port_conf.rxmode.offloads |= + DEV_RX_OFFLOAD_IPV4_CKSUM; + else { + l3_sft_cksum = true; + printf("WARNING: IPV4 Checksum offload not available.\n"); + } + + if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) + local_port_conf.rxmode.offloads |= + DEV_RX_OFFLOAD_UDP_CKSUM; + + else { + l4_sft_cksum = true; + printf("WARNING: UDP Checksum offload not available.\n"); + } + + if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) + local_port_conf.rxmode.offloads |= + DEV_RX_OFFLOAD_TCP_CKSUM; + + else { + l4_sft_cksum = true; + printf("WARNING: TCP Checksum offload not available.\n"); + } + local_port_conf.rx_adv_conf.rss_conf.rss_hf &= dev_info.flow_type_rss_offloads; -- 2.17.1