From patchwork Sun Jan 26 01:09:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 65130 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C8240A0531; Sun, 26 Jan 2020 02:10:02 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 896441BE3D; Sun, 26 Jan 2020 02:09:30 +0100 (CET) Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) by dpdk.org (Postfix) with ESMTP id 1E0701B1D5 for ; Sun, 26 Jan 2020 02:09:27 +0100 (CET) Received: by mail-pj1-f66.google.com with SMTP id m4so1573407pjv.3 for ; Sat, 25 Jan 2020 17:09:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ihqtZlbjenRstaDhM+8Y6HyDQiiYQa0SXkxqKoKCfnI=; b=OqhkpsgWyVS21cOycHdbmzzd531oDffpfmT8sqHNI6RyhrRvUauf/C7dPUeqlRt9yd VtyFcvx97p9B8ksfSEGSxVpDVkvKlO4OI/z6xd9xIwvEI6BVuMah6DQnEqGrsB1dDBmm epS+yHLEX07aDV/n2cLHGkhvkX07wOsQsLZ/shsRj2L8Up+Ut0W/X+0+6PVh/WEbfDAu CuLrIQnbycAUQXaVhKrZlAeOH3wnJ3CIuImRRnG5fGEa3fLe/7gCbEJfGALGf0srtETs sR4Opz4rdZS397BxQ2IhTjjx6znTxmyGllfJpFe3YcYfIJtkczpdmQuj/Mi+dDpMvMlO I5RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ihqtZlbjenRstaDhM+8Y6HyDQiiYQa0SXkxqKoKCfnI=; b=E8W0B3D37F0ebw1fCjIkODDju0lnSyaxcw1vjvX7BHUfUHQ9qmSioZNcExCL5alQ2h RAIEWA+kinyktdKLn9ZYTy10x8AgRSj0RS/IqloA5B9SXTVawc/OXWAoda/OTCfWLsqb diKfoQlNGwddDbpGba6U7tOOcTdKr+5kuCtNGvKrV6pxSd0+MLTWDvan0fURbOtcab/c W2zLS1684enAPliHhujFUcEbcMfocb5D1fz9a9moukJS4wMYJaiSZjB7WkkmahwL+cGe 7B+vi7oOXNdEf6BaB5NdUg/zQDTkt3MwwpfzCjqQxN/CLu9YI14v4mWPYHAbAm5OthMg 6Mzw== X-Gm-Message-State: APjAAAXsh5oI/iS1h29kmAZXLZdYbUib44kIvSqy8ZNf0Segbrkp4Iix 8+oVoOCjEGzGRSLKZpr2W60DNGJh+v0= X-Google-Smtp-Source: APXvYqzPOnwjLzvGhJolc7PHzDv43oTHfIIJGHJnQxDKOUPd1UKAB69Vl4tEpJp1py6btS7AwA8M2Q== X-Received: by 2002:a17:902:ab91:: with SMTP id f17mr11118456plr.172.1580000965727; Sat, 25 Jan 2020 17:09:25 -0800 (PST) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id t1sm11560267pgq.23.2020.01.25.17.09.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2020 17:09:24 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Sat, 25 Jan 2020 17:09:11 -0800 Message-Id: <20200126010911.3733-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200126010911.3733-1-stephen@networkplumber.org> References: <20200126010911.3733-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 5/5] examples/l3fwd: improve readability for destination lookup X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" The functions to lookup ipv4 and ipv6 were both using opaque pointers (void *) when they should use a typed pointer instead. The ip headers are not modified during lookup. Get rid of unnecessary cast on the return from the function. Replace complex trigraph expression with simple if to improve readability. Signed-off-by: Stephen Hemminger --- examples/l3fwd/l3fwd_lpm.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/examples/l3fwd/l3fwd_lpm.c b/examples/l3fwd/l3fwd_lpm.c index 30f6385419ee..bd6e7fe03d77 100644 --- a/examples/l3fwd/l3fwd_lpm.c +++ b/examples/l3fwd/l3fwd_lpm.c @@ -77,27 +77,31 @@ static struct rte_lpm *ipv4_l3fwd_lpm_lookup_struct[NB_SOCKETS]; static struct rte_lpm6 *ipv6_l3fwd_lpm_lookup_struct[NB_SOCKETS]; static inline uint16_t -lpm_get_ipv4_dst_port(void *ipv4_hdr, uint16_t portid, void *lookup_struct) +lpm_get_ipv4_dst_port(const struct rte_ipv4_hdr *ipv4_hdr, + uint16_t portid, + struct rte_lpm *ipv4_l3fwd_lookup_struct) { + uint32_t dst_ip = rte_be_to_cpu_32(ipv4_hdr->dst_addr); uint32_t next_hop; - struct rte_lpm *ipv4_l3fwd_lookup_struct = - (struct rte_lpm *)lookup_struct; - return (uint16_t) ((rte_lpm_lookup(ipv4_l3fwd_lookup_struct, - rte_be_to_cpu_32(((struct rte_ipv4_hdr *)ipv4_hdr)->dst_addr), - &next_hop) == 0) ? next_hop : portid); + if (rte_lpm_lookup(ipv4_l3fwd_lookup_struct, dst_ip, &next_hop) == 0) + return next_hop; + else + return portid; } static inline uint16_t -lpm_get_ipv6_dst_port(void *ipv6_hdr, uint16_t portid, void *lookup_struct) +lpm_get_ipv6_dst_port(const struct rte_ipv6_hdr *ipv6_hdr, + uint16_t portid, + struct rte_lpm6 *ipv6_l3fwd_lookup_struct) { + const uint8_t *dst_ip = ipv6_hdr->dst_addr; uint32_t next_hop; - struct rte_lpm6 *ipv6_l3fwd_lookup_struct = - (struct rte_lpm6 *)lookup_struct; - return (uint16_t) ((rte_lpm6_lookup(ipv6_l3fwd_lookup_struct, - ((struct rte_ipv6_hdr *)ipv6_hdr)->dst_addr, - &next_hop) == 0) ? next_hop : portid); + if (rte_lpm6_lookup(ipv6_l3fwd_lookup_struct, dst_ip, &next_hop) == 0) + return next_hop; + else + return portid; } static __rte_always_inline uint16_t