Skip to content

Commit bf79e2f

Browse files
Merge pull request #465 from espressif-abhikroy/component/ifconfig_bug_fix
fix(console): Fixed ifconfig command for PPP interface and IPv4 only
2 parents d2e4370 + a22c9e8 commit bf79e2f

File tree

5 files changed

+88
-19
lines changed

5 files changed

+88
-19
lines changed

components/console_cmd_ifconfig/.cz.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ commitizen:
33
bump_message: 'bump(console): $current_version -> $new_version'
44
pre_bump_hooks: python ../../ci/changelog.py console_cmd_ifconfig
55
tag_format: console_cmd_ifconfig-v$version
6-
version: 1.0.0
6+
version: 1.0.1
77
version_files:
88
- idf_component.yml

components/console_cmd_ifconfig/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [1.0.1](https://github.com/espressif/esp-protocols/commits/console_cmd_ifconfig-v1.0.1)
4+
5+
### Bug Fixes
6+
7+
- Fixed ifconfig command for PPP interface and IPv4 only ([8548dabb](https://github.com/espressif/esp-protocols/commit/8548dabb))
8+
39
## [1.0.0](https://github.com/espressif/esp-protocols/commits/console_cmd_ifconfig-v1.0.0)
410

511
### Features

components/console_cmd_ifconfig/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,52 @@ For more details refer [IDF Component Manager](https://docs.espressif.com/projec
6262
ifconfig <iface> dhcp client <enable/disable>: Enable or disable the DHCP client.
6363
Note: Disabling the DHCP server and client enables the use of static IP configuration.
6464
```
65+
66+
## Usage:
67+
68+
### Creating an ethernet interface
69+
```
70+
esp> ifconfig eth init
71+
Internal(IP101): pins: 23,18, Id: 0
72+
esp> ifconfig netif create 0
73+
```
74+
75+
### Removing an interface and deinitializing ethernet
76+
```
77+
esp> ifconfig netif destroy en1
78+
I (8351266) ethernet_init: Ethernet(IP101[23,18]) Link Down
79+
I (8351266) ethernet_init: Ethernet(IP101[23,18]) Stopped
80+
esp> ifconfig eth deinit
81+
```
82+
83+
### Set default interface
84+
```
85+
esp> ifconfig en1 default
86+
```
87+
88+
### Enable NAPT on an interface
89+
```
90+
esp> ifconfig en1 napt enable
91+
I (8467116) console_ifconfig: Setting napt enable on en1
92+
```
93+
94+
### Enable DHCP client on an interface
95+
```
96+
esp> ifconfig en1 dhcp client enable
97+
```
98+
99+
### Enable static IP on an interface
100+
```
101+
esp> ifconfig en1 dhcp client disable
102+
```
103+
104+
### Set static IP address
105+
```
106+
esp> ifconfig en1 ip 192.168.5.2
107+
I (111466) console_ifconfig: Setting ip: 192.168.5.2
108+
esp> ifconfig en1 mask 255.255.255.0
109+
I (130946) console_ifconfig: Setting mask: 255.255.255.0
110+
esp> ifconfig en1 gw 192.168.5.1
111+
I (143576) console_ifconfig: Setting gw: 192.168.5.1
112+
I (143576) esp_netif_handlers: eth ip: 192.168.5.2, mask: 255.255.255.0, gw: 192.168.5.1
113+
```

components/console_cmd_ifconfig/console_ifconfig.c

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
#include "argtable3/argtable3.h"
1717
#include "esp_log.h"
1818
#include "esp_netif_net_stack.h"
19+
#if CONFIG_LWIP_IPV6
1920
#include "lwip/ip6.h"
21+
#endif
2022
#include "lwip/opt.h"
2123
#include "ethernet_init.h"
2224
#include "console_ifconfig.h"
@@ -65,7 +67,9 @@ netif_op_t cmd_list[] = {
6567
{.name = "ifconfig", .operation = ifcfg_print_op, .arg_cnt = 1, .start_index = 0, .netif_flag = false, .help = "ifconfig: Display a list of all esp_netif interfaces along with their information"},
6668
{.name = "ifconfig", .operation = ifcfg_print_op, .arg_cnt = 2, .start_index = 0, .netif_flag = true, .help = "ifconfig <iface>: Provide the details of the named interface"},
6769
{.name = "default", .operation = ifcfg_basic_op, .arg_cnt = 3, .start_index = 2, .netif_flag = true, .help = "ifconfig <iface> default: Set the specified interface as the default interface"},
70+
#if CONFIG_LWIP_IPV6
6871
{.name = "ip6", .operation = ifcfg_basic_op, .arg_cnt = 3, .start_index = 2, .netif_flag = true, .help = "ifconfig <iface> ip6: Enable IPv6 on the specified interface"},
72+
#endif
6973
{.name = "up", .operation = ifcfg_lwip_op, .arg_cnt = 3, .start_index = 2, .netif_flag = true, .help = "ifconfig <iface> up: Enable the specified interface"},
7074
{.name = "down", .operation = ifcfg_lwip_op, .arg_cnt = 3, .start_index = 2, .netif_flag = true, .help = "ifconfig <iface> down: Disable the specified interface"},
7175
{.name = "link", .operation = ifcfg_lwip_op, .arg_cnt = 4, .start_index = 2, .netif_flag = true, .help = "ifconfig <iface> link <up/down>: Enable or disable the link of the specified interface"},
@@ -99,10 +103,10 @@ static esp_netif_t *get_esp_netif_from_ifname(char *if_name)
99103
char interface[10];
100104

101105
/* Get interface details and obtain the global IPv6 address */
102-
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
103-
while ((esp_netif = esp_netif_next(esp_netif)) != NULL) {
104-
#else
106+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
105107
while ((esp_netif = esp_netif_next_unsafe(esp_netif)) != NULL) {
108+
#else
109+
while ((esp_netif = esp_netif_next(esp_netif)) != NULL) {
106110
#endif
107111
ret = esp_netif_get_netif_impl_name(esp_netif, interface);
108112

@@ -128,12 +132,13 @@ static esp_err_t ifcfg_basic_op(netif_op_t *self, int argc, char *argv[], esp_ne
128132
return ESP_OK;
129133
}
130134

135+
#if CONFIG_LWIP_IPV6
131136
/* Enable IPv6 on this interface */
132137
if (!strcmp("ip6", argv[self->start_index])) {
133138
ESP_ERROR_CHECK(esp_netif_create_ip6_linklocal(esp_netif));
134139
return ESP_OK;
135140
}
136-
141+
#endif
137142
return ESP_FAIL;
138143
}
139144

@@ -216,10 +221,10 @@ static esp_err_t set_napt(char *if_name, bool state)
216221

217222
/* Get interface details and own global ipv6 address */
218223
for (int i = 0; i < esp_netif_get_nr_of_ifs(); ++i) {
219-
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
220-
esp_netif = esp_netif_next(esp_netif);
221-
#else
224+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
222225
esp_netif = esp_netif_next_unsafe(esp_netif);
226+
#else
227+
esp_netif = esp_netif_next(esp_netif);
223228
#endif
224229
ret = esp_netif_get_netif_impl_name(esp_netif, interface);
225230
if ((ESP_FAIL == ret) || (NULL == esp_netif)) {
@@ -228,9 +233,7 @@ static esp_err_t set_napt(char *if_name, bool state)
228233
}
229234

230235
if (!strcmp(interface, if_name)) {
231-
struct netif *lwip_netif = esp_netif_get_netif_impl(esp_netif);
232-
ip_napt_enable_netif(lwip_netif, state);
233-
return ESP_OK;
236+
return esp_netif_napt_enable(esp_netif);
234237
}
235238
}
236239

@@ -303,8 +306,10 @@ static void print_iface_details(esp_netif_t *esp_netif)
303306
esp_netif_ip_info_t ip_info;
304307
uint8_t mac[NETIF_MAX_HWADDR_LEN];
305308
char interface[10];
309+
#if CONFIG_LWIP_IPV6
306310
int ip6_addrs_count = 0;
307311
esp_ip6_addr_t ip6[LWIP_IPV6_NUM_ADDRESSES];
312+
#endif
308313
esp_err_t ret = ESP_FAIL;
309314
esp_netif_dhcp_status_t status;
310315

@@ -326,7 +331,9 @@ static void print_iface_details(esp_netif_t *esp_netif)
326331
#else
327332
ESP_LOGI(TAG, "Interface Name: %s", interface);
328333
#endif
329-
ESP_LOGI(TAG, "Interface Number: %d", lwip_netif->num);
334+
if (lwip_netif != NULL) {
335+
ESP_LOGI(TAG, "Interface Number: %d", lwip_netif->num);
336+
}
330337

331338
/* Print MAC address */
332339
esp_netif_get_mac(esp_netif, mac);
@@ -350,19 +357,25 @@ static void print_iface_details(esp_netif_t *esp_netif)
350357

351358
#if IP_NAPT
352359
/* Print NAPT status*/
353-
ESP_LOGI(TAG, "NAPT: %s", lwip_netif->napt ? "enabled" : "disabled");
360+
if (lwip_netif != NULL) {
361+
ESP_LOGI(TAG, "NAPT: %s", lwip_netif->napt ? "enabled" : "disabled");
362+
}
354363
#endif
355364

365+
#if CONFIG_LWIP_IPV6
356366
/* Print IPv6 Address */
357367
ip6_addrs_count = esp_netif_get_all_ip6(esp_netif, ip6);
358368
for (int j = 0; j < ip6_addrs_count; ++j) {
359369
ESP_LOGI(TAG, "IPv6 address: " IPV6STR, IPV62STR(ip6[j]));
360370
}
371+
#endif
361372

362373
/* Print Interface and Link Status*/
363374
ESP_LOGI(TAG, "Interface Status: %s", esp_netif_is_netif_up(esp_netif) ? "UP" : "DOWN");
364-
ESP_LOGI(TAG, "Link Status: %s\n", netif_is_link_up(lwip_netif) ? "UP" : "DOWN");
365-
375+
if (lwip_netif != NULL) {
376+
ESP_LOGI(TAG, "Link Status: %s", netif_is_link_up(lwip_netif) ? "UP" : "DOWN");
377+
}
378+
ESP_LOGI(TAG, "");
366379
}
367380

368381

@@ -376,10 +389,10 @@ static esp_err_t ifcfg_print_op(netif_op_t *self, int argc, char *argv[], esp_ne
376389

377390
/* Get interface details and own global ipv6 address of all interfaces */
378391
for (int i = 0; i < esp_netif_get_nr_of_ifs(); ++i) {
379-
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
380-
esp_netif = esp_netif_next(esp_netif);
381-
#else
392+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
382393
esp_netif = esp_netif_next_unsafe(esp_netif);
394+
#else
395+
esp_netif = esp_netif_next(esp_netif);
383396
#endif
384397
print_iface_details(esp_netif);
385398
}
@@ -424,6 +437,7 @@ static esp_err_t get_netif_config(uint16_t id, esp_netif_config_t *eth_cfg_o)
424437
return ESP_FAIL;
425438
}
426439
*esp_eth_base_config = (esp_netif_inherent_config_t)ESP_NETIF_INHERENT_DEFAULT_ETH();
440+
427441
esp_eth_base_config->if_key = if_key;
428442

429443
eth_cfg_o->base = esp_eth_base_config;

components/console_cmd_ifconfig/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 1.0.0
1+
version: 1.0.1
22
url: https://github.com/espressif/esp-protocols/tree/master/components/console_cmd_ifconfig
33
description: The component offers a console that enables runtime network interface configuration and monitoring.
44
dependencies:

0 commit comments

Comments
 (0)