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 8E6C145B09; Thu, 10 Oct 2024 21:43:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3D4AA40B92; Thu, 10 Oct 2024 21:42:55 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id C5207406B8 for ; Thu, 10 Oct 2024 21:42:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728589373; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RWifWjP0hbfio5TiplYWE/oOnrtgxiO2qKpLvq4walk=; b=OtZvkdRlSe+fjnd192rBrumh7gLDhKUcSO6YtHgy/VB+Lmknpa0nSolzmudquc9ARw9o1x sYG6BKbcZG0MBpiV3/DFE46WdpJNO0wdZ40nFAIDsxlx89Hadn94pJ0InsaLmAF9nIewMr SeiyhLoxrsb4CSLvhRXSks2a0oW4SlE= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-88-9atAyjYrP_W_CpHBlG2D8A-1; Thu, 10 Oct 2024 15:42:50 -0400 X-MC-Unique: 9atAyjYrP_W_CpHBlG2D8A-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B81E41956088; Thu, 10 Oct 2024 19:42:48 +0000 (UTC) Received: from ringo.redhat.com (unknown [10.39.208.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4544919560AA; Thu, 10 Oct 2024 19:42:45 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org, Sunil Kumar Kori , Rakesh Kudurumalla , Aman Singh , Ori Kam Cc: Robin Jarry Subject: [PATCH dpdk v3 09/17] cmdline: replace in6_addr with rte_ipv6_addr Date: Thu, 10 Oct 2024 21:41:39 +0200 Message-ID: <20241010194148.1877659-10-rjarry@redhat.com> In-Reply-To: <20241010194148.1877659-1-rjarry@redhat.com> References: <20240821162516.610624-17-rjarry@redhat.com> <20241010194148.1877659-1-rjarry@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 From: Robin Jarry The previous commits introduced a new rte_ipv6_addr structure without any alignment requirements. It is not compatible with the in6_addr POSIX type available in netinet/in.h. The main issue is that in6_addr is not uniform on all platforms which causes unaligned access warnings when compiling without -Wno-address-of-packed-member (set in dpdk by default). In order to have a consistent code base, replace in6_addr with rte_ipv6_addr in the cmdline library. Update all code accordingly. Signed-off-by: Robin Jarry --- Notes: v3: new patch app/graph/ethdev.c | 4 +-- app/graph/ip6_route.c | 6 ++-- app/graph/neigh.c | 2 +- app/test-pmd/cmdline.c | 4 +-- app/test-pmd/cmdline_flow.c | 14 +++----- app/test-pmd/testpmd.h | 16 ++++----- app/test/test_cmdline_ipaddr.c | 49 ++++---------------------- doc/guides/rel_notes/release_24_11.rst | 1 + examples/cmdline/commands.c | 30 +++------------- lib/cmdline/cmdline_parse_ipaddr.h | 3 +- 10 files changed, 33 insertions(+), 96 deletions(-) diff --git a/app/graph/ethdev.c b/app/graph/ethdev.c index cfc1b1856910..13ed791412e1 100644 --- a/app/graph/ethdev.c +++ b/app/graph/ethdev.c @@ -627,10 +627,10 @@ cmd_ethdev_dev_ip6_addr_add_parsed(void *parsed_result, __rte_unused struct cmdl int rc = -EINVAL, i; for (i = 0; i < ETHDEV_IPV6_ADDR_LEN; i++) - config.ip[i] = res->ip.addr.ipv6.s6_addr[i]; + config.ip[i] = res->ip.addr.ipv6.a[i]; for (i = 0; i < ETHDEV_IPV6_ADDR_LEN; i++) - config.mask[i] = res->mask.addr.ipv6.s6_addr[i]; + config.mask[i] = res->mask.addr.ipv6.a[i]; rc = ethdev_ip6_addr_add(res->dev, &config); if (rc < 0) diff --git a/app/graph/ip6_route.c b/app/graph/ip6_route.c index 834719ecaeb4..d91466cd78d6 100644 --- a/app/graph/ip6_route.c +++ b/app/graph/ip6_route.c @@ -157,13 +157,13 @@ cmd_ipv6_lookup_route_add_ipv6_parsed(void *parsed_result, __rte_unused struct c int rc = -EINVAL, i; for (i = 0; i < ETHDEV_IPV6_ADDR_LEN; i++) - config.ip[i] = res->ip.addr.ipv6.s6_addr[i]; + config.ip[i] = res->ip.addr.ipv6.a[i]; for (i = 0; i < ETHDEV_IPV6_ADDR_LEN; i++) - config.mask[i] = res->mask.addr.ipv6.s6_addr[i]; + config.mask[i] = res->mask.addr.ipv6.a[i]; for (i = 0; i < ETHDEV_IPV6_ADDR_LEN; i++) - config.gateway[i] = res->via_ip.addr.ipv6.s6_addr[i]; + config.gateway[i] = res->via_ip.addr.ipv6.a[i]; rc = route_ip6_add(&config); if (rc) diff --git a/app/graph/neigh.c b/app/graph/neigh.c index 79fd542c8948..eb7a09f1f145 100644 --- a/app/graph/neigh.c +++ b/app/graph/neigh.c @@ -266,7 +266,7 @@ cmd_neigh_add_ipv6_parsed(void *parsed_result, __rte_unused struct cmdline *cl, uint64_t mac; for (i = 0; i < ETHDEV_IPV6_ADDR_LEN; i++) - ip[i] = res->ip.addr.ipv6.s6_addr[i]; + ip[i] = res->ip.addr.ipv6.a[i]; if (parser_mac_read(&mac, res->mac)) { printf(MSG_ARG_INVALID, "mac"); diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index b7759e38a871..9de626f20850 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -8603,9 +8603,7 @@ do { \ #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \ do { \ if ((ip_addr).family == AF_INET6) \ - rte_memcpy(&(ip), \ - &((ip_addr).addr.ipv6), \ - sizeof(struct in6_addr)); \ + ip = ip_addr.addr.ipv6; \ else { \ fprintf(stderr, "invalid parameter.\n"); \ return; \ diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index d04280eb3e46..ff3041b37543 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -900,10 +900,8 @@ struct vxlan_encap_conf vxlan_encap_conf = { .udp_dst = RTE_BE16(RTE_VXLAN_DEFAULT_PORT), .ipv4_src = RTE_IPV4(127, 0, 0, 1), .ipv4_dst = RTE_IPV4(255, 255, 255, 255), - .ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00" - "\x00\x00\x00\x00\x00\x00\x00\x01", - .ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00" - "\x00\x00\x00\x00\x00\x00\x11\x11", + .ipv6_src = RTE_IPV6_ADDR_LOOPBACK, + .ipv6_dst = RTE_IPV6(0, 0, 0, 0, 0, 0, 0, 0x1111), .vlan_tci = 0, .ip_tos = 0, .ip_ttl = 255, @@ -934,10 +932,8 @@ struct nvgre_encap_conf nvgre_encap_conf = { .tni = "\x00\x00\x00", .ipv4_src = RTE_IPV4(127, 0, 0, 1), .ipv4_dst = RTE_IPV4(255, 255, 255, 255), - .ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00" - "\x00\x00\x00\x00\x00\x00\x00\x01", - .ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00" - "\x00\x00\x00\x00\x00\x00\x11\x11", + .ipv6_src = RTE_IPV6_ADDR_LOOPBACK, + .ipv6_dst = RTE_IPV6(0, 0, 0, 0, 0, 0, 0, 0x1111), .vlan_tci = 0, .eth_src = "\x00\x00\x00\x00\x00\x00", .eth_dst = "\xff\xff\xff\xff\xff\xff", @@ -11890,7 +11886,7 @@ parse_ipv6_addr(struct context *ctx, const struct token *token, { const struct arg *arg = pop_args(ctx); char str2[len + 1]; - struct in6_addr tmp; + struct rte_ipv6_addr tmp; int ret; (void)token; diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 9facd7f281d9..2751c441112b 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -712,8 +712,8 @@ struct vxlan_encap_conf { rte_be16_t udp_dst; rte_be32_t ipv4_src; rte_be32_t ipv4_dst; - uint8_t ipv6_src[16]; - uint8_t ipv6_dst[16]; + struct rte_ipv6_addr ipv6_src; + struct rte_ipv6_addr ipv6_dst; rte_be16_t vlan_tci; uint8_t ip_tos; uint8_t ip_ttl; @@ -730,8 +730,8 @@ struct nvgre_encap_conf { uint8_t tni[3]; rte_be32_t ipv4_src; rte_be32_t ipv4_dst; - uint8_t ipv6_src[16]; - uint8_t ipv6_dst[16]; + struct rte_ipv6_addr ipv6_src; + struct rte_ipv6_addr ipv6_dst; rte_be16_t vlan_tci; uint8_t eth_src[RTE_ETHER_ADDR_LEN]; uint8_t eth_dst[RTE_ETHER_ADDR_LEN]; @@ -762,8 +762,8 @@ struct mplsogre_encap_conf { uint8_t label[3]; rte_be32_t ipv4_src; rte_be32_t ipv4_dst; - uint8_t ipv6_src[16]; - uint8_t ipv6_dst[16]; + struct rte_ipv6_addr ipv6_src; + struct rte_ipv6_addr ipv6_dst; rte_be16_t vlan_tci; uint8_t eth_src[RTE_ETHER_ADDR_LEN]; uint8_t eth_dst[RTE_ETHER_ADDR_LEN]; @@ -786,8 +786,8 @@ struct mplsoudp_encap_conf { rte_be16_t udp_dst; rte_be32_t ipv4_src; rte_be32_t ipv4_dst; - uint8_t ipv6_src[16]; - uint8_t ipv6_dst[16]; + struct rte_ipv6_addr ipv6_src; + struct rte_ipv6_addr ipv6_dst; rte_be16_t vlan_tci; uint8_t eth_src[RTE_ETHER_ADDR_LEN]; uint8_t eth_dst[RTE_ETHER_ADDR_LEN]; diff --git a/app/test/test_cmdline_ipaddr.c b/app/test/test_cmdline_ipaddr.c index f540063508ae..dcd9c521eb5f 100644 --- a/app/test/test_cmdline_ipaddr.c +++ b/app/test/test_cmdline_ipaddr.c @@ -17,21 +17,7 @@ (((c) & 0xff) << 16) | \ ((d) & 0xff) << 24)} -#define U16_SWAP(x) \ - (((x & 0xFF) << 8) | ((x & 0xFF00) >> 8)) - -/* create IPv6 address, swapping bytes where needed */ -#ifndef s6_addr16 -#ifdef RTE_EXEC_ENV_WINDOWS -#define s6_addr16 u.Word -#else -#define s6_addr16 __u6_addr.__u6_addr16 -#endif -#endif -#define IP6(a,b,c,d,e,f,g,h) .ipv6 = \ - {.s6_addr16 = \ - {U16_SWAP(a),U16_SWAP(b),U16_SWAP(c),U16_SWAP(d),\ - U16_SWAP(e),U16_SWAP(f),U16_SWAP(g),U16_SWAP(h)}} +#define IP6(a, b, c, d, e, f, g, h) .ipv6 = RTE_IPV6(a, b, c, d, e, f, g, h) /** these are defined in netinet/in.h but not present in linux headers */ #ifndef NIPQUAD @@ -42,30 +28,8 @@ (unsigned)((unsigned char *)&addr)[1], \ (unsigned)((unsigned char *)&addr)[2], \ (unsigned)((unsigned char *)&addr)[3] - -#define NIP6_FMT "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x" -#define NIP6(addr) \ - (unsigned)((addr).s6_addr[0]), \ - (unsigned)((addr).s6_addr[1]), \ - (unsigned)((addr).s6_addr[2]), \ - (unsigned)((addr).s6_addr[3]), \ - (unsigned)((addr).s6_addr[4]), \ - (unsigned)((addr).s6_addr[5]), \ - (unsigned)((addr).s6_addr[6]), \ - (unsigned)((addr).s6_addr[7]), \ - (unsigned)((addr).s6_addr[8]), \ - (unsigned)((addr).s6_addr[9]), \ - (unsigned)((addr).s6_addr[10]), \ - (unsigned)((addr).s6_addr[11]), \ - (unsigned)((addr).s6_addr[12]), \ - (unsigned)((addr).s6_addr[13]), \ - (unsigned)((addr).s6_addr[14]), \ - (unsigned)((addr).s6_addr[15]) - #endif - - struct ipaddr_str { const char * str; cmdline_ipaddr_t addr; @@ -273,8 +237,8 @@ dump_addr(cmdline_ipaddr_t addr) } case AF_INET6: { - printf(NIP6_FMT " prefixlen=%u\n", - NIP6(addr.addr.ipv6), addr.prefixlen); + printf(RTE_IPV6_ADDR_FMT " prefixlen=%u\n", + RTE_IPV6_ADDR_SPLIT(&addr.addr.ipv6), addr.prefixlen); break; } default: @@ -303,8 +267,7 @@ is_addr_different(cmdline_ipaddr_t addr1, cmdline_ipaddr_t addr2) /* IPv6 */ case AF_INET6: { - if (memcmp(&addr1.addr.ipv6, &addr2.addr.ipv6, - sizeof(struct in6_addr)) != 0) + if (!rte_ipv6_addr_eq(&addr1.addr.ipv6, &addr2.addr.ipv6)) return 1; break; } @@ -476,7 +439,7 @@ test_parse_ipaddr_valid(void) return -1; } if (ret != -1 && - memcmp(&result.addr.ipv6, &tmp.addr.ipv6, sizeof(struct in6_addr))) { + !rte_ipv6_addr_eq(&result.addr.ipv6, &tmp.addr.ipv6)) { printf("Error: result mismatch when parsing %s as %s!\n", ipaddr_garbage_addr6_strs[i], buf); return -1; @@ -561,7 +524,7 @@ test_parse_ipaddr_valid(void) return -1; } if (ret != -1 && - memcmp(&result.addr.ipv6, &tmp.addr.ipv6, sizeof(struct in6_addr))) { + !rte_ipv6_addr_eq(&result.addr.ipv6, &tmp.addr.ipv6)) { printf("Error: result mismatch when parsing %s as %s!\n", ipaddr_garbage_network6_strs[i], buf); return -1; diff --git a/doc/guides/rel_notes/release_24_11.rst b/doc/guides/rel_notes/release_24_11.rst index dc8926a6078e..f5a2ac3cfb4f 100644 --- a/doc/guides/rel_notes/release_24_11.rst +++ b/doc/guides/rel_notes/release_24_11.rst @@ -145,6 +145,7 @@ API Changes * net: IPv6 related symbols were moved from ```` to the new ```` header. * net: The ``rte_ipv6_hdr`` structure was modified to use ``struct rte_ipv6_addr`` instead of ``uint8_t[16]`` fields. * rib6,fib6,lpm6: All public API functions were modified to use ``struct rte_ipv6_addr`` instead of ``uint8_t[16]`` parameters. +* cmdline: ``cmdline_ipaddr_t`` was modified to use ``struct rte_ipv6_addr`` instead of ``in6_addr``. ABI Changes ----------- diff --git a/examples/cmdline/commands.c b/examples/cmdline/commands.c index aec151d08987..09a42a9917cb 100644 --- a/examples/cmdline/commands.c +++ b/examples/cmdline/commands.c @@ -33,28 +33,6 @@ struct object_list global_obj_list; (unsigned)((unsigned char *)&addr)[3] #endif -#ifndef NIP6 -#define NIP6_FMT "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x" -#define NIP6(addr) \ - (unsigned)((addr).s6_addr[0]), \ - (unsigned)((addr).s6_addr[1]), \ - (unsigned)((addr).s6_addr[2]), \ - (unsigned)((addr).s6_addr[3]), \ - (unsigned)((addr).s6_addr[4]), \ - (unsigned)((addr).s6_addr[5]), \ - (unsigned)((addr).s6_addr[6]), \ - (unsigned)((addr).s6_addr[7]), \ - (unsigned)((addr).s6_addr[8]), \ - (unsigned)((addr).s6_addr[9]), \ - (unsigned)((addr).s6_addr[10]), \ - (unsigned)((addr).s6_addr[11]), \ - (unsigned)((addr).s6_addr[12]), \ - (unsigned)((addr).s6_addr[13]), \ - (unsigned)((addr).s6_addr[14]), \ - (unsigned)((addr).s6_addr[15]) -#endif - - /**********************************************************/ /* Show or delete tokens. 8< */ @@ -74,8 +52,8 @@ static void cmd_obj_del_show_parsed(void *parsed_result, snprintf(ip_str, sizeof(ip_str), NIPQUAD_FMT, NIPQUAD(res->obj->ip.addr.ipv4)); else - snprintf(ip_str, sizeof(ip_str), NIP6_FMT, - NIP6(res->obj->ip.addr.ipv6)); + snprintf(ip_str, sizeof(ip_str), RTE_IPV6_ADDR_FMT, + RTE_IPV6_ADDR_SPLIT(&res->obj->ip.addr.ipv6)); if (strcmp(res->action, "del") == 0) { SLIST_REMOVE(&global_obj_list, res->obj, object, next); @@ -145,8 +123,8 @@ static void cmd_obj_add_parsed(void *parsed_result, snprintf(ip_str, sizeof(ip_str), NIPQUAD_FMT, NIPQUAD(o->ip.addr.ipv4)); else - snprintf(ip_str, sizeof(ip_str), NIP6_FMT, - NIP6(o->ip.addr.ipv6)); + snprintf(ip_str, sizeof(ip_str), RTE_IPV6_ADDR_FMT, + RTE_IPV6_ADDR_SPLIT(&o->ip.addr.ipv6)); cmdline_printf(cl, "Object %s added, ip=%s\n", o->name, ip_str); diff --git a/lib/cmdline/cmdline_parse_ipaddr.h b/lib/cmdline/cmdline_parse_ipaddr.h index 0118c31d4484..8653de8237fc 100644 --- a/lib/cmdline/cmdline_parse_ipaddr.h +++ b/lib/cmdline/cmdline_parse_ipaddr.h @@ -9,6 +9,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -22,7 +23,7 @@ struct cmdline_ipaddr { uint8_t family; union { struct in_addr ipv4; - struct in6_addr ipv6; + struct rte_ipv6_addr ipv6; } addr; unsigned int prefixlen; /* in case of network only */ }; -- 2.46.2