From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 19695A034F; Mon, 25 Nov 2019 22:47:18 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BBB772952; Mon, 25 Nov 2019 22:47:16 +0100 (CET) Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by dpdk.org (Postfix) with ESMTP id A8096235 for ; Mon, 25 Nov 2019 22:47:15 +0100 (CET) Received: by mail-pf1-f194.google.com with SMTP id n13so8047349pff.1 for ; Mon, 25 Nov 2019 13:47:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=v0ebAxXdSQ93v9qTSiv+1H5e5Z1GwsCkShJS4VriO9Y=; b=gRYnikjfPKDP4q7QxofVZ6eTEC4hpHFDHUD6CG+w4J/XrpXG4K3DivvbxLNIsZSc29 HxdEJVKdAZyCiUf5CoX3C9E2txds24V5e7XztiFaoX/v5Nmol6KOg5BJVeWhLjBOhwjX lSULMYuFfsbOIFdsNQJ5swkgzABaQJWtfuNSKCS8Guq4VflWmBjAXCrAiI8SCv/KKelR ssQp6tsCBZSMrl2nNN1f9eKjc3uk5rJeuwlN5TMzF+kxe3sNVGZuzUId75wrCR4JCxTC a4jxSjTUGcSBw24hjWqqdH5ejjl9gPGNJ9KI4izxQbyn04YwQxPGuIbjBRDmZlUZZk3o OAQw== 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; bh=v0ebAxXdSQ93v9qTSiv+1H5e5Z1GwsCkShJS4VriO9Y=; b=E/47JlgbYWo4/ol5moILShfn0BE+t2E3PqGEIr49vq6FiUngtyeW7x11f3PxRcy0xN WbiKznOAaEO/osMvw85SSV+Ab9OIJiAon5eIhV9UugpeDg2HP482R5b8e6MbmZAPianZ dI6uQvsjqXWFaFj4a1XobQwnE1Kn3VE3jKNnldeGMK4qMbPWEOPb1EILN4TxOgEhbEPq 76+TKFMp+JYQ77m8hfXglMYNV/vve49uM9KaY4mDqpQg5KSE3wbmKCCs+HHvRYrVN359 sT0sqbkG1RNwVF/3WhwFagwMICD+FGc6oyVxGs9GY0yDF4osNtsWFsf+wAhAFlTBUaVg 2vEQ== X-Gm-Message-State: APjAAAXQBbLyZdZwuKpkVDmeJcw3fRKYeYZvKnO3res9i/oN9X8M5/uI Mj12LbM3ol7Fxrsv9ngskDE= X-Google-Smtp-Source: APXvYqxJEXk3GbW7Z0zAeKBcZHkA1JzgIyLrXpwFcH5kygMAZ46g1HTEMRjqy7BxZioycuQ6QF/OQg== X-Received: by 2002:a63:6fca:: with SMTP id k193mr35447966pgc.363.1574718434436; Mon, 25 Nov 2019 13:47:14 -0800 (PST) Received: from localhost ([2620:10d:c090:200::3:8fc3]) by smtp.gmail.com with ESMTPSA id m13sm9288172pga.70.2019.11.25.13.47.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2019 13:47:13 -0800 (PST) From: Frank Li To: Keith Wiles Cc: dev@dpdk.org, Frank Li Date: Mon, 25 Nov 2019 13:46:38 -0800 Message-Id: <20191125214638.41094-1-frank.li.65@gmail.com> X-Mailer: git-send-email 2.13.5 Subject: [dpdk-dev] [PATCH] pktgen: Fix IPv6 addressing for set/sequence/save commands, packet headers, UI printing 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" Current IPv6 functionality in pktgen is broken. This fix makes it so that IPv6 addresses are properly set when using the set, sequence, and save commands and that the IP header and UDP/TCP psuedo-header IPV6 addresses are properly set. To preserve the runtime commands, the `_atoip` function no longer takes in flags to specify converting IPv4/6 addresses, and will try both, returning, 4, 6, or -1 for a valid IPv4/6, invalid address, respectively. Also print IPv6 addresses in UI properly. Co-authored-by Valentin Andrei Signed-off-by: Frank Li --- app/cli-functions.c | 46 +++++++++++++++++++---------------------- app/lpktgenlib.c | 26 ++++++++--------------- app/pktgen-cmds.c | 50 ++++++++++++++++++++++++++++++++++++++++----- app/pktgen-cmds.h | 3 ++- app/pktgen-ipv6.c | 9 ++++---- app/pktgen-stats.c | 23 +++++++++++++++------ app/pktgen-tcp.c | 9 ++++---- app/pktgen-udp.c | 9 ++++---- lib/utils/_atoip.c | 39 +++++++++++++++++++---------------- lib/utils/_atoip.h | 2 +- 10 files changed, 128 insertions(+), 88 deletions(-) diff --git a/app/cli-functions.c b/app/cli-functions.c index f104781..b906e86 100644 --- a/app/cli-functions.c +++ b/app/cli-functions.c @@ -214,7 +214,7 @@ range_cmd(int argc, char **argv) p = strchr(argv[4], '/'); if (p) *p = '\0'; - _atoip(val, PG_IPADDR_V4, &ip, sizeof(ip)); + _atoip(val, 0, &ip, sizeof(ip)); foreach_port(portlist, range_set_dst_ip(info, what, &ip)); break; @@ -223,7 +223,7 @@ range_cmd(int argc, char **argv) p = strchr(argv[4], '/'); if (p) *p = '\0'; - _atoip(argv[5], PG_IPADDR_V4, &ip, sizeof(ip)); + _atoip(argv[5], 0, &ip, sizeof(ip)); foreach_port(portlist, range_set_src_ip(info, what, &ip)); break; @@ -463,6 +463,7 @@ set_cmd(int argc, char **argv) struct pg_ipaddr ip; uint16_t id1, id2; uint32_t u1; + int ip_ver; m = cli_mapping(set_map, argc, argv); if (!m) @@ -527,13 +528,13 @@ set_cmd(int argc, char **argv) case 30: p = strchr(argv[4], '/'); if (!p) { - char buf[32]; - snprintf(buf, sizeof(buf), "%s/32", argv[4]); - cli_printf("src IP address should contain /NN subnet value, default /32\n"); - _atoip(buf, PG_IPADDR_V4 | PG_IPADDR_NETWORK, &ip, sizeof(ip)); - } else - _atoip(argv[4], PG_IPADDR_V4 | PG_IPADDR_NETWORK, &ip, sizeof(ip)); - foreach_port(portlist, single_set_ipaddr(info, 's', &ip)); + cli_printf("src IP address should contain subnet value, default /32 for IPv4, /128 for IPv6\n"); + } + ip_ver = _atoip(argv[4], + PG_IPADDR_V4 | PG_IPADDR_NETWORK, + &ip, sizeof(ip)); + foreach_port(portlist, + single_set_ipaddr(info, 's', &ip, ip_ver)); break; case 31: /* Remove the /XX mask value if supplied */ @@ -542,8 +543,9 @@ set_cmd(int argc, char **argv) cli_printf("Subnet mask not required, removing subnet mask value\n"); *p = '\0'; } - _atoip(argv[4], PG_IPADDR_V4, &ip, sizeof(ip)); - foreach_port(portlist, single_set_ipaddr(info, 'd', &ip)); + ip_ver = _atoip(argv[4], 0, &ip, sizeof(ip)); + foreach_port(portlist, + single_set_ipaddr(info, 'd', &ip, ip_ver)); break; case 40: pktgen_set_page_size(atoi(argv[2])); @@ -1116,15 +1118,12 @@ seq_1_set_cmd(int argc __rte_unused, char **argv) p = strchr(argv[5], '/'); /* remove subnet if found */ if (p) *p = '\0'; - _atoip(argv[5], PG_IPADDR_V4, &dst, sizeof(dst)); + _atoip(argv[5], 0, &dst, sizeof(dst)); p = strchr(argv[6], '/'); if (!p) { - char buf[32]; - cli_printf("src IP address should contain /NN subnet value, default /32\n"); - snprintf(buf, sizeof(buf), "%s/32", argv[6]); - _atoip(buf, PG_IPADDR_V4 | PG_IPADDR_NETWORK, &src, sizeof(src)); - } else - _atoip(argv[6], PG_IPADDR_V4 | PG_IPADDR_NETWORK, &src, sizeof(src)); + cli_printf("src IP address should contain subnet value, default /32 for IPv4, /128 for IPv6\n"); + } + _atoip(argv[6], PG_IPADDR_NETWORK, &src, sizeof(src)); portlist_parse(argv[2], &portlist); pg_ether_aton(argv[3], &dmac); pg_ether_aton(argv[4], &smac); @@ -1179,15 +1178,12 @@ seq_2_set_cmd(int argc __rte_unused, char **argv) p = strchr(argv[8], '/'); /* remove subnet if found */ if (p) *p = '\0'; - _atoip(argv[8], PG_IPADDR_V4, &dst, sizeof(dst)); + _atoip(argv[8], 0, &dst, sizeof(dst)); p = strchr(argv[10], '/'); if (p == NULL) { - char buf[32]; - snprintf(buf, sizeof(buf), "%s/32", argv[10]); - cli_printf("src IP address should contain /NN subnet value, default /32"); - _atoip(buf, PG_IPADDR_V4 | PG_IPADDR_NETWORK, &src, sizeof(src)); - } else - _atoip(argv[10], PG_IPADDR_V4 | PG_IPADDR_NETWORK, &src, sizeof(src)); + cli_printf("src IP address should contain subnet value, default /32 for IPv4, /128 for IPv6\n"); + } + _atoip(argv[10], PG_IPADDR_NETWORK, &src, sizeof(src)); portlist_parse(argv[2], &portlist); pg_ether_aton(argv[4], &dmac); pg_ether_aton(argv[6], &smac); diff --git a/app/lpktgenlib.c b/app/lpktgenlib.c index c29e6ac..263bb27 100644 --- a/app/lpktgenlib.c +++ b/app/lpktgenlib.c @@ -295,19 +295,11 @@ set_seq(lua_State *L, uint32_t seqnum) /* Determine if we are IPv4 or IPv6 packets */ ip = (char *)luaL_checkstring(L, 9); - if (ip[3] == '6') { - _atoip(luaL_checkstring(L, 5), PG_IPADDR_V6, - &ip_daddr, sizeof(struct pg_ipaddr)); - _atoip(luaL_checkstring(L, 6), - PG_IPADDR_NETWORK | PG_IPADDR_V6, - &ip_saddr, sizeof(struct pg_ipaddr)); - } else { - _atoip(luaL_checkstring(L, 5), PG_IPADDR_V4, - &ip_daddr, sizeof(struct pg_ipaddr)); - _atoip(luaL_checkstring(L, 6), - PG_IPADDR_NETWORK | PG_IPADDR_V4, - &ip_saddr, sizeof(struct pg_ipaddr)); - } + _atoip(luaL_checkstring(L, 5), 0, + &ip_daddr, sizeof(struct pg_ipaddr)); + _atoip(luaL_checkstring(L, 6), + PG_IPADDR_NETWORK, + &ip_saddr, sizeof(struct pg_ipaddr)); proto = (char *)luaL_checkstring(L, 10); vlanid = luaL_checkinteger(L, 11); pktsize = luaL_checkinteger(L, 12); @@ -657,6 +649,7 @@ pktgen_set_ip_addr(lua_State *L) { struct pg_ipaddr ipaddr; int flags; char *type; + int ip_ver; switch (lua_gettop(L) ) { default: return luaL_error(L, "set_ipaddr, wrong number of arguments"); @@ -665,14 +658,13 @@ pktgen_set_ip_addr(lua_State *L) { } type = (char *)luaL_checkstring(L, 2); portlist_parse(luaL_checkstring(L, 1), &portlist); - flags = PG_IPADDR_V4; if (type[0] == 's') - flags |= PG_IPADDR_NETWORK; - _atoip(luaL_checkstring(L, 3), flags, + flags = PG_IPADDR_NETWORK; + ip_ver = _atoip(luaL_checkstring(L, 3), flags, &ipaddr, sizeof(struct pg_ipaddr)); foreach_port(portlist, - single_set_ipaddr(info, type[0], &ipaddr) ); + single_set_ipaddr(info, type[0], &ipaddr, ip_ver)); pktgen_update_display(); return 0; diff --git a/app/pktgen-cmds.c b/app/pktgen-cmds.c index 0e9af7c..91312a7 100644 --- a/app/pktgen-cmds.c +++ b/app/pktgen-cmds.c @@ -173,10 +173,16 @@ pktgen_script_save(char *path) (pkt->ipProto == PG_IPPROTO_TCP) ? "tcp" : (pkt->ipProto == PG_IPPROTO_ICMP) ? "icmp" : "udp"); fprintf(fd, "set %d dst ip %s\n", i, + (pkt->ethType == ETHER_TYPE_IPv6) ? + inet_ntop6(buff, sizeof(buff), + pkt->ip_dst_addr.addr.ipv6.s6_addr) : inet_ntop4(buff, sizeof(buff), ntohl(pkt->ip_dst_addr.addr.ipv4.s_addr), 0xFFFFFFFF)); fprintf(fd, "set %d src ip %s\n", i, + (pkt->ethType == ETHER_TYPE_IPv6) ? + inet_ntop6(buff, sizeof(buff), + pkt->ip_src_addr.addr.ipv6.s6_addr) : inet_ntop4(buff, sizeof(buff), ntohl(pkt->ip_src_addr.addr.ipv4.s_addr), pkt->ip_mask)); @@ -370,11 +376,17 @@ pktgen_script_save(char *path) sizeof(buff), &pkt->eth_src_addr)); fprintf(fd, "%s ", + (pkt->ethType == ETHER_TYPE_IPv6) ? + inet_ntop6(buff, sizeof(buff), + pkt->ip_dst_addr.addr.ipv6.s6_addr) : inet_ntop4(buff, sizeof(buff), htonl(pkt->ip_dst_addr.addr.ipv4. s_addr), 0xFFFFFFFF)); fprintf(fd, "%s ", + (pkt->ethType == ETHER_TYPE_IPv6) ? + inet_ntop6(buff, sizeof(buff), + pkt->ip_src_addr.addr.ipv6.s6_addr) : inet_ntop4(buff, sizeof(buff), htonl(pkt->ip_src_addr.addr.ipv4. s_addr), @@ -537,10 +549,16 @@ pktgen_lua_save(char *path) (pkt->ipProto == PG_IPPROTO_TCP) ? "tcp" : (pkt->ipProto == PG_IPPROTO_ICMP) ? "icmp" : "udp"); fprintf(fd, "pktgen.set_ipaddr('%d', 'dst', '%s');\n", i, + (pkt->ethType == ETHER_TYPE_IPv6) ? + inet_ntop6(buff, sizeof(buff), + pkt->ip_dst_addr.addr.ipv6.s6_addr) : inet_ntop4(buff, sizeof(buff), ntohl(pkt->ip_dst_addr.addr.ipv4.s_addr), 0xFFFFFFFF)); fprintf(fd, "pktgen.set_ipaddr('%d', 'src','%s');\n", i, + (pkt->ethType == ETHER_TYPE_IPv6) ? + inet_ntop6(buff, sizeof(buff), + pkt->ip_src_addr.addr.ipv6.s6_addr) : inet_ntop4(buff, sizeof(buff), ntohl(pkt->ip_src_addr.addr.ipv4.s_addr), pkt->ip_mask)); @@ -729,11 +747,17 @@ pktgen_lua_save(char *path) sizeof(buff), &pkt->eth_src_addr)); fprintf(fd, "'%s', ", + (pkt->ethType == ETHER_TYPE_IPv6) ? + inet_ntop6(buff, sizeof(buff), + pkt->ip_dst_addr.addr.ipv6.s6_addr) : inet_ntop4(buff, sizeof(buff), htonl(pkt->ip_dst_addr.addr.ipv4. s_addr), 0xFFFFFFFF)); fprintf(fd, "'%s', ", + (pkt->ethType == ETHER_TYPE_IPv6) ? + inet_ntop6(buff, sizeof(buff), + pkt->ip_src_addr.addr.ipv6.s6_addr) : inet_ntop4(buff, sizeof(buff), htonl(pkt->ip_src_addr.addr.ipv4. s_addr), @@ -762,10 +786,16 @@ pktgen_lua_save(char *path) fprintf(fd, " ['eth_src_addr'] = '%s',\n", inet_mtoa(buff, sizeof(buff), &pkt->eth_src_addr)); fprintf(fd, " ['ip_dst_addr'] = '%s',\n", + (pkt->ethType == ETHER_TYPE_IPv6) ? + inet_ntop6(buff, sizeof(buff), + pkt->ip_dst_addr.addr.ipv6.s6_addr) : inet_ntop4(buff, sizeof(buff), htonl(pkt->ip_dst_addr.addr.ipv4.s_addr), 0xFFFFFFFF)); fprintf(fd, " ['ip_src_addr'] = '%s',\n", + (pkt->ethType == ETHER_TYPE_IPv6) ? + inet_ntop6(buff, sizeof(buff), + pkt->ip_src_addr.addr.ipv6.s6_addr) : inet_ntop4(buff, sizeof(buff), htonl(pkt->ip_src_addr.addr.ipv4.s_addr), 0xFFFFFFFF)); @@ -3037,15 +3067,25 @@ single_set_tx_rate(port_info_t *info, const char *r) */ void -single_set_ipaddr(port_info_t *info, char type, struct pg_ipaddr *ip) +single_set_ipaddr(port_info_t *info, char type, struct pg_ipaddr *ip, + int ip_ver) { - if (type == 's') { + if (type == 's' && ip_ver == 4) { info->seq_pkt[SINGLE_PKT].ip_mask = size_to_mask(ip->prefixlen); info->seq_pkt[SINGLE_PKT].ip_src_addr.addr.ipv4.s_addr = ntohl( - ip->ipv4.s_addr); - } else + ip->ipv4.s_addr); + } else if (type == 'd' && ip_ver == 4) { info->seq_pkt[SINGLE_PKT].ip_dst_addr.addr.ipv4.s_addr = ntohl( - ip->ipv4.s_addr); + ip->ipv4.s_addr); + } else if (type == 's' && ip_ver == 6) { + rte_memcpy( + info->seq_pkt[SINGLE_PKT].ip_src_addr.addr.ipv6.s6_addr, + ip->ipv6.s6_addr, sizeof(struct in6_addr)); + } else if (type == 'd' && ip_ver == 6) { + rte_memcpy( + info->seq_pkt[SINGLE_PKT].ip_dst_addr.addr.ipv6.s6_addr, + ip->ipv6.s6_addr, sizeof(struct in6_addr)); + } pktgen_packet_ctor(info, SINGLE_PKT, -1); pktgen_set_tx_update(info); } diff --git a/app/pktgen-cmds.h b/app/pktgen-cmds.h index 46055fe..033c1b9 100644 --- a/app/pktgen-cmds.h +++ b/app/pktgen-cmds.h @@ -66,7 +66,8 @@ void pktgen_port_defaults(uint32_t pid, uint8_t seq); struct pg_ipaddr; /* Single */ -void single_set_ipaddr(port_info_t *info, char type, struct pg_ipaddr *ip); +void single_set_ipaddr(port_info_t *info, char type, + struct pg_ipaddr *ip, int ip_ver); void single_set_proto(port_info_t *info, char *type); void single_set_vlan_id(port_info_t *info, uint16_t vlanid); void single_set_cos(port_info_t *info, uint8_t cos); diff --git a/app/pktgen-ipv6.c b/app/pktgen-ipv6.c index e8d3874..0430e7f 100644 --- a/app/pktgen-ipv6.c +++ b/app/pktgen-ipv6.c @@ -29,7 +29,6 @@ void pktgen_ipv6_ctor(pkt_seq_t *pkt, void *hdr) { struct pg_ipv6_hdr *ip = hdr; - uint32_t addr; uint16_t tlen; /* IPv6 Header constructor */ @@ -42,10 +41,10 @@ pktgen_ipv6_ctor(pkt_seq_t *pkt, void *hdr) ip->hop_limits = 4; ip->proto = pkt->ipProto; - addr = htonl(pkt->ip_dst_addr.addr.ipv4.s_addr); - (void)rte_memcpy(&ip->dst_addr[8], &addr, sizeof(uint32_t)); - addr = htonl(pkt->ip_src_addr.addr.ipv4.s_addr); - (void)rte_memcpy(&ip->src_addr[8], &addr, sizeof(uint32_t)); + rte_memcpy(&ip->dst_addr, pkt->ip_dst_addr.addr.ipv6.s6_addr, + sizeof(struct in6_addr)); + rte_memcpy(&ip->src_addr, pkt->ip_src_addr.addr.ipv6.s6_addr, + sizeof(struct in6_addr)); } /**************************************************************************//** diff --git a/app/pktgen-stats.c b/app/pktgen-stats.c index 572b10d..367a3b7 100644 --- a/app/pktgen-stats.c +++ b/app/pktgen-stats.c @@ -168,12 +168,23 @@ pktgen_print_static_data(void) scrn_printf(row++, col, "%*s", COLUMN_WIDTH_1, buff); pktgen_display_set_color("stats.ip"); - scrn_printf(row++, col, "%*s", COLUMN_WIDTH_1, - inet_ntop4(buff, sizeof(buff), - htonl(pkt->ip_dst_addr.addr.ipv4.s_addr), 0xFFFFFFFF)); - scrn_printf(row++, col, "%*s", COLUMN_WIDTH_1, - inet_ntop4(buff, sizeof(buff), - htonl(pkt->ip_src_addr.addr.ipv4.s_addr), pkt->ip_mask)); + if (pkt->ethType == PG_ETHER_TYPE_IPv6) { + scrn_printf(row++, col, "%*s", COLUMN_WIDTH_1, + inet_ntop6(buff, sizeof(buff), + pkt->ip_dst_addr.addr.ipv6.s6_addr)); + scrn_printf(row++, col, "%*s", COLUMN_WIDTH_1, + inet_ntop6(buff, sizeof(buff), + pkt->ip_src_addr.addr.ipv6.s6_addr)); + } else { + scrn_printf(row++, col, "%*s", COLUMN_WIDTH_1, + inet_ntop4(buff, sizeof(buff), + htonl(pkt->ip_dst_addr.addr.ipv4.s_addr), + 0xFFFFFFFF)); + scrn_printf(row++, col, "%*s", COLUMN_WIDTH_1, + inet_ntop4(buff, sizeof(buff), + htonl(pkt->ip_src_addr.addr.ipv4.s_addr), + pkt->ip_mask)); + } pktgen_display_set_color("stats.mac"); scrn_printf(row++, col, "%*s", COLUMN_WIDTH_1, inet_mtoa(buff, sizeof(buff), &pkt->eth_dst_addr)); diff --git a/app/pktgen-tcp.c b/app/pktgen-tcp.c index 7c31960..089c93a 100644 --- a/app/pktgen-tcp.c +++ b/app/pktgen-tcp.c @@ -55,15 +55,14 @@ pktgen_tcp_hdr_ctor(pkt_seq_t *pkt, void * hdr, int type) } else { struct pg_ipv6_hdr *ipv6 = (struct pg_ipv6_hdr *)hdr; struct pg_tcp_hdr *tcp = (struct pg_tcp_hdr *)&ipv6[1]; - uint32_t addr; /* Create the pseudo header and TCP information */ memset(ipv6->dst_addr, 0, sizeof(struct in6_addr)); memset(ipv6->src_addr, 0, sizeof(struct in6_addr)); - addr = htonl(pkt->ip_dst_addr.addr.ipv4.s_addr); - (void)rte_memcpy(&ipv6->dst_addr[8], &addr, sizeof(uint32_t)); - addr = htonl(pkt->ip_src_addr.addr.ipv4.s_addr); - (void)rte_memcpy(&ipv6->src_addr[8], &addr, sizeof(uint32_t)); + rte_memcpy(ipv6->dst_addr, &pkt->ip_dst_addr.addr.ipv6.s6_addr, + sizeof(struct in6_addr)); + rte_memcpy(ipv6->src_addr, &pkt->ip_src_addr.addr.ipv6.s6_addr, + sizeof(struct in6_addr)); tlen = pkt->pktSize - (pkt->ether_hdr_size + sizeof(struct pg_ipv6_hdr)); ipv6->payload_len = htons(tlen); diff --git a/app/pktgen-udp.c b/app/pktgen-udp.c index 41bb5c6..6e5dd03 100644 --- a/app/pktgen-udp.c +++ b/app/pktgen-udp.c @@ -59,17 +59,16 @@ pktgen_udp_hdr_ctor(pkt_seq_t *pkt, void *hdr, int type) if (udp->dgram_cksum == 0) udp->dgram_cksum = 0xFFFF; } else { - uint32_t addr; struct pg_ipv6_hdr *ipv6 = hdr; struct pg_udp_hdr *udp = (struct pg_udp_hdr *)&ipv6[1]; /* Create the pseudo header and TCP information */ memset(ipv6->dst_addr, 0, sizeof(struct in6_addr)); memset(ipv6->src_addr, 0, sizeof(struct in6_addr)); - addr = htonl(pkt->ip_dst_addr.addr.ipv4.s_addr); - (void)rte_memcpy(&ipv6->dst_addr[8], &addr, sizeof(uint32_t)); - addr = htonl(pkt->ip_src_addr.addr.ipv4.s_addr); - (void)rte_memcpy(&ipv6->src_addr[8], &addr, sizeof(uint32_t)); + rte_memcpy(ipv6->dst_addr, &pkt->ip_dst_addr.addr.ipv6.s6_addr, + sizeof(struct in6_addr)); + rte_memcpy(ipv6->src_addr, &pkt->ip_src_addr.addr.ipv6.s6_addr, + sizeof(struct in6_addr)); tlen = pkt->pktSize - (pkt->ether_hdr_size + sizeof(struct pg_ipv6_hdr)); diff --git a/lib/utils/_atoip.c b/lib/utils/_atoip.c index c33e6ae..1ba142c 100644 --- a/lib/utils/_atoip.c +++ b/lib/utils/_atoip.c @@ -228,6 +228,7 @@ _atoip(const char *buf, int flags, void *res, unsigned ressize) struct rte_ipaddr ipaddr; char *prefix, *prefix_end; long prefixlen = 0; + int default_max_prefix = 0; if (res && ressize < sizeof(struct rte_ipaddr)) return -1; @@ -247,35 +248,37 @@ _atoip(const char *buf, int flags, void *res, unsigned ressize) /* convert the network prefix */ if (flags & RTE_IPADDR_NETWORK) { prefix = strrchr(ip_str, '/'); - if (prefix == NULL) - return -1; - *prefix = '\0'; - prefix++; - errno = 0; - prefixlen = strtol(prefix, &prefix_end, 10); - if (errno || (*prefix_end != '\0') - || prefixlen < 0 || prefixlen > RTE_PREFIXMAX) - return -1; - ipaddr.prefixlen = prefixlen; + if (prefix == NULL) { + default_max_prefix = 1; + } else { + *prefix = '\0'; + prefix++; + errno = 0; + prefixlen = strtol(prefix, &prefix_end, 10); + if (errno || (*prefix_end != '\0') + || prefixlen < 0 || prefixlen > RTE_PREFIXMAX) + return -1; + ipaddr.prefixlen = prefixlen; + } } else ipaddr.prefixlen = 0; /* convert the IP addr */ - if ((flags & RTE_IPADDR_V4) && - inet_ipton(AF_INET, ip_str, &ipaddr.ipv4) == 1 && + if (inet_ipton(AF_INET, ip_str, &ipaddr.ipv4) == 1 && prefixlen <= RTE_V4PREFIXMAX) { + if (default_max_prefix) + ipaddr.prefixlen = RTE_V4PREFIXMAX; ipaddr.family = AF_INET; if (res) memcpy(res, &ipaddr, sizeof(ipaddr)); - return token_len; - } - - if ((flags & RTE_IPADDR_V6) && - inet_ipton(AF_INET6, ip_str, &ipaddr.ipv6) == 1) { + return 4; + } else if (inet_ipton(AF_INET6, ip_str, &ipaddr.ipv6) == 1) { ipaddr.family = AF_INET6; + if (default_max_prefix) + ipaddr.prefixlen = RTE_PREFIXMAX; if (res) memcpy(res, &ipaddr, sizeof(ipaddr)); - return token_len; + return 6; } return -1; diff --git a/lib/utils/_atoip.h b/lib/utils/_atoip.h index c03093a..322ee2d 100644 --- a/lib/utils/_atoip.h +++ b/lib/utils/_atoip.h @@ -49,7 +49,7 @@ struct rte_ipaddr { * @param ressize * Length of res in bytes. * @return - * 0 on OK and -1 on error + * 4 or 6 on OK, indicating an IPv4/v6 address, respectively, and -1 on error */ int _atoip(const char *buf, int flags, void *res, unsigned ressize); -- 2.17.1