aboutsummaryrefslogtreecommitdiff
path: root/kernel/features
diff options
context:
space:
mode:
authorMarvin Borner2020-11-21 14:50:11 +0100
committerMarvin Borner2020-11-21 14:50:11 +0100
commit292dc556cbab0943b6c6c5d9ac0630cb102bbcef (patch)
treeac999f21f38a3c8032d853cc8dea3b85bacf453d /kernel/features
parente8aa2eb5787b5074b5b2867cb89653387f7e8d67 (diff)
Added TCP RST support
Diffstat (limited to 'kernel/features')
-rw-r--r--kernel/features/net.c14
1 files changed, 12 insertions, 2 deletions
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) {