mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #17709 from benpicco/cpu/native-tap_wired
netdev_tap: make 'wired' property configurable
This commit is contained in:
commit
c4e202ae67
@ -25,6 +25,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include "net/netdev.h"
|
#include "net/netdev.h"
|
||||||
|
|
||||||
#include "net/ethernet/hdr.h"
|
#include "net/ethernet/hdr.h"
|
||||||
@ -43,7 +44,8 @@ typedef struct netdev_tap {
|
|||||||
char tap_name[IFNAMSIZ]; /**< host dev file name */
|
char tap_name[IFNAMSIZ]; /**< host dev file name */
|
||||||
int tap_fd; /**< host file descriptor for the TAP */
|
int tap_fd; /**< host file descriptor for the TAP */
|
||||||
uint8_t addr[ETHERNET_ADDR_LEN]; /**< The MAC address of the TAP */
|
uint8_t addr[ETHERNET_ADDR_LEN]; /**< The MAC address of the TAP */
|
||||||
uint8_t promiscuous; /**< Flag for promiscuous mode */
|
bool promiscuous; /**< Flag for promiscuous mode */
|
||||||
|
bool wired; /**< Flag for wired mode */
|
||||||
} netdev_tap_t;
|
} netdev_tap_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,6 +54,8 @@ typedef struct netdev_tap {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
char **tap_name; /**< Name of the host system's tap
|
char **tap_name; /**< Name of the host system's tap
|
||||||
interface to bind to. */
|
interface to bind to. */
|
||||||
|
bool wired; /**< Interface should behave like a
|
||||||
|
wired interface. */
|
||||||
} netdev_tap_params_t;
|
} netdev_tap_params_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,6 +94,12 @@ static inline int _set_promiscuous(netdev_t *netdev, int value)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int _get_wired(netdev_t *netdev)
|
||||||
|
{
|
||||||
|
netdev_tap_t *dev = container_of(netdev, netdev_tap_t, netdev);
|
||||||
|
return dev->wired;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void _isr(netdev_t *netdev)
|
static inline void _isr(netdev_t *netdev)
|
||||||
{
|
{
|
||||||
if (netdev->event_callback) {
|
if (netdev->event_callback) {
|
||||||
@ -124,6 +130,16 @@ static int _get(netdev_t *dev, netopt_t opt, void *value, size_t max_len)
|
|||||||
*((bool*)value) = (bool)_get_promiscuous(dev);
|
*((bool*)value) = (bool)_get_promiscuous(dev);
|
||||||
res = sizeof(bool);
|
res = sizeof(bool);
|
||||||
break;
|
break;
|
||||||
|
case NETOPT_IS_WIRED:
|
||||||
|
if (!_get_wired(dev)) {
|
||||||
|
res = -ENOTSUP;
|
||||||
|
} else {
|
||||||
|
if (value) {
|
||||||
|
*((bool*)value) = true;
|
||||||
|
}
|
||||||
|
res = sizeof(bool);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
res = netdev_eth_get(dev, opt, value, max_len);
|
res = netdev_eth_get(dev, opt, value, max_len);
|
||||||
break;
|
break;
|
||||||
@ -294,6 +310,7 @@ void netdev_tap_setup(netdev_tap_t *dev, const netdev_tap_params_t *params, int
|
|||||||
dev->netdev.driver = &netdev_driver_tap;
|
dev->netdev.driver = &netdev_driver_tap;
|
||||||
strncpy(dev->tap_name, *(params->tap_name), IFNAMSIZ - 1);
|
strncpy(dev->tap_name, *(params->tap_name), IFNAMSIZ - 1);
|
||||||
dev->tap_name[IFNAMSIZ - 1] = '\0';
|
dev->tap_name[IFNAMSIZ - 1] = '\0';
|
||||||
|
dev->wired = params->wired;
|
||||||
netdev_register(&dev->netdev, NETDEV_TAP, index);
|
netdev_register(&dev->netdev, NETDEV_TAP, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +115,9 @@ static const char short_opts[] = ":hi:s:deEoc:"
|
|||||||
#endif
|
#endif
|
||||||
#ifdef MODULE_PERIPH_SPIDEV_LINUX
|
#ifdef MODULE_PERIPH_SPIDEV_LINUX
|
||||||
"p:"
|
"p:"
|
||||||
|
#endif
|
||||||
|
#ifdef MODULE_NETDEV_TAP
|
||||||
|
"w:"
|
||||||
#endif
|
#endif
|
||||||
"";
|
"";
|
||||||
|
|
||||||
@ -367,6 +370,11 @@ void usage_exit(int status)
|
|||||||
" -M <eeprom> , --eeprom=<eeprom>\n"
|
" -M <eeprom> , --eeprom=<eeprom>\n"
|
||||||
" Specify the file path where the EEPROM content is stored\n"
|
" Specify the file path where the EEPROM content is stored\n"
|
||||||
" Example: --eeprom=/tmp/riot_native.eeprom\n");
|
" Example: --eeprom=/tmp/riot_native.eeprom\n");
|
||||||
|
#endif
|
||||||
|
#ifdef MODULE_NETDEV_TAP
|
||||||
|
real_printf(
|
||||||
|
" -w <tap>\n"
|
||||||
|
" Add a tap interface as a wireless interface\n");
|
||||||
#endif
|
#endif
|
||||||
real_exit(status);
|
real_exit(status);
|
||||||
}
|
}
|
||||||
@ -468,6 +476,10 @@ __attribute__((constructor)) static void startup(int argc, char **argv, char **e
|
|||||||
_native_id = _native_pid;
|
_native_id = _native_pid;
|
||||||
|
|
||||||
int c, opt_idx = 0, uart = 0;
|
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
|
#ifdef MODULE_SOCKET_ZEP
|
||||||
unsigned zeps = 0;
|
unsigned zeps = 0;
|
||||||
#endif
|
#endif
|
||||||
@ -575,20 +587,19 @@ __attribute__((constructor)) static void startup(int argc, char **argv, char **e
|
|||||||
strncpy(eeprom_file, optarg, EEPROM_FILEPATH_MAX_LEN);
|
strncpy(eeprom_file, optarg, EEPROM_FILEPATH_MAX_LEN);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef MODULE_NETDEV_TAP
|
||||||
|
case 'w':
|
||||||
|
netdev_tap_params[taps].tap_name = &argv[optind - 1];
|
||||||
|
netdev_tap_params[taps].wired = false;
|
||||||
|
++taps;
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
usage_exit(EXIT_FAILURE);
|
usage_exit(EXIT_FAILURE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef MODULE_NETDEV_TAP
|
|
||||||
for (int i = 0; i < NETDEV_TAP_MAX; i++) {
|
|
||||||
if (argv[optind + i] == NULL) {
|
|
||||||
/* no tap parameter left */
|
|
||||||
usage_exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#ifdef MODULE_SOCKET_ZEP
|
#ifdef MODULE_SOCKET_ZEP
|
||||||
if (zeps != SOCKET_ZEP_MAX) {
|
if (zeps != SOCKET_ZEP_MAX) {
|
||||||
/* not enough ZEPs given */
|
/* not enough ZEPs given */
|
||||||
@ -653,8 +664,12 @@ __attribute__((constructor)) static void startup(int argc, char **argv, char **e
|
|||||||
native_cpu_init();
|
native_cpu_init();
|
||||||
native_interrupt_init();
|
native_interrupt_init();
|
||||||
#ifdef MODULE_NETDEV_TAP
|
#ifdef MODULE_NETDEV_TAP
|
||||||
for (int i = 0; i < NETDEV_TAP_MAX; i++) {
|
for (unsigned i = 0; taps < NETDEV_TAP_MAX; ++taps, ++i) {
|
||||||
netdev_tap_params[i].tap_name = &argv[optind + i];
|
if (argv[optind + i] == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
netdev_tap_params[taps].tap_name = &argv[optind + i];
|
||||||
|
netdev_tap_params[taps].wired = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -33,6 +33,9 @@ static netdev_tap_t netdev_taps[NETIF_TAP_NUMOF];
|
|||||||
static void auto_init_netdev_tap(void)
|
static void auto_init_netdev_tap(void)
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < NETIF_TAP_NUMOF; i++) {
|
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);
|
netdev_tap_setup(&netdev_taps[i], &netdev_tap_params[i], i);
|
||||||
if (lwip_add_ethernet(&netif[i], &netdev_taps[i].netdev) == NULL) {
|
if (lwip_add_ethernet(&netif[i], &netdev_taps[i].netdev) == NULL) {
|
||||||
DEBUG("Could not add netdev_tap device\n");
|
DEBUG("Could not add netdev_tap device\n");
|
||||||
|
@ -35,6 +35,10 @@ void auto_init_netdev_tap(void)
|
|||||||
for (unsigned i = 0; i < NETDEV_TAP_MAX; i++) {
|
for (unsigned i = 0; i < NETDEV_TAP_MAX; i++) {
|
||||||
const netdev_tap_params_t *p = &netdev_tap_params[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",
|
LOG_DEBUG("[auto_init_netif] initializing netdev_tap #%u on TAP %s\n",
|
||||||
i, *(p->tap_name));
|
i, *(p->tap_name));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user