Kernel: Put IPv4 and TCP related debug spam behind flags

...and turn those flags off for now, to make it possible to write some
networking code without being spammed to death.
This commit is contained in:
Andreas Kling 2019-08-04 10:04:06 +02:00
parent 273d9d6cf5
commit 675aa550a4
Notes: sideshowbarker 2024-07-19 12:54:31 +09:00
3 changed files with 12 additions and 4 deletions

View file

@ -13,7 +13,7 @@
#include <Kernel/UnixTypes.h>
#include <LibC/errno_numbers.h>
#define IPV4_SOCKET_DEBUG
//#define IPV4_SOCKET_DEBUG
Lockable<HashTable<IPv4Socket*>>& IPv4Socket::all_sockets()
{

View file

@ -14,10 +14,10 @@
#include <Kernel/Process.h>
//#define ETHERNET_DEBUG
#define IPV4_DEBUG
//#define IPV4_DEBUG
//#define ICMP_DEBUG
#define UDP_DEBUG
#define TCP_DEBUG
//#define UDP_DEBUG
//#define TCP_DEBUG
static void handle_arp(const EthernetFrameHeader&, int frame_size);
static void handle_ipv4(const EthernetFrameHeader&, int frame_size);
@ -329,12 +329,14 @@ void handle_tcp(const EthernetFrameHeader& eth, int frame_size)
}
socket->set_ack_number(tcp_packet.sequence_number() + payload_size);
#ifdef TCP_DEBUG
kprintf("Got packet with ack_no=%u, seq_no=%u, payload_size=%u, acking it with new ack_no=%u, seq_no=%u\n",
tcp_packet.ack_number(),
tcp_packet.sequence_number(),
payload_size,
socket->ack_number(),
socket->sequence_number());
#endif
socket->send_tcp_packet(TCPFlags::ACK);
if (payload_size != 0)

View file

@ -6,6 +6,8 @@
#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/Process.h>
//#define TCP_SOCKET_DEBUG
Lockable<HashMap<u16, TCPSocket*>>& TCPSocket::sockets_by_port()
{
static Lockable<HashMap<u16, TCPSocket*>>* s_map;
@ -51,7 +53,9 @@ int TCPSocket::protocol_receive(const ByteBuffer& packet_buffer, void* buffer, s
auto& ipv4_packet = *(const IPv4Packet*)(packet_buffer.pointer());
auto& tcp_packet = *static_cast<const TCPPacket*>(ipv4_packet.payload());
size_t payload_size = packet_buffer.size() - sizeof(IPv4Packet) - tcp_packet.header_size();
#ifdef TCP_SOCKET_DEBUG
kprintf("payload_size %u, will it fit in %u?\n", payload_size, buffer_size);
#endif
ASSERT(buffer_size >= payload_size);
memcpy(buffer, tcp_packet.payload(), payload_size);
return payload_size;
@ -93,6 +97,7 @@ void TCPSocket::send_tcp_packet(u16 flags, const void* payload, int payload_size
memcpy(tcp_packet.payload(), payload, payload_size);
tcp_packet.set_checksum(compute_tcp_checksum(adapter->ipv4_address(), peer_address(), tcp_packet, payload_size));
#ifdef TCP_SOCKET_DEBUG
kprintf("sending tcp packet from %s:%u to %s:%u with (%s %s) seq_no=%u, ack_no=%u\n",
adapter->ipv4_address().to_string().characters(),
local_port(),
@ -102,6 +107,7 @@ void TCPSocket::send_tcp_packet(u16 flags, const void* payload, int payload_size
tcp_packet.has_ack() ? "ACK" : "",
tcp_packet.sequence_number(),
tcp_packet.ack_number());
#endif
adapter->send_ipv4(MACAddress(), peer_address(), IPv4Protocol::TCP, move(buffer));
}