Kernel: Implement is_zero for RoutingDecision
This commit is contained in:
parent
302d521485
commit
b15a7c435f
Notes:
sideshowbarker
2024-07-19 12:26:57 +09:00
Author: https://github.com/deoxxa Commit: https://github.com/SerenityOS/serenity/commit/b15a7c435ff Pull-request: https://github.com/SerenityOS/serenity/pull/499 Reviewed-by: https://github.com/awesomekling
5 changed files with 11 additions and 4 deletions
|
@ -170,7 +170,7 @@ ssize_t IPv4Socket::sendto(FileDescription&, const void* data, size_t data_lengt
|
|||
}
|
||||
|
||||
auto routing_decision = route_to(m_peer_address, m_local_address);
|
||||
if (!routing_decision.adapter || routing_decision.next_hop.is_zero())
|
||||
if (routing_decision.is_zero())
|
||||
return -EHOSTUNREACH;
|
||||
|
||||
if (m_local_address.to_u32() == 0)
|
||||
|
|
|
@ -11,6 +11,11 @@ Lockable<HashMap<IPv4Address, MACAddress>>& arp_table()
|
|||
return *the;
|
||||
}
|
||||
|
||||
bool RoutingDecision::is_zero() const
|
||||
{
|
||||
return adapter.is_null() || next_hop.is_zero();
|
||||
}
|
||||
|
||||
RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source)
|
||||
{
|
||||
auto target_addr = target.to_u32();
|
||||
|
|
|
@ -6,6 +6,8 @@ struct RoutingDecision
|
|||
{
|
||||
WeakPtr<NetworkAdapter> adapter;
|
||||
MACAddress next_hop;
|
||||
|
||||
bool is_zero() const;
|
||||
};
|
||||
|
||||
RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source);
|
||||
|
|
|
@ -126,7 +126,7 @@ int TCPSocket::protocol_send(const void* data, int data_length)
|
|||
void TCPSocket::send_tcp_packet(u16 flags, const void* payload, int payload_size)
|
||||
{
|
||||
auto routing_decision = route_to(peer_address(), local_address());
|
||||
ASSERT(!!routing_decision.adapter);
|
||||
ASSERT(!routing_decision.is_zero());
|
||||
|
||||
auto buffer = ByteBuffer::create_zeroed(sizeof(TCPPacket) + payload_size);
|
||||
auto& tcp_packet = *(TCPPacket*)(buffer.pointer());
|
||||
|
@ -242,7 +242,7 @@ KResult TCPSocket::protocol_listen()
|
|||
KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock should_block)
|
||||
{
|
||||
auto routing_decision = route_to(peer_address(), local_address());
|
||||
if (!routing_decision.adapter || routing_decision.next_hop.is_zero())
|
||||
if (routing_decision.is_zero())
|
||||
return KResult(-EHOSTUNREACH);
|
||||
if (!has_specific_local_address())
|
||||
set_local_address(routing_decision.adapter->ipv4_address());
|
||||
|
|
|
@ -64,7 +64,7 @@ int UDPSocket::protocol_receive(const KBuffer& packet_buffer, void* buffer, size
|
|||
int UDPSocket::protocol_send(const void* data, int data_length)
|
||||
{
|
||||
auto routing_decision = route_to(peer_address(), local_address());
|
||||
if (!routing_decision.adapter)
|
||||
if (routing_decision.is_zero())
|
||||
return -EHOSTUNREACH;
|
||||
auto buffer = ByteBuffer::create_zeroed(sizeof(UDPPacket) + data_length);
|
||||
auto& udp_packet = *(UDPPacket*)(buffer.pointer());
|
||||
|
|
Loading…
Add table
Reference in a new issue