Fix network, ping works again
This commit is contained in:
51
vnet.c
51
vnet.c
@@ -14,6 +14,7 @@
|
||||
#include <inttypes.h>
|
||||
#define _POSIX // to have SIGSYS on windows
|
||||
#include <signal.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -38,8 +39,8 @@
|
||||
static int
|
||||
vnet_input(void *udata) {
|
||||
umka_sti();
|
||||
struct vnet *net = udata;
|
||||
int fd = net->fdin;
|
||||
struct vnet *vnet = udata;
|
||||
int fd = vnet->fdin;
|
||||
int plen = 0;
|
||||
fprintf(stderr, "[vnet] input interrupt\n");
|
||||
net_buff_t *buf = kos_net_buff_alloc(NET_BUFFER_SIZE);
|
||||
@@ -47,11 +48,12 @@ vnet_input(void *udata) {
|
||||
fprintf(stderr, "[vnet] Can't allocate network buffer!\n");
|
||||
return 1;
|
||||
}
|
||||
buf->device = &net->netdev;
|
||||
buf->device = &vnet->eth.net;
|
||||
plen = read(fd, buf->data, NET_BUFFER_SIZE - offsetof(net_buff_t, data));
|
||||
if (plen == -1) {
|
||||
plen = 0; // we have just allocated a buffer, so we have to submit it
|
||||
}
|
||||
//if (plen != 0)
|
||||
fprintf(stderr, "[vnet] read %i bytes\n", plen);
|
||||
for (int i = 0; i < plen; i++) {
|
||||
fprintf(stderr, " %2.2x", buf->data[i]);
|
||||
@@ -61,7 +63,7 @@ vnet_input(void *udata) {
|
||||
buf->length = plen;
|
||||
buf->offset = offsetof(net_buff_t, data);
|
||||
kos_eth_input(buf);
|
||||
net->input_processed = 1;
|
||||
vnet->input_processed = 1;
|
||||
|
||||
return 1; // acknowledge our interrupt
|
||||
}
|
||||
@@ -73,8 +75,9 @@ vnet_input_monitor(struct vnet *net) {
|
||||
while (1) {
|
||||
if (net->input_processed && poll(&pfd, 1, 0)) {
|
||||
net->input_processed = 0;
|
||||
umka_irq_number = UMKA_IRQ_NETWORK;
|
||||
raise(SIGSYS);
|
||||
atomic_store_explicit(&umka_irq_number, UMKA_IRQ_NETWORK,
|
||||
memory_order_release);
|
||||
raise(UMKA_SIGNAL_IRQ);
|
||||
umka_sti();
|
||||
}
|
||||
}
|
||||
@@ -83,41 +86,47 @@ vnet_input_monitor(struct vnet *net) {
|
||||
struct vnet *
|
||||
vnet_init(enum vnet_type type) {
|
||||
// printf("vnet_init\n");
|
||||
struct vnet *net;
|
||||
struct vnet *vnet;
|
||||
switch (type) {
|
||||
case VNET_FILE:
|
||||
net = vnet_init_file();
|
||||
vnet = vnet_init_file();
|
||||
break;
|
||||
case VNET_TAP:
|
||||
net = vnet_init_tap();
|
||||
vnet = vnet_init_tap();
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "[vnet] bad vnet type: %d\n", type);
|
||||
return NULL;
|
||||
}
|
||||
if (!net) {
|
||||
if (!vnet) {
|
||||
fprintf(stderr, "[vnet] device initialization failed\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
net->netdev.bytes_tx = 0;
|
||||
net->netdev.bytes_rx = 0;
|
||||
net->netdev.packets_tx = 0;
|
||||
net->netdev.packets_rx = 0;
|
||||
vnet->eth.net.link_state = ETH_LINK_FD + ETH_LINK_10M;
|
||||
vnet->eth.net.hwacc = 0;
|
||||
|
||||
net->netdev.link_state = ETH_LINK_FD + ETH_LINK_10M;
|
||||
net->netdev.hwacc = 0;
|
||||
memcpy(net->netdev.mac, &(uint8_t[6]){0x80, 0x2b, 0xf9, 0x3b, 0x6c, 0xca},
|
||||
sizeof(net->netdev.mac));
|
||||
vnet->eth.net.bytes_tx = 0;
|
||||
vnet->eth.net.bytes_rx = 0;
|
||||
|
||||
kos_attach_int_handler(UMKA_IRQ_NETWORK, vnet_input, net);
|
||||
vnet->eth.net.packets_tx = 0;
|
||||
vnet->eth.net.packets_tx_err = 0;
|
||||
vnet->eth.net.packets_tx_drop = 0;
|
||||
vnet->eth.net.packets_tx_ovr = 0;
|
||||
|
||||
vnet->eth.net.packets_rx = 0;
|
||||
vnet->eth.net.packets_rx_err = 0;
|
||||
vnet->eth.net.packets_rx_drop = 0;
|
||||
vnet->eth.net.packets_rx_ovr = 0;
|
||||
|
||||
kos_attach_int_handler(UMKA_IRQ_NETWORK, vnet_input, vnet);
|
||||
fprintf(stderr, "[vnet] start input_monitor thread\n");
|
||||
uint8_t *stack = malloc(STACK_SIZE);
|
||||
size_t tid = umka_new_sys_threads(0, vnet_input_monitor, stack + STACK_SIZE);
|
||||
appdata_t *t = kos_slot_base + tid;
|
||||
*(void**)((uint8_t*)t->saved_esp0-12) = net; // param for monitor thread
|
||||
*(void**)((uint8_t*)t->saved_esp0-12) = vnet; // param for monitor thread
|
||||
// -12 here because in UMKa, unlike real hardware, we don't switch between
|
||||
// kernel and userspace, i.e. stack structure is different
|
||||
|
||||
return net;
|
||||
return vnet;
|
||||
}
|
||||
|
Reference in New Issue
Block a user