summaryrefslogtreecommitdiff
path: root/Kernel/Net/NetworkAdapter.h
AgeCommit message (Collapse)Author
2021-04-26Kernel: Respond to packets sent to the directed broadcast addressGunnar Beutner
The last IP address in an IPv4 subnet is considered the directed broadcast address, e.g. for 192.168.3.0/24 the directed broadcast address is 192.168.3.255. We need to consider this address as belonging to the interface. Here's an example with this fix applied, SerenityOS has 192.168.3.190: [gunnar@nyx ~]$ ping -b 192.168.3.255 WARNING: pinging broadcast address PING 192.168.3.255 (192.168.3.255) 56(84) bytes of data. 64 bytes from 192.168.3.175: icmp_seq=1 ttl=64 time=0.950 ms 64 bytes from 192.168.3.188: icmp_seq=1 ttl=64 time=2.33 ms 64 bytes from 192.168.3.46: icmp_seq=1 ttl=64 time=2.77 ms 64 bytes from 192.168.3.41: icmp_seq=1 ttl=64 time=4.15 ms 64 bytes from 192.168.3.190: icmp_seq=1 ttl=64 time=29.4 ms 64 bytes from 192.168.3.42: icmp_seq=1 ttl=64 time=30.8 ms 64 bytes from 192.168.3.55: icmp_seq=1 ttl=64 time=31.0 ms 64 bytes from 192.168.3.30: icmp_seq=1 ttl=64 time=33.2 ms 64 bytes from 192.168.3.31: icmp_seq=1 ttl=64 time=33.2 ms 64 bytes from 192.168.3.173: icmp_seq=1 ttl=64 time=41.7 ms 64 bytes from 192.168.3.43: icmp_seq=1 ttl=64 time=47.7 ms ^C --- 192.168.3.255 ping statistics --- 1 packets transmitted, 1 received, +10 duplicates, 0% packet loss, time 0ms, rtt min/avg/max/mdev = 0.950/23.376/47.676/16.539 ms [gunnar@nyx ~]$
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-31Kernel: Use KResult a bit more in the IPv4 networking codeAndreas Kling
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-07-28Kernel: Use AK::Span a bunch in the network adapter codeAndreas Kling
2020-04-05Kernel+AK: Separate out MACAddress and move it into AKAnotherTest
2020-04-02Kernel: Send Fragmented IPv4 packets if payload size > mtuAnotherTest
This adds IPv4 fragmentation, so now we can send huuuuuuge packets properly.
2020-03-22Kernel: Run clang-format on filesShannon Booth
Let's rip off the band-aid
2020-02-16Kernel: Move all code into the Kernel namespaceAndreas Kling
2020-02-08Net: Make NetworkAdapter reference-countedAndreas Kling
The idea behind WeakPtr<NetworkAdapter> was to support hot-pluggable network adapters, but on closer thought, that's super impractical so let's not go down that road.
2020-01-30Kernel: Some more int => size_t in NetworkAdapter and subclassesAndreas Kling
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-14Net: Try to reuse incoming packet buffers to avoid allocation churnAndreas Kling
The majority of the time in NetworkTask was being spent in allocating and deallocating KBuffers for each incoming packet. We'll now keep up to 100 buffers around and reuse them for new packets if the next incoming packet fits in an old buffer. This is pretty naively implemented but definitely cuts down on time spent here.
2019-11-28Kernel+ifconfig: Add an MTU value to NetworkAdapterAndreas Kling
This defaults to 1500 for all adapters, but LoopbackAdapter increases it to 65536 on construction. If an IPv4 packet is larger than the MTU, we'll need to break it into smaller fragments before transmitting it. This part is a FIXME. :^)
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-29Kernel: Use a public member for NetworkAdapter on_receiveConrad Pankoff
2019-08-29Kernel: Add on_receive callback to NetworkAdapterConrad Pankoff
2019-08-29Kernel: Add netmask and gateway to NetworkAdapterConrad Pankoff
2019-08-21Kernel: Implement link status in /proc/net/adaptersConrad Pankoff
2019-08-09Kernel: Use WeakPtr<NetworkAdapter> instead of NetworkAdapter* in net codeConrad Pankoff
2019-08-08Kernel: Record network statistics and expose as JSONConrad Pankoff
This is comprised of five small changes: * Keep a counter for tx/rx packets/bytes per TCP socket * Keep a counter for tx/rx packets/bytes per network adapter * Expose that data in /proc/net_tcp and /proc/netadapters * Convert /proc/netadapters to JSON * Fix up ifconfig to read the JSON from netadapters
2019-08-05Kernel: Make KBuffer a value-type wrapper around a KBufferImplAndreas Kling
A KBuffer always contains a valid KBufferImpl. If you need a "null" state buffer, use Optional<KBuffer>. This makes KBuffer very easy to work with and pass around, just like ByteBuffer before it.
2019-08-05IPv4: Remove an unnecessary copy of each outgoing IPv4 payloadAndreas Kling
There's no need for send_ipv4() to take a ByteBuffer&&, the data is immediately cooked into a packet and transmitted. Instead, just pass it the address+length of whatever buffer we've been using locally. The more we can reduce the pressure on kmalloc the better. :^)
2019-08-04Net: Use KBuffers for network adapter packet queuesAndreas Kling
This further reduces pressure on the kmalloc heap. :^)
2019-07-14Kernel: Add Thread::block_until(Condition).Andreas Kling
Replace the class-based snooze alarm mechanism with a per-thread callback. This makes it easy to block the current thread on an arbitrary condition: void SomeDevice::wait_for_irq() { m_interrupted = false; current->block_until([this] { return m_interrupted; }); } void SomeDevice::handle_irq() { m_interrupted = true; } Use this in the SB16 driver, and in NetworkTask :^)
2019-07-03AK: Rename the common integer typedefs to make it obvious what they are.Andreas Kling
These types can be picked up by including <AK/Types.h>: * u8, u16, u32, u64 (unsigned) * i8, i16, i32, i64 (signed)
2019-06-16Kernel+Userland: Expose list of network adapters through /proc/netadapters.Andreas Kling
Added a simple /bin/ifconfig program that just pretty-prints that file. :^)
2019-05-28Add clang-format fileRobin Burchell
Also run it across the whole tree to get everything using the One True Style. We don't yet run this in an automated fashion as it's a little slow, but there is a snippet to do so in makeall.sh.
2019-04-02Kernel: Move networking related files into Kernel/Net/.Andreas Kling