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 <robert.lubos@nordicsemi.no>
This commit is contained in:
parent
4595295028
commit
c377017146
3 changed files with 49 additions and 53 deletions
|
|
@ -91,7 +91,6 @@ static void print_phy_link_state(const struct shell *sh, const struct device *ph
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_NATIVE)
|
||||
static const char *iface_flags2str(struct net_if *iface)
|
||||
{
|
||||
static char str[sizeof("POINTOPOINT") + sizeof("PROMISC") +
|
||||
|
|
@ -148,17 +147,17 @@ static const char *iface_flags2str(struct net_if *iface)
|
|||
|
||||
return str;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void iface_cb(struct net_if *iface, void *user_data)
|
||||
{
|
||||
#if defined(CONFIG_NET_NATIVE)
|
||||
struct net_shell_user_data *data = user_data;
|
||||
const struct shell *sh = data->sh;
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
#if defined(CONFIG_NET_NATIVE_IPV6)
|
||||
struct net_if_ipv6_prefix *prefix;
|
||||
struct net_if_router *router;
|
||||
#endif
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
struct net_if_ipv6 *ipv6;
|
||||
#endif
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
|
|
@ -393,6 +392,7 @@ static void iface_cb(struct net_if *iface, void *user_data)
|
|||
PR("\t<none>\n");
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_NATIVE_IPV6)
|
||||
count = 0;
|
||||
|
||||
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)
|
|||
net_sprint_ipv6_addr(&router->address.in6_addr),
|
||||
router->is_infinite ? " infinite" : "");
|
||||
}
|
||||
#endif /* CONFIG_NET_NATIVE_IPV6 */
|
||||
|
||||
skip_ipv6:
|
||||
|
||||
|
|
@ -532,12 +533,6 @@ skip_ipv4:
|
|||
iface->config.dhcpv4.attempts);
|
||||
}
|
||||
#endif /* CONFIG_NET_DHCPV4 */
|
||||
|
||||
#else
|
||||
ARG_UNUSED(iface);
|
||||
ARG_UNUSED(user_data);
|
||||
|
||||
#endif /* CONFIG_NET_NATIVE */
|
||||
}
|
||||
|
||||
static int cmd_net_set_mac(const struct shell *sh, size_t argc, char *argv[])
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ LOG_MODULE_DECLARE(net_shell);
|
|||
#include "net_shell_private.h"
|
||||
#include "../ip/ipv4.h"
|
||||
|
||||
#if defined(CONFIG_NET_NATIVE_IPV4)
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
static void ip_address_lifetime_cb(struct net_if *iface, void *user_data)
|
||||
{
|
||||
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)
|
|||
&ipv4->unicast[i].netmask));
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_NET_NATIVE_IPV4 */
|
||||
#endif /* CONFIG_NET_IPV4 */
|
||||
|
||||
static int cmd_net_ipv4(const struct shell *sh, size_t argc, char *argv[])
|
||||
{
|
||||
|
|
@ -62,14 +62,17 @@ static int cmd_net_ipv4(const struct shell *sh, size_t argc, char *argv[])
|
|||
}
|
||||
|
||||
#if defined(CONFIG_NET_NATIVE_IPV4)
|
||||
struct net_shell_user_data user_data;
|
||||
|
||||
PR("IPv4 fragmentation support : %s\n",
|
||||
IS_ENABLED(CONFIG_NET_IPV4_FRAGMENT) ? "enabled" :
|
||||
"disabled");
|
||||
PR("IPv4 conflict detection support : %s\n",
|
||||
IS_ENABLED(CONFIG_NET_IPV4_ACD) ? "enabled" :
|
||||
"disabled");
|
||||
#endif /* CONFIG_NET_NATIVE_IPV4 */
|
||||
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
struct net_shell_user_data user_data;
|
||||
|
||||
PR("Max number of IPv4 network interfaces "
|
||||
"in the system : %d\n",
|
||||
CONFIG_NET_IF_MAX_IPV4_COUNT);
|
||||
|
|
@ -85,14 +88,14 @@ static int cmd_net_ipv4(const struct shell *sh, size_t argc, char *argv[])
|
|||
|
||||
/* Print information about address lifetime */
|
||||
net_if_foreach(ip_address_lifetime_cb, &user_data);
|
||||
#endif
|
||||
#endif /* CONFIG_NET_IPV4 */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_net_ip_add(const struct shell *sh, size_t argc, char *argv[])
|
||||
{
|
||||
#if defined(CONFIG_NET_NATIVE_IPV4)
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
struct net_if *iface = NULL;
|
||||
int idx;
|
||||
struct in_addr addr;
|
||||
|
|
@ -151,16 +154,15 @@ static int cmd_net_ip_add(const struct shell *sh, size_t argc, char *argv[])
|
|||
net_if_ipv4_set_netmask_by_addr(iface, &addr, &netmask);
|
||||
}
|
||||
|
||||
#else /* CONFIG_NET_NATIVE_IPV4 */
|
||||
PR_INFO("Set %s and %s to enable native %s support.\n",
|
||||
"CONFIG_NET_NATIVE", "CONFIG_NET_IPV4", "IPv4");
|
||||
#endif /* CONFIG_NET_NATIVE_IPV4 */
|
||||
#else /* CONFIG_NET_IPV4 */
|
||||
PR_INFO("Set %s to enable %s support.\n", "CONFIG_NET_IPV4", "IPv4");
|
||||
#endif /* CONFIG_NET_IPV4 */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_net_ip_del(const struct shell *sh, size_t argc, char *argv[])
|
||||
{
|
||||
#if defined(CONFIG_NET_NATIVE_IPV4)
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
struct net_if *iface = NULL;
|
||||
int idx;
|
||||
struct in_addr addr;
|
||||
|
|
@ -201,16 +203,15 @@ static int cmd_net_ip_del(const struct shell *sh, size_t argc, char *argv[])
|
|||
return -ENOEXEC;
|
||||
}
|
||||
}
|
||||
#else /* CONFIG_NET_NATIVE_IPV4 */
|
||||
PR_INFO("Set %s and %s to enable native %s support.\n",
|
||||
"CONFIG_NET_NATIVE", "CONFIG_NET_IPV4", "IPv4");
|
||||
#endif /* CONFIG_NET_NATIVE_IPV4 */
|
||||
#else /* CONFIG_NET_IPV4 */
|
||||
PR_INFO("Set %s to enable %s support.\n", "CONFIG_NET_IPV4", "IPv4");
|
||||
#endif /* CONFIG_NET_IPV4 */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_net_ip_gateway(const struct shell *sh, size_t argc, char *argv[])
|
||||
{
|
||||
#if defined(CONFIG_NET_NATIVE_IPV4)
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
struct net_if *iface;
|
||||
int idx;
|
||||
struct in_addr addr;
|
||||
|
|
@ -238,10 +239,9 @@ static int cmd_net_ip_gateway(const struct shell *sh, size_t argc, char *argv[])
|
|||
|
||||
net_if_ipv4_set_gw(iface, &addr);
|
||||
|
||||
#else /* CONFIG_NET_NATIVE_IPV4 */
|
||||
PR_INFO("Set %s and %s to enable native %s support.\n",
|
||||
"CONFIG_NET_NATIVE", "CONFIG_NET_IPV4", "IPv4");
|
||||
#endif /* CONFIG_NET_NATIVE_IPV4 */
|
||||
#else /* CONFIG_NET_IPV4 */
|
||||
PR_INFO("Set %s to enable %s support.\n", "CONFIG_NET_IPV4", "IPv4");
|
||||
#endif /* CONFIG_NET_IPV4 */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,8 +54,6 @@ void ipv6_frag_cb(struct net_ipv6_reassembly *reass, void *user_data)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPV6_FRAGMENT */
|
||||
|
||||
#if defined(CONFIG_NET_NATIVE_IPV6)
|
||||
|
||||
#if defined(CONFIG_NET_IPV6_PE)
|
||||
static void ipv6_pe_filter_cb(struct in6_addr *prefix, bool is_denylist,
|
||||
void *user_data)
|
||||
|
|
@ -78,6 +76,7 @@ static void ipv6_pe_filter_cb(struct in6_addr *prefix, bool is_denylist,
|
|||
}
|
||||
#endif /* CONFIG_NET_IPV6_PE */
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
static void address_lifetime_cb(struct net_if *iface, void *user_data)
|
||||
{
|
||||
struct net_shell_user_data *data = user_data;
|
||||
|
|
@ -99,16 +98,18 @@ static void address_lifetime_cb(struct net_if *iface, void *user_data)
|
|||
PR("Type \tState \tLifetime (sec)\tRef\tAddress\n");
|
||||
|
||||
ARRAY_FOR_EACH(ipv6->unicast, i) {
|
||||
struct net_if_ipv6_prefix *prefix;
|
||||
char remaining_str[sizeof("01234567890")];
|
||||
uint32_t remaining;
|
||||
uint8_t prefix_len;
|
||||
uint8_t prefix_len = 128U;
|
||||
|
||||
if (!ipv6->unicast[i].is_used ||
|
||||
ipv6->unicast[i].address.family != AF_INET6) {
|
||||
continue;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_NATIVE_IPV6)
|
||||
struct net_if_ipv6_prefix *prefix;
|
||||
uint32_t remaining;
|
||||
|
||||
remaining = net_timeout_remaining(&ipv6->unicast[i].lifetime,
|
||||
k_uptime_get_32());
|
||||
|
||||
|
|
@ -116,8 +117,6 @@ static void address_lifetime_cb(struct net_if *iface, void *user_data)
|
|||
&ipv6->unicast[i].address.in6_addr);
|
||||
if (prefix) {
|
||||
prefix_len = prefix->len;
|
||||
} else {
|
||||
prefix_len = 128U;
|
||||
}
|
||||
|
||||
if (ipv6->unicast[i].is_infinite) {
|
||||
|
|
@ -127,6 +126,9 @@ static void address_lifetime_cb(struct net_if *iface, void *user_data)
|
|||
snprintk(remaining_str, sizeof(remaining_str) - 1,
|
||||
"%u", remaining);
|
||||
}
|
||||
#else
|
||||
snprintk(remaining_str, sizeof(remaining_str) - 1, "infinite");
|
||||
#endif /* CONFIG_NET_NATIVE_IPV6 */
|
||||
|
||||
PR("%s \t%s\t%14s\t%ld\t%s/%d%s\n",
|
||||
addrtype2str(ipv6->unicast[i].addr_type),
|
||||
|
|
@ -137,13 +139,13 @@ static void address_lifetime_cb(struct net_if *iface, void *user_data)
|
|||
ipv6->unicast[i].is_temporary ? " (temporary)" : "");
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_NET_NATIVE_IPV6 */
|
||||
#endif /* CONFIG_NET_IPV6 */
|
||||
|
||||
static int cmd_net_ipv6(const struct shell *sh, size_t argc, char *argv[])
|
||||
{
|
||||
#if defined(CONFIG_NET_NATIVE_IPV6)
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
struct net_shell_user_data user_data;
|
||||
#endif
|
||||
#endif /* CONFIG_NET_IPV6 */
|
||||
|
||||
PR("IPv6 support : %s\n",
|
||||
IS_ENABLED(CONFIG_NET_IPV6) ?
|
||||
|
|
@ -189,8 +191,10 @@ static int cmd_net_ipv6(const struct shell *sh, size_t argc, char *argv[])
|
|||
PR("Max number of IPv6 privacy extension filters "
|
||||
" : %d\n",
|
||||
CONFIG_NET_IPV6_PE_FILTER_PREFIX_COUNT);
|
||||
#endif
|
||||
#endif /* CONFIG_NET_IPV6_PE */
|
||||
#endif /* CONFIG_NET_NATIVE_IPV6 */
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
PR("Max number of IPv6 network interfaces "
|
||||
"in the system : %d\n",
|
||||
CONFIG_NET_IF_MAX_IPV6_COUNT);
|
||||
|
|
@ -209,15 +213,14 @@ static int cmd_net_ipv6(const struct shell *sh, size_t argc, char *argv[])
|
|||
|
||||
/* Print information about address lifetime */
|
||||
net_if_foreach(address_lifetime_cb, &user_data);
|
||||
|
||||
#endif /* CONFIG_NET_NATIVE_IPV6 */
|
||||
#endif /* CONFIG_NET_IPV6 */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_net_ip6_add(const struct shell *sh, size_t argc, char *argv[])
|
||||
{
|
||||
#if defined(CONFIG_NET_NATIVE_IPV6)
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
struct net_if *iface = NULL;
|
||||
int idx;
|
||||
struct in6_addr addr;
|
||||
|
|
@ -262,16 +265,15 @@ static int cmd_net_ip6_add(const struct shell *sh, size_t argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
#else /* CONFIG_NET_NATIVE_IPV6 */
|
||||
PR_INFO("Set %s and %s to enable native %s support.\n",
|
||||
"CONFIG_NET_NATIVE", "CONFIG_NET_IPV6", "IPv6");
|
||||
#endif /* CONFIG_NET_NATIVE_IPV6 */
|
||||
#else /* CONFIG_NET_IPV6 */
|
||||
PR_INFO("Set %s to enable %s support.\n", "CONFIG_NET_IPV6", "IPv6");
|
||||
#endif /* CONFIG_NET_IPV6 */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_net_ip6_del(const struct shell *sh, size_t argc, char *argv[])
|
||||
{
|
||||
#if defined(CONFIG_NET_NATIVE_IPV6)
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
struct net_if *iface = NULL;
|
||||
int idx;
|
||||
struct in6_addr addr;
|
||||
|
|
@ -317,10 +319,9 @@ static int cmd_net_ip6_del(const struct shell *sh, size_t argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
#else /* CONFIG_NET_NATIVE_IPV6 */
|
||||
PR_INFO("Set %s and %s to enable native %s support.\n",
|
||||
"CONFIG_NET_NATIVE", "CONFIG_NET_IPV6", "IPv6");
|
||||
#endif /* CONFIG_NET_NATIVE_IPV6 */
|
||||
#else /* CONFIG_NET_IPV6 */
|
||||
PR_INFO("Set %s to enable %s support.\n", "CONFIG_NET_IPV6", "IPv6");
|
||||
#endif /* CONFIG_NET_IPV6 */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue