Commit graph

149 commits

Author SHA1 Message Date
Andreas Kling 61f611bf3c IPv4: Protect the list of unacked TCP packets with a lock
Otherwise things get racy and crashy.
2019-11-23 21:44:47 +01:00
Andreas Kling 0e9e70ca4f IPv4: Disconnected non-blocking sockets were not signalling EOF
After a socket has disconnected, we shouldn't return -EAGAIN. Instead
we should allow userspace to read/recvfrom the socket until its packet
queue has been exhausted.

At that point, we now return 0, signalling EOF.

It might be even better to start returning -ENOTCONN after signalling
EOF once. I'm not sure how that should work, needs looking into.
2019-11-18 17:37:54 +01:00
Andreas Kling 06a80bcf69 Kernel+SystemMonitor: Publish can_read/write state for open files
The can_read() and can_write() states for file descriptions are now
published in /proc, allowing SystemMonitor to display it.
2019-11-09 22:42:19 +01:00
Andreas Kling 1b2ef8582c Kernel: Make File's can_read/can_write take a const FileDescription&
Asking a File if we could possibly read or write it will never mutate
the asking FileDescription&, so it should be const.
2019-11-04 14:03:14 +01:00
Andreas Kling ecd23ce1a1 IPv4: Non-blocking IPv4 sockets should return -EAGAIN in recvfrom()
...if there are no packets in the receive queue.
2019-11-04 13:42:25 +01:00
Andreas Kling e08991319a Net: Put a bunch of socket debug logging behind FOO_DEBUG
Also remove an unused Socket::listen() implementation.
2019-10-18 16:50:23 +02:00
Andreas Kling ec65b8db2e Revert "Kernel: Make DoubleBuffer use a KBuffer instead of kmalloc()ing"
This reverts commit 1cca5142af.

This appears to be causing intermittent triple-faults and I don't know
why yet, so I'll just revert it to keep the tree in decent shape.
2019-10-18 15:58:06 +02:00
Andreas Kling 1cca5142af Kernel: Make DoubleBuffer use a KBuffer instead of kmalloc()ing
Background: DoubleBuffer is a handy buffer class in the kernel that
allows you to keep writing to it from the "outside" while the "inside"
reads from it. It's used for things like LocalSocket and PTY's.
Internally, it has a read buffer and a write buffer, but the two will
swap places when the read buffer is exhausted (by reading from it.)

Before this patch, it was internally implemented as two Vector<u8>
that we would swap between when the reader side had exhausted the data
in the read buffer. Now instead we preallocate a large KBuffer (64KB*2)
on DoubleBuffer construction and use that throughout its lifetime.

This removes all the kmalloc heap traffic caused by DoubleBuffers :^)
2019-10-18 14:55:04 +02:00
Andreas Kling 340b524c0d Kernel: Minor cleanup in TCPSocket::send_tcp_packet() 2019-10-17 23:39:31 +02:00
Andreas Kling 9bb0374d7d Kernel: Delay moving accepted sockets to SetupState::Completed a bit
Make sure we don't move accepted sockets to the Completed setup state
until we've actually constructed a FileDescription for them.

This is important, since this state transition will trigger connect()
to unblock on the client side, and the client may try writing to the
socket right away.

This makes DNS lookups way more reliable since we don't just fail to
write() right after connect()ing to LookupServer sometimes. :^)
2019-10-08 21:44:50 +02:00
Andreas Kling 3aa27b5b0e Kernel: Don't put LocalSocket in SetupState::Completed in bind()
This was causing connect() to unblock immediately for local sockets,
since that's exactly what ConnectBlocker checks for.

Instead, just move to SetupState::Completed when it's accept()ed.
2019-10-08 21:32:04 +02:00
Andreas Kling 3f2c1a2e3d Kernel: Add SIOCGIFHWADDR ioctl to get the MAC address of an adapter 2019-10-02 18:20:11 +02:00
Andreas Kling 8f45a259fc ByteBuffer: Remove pointer() in favor of data()
We had two ways to get the data inside a ByteBuffer. That was silly.
2019-09-30 08:57:01 +02: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 65409e8f04 LocalSocket: Teach recvfrom() how to block if needed, and simplify it
If we can't already read when we enter recvfrom() on a LocalSocket,
we'll now block the current thread until we can.

Also added a buffer_for(FileDescription&) helper so that the client
and server can share some of the code. :^)
2019-09-22 21:30:30 +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
Andreas Kling 1c692e87a6 Kernel: Move kmalloc() into a Kernel/Heap/ directory 2019-09-16 09:01:44 +02:00
Andreas Kling 54caeb1f1a RTL8139: Fix bogus (but harmless) TX buffer index in send_raw()
This was getting fixed up by the loop that chooses the next TX buffer
anyway, but let's do this correctly.

Fixes #522.
2019-09-09 08:51:08 +02:00
Conrad Pankoff c983e96664 Kernel: Use timeval_sub for TCP retransmissions and lower timer to 500ms 2019-09-08 12:34:20 +02:00
Conrad Pankoff 3f1c3a341b Kernel: Handle listening socket disappearing during incoming handshake 2019-09-08 12:34:20 +02:00
Conrad Pankoff feb6d1afe0 Kernel: Use a WeakPtr instead of a RefPtr for TCP socket originator 2019-09-08 12:34:20 +02:00
Conrad Pankoff a2b61e30c5 Kernel: Put some network log messages behind debug flags 2019-09-08 12:34:20 +02:00
Conrad Pankoff 328d52b323 Kernel: Send ACK/FIN in response to FIN packets on active connections
This is to work around our lack of a shutdown() implementation.
2019-09-08 12:34:20 +02:00
Conrad Pankoff 117d8db2a2 Kernel: Implement outgoing TCP retransmission and better ACK handling
This approach is a bit naiive - whenever we send a packet out, we
check to see if there are any other packets we should try to send.
This works well enough for a busy connection but not very well for a
quiet one. Ideally we would check for not-acked packets on some kind
of timer, and use the length of this not-acked list as feedback to
throttle the writes coming from userspace.
2019-09-08 12:34:20 +02:00
Conrad Pankoff b8e3c7ef01 Kernel: Remember all ARP replies, even ones we didn't request
This allows us to take advantage of unsolicited ARP replies, such as
those that are emitted by many systems after their network interfaces
are enabled, or after their DHCP client sets their IP.

This also makes us a bit more vulnerable to ARP flooding, but we need
some kind of eviction strategy anyway, so we can deal with that later.
2019-09-08 12:34:20 +02:00
Conrad Pankoff b45cfae7f4 Kernel: Don't mark incoming sockets as connected in NetworkTask
An incoming socket should only be considered connected after a
program has received it from accept(). Before that point, it's only
"half" open, and it might not ever actually be served to a program.

Socket::accept is where m_connected is correctly set.
2019-09-08 12:34:20 +02:00
Conrad Pankoff 72f728b0d6 Kernel: Hold socket back from accept() until it's fully set up 2019-09-08 12:34:20 +02:00
Conrad Pankoff d53c9d4416 Kernel: Use RefPtr instead of SocketHandle for TCPSocket clients
Using a SocketHandle takes a lock on the socket, which we don't want
to do.
2019-09-08 12:34:20 +02:00
Conrad Pankoff cfcb53fe77 Kernel: Don't set sequence manually; send_tcp_packet will do it 2019-09-08 12:34:20 +02:00
Conrad Pankoff e8a10848b5 Kernel: Make sure IPv4Socket is marked as listening in listen() 2019-09-08 12:34:20 +02:00
Conrad Pankoff 706e04d340 Kernel: Don't increment ACK number without SYN, FIN, or data 2019-09-08 12:34:20 +02:00
Conrad Pankoff 749719b4d0 Kernel: Fix debug messages in IPv4Socket 2019-09-08 12:34:20 +02:00
Andreas Kling 73fdbba59c AK: Rename <AK/AKString.h> to <AK/String.h>
This was a workaround to be able to build on case-insensitive file
systems where it might get confused about <string.h> vs <String.h>.

Let's just not support building that way, so String.h can have an
objectively nicer name. :^)
2019-09-06 15:36:54 +02:00
Conrad Pankoff a3468dc993 Kernel: Pad packets out to 64 bytes in rtl8139 driver 2019-09-03 15:24:48 +02:00
Conrad Pankoff c8fa95b8cd Kernel: Only set tx buffer address once in rtl8139 driver 2019-09-03 15:24:48 +02:00
Conrad Pankoff 7c9adcf24e Kernel: Reword some constants/comments in rtl8139 driver for clarity 2019-09-03 15:24:48 +02:00
Conrad Pankoff ff2997f018 Kernel: Use regular kmalloc for buffers in rtl8139 driver 2019-09-03 15:24:48 +02:00
Andreas Kling c82627aae2 Kernel: Don't allow non-superusers to bind TCP/UDP ports < 1024 2019-09-02 18:49:54 +02:00
Conrad Pankoff b15a7c435f Kernel: Implement is_zero for RoutingDecision 2019-08-29 06:25:06 +02:00
Conrad Pankoff 302d521485 Kernel: Take a copy of MACAddress in RoutingDecision 2019-08-29 06:25:06 +02:00
Conrad Pankoff 498f8c01a2 Kernel: Use a public member for NetworkAdapter on_receive 2019-08-29 06:25:06 +02:00
Conrad Pankoff 6d1418aa7a Kernel: Add simple ARP routing layer
This replaces the previous placeholder routing layer with a real one!
It's still very primitive, doesn't deal with things like timeouts very
well, and will probably need several more iterations to support more
normal networking things.

I haven't confirmed that this works with anything other than the QEMU
user networking layer, but I suspect that's what nearly everybody is
using at this point, so that's the important target to keep working.
2019-08-29 06:25:06 +02:00
Conrad Pankoff 626e176cab Kernel: Remove IP configuration from LoopbackAdapter
This is configured in NetworkTask_main now, so there's no need to do it
here as well.
2019-08-29 06:25:06 +02:00
Conrad Pankoff 13abb3e88b Kernel: Remove now-unused singleton methods from our network devices 2019-08-29 06:25:06 +02:00
Conrad Pankoff 93c16590f1 Kernel: Remove specific devices from network code
By setting up the devices in init() and looping over the registered
network adapters in NetworkTask_main, we can remove the remaining
hard-coded adapter references from the network code.

This also assigns IPs according to the default range supplied by QEMU
in its slirp networking mode.
2019-08-29 06:25:06 +02:00
Conrad Pankoff 41e9ad5ea0 Kernel: Add const to packet data in send_raw call 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 bed069bd14 Kernel: Ask for all relevant IRQs in rtl8139 driver 2019-08-29 06:25:06 +02:00
Conrad Pankoff 5f86a979ea Kernel: Ignore IPv6 packets; log unknown Ethernet payload types 2019-08-29 06:25:06 +02:00