toaruos/kernel/net/netif.c

58 lines
1.3 KiB
C
Raw Normal View History

2021-05-31 04:47:02 +03:00
/**
* @file kernel/net/netif.c
* @brief Network interface manager.
*
* @copyright
* This file is part of ToaruOS and is released under the terms
* of the NCSA / University of Illinois License - see LICENSE.md
* Copyright (C) 2021 K. Lange
*/
#include <kernel/types.h>
#include <kernel/vfs.h>
#include <kernel/string.h>
#include <kernel/list.h>
#include <kernel/printf.h>
#include <kernel/spinlock.h>
2021-06-06 08:22:14 +03:00
#include <kernel/hashmap.h>
#include <kernel/net/netif.h>
2021-05-31 04:47:02 +03:00
#include <errno.h>
2021-06-06 08:22:14 +03:00
static hashmap_t * interfaces = NULL;
2021-06-09 02:44:42 +03:00
extern list_t * net_raw_sockets_list;
2021-06-14 08:18:23 +03:00
static fs_node_t * _if_first = NULL;
2021-06-06 08:22:14 +03:00
extern void ipv4_install(void);
extern hashmap_t * net_arp_cache;
2021-05-31 04:47:02 +03:00
void net_install(void) {
2021-06-09 02:23:34 +03:00
/* Set up virtual devices */
2021-05-31 04:47:02 +03:00
map_vfs_directory("/dev/net");
2021-06-06 08:22:14 +03:00
interfaces = hashmap_create(10);
2021-06-09 02:44:42 +03:00
net_raw_sockets_list = list_create("raw sockets", NULL);
net_arp_cache = hashmap_create_int(10);
ipv4_install();
2021-06-06 08:22:14 +03:00
}
/* kinda temporary for now */
int net_add_interface(const char * name, fs_node_t * deviceNode) {
hashmap_set(interfaces, name, deviceNode);
char tmp[100];
snprintf(tmp,100,"/dev/net/%s", name);
vfs_mount(tmp, deviceNode);
2021-06-14 08:18:23 +03:00
if (!_if_first) _if_first = deviceNode;
2021-06-06 08:22:14 +03:00
return 0;
2021-05-31 04:47:02 +03:00
}
2021-06-09 02:23:34 +03:00
fs_node_t * net_if_lookup(const char * name) {
return hashmap_get(interfaces, name);
}
2021-06-14 08:18:23 +03:00
fs_node_t * net_if_any(void) {
return _if_first;
}