Skip to content

Commit c5b2a16

Browse files
fengming-yefabiobaltieri
authored andcommitted
net: zperf: fix download ipv6 bind fail on specific ip address
For command zperf udp download 5001 192.168.10.1, zperf will bind both ipv4 and ipv6 sockets on ipv4 address. But bind ipv6 socket will fail, thus command return fail. Fix it by check ip address when zperf download. For ipv4 address only bind ipv4 socket. For ipv6 address only bind ipv6 socket. For unspecific address bind both ipv4 and ipv6 sockets. Signed-off-by: Fengming Ye <[email protected]>
1 parent e64fc33 commit c5b2a16

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

subsys/net/lib/zperf/zperf_tcp_receiver.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,15 @@ static int tcp_bind_listen_connection(struct zsock_pollfd *pollfd,
278278
static int zperf_tcp_receiver_init(void)
279279
{
280280
int ret;
281+
int family;
281282

282283
for (int i = 0; i < ARRAY_SIZE(fds); i++) {
283284
fds[i].fd = -1;
284285
}
285286

286-
if (IS_ENABLED(CONFIG_NET_IPV4)) {
287+
family = tcp_server_addr.sa_family;
288+
289+
if (IS_ENABLED(CONFIG_NET_IPV4) && (family == AF_INET || family == AF_UNSPEC)) {
287290
struct sockaddr_in *in4_addr = zperf_get_sin();
288291
const struct in_addr *addr = NULL;
289292

@@ -329,7 +332,7 @@ static int zperf_tcp_receiver_init(void)
329332
}
330333
}
331334

332-
if (IS_ENABLED(CONFIG_NET_IPV6)) {
335+
if (IS_ENABLED(CONFIG_NET_IPV6) && (family == AF_INET6 || family == AF_UNSPEC)) {
333336
struct sockaddr_in6 *in6_addr = zperf_get_sin6();
334337
const struct in6_addr *addr = NULL;
335338

subsys/net/lib/zperf/zperf_udp_receiver.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,15 @@ static void udp_svc_handler(struct k_work *work)
311311
static int zperf_udp_receiver_init(void)
312312
{
313313
int ret;
314+
int family;
314315

315316
for (int i = 0; i < ARRAY_SIZE(fds); i++) {
316317
fds[i].fd = -1;
317318
}
318319

319-
if (IS_ENABLED(CONFIG_NET_IPV4)) {
320+
family = udp_server_addr.sa_family;
321+
322+
if (IS_ENABLED(CONFIG_NET_IPV4) && (family == AF_INET || family == AF_UNSPEC)) {
320323
const struct in_addr *in4_addr = NULL;
321324

322325
in4_addr_my = zperf_get_sin();
@@ -365,7 +368,7 @@ static int zperf_udp_receiver_init(void)
365368
fds[SOCK_ID_IPV4].events = ZSOCK_POLLIN;
366369
}
367370

368-
if (IS_ENABLED(CONFIG_NET_IPV6)) {
371+
if (IS_ENABLED(CONFIG_NET_IPV6) && (family == AF_INET6 || family == AF_UNSPEC)) {
369372
const struct in6_addr *in6_addr = NULL;
370373

371374
in6_addr_my = zperf_get_sin6();

0 commit comments

Comments
 (0)