From c7f9bce6445d58aecff2df26fa2dc203794c2b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cenk=20G=C3=BCndo=C4=9Fan?= Date: Wed, 5 Aug 2015 22:34:52 +0200 Subject: [PATCH] sc_ipv6_nc: add ncache reset functionality --- sys/shell/commands/sc_ipv6_nc.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/sys/shell/commands/sc_ipv6_nc.c b/sys/shell/commands/sc_ipv6_nc.c index 10fd629204..b32a762ca9 100644 --- a/sys/shell/commands/sc_ipv6_nc.c +++ b/sys/shell/commands/sc_ipv6_nc.c @@ -168,13 +168,35 @@ static int _ipv6_nc_del(char *ipv6_addr_str) return 0; } +static int _ipv6_nc_reset(void) +{ + ng_ipv6_nc_t *tmp = NULL; + + for (ng_ipv6_nc_t *entry = ng_ipv6_nc_get_next(NULL); + entry != NULL; + tmp = entry, entry = ng_ipv6_nc_get_next(entry)) { + if (tmp) { + ng_ipv6_nc_remove(tmp->iface, &tmp->ipv6_addr); + } + } + + /* remove last entry */ + if (tmp) { + ng_ipv6_nc_remove(tmp->iface, &tmp->ipv6_addr); + } + + printf("success: reset neighbor cache\n"); + + return 0; +} + 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 > 1) { if ((argc == 4) && (strcmp("add", argv[1]) == 0)) { kernel_pid_t ifs[NG_NETIF_NUMOF]; size_t ifnum = ng_netif_get(ifs); @@ -199,12 +221,17 @@ int _ipv6_nc_manage(int argc, char **argv) if (strcmp("del", argv[1]) == 0) { return _ipv6_nc_del(argv[2]); } + + if (strcmp("reset", argv[1]) == 0) { + return _ipv6_nc_reset(); + } } printf("usage: %s [list]\n" " or: %s add [] \n" " * is optional if only one interface exists.\n" - " or: %s del \n", argv[0], argv[0], argv[0]); + " or: %s del \n" + " or: %s reset\n", argv[0], argv[0], argv[0], argv[0]); return 1; }