From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [dpdk-dev] [PATCH 5/5] examples/l3fwd: improve readability for destination lookup
Date: Sat, 25 Jan 2020 17:09:11 -0800 [thread overview]
Message-ID: <20200126010911.3733-6-stephen@networkplumber.org> (raw)
In-Reply-To: <20200126010911.3733-1-stephen@networkplumber.org>
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 <stephen@networkplumber.org>
---
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
--
2.20.1
next prev parent reply other threads:[~2020-01-26 1:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-26 1:09 [dpdk-dev] [PATCH 0/5] l3fwd and lpm cleanups Stephen Hemminger
2020-01-26 1:09 ` [dpdk-dev] [PATCH 1/5] lpm: make ipv6 address immutable Stephen Hemminger
2020-01-26 1:09 ` [dpdk-dev] [PATCH 2/5] examples/l3fwd: use RTE_DIM Stephen Hemminger
2020-01-26 1:09 ` [dpdk-dev] [PATCH 3/5] examples/l3fwd: make lookup struct static Stephen Hemminger
2020-01-26 1:09 ` [dpdk-dev] [PATCH 4/5] examples/l3fwd: make route array constant Stephen Hemminger
2020-01-26 1:09 ` Stephen Hemminger [this message]
2020-02-16 19:39 ` [dpdk-dev] [PATCH 0/5] l3fwd and lpm cleanups Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200126010911.3733-6-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).