net: Cleanup headers

This commit is contained in:
K. Lange 2022-09-17 13:35:08 +09:00
parent 1f5fb5be2e
commit e80d2da3f3
8 changed files with 20 additions and 57 deletions

View File

@ -1,34 +0,0 @@
#ifndef KERNEL_MOD_NET_H
#define KERNEL_MOD_NET_H
#include <stdint.h>
typedef uint8_t* (*get_mac_func)(void);
typedef struct ethernet_packet* (*get_packet_func)(void);
typedef void (*send_packet_func)(uint8_t*, size_t);
struct netif {
void *extra;
get_mac_func get_mac;
get_packet_func get_packet;
send_packet_func send_packet;
uint8_t hwaddr[6];
uint32_t source;
char * driver;
uint32_t gateway;
};
extern void init_netif_funcs(get_mac_func mac_func, get_packet_func get_func, send_packet_func send_func, char * device);
extern void net_handler(void * data, char * name);
extern size_t write_dhcp_packet(uint8_t * buffer);
extern struct socket* net_open(uint32_t type);
extern int net_send(struct socket* socket, uint8_t* payload, size_t payload_size, int flags);
extern size_t net_recv(struct socket* socket, uint8_t* buffer, size_t len);
extern int net_connect(struct socket* socket, uint32_t dest_ip, uint16_t dest_port);
extern int net_close(struct socket* socket);
#endif

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <kernel/vfs.h> #include <kernel/vfs.h>
#include <kernel/mod/net.h>
#define ETHERNET_TYPE_IPV4 0x0800 #define ETHERNET_TYPE_IPV4 0x0800
#define ETHERNET_TYPE_ARP 0x0806 #define ETHERNET_TYPE_ARP 0x0806
@ -10,6 +9,13 @@
#define MAC_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x" #define MAC_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x"
#define FORMAT_MAC(m) (m)[0], (m)[1], (m)[2], (m)[3], (m)[4], (m)[5] #define FORMAT_MAC(m) (m)[0], (m)[1], (m)[2], (m)[3], (m)[4], (m)[5]
struct ethernet_packet {
uint8_t destination[6];
uint8_t source[6];
uint16_t type;
uint8_t payload[];
} __attribute__((packed)) __attribute__((aligned(2)));
void net_eth_handle(struct ethernet_packet * frame, fs_node_t * nic, size_t size); void net_eth_handle(struct ethernet_packet * frame, fs_node_t * nic, size_t size);
struct EthernetDevice { struct EthernetDevice {

View File

@ -39,3 +39,15 @@ void net_sock_alert(sock_t * sock);
void net_sock_add(sock_t * sock, void * frame, size_t size); void net_sock_add(sock_t * sock, void * frame, size_t size);
void * net_sock_get(sock_t * sock); void * net_sock_get(sock_t * sock);
sock_t * net_sock_create(void); sock_t * net_sock_create(void);
extern long net_socket(int,int,int);
extern long net_setsockopt(int,int,int,const void*,socklen_t);
extern long net_bind(int, const struct sockaddr*, socklen_t);
extern long net_accept(int, struct sockaddr*, socklen_t*);
extern long net_listen(int,int);
extern long net_connect(int, const struct sockaddr*, socklen_t);
extern long net_getsockopt(int,int,int,void*,socklen_t*);
extern long net_recv(int,struct msghdr*,int);
extern long net_send(int, const struct msghdr*, int);
extern long net_shutdown(int, int);

View File

@ -14,7 +14,6 @@
#include <kernel/syscall.h> #include <kernel/syscall.h>
#include <kernel/vfs.h> #include <kernel/vfs.h>
#include <kernel/hashmap.h> #include <kernel/hashmap.h>
#include <kernel/mod/net.h>
#include <kernel/net/netif.h> #include <kernel/net/netif.h>
#include <kernel/net/eth.h> #include <kernel/net/eth.h>

View File

@ -15,7 +15,6 @@
#include <kernel/list.h> #include <kernel/list.h>
#include <kernel/spinlock.h> #include <kernel/spinlock.h>
#include <kernel/vfs.h> #include <kernel/vfs.h>
#include <kernel/mod/net.h>
#include <kernel/net/netif.h> #include <kernel/net/netif.h>
#include <kernel/net/eth.h> #include <kernel/net/eth.h>
#include <kernel/net/ipv4.h> #include <kernel/net/ipv4.h>
@ -27,13 +26,6 @@
#define printf(...) #define printf(...)
#endif #endif
struct ethernet_packet {
uint8_t destination[6];
uint8_t source[6];
uint16_t type;
uint8_t payload[];
} __attribute__((packed)) __attribute__((aligned(2)));
extern spin_lock_t net_raw_sockets_lock; extern spin_lock_t net_raw_sockets_lock;
extern list_t * net_raw_sockets_list; extern list_t * net_raw_sockets_list;
extern void net_ipv4_handle(void * packet, fs_node_t * nic, size_t); extern void net_ipv4_handle(void * packet, fs_node_t * nic, size_t);

View File

@ -13,7 +13,6 @@
#include <kernel/vfs.h> #include <kernel/vfs.h>
#include <kernel/spinlock.h> #include <kernel/spinlock.h>
#include <kernel/list.h> #include <kernel/list.h>
#include <kernel/mod/net.h>
#include <kernel/net/netif.h> #include <kernel/net/netif.h>
#include <kernel/net/eth.h> #include <kernel/net/eth.h>
#include <errno.h> #include <errno.h>

View File

@ -31,6 +31,7 @@
#include <kernel/syscall.h> #include <kernel/syscall.h>
#include <kernel/misc.h> #include <kernel/misc.h>
#include <kernel/ptrace.h> #include <kernel/ptrace.h>
#include <kernel/net/netif.h>
static char hostname[256]; static char hostname[256];
static size_t hostname_len = 0; static size_t hostname_len = 0;
@ -1156,17 +1157,6 @@ long sys_times(struct tms *buf) {
return arch_perf_timer() / arch_cpu_mhz(); return arch_perf_timer() / arch_cpu_mhz();
} }
extern long net_socket();
extern long net_setsockopt();
extern long net_bind();
extern long net_accept();
extern long net_listen();
extern long net_connect();
extern long net_getsockopt();
extern long net_recv();
extern long net_send();
extern long net_shutdown();
extern long ptrace_handle(long,pid_t,void*,void*); extern long ptrace_handle(long,pid_t,void*,void*);
static long (*syscalls[])() = { static long (*syscalls[])() = {

View File

@ -22,7 +22,6 @@
#include <kernel/spinlock.h> #include <kernel/spinlock.h>
#include <kernel/time.h> #include <kernel/time.h>
#include <kernel/vfs.h> #include <kernel/vfs.h>
#include <kernel/mod/net.h>
#include <kernel/net/netif.h> #include <kernel/net/netif.h>
#include <kernel/net/eth.h> #include <kernel/net/eth.h>
#include <kernel/module.h> #include <kernel/module.h>