Commit graph

681 commits

Author SHA1 Message Date
Timon Kruiper a4534678f9 Kernel: Implement InterruptDisabler using generic Processor functions
Now that the code does not use architectural specific code, it is moved
to the generic Arch directory and the paths are modified accordingly.
2022-06-02 13:14:12 +01:00
brapru 1dd22582da Kernel: Ignore interfaces without an IP address when updating ARP
For the same reason we ignore interfaces without an IP address when
choosing where to send a route, we should also ignore interfaces without
IP addresses when updating the ARP table on incoming packets from
local addresses.

On an interface with a null address, the mask checking would always
result in zero, which resulted in the system updating the ARP table on
almost every incoming packet from any address (private or public).

This patch fixes this behavior by only applying this check to interfaces
with valid addresses and now the ARP table won't get constantly
hammered.

Closes #13713
2022-05-31 10:22:46 +01:00
brapru 7a4e41f8f8 Kernel: Add support for route flags
Previously the routing table did not store the route flags. This
adds basic support and exposes them in the /proc directory so that a
userspace caller can query the route and identify the type of each
route.
2022-05-26 16:33:10 +02:00
Maciej 66ab4d61a4 Kernel: Stop exposing gateway field
It doesn't make sense after introduction of routing table which allows
having multiple gateways for every interface, and isn't used by any of
the userspace programs now.
2022-05-01 13:34:27 +02:00
brapru 0866a0cd1e Kernel+route: Support global routing table deletion 2022-04-30 16:24:33 +02:00
brapru 863c14c4f4 Kernel: Make Route's operator== overload const 2022-04-30 16:24:33 +02:00
brapru 8596b1e0c3 Kernel: Add a global routing table
Previously the system had no concept of assigning different routes for
different destination addresses as the default gateway IP address was
directly assigned to a network adapter. This default gateway was
statically assigned and any update  would remove the previously existing
route.

This patch is a beginning step towards implementing #180. It implements
a simple global routing table that is referenced during the routing
process. With this implementation it is now possible for a user or
service (i.e. DHCP) to dynamically add routes to the table.

The routing table will select the most specific route when possible. It
will select any direct match between the destination and routing entry
addresses. If the destination address overlaps between multiple entries,
the Kernel will use the longest prefix match, or the longest number of
matching bits between the destination address and the routing address.
In the event that there is no entries found for a specific destination
address, this implementation supports entries for a default route to be
set for any specified interface.

This is a small first step towards enhancing the system's routing
capabilities. Future enhancements would include referencing a
configuration file at boot to load pre-defined static routes.
2022-04-28 08:41:11 -07:00
brapru 0718b20df0 Kernel: Generalize the UpdateArp table to UpdateTable
We can use the same enum cases to apply to updates on different
networking tables within the Kernel (i.e. a routing table)
2022-04-28 08:41:11 -07:00
Andreas Kling 5e4d5a436e Kernel: Allow sys$bind() on local sockets with short socket address
Previously, we required local socket addresses to be exactly
sizeof(sockaddr_un). There was no real reason for this, so let's not
enforce it.
2022-04-21 16:31:53 +02:00
Andreas Kling 8e9676c28c Kernel: Report AF_UNIX address family when accepting local sockets
Previously we just wrote the local socket bind path into the sockaddr_un
buffer. With this patch, we actually report the family as well.
2022-04-21 16:31:53 +02:00
Idan Horowitz 2c025d6334 Kernel: Move NNRP<Socket>s instead of copying in queue_connection_from 2022-04-09 23:46:02 +02:00
Idan Horowitz 4a270c93ed Kernel: Accept NNRP<Socket> instead of RP<Socket> in release_for_accept
This value is always non-null, so let's make it explicit.
2022-04-09 23:46:02 +02:00
Idan Horowitz 086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Andreas Kling 6625edb5d2 Kernel: When receiving unexpected TCP flags, print the flags
It'll be easier to understand what might be happening if we know which
unexpected flags are actually showing up. :^)
2022-03-18 15:18:48 +01:00
Andreas Kling f0dde1cee1 Kernel: Rename TCPFlags::PUSH => PSH
Let's use the proper name of this TCP flag.
2022-03-18 15:18:48 +01:00
Lenny Maiorani 2548ee4149 Kernel: Make number of RTL8168 rx/tx descriptors constexpr 2022-03-17 13:36:17 -07:00
Lenny Maiorani 190cf1507b Kernel: Use default constructors/destructors
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-17 00:51:36 -07:00
Liav A 3fb289e27d Kernel/PCI: Don't hold spinlocks when doing fast device enumeration
Instead, hold the lock while we copy the contents to a stack-based
Vector then iterate on it without any locking.

Because we rely on heap allocations, we need to propagate errors back
in case of OOM condition, therefore, both PCI::enumerate API function
and PCI::Access::add_host_controller_and_enumerate_attached_devices use
now a ErrorOr<void> return value to propagate errors. OOM Error can only
occur when enumerating the m_device_identifiers vector under a spinlock
and trying to expand the temporary Vector which will be used locklessly
to actually iterate over the PCI::DeviceIdentifiers objects.
2022-03-14 22:39:09 +01:00
Liav A 71de4f7114 Kernel/Net: Don't try to enumerate PCI adapters if PCI is disabled 2022-03-02 18:41:54 +01:00
Idan Horowitz 6682afb5d4 Kernel: Add UDPSocket::try_for_each() for fallible iteration
This API will allow users to short circuit iteration and properly
propagate errors.
2022-02-27 20:37:57 +01:00
Idan Horowitz aabc8d348b Kernel: Add TCPSocket::try_for_each() for fallible iteration
This API will allow users to short circuit iteration and properly
propagate errors.
2022-02-27 20:37:57 +01:00
Idan Horowitz 24be52b3f5 Kernel: Add LocalSocket::try_for_each() for fallible iteration
This API will allow users to short circuit iteration and properly
propagate errors.
2022-02-27 20:37:57 +01:00
Idan Horowitz 74ab8ccde0 Kernel: Add NetworkingManagement::try_for_each() for fallible iteration
This API will allow users to short circuit iteration and properly
propagate errors.
2022-02-27 20:37:57 +01:00
Idan Horowitz ead8ac8972 Kernel: Lock socket Mutex when servicing IPv4Socket ioctls
This prevents a kernel panic found in CI when m_receive_queue's size is
queried and found to be non-zero, then a different thread clears the
queue, and finally the first thread continues into the if block and
calls the queue's first() method, which then fails an assertion that
the queue's size is non-zero.
2022-02-18 02:22:12 +02:00
Andreas Kling c797eaa9f8 Kernel/Net: Don't update TCP socket "last sent ACK" field too early
Defer updating this field until after the last fallible operation has
succeeded.
2022-02-11 12:45:38 +01:00
Andreas Kling 06cf01cd1e Kernel/E1000: Bump RX/TX buffer count to 256/256
We were frequently dropping packets when downloading large files.
Then we had to wait for TCP retransmission which slowed things down.

This patch dramatically improves E1000 throughput by increasing the
number of RX/TX buffers from 32/8 to 256/256.

The largest chunk of JavaScript from Discord now downloads in roughly
1 second instead of 7 seconds. :^)
2022-02-11 12:45:38 +01:00
Jamie Mansfield 8964f754f5 Kernel: Fix bug in TCP state handling in SynSent
When receiving SYN while in SynSent, we now reply with SYN|ACK in
addition to the SynSent->SynReceived transition.
2022-02-07 13:18:13 +01:00
Andreas Kling cda56f8049 Kernel: Robustify and rename Inode bound socket API
Rename the bound socket accessor from socket() to bound_socket().
Also return RefPtr<LocalSocket> instead of a raw pointer, to make it
harder for callers to mess up.
2022-02-07 13:02:34 +01:00
Andreas Kling 83523cabda Kernel: Fix bugs in TCP state handling in FinWait1 & FinWait2
1. When receiving FIN while in FinWait1, we now reply with ACK
   in addition to the FinWait1->Closing transition.

2. When receiving FIN|ACK while in FinWait1, we now reply with
   ACK and transition from FinWait1->TimeWait.

3. When receiving FIN while in FinWait2, we now reply with ACK.
2022-02-06 22:13:13 +01:00
Andreas Kling 7247f0204d Kernel: Send only FIN when shutting down TCP socket from ESTABLISHED
We were previously sending FIN|ACK for some reason.
2022-02-06 22:13:13 +01:00
Idan Horowitz e5e7cb822a Kernel: Ignore allocation failures when trying to retransmit packets
We ignore allocation failures above the first 16 guaranteed socket
slots, as we will just retransmit their packets the next time around.
2022-02-03 23:33:20 +01:00
Andreas Kling 3becff9eae Kernel: Protect network adapter list with spinlock instead of mutex 2022-02-03 16:11:26 +01:00
Andreas Kling 6fbb924bbf Kernel: Protect ARP table with spinlock instead of mutex 2022-02-03 16:11:26 +01:00
Idan Horowitz e28af4a2fc Kernel: Stop using HashMap in Mutex
This commit removes the usage of HashMap in Mutex, thereby making Mutex
be allocation-free.

In order to achieve this several simplifications were made to Mutex,
removing unused code-paths and extra VERIFYs:
 * We no longer support 'upgrading' a shared lock holder to an
   exclusive holder when it is the only shared holder and it did not
   unlock the lock before relocking it as exclusive. NOTE: Unlike the
   rest of these changes, this scenario is not VERIFY-able in an
   allocation-free way, as a result the new LOCK_SHARED_UPGRADE_DEBUG
   debug flag was added, this flag lets Mutex allocate in order to
   detect such cases when debugging a deadlock.
 * We no longer support checking if a Mutex is locked by the current
   thread when the Mutex was not locked exclusively, the shared version
   of this check was not used anywhere.
 * We no longer support force unlocking/relocking a Mutex if the Mutex
   was not locked exclusively, the shared version of these functions
   was not used anywhere.
2022-01-29 16:45:39 +01:00
Idan Horowitz 664ca58746 Kernel: Use u64 instead of size_t for File::can_write offset
This ensures offsets will not be truncated on large files on i686.
2022-01-25 22:41:17 +02:00
Idan Horowitz 9ce537d703 Kernel: Use u64 instead of size_t for File::can_read offset
This ensures offsets will not be truncated on large files on i686.
2022-01-25 22:41:17 +02:00
Sam Atkins 45cf40653a Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOr
Apologies for the enormous commit, but I don't see a way to split this
up nicely. In the vast majority of cases it's a simple change. A few
extra places can use TRY instead of manual error checking though. :^)
2022-01-24 22:36:09 +01:00
Brian Gianforcaro 4bf88bb732 Kernel: Fix typo in Socket::getsockopt tracing 2022-01-18 08:47:22 +01:00
Idan Horowitz c92753a686 Kernel: Convert IPv4SocketTuple::to_string() to KString 2022-01-12 16:09:09 +02:00
Idan Horowitz b84444cbb3 Kernel: Move IPv4SocketTuple into the Kernel namespace
This class was accidentally declared in the global namespace.
2022-01-12 16:09:09 +02:00
Brian Gianforcaro ccbc3f8975 Kernel: Harden Socket::pseudo_path(..) implementations against OOM
Use the try variants of AK::StringBuilder append APIs to harden these
functions against OOM.
2022-01-09 12:22:52 +01:00
Andreas Kling b86443f0e1 Kernel: Lock weak pointer revocation during listed-ref-counted unref
When doing the last unref() on a listed-ref-counted object, we keep
the list locked while mutating the ref count. The destructor itself
is invoked after unlocking the list.

This was racy with weakable classes, since their weak pointer factory
still pointed to the object after we'd decided to destroy it. That
opened a small time window where someone could try to strong-ref a weak
pointer to an object after it was removed from the list, but just before
the destructor got invoked.

This patch closes the race window by explicitly revoking all weak
pointers while the list is locked.
2022-01-08 16:31:14 +01:00
Andreas Kling 626507943c Kernel: Remove redundant socket_by_tuple removal in ~TCPSocket() 2022-01-06 22:51:28 +01:00
Andreas Kling 01b3666894 Kernel: Lock TCPSocket lookup table across destruction
Use the same trick as SlavePTY and override unref() to provide safe
removal from the sockets_by_tuple table when destroying a TCPSocket.

This should fix the TCPSocket::from_tuple() flake seen on CI.
2022-01-06 22:30:40 +01:00
Brian Gianforcaro 24066ba5ef Kernel: Use MUST + Vector::try_append instead of Vector::append
In preparation for making Vector::append unavailable during
compilation of the Kernel.
2022-01-05 14:04:18 +01:00
drblah b6ba0f9fad Kernel: Update E1000 link state using interrupt
Calls to link_up() in the E1000 driver would read the link state
directly from the hardware on every call. This had negative
performance impact in high throughput situations since link_up()
is called every time an IP packet's route is resolved.

This patch takes inspiration from the RTL8139 network adapter where
the link state is stored in a bool and only updated when the hardware
generates an interrupt related to link state change.

After this change I measured a ~9% increase in TCP Tx throughput
using:
cat /dev/zero | nc <host_IP> <host_port> from the Serenity VM to my
host machine
2021-12-31 15:48:16 +01:00
Daniel Bertalan 8e2efe78f7 Kernel: Tighten String-related includes 2021-12-30 14:16:03 +01:00
Daniel Bertalan 2175c689ef Kernel: Remove redundant (K)String::characters() calls 2021-12-30 14:16:03 +01:00
Daniel Bertalan 1d2f78682b Kernel+AK: Eliminate a couple of temporary String allocations 2021-12-30 14:16:03 +01:00
Brian Gianforcaro 54b9a4ec1e Kernel: Handle promise violations in the syscall handler
Previously we would crash the process immediately when a promise
violation was found during a syscall. This is error prone, as we
don't unwind the stack. This means that in certain cases we can
leak resources, like an OwnPtr / RefPtr tracked on the stack. Or
even leak a lock acquired in a ScopeLockLocker.

To remedy this situation we move the promise violation handling to
the syscall handler, right before we return to user space. This
allows the code to follow the normal unwind path, and grantees
there is no longer any cleanup that needs to occur.

The Process::require_promise() and Process::require_no_promises()
functions were modified to return ErrorOr<void> so we enforce that
the errors are always propagated by the caller.
2021-12-29 18:08:15 +01:00