pktgen: Fix IPv6 addressing for set/sequence/save commands, packet headers, UI printing
PATCH 1/1 pktgen: Fix IPv6 addressing for set/sequence/save commands, packet headers, UI printing
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 <[email protected]>
--- 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(-)
app/cli-functions.c +21 -25
@@ -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);
app/lpktgenlib.c +9 -17
@@ -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 ;
app/pktgen-cmds.c +45 -5
112 lines not on this page · raw message
app/pktgen-cmds.h +2 -1
@@ -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);
app/pktgen-ipv6.c +4 -5
@@ -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 )); }/**************************************************************************//**
app/pktgen-stats.c +17 -6
@@ -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));
app/pktgen-tcp.c +4 -5
@@ -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);
app/pktgen-udp.c +4 -5
@@ -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 ));
lib/utils/_atoip.c +21 -18
@@ -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 ;
lib/utils/_atoip.h +1 -1
@@ -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);
Signature · 1 line
2.17.1
Quoted 13 lines · Frank Li
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
_atoipfunction 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.
Quoted 6 lines
Also print IPv6 addresses in UI properly.
Co-authored-by Valentin Andrei <[email protected]>
Signed-off-by Frank Li <[email protected]>
Thanks I will try to find time to pull this into the next release.
Regards,
Keith