net: implement netdev flags

This commit is contained in:
Matheus
2026-04-01 16:53:00 -03:00
parent e294f9814c
commit 7509d17f1c
4 changed files with 16 additions and 5 deletions
+12 -5
View File
@@ -19,16 +19,28 @@ typedef struct {
size_t size;
} netdesc_t;
typedef struct {
uint16_t port;
uint32_t addr;
} ipv4addr_t;
typedef struct {
uint8_t address[6];
} __attribute__((packed)) mac_t;
#define NETDEV_FLAGS_UP 0x1
#define NETDEV_FLAGS_BROADCAST 0x2
#define NETDEV_FLAGS_DEBUG 0x4
#define NETDEV_FLAGS_LOOPBACK 0x8
#define NETDEV_FLAGS_RUNNING 0x40
typedef struct netdev_t {
mac_t mac;
size_t mtu;
uint32_t ip;
int ipcurrid; // XXX This is defined as something per peer. However, having only one of these *should* work for most cases
hashtable_t arpcache;
short flags;
int (*allocdesc)(struct netdev_t *netdev, size_t requestedsize, netdesc_t *desc);
int (*freedesc)(struct netdev_t *netdev, netdesc_t *desc);
int (*sendpacket)(struct netdev_t *_internal, netdesc_t desc, mac_t targetmac, int proto);
@@ -54,11 +66,6 @@ typedef struct {
uint16_t checksum;
} __attribute__((packed)) udpframe_t;
typedef struct {
uint16_t port;
uint32_t addr;
} ipv4addr_t;
#define NET_BROADCAST_MAC (mac_t){.address = {0xff,0xff,0xff,0xff,0xff,0xff}}
#define MAC_EQUAL(m1,m2) (memcmp(m1, m2, sizeof(mac_t)) == 0)
+1
View File
@@ -26,6 +26,7 @@ typedef struct {
pollheader_t pollheader;
int type;
int shutdown;
int error;
} socket_t;
typedef struct {
+1
View File
@@ -59,6 +59,7 @@ void loopback_init() {
loopbacknetdev.allocdesc = loopback_allocdesc;
loopbacknetdev.freedesc = loopback_freedesc;
loopbacknetdev.ip = 0x7f000001;
loopbacknetdev.flags = NETDEV_FLAGS_UP | NETDEV_FLAGS_LOOPBACK | NETDEV_FLAGS_RUNNING;
__assert(hashtable_init(&loopbacknetdev.arpcache, 30) == 0);
for (int i = 0; i < 6; ++i)
+2
View File
@@ -404,6 +404,8 @@ static void init_controller(pcienum_t *pci_enum) {
return;
}
netdev->netdev.flags = NETDEV_FLAGS_UP | NETDEV_FLAGS_BROADCAST | NETDEV_FLAGS_RUNNING;
// enable rx/tx
outb(pci_bar.address + REGISTER_COMMAND, REGISTER_COMMAND_TX_ENABLE | REGISTER_COMMAND_RX_ENABLE);
}