Skip to content

Commit

Permalink
netdev_tap: make NETDEV_TAP_MAX an upper bound
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Feb 26, 2022
1 parent 1975be9 commit 2b367f3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
12 changes: 4 additions & 8 deletions cpu/native/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/lwip/init_devs/auto_init_netdev_tap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions sys/net/gnrc/netif/init_devs/auto_init_netdev_tap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit 2b367f3

Please sign in to comment.