int _ipv6_nc_routers(int argc, char **argv) { kernel_pid_t iface = KERNEL_PID_UNDEF; char ipv6_str[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, ipv6_addr_to_str(ipv6_str, &entry->ipv6_addr, sizeof(ipv6_str))); _print_nc_state(entry); _print_nc_type(entry); puts(""); } return 0; }
/* shell commands */ int _netif_send(int argc, char **argv) { kernel_pid_t dev; uint8_t addr[MAX_ADDR_LEN]; size_t addr_len; gnrc_pktsnip_t *pkt, *hdr; gnrc_netif_hdr_t *nethdr; uint8_t flags = 0x00; if (argc < 4) { printf("usage: %s <if> [<L2 addr>|bcast] <data>\n", argv[0]); return 1; } /* parse interface */ dev = atoi(argv[1]); if (!_is_iface(dev)) { puts("error: invalid interface given"); return 1; } /* parse address */ addr_len = gnrc_netif_addr_from_str(addr, sizeof(addr), argv[2]); if (addr_len == 0) { if (strcmp(argv[2], "bcast") == 0) { flags |= GNRC_NETIF_HDR_FLAGS_BROADCAST; } else { puts("error: invalid address given"); return 1; } } /* put packet together */ pkt = gnrc_pktbuf_add(NULL, argv[3], strlen(argv[3]), GNRC_NETTYPE_UNDEF); if (pkt == NULL) { puts("error: packet buffer full"); return 1; } hdr = gnrc_netif_hdr_build(NULL, 0, addr, addr_len); if (hdr == NULL) { puts("error: packet buffer full"); gnrc_pktbuf_release(pkt); return 1; } LL_PREPEND(pkt, hdr); nethdr = (gnrc_netif_hdr_t *)hdr->data; nethdr->flags = flags; /* and send it */ if (gnrc_netapi_send(dev, pkt) < 1) { puts("error: unable to send"); gnrc_pktbuf_release(pkt); return 1; } return 0; }
/* shell commands */ int _netif_send(int argc, char **argv) { kernel_pid_t dev; uint8_t addr[MAX_ADDR_LEN]; size_t addr_len; gnrc_pktsnip_t *pkt; gnrc_netif_hdr_t *nethdr; uint8_t flags = 0x00; if (argc < 4) { printf("usage: %s <if> [<addr>|bcast] <data>\n", argv[0]); return 1; } /* parse interface */ dev = (kernel_pid_t)atoi(argv[1]); if (!_is_iface(dev)) { puts("error: invalid interface given"); return 1; } /* parse address */ addr_len = gnrc_netif_addr_from_str(addr, sizeof(addr), argv[2]); if (addr_len == 0) { if (strcmp(argv[2], "bcast") == 0) { flags |= GNRC_NETIF_HDR_FLAGS_BROADCAST; } else { puts("error: invalid address given"); return 1; } } /* put packet together */ pkt = gnrc_pktbuf_add(NULL, argv[3], strlen(argv[3]), GNRC_NETTYPE_UNDEF); pkt = gnrc_pktbuf_add(pkt, NULL, sizeof(gnrc_netif_hdr_t) + addr_len, GNRC_NETTYPE_NETIF); nethdr = (gnrc_netif_hdr_t *)pkt->data; gnrc_netif_hdr_init(nethdr, 0, addr_len); gnrc_netif_hdr_set_dst_addr(nethdr, addr, addr_len); nethdr->flags = flags; /* and send it */ gnrc_netapi_send(dev, pkt); return 0; }
int _ipv6_nc_manage(int argc, char **argv) { if ((argc == 1) || (strcmp("list", argv[1]) == 0)) { return _ipv6_nc_list(); } 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); if (ifnum > 1) { puts("error: multiple interfaces exist."); return 1; } return _ipv6_nc_add(ifs[0], argv[2], argv[3]); } else if ((argc > 4) && (strcmp("add", argv[1]) == 0)) { kernel_pid_t iface = (kernel_pid_t)atoi(argv[2]); if (!_is_iface(iface)) { puts("error: invalid interface given."); return 1; } return _ipv6_nc_add(iface, argv[3], argv[4]); } 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 [<iface pid>] <ipv6_addr> <l2_addr>\n" " * <iface pid> is optional if only one interface exists.\n" " or: %s del <ipv6_addr>\n" " or: %s reset\n", argv[0], argv[0], argv[0], argv[0]); return 1; }
int _netif_config(int argc, char **argv) { if (argc < 2) { kernel_pid_t ifs[GNRC_NETIF_NUMOF]; size_t numof = gnrc_netif_get(ifs); for (size_t i = 0; i < numof && i < GNRC_NETIF_NUMOF; i++) { _netif_list(ifs[i]); } return 0; } else if (_is_number(argv[1])) { kernel_pid_t dev = (kernel_pid_t)atoi(argv[1]); if (_is_iface(dev)) { if (argc < 3) { _netif_list(dev); return 0; } else if (strcmp(argv[2], "set") == 0) { if (argc < 5) { _set_usage(argv[0]); return 1; } return _netif_set(argv[0], dev, argv[3], argv[4]); } else if (strcmp(argv[2], "add") == 0) { if (argc < 4) { _add_usage(argv[0]); return 1; } return _netif_add(argv[0], (kernel_pid_t)dev, argc - 3, argv + 3); } else if (strcmp(argv[2], "del") == 0) { if (argc < 4) { _del_usage(argv[0]); return 1; } return _netif_del((kernel_pid_t)dev, argv[3]); } else { return _netif_flag(argv[0], dev, argv[2]); } } else { puts("error: invalid interface given"); return 1; } } printf("usage: %s [<if_id>]\n", argv[0]); _set_usage(argv[0]); _flag_usage(argv[0]); _add_usage(argv[0]); _del_usage(argv[0]); return 1; }
int _netif_config(int argc, char **argv) { if (argc < 2) { kernel_pid_t ifs[GNRC_NETIF_NUMOF]; size_t numof = gnrc_netif_get(ifs); for (size_t i = 0; i < numof && i < GNRC_NETIF_NUMOF; i++) { _netif_list(ifs[i]); } return 0; } else if (_is_number(argv[1])) { kernel_pid_t dev = (kernel_pid_t)atoi(argv[1]); if (_is_iface(dev)) { if (argc < 3) { _netif_list(dev); return 0; } else if (strcmp(argv[2], "set") == 0) { if (argc < 5) { _set_usage(argv[0]); return 1; } return _netif_set(argv[0], dev, argv[3], argv[4]); } else if (strcmp(argv[2], "add") == 0) { if (argc < 4) { _add_usage(argv[0]); return 1; } return _netif_add(argv[0], (kernel_pid_t)dev, argc - 3, argv + 3); } else if (strcmp(argv[2], "del") == 0) { if (argc < 4) { _del_usage(argv[0]); return 1; } return _netif_del((kernel_pid_t)dev, argv[3]); } else if (strcmp(argv[2], "mtu") == 0) { if (argc < 4) { _mtu_usage(argv[0]); return 1; } return _netif_mtu((kernel_pid_t)dev, argv[3]); } #ifdef MODULE_GNRC_IPV6_NETIF else if (strcmp(argv[2], "hl") == 0) { if (argc < 4) { _hl_usage(argv[0]); return 1; } int hl; gnrc_ipv6_netif_t *entry; if (((hl = atoi(argv[3])) < 0) || (hl > UINT8_MAX)) { printf("error: Hop limit must be between %" PRIu16 " and %" PRIu16 "\n", (uint16_t)0, (uint16_t)UINT16_MAX); return 1; } if ((entry = gnrc_ipv6_netif_get(dev)) == NULL) { puts("error: unable to set hop limit."); return 1; } entry->cur_hl = hl; printf("success: set hop limit %u interface %" PRIkernel_pid "\n", hl, dev); return 0; } #endif else { return _netif_flag(argv[0], dev, argv[2]); } } else { puts("error: invalid interface given"); return 1; } } printf("usage: %s [<if_id>]\n", argv[0]); _set_usage(argv[0]); _mtu_usage(argv[0]); _hl_usage(argv[0]); _flag_usage(argv[0]); _add_usage(argv[0]); _del_usage(argv[0]); return 1; }
int _netif_config(int argc, char **argv) { if (argc < 2) { kernel_pid_t ifs[GNRC_NETIF_NUMOF]; size_t numof = gnrc_netif_get(ifs); for (size_t i = 0; i < numof && i < GNRC_NETIF_NUMOF; i++) { _netif_list(ifs[i]); } return 0; } else if (_is_number(argv[1])) { kernel_pid_t dev = atoi(argv[1]); if (_is_iface(dev)) { if (argc < 3) { _netif_list(dev); return 0; } else if (strcmp(argv[2], "set") == 0) { if (argc < 5) { _set_usage(argv[0]); return 1; } return _netif_set(argv[0], dev, argv[3], argv[4]); } else if (strcmp(argv[2], "add") == 0) { if (argc < 4) { _add_usage(argv[0]); return 1; } return _netif_add(argv[0], (kernel_pid_t)dev, argc - 3, argv + 3); } else if (strcmp(argv[2], "del") == 0) { if (argc < 4) { _del_usage(argv[0]); return 1; } return _netif_del((kernel_pid_t)dev, argv[3]); } else if (strcmp(argv[2], "mtu") == 0) { if (argc < 4) { _mtu_usage(argv[0]); return 1; } return _netif_mtu((kernel_pid_t)dev, argv[3]); } #ifdef MODULE_L2FILTER else if (strcmp(argv[2], "l2filter") == 0) { if (argc < 5) { _l2filter_usage(argv[2]); } else if (strcmp(argv[3], "add") == 0) { return _netif_addrm_l2filter(dev, argv[4], true); } else if (strcmp(argv[3], "del") == 0) { return _netif_addrm_l2filter(dev, argv[4], false); } else { _l2filter_usage(argv[2]); } return 1; } #endif #ifdef MODULE_NETSTATS else if (strcmp(argv[2], "stats") == 0) { uint8_t module; bool reset = false; /* check for requested module */ if ((argc == 3) || (strcmp(argv[3], "all") == 0)) { module = NETSTATS_ALL; } else if (strcmp(argv[3], "l2") == 0) { module = NETSTATS_LAYER2; } else if (strcmp(argv[3], "ipv6") == 0) { module = NETSTATS_IPV6; } else { printf("Module %s doesn't exist or does not provide statistics.\n", argv[3]); return 0; } /* check if reset flag was given */ if ((argc > 4) && (strncmp(argv[4], "reset", 5) == 0)) { reset = true; } if (module & NETSTATS_LAYER2) { _netif_stats((kernel_pid_t) dev, NETSTATS_LAYER2, reset); } if (module & NETSTATS_IPV6) { _netif_stats((kernel_pid_t) dev, NETSTATS_IPV6, reset); } return 1; } #endif #ifdef MODULE_GNRC_IPV6_NETIF else if (strcmp(argv[2], "hl") == 0) { if (argc < 4) { _hl_usage(argv[0]); return 1; } int hl; gnrc_ipv6_netif_t *entry; if (((hl = atoi(argv[3])) < 0) || (hl > UINT8_MAX)) { printf("error: Hop limit must be between %" PRIu16 " and %" PRIu16 "\n", (uint16_t)0, (uint16_t)UINT16_MAX); return 1; } if ((entry = gnrc_ipv6_netif_get(dev)) == NULL) { puts("error: unable to set hop limit."); return 1; } entry->cur_hl = hl; printf("success: set hop limit %u interface %" PRIkernel_pid "\n", hl, dev); return 0; } #endif else { return _netif_flag(argv[0], dev, argv[2]); } } else { puts("error: invalid interface given"); return 1; } } printf("usage: %s [<if_id>]\n", argv[0]); _set_usage(argv[0]); _mtu_usage(argv[0]); #ifdef MODULE_GNRC_IPV6_NETIF _hl_usage(argv[0]); #endif _flag_usage(argv[0]); _add_usage(argv[0]); _del_usage(argv[0]); #ifdef MODULE_L2FILTER _l2filter_usage(argv[0]); #endif #ifdef MODULE_NETSTATS _stats_usage(argv[0]); #endif return 1; }
int _gnrc_netif_config(int argc, char **argv) { if (argc < 2) { gnrc_netif_t *netif = NULL; while ((netif = gnrc_netif_iter(netif))) { _netif_list(netif->pid); } return 0; } else if (_is_number(argv[1])) { kernel_pid_t iface = atoi(argv[1]); if (_is_iface(iface)) { if (argc < 3) { _netif_list(iface); return 0; } else if (strcmp(argv[2], "set") == 0) { if (argc < 5) { _set_usage(argv[0]); return 1; } return _netif_set(argv[0], iface, argv[3], argv[4]); } else if (strcmp(argv[2], "add") == 0) { if (argc < 4) { _add_usage(argv[0]); return 1; } return _netif_add(argv[0], (kernel_pid_t)iface, argc - 3, argv + 3); } else if (strcmp(argv[2], "del") == 0) { if (argc < 4) { _del_usage(argv[0]); return 1; } return _netif_del((kernel_pid_t)iface, argv[3]); } #ifdef MODULE_L2FILTER else if (strcmp(argv[2], "l2filter") == 0) { if (argc < 5) { _l2filter_usage(argv[2]); } else if (strcmp(argv[3], "add") == 0) { return _netif_addrm_l2filter(iface, argv[4], true); } else if (strcmp(argv[3], "del") == 0) { return _netif_addrm_l2filter(iface, argv[4], false); } else { _l2filter_usage(argv[2]); } return 1; } #endif #ifdef MODULE_NETSTATS else if (strcmp(argv[2], "stats") == 0) { uint8_t module; bool reset = false; /* check for requested module */ if ((argc == 3) || (strcmp(argv[3], "all") == 0)) { module = NETSTATS_ALL; } else if (strcmp(argv[3], "l2") == 0) { module = NETSTATS_LAYER2; } else if (strcmp(argv[3], "ipv6") == 0) { module = NETSTATS_IPV6; } else { printf("Module %s doesn't exist or does not provide statistics.\n", argv[3]); return 0; } /* check if reset flag was given */ if ((argc > 4) && (strncmp(argv[4], "reset", 5) == 0)) { reset = true; } if (module & NETSTATS_LAYER2) { _netif_stats((kernel_pid_t) iface, NETSTATS_LAYER2, reset); } if (module & NETSTATS_IPV6) { _netif_stats((kernel_pid_t) iface, NETSTATS_IPV6, reset); } return 1; } #endif else if (strcmp(argv[2], "help") == 0) { _usage(argv[0]); return 0; } else { return _netif_flag(argv[0], iface, argv[2]); } } else { puts("error: invalid interface given"); return 1; } } _usage(argv[0]); return 1; }