1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:28:11 +00:00

Kernel: Make sure we increment the TX counter

This was broken by b436dd1.
This commit is contained in:
Gunnar Beutner 2021-06-04 17:58:55 +02:00 committed by Andreas Kling
parent c66b281856
commit 60298121d8
6 changed files with 15 additions and 9 deletions

View file

@ -230,7 +230,7 @@ KResultOr<size_t> IPv4Socket::sendto(FileDescription&, const UserOrKernelBuffer&
routing_decision.adapter->release_packet_buffer(*packet);
return EFAULT;
}
routing_decision.adapter->send_raw({ packet->buffer.data(), packet->buffer.size() });
routing_decision.adapter->send_packet({ packet->buffer.data(), packet->buffer.size() });
routing_decision.adapter->release_packet_buffer(*packet);
return data_length;
}

View file

@ -61,6 +61,12 @@ NetworkAdapter::~NetworkAdapter()
all_adapters().resource().remove(this);
}
void NetworkAdapter::send_packet(ReadonlyBytes packet)
{
m_packets_out++;
send_raw(packet);
}
void NetworkAdapter::send(const MACAddress& destination, const ARPPacket& packet)
{
size_t size_in_bytes = sizeof(EthernetFrameHeader) + sizeof(ARPPacket);
@ -69,10 +75,9 @@ void NetworkAdapter::send(const MACAddress& destination, const ARPPacket& packet
eth->set_source(mac_address());
eth->set_destination(destination);
eth->set_ether_type(EtherType::ARP);
m_packets_out++;
m_bytes_out += size_in_bytes;
memcpy(eth->payload(), &packet, sizeof(ARPPacket));
send_raw({ (const u8*)eth, size_in_bytes });
send_packet({ (const u8*)eth, size_in_bytes });
}
void NetworkAdapter::fill_in_ipv4_header(PacketWithTimestamp& packet, IPv4Address const& source_ipv4, MACAddress const& destination_mac, IPv4Address const& destination_ipv4, IPv4Protocol protocol, size_t payload_size, u8 ttl)

View file

@ -89,15 +89,16 @@ public:
constexpr size_t layer3_payload_offset() const { return sizeof(EthernetFrameHeader); }
constexpr size_t ipv4_payload_offset() const { return layer3_payload_offset() + sizeof(IPv4Packet); }
virtual void send_raw(ReadonlyBytes) = 0;
Function<void()> on_receive;
void send_packet(ReadonlyBytes);
protected:
NetworkAdapter();
void set_interface_name(const PCI::Address&);
void set_mac_address(const MACAddress& mac_address) { m_mac_address = mac_address; }
void did_receive(ReadonlyBytes);
virtual void send_raw(ReadonlyBytes) = 0;
void set_loopback_name();

View file

@ -263,7 +263,7 @@ void handle_icmp(const EthernetFrameHeader& eth, const IPv4Packet& ipv4_packet,
memcpy(response.payload(), request.payload(), icmp_payload_size);
response.header.set_checksum(internet_checksum(&response, icmp_packet_size));
// FIXME: What is the right TTL value here? Is 64 ok? Should we use the same TTL as the echo request?
adapter->send_raw({ packet->buffer.data(), packet->buffer.size() });
adapter->send_packet({ packet->buffer.data(), packet->buffer.size() });
adapter->release_packet_buffer(*packet);
}
}

View file

@ -240,7 +240,7 @@ KResult TCPSocket::send_tcp_packet(u16 flags, const UserOrKernelBuffer* payload,
tcp_packet.set_checksum(compute_tcp_checksum(local_address(), peer_address(), tcp_packet, payload_size));
routing_decision.adapter->send_raw({ packet->buffer.data(), packet->buffer.size() });
routing_decision.adapter->send_packet({ packet->buffer.data(), packet->buffer.size() });
m_packets_out++;
m_bytes_out += buffer_size;
@ -572,7 +572,7 @@ void TCPSocket::retransmit_packets()
routing_decision.adapter->fill_in_ipv4_header(*packet.buffer,
local_address(), routing_decision.next_hop, peer_address(),
IPv4Protocol::TCP, packet.buffer->buffer.size() - ipv4_payload_offset, ttl());
routing_decision.adapter->send_raw({ packet.buffer->buffer.data(), packet.buffer->buffer.size() });
routing_decision.adapter->send_packet({ packet.buffer->buffer.data(), packet.buffer->buffer.size() });
m_packets_out++;
m_bytes_out += packet.buffer->buffer.size();
}

View file

@ -94,7 +94,7 @@ KResultOr<size_t> UDPSocket::protocol_send(const UserOrKernelBuffer& data, size_
routing_decision.adapter->fill_in_ipv4_header(*packet, local_address(), routing_decision.next_hop,
peer_address(), IPv4Protocol::UDP, udp_buffer_size, ttl());
routing_decision.adapter->send_raw({ packet->buffer.data(), packet->buffer.size() });
routing_decision.adapter->send_packet({ packet->buffer.data(), packet->buffer.size() });
return data_length;
}