Implement vnet_null device

Such device don't need new threads and files but are valid ethernet
devices for the kernel. Convenient for testing.
This commit is contained in:
2023-02-06 16:01:37 +00:00
parent 6a479621e9
commit e71791c0ab
22 changed files with 194 additions and 71 deletions

View File

@@ -22,31 +22,20 @@
#include "vnet.h"
#define TAP_DEV "/dev/net/tun"
#define UMKA_TAP_NAME "umka%d"
static STDCALL void
vnet_unload_tap(void) {
printf("vnet_unload_tap\n");
COVERAGE_ON();
COVERAGE_OFF();
}
static STDCALL void
vnet_reset_tap(void) {
printf("vnet_reset_tap\n");
COVERAGE_ON();
COVERAGE_OFF();
}
/*
static void
dump_net_buff(net_buff_t *buf) {
for (size_t i = 0; i < buf->length; i++) {
printf("%2.2x ", buf->data[i]);
}
putchar('\n');
}
*/
static STDCALL int
vnet_transmit_tap(net_buff_t *buf) {
struct vnet *net;
@@ -56,20 +45,17 @@ vnet_transmit_tap(net_buff_t *buf) {
:
: "memory");
// printf("vnet_transmit: %d bytes\n", buf->length);
// dump_net_buff(buf);
ssize_t written = write(net->fdout, buf->data, buf->length);
(void)written;
buf->length = 0;
COVERAGE_OFF();
COVERAGE_ON();
// printf("vnet_transmit: %d bytes written\n", written);
return 0;
}
struct vnet *
vnet_init_tap(void) {
struct ifreq ifr = {.ifr_name = UMKA_VNET_NAME,
struct ifreq ifr = {.ifr_name = UMKA_TAP_NAME,
.ifr_flags = IFF_TAP | IFF_NO_PI};
int fd, err;