summaryrefslogtreecommitdiff
path: root/Kernel/Net
diff options
context:
space:
mode:
authorConrad Pankoff <deoxxa@fknsrs.biz>2019-08-10 13:14:00 +1000
committerAndreas Kling <awesomekling@gmail.com>2019-08-10 09:07:11 +0200
commit638008da13555179af2257fdc7a4a0a31db2413c (patch)
tree4c8d3b8bf348770d82a3eb2aa40c7349dd175e33 /Kernel/Net
parente978e7543fd0af968c2b734da09589480caeeca5 (diff)
downloadserenity-638008da13555179af2257fdc7a4a0a31db2413c.zip
Kernel: Move TCP state logging into TCPSocket
Diffstat (limited to 'Kernel/Net')
-rw-r--r--Kernel/Net/NetworkTask.cpp18
-rw-r--r--Kernel/Net/TCPSocket.cpp11
-rw-r--r--Kernel/Net/TCPSocket.h2
3 files changed, 12 insertions, 19 deletions
diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp
index 8a980a7916..ae6351c9a5 100644
--- a/Kernel/Net/NetworkTask.cpp
+++ b/Kernel/Net/NetworkTask.cpp
@@ -378,7 +378,6 @@ void handle_tcp(const IPv4Packet& ipv4_packet)
kprintf("handle_tcp: unexpected flags in TimeWait state\n");
socket->send_tcp_packet(TCPFlags::RST);
socket->set_state(TCPSocket::State::Closed);
- kprintf("handle_tcp: TimeWait -> Closed\n");
return;
case TCPSocket::State::Listen:
switch (tcp_packet.flags()) {
@@ -397,7 +396,6 @@ void handle_tcp(const IPv4Packet& ipv4_packet)
client->send_tcp_packet(TCPFlags::SYN | TCPFlags::ACK);
client->set_sequence_number(1001);
client->set_state(TCPSocket::State::SynReceived);
- kprintf("handle_tcp: Closed -> SynReceived\n");
return;
}
default:
@@ -411,20 +409,17 @@ void handle_tcp(const IPv4Packet& ipv4_packet)
socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1);
socket->send_tcp_packet(TCPFlags::ACK);
socket->set_state(TCPSocket::State::SynReceived);
- kprintf("handle_tcp: SynSent -> SynReceived\n");
return;
case TCPFlags::SYN | TCPFlags::ACK:
socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1);
socket->send_tcp_packet(TCPFlags::ACK);
socket->set_state(TCPSocket::State::Established);
socket->set_connected(true);
- kprintf("handle_tcp: SynSent -> Established\n");
return;
default:
kprintf("handle_tcp: unexpected flags in SynSent state\n");
socket->send_tcp_packet(TCPFlags::RST);
socket->set_state(TCPSocket::State::Closed);
- kprintf("handle_tcp: SynSent -> Closed\n");
return;
}
case TCPSocket::State::SynReceived:
@@ -434,13 +429,11 @@ void handle_tcp(const IPv4Packet& ipv4_packet)
socket->set_state(TCPSocket::State::Established);
if (socket->direction() == TCPSocket::Direction::Outgoing)
socket->set_connected(true);
- kprintf("handle_tcp: SynReceived -> Established\n");
return;
default:
kprintf("handle_tcp: unexpected flags in SynReceived state\n");
socket->send_tcp_packet(TCPFlags::RST);
socket->set_state(TCPSocket::State::Closed);
- kprintf("handle_tcp: SynReceived -> Closed\n");
return;
}
case TCPSocket::State::CloseWait:
@@ -449,7 +442,6 @@ void handle_tcp(const IPv4Packet& ipv4_packet)
kprintf("handle_tcp: unexpected flags in CloseWait state\n");
socket->send_tcp_packet(TCPFlags::RST);
socket->set_state(TCPSocket::State::Closed);
- kprintf("handle_tcp: CloseWait -> Closed\n");
return;
}
case TCPSocket::State::LastAck:
@@ -457,13 +449,11 @@ void handle_tcp(const IPv4Packet& ipv4_packet)
case TCPFlags::ACK:
socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1);
socket->set_state(TCPSocket::State::Closed);
- kprintf("handle_tcp: LastAck -> Closed\n");
return;
default:
kprintf("handle_tcp: unexpected flags in LastAck state\n");
socket->send_tcp_packet(TCPFlags::RST);
socket->set_state(TCPSocket::State::Closed);
- kprintf("handle_tcp: LastAck -> Closed\n");
return;
}
case TCPSocket::State::FinWait1:
@@ -471,18 +461,15 @@ void handle_tcp(const IPv4Packet& ipv4_packet)
case TCPFlags::ACK:
socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1);
socket->set_state(TCPSocket::State::FinWait2);
- kprintf("handle_tcp: FinWait1 -> FinWait2\n");
return;
case TCPFlags::FIN:
socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1);
socket->set_state(TCPSocket::State::Closing);
- kprintf("handle_tcp: FinWait1 -> Closing\n");
return;
default:
kprintf("handle_tcp: unexpected flags in FinWait1 state\n");
socket->send_tcp_packet(TCPFlags::RST);
socket->set_state(TCPSocket::State::Closed);
- kprintf("handle_tcp: FinWait1 -> Closed\n");
return;
}
case TCPSocket::State::FinWait2:
@@ -490,13 +477,11 @@ void handle_tcp(const IPv4Packet& ipv4_packet)
case TCPFlags::FIN:
socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1);
socket->set_state(TCPSocket::State::TimeWait);
- kprintf("handle_tcp: FinWait2 -> TimeWait\n");
return;
default:
kprintf("handle_tcp: unexpected flags in FinWait2 state\n");
socket->send_tcp_packet(TCPFlags::RST);
socket->set_state(TCPSocket::State::Closed);
- kprintf("handle_tcp: FinWait2 -> Closed\n");
return;
}
case TCPSocket::State::Closing:
@@ -504,13 +489,11 @@ void handle_tcp(const IPv4Packet& ipv4_packet)
case TCPFlags::ACK:
socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1);
socket->set_state(TCPSocket::State::TimeWait);
- kprintf("handle_tcp: Closing -> TimeWait\n");
return;
default:
kprintf("handle_tcp: unexpected flags in Closing state\n");
socket->send_tcp_packet(TCPFlags::RST);
socket->set_state(TCPSocket::State::Closed);
- kprintf("handle_tcp: Closing -> Closed\n");
return;
}
case TCPSocket::State::Established:
@@ -522,7 +505,6 @@ void handle_tcp(const IPv4Packet& ipv4_packet)
socket->send_tcp_packet(TCPFlags::ACK);
socket->set_state(TCPSocket::State::CloseWait);
socket->set_connected(false);
- kprintf("handle_tcp: Established -> CloseWait\n");
return;
}
diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp
index ef4bfa0889..f665823962 100644
--- a/Kernel/Net/TCPSocket.cpp
+++ b/Kernel/Net/TCPSocket.cpp
@@ -15,6 +15,17 @@ void TCPSocket::for_each(Function<void(TCPSocket&)> callback)
callback(*it.value);
}
+void TCPSocket::set_state(State new_state)
+{
+#ifdef TCP_SOCKET_DEBUG
+ kprintf("%s(%u) TCPSocket{%p} state moving from %s to %s\n",
+ current->process().name().characters(), current->pid(), this,
+ to_string(m_state), to_string(new_state));
+#endif
+
+ m_state = new_state;
+}
+
Lockable<HashMap<IPv4SocketTuple, TCPSocket*>>& TCPSocket::sockets_by_tuple()
{
static Lockable<HashMap<IPv4SocketTuple, TCPSocket*>>* s_map;
diff --git a/Kernel/Net/TCPSocket.h b/Kernel/Net/TCPSocket.h
index 09fdfb1984..7afb071cfc 100644
--- a/Kernel/Net/TCPSocket.h
+++ b/Kernel/Net/TCPSocket.h
@@ -78,7 +78,7 @@ public:
}
State state() const { return m_state; }
- void set_state(State state) { m_state = state; }
+ void set_state(State state);
Direction direction() const { return m_direction; }