Commit Graph

26 Commits

Author SHA1 Message Date
Andreas Kling
f5ac4da993 Kernel: Use AK::Span a bunch in the network adapter code 2020-07-28 20:19:22 +02:00
AnotherTest
7d0bf9b5a9 Kernel+AK: Separate out MACAddress and move it into AK 2020-04-05 09:50:48 +02:00
AnotherTest
b3d7c5d9de Kernel: Send Fragmented IPv4 packets if payload size > mtu
This adds IPv4 fragmentation, so now we can send huuuuuuge packets
properly.
2020-04-02 14:38:28 +02:00
Shannon Booth
81adefef27 Kernel: Run clang-format on files
Let's rip off the band-aid
2020-03-22 01:22:32 +01:00
Andreas Kling
a356e48150 Kernel: Move all code into the Kernel namespace 2020-02-16 01:27:42 +01:00
Andreas Kling
a3f39fe789 Net: Make NetworkAdapter reference-counted
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-02-08 00:19:46 +01:00
Andreas Kling
164d9ecad7 Kernel: Some more int => size_t in NetworkAdapter and subclasses 2020-01-30 21:51:27 +01:00
Andreas Kling
94ca55cefd Meta: Add license header to source files
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.
2020-01-18 09:45:54 +01:00
Andreas Kling
ac215ca601 Net: Try to reuse incoming packet buffers to avoid allocation churn
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-12-14 11:07:37 +01:00
Andreas Kling
75ed262fe5 Kernel+ifconfig: Add an MTU value to NetworkAdapter
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-11-28 14:14:26 +01:00
Andreas Kling
2482fc3538 IPv4: Implement socket ioctls SIOCGIFADDR and SIOCSIFADDR
This allows userspace programs to get and set (superuser-only) the IPv4
address of a network adapter. :^)
2019-09-23 19:06:03 +02:00
Andreas Kling
8cfb859368 IPv4: Support overriding the default TTL (64)
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-09-19 21:42:59 +02:00
Conrad Pankoff
498f8c01a2 Kernel: Use a public member for NetworkAdapter on_receive 2019-08-29 06:25:06 +02:00
Conrad Pankoff
36d349f7a7 Kernel: Add on_receive callback to NetworkAdapter 2019-08-29 06:25:06 +02:00
Conrad Pankoff
1aa7437ad7 Kernel: Add netmask and gateway to NetworkAdapter 2019-08-29 06:25:06 +02:00
Conrad Pankoff
286bafbb19 Kernel: Implement link status in /proc/net/adapters 2019-08-21 17:10:34 +02:00
Conrad Pankoff
54ceabd48d Kernel: Use WeakPtr<NetworkAdapter> instead of NetworkAdapter* in net code 2019-08-09 07:09:26 +02:00
Conrad Pankoff
7ed54d86d5 Kernel: Record network statistics and expose as JSON
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-08 06:44:49 +02:00
Andreas Kling
605975adb5 Kernel: Make KBuffer a value-type wrapper around a KBufferImpl
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-05 11:07:45 +02:00
Andreas Kling
52cfe9ebae IPv4: Remove an unnecessary copy of each outgoing IPv4 payload
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-05 10:43:22 +02:00
Andreas Kling
e58b734363 Net: Use KBuffers for network adapter packet queues
This further reduces pressure on the kmalloc heap. :^)
2019-08-04 21:22:22 +02:00
Andreas Kling
b2e502e533 Kernel: Add Thread::block_until(Condition).
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-14 14:54:54 +02:00
Andreas Kling
27f699ef0c AK: Rename the common integer typedefs to make it obvious what they are.
These types can be picked up by including <AK/Types.h>:

* u8, u16, u32, u64 (unsigned)
* i8, i16, i32, i64 (signed)
2019-07-03 21:20:13 +02:00
Andreas Kling
9e0f7acfe5 Kernel+Userland: Expose list of network adapters through /proc/netadapters.
Added a simple /bin/ifconfig program that just pretty-prints that file. :^)
2019-06-16 07:06:49 +02:00
Robin Burchell
0dc9af5f7e Add clang-format file
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-05-28 17:31:20 +02:00
Andreas Kling
649c81a714 Kernel: Move networking related files into Kernel/Net/. 2019-04-02 19:54:38 +02:00