1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

netdev_tap: make NETDEV_TAP_MAX an upper bound

This commit is contained in:
Benjamin Valentin 2022-02-26 15:50:31 +01:00
parent 2520aaf1e8
commit fad65011b7
3 changed files with 11 additions and 8 deletions

View File

@ -478,6 +478,7 @@ __attribute__((constructor)) static void startup(int argc, char **argv, char **e
int c, opt_idx = 0, uart = 0;
#ifdef MODULE_NETDEV_TAP
unsigned taps = 0;
memset(netdev_tap_params, 0, sizeof(netdev_tap_params));
#endif
#ifdef MODULE_SOCKET_ZEP
unsigned zeps = 0;
@ -599,14 +600,6 @@ __attribute__((constructor)) static void startup(int argc, char **argv, char **e
break;
}
}
#ifdef MODULE_NETDEV_TAP
for (unsigned i = 0; i < NETDEV_TAP_MAX - taps; i++) {
if (argv[optind + i] == NULL) {
/* no tap parameter left */
usage_exit(EXIT_FAILURE);
}
}
#endif
#ifdef MODULE_SOCKET_ZEP
if (zeps != SOCKET_ZEP_MAX) {
/* not enough ZEPs given */
@ -672,6 +665,9 @@ __attribute__((constructor)) static void startup(int argc, char **argv, char **e
native_interrupt_init();
#ifdef MODULE_NETDEV_TAP
for (unsigned i = 0; taps < NETDEV_TAP_MAX; ++taps, ++i) {
if (argv[optind + i] == NULL) {
break;
}
netdev_tap_params[taps].tap_name = &argv[optind + i];
netdev_tap_params[taps].wired = true;
}

View File

@ -33,6 +33,9 @@ static netdev_tap_t netdev_taps[NETIF_TAP_NUMOF];
static void auto_init_netdev_tap(void)
{
for (unsigned i = 0; i < NETIF_TAP_NUMOF; i++) {
if (netdev_tap_params[i].tap_name == NULL) {
continue;
}
netdev_tap_setup(&netdev_taps[i], &netdev_tap_params[i], i);
if (lwip_add_ethernet(&netif[i], &netdev_taps[i].netdev) == NULL) {
DEBUG("Could not add netdev_tap device\n");

View File

@ -35,6 +35,10 @@ void auto_init_netdev_tap(void)
for (unsigned i = 0; i < NETDEV_TAP_MAX; i++) {
const netdev_tap_params_t *p = &netdev_tap_params[i];
if (p->tap_name == NULL) {
continue;
}
LOG_DEBUG("[auto_init_netif] initializing netdev_tap #%u on TAP %s\n",
i, *(p->tap_name));