summaryrefslogtreecommitdiff
path: root/Kernel/Net/IPv4Socket.cpp
AgeCommit message (Collapse)Author
2022-05-26Kernel: Add support for route flagsbrapru
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-04-30Kernel+route: Support global routing table deletionbrapru
2022-04-28Kernel: Add a global routing tablebrapru
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-28Kernel: Generalize the UpdateArp table to UpdateTablebrapru
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-01Everywhere: Run clang-formatIdan Horowitz
2022-02-18Kernel: Lock socket Mutex when servicing IPv4Socket ioctlsIdan Horowitz
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-01-25Kernel: Use u64 instead of size_t for File::can_write offsetIdan Horowitz
This ensures offsets will not be truncated on large files on i686.
2022-01-25Kernel: Use u64 instead of size_t for File::can_read offsetIdan Horowitz
This ensures offsets will not be truncated on large files on i686.
2022-01-09Kernel: Harden Socket::pseudo_path(..) implementations against OOMBrian Gianforcaro
Use the try variants of AK::StringBuilder append APIs to harden these functions against OOM.
2021-12-30Kernel+AK: Eliminate a couple of temporary String allocationsDaniel Bertalan
2021-12-29Kernel: Handle promise violations in the syscall handlerBrian Gianforcaro
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-29Kernel: Use Process::require_promise() instead of REQUIRE_PROMISE()Brian Gianforcaro
This change lays the foundation for making the require_promise return an error hand handling the process abort outside of the syscall implementations, to avoid cases where we would leak resources. It also has the advantage that it makes removes a gs pointer read to look up the current thread, then process for every syscall. We can instead go through the Process this pointer in most cases.
2021-12-28Kernel: Lock socket mutex across {get,set}sockopt() and SO_ERROR updatesAndreas Kling
Since a socket can be accessed by multiple threads concurrently, we need to protect shared data behind the socket mutex. There's very likely more places where we need to fix this, the purpose of this patch is to fix a VERIFY() failure in getsockopt() seen on CI.
2021-12-22Kernel: Define and return the ARPHRD_* device type in SIOCGIFHWADDRIdan Horowitz
The sa_family field in SIOCGIFHWADDR specifies the underlying network interface's device type, this is hardcoded to generic "Ethernet" right now, as we don't have a nice way to query it.
2021-12-16Kernel+LibC: Move errno definitions to Kernel/API/POSIXsin-ack
This fixes at least half of our LibC includes in the kernel. The source of truth for errno codes and their description strings now lives in Kernel/API/POSIX/errno.h as an enumeration, which LibC includes.
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-12-05Kernel: Implement the SO_DONTROUTE SOL_SOCKET-level optionIdan Horowitz
2021-12-05Kernel: Add support for the MSG_WAITALL sys$recvmsg flagIdan Horowitz
2021-12-05Kernel: Add support for the MSG_DONTROUTE sys$sendmsg flagIdan Horowitz
2021-11-16Kernel: Use static_ptr_cast to convert between Userspace<T*> typesAndrew Kaster
Some calls of copy_to_user were converting Userspace<T*> to Userspace<U*> via the implicit conversion to FlatPtr. Change them to use the static_ptr_cast overload that is designed to express this conversion
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-31Kernel: Clarify ambiguous {File,Description}::absolute_pathBen Wiederhake
Found due to smelly code in InodeFile::absolute_path. In particular, this replaces the following misleading methods: File::absolute_path This method *never* returns an actual path, and if called on an InodeFile (which is impossible), it would VERIFY_NOT_REACHED(). OpenFileDescription::try_serialize_absolute_path OpenFileDescription::absolute_path These methods do not guarantee to return an actual path (just like the other method), and just like Custody::absolute_path they do not guarantee accuracy. In particular, just renaming the method made a TOCTOU bug obvious. The new method signatures use KResultOr, just like try_serialize_absolute_path() already did.
2021-10-28Kernel+LibC: Add support for the IPv4 TOS field via the IP_TOS sockoptIdan Horowitz
2021-10-28Kernel: Fix accidental memory over-read in getsockopt(IP_TTL)Idan Horowitz
We were accidentally casting the pointer to m_ttl from an u8* to an int* which resulted in copying of 3 extra unrelated bytes (which turned out to be padding in this case).
2021-09-16Kernel: Drop the receive buffer when socket enters the TimeWait statesin-ack
The TimeWait state is intended to prevent another socket from taking the address tuple in case any packets are still in transit after the final close. Since this state never delivers packets to userspace, it doesn't make sense to keep the receive buffer around.
2021-09-10Kernel: Fix null dereference in IPv4Socket::receive_packet_buffered()Andreas Kling
This was a mistake in the move away from KBuffer-as-a-value type. We need to check `packet` here, not `packet->data`. Regressed in b300f9aa2fd11796e63b5029008b33a1ae735928. Fixes #9888.
2021-09-08Kernel: Add KBuffer::bytes() and use itAndreas Kling
(Instead of hand-wrapping { data(), size() } in a bunch of places.)
2021-09-07Kernel: Remove KBuffer::try_copy() in favor of try_create_with_bytes()Andreas Kling
These were already equivalent, so let's only have one of them.
2021-09-07Kernel: Convert KBuffer::copy() => KBuffer::try_copy()Andreas Kling
This was a weird KBuffer API that assumed failure was impossible. This patch converts it to a modern KResultOr<NonnullOwnPtr<KBuffer>> API and updates the two clients to the new style.
2021-09-07Kernel/Net: Add a special SOCKET_TRY() and use it in socket codeAndreas Kling
Sockets remember their last error code in the SO_ERROR field, so we need to take special care to remember this when returning an error. This patch adds a SOCKET_TRY() that works like TRY() but also calls set_so_error() on the failure path. There's probably a lot more code that should be using this, but that's outside the scope of this patch.
2021-09-07Kernel: Make DoubleBuffer::try() return KResultOrAndreas Kling
This tidies up error propagation in a number of places.
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-07Kernel: Make UserOrKernelBuffer return KResult from read/write/memsetAndreas Kling
This allows us to simplify a whole bunch of call sites with TRY(). :^)
2021-09-05Kernel: Make copy_{from,to}_user() return KResult and use TRY()Andreas Kling
This makes EFAULT propagation flow much more naturally. :^)
2021-09-05Kernel: Use TRY() in IPv4SocketAndreas Kling
2021-09-04Kernel: Tidy up UDPSocket creation a bitAndreas Kling
- Rename create() => try_create() - Use adopt_nonnull_ref_or_enomem()
2021-09-04Kernel: Tidy up TCPSocket creation a bitAndreas Kling
- Rename create() => try_create() - Use adopt_nonnull_ref_or_enomem()
2021-08-29Kernel: Rename Socket::lock() => Socket::mutex()Andreas Kling
"lock" is ambiguous (verb vs noun) while "mutex" is not.
2021-08-29Kernel: Add Socket::set_role() and use it everywhereAndreas Kling
Instead of having Socket subclasses write their role into Socket::m_role directly, add a setter to do this.
2021-08-22Kernel+LibC: Implement FIONREAD ioctlPeter Elliott
FIONREAD gets the number of bytes availible to read from a file descriptor without blocking. I only implemented it for regular files and sockets
2021-08-22Kernel: Rename ProtectedValue<T> => MutexProtected<T>Andreas Kling
Let's make it obvious what we're protecting it with.
2021-08-19Kernel: Make Process::current() return a Process& instead of Process*Idan Horowitz
This has several benefits: 1) We no longer just blindly derefence a null pointer in various places 2) We will get nicer runtime error messages if the current process does turn out to be null in the call location 3) GCC no longer complains about possible nullptr dereferences when compiling without KUBSAN
2021-08-15Kernel: Convert IPv4 socket list from HashTable to IntrusiveListAndreas Kling
There was no reason whatsoever to use a HashTable here. IntrusiveList removes all the heap allocations and does everything more efficiently.
2021-08-14Kernel: Stop allowing implicit conversion from KResult to intAndreas Kling
This patch removes KResult::operator int() and deals with the fallout. This forces a lot of code to be more explicit in its handling of errors, greatly improving readability.
2021-08-13Kernel: Remove char* versions of path argument / kstring copy methodsBrian Gianforcaro
The only two paths for copying strings in the kernel should be going through the existing Userspace<char const*>, or StringArgument methods. Lets enforce this by removing the option for using the raw cstring APIs that were previously available.
2021-08-10Kernel: Add so_error to keep track of the socket's error statebrapru
This sets the m_so_error variable every time the socket returns an error.
2021-08-08Everywhere: Replace AK::Singleton => SingletonAndreas Kling
2021-08-07Kernel: Migrate IPv4 socket table locking to ProtectedValueJean-Baptiste Boric
2021-08-06Kernel: Fix handful of remaining "return -EFOO" mistakesAndreas Kling
Now that all KResult and KResultOr are used consistently throughout the kernel, it's no longer necessary to return negative error codes. However, we were still doing that in some places, so let's fix all those (bugs) by removing the minuses. :^)
2021-08-06Kernel: Use try_copy_kstring_from_user() in IPv4Socket::ioctl()Andreas Kling