diff options
| author | Anton Kling <anton@kling.gg> | 2024-07-04 23:03:16 +0200 | 
|---|---|---|
| committer | Anton Kling <anton@kling.gg> | 2024-07-05 12:46:50 +0200 | 
| commit | 6bf371cc35c11890ab18c32aabd11bf8a816e574 (patch) | |
| tree | 00df8f66ec65fc8a59aa315ef90be91cadd64cb5 /kernel/network | |
| parent | 59893c116e9e4e5dd04c24c0ba2fd06fe1936500 (diff) | |
TCP: Add back support for listening on a socket
Diffstat (limited to 'kernel/network')
| -rw-r--r-- | kernel/network/tcp.c | 16 | 
1 files changed, 14 insertions, 2 deletions
diff --git a/kernel/network/tcp.c b/kernel/network/tcp.c index 6bec93e..a2df3cd 100644 --- a/kernel/network/tcp.c +++ b/kernel/network/tcp.c @@ -224,9 +224,15 @@ void handle_tcp(ipv4_t src_ip, ipv4_t dst_ip, const u8 *payload,    u32 seq_num = htonl(n_seq_num);    u32 ack_num = htonl(n_ack_num);    u16 window_size = htons(n_window_size); -  struct TcpConnection *con = -      tcp_find_connection(src_ip, src_port, dst_ip, dst_port); + +  struct TcpConnection *con = NULL; +  if (SYN == flags) { +    con = tcp_connect_to_listen(src_ip, src_port, dst_ip, dst_port); +  } else { +    con = tcp_find_connection(src_ip, src_port, dst_ip, dst_port); +  }    if (!con) { +    kprintf("Unable to find connection for port: %d\n", dst_port);      return;    } @@ -321,6 +327,12 @@ void handle_tcp(ipv4_t src_ip, ipv4_t dst_ip, const u8 *payload,      }      break;    } +  case TCP_STATE_FIN_WAIT2: { +    if (FIN & flags) { +      tcp_send_empty_payload(con, ACK); +    } +    break; +  }    case TCP_STATE_CLOSE_WAIT: {      // Waiting for this machine to close the connection. There is      // nothing to respond with.  |