Skip to content

Commit c377017

Browse files
rlubosfabiobaltieri
authored andcommitted
net: shell: Enable IPv4/6 and iface commands if NET_NATIVE is disabled
Some commands can be executed and some statuses can be printed even if native IP is disabled. Signed-off-by: Robert Lubos <[email protected]>
1 parent 4595295 commit c377017

File tree

3 files changed

+49
-53
lines changed

3 files changed

+49
-53
lines changed

subsys/net/lib/shell/iface.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ static void print_phy_link_state(const struct shell *sh, const struct device *ph
9191
}
9292
#endif
9393

94-
#if defined(CONFIG_NET_NATIVE)
9594
static const char *iface_flags2str(struct net_if *iface)
9695
{
9796
static char str[sizeof("POINTOPOINT") + sizeof("PROMISC") +
@@ -148,17 +147,17 @@ static const char *iface_flags2str(struct net_if *iface)
148147

149148
return str;
150149
}
151-
#endif
152150

153151
static void iface_cb(struct net_if *iface, void *user_data)
154152
{
155-
#if defined(CONFIG_NET_NATIVE)
156153
struct net_shell_user_data *data = user_data;
157154
const struct shell *sh = data->sh;
158155

159-
#if defined(CONFIG_NET_IPV6)
156+
#if defined(CONFIG_NET_NATIVE_IPV6)
160157
struct net_if_ipv6_prefix *prefix;
161158
struct net_if_router *router;
159+
#endif
160+
#if defined(CONFIG_NET_IPV6)
162161
struct net_if_ipv6 *ipv6;
163162
#endif
164163
#if defined(CONFIG_NET_IPV4)
@@ -393,6 +392,7 @@ static void iface_cb(struct net_if *iface, void *user_data)
393392
PR("\t<none>\n");
394393
}
395394

395+
#if defined(CONFIG_NET_NATIVE_IPV6)
396396
count = 0;
397397

398398
PR("IPv6 prefixes (max %d):\n", NET_IF_MAX_IPV6_PREFIX);
@@ -421,6 +421,7 @@ static void iface_cb(struct net_if *iface, void *user_data)
421421
net_sprint_ipv6_addr(&router->address.in6_addr),
422422
router->is_infinite ? " infinite" : "");
423423
}
424+
#endif /* CONFIG_NET_NATIVE_IPV6 */
424425

425426
skip_ipv6:
426427

@@ -532,12 +533,6 @@ static void iface_cb(struct net_if *iface, void *user_data)
532533
iface->config.dhcpv4.attempts);
533534
}
534535
#endif /* CONFIG_NET_DHCPV4 */
535-
536-
#else
537-
ARG_UNUSED(iface);
538-
ARG_UNUSED(user_data);
539-
540-
#endif /* CONFIG_NET_NATIVE */
541536
}
542537

543538
static int cmd_net_set_mac(const struct shell *sh, size_t argc, char *argv[])

subsys/net/lib/shell/ipv4.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LOG_MODULE_DECLARE(net_shell);
1313
#include "net_shell_private.h"
1414
#include "../ip/ipv4.h"
1515

16-
#if defined(CONFIG_NET_NATIVE_IPV4)
16+
#if defined(CONFIG_NET_IPV4)
1717
static void ip_address_lifetime_cb(struct net_if *iface, void *user_data)
1818
{
1919
struct net_shell_user_data *data = user_data;
@@ -50,7 +50,7 @@ static void ip_address_lifetime_cb(struct net_if *iface, void *user_data)
5050
&ipv4->unicast[i].netmask));
5151
}
5252
}
53-
#endif /* CONFIG_NET_NATIVE_IPV4 */
53+
#endif /* CONFIG_NET_IPV4 */
5454

5555
static int cmd_net_ipv4(const struct shell *sh, size_t argc, char *argv[])
5656
{
@@ -62,14 +62,17 @@ static int cmd_net_ipv4(const struct shell *sh, size_t argc, char *argv[])
6262
}
6363

6464
#if defined(CONFIG_NET_NATIVE_IPV4)
65-
struct net_shell_user_data user_data;
66-
6765
PR("IPv4 fragmentation support : %s\n",
6866
IS_ENABLED(CONFIG_NET_IPV4_FRAGMENT) ? "enabled" :
6967
"disabled");
7068
PR("IPv4 conflict detection support : %s\n",
7169
IS_ENABLED(CONFIG_NET_IPV4_ACD) ? "enabled" :
7270
"disabled");
71+
#endif /* CONFIG_NET_NATIVE_IPV4 */
72+
73+
#if defined(CONFIG_NET_IPV4)
74+
struct net_shell_user_data user_data;
75+
7376
PR("Max number of IPv4 network interfaces "
7477
"in the system : %d\n",
7578
CONFIG_NET_IF_MAX_IPV4_COUNT);
@@ -85,14 +88,14 @@ static int cmd_net_ipv4(const struct shell *sh, size_t argc, char *argv[])
8588

8689
/* Print information about address lifetime */
8790
net_if_foreach(ip_address_lifetime_cb, &user_data);
88-
#endif
91+
#endif /* CONFIG_NET_IPV4 */
8992

9093
return 0;
9194
}
9295

9396
static int cmd_net_ip_add(const struct shell *sh, size_t argc, char *argv[])
9497
{
95-
#if defined(CONFIG_NET_NATIVE_IPV4)
98+
#if defined(CONFIG_NET_IPV4)
9699
struct net_if *iface = NULL;
97100
int idx;
98101
struct in_addr addr;
@@ -151,16 +154,15 @@ static int cmd_net_ip_add(const struct shell *sh, size_t argc, char *argv[])
151154
net_if_ipv4_set_netmask_by_addr(iface, &addr, &netmask);
152155
}
153156

154-
#else /* CONFIG_NET_NATIVE_IPV4 */
155-
PR_INFO("Set %s and %s to enable native %s support.\n",
156-
"CONFIG_NET_NATIVE", "CONFIG_NET_IPV4", "IPv4");
157-
#endif /* CONFIG_NET_NATIVE_IPV4 */
157+
#else /* CONFIG_NET_IPV4 */
158+
PR_INFO("Set %s to enable %s support.\n", "CONFIG_NET_IPV4", "IPv4");
159+
#endif /* CONFIG_NET_IPV4 */
158160
return 0;
159161
}
160162

161163
static int cmd_net_ip_del(const struct shell *sh, size_t argc, char *argv[])
162164
{
163-
#if defined(CONFIG_NET_NATIVE_IPV4)
165+
#if defined(CONFIG_NET_IPV4)
164166
struct net_if *iface = NULL;
165167
int idx;
166168
struct in_addr addr;
@@ -201,16 +203,15 @@ static int cmd_net_ip_del(const struct shell *sh, size_t argc, char *argv[])
201203
return -ENOEXEC;
202204
}
203205
}
204-
#else /* CONFIG_NET_NATIVE_IPV4 */
205-
PR_INFO("Set %s and %s to enable native %s support.\n",
206-
"CONFIG_NET_NATIVE", "CONFIG_NET_IPV4", "IPv4");
207-
#endif /* CONFIG_NET_NATIVE_IPV4 */
206+
#else /* CONFIG_NET_IPV4 */
207+
PR_INFO("Set %s to enable %s support.\n", "CONFIG_NET_IPV4", "IPv4");
208+
#endif /* CONFIG_NET_IPV4 */
208209
return 0;
209210
}
210211

211212
static int cmd_net_ip_gateway(const struct shell *sh, size_t argc, char *argv[])
212213
{
213-
#if defined(CONFIG_NET_NATIVE_IPV4)
214+
#if defined(CONFIG_NET_IPV4)
214215
struct net_if *iface;
215216
int idx;
216217
struct in_addr addr;
@@ -238,10 +239,9 @@ static int cmd_net_ip_gateway(const struct shell *sh, size_t argc, char *argv[])
238239

239240
net_if_ipv4_set_gw(iface, &addr);
240241

241-
#else /* CONFIG_NET_NATIVE_IPV4 */
242-
PR_INFO("Set %s and %s to enable native %s support.\n",
243-
"CONFIG_NET_NATIVE", "CONFIG_NET_IPV4", "IPv4");
244-
#endif /* CONFIG_NET_NATIVE_IPV4 */
242+
#else /* CONFIG_NET_IPV4 */
243+
PR_INFO("Set %s to enable %s support.\n", "CONFIG_NET_IPV4", "IPv4");
244+
#endif /* CONFIG_NET_IPV4 */
245245
return 0;
246246
}
247247

subsys/net/lib/shell/ipv6.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ void ipv6_frag_cb(struct net_ipv6_reassembly *reass, void *user_data)
5454
}
5555
#endif /* CONFIG_NET_IPV6_FRAGMENT */
5656

57-
#if defined(CONFIG_NET_NATIVE_IPV6)
58-
5957
#if defined(CONFIG_NET_IPV6_PE)
6058
static void ipv6_pe_filter_cb(struct in6_addr *prefix, bool is_denylist,
6159
void *user_data)
@@ -78,6 +76,7 @@ static void ipv6_pe_filter_cb(struct in6_addr *prefix, bool is_denylist,
7876
}
7977
#endif /* CONFIG_NET_IPV6_PE */
8078

79+
#if defined(CONFIG_NET_IPV6)
8180
static void address_lifetime_cb(struct net_if *iface, void *user_data)
8281
{
8382
struct net_shell_user_data *data = user_data;
@@ -99,25 +98,25 @@ static void address_lifetime_cb(struct net_if *iface, void *user_data)
9998
PR("Type \tState \tLifetime (sec)\tRef\tAddress\n");
10099

101100
ARRAY_FOR_EACH(ipv6->unicast, i) {
102-
struct net_if_ipv6_prefix *prefix;
103101
char remaining_str[sizeof("01234567890")];
104-
uint32_t remaining;
105-
uint8_t prefix_len;
102+
uint8_t prefix_len = 128U;
106103

107104
if (!ipv6->unicast[i].is_used ||
108105
ipv6->unicast[i].address.family != AF_INET6) {
109106
continue;
110107
}
111108

109+
#if defined(CONFIG_NET_NATIVE_IPV6)
110+
struct net_if_ipv6_prefix *prefix;
111+
uint32_t remaining;
112+
112113
remaining = net_timeout_remaining(&ipv6->unicast[i].lifetime,
113114
k_uptime_get_32());
114115

115116
prefix = net_if_ipv6_prefix_get(iface,
116117
&ipv6->unicast[i].address.in6_addr);
117118
if (prefix) {
118119
prefix_len = prefix->len;
119-
} else {
120-
prefix_len = 128U;
121120
}
122121

123122
if (ipv6->unicast[i].is_infinite) {
@@ -127,6 +126,9 @@ static void address_lifetime_cb(struct net_if *iface, void *user_data)
127126
snprintk(remaining_str, sizeof(remaining_str) - 1,
128127
"%u", remaining);
129128
}
129+
#else
130+
snprintk(remaining_str, sizeof(remaining_str) - 1, "infinite");
131+
#endif /* CONFIG_NET_NATIVE_IPV6 */
130132

131133
PR("%s \t%s\t%14s\t%ld\t%s/%d%s\n",
132134
addrtype2str(ipv6->unicast[i].addr_type),
@@ -137,13 +139,13 @@ static void address_lifetime_cb(struct net_if *iface, void *user_data)
137139
ipv6->unicast[i].is_temporary ? " (temporary)" : "");
138140
}
139141
}
140-
#endif /* CONFIG_NET_NATIVE_IPV6 */
142+
#endif /* CONFIG_NET_IPV6 */
141143

142144
static int cmd_net_ipv6(const struct shell *sh, size_t argc, char *argv[])
143145
{
144-
#if defined(CONFIG_NET_NATIVE_IPV6)
146+
#if defined(CONFIG_NET_IPV6)
145147
struct net_shell_user_data user_data;
146-
#endif
148+
#endif /* CONFIG_NET_IPV6 */
147149

148150
PR("IPv6 support : %s\n",
149151
IS_ENABLED(CONFIG_NET_IPV6) ?
@@ -189,8 +191,10 @@ static int cmd_net_ipv6(const struct shell *sh, size_t argc, char *argv[])
189191
PR("Max number of IPv6 privacy extension filters "
190192
" : %d\n",
191193
CONFIG_NET_IPV6_PE_FILTER_PREFIX_COUNT);
192-
#endif
194+
#endif /* CONFIG_NET_IPV6_PE */
195+
#endif /* CONFIG_NET_NATIVE_IPV6 */
193196

197+
#if defined(CONFIG_NET_IPV6)
194198
PR("Max number of IPv6 network interfaces "
195199
"in the system : %d\n",
196200
CONFIG_NET_IF_MAX_IPV6_COUNT);
@@ -209,15 +213,14 @@ static int cmd_net_ipv6(const struct shell *sh, size_t argc, char *argv[])
209213

210214
/* Print information about address lifetime */
211215
net_if_foreach(address_lifetime_cb, &user_data);
212-
213-
#endif /* CONFIG_NET_NATIVE_IPV6 */
216+
#endif /* CONFIG_NET_IPV6 */
214217

215218
return 0;
216219
}
217220

218221
static int cmd_net_ip6_add(const struct shell *sh, size_t argc, char *argv[])
219222
{
220-
#if defined(CONFIG_NET_NATIVE_IPV6)
223+
#if defined(CONFIG_NET_IPV6)
221224
struct net_if *iface = NULL;
222225
int idx;
223226
struct in6_addr addr;
@@ -262,16 +265,15 @@ static int cmd_net_ip6_add(const struct shell *sh, size_t argc, char *argv[])
262265
}
263266
}
264267

265-
#else /* CONFIG_NET_NATIVE_IPV6 */
266-
PR_INFO("Set %s and %s to enable native %s support.\n",
267-
"CONFIG_NET_NATIVE", "CONFIG_NET_IPV6", "IPv6");
268-
#endif /* CONFIG_NET_NATIVE_IPV6 */
268+
#else /* CONFIG_NET_IPV6 */
269+
PR_INFO("Set %s to enable %s support.\n", "CONFIG_NET_IPV6", "IPv6");
270+
#endif /* CONFIG_NET_IPV6 */
269271
return 0;
270272
}
271273

272274
static int cmd_net_ip6_del(const struct shell *sh, size_t argc, char *argv[])
273275
{
274-
#if defined(CONFIG_NET_NATIVE_IPV6)
276+
#if defined(CONFIG_NET_IPV6)
275277
struct net_if *iface = NULL;
276278
int idx;
277279
struct in6_addr addr;
@@ -317,10 +319,9 @@ static int cmd_net_ip6_del(const struct shell *sh, size_t argc, char *argv[])
317319
}
318320
}
319321

320-
#else /* CONFIG_NET_NATIVE_IPV6 */
321-
PR_INFO("Set %s and %s to enable native %s support.\n",
322-
"CONFIG_NET_NATIVE", "CONFIG_NET_IPV6", "IPv6");
323-
#endif /* CONFIG_NET_NATIVE_IPV6 */
322+
#else /* CONFIG_NET_IPV6 */
323+
PR_INFO("Set %s to enable %s support.\n", "CONFIG_NET_IPV6", "IPv6");
324+
#endif /* CONFIG_NET_IPV6 */
324325
return 0;
325326
}
326327

0 commit comments

Comments
 (0)