Commit Graph

130 Commits

Author SHA1 Message Date
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
Conrad Pankoff
4a4e66b2d0 Kernel/AK: Add is_zero helpers for IP and MAC addresses 2019-08-29 06:25:06 +02:00
Conrad Pankoff
fac1148679 Kernel: Always format MACAddress with two-byte hex digits in to_string 2019-08-29 06:25:06 +02:00
Conrad Pankoff
eb01735ec5 Kernel: Add list-compatible constructor for MACAddress 2019-08-29 06:25:06 +02:00
Conrad Pankoff
0b3308f995 Kernel: Remove over-eager const from rtl8139 driver link_up function 2019-08-21 17:16:03 +02:00
Conrad Pankoff
4afe9e4f2a Kernel: Implement rtl8139 network interface driver 2019-08-21 17:10:34 +02:00
Conrad Pankoff
286bafbb19 Kernel: Implement link status in /proc/net/adapters 2019-08-21 17:10:34 +02:00
Andreas Kling
910fab564e LocalSocket: Make recvfrom() return 0 to signal EOF when peer is gone
Once the peer has disconnected, recvfrom() should always return 0 once
the socket buffer has been drained.
2019-08-17 11:04:45 +02:00
Sergey Bugaev
dadf6337ef Kernel: Customize absolute_path() for more file types 2019-08-11 16:30:43 +02:00
Sergey Bugaev
1d03391488 Net: Store an acceptor PID alongside the origin PID in a socket
* The origin PID is the PID of the process that created this socket,
  either explicitly by calling socket(), or implicitly by accepting
  a TCP connection. Note that accepting a local socket connection
  does not create a new socket, it reuses the one connect() was
  called on, so for accepted local sockets the origin PID points
  to the connecting process.

* The acceptor PID is the PID of the process that accept()ed this
  socket. For accepted TCP sockets, this is the same as origin PID.
2019-08-11 16:30:43 +02:00
Sergey Bugaev
66e5d0bdf3 Net: Store all the LocalSockets in an InlineLinkedList 2019-08-11 16:30:43 +02:00
Sergey Bugaev
a30930465e Net: Add LocalSocket::socket_path()
This is a little utility function to safely extract the path without
manually dealing with sun_path and null-termination.
2019-08-11 16:30:43 +02:00
Sergey Bugaev
8a975ff630 Net: Override LocalSocket::class_name() 2019-08-11 16:30:43 +02:00
Sergey Bugaev
908068d19d Net: Fix initializing sockaddr_un.sun_path copy buffers
The whole point of allocating an extra byte for the null terminator
is to initialize it to zero.
2019-08-11 16:30:43 +02:00
Sergey Bugaev
43ce6c5474 Kernel: Move socket role tracking to the Socket class itself
This is more logical and allows us to solve the problem of
non-blocking TCP sockets getting stuck in SocketRole::None.

The only complication is that a single LocalSocket may be shared
between two file descriptions (on the connect and accept sides),
and should have two different roles depending from which side
you look at it. To deal with it, Socket::role() is made a
virtual method that accepts a file description, and LocalSocket
internally tracks which FileDescription is the which one and
returns a correct role.
2019-08-11 16:30:43 +02:00
Sergey Bugaev
d46c3b0b5b Net: Simplify how LocalSocket tracks open fds
Now that there can't be multiple clones of the same fd,
we only need to track whether or not an fd exists on each
side. Also there's no point in tracking connecting fds.
2019-08-11 16:30:43 +02:00
Conrad Pankoff
fc3667c026 Kernel: Detect some outgoing TCP connection failures 2019-08-10 09:07:11 +02:00
Conrad Pankoff
bd6d2c0819 Kernel: Use a more detailed state machine for socket setup 2019-08-10 09:07:11 +02:00
Conrad Pankoff
638008da13 Kernel: Move TCP state logging into TCPSocket 2019-08-10 09:07:11 +02:00
Conrad Pankoff
5c0f1f9834 Kernel: Fix get{sock,peer}name port endianness 2019-08-10 08:49:31 +02:00