Beispiel #1
0
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;
}
Beispiel #2
0
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;
}
Beispiel #3
0
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;
}
Beispiel #4
0
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;
}