summaryrefslogtreecommitdiff
path: root/Kernel/Net/TCPSocket.h
AgeCommit message (Collapse)Author
2021-12-16Kernel: Return the correct result for FIONREAD on datagram socketssin-ack
Before this commit, we only checked the receive buffer on the socket, which is unused on datagram streams. Now we return the actual size of the datagram without the protocol headers, which required the protocol to tell us what the size of the payload is.
2021-11-08Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>Andreas Kling
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace! This was a slightly tedious refactoring that took a long time, so it's not unlikely that some bugs crept in. Nevertheless, it does pass basic functionality testing, and it's just real nice to finally see the same pattern in all contexts. :^)
2021-10-03Kernel: Use `operator ""sv` in all class_name() implementationsBrian Gianforcaro
Previously there was a mix of returning plain strings and returning explicit string views using `operator ""sv`. This change switches them all to standardized on `operator ""sv` as it avoids a call to strlen.
2021-09-10AK+Everywhere: Reduce the number of template parameters of IntrusiveListAli Mohammad Pur
This makes the user-facing type only take the node member pointer, and lets the compiler figure out the other needed types from that.
2021-09-07Kernel: TCPSocket always has a scratch bufferAndreas Kling
Let's encode this in the constructor signature.
2021-09-07Kernel: Make TCPSocket client construction use KResultOr and TRY()Andreas Kling
We don't really have anywhere to propagate the error in NetworkTask at the moment, since it runs in its own kernel thread and has no direct userspace caller.
2021-09-07Kernel: Rename FileDescription => OpenFileDescriptionAndreas Kling
Dr. POSIX really calls these "open file description", not just "file description", so let's call them exactly that. :^)
2021-09-05AK+Kernel: Move KResult.h to Kernel/API for userspace accesssin-ack
This commit moves the KResult and KResultOr objects to Kernel/API to signify that they may now be freely used by userspace code at points where a syscall-related error result is to be expected. It also exposes KResult and KResultOr to the global namespace to make it nicer to use for userspace code.
2021-09-04Kernel: Tidy up TCPSocket creation a bitAndreas Kling
- Rename create() => try_create() - Use adopt_nonnull_ref_or_enomem()
2021-08-22Kernel: Rename ProtectedValue<T> => MutexProtected<T>Andreas Kling
Let's make it obvious what we're protecting it with.
2021-08-15Kernel: Convert TCP retransmit queue from HashTable to IntrusiveListAndreas Kling
2021-08-07Kernel/TCP: Port TCP retransmit queue to ProtectedValueAndreas Kling
I had to switch to exclusive locking since ProtectedValue rightly doesn't allow you to mutate protected data with only a shared lock.
2021-08-07Kernel: Migrate TCP socket tables locking to ProtectedValueJean-Baptiste Boric
Note: TCPSocket::create_client() has a dubious locking process where the sockets by tuple table is first shared lock to check if the socket exists and bail out if it does, then unlocks, then exclusively locks to add the tuple. There could be a race condition where two client creation requests for the same tuple happen at the same time and both cleared the shared lock check. When in doubt, lock exclusively the whole time.
2021-08-07Kernel: Migrate IPv4 socket table locking to ProtectedValueJean-Baptiste Boric
2021-08-06Kernel: Make a bunch of "char const* to_string()" return StringViewAndreas Kling
2021-08-03Kernel: Handle OOM when allocating IPv4Socket optional scratch bufferBrian Gianforcaro
2021-08-03Kernel: Handle OOM from DoubleBuffer usage in IPv4SocketBrian Gianforcaro
The IPv4Socket requires a DoubleBuffer for storage of any data it received on the socket. However it was previously using the default constructor which can not observe allocation failure. Address this by plumbing the receive buffer through the various derived classes.
2021-08-02Kernel: Send RST/ACK if no socket is availablebrapru
Previously there was no way for Serenity to send a packet without an established socket connection, and there was no way to appropriately respond to a SYN packet on a non-listening port. This patch will respond to any non-established socket attempts with the appropraite RST/ACK, letting the client know to close the connection.
2021-07-17Kernel: Rename Lock to MutexAndreas Kling
Let's be explicit about what kind of lock this is meant to be.
2021-07-11Kernel: Make various T::class_name() and similar return StringViewAndreas Kling
Instead of returning char const*, we can also give you a StringView.
2021-06-01Kernel: Dont try to register ephemeral TCP ports twicestelar7
2021-05-26Kernel: Block when writing to TCP sockets when the send window is fullGunnar Beutner
Previously we'd just dump those packets into the network adapter's send queue and hope for the best. Instead we should wait until the peer has sent TCP ACK packets. Ideally this would parse the TCP window size option from the SYN or SYN|ACK packet, but for now we just assume the window size is 64 kB.
2021-05-26Kernel: Avoid allocations when sending IP packetsGunnar Beutner
Previously we'd allocate buffers when sending packets. This patch avoids these allocations by using the NetworkAdapter's packet queue. At the same time this also avoids copying partially constructed packets in order to prepend Ethernet and/or IPv4 headers. It also properly truncates UDP and raw IP packets.
2021-05-25Kernel: Don't try to send TCP packets larger than the MSSGunnar Beutner
Previously TCPSocket::send_tcp_packet() would try to send TCP packets which matched whatever size the userspace program specified. We'd try to break those packets up into smaller fragments, however a much better approach is to limit TCP packets to the maximum segment size and avoid fragmentation altogether.
2021-05-16Kernel: Avoid allocations when handling network packetsGunnar Beutner
2021-05-14Kernel: Merge do_retransmit_packets() into retransmit_packets()Gunnar Beutner
2021-05-14Kernel: Try to retransmit lost TCP packetsGunnar Beutner
Previously we didn't retransmit lost TCP packets which would cause connections to hang if packets were lost. Also we now time out TCP connections after a number of retransmission attempts.
2021-05-14Kernel: Remove dead TCPSocket::from_endpoints methodBrian Gianforcaro
2021-05-13Kernel: Make TCPSocket::create API OOM safeBrian Gianforcaro
Note that the changes to IPv4Socket::create are unfortunately needed as the return type of TCPSocket::create and IPv4Socket::create don't match. - KResultOr<NonnullRefPtr<TcpSocket>>> vs - KResultOr<NonnullRefPtr<Socket>>> To handle this we are forced to manually decompose the KResultOr<T> and return the value() and error() separately.
2021-05-12Kernel: Coalesce TCP ACKsGunnar Beutner
Previously we'd send a TCP ACK for each TCP packet we received. This changes NetworkTask so that we send fewer TCP ACKs.
2021-05-12Kernel: Trigger TCP fast retransmission when we encounter lost packetsGunnar Beutner
When we receive a TCP packet with a sequence number that is not what we expected we have lost one or more packets. We can signal this to the sender by sending a TCP ACK with the previous ack number so that they can resend the missing TCP fragments.
2021-05-12Kernel: Set MSS option for outbound TCP SYN packetsGunnar Beutner
When the MSS option header is missing the default maximum segment size is 536 which results in lots of very small TCP packets that NetworkTask has to handle. This adds the MSS option header to outbound TCP SYN packets and sets it to an appropriate value depending on the interface's MTU. Note that we do not currently do path MTU discovery so this could cause problems when hops don't fragment packets properly.
2021-04-30Kernel/IPv4: Propagate errors from local port allocationAndreas Kling
Remove hacks and assumptions and make the EADDRINUSE propagate all the way from the point of failure to the syscall layer.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-03-02Kernel: Make sockets use AK::TimeBen Wiederhake
2021-01-31Kernel: Use KResult a bit more in the IPv4 networking codeAndreas Kling
2020-12-18Kernel/Net: Make IPv4Socket::protocol_receive() take a ReadonlyBytesAndreas Kling
The overrides of this function don't need to know how the original packet was stored, so let's just give them a ReadonlyBytes view of the raw packet data.
2020-11-10AK: Make RefPtr, NonnullRefPtr, WeakPtr thread safeTom
This makes most operations thread safe, especially so that they can safely be used in the Kernel. This includes obtaining a strong reference from a weak reference, which now requires an explicit call to WeakPtr::strong_ref(). Another major change is that Weakable::make_weak_ref() may require the explicit target type. Previously we used reinterpret_cast in WeakPtr, assuming that it can be properly converted. But WeakPtr does not necessarily have the knowledge to be able to do this. Instead, we now ask the class itself to deliver a WeakPtr to the type that we want. Also, WeakLink is no longer specific to a target type. The reason for this is that we want to be able to safely convert e.g. WeakPtr<T> to WeakPtr<U>, and before this we just reinterpret_cast the internal WeakLink<T> to WeakLink<U>, which is a bold assumption that it would actually produce the correct code. Instead, WeakLink now operates on just a raw pointer and we only make those constructors/operators available if we can verify that it can be safely cast. In order to guarantee thread safety, we now use the least significant bit in the pointer for locking purposes. This also means that only properly aligned pointers can be used.
2020-09-13Kernel: Make copy_to/from_user safe and remove unnecessary checksTom
Since the CPU already does almost all necessary validation steps for us, we don't really need to attempt to do this. Doing it ourselves doesn't really work very reliably, because we'd have to account for other processors modifying virtual memory, and we'd have to account for e.g. pages not being able to be allocated due to insufficient resources. So change the copy_to/from_user (and associated helper functions) to use the new safe_memcpy, which will return whether it succeeded or not. The only manual validation step needed (which the CPU can't perform for us) is making sure the pointers provided by user mode aren't pointing to kernel mappings. To make it easier to read/write from/to either kernel or user mode data add the UserOrKernelBuffer helper class, which will internally either use copy_from/to_user or directly memcpy, or pass the data through directly using a temporary buffer on the stack. Last but not least we need to keep syscall params trivial as we need to copy them from/to user mode using copy_from/to_user.
2020-09-06Kernel: Make File weakableAndreas Kling
This will be useful for some things. This also removes the need for TCPSocket to be special about this.
2020-08-04Kernel: Make File::write() and File::read() return KResultOr<size_t>Andreas Kling
Instead of returning a ssize_t where negative values mean error, we now return KResultOr<size_t> and use the error state to report errors exclusively.
2020-06-02Kernel: Allow File::close() to failSergey Bugaev
And pass the result through to sys$close() return value. Fixes https://github.com/SerenityOS/serenity/issues/427
2020-04-18Kernel: Use shared locking mode in some placesSergey Bugaev
The notable piece of code that remains to be converted is Ext2FS.
2020-02-16Kernel: Move all code into the Kernel namespaceAndreas Kling
2020-02-08IPv4: Basic implementation of TCP socket shutdownAndreas Kling
We can now participate in the TCP connection closing handshake. :^) This implementation is definitely not complete and needs to handle a bunch of other cases. But it's a huge improvement over not being able to close connections at all. Note that we hold on to pending-close sockets indefinitely, until they are moved into the Closed state. This should also have a timeout but that's still a FIXME. :^) Fixes #428.
2020-02-08IPv4: Send TCP packets right away instead of waiting to "retry"Andreas Kling
Also be more explicit about zero-initializing OutgoingPacket objects.
2020-02-08Net: Make NetworkAdapter reference-countedAndreas Kling
The idea behind WeakPtr<NetworkAdapter> was to support hot-pluggable network adapters, but on closer thought, that's super impractical so let's not go down that road.
2020-01-29Kernel: Make IPv4Socket::protocol_send() use a size_t for buffer sizeAndreas Kling
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2019-11-23IPv4: Protect the list of unacked TCP packets with a lockAndreas Kling
Otherwise things get racy and crashy.