summaryrefslogtreecommitdiff
path: root/Kernel/Net
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel/Net')
-rw-r--r--Kernel/Net/IPv4Socket.cpp6
-rw-r--r--Kernel/Net/IPv4Socket.h8
-rw-r--r--Kernel/Net/LocalSocket.cpp2
-rw-r--r--Kernel/Net/LocalSocket.h2
-rw-r--r--Kernel/Net/NetworkAdapter.cpp5
-rw-r--r--Kernel/Net/NetworkAdapter.h4
-rw-r--r--Kernel/Net/NetworkTask.cpp20
-rw-r--r--Kernel/Net/Socket.cpp24
-rw-r--r--Kernel/Net/Socket.h15
-rw-r--r--Kernel/Net/TCPSocket.cpp9
-rw-r--r--Kernel/Net/TCPSocket.h2
11 files changed, 50 insertions, 47 deletions
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp
index d08c29e204..104fcc6b8a 100644
--- a/Kernel/Net/IPv4Socket.cpp
+++ b/Kernel/Net/IPv4Socket.cpp
@@ -269,7 +269,7 @@ KResultOr<size_t> IPv4Socket::receive_byte_buffered(FileDescription& description
return nreceived;
}
-KResultOr<size_t> IPv4Socket::receive_packet_buffered(FileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*> addr, Userspace<socklen_t*> addr_length, timeval& packet_timestamp)
+KResultOr<size_t> IPv4Socket::receive_packet_buffered(FileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*> addr, Userspace<socklen_t*> addr_length, Time& packet_timestamp)
{
Locker locker(lock());
ReceivedPacket packet;
@@ -352,7 +352,7 @@ KResultOr<size_t> IPv4Socket::receive_packet_buffered(FileDescription& descripti
return protocol_receive(ReadonlyBytes { packet.data.value().data(), packet.data.value().size() }, buffer, buffer_length, flags);
}
-KResultOr<size_t> IPv4Socket::recvfrom(FileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*> user_addr, Userspace<socklen_t*> user_addr_length, timeval& packet_timestamp)
+KResultOr<size_t> IPv4Socket::recvfrom(FileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*> user_addr, Userspace<socklen_t*> user_addr_length, Time& packet_timestamp)
{
if (user_addr_length) {
socklen_t addr_length;
@@ -377,7 +377,7 @@ KResultOr<size_t> IPv4Socket::recvfrom(FileDescription& description, UserOrKerne
return nreceived;
}
-bool IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port, KBuffer&& packet, const timeval& packet_timestamp)
+bool IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port, KBuffer&& packet, const Time& packet_timestamp)
{
LOCKER(lock());
diff --git a/Kernel/Net/IPv4Socket.h b/Kernel/Net/IPv4Socket.h
index bc1b0fc6da..5fb55b741f 100644
--- a/Kernel/Net/IPv4Socket.h
+++ b/Kernel/Net/IPv4Socket.h
@@ -57,13 +57,13 @@ public:
virtual bool can_read(const FileDescription&, size_t) const override;
virtual bool can_write(const FileDescription&, size_t) const override;
virtual KResultOr<size_t> sendto(FileDescription&, const UserOrKernelBuffer&, size_t, int, Userspace<const sockaddr*>, socklen_t) override;
- virtual KResultOr<size_t> recvfrom(FileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, timeval&) override;
+ virtual KResultOr<size_t> recvfrom(FileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Time&) override;
virtual KResult setsockopt(int level, int option, Userspace<const void*>, socklen_t) override;
virtual KResult getsockopt(FileDescription&, int level, int option, Userspace<void*>, Userspace<socklen_t*>) override;
virtual int ioctl(FileDescription&, unsigned request, FlatPtr arg) override;
- bool did_receive(const IPv4Address& peer_address, u16 peer_port, KBuffer&&, const timeval&);
+ bool did_receive(const IPv4Address& peer_address, u16 peer_port, KBuffer&&, const Time&);
const IPv4Address& local_address() const { return m_local_address; }
u16 local_port() const { return m_local_port; }
@@ -109,7 +109,7 @@ private:
virtual bool is_ipv4() const override { return true; }
KResultOr<size_t> receive_byte_buffered(FileDescription&, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>);
- KResultOr<size_t> receive_packet_buffered(FileDescription&, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, timeval&);
+ KResultOr<size_t> receive_packet_buffered(FileDescription&, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Time&);
void set_can_read(bool);
@@ -119,7 +119,7 @@ private:
struct ReceivedPacket {
IPv4Address peer_address;
u16 peer_port;
- timeval timestamp;
+ Time timestamp;
Optional<KBuffer> data;
};
diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp
index d77d4c287f..09809cf5ac 100644
--- a/Kernel/Net/LocalSocket.cpp
+++ b/Kernel/Net/LocalSocket.cpp
@@ -307,7 +307,7 @@ DoubleBuffer* LocalSocket::send_buffer_for(FileDescription& description)
return nullptr;
}
-KResultOr<size_t> LocalSocket::recvfrom(FileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_size, int, Userspace<sockaddr*>, Userspace<socklen_t*>, timeval&)
+KResultOr<size_t> LocalSocket::recvfrom(FileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_size, int, Userspace<sockaddr*>, Userspace<socklen_t*>, Time&)
{
auto* socket_buffer = receive_buffer_for(description);
if (!socket_buffer)
diff --git a/Kernel/Net/LocalSocket.h b/Kernel/Net/LocalSocket.h
index ab98dd017e..12391fb31b 100644
--- a/Kernel/Net/LocalSocket.h
+++ b/Kernel/Net/LocalSocket.h
@@ -61,7 +61,7 @@ public:
virtual bool can_read(const FileDescription&, size_t) const override;
virtual bool can_write(const FileDescription&, size_t) const override;
virtual KResultOr<size_t> sendto(FileDescription&, const UserOrKernelBuffer&, size_t, int, Userspace<const sockaddr*>, socklen_t) override;
- virtual KResultOr<size_t> recvfrom(FileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, timeval&) override;
+ virtual KResultOr<size_t> recvfrom(FileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Time&) override;
virtual KResult getsockopt(FileDescription&, int level, int option, Userspace<void*>, Userspace<socklen_t*>) override;
virtual KResult chown(FileDescription&, uid_t, gid_t) override;
virtual KResult chmod(FileDescription&, mode_t) override;
diff --git a/Kernel/Net/NetworkAdapter.cpp b/Kernel/Net/NetworkAdapter.cpp
index b430bccf57..84be1a7b2f 100644
--- a/Kernel/Net/NetworkAdapter.cpp
+++ b/Kernel/Net/NetworkAdapter.cpp
@@ -193,14 +193,13 @@ void NetworkAdapter::did_receive(ReadonlyBytes payload)
}
}
- // FIXME: Should use AK::Time internally
- m_packet_queue.append({ buffer.value(), kgettimeofday().to_timeval() });
+ m_packet_queue.append({ buffer.value(), kgettimeofday() });
if (on_receive)
on_receive();
}
-size_t NetworkAdapter::dequeue_packet(u8* buffer, size_t buffer_size, timeval& packet_timestamp)
+size_t NetworkAdapter::dequeue_packet(u8* buffer, size_t buffer_size, Time& packet_timestamp)
{
InterruptDisabler disabler;
if (m_packet_queue.is_empty())
diff --git a/Kernel/Net/NetworkAdapter.h b/Kernel/Net/NetworkAdapter.h
index 5b2f3837ee..19d354b763 100644
--- a/Kernel/Net/NetworkAdapter.h
+++ b/Kernel/Net/NetworkAdapter.h
@@ -67,7 +67,7 @@ public:
KResult send_ipv4(const MACAddress&, const IPv4Address&, IPv4Protocol, const UserOrKernelBuffer& payload, size_t payload_size, u8 ttl);
KResult send_ipv4_fragmented(const MACAddress&, const IPv4Address&, IPv4Protocol, const UserOrKernelBuffer& payload, size_t payload_size, u8 ttl);
- size_t dequeue_packet(u8* buffer, size_t buffer_size, timeval& packet_timestamp);
+ size_t dequeue_packet(u8* buffer, size_t buffer_size, Time& packet_timestamp);
bool has_queued_packets() const { return !m_packet_queue.is_empty(); }
@@ -96,7 +96,7 @@ private:
struct PacketWithTimestamp {
KBuffer packet;
- timeval timestamp;
+ Time timestamp;
};
SinglyLinkedList<PacketWithTimestamp> m_packet_queue;
diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp
index 51dbecba6b..89d2ad1d18 100644
--- a/Kernel/Net/NetworkTask.cpp
+++ b/Kernel/Net/NetworkTask.cpp
@@ -44,10 +44,10 @@
namespace Kernel {
static void handle_arp(const EthernetFrameHeader&, size_t frame_size);
-static void handle_ipv4(const EthernetFrameHeader&, size_t frame_size, const timeval& packet_timestamp);
-static void handle_icmp(const EthernetFrameHeader&, const IPv4Packet&, const timeval& packet_timestamp);
-static void handle_udp(const IPv4Packet&, const timeval& packet_timestamp);
-static void handle_tcp(const IPv4Packet&, const timeval& packet_timestamp);
+static void handle_ipv4(const EthernetFrameHeader&, size_t frame_size, const Time& packet_timestamp);
+static void handle_icmp(const EthernetFrameHeader&, const IPv4Packet&, const Time& packet_timestamp);
+static void handle_udp(const IPv4Packet&, const Time& packet_timestamp);
+static void handle_tcp(const IPv4Packet&, const Time& packet_timestamp);
[[noreturn]] static void NetworkTask_main(void*);
@@ -81,7 +81,7 @@ void NetworkTask_main(void*)
};
});
- auto dequeue_packet = [&pending_packets](u8* buffer, size_t buffer_size, timeval& packet_timestamp) -> size_t {
+ auto dequeue_packet = [&pending_packets](u8* buffer, size_t buffer_size, Time& packet_timestamp) -> size_t {
if (pending_packets == 0)
return 0;
size_t packet_size = 0;
@@ -100,7 +100,7 @@ void NetworkTask_main(void*)
size_t buffer_size = 64 * KiB;
auto buffer_region = MM.allocate_kernel_region(buffer_size, "Kernel Packet Buffer", Region::Access::Read | Region::Access::Write);
auto buffer = (u8*)buffer_region->vaddr().get();
- timeval packet_timestamp;
+ Time packet_timestamp;
klog() << "NetworkTask: Enter main loop.";
for (;;) {
@@ -205,7 +205,7 @@ void handle_arp(const EthernetFrameHeader& eth, size_t frame_size)
}
}
-void handle_ipv4(const EthernetFrameHeader& eth, size_t frame_size, const timeval& packet_timestamp)
+void handle_ipv4(const EthernetFrameHeader& eth, size_t frame_size, const Time& packet_timestamp)
{
constexpr size_t minimum_ipv4_frame_size = sizeof(EthernetFrameHeader) + sizeof(IPv4Packet);
if (frame_size < minimum_ipv4_frame_size) {
@@ -242,7 +242,7 @@ void handle_ipv4(const EthernetFrameHeader& eth, size_t frame_size, const timeva
}
}
-void handle_icmp(const EthernetFrameHeader& eth, const IPv4Packet& ipv4_packet, const timeval& packet_timestamp)
+void handle_icmp(const EthernetFrameHeader& eth, const IPv4Packet& ipv4_packet, const Time& packet_timestamp)
{
auto& icmp_header = *static_cast<const ICMPHeader*>(ipv4_packet.payload());
#if ICMP_DEBUG
@@ -290,7 +290,7 @@ void handle_icmp(const EthernetFrameHeader& eth, const IPv4Packet& ipv4_packet,
}
}
-void handle_udp(const IPv4Packet& ipv4_packet, const timeval& packet_timestamp)
+void handle_udp(const IPv4Packet& ipv4_packet, const Time& packet_timestamp)
{
if (ipv4_packet.payload_size() < sizeof(UDPPacket)) {
klog() << "handle_udp: Packet too small (" << ipv4_packet.payload_size() << ", need " << sizeof(UDPPacket) << ")";
@@ -319,7 +319,7 @@ void handle_udp(const IPv4Packet& ipv4_packet, const timeval& packet_timestamp)
socket->did_receive(ipv4_packet.source(), udp_packet.source_port(), KBuffer::copy(&ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size()), packet_timestamp);
}
-void handle_tcp(const IPv4Packet& ipv4_packet, const timeval& packet_timestamp)
+void handle_tcp(const IPv4Packet& ipv4_packet, const Time& packet_timestamp)
{
if (ipv4_packet.payload_size() < sizeof(TCPPacket)) {
klog() << "handle_tcp: IPv4 payload is too small to be a TCP packet (" << ipv4_packet.payload_size() << ", need " << sizeof(TCPPacket) << ")";
diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp
index 0c25547244..d0ad2e3cec 100644
--- a/Kernel/Net/Socket.cpp
+++ b/Kernel/Net/Socket.cpp
@@ -110,8 +110,7 @@ KResult Socket::setsockopt(int level, int option, Userspace<const void*> user_va
auto timeout = copy_time_from_user(static_ptr_cast<const timeval*>(user_value));
if (!timeout.has_value())
return EFAULT;
- // FIXME: Should use AK::Time internally
- m_send_timeout = timeout->to_timeval();
+ m_send_timeout = timeout.value();
}
return KSuccess;
case SO_RCVTIMEO:
@@ -121,8 +120,7 @@ KResult Socket::setsockopt(int level, int option, Userspace<const void*> user_va
auto timeout = copy_time_from_user(static_ptr_cast<const timeval*>(user_value));
if (!timeout.has_value())
return EFAULT;
- // FIXME: Should use AK::Time internally
- m_receive_timeout = timeout->to_timeval();
+ m_receive_timeout = timeout.value();
}
return KSuccess;
case SO_BINDTODEVICE: {
@@ -178,8 +176,11 @@ KResult Socket::getsockopt(FileDescription&, int level, int option, Userspace<vo
case SO_SNDTIMEO:
if (size < sizeof(timeval))
return EINVAL;
- if (!copy_to_user(static_ptr_cast<timeval*>(value), &m_send_timeout))
- return EFAULT;
+ {
+ timeval tv = m_send_timeout.to_timeval();
+ if (!copy_to_user(static_ptr_cast<timeval*>(value), &tv))
+ return EFAULT;
+ }
size = sizeof(timeval);
if (!copy_to_user(value_size, &size))
return EFAULT;
@@ -187,8 +188,11 @@ KResult Socket::getsockopt(FileDescription&, int level, int option, Userspace<vo
case SO_RCVTIMEO:
if (size < sizeof(timeval))
return EINVAL;
- if (!copy_to_user(static_ptr_cast<timeval*>(value), &m_receive_timeout))
- return EFAULT;
+ {
+ timeval tv = m_send_timeout.to_timeval();
+ if (!copy_to_user(static_ptr_cast<timeval*>(value), &tv))
+ return EFAULT;
+ }
size = sizeof(timeval);
if (!copy_to_user(value_size, &size))
return EFAULT;
@@ -243,8 +247,8 @@ KResultOr<size_t> Socket::read(FileDescription& description, size_t, UserOrKerne
{
if (is_shut_down_for_reading())
return 0;
- timeval tv;
- return recvfrom(description, buffer, size, 0, {}, 0, tv);
+ Time t {};
+ return recvfrom(description, buffer, size, 0, {}, 0, t);
}
KResultOr<size_t> Socket::write(FileDescription& description, size_t, const UserOrKernelBuffer& data, size_t size)
diff --git a/Kernel/Net/Socket.h b/Kernel/Net/Socket.h
index e0a53a6f99..c45f1a2865 100644
--- a/Kernel/Net/Socket.h
+++ b/Kernel/Net/Socket.h
@@ -30,6 +30,7 @@
#include <AK/NonnullRefPtrVector.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
+#include <AK/Time.h>
#include <Kernel/FileSystem/File.h>
#include <Kernel/KResult.h>
#include <Kernel/Lock.h>
@@ -106,7 +107,7 @@ public:
virtual bool is_local() const { return false; }
virtual bool is_ipv4() const { return false; }
virtual KResultOr<size_t> sendto(FileDescription&, const UserOrKernelBuffer&, size_t, int flags, Userspace<const sockaddr*>, socklen_t) = 0;
- virtual KResultOr<size_t> recvfrom(FileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, timeval&) = 0;
+ virtual KResultOr<size_t> recvfrom(FileDescription&, UserOrKernelBuffer&, size_t, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>, Time&) = 0;
virtual KResult setsockopt(int level, int option, Userspace<const void*>, socklen_t);
virtual KResult getsockopt(FileDescription&, int level, int option, Userspace<void*>, Userspace<socklen_t*>);
@@ -127,11 +128,11 @@ public:
virtual KResult stat(::stat&) const override;
virtual String absolute_path(const FileDescription&) const override = 0;
- bool has_receive_timeout() const { return m_receive_timeout.tv_sec || m_receive_timeout.tv_usec; }
- const timeval& receive_timeout() const { return m_receive_timeout; }
+ bool has_receive_timeout() const { return m_receive_timeout != Time::zero(); }
+ const Time& receive_timeout() const { return m_receive_timeout; }
- bool has_send_timeout() const { return m_send_timeout.tv_sec || m_send_timeout.tv_usec; }
- const timeval& send_timeout() const { return m_send_timeout; }
+ bool has_send_timeout() const { return m_send_timeout != Time::zero(); }
+ const Time& send_timeout() const { return m_send_timeout; }
bool wants_timestamp() const { return m_timestamp; }
@@ -170,8 +171,8 @@ private:
RefPtr<NetworkAdapter> m_bound_interface { nullptr };
- timeval m_receive_timeout { 0, 0 };
- timeval m_send_timeout { 0, 0 };
+ Time m_receive_timeout {};
+ Time m_send_timeout {};
int m_timestamp { 0 };
NonnullRefPtrVector<Socket> m_pending;
diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp
index 2722bcaee2..e3f7274615 100644
--- a/Kernel/Net/TCPSocket.cpp
+++ b/Kernel/Net/TCPSocket.cpp
@@ -238,14 +238,13 @@ void TCPSocket::send_outgoing_packets()
auto routing_decision = route_to(peer_address(), local_address(), bound_interface());
VERIFY(!routing_decision.is_zero());
- // FIXME: Should use AK::Time internally
- auto now = kgettimeofday().to_timeval();
+ auto now = kgettimeofday();
LOCKER(m_not_acked_lock, Lock::Mode::Shared);
for (auto& packet : m_not_acked) {
- timeval diff;
- timeval_sub(packet.tx_time, now, diff);
- if (diff.tv_sec == 0 && diff.tv_usec <= 500000)
+ // FIXME: This doesn't look correct to me. Bug?
+ auto diff = packet.tx_time - now;
+ if (diff <= Time::from_nanoseconds(500'000'000))
continue;
packet.tx_time = now;
packet.tx_counter++;
diff --git a/Kernel/Net/TCPSocket.h b/Kernel/Net/TCPSocket.h
index 6c2abfef18..afe1490ca1 100644
--- a/Kernel/Net/TCPSocket.h
+++ b/Kernel/Net/TCPSocket.h
@@ -202,7 +202,7 @@ private:
u32 ack_number { 0 };
ByteBuffer buffer;
int tx_counter { 0 };
- timeval tx_time { 0, 0 };
+ Time tx_time {};
};
Lock m_not_acked_lock { "TCPSocket unacked packets" };