summaryrefslogtreecommitdiff
path: root/Kernel/Net/IPv4Socket.cpp
AgeCommit message (Collapse)Author
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
2021-08-03Kernel: Handle OOM when allocating Packet KBuffersBrian Gianforcaro
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-25Kernel: Support ioctl SIOCSARP and SIOCDARPbrapru
Creates ioctl calls necessary to set/delete an entry from the ARP table
2021-07-18Kernel: Rename Locker => MutexLockerAndreas Kling
2021-07-07Kernel: Fix kernel crash when remote peer resets unexpectedlyngc6302h
2021-06-24Everywhere: Use nothrow new with `adopt_{ref,own}_if_nonnull`Daniel Bertalan
This commit converts naked `new`s to `AK::try_make` and `AK::try_create` wherever possible. If the called constructor is private, this can not be done, so we instead now use the standard-defined and compiler-agnostic `new (nothrow)`.
2021-06-16Kernel: Use KResultOr<size_t> for the DoubleBuffer classGunnar Beutner
2021-06-09Kernel: Introduce the NetworkingManagement singletonLiav A
Instead of initializing network adapters in init.cpp, let's move that logic into a separate class to handle this. Also, it seems like a good idea to shift responsiblity on enumeration of network adapters after the boot process, so this singleton will take care of finding the appropriate network adapter when asked to with an IPv4 address or interface name. With this change being merged, we simplify the creation logic of NetworkAdapter derived classes, so we enumerate the PCI bus only once, searching for driver candidates when doing so, and we let each driver to test if it is resposible for the specified PCI device.
2021-06-05Kernel: Return EPIPE when trying to write to an unconnected socketGunnar Beutner
When attempting to write to a socket that is not connected or - for connection-less protocols - doesn't have a peer address set we should return EPIPE instead of blocking the thread.
2021-06-04Kernel: Make sure we increment the TX counterGunnar Beutner
This was broken by b436dd1.
2021-06-01Kernel: Dont try to register ephemeral TCP ports twicestelar7
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-13Kernel: Make UDPSocket::create() API OOM safeBrian Gianforcaro
2021-05-13Kernel: Make IPv4Socket::create API for SOCK_RAW OOM safeBrian 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: Outbound packets should use the source address from the socketGunnar Beutner
Previously we'd use the adapter's address as the source address when sending packets. Instead we should use the socket's bound local address.
2021-05-12Kernel: Treat 0.0.0.0 as a loopback addressGunnar Beutner
This matches what other operating systems like Linux do: $ ip route get 0.0.0.0 local 0.0.0.0 dev lo src 127.0.0.1 uid 1000 cache <local> $ ssh 0.0.0.0 gunnar@0.0.0.0's password: $ ss -na | grep :22 | grep ESTAB tcp ESTAB 0 0 127.0.0.1:43118 127.0.0.1:22 tcp ESTAB 0 0 127.0.0.1:22 127.0.0.1:43118
2021-05-12Kernel: Avoid allocating KBuffers for TCP packetsGunnar Beutner
This avoids allocating a KBuffer for each incoming TCP packet.
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-05-01Kernel/IPv4: Unbreak raw socket (port allocation failing is OK)Andreas Kling
Raw sockets don't need a local port, so we shouldn't fail operations if allocation yields an ENOPROTOOPT. I'm not in love with the factoring here, just patching up the bug.
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.