summaryrefslogtreecommitdiff
path: root/Kernel/Net/Routing.cpp
AgeCommit message (Collapse)Author
2023-06-04Kernel: Move all tasks-related code to the Tasks subdirectoryLiav A
2023-04-14Kernel/Net: Iron out the locking mechanism across the subsystemLiav A
There is a big mix of LockRefPtrs all over the Networking subsystem, as well as lots of room for improvements with our locking patterns, which this commit will not pursue, but will give a good start for such work. To deal with this situation, we change the following things: - Creating instances of NetworkAdapter should always yield a non-locking NonnullRefPtr. Acquiring an instance from the NetworkingManagement should give a simple RefPtr,as giving LockRefPtr does not really protect from concurrency problems in such case. - Since NetworkingManagement works with normal RefPtrs we should protect all instances of RefPtr<NetworkAdapter> with SpinlockProtected to ensure references are gone unexpectedly. - Protect the so_error class member with a proper spinlock. This happens to be important because the clear_so_error() method lacked any proper locking measures. It also helps preventing a possible TOCTOU when we might do a more fine-grained locking in the Socket code, so this could be definitely a start for this. - Change unnecessary LockRefPtr<PacketWithTimestamp> in the structure of OutgoingPacket to a simple RefPtr<PacketWithTimestamp> as the whole list should be MutexProtected.
2023-01-02Kernel: Turn lock ranks into template parameterskleines Filmröllchen
This step would ideally not have been necessary (increases amount of refactoring and templates necessary, which in turn increases build times), but it gives us a couple of nice properties: - SpinlockProtected inside Singleton (a very common combination) can now obtain any lock rank just via the template parameter. It was not previously possible to do this with SingletonInstanceCreator magic. - SpinlockProtected's lock rank is now mandatory; this is the majority of cases and allows us to see where we're still missing proper ranks. - The type already informs us what lock rank a lock has, which aids code readability and (possibly, if gdb cooperates) lock mismatch debugging. - The rank of a lock can no longer be dynamic, which is not something we wanted in the first place (or made use of). Locks randomly changing their rank sounds like a disaster waiting to happen. - In some places, we might be able to statically check that locks are taken in the right order (with the right lock rank checking implementation) as rank information is fully statically known. This refactoring even more exposes the fact that Mutex has no lock rank capabilites, which is not fixed here.
2022-08-20Kernel: Make self-contained locking smart pointers their own classesAndreas Kling
Until now, our kernel has reimplemented a number of AK classes to provide automatic internal locking: - RefPtr - NonnullRefPtr - WeakPtr - Weakable This patch renames the Kernel classes so that they can coexist with the original AK classes: - RefPtr => LockRefPtr - NonnullRefPtr => NonnullLockRefPtr - WeakPtr => LockWeakPtr - Weakable => LockWeakable The goal here is to eventually get rid of the Lock* classes in favor of using external locking.
2022-07-09Kernel/Routing: Hide some leftover debugging under a debug flagMaciej
2022-07-09Kernel/Net: Support removing route entries with unknown gatewayMaciej
If you specify gateway as 0.0.0.0, the SIOCDELRT ioctl will remove all route entries that match all the other arguments.
2022-07-04Kernel: Negate condition in ARPTableBlockerSet::should_add_blockerIdan Horowitz
To prevent a race condition in case we received the ARP response in the window between creating and initializing the Thread Blocker and the actual blocking, we were checking if the IP address was updated in the ARP table just before starting to block. Unfortunately, the condition was partially flipped, which meant that if the table was updated with the IP address we would still end up blocking, at which point we would never end unblocking again, which would result in LookupServer locking up as well.
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-03Kernel: Protect ARP table with spinlock instead of mutexAndreas Kling
2021-12-05Kernel: Add support for the MSG_DONTROUTE sys$sendmsg flagIdan Horowitz
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-03Kernel: Convert Routing to east-const stylebrapru
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 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: Rename ScopedSpinlock => SpinlockLockerAndreas Kling
This matches MutexLocker, and doesn't sound like it's a lock itself.
2021-08-22Kernel: Rename SpinLock => SpinlockAndreas Kling
2021-08-22Kernel: Rename ProtectedValue<T> => MutexProtected<T>Andreas Kling
Let's make it obvious what we're protecting it with.
2021-08-15Kernel: Move ARP debug information to ARP_DEBUGbrapru
Previously when trying to debug the system's routing, the ARP information would clutter the output and make it difficult to focus on the routing decisions. It would be better to specify these debug messages under ARP_DEBUG.
2021-08-08Everywhere: Replace AK::Singleton => SingletonAndreas Kling
2021-08-07Kernel: Migrate ARP table locking to ProtectedValueJean-Baptiste Boric
2021-08-06Kernel: Make Thread::state_string() return StringViewAndreas Kling
2021-07-25Kernel: Add update option to remove an entry from the ARP tablebrapru
Allows for specifying whether to set/delete an entry from the table.
2021-07-18Kernel: Rename Locker => MutexLockerAndreas Kling
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-05-21Kernel: Ignore interfaces without an IP address when routing packagesGunnar Beutner
Let's not route packages through interfaces which don't have an address yet unless we're explicitly asked to (e.g. by DHCPClient).
2021-05-12Kernel: Route packets destined for us through the loopback adapterGunnar Beutner
Without this patch we'd send packets through the physical adapter and they'd incorrectly end up on the network.
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-10Kernel: Use correct destination MAC address for multicast packetsGunnar Beutner
Previously we'd incorrectly use the default gateway's MAC address. Instead we must use destination MAC addresses that are derived from the multicast IPv4 address. With this patch applied I can query mDNS on a real network.
2021-04-30Kernel: Avoid deadlock when trying to send packets from the NetworkTaskGunnar Beutner
fixes #6758
2021-04-27Kernel: Silence a few more network dbgln()sGunnar Beutner
2021-04-25Kernel: Remove the now defunct `LOCKER(..)` macro.Brian Gianforcaro
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-09Kernel: Convert klog() => dmesgln() in ARP/routing codeAndreas Kling
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-17Kernel: Don't go through ARP for IP broadcast messagesAnotherTest
2021-01-26Meta: Split debug defines into multiple headers.asynts
The following script was used to make these changes: #!/bin/bash set -e tmp=$(mktemp -d) echo "tmp=$tmp" find Kernel \( -name '*.cpp' -o -name '*.h' \) | sort > $tmp/Kernel.files find . \( -path ./Toolchain -prune -o -path ./Build -prune -o -path ./Kernel -prune \) -o \( -name '*.cpp' -o -name '*.h' \) -print | sort > $tmp/EverythingExceptKernel.files cat $tmp/Kernel.files | xargs grep -Eho '[A-Z0-9_]+_DEBUG' | sort | uniq > $tmp/Kernel.macros cat $tmp/EverythingExceptKernel.files | xargs grep -Eho '[A-Z0-9_]+_DEBUG' | sort | uniq > $tmp/EverythingExceptKernel.macros comm -23 $tmp/Kernel.macros $tmp/EverythingExceptKernel.macros > $tmp/Kernel.unique comm -1 $tmp/Kernel.macros $tmp/EverythingExceptKernel.macros > $tmp/EverythingExceptKernel.unique cat $tmp/Kernel.unique | awk '{ print "#cmakedefine01 "$1 }' > $tmp/Kernel.header cat $tmp/EverythingExceptKernel.unique | awk '{ print "#cmakedefine01 "$1 }' > $tmp/EverythingExceptKernel.header for macro in $(cat $tmp/Kernel.unique) do cat $tmp/Kernel.files | xargs grep -l $macro >> $tmp/Kernel.new-includes ||: done cat $tmp/Kernel.new-includes | sort > $tmp/Kernel.new-includes.sorted for macro in $(cat $tmp/EverythingExceptKernel.unique) do cat $tmp/Kernel.files | xargs grep -l $macro >> $tmp/Kernel.old-includes ||: done cat $tmp/Kernel.old-includes | sort > $tmp/Kernel.old-includes.sorted comm -23 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.new comm -13 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.old comm -12 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.mixed for file in $(cat $tmp/Kernel.includes.new) do sed -i -E 's/#include <AK\/Debug\.h>/#include <Kernel\/Debug\.h>/' $file done for file in $(cat $tmp/Kernel.includes.mixed) do echo "mixed include in $file, requires manual editing." done
2021-01-25Everywhere: Hook up remaining debug macros to Debug.h.asynts
2021-01-25Everywhere: Remove unnecessary debug comments.asynts
It would be tempting to uncomment these statements, but that won't work with the new changes. This was done with the following commands: find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/#define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/#define/ { toggle = 1 }' {} \; find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/ #define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/ #define/ { toggle = 1 }' {} \;
2021-01-12AK: Simplify constructors and conversions from nullptr_tLenny Maiorani
Problem: - Many constructors are defined as `{}` rather than using the ` = default` compiler-provided constructor. - Some types provide an implicit conversion operator from `nullptr_t` instead of requiring the caller to default construct. This violates the C++ Core Guidelines suggestion to declare single-argument constructors explicit (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit). Solution: - Change default constructors to use the compiler-provided default constructor. - Remove implicit conversion operators from `nullptr_t` and change usage to enforce type consistency without conversion.