aboutsummaryrefslogtreecommitdiff
path: root/kernel
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
parente8aa2eb5787b5074b5b2867cb89653387f7e8d67 (diff)
Added TCP RST support
Diffstat (limited to 'kernel')
-rw-r--r--kernel/features/net.c14
-rw-r--r--kernel/inc/net.h2
2 files changed, 13 insertions, 3 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) {
diff --git a/kernel/inc/net.h b/kernel/inc/net.h
index 9a305a1..2ad3d65 100644
--- a/kernel/inc/net.h
+++ b/kernel/inc/net.h
@@ -25,7 +25,7 @@
#define TCP_FLAG_FIN (1 << 0)
#define TCP_FLAG_SYN (1 << 1)
-#define TCP_FLAG_RES (1 << 2)
+#define TCP_FLAG_RST (1 << 2)
#define TCP_FLAG_PSH (1 << 3)
#define TCP_FLAG_ACK (1 << 4)
#define TCP_FLAG_URG (1 << 5)