From 653d6a70351c6ad2467820b94ef58d4366d97b21 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Sat, 19 Jun 2021 13:11:43 +0900 Subject: [PATCH] net: select random sequence number to start --- kernel/net/ipv4.c | 4 +++- kernel/vfs/random.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/net/ipv4.c b/kernel/net/ipv4.c index 011bf5d0..bfc4ee28 100644 --- a/kernel/net/ipv4.c +++ b/kernel/net/ipv4.c @@ -564,6 +564,8 @@ static long sock_tcp_recv(sock_t * sock, struct msghdr * msg, int flags) { return resp; } +extern uint32_t rand(void); + static long sock_tcp_connect(sock_t * sock, const struct sockaddr *addr, socklen_t addrlen) { const struct sockaddr_in * dest = (const struct sockaddr_in *)addr; char deststr[16]; @@ -594,7 +596,7 @@ static long sock_tcp_connect(sock_t * sock, const struct sockaddr *addr, socklen response->source = ((struct EthernetDevice*)nic->device)->ipv4_addr; response->ttl = 64; response->protocol = IPV4_PROT_TCP; - sock->priv[2] = 1; + sock->priv[2] = rand(); response->ident = htons(sock->priv[2]); response->flags_fragment = htons(0x0); response->version_ihl = 0x45; diff --git a/kernel/vfs/random.c b/kernel/vfs/random.c index 782df6a2..99463f4c 100644 --- a/kernel/vfs/random.c +++ b/kernel/vfs/random.c @@ -13,7 +13,7 @@ #include #include -static uint32_t rand(void) { +uint32_t rand(void) { static uint32_t x = 123456789; static uint32_t y = 362436069; static uint32_t z = 521288629;