summaryrefslogtreecommitdiff
path: root/Kernel/Net/IPv4Socket.h
AgeCommit message (Collapse)Author
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.
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: Split IPv4Socket::recvfrom() into packet/byte buffered functionsAndreas Kling
This code was really hard to follow since it handles two separate modes of buffering the data.
2020-02-07Kernel: Truncate addresses stored by getsockname() and getpeername()Andreas Kling
If there's not enough space in the output buffer for the whole sockaddr we now simply truncate the address instead of returning EINVAL. This patch also makes getpeername() actually return the peer address rather than the local address.. :^)
2020-01-29Kernel: Make IPv4Socket::protocol_send() use a size_t for buffer sizeAndreas Kling
2020-01-23Kernel: Allow Socket subclasses to fail constructionAndreas Kling
For example, socket(AF_INET) should only succeed for valid SOCK_TYPEs.
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-12-14IPv4: Only buffer payload bytes for SOCK_STREAM socketsAndreas Kling
Since stream sockets don't actually need to deliver packets-at-a-time data in recvfrom(), they can just buffer the payload bytes instead. This avoids keeping one KBuffer per incoming packet in the receive queue, which was a big performance issue in ProtocolServer. This code is definitely not perfect and is something we should keep improving over time.
2019-12-06Kernel: Add getsockopt(SO_PEERCRED) for local socketsAndreas Kling
This sockopt gives you a struct with the PID, UID and GID of a socket's peer process.
2019-11-04Kernel: Make File's can_read/can_write take a const FileDescription&Andreas Kling
Asking a File if we could possibly read or write it will never mutate the asking FileDescription&, so it should be const.
2019-09-23IPv4: Implement socket ioctls SIOCGIFADDR and SIOCSIFADDRAndreas Kling
This allows userspace programs to get and set (superuser-only) the IPv4 address of a network adapter. :^)
2019-09-19IPv4: Support overriding the default TTL (64)Andreas Kling
Made getsockopt() and setsockopt() virtual so we can handle them in the various Socket subclasses. The subclasses map kinda nicely to "levels". This will allow us to implement things like "traceroute", although.. I spent some time trying to do that, but then hit a wall when it turned out that the user-mode networking in QEMU doesn't preserve TTL in the ICMP packets passing through.
2019-08-11Kernel: Customize absolute_path() for more file typesSergey Bugaev
2019-08-09Kernel: Merge FooSocketHandle classes into a single SocketHandle<Foo>Andreas Kling
- IPv4SocketHandle => SocketHandle<IPv4Socket> - TCPSocketHandle => SocketHandle<TCPSocket> - UDPSocketHandle => SocketHandle<UDPSocket>