summaryrefslogtreecommitdiff
path: root/Kernel/Net/IPv4Socket.h
AgeCommit message (Collapse)Author
2022-04-01Everywhere: Run clang-formatIdan Horowitz
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.
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-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-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-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-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: 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: 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-08-22Kernel: Rename ProtectedValue<T> => MutexProtected<T>Andreas Kling
Let's make it obvious what we're protecting it with.
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-07Kernel: Migrate IPv4 socket table locking to ProtectedValueJean-Baptiste Boric
2021-08-07Kernel: Move Lockable into its own headerJean-Baptiste Boric
2021-08-07Kernel: Move Mutex into Locking/Jean-Baptiste Boric
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-07-27Kernel: Modify the IOCTL API to return KResultBrian Gianforcaro
The kernel has been gradually moving towards KResult from just bare int's, this change migrates the IOCTL paths.
2021-07-27Kernel: Utilize AK::Userspace<T> in the ioctl interfaceBrian Gianforcaro
It's easy to forget the responsibility of validating and safely copying kernel parameters in code that is far away from syscalls. ioctl's are one such example, and bugs there are just as dangerous as at the root syscall level. To avoid this case, utilize the AK::Userspace<T> template in the ioctl kernel interface so that implementors have no choice but to properly validate and copy ioctl pointer arguments.
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-12Kernel: Avoid allocating KBuffers for TCP packetsGunnar Beutner
This avoids allocating a KBuffer for each incoming TCP packet.
2021-05-12Kernel: Increase IPv4 buffer size to 256kBGunnar Beutner
This increases the buffer size for connection-oriented sockets to 256kB. In combination with the other patches in this series I was able to receive TCP packets at a rate of about 120Mbps.
2021-05-05Kernel: Implement IP multicast supportSergey Bugaev
An IP socket can now join a multicast group by using the IP_ADD_MEMBERSHIP sockopt, which will cause it to start receiving packets sent to the multicast address, even though this address does not belong to this host.
2021-04-30Kernel: Fix bogus error codes from raw socket protocol_{send,receive}Andreas Kling
Since these return KResultOr, we should not negate the error code.
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-03Kernel: Improve ProcFS behavior in low memory conditionsTom
When ProcFS could no longer allocate KBuffer objects to serve calls to read, it would just return 0, indicating EOF. This then triggered parsing errors because code assumed it read the file. Because read isn't supposed to return ENOMEM, change ProcFS to populate the file data upon file open or seek to the beginning. This also means that calls to open can now return ENOMEM if needed. This allows the caller to either be able to successfully open the file and read it, or fail to open it in the first place.
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-30Kernel: Move block condition evaluation out of the SchedulerTom
This makes the Scheduler a lot leaner by not having to evaluate block conditions every time it is invoked. Instead evaluate them as the states change, and unblock threads at that point. This also implements some more waitid/waitpid/wait features and behavior. For example, WUNTRACED and WNOWAIT are now supported. And wait will now not return EINTR when SIGCHLD is delivered at the same time.
2020-09-17Kernel: Plumb packet receive timestamp from NetworkAdapter to Socket::recvfromNico Weber
Since the receiving socket isn't yet known at packet receive time, keep timestamps for all packets. This is useful for keeping statistics about in-kernel queue latencies in the future, and it can be used to implement SO_TIMESTAMP.
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-08-19Kernel: Use Userspace<T> for the recvfrom syscall, and Socket implementationBrian Gianforcaro
This fixes a bunch of unchecked kernel reads and writes, seems like they would might exploitable :). Write of sockaddr_in size to any address you please...
2020-08-19Kernel: Use Userspace<T> for the sendto syscall, and Socket implementationBrian Gianforcaro
Note that the data member is of type ImmutableBufferArgument, which has no Userspace<T> usage. I left it alone for now, to be fixed in a future change holistically for all usages.
2020-08-10Kernel: Use Userspace<T> for the bind syscall, and implementationBrian Gianforcaro
2020-08-07Kernel: Use Userspace<T> for the getsockopt syscall and Socket interfaceBrian Gianforcaro
The way getsockopt is implemented for socket types requires us to push down Userspace<T> using into those interfaces. This change does so, and utilizes proper copy implementations instead of the kind of haphazard pointer dereferencing that was occurring there before.
2020-08-07Kernel: Use Userspace<T> for the setsockopt syscallBrian Gianforcaro
2020-08-05Kernel: Switch IPv4Socket receive queue to SinglyLinkedListWithCount<T>Brian Gianforcaro
Avoid walking the packet queue, instead use a linked list with a count.
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-05-23Kernel: Use a FlatPtr for the "argument" to ioctl()Andreas Kling
Since it's often used to pass pointers, it should really be a FlatPtr.
2020-04-10Kernel: Add explicit offset parameter to File::read etcConrad Pankoff
2020-02-25AK: Make Vector use size_t for its size and capacityAndreas Kling
2020-02-16Kernel: Move all code into the Kernel namespaceAndreas Kling
2020-02-08IPv4: Sockets should say can_read() after reading is shut downAndreas Kling
This allows clients to get their EOF after shutting down reading.