mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
shell: add support for nc iterators
This commit is contained in:
parent
bbf57d1691
commit
188c1a4ca9
@ -26,6 +26,64 @@
|
||||
/* maximum length of L2 address */
|
||||
#define MAX_L2_ADDR_LEN (8U)
|
||||
|
||||
static void _print_nc_state(ng_ipv6_nc_t *entry)
|
||||
{
|
||||
switch (entry->flags & NG_IPV6_NC_STATE_MASK) {
|
||||
case NG_IPV6_NC_STATE_UNMANAGED:
|
||||
printf("UNMANAGED");
|
||||
break;
|
||||
|
||||
case NG_IPV6_NC_STATE_UNREACHABLE:
|
||||
printf("UNREACHABLE");
|
||||
break;
|
||||
|
||||
case NG_IPV6_NC_STATE_INCOMPLETE:
|
||||
printf("INCOMPLETE");
|
||||
break;
|
||||
|
||||
case NG_IPV6_NC_STATE_STALE:
|
||||
printf("STALE");
|
||||
break;
|
||||
|
||||
case NG_IPV6_NC_STATE_DELAY:
|
||||
printf("DELAY");
|
||||
break;
|
||||
|
||||
case NG_IPV6_NC_STATE_PROBE:
|
||||
printf("PROBE");
|
||||
break;
|
||||
|
||||
case NG_IPV6_NC_STATE_REACHABLE:
|
||||
printf("REACHABLE");
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("UNKNOWN");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void _print_nc_type(ng_ipv6_nc_t *entry)
|
||||
{
|
||||
switch (entry->flags & NG_IPV6_NC_TYPE_MASK) {
|
||||
case NG_IPV6_NC_TYPE_GC:
|
||||
printf("GC");
|
||||
break;
|
||||
|
||||
case NG_IPV6_NC_TYPE_TENTATIVE:
|
||||
printf("T");
|
||||
break;
|
||||
|
||||
case NG_IPV6_NC_TYPE_REGISTERED:
|
||||
printf("R");
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("-");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static bool _is_iface(kernel_pid_t iface)
|
||||
{
|
||||
#ifdef MODULE_NG_NETIF
|
||||
@ -44,6 +102,30 @@ static bool _is_iface(kernel_pid_t iface)
|
||||
#endif
|
||||
}
|
||||
|
||||
static int _ipv6_nc_list(void)
|
||||
{
|
||||
char ipv6_str[NG_IPV6_ADDR_MAX_STR_LEN];
|
||||
char l2addr_str[3 * MAX_L2_ADDR_LEN];
|
||||
|
||||
puts("IPv6 address if L2 address state type");
|
||||
puts("-----------------------------------------------------------------------------");
|
||||
|
||||
for (ng_ipv6_nc_t *entry = ng_ipv6_nc_get_next(NULL);
|
||||
entry != NULL;
|
||||
entry = ng_ipv6_nc_get_next(entry)) {
|
||||
printf("%-30s %2" PRIkernel_pid " %-24s ",
|
||||
ng_ipv6_addr_to_str(ipv6_str, &entry->ipv6_addr, sizeof(ipv6_str)),
|
||||
entry->iface,
|
||||
ng_netif_addr_to_str(l2addr_str, sizeof(l2addr_str),
|
||||
entry->l2_addr, entry->l2_addr_len));
|
||||
_print_nc_state(entry);
|
||||
_print_nc_type(entry);
|
||||
puts("");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _ipv6_nc_add(kernel_pid_t iface, char *ipv6_addr_str,
|
||||
char *l2_addr_str)
|
||||
{
|
||||
@ -88,6 +170,10 @@ static int _ipv6_nc_del(char *ipv6_addr_str)
|
||||
|
||||
int _ipv6_nc_manage(int argc, char **argv)
|
||||
{
|
||||
if ((argc == 1) || (strcmp("list", argv[1]) == 0)) {
|
||||
return _ipv6_nc_list();
|
||||
}
|
||||
|
||||
if (argc > 2) {
|
||||
if ((argc > 4) && (strcmp("add", argv[1]) == 0)) {
|
||||
kernel_pid_t iface = (kernel_pid_t)atoi(argv[2]);
|
||||
@ -105,11 +191,46 @@ int _ipv6_nc_manage(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
printf("usage: %s add <iface pid> <ipv6_addr> <l2_addr>\n"
|
||||
" or: %s del <ipv6_addr>\n", argv[0], argv[0]);
|
||||
printf("usage: %s [list]\n"
|
||||
" or: %s add <iface pid> <ipv6_addr> <l2_addr>\n"
|
||||
" or: %s del <ipv6_addr>\n", argv[0], argv[0], argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _ipv6_nc_routers(int argc, char **argv)
|
||||
{
|
||||
kernel_pid_t iface = KERNEL_PID_UNDEF;
|
||||
char ipv6_str[NG_IPV6_ADDR_MAX_STR_LEN];
|
||||
|
||||
if (argc > 1) {
|
||||
iface = atoi(argv[1]);
|
||||
|
||||
if (!_is_iface(iface)) {
|
||||
printf("usage: %s [<iface pid>]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
puts("if Router state type");
|
||||
puts("---------------------------------------------------");
|
||||
|
||||
for (ng_ipv6_nc_t *entry = ng_ipv6_nc_get_next_router(NULL);
|
||||
entry != NULL;
|
||||
entry = ng_ipv6_nc_get_next_router(entry)) {
|
||||
if ((iface != KERNEL_PID_UNDEF) && (iface != entry->iface)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("%2" PRIkernel_pid " %-30s ", entry->iface,
|
||||
ng_ipv6_addr_to_str(ipv6_str, &entry->ipv6_addr, sizeof(ipv6_str)));
|
||||
_print_nc_state(entry);
|
||||
_print_nc_type(entry);
|
||||
puts("");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
@ -165,6 +165,7 @@ extern int _fib_route_handler(int argc, char **argv);
|
||||
|
||||
#ifdef MODULE_NG_IPV6_NC
|
||||
extern int _ipv6_nc_manage(int argc, char **argv);
|
||||
extern int _ipv6_nc_routers(int argc, char **argv);
|
||||
#endif
|
||||
|
||||
const shell_command_t _shell_command_list[] = {
|
||||
@ -273,6 +274,7 @@ const shell_command_t _shell_command_list[] = {
|
||||
#endif
|
||||
#ifdef MODULE_NG_IPV6_NC
|
||||
{"ncache", "manage neighbor cache by hand", _ipv6_nc_manage },
|
||||
{"routers", "IPv6 default router list", _ipv6_nc_routers },
|
||||
#endif
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user