From 292dc556cbab0943b6c6c5d9ac0630cb102bbcef Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 21 Nov 2020 14:50:11 +0100 Subject: Added TCP RST support --- kernel/features/net.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'kernel/features/net.c') diff --git a/kernel/features/net.c b/kernel/features/net.c index edad1a9..9f64f31 100644 --- a/kernel/features/net.c +++ b/kernel/features/net.c @@ -428,6 +428,13 @@ static void tcp_handle_packet(struct tcp_packet *packet, u32 dst, int len) // TODO: Verify checksum first, then send ACK + if (flags & TCP_FLAG_RST) { + proc_from_pid(socket->pid)->state = PROC_RUNNING; + socket->state = S_FAILED; + tcp->state = 0; + return; + } + // Serve if (tcp->state == 0 && (flags & 0xff) == TCP_FLAG_SYN) { socket->ip_addr = ntohl(dst); @@ -515,6 +522,7 @@ static void tcp_handle_packet(struct tcp_packet *packet, u32 dst, int len) tcp_send_packet(socket, TCP_FLAG_FIN | TCP_FLAG_ACK, NULL, 0); tcp->state++; } + /* tcp_send_packet(socket, TCP_FLAG_ACK, NULL, 0); */ socket->state = S_CONNECTED; return; @@ -756,8 +764,10 @@ int net_connect(struct socket *socket, u32 ip_addr, u16 dst_port) scheduler_disable(); sti(); u32 time = timer_get(); - while (socket->state != S_CONNECTED && timer_get() - time < 1000) - ; + while ((socket->state != S_CONNECTED && timer_get() - time < 1000)) { + if (socket->state == S_FAILED) + break; + } cli(); scheduler_enable(); if (socket->state != S_CONNECTED) { -- cgit v1.2.3