Skip to content

Commit caea973

Browse files
committed
fix: fix build with ipv6 only
1 parent 9a6e0dc commit caea973

File tree

7 files changed

+154
-52
lines changed

7 files changed

+154
-52
lines changed

apps/.build-rules.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ apps/iperf:
22
disable:
33
- if: SOC_WIFI_SUPPORTED != 1
44
reason: This example app is using wifi connections
5+
# ipv6-only
6+
- if: CONFIG_NAME == "ipv6_only" and IDF_VERSION_MAJOR < 5
7+
reason: IDF do not support ipv6-only
8+
- if: CONFIG_NAME == "ipv6_only" and (IDF_VERSION_MAJOR == 5 and IDF_VERSION_MINOR < 1)
9+
reason: IDF do not support ipv6-only
510
# build specific configuration for only one target
611
- if: IDF_TARGET != "esp32" and CONFIG_NAME == "ipv4_only"
712
- if: IDF_TARGET != "esp32c3" and CONFIG_NAME == "ipv6_only"

apps/iperf/main/iperf_main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
*/
66
#include <errno.h>
77
#include <string.h>
8+
#include <sys/socket.h>
9+
10+
/* Build check: LWIP_IPV4/LWIP_IPV6 should be defined after include sys/socket.h */
11+
#if !(defined LWIP_IPV4) || !(defined LWIP_IPV6)
12+
#error "Both LWIP_IPV4 and LWIP_IPV6 should be defined!"
13+
#endif
14+
815
#include "esp_wifi.h"
916
#include "esp_log.h"
1017
#include "esp_err.h"

iperf-cmd/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This repository contains `iperf` command based esp-idf console.
1515
-c, --client=<host> run in client mode, connecting to <host>
1616
-s, --server run in server mode
1717
-u, --udp use UDP rather than TCP
18+
-V, --ipv6_domain Set the domain to IPv6 (send packets over IPv6)
1819
-p, --port=<port> server port to listen on/connect to
1920
-l, --len=<length> Set read/write buffer size
2021
-i, --interval=<interval> seconds between periodic bandwidth reports

iperf-cmd/iperf_cmd.c

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
#include <stdio.h>
77
#include <string.h>
88
#include <inttypes.h>
9+
#include <sys/socket.h>
910
// #include "esp_idf_version.h"
1011
#include "esp_log.h"
1112
#include "esp_console.h"
1213
#include "argtable3/argtable3.h"
14+
#include "esp_netif.h"
15+
1316
#include "iperf.h"
1417

15-
#include "esp_netif.h"
1618

1719
#ifndef APP_TAG
1820
#define APP_TAG "IPERF"
@@ -22,7 +24,9 @@ typedef struct {
2224
struct arg_str *ip;
2325
struct arg_lit *server;
2426
struct arg_lit *udp;
25-
// struct arg_lit *version6;
27+
#if IPERF_IPV6_ENABLED
28+
struct arg_lit *ipv6_domain;
29+
#endif
2630
struct arg_int *port;
2731
struct arg_int *length;
2832
struct arg_int *interval;
@@ -55,8 +59,13 @@ static int cmd_do_iperf(int argc, char **argv)
5559
}
5660

5761
memset(&cfg, 0, sizeof(cfg));
58-
// now iperf-cmd only support IPV4 address
62+
5963
cfg.type = IPERF_IP_TYPE_IPV4;
64+
#if IPERF_IPV6_ENABLED
65+
if (iperf_args.ipv6_domain->count > 0) {
66+
cfg.type = IPERF_IP_TYPE_IPV6;
67+
}
68+
#endif
6069

6170
if (((iperf_args.ip->count == 0) && (iperf_args.server->count == 0)) ||
6271
((iperf_args.ip->count != 0) && (iperf_args.server->count != 0))) {
@@ -67,12 +76,20 @@ static int cmd_do_iperf(int argc, char **argv)
6776
if (iperf_args.ip->count == 0) {
6877
cfg.flag |= IPERF_FLAG_SERVER;
6978
} else {
70-
cfg.destination_ip4 = esp_ip4addr_aton(iperf_args.ip->sval[0]);
7179
cfg.flag |= IPERF_FLAG_CLIENT;
80+
#if IPERF_IPV6_ENABLED
81+
if (cfg.type == IPERF_IP_TYPE_IPV6) {
82+
/* TODO: Refactor iperf config structure in v1.0 */
83+
cfg.destination_ip6 = (char*)(iperf_args.ip->sval[0]);
84+
}
85+
#endif
86+
#if IPERF_IPV4_ENABLED
87+
if (cfg.type == IPERF_IP_TYPE_IPV4) {
88+
cfg.destination_ip4 = esp_ip4addr_aton(iperf_args.ip->sval[0]);
89+
}
90+
#endif
7291
}
7392

74-
// NOTE: Do not bind local ip now
75-
7693
if (iperf_args.udp->count == 0) {
7794
cfg.flag |= IPERF_FLAG_TCP;
7895
} else {
@@ -137,15 +154,15 @@ static int cmd_do_iperf(int argc, char **argv)
137154
}
138155
}
139156

140-
ESP_LOGI(APP_TAG, "mode=%s-%s sip=%" PRId32 ".%" PRId32 ".%" PRId32 ".%" PRId32 ":%d,\
141-
dip=%" PRId32 ".%" PRId32 ".%" PRId32 ".%" PRId32 ":%d,\
142-
interval=%" PRId32 ", time=%" PRId32 "",
157+
ESP_LOGI(APP_TAG, "mode=%s-%s sip=%s:%" PRId32 ", dip=%s:%" PRId32 ", interval=%" PRId32 ", time=%" PRId32,
143158
cfg.flag & IPERF_FLAG_TCP ? "tcp" : "udp",
144159
cfg.flag & IPERF_FLAG_SERVER ? "server" : "client",
145-
cfg.source_ip4 & 0xFF, (cfg.source_ip4 >> 8) & 0xFF, (cfg.source_ip4 >> 16) & 0xFF,
146-
(cfg.source_ip4 >> 24) & 0xFF, cfg.sport,
147-
cfg.destination_ip4 & 0xFF, (cfg.destination_ip4 >> 8) & 0xFF,
148-
(cfg.destination_ip4 >> 16) & 0xFF, (cfg.destination_ip4 >> 24) & 0xFF, cfg.dport,
160+
"localhost", cfg.sport,
161+
#if IPERF_IPV4_ENABLED
162+
cfg.type == IPERF_IP_TYPE_IPV6? cfg.destination_ip6 : inet_ntoa(cfg.destination_ip4), cfg.dport,
163+
#else
164+
cfg.type == IPERF_IP_TYPE_IPV6? cfg.destination_ip6 : "0.0.0.0", cfg.dport,
165+
#endif
149166
cfg.interval, cfg.time);
150167

151168
iperf_start(&cfg);
@@ -159,9 +176,14 @@ esp_err_t app_register_iperf_commands(void)
159176
iperf_args.ip = arg_str0("c", "client", "<host>", "run in client mode, connecting to <host>");
160177
iperf_args.server = arg_lit0("s", "server", "run in server mode");
161178
iperf_args.udp = arg_lit0("u", "udp", "use UDP rather than TCP");
162-
// #ifdef CONFIG_LWIP_IPV6
163-
// iperf_args.version6 = arg_lit0("6", "version6", "Use IPv6 addresses");
164-
// #endif
179+
#if IPERF_IPV6_ENABLED
180+
/*
181+
* NOTE: iperf2 uses -V(--ipv6_domain or --IPv6Version) for ipv6
182+
* iperf3 uses -6(--version6)
183+
* May add a new command "iperf3" in the future
184+
*/
185+
iperf_args.ipv6_domain = arg_lit0("V", "ipv6_domain", "Set the domain to IPv6 (send packets over IPv6)");
186+
#endif
165187
iperf_args.port = arg_int0("p", "port", "<port>", "server port to listen on/connect to");
166188
iperf_args.length = arg_int0("l", "len", "<length>", "Set read/write buffer size");
167189
iperf_args.interval = arg_int0("i", "interval", "<interval>", "seconds between periodic bandwidth reports");

iperf/api.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
| define | [**IPERF\_FLAG\_SET**](#define-iperf_flag_set) (cfg, flag) ((cfg) |= (flag))<br> |
4848
| define | [**IPERF\_FLAG\_TCP**](#define-iperf_flag_tcp) (1 &lt;&lt; 2)<br> |
4949
| define | [**IPERF\_FLAG\_UDP**](#define-iperf_flag_udp) (1 &lt;&lt; 3)<br> |
50+
| define | [**IPERF\_IPV4\_ENABLED**](#define-iperf_ipv4_enabled) LWIP\_IPV4<br> |
51+
| define | [**IPERF\_IPV6\_ENABLED**](#define-iperf_ipv6_enabled) LWIP\_IPV6<br> |
5052
| define | [**IPERF\_IP\_TYPE\_IPV4**](#define-iperf_ip_type_ipv4) 0<br> |
5153
| define | [**IPERF\_IP\_TYPE\_IPV6**](#define-iperf_ip_type_ipv6) 1<br> |
5254
| define | [**IPERF\_MAX\_DELAY**](#define-iperf_max_delay) 64<br> |
@@ -281,6 +283,18 @@ ESP\_OK on success
281283
#define IPERF_FLAG_UDP (1 << 3)
282284
```
283285
286+
### define `IPERF_IPV4_ENABLED`
287+
288+
```c
289+
#define IPERF_IPV4_ENABLED LWIP_IPV4
290+
```
291+
292+
### define `IPERF_IPV6_ENABLED`
293+
294+
```c
295+
#define IPERF_IPV6_ENABLED LWIP_IPV6
296+
```
297+
284298
### define `IPERF_IP_TYPE_IPV4`
285299
286300
```c

iperf/include/iperf.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,30 @@
55
*/
66
#pragma once
77

8+
#include <sys/socket.h>
89
#include "esp_err.h"
910
#include "esp_types.h"
1011

1112
#ifdef __cplusplus
1213
extern "C" {
1314
#endif
1415

16+
/*
17+
* There's no CONFIG_LWIP_IPV4 in idf<5.1
18+
* use LWIP_IPV4 from lwipopts.h (sys/socket.h)
19+
* LWIP_IPV4 should always be defined (0/1).
20+
*/
21+
#ifndef LWIP_IPV4
22+
#error "LWIP_IPV4 should be defined from lwipopts.h (sys/socket.h)."
23+
#endif
24+
25+
/*
26+
* We only use lwip stack for now, but we may support different IP stack in the future.
27+
*/
28+
#define IPERF_IPV4_ENABLED LWIP_IPV4
29+
#define IPERF_IPV6_ENABLED LWIP_IPV6
30+
31+
1532
#define IPERF_IP_TYPE_IPV4 0
1633
#define IPERF_IP_TYPE_IPV6 1
1734
#define IPERF_TRANS_TYPE_TCP 0

0 commit comments

Comments
 (0)