From e6c8f7298b40757a410d9df6319824c4f0d70351 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Wed, 28 Feb 2024 21:47:49 +0100 Subject: TCP/UDP: Start rewrite of network sockets Having sockets be file descriptors seems like a bad idea so I trying to make UDP and TCP sockets be more independent and not be abstracted away as much. --- kernel/socket.h | 51 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) (limited to 'kernel/socket.h') diff --git a/kernel/socket.h b/kernel/socket.h index f765fb7..174ceb1 100644 --- a/kernel/socket.h +++ b/kernel/socket.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -17,6 +18,42 @@ #define MSG_WAITALL 1 +u32 gen_ipv4(u8 i1, u8 i2, u8 i3, u8 i4); +u32 tcp_connect_ipv4(u32 ip, u16 port, int *error); + +u32 tcp_listen_ipv4(u32 ip, u16 port, int *error); +u32 tcp_accept(u32 listen_socket, int *error); + +int tcp_write(u32 socket, const u8 *buffer, u64 len, u64 *out); +int tcp_read(u32 socket, u8 *buffer, u64 buffer_size, u64 *out); + +struct TcpListen { + u32 ip; + u16 port; + struct stack incoming_connections; +}; + +struct TcpConnection { + int dead; + u16 incoming_port; + u32 outgoing_ip; + u16 outgoing_port; + + int unhandled_packet; + + FIFO_FILE *data_file; + + u32 seq; + u32 ack; + + int handshake_state; +}; + +struct TcpConnection *internal_tcp_incoming(u32 src_ip, u16 src_port, + u32 dst_ip, u16 dst_port); + +struct TcpConnection *tcp_find_connection(u16 port); + typedef struct { vfs_fd_t *ptr_socket_fd; FIFO_FILE *fifo_file; @@ -42,20 +79,6 @@ typedef struct { SOCKET *s; } OPEN_INET_SOCKET; -struct INCOMING_TCP_CONNECTION { - u8 ip[4]; - u16 n_port; - u16 dst_port; - FIFO_FILE *data_file; - struct buffered buffer; - u8 *has_data_ptr; - u8 is_used; - u32 ack_num; - u32 seq_num; - u8 connection_closed; - u8 requesting_connection_close; -}; - typedef u32 in_addr_t; typedef u16 in_port_t; typedef unsigned int sa_family_t; -- cgit v1.2.3