summaryrefslogtreecommitdiff
path: root/Kernel/Net
diff options
context:
space:
mode:
authorConrad Pankoff <deoxxa@fknsrs.biz>2019-08-29 11:18:38 +1000
committerAndreas Kling <awesomekling@gmail.com>2019-08-29 06:25:06 +0200
commitb15a7c435ff8f23b92fa007ca987a13df711c8a4 (patch)
treed64bff1c7b804d2c6dff3acf135e2b821824bae6 /Kernel/Net
parent302d52148514cac35cb3eae3f2a85d37d8cdd8c9 (diff)
downloadserenity-b15a7c435ff8f23b92fa007ca987a13df711c8a4.zip
Kernel: Implement is_zero for RoutingDecision
Diffstat (limited to 'Kernel/Net')
-rw-r--r--Kernel/Net/IPv4Socket.cpp2
-rw-r--r--Kernel/Net/Routing.cpp5
-rw-r--r--Kernel/Net/Routing.h2
-rw-r--r--Kernel/Net/TCPSocket.cpp4
-rw-r--r--Kernel/Net/UDPSocket.cpp2
5 files changed, 11 insertions, 4 deletions
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp
index 9ba3555358..77077b79c0 100644
--- a/Kernel/Net/IPv4Socket.cpp
+++ b/Kernel/Net/IPv4Socket.cpp
@@ -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)
diff --git a/Kernel/Net/Routing.cpp b/Kernel/Net/Routing.cpp
index a74c3e329a..befbaf7bb5 100644
--- a/Kernel/Net/Routing.cpp
+++ b/Kernel/Net/Routing.cpp
@@ -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();
diff --git a/Kernel/Net/Routing.h b/Kernel/Net/Routing.h
index 131237336b..842810d2b9 100644
--- a/Kernel/Net/Routing.h
+++ b/Kernel/Net/Routing.h
@@ -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);
diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp
index e2d8c0f731..acdb6c341e 100644
--- a/Kernel/Net/TCPSocket.cpp
+++ b/Kernel/Net/TCPSocket.cpp
@@ -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());
diff --git a/Kernel/Net/UDPSocket.cpp b/Kernel/Net/UDPSocket.cpp
index bbadbb505e..da6f6d140f 100644
--- a/Kernel/Net/UDPSocket.cpp
+++ b/Kernel/Net/UDPSocket.cpp
@@ -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());