summaryrefslogtreecommitdiff
path: root/Kernel/Net
AgeCommit message (Collapse)Author
2021-09-07Kernel: TCPSocket always has a scratch bufferAndreas Kling
Let's encode this in the constructor signature.
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: Use TRY() some more in SocketAndreas Kling
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: 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: Store process names as KStringAndreas Kling
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-07Kernel/PCI: Simplify the entire subsystemLiav A
A couple of things were changed: 1. Semantic changes - PCI segments are now called PCI domains, to better match what they are really. It's also the name that Linux gave, and it seems that Wikipedia also uses this name. We also remove PCI::ChangeableAddress, because it was used in the past but now it's no longer being used. 2. There are no WindowedMMIOAccess or MMIOAccess classes anymore, as they made a bunch of unnecessary complexity. Instead, Windowed access is removed entirely (this was tested, but never was benchmarked), so we are left with IO access and memory access options. The memory access option is essentially mapping the PCI bus (from the chosen PCI domain), to virtual memory as-is. This means that unless needed, at any time, there is only one PCI bus being mapped, and this is changed if access to another PCI bus in the same PCI domain is needed. For now, we don't support mapping of different PCI buses from different PCI domains at the same time, because basically it's still a non-issue for most machines out there. 2. OOM-safety is increased, especially when constructing the Access object. It means that we pre-allocating any needed resources, and we try to find PCI domains (if requested to initialize memory access) after we attempt to construct the Access object, so it's possible to fail at this point "gracefully". 3. All PCI API functions are now separated into a different header file, which means only "clients" of the PCI subsystem API will need to include that header file. 4. Functional changes - we only allow now to enumerate the bus after a hardware scan. This means that the old method "enumerate_hardware" is removed, so, when initializing an Access object, the initializing function must call rescan on it to force it to find devices. This makes it possible to fail rescan, and also to defer it after construction from both OOM-safety terms and hotplug capabilities.
2021-09-07Kernel: Avoid string creation for simple string comparisonBrian Gianforcaro
2021-09-07Kernel: Make copy_time_from_user() helpers use KResultOr<Time>Andreas Kling
...and use TRY() for smooth error propagation everywhere.
2021-09-06Kernel: Use TRY() once more in LocalSocket::try_create_connected_pair()Andreas Kling
2021-09-06Kernel: Make KString factories return KResultOr + use TRY() everywhereAndreas Kling
There are a number of places that don't have an error propagation path right now, so I've added FIXME's about that.
2021-09-06Kernel: Make kernel region allocators return KResultOr<NOP<Region>>Andreas Kling
This expands the reach of error propagation greatly throughout the kernel. Sadly, it also exposes the fact that we're allocating (and doing other fallible things) in constructors all over the place. This patch doesn't attempt to address that of course. That's work for our future selves.
2021-09-06Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safeAli Mohammad Pur
2021-09-05Kernel: Switch static_asserts of a type size to AK::AssertSizeBrian Gianforcaro
This will provide better debug ability when the size comparison fails.
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 TCPSocketAndreas Kling
2021-09-05Kernel: Use TRY() in IPv4SocketAndreas Kling
2021-09-05Kernel: Use TRY() in LocalSocketAndreas Kling
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-05Kernel: Improve names in the ARP table thread blockerAndreas Kling
More instances of functions named "unblock()" that don't actually unblock in all cases being renamed to something more precise.
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-09-03Kernel: Convert Routing to east-const stylebrapru
2021-09-01Kernel: Don't cast to NetworkOrdered<u16>* from random dataBrian Gianforcaro
NetworkOrdered is a non trivial type, and it's undefined behavior to cast a random pointer to it and then pretend it's that type. Instead just call AK::convert_between_host_and_network_endian on the individual u16*. This suppresses static analysis warnings. I don't think there was a "bug" in the previous code, it worked, but it was very brittle.
2021-08-31Kernel: Don't VERIFY_NOT_REACHED in LocalSocket::has_attached_peer()Owen Smith
Invoking sendmsg on a listening socket triggers this assertion as sendto calls has_attached_peer before checking the result of send_buffer_for.
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-29Kernel: Store LocalSocket address as a KString internallyAndreas Kling
Just because we deal with sockaddr_un at the userspace API layer doesn't mean we have to store an awkward C type internally. :^)
2021-08-29Kernel: Rename LocalSocket::create_connected_pair() => try_*()Andreas Kling
2021-08-29Kernel: Encapsulate assignment of socket origin/acceptor credentialsAndreas Kling
2021-08-29Kernel: Rename LocalSocket factory to try_create() & tighten return typeAndreas Kling
Also tighten the return type to KResultOr<NonnullRefPtr<LocalSocket>> since it cannot return any other socket type.
2021-08-29Kernel: Use ProcessID a bit more in SocketAndreas Kling
Store the origin and acceptor PID's as ProcessID.
2021-08-29Kernel: Strongly typed user & group ID'sAndreas Kling
Prior to this change, both uid_t and gid_t were typedef'ed to `u32`. This made it easy to use them interchangeably. Let's not allow that. This patch adds UserID and GroupID using the AK::DistinctNumeric mechanism we've already been employing for pid_t/ProcessID.
2021-08-29Kernel: Rename FileDescription::create() => try_create()Andreas Kling
2021-08-24Kernel: Simplify Blockers so they don't need a "should block" flagAndreas Kling
The `m_should_block` member variable that many of the Thread::Blocker subclasses had was really only used to carry state from the constructor to the immediate-unblock-without-blocking escape hatch. This patch refactors the blockers so that we don't need to hold on to this flag after setup_blocker(), and instead the return value from setup_blocker() is the authority on whether the unblock conditions are already met.
2021-08-24Kernel: Remove unused Thread::Blocker::should_block() virtualAndreas Kling
This was previously used after construction to check for early unblock conditions that couldn't be communicated from the constructor. Now that we've moved early unblock checks from the constructor into setup_blocker(), we don't need should_block() anymore.
2021-08-24Kernel: Move Blocker setup out from constructors into setup_blocker()Andreas Kling
Instead of registering with blocker sets and whatnot in the various Blocker subclass constructors, this patch moves such initialization to a separate setup_blocker() virtual. setup_blocker() returns false if there's no need to actually block the thread. This allows us to bail earlier in Thread::block().
2021-08-23Kernel: Rename Blocker::not_blocking(bool) to something more descriptiveAndreas Kling
Namely, will_unblock_immediately_without_blocking(Reason). This virtual function is called on a blocker *before any block occurs*, if it turns out that we don't need to block the thread after all. This can happens for one of two reasons: - UnblockImmediatelyReason::UnblockConditionAlreadyMet We don't need to block the thread because the condition for unblocking it is already met. - UnblockImmediatelyReason::TimeoutInThePast We don't need to block the thread because a timeout was specified and that timeout is already in the past. This patch does not introduce any behavior changes, it's only meant to clarify this part of the blocking logic.
2021-08-23Kernel: Rename some BlockerSets to foo_blocker_setAndreas Kling
Cleanup after renaming BlockCondition to BlockerSet.
2021-08-23Kernel: Rename PCI::DeviceController => PCI::DeviceLiav A
Now that the old PCI::Device was removed, we can complete the PCI changes by making the PCI::DeviceController to be named PCI::Device. Really the entire purpose and the distinction between the two was about interrupts, but since this is no longer a problem, just rename it to simplify things further.
2021-08-23Kernel/PCI: Delete PCI::Device in its current formLiav A
I created this class a long time ago just to be able to quickly make a PCI device to also represent an interrupt handler (because PCI devices have this capability for most devices). Then after a while I introduced the PCI::DeviceController, which is really almost the same thing (a PCI device class that has Address member in it), but is not tied to interrupts so it can have no interrupts, or spawn interrupt handlers however it wants to seems fit. However I decided it's time to say goodbye for this class for a couple of reasons: 1. It made a whole bunch of weird patterns where you had a PCI::Device and a PCI::DeviceController being used in the topic of implementation, where originally, they meant to be used mutually exclusively (you can't and really don't want to use both). 2. We can really make all the classes that inherit from PCI::Device to inherit from IRQHandler at this point. Later on, when we have MSI interrupts support, we can go further and untie things even more. 3. It makes it possible to simplify the VirtIO implementation to a great extent. While this commit almost doesn't change it, future changes can untangle some complexity in the VirtIO code. For UHCIController, E1000NetworkAdapter, NE2000NetworkAdapter, RTL8139NetworkAdapter, RTL8168NetworkAdapter, E1000ENetworkAdapter we are simply making them to inherit the IRQHandler. This makes some sense, because the first 3 devices will never support anything besides IRQs. For the last 2, they might have MSI support, so when we start to utilize those, we might need to untie these classes from IRQHandler and spawn IRQHandler(s) or MSIHandler(s) as needed. The VirtIODevice class is also a case where we currently need to use both PCI::DeviceController and IRQHandler classes as parents, but it could also be untied from the latter.
2021-08-23Kernel: Rename BlockerSet::unblock() to something more accurateAndreas Kling
Namely, unblock_all_blockers_whose_conditions_are_met(). The old name made it sound like things were getting unblocked no matter what, but that's not actually the case. What this actually does is iterate through the set of blockers, unblocking those whose conditions are met. So give it a (very) verbose name that errs on the side of descriptiveness.
2021-08-23Kernel: Rename Thread::BlockCondition to BlockerSetAndreas Kling
This class represents a set of Thread::Blocker objects attached to something that those blockers are waiting on.
2021-08-23Kernel: Mark Thread::Blocker leaf subclasses finalAndreas Kling
2021-08-23Kernel: Mark BlockCondition subclasses as finalAndreas Kling
2021-08-22Kernel: Return ENOTSUP instead of panicking on invalid sockoptPeter Elliott
X11 handles this gracefully, and it makes more sense than panicking.
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 ScopedSpinlock => SpinlockLockerAndreas Kling
This matches MutexLocker, and doesn't sound like it's a lock itself.