Commit Graph

77 Commits

Author SHA1 Message Date
Andreas Kling
f9de264f88 Kernel: Actually, let's not hang() on bad incoming packets
That kinda defeats the purpose of being smart enough to ignore them :^)
2019-08-09 09:38:38 +02:00
Andreas Kling
9e2a00248e Kernel: Do some basic sanity checking on IPv4 packet headers
Ignore packets that are too small, or not as large as they claim to be.
2019-08-09 09:36:06 +02:00
Andreas Kling
04603237da Kernel: Merge FooSocketHandle classes into a single SocketHandle<Foo>
- IPv4SocketHandle => SocketHandle<IPv4Socket>
- TCPSocketHandle => SocketHandle<TCPSocket>
- UDPSocketHandle => SocketHandle<UDPSocket>
2019-08-09 09:18:16 +02:00
Conrad Pankoff
5c66c67f32 Kernel: Improve some network-related log messages 2019-08-09 07:09:26 +02:00
Conrad Pankoff
4fcbbd24f7 Kernel: Support binding to INADDR_ANY (all IPs) 2019-08-09 07:09:26 +02:00
Conrad Pankoff
3eb659a2bb Kernel: Implement TCP listening sockets and incoming connections 2019-08-09 07:09:26 +02:00
Conrad Pankoff
a53437aa06 Kernel: Let pending socket queue keep socket objects alive until accept() 2019-08-09 07:09:26 +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
Conrad Pankoff
061c092fae Kernel: Prevent RST spam when we get an unexpected packet 2019-08-08 06:42:41 +02:00
Conrad Pankoff
73c998dbfc Kernel: Refactor TCP/IP stack
This has several significant changes to the networking stack.

* Significant refactoring of the TCP state machine. Right now it's
  probably more fragile than it used to be, but handles quite a lot
  more of the handshake process.
* `TCPSocket` holds a `NetworkAdapter*`, assigned during `connect()` or
  `bind()`, whichever comes first.
* `listen()` is now virtual in `Socket` and intended to be implemented
  in its child classes
* `listen()` no longer works without `bind()` - this is a bit of a
  regression, but listening sockets didn't work at all before, so it's
  not possible to observe the regression.
* A file is exposed at `/proc/net_tcp`, which is a JSON document listing
  the current TCP sockets with a bit of metadata.
* There's an `ETHERNET_VERY_DEBUG` flag for dumping packet's content out
  to `kprintf`. It is, indeed, _very debug_.
2019-08-06 16:21:17 +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
6347e3aa51 Net: Let Socket have read/write wrappers around sendto/recvfrom
The situations in IPv4Socket and LocalSocket were mirrors of each other
where one had implemented read/write as wrappers and the other had
sendto/recvfrom as wrappers.

Instead of this silliness, move read and write up to the Socket base.
Then mark them final, so subclasses have no choice but to implement
sendto and recvfrom.
2019-08-05 10:03:19 +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
72798519cb IPv4: Use KBuffer instead of ByteBuffer for socket receive queues
This drastically reduces the pressure on the kernel heap when receiving
data from IPv4 sockets.
2019-08-04 21:09:38 +02:00
Andreas Kling
c06993b7cf Kernel: Remove more unused members of IPv4Socket.
I thought I had included these in the previous commit, but it turns out
I hadn't, duh.
2019-08-04 20:39:59 +02:00
Andreas Kling
f8ffe2019c Kernel: Remove a bunch of unused members in IPv4Socket. 2019-08-04 20:38:21 +02:00
Andreas Kling
675aa550a4 Kernel: Put IPv4 and TCP related debug spam behind flags
...and turn those flags off for now, to make it possible to write some
networking code without being spammed to death.
2019-08-04 10:04:06 +02:00
Robin Burchell
96de90ceef Net: Merge Thread::wait_for_connect into LocalSocket (as the only place that uses it)
Also do this more like other blockers, don't call yield ourselves, as
block will do that for us.
2019-07-20 12:15:24 +02:00
Robin Burchell
833d444cd8 Thread: Return a result from block() indicating why the block terminated
And use this to return EINTR in various places; some of which we were
not handling properly before.

This might expose a few bugs in userspace, but should be more compatible
with other POSIX systems, and is certainly a little cleaner.
2019-07-20 12:15:24 +02:00
Robin Burchell
cd76b691fb Kernel: Remove memory allocations from the new Blocker API 2019-07-19 11:03:22 +02:00
Robin Burchell
762333ba95 Kernel: Restore state strings for block states
"Blocking" is not terribly informative, but now that everything is
ported over, we can force the blocker to provide us with a reason.

This does mean that to_string(State) needed to become a member, but
that's OK.
2019-07-19 11:03:22 +02:00
Robin Burchell
52743f9eec Kernel: Rename ThreadBlocker classes to avoid stutter
Thread::ThreadBlockerFoo is a lot less nice to read than Thread::FooBlocker
2019-07-19 11:03:22 +02:00
Robin Burchell
0c8813e6d9 Kernel: Introduce ThreadBlocker as a way to make unblocking neater :)
And port all the descriptor-based blocks over to it as a proof of concept.
2019-07-19 11:03: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
f4cec2f110 Kernel: Move File.{cpp,h} into FileSystem/
Also tweak the kernel's Makefile to use -nostdinc and -nostdinc++.
This prevents us from picking up random headers from ../Root, which may
include older versions of kernel headers.

Since we still need <initializer_list> for Vector, we specifically include
the necessary GCC path. This is a bit hackish but it works for now.
2019-07-09 15:04:45 +02:00
Andreas Kling
0e75aba7c3 StringView: Rename characters() to characters_without_null_termination().
This should make you think twice before trying to use the const char* from
a StringView as if it's a null-terminated string.
2019-07-08 15:38:44 +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
VAN BOSSUYT Nicolas
802d4dcb6b Meta: Removed all gitignore in the source tree only keeping the root one 2019-06-30 10:41:26 +02:00
Andreas Kling
d5bb98acbc AK: Defer to Traits<T> for equality comparison in container templates.
This is prep work for supporting HashMap with NonnullRefPtr<T> as values.
It's currently not possible because many HashTable functions require being
able to default-construct the value type.
2019-06-29 19:14:03 +02:00
Andreas Kling
46a06c23e3 Kernel: Fix all compiler warnings. 2019-06-22 16:22:34 +02:00
Andreas Kling
d343fb2429 AK: Rename Retainable.h => RefCounted.h. 2019-06-21 18:58:45 +02:00
Andreas Kling
550b0b062b AK: Rename RetainPtr.h => RefPtr.h, Retained.h => NonnullRefPtr.h. 2019-06-21 18:45:59 +02:00
Andreas Kling
90b1354688 AK: Rename RetainPtr => RefPtr and Retained => NonnullRefPtr. 2019-06-21 18:37:47 +02:00
Andreas Kling
d9a48b5916 AK: Move IPv4Address from Kernel/Net/ to AK/ since it's quite useful. 2019-06-18 11:28:48 +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
Andreas Kling
c1bbd40b9e Kernel: Rename "descriptor" to "description" where appropriate.
Now that FileDescription is called that, variables of that type should not
be called "descriptor". This is kinda wordy but we'll get used to it.
2019-06-13 22:03:04 +02:00
Andreas Kling
63f029ef9b Kernel: Use NetworkOrdered<T> in ARPPacket. 2019-06-10 00:59:19 -07:00
Andreas Kling
39d1a9ae66 Meta: Tweak .clang-format to not wrap braces after enums. 2019-06-07 17:13:23 +02:00
Andreas Kling
e42c3b4fd7 Kernel: Rename LinearAddress => VirtualAddress. 2019-06-07 12:56:50 +02:00
Andreas Kling
bc951ca565 Kernel: Run clang-format on everything. 2019-06-07 11:43:58 +02:00
Andreas Kling
08cd75ac4b Kernel: Rename FileDescriptor to FileDescription.
After reading a bunch of POSIX specs, I've learned that a file descriptor
is the number that refers to a file description, not the description itself.
So this patch renames FileDescriptor to FileDescription, and Process now has
FileDescription* file_description(int fd).
2019-06-07 09:36:51 +02:00
Andreas Kling
2dd9ef6863 Kernel: Make File::absolute_path() const. 2019-06-01 18:56:56 +02:00
Andreas Kling
55821c91f8 Kernel: Rename Process::cwd_custody() to Process::current_directory().
...and executable_custody() to just executable().
2019-05-30 22:30:25 +02:00
Andreas Kling
393851418b FileSystem: Port most of the code over to using custodies.
The current working directory is now stored as a custody. Likewise for a
process executable file. This unbreaks /proc/PID/fd which has not been
working since we made the filesystem bigger.

This still needs a bunch of work, for instance when renaming or removing
a file somewhere, we have to update the relevant custody links.
2019-05-30 18:58:59 +02:00
Robin Burchell
a906098579 Kernel: Fix a bad printf, and stub out SO_ERROR a bit more fully
links requests SO_ERROR, so in not supporting it, things were unhappy.
Supporting this properly looks a little messy. I guess Socket will need
an m_error member it sets everywhere it returns an error. Or Syscall
could set it, perhaps, but I don't know if that's the right thing to
do, so let's just stub this for now and file a bug.
2019-05-30 02:02:30 +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
ae470ec955 Kernel: Add getpeername() syscall, and fix getsockname() behavior.
We were copying the raw IPv4 addresses into the wrong part of sockaddr_in,
and we didn't set sa_family or sa_port.
2019-05-20 20:33:03 +02:00
Andreas Kling
f008156dbf Socket: Fix missing kprintf() args in setsockopt(). 2019-05-20 19:45:27 +02:00