1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:57:44 +00:00

Kernel: Move all code into the Kernel namespace

This commit is contained in:
Andreas Kling 2020-02-16 01:27:42 +01:00
parent d42f0f4661
commit a356e48150
201 changed files with 907 additions and 111 deletions

View file

@ -31,6 +31,8 @@
#include <Kernel/Net/IPv4.h>
#include <Kernel/Net/MACAddress.h>
namespace Kernel {
struct ARPOperation {
enum : u16 {
Request = 1,
@ -87,3 +89,5 @@ private:
};
static_assert(sizeof(ARPPacket) == 28);
}

View file

@ -30,6 +30,8 @@
//#define E1000_DEBUG
namespace Kernel {
#define REG_CTRL 0x0000
#define REG_STATUS 0x0008
#define REG_EEPROM 0x0014
@ -420,3 +422,5 @@ void E1000NetworkAdapter::receive()
out32(REG_RXDESCTAIL, rx_current);
}
}
}

View file

@ -31,6 +31,8 @@
#include <Kernel/Net/NetworkAdapter.h>
#include <Kernel/PCI/Access.h>
namespace Kernel {
class E1000NetworkAdapter final : public NetworkAdapter
, public IRQHandler {
public:
@ -102,3 +104,5 @@ private:
WaitQueue m_wait_queue;
};
}

View file

@ -32,6 +32,8 @@
#include <AK/NetworkOrdered.h>
#include <AK/Types.h>
namespace Kernel {
enum class IPv4Protocol : u16 {
ICMP = 1,
TCP = 6,
@ -110,3 +112,5 @@ inline NetworkOrdered<u16> internet_checksum(const void* ptr, size_t count)
checksum = (checksum & 0xffff) + (checksum >> 16);
return ~checksum & 0xffff;
}
}

View file

@ -43,6 +43,8 @@
//#define IPV4_SOCKET_DEBUG
namespace Kernel {
Lockable<HashTable<IPv4Socket*>>& IPv4Socket::all_sockets()
{
static Lockable<HashTable<IPv4Socket*>>* s_table;
@ -511,3 +513,5 @@ void IPv4Socket::shut_down_for_reading()
Socket::shut_down_for_reading();
m_can_read = true;
}
}

View file

@ -35,6 +35,8 @@
#include <Kernel/Net/IPv4SocketTuple.h>
#include <Kernel/Net/Socket.h>
namespace Kernel {
class NetworkAdapter;
class TCPPacket;
class TCPSocket;
@ -137,3 +139,5 @@ private:
Optional<KBuffer> m_scratch_buffer;
};
}

View file

@ -35,6 +35,8 @@
//#define DEBUG_LOCAL_SOCKET
namespace Kernel {
Lockable<InlineLinkedList<LocalSocket>>& LocalSocket::all_sockets()
{
static Lockable<InlineLinkedList<LocalSocket>>* s_list;
@ -394,3 +396,5 @@ KResult LocalSocket::chown(uid_t uid, gid_t gid)
m_prebind_gid = gid;
return KSuccess;
}
}

View file

@ -30,6 +30,8 @@
#include <Kernel/DoubleBuffer.h>
#include <Kernel/Net/Socket.h>
namespace Kernel {
class FileDescription;
class LocalSocket final : public Socket, public InlineLinkedListNode<LocalSocket> {
@ -100,3 +102,5 @@ private:
LocalSocket* m_prev { nullptr };
LocalSocket* m_next { nullptr };
};
}

View file

@ -26,6 +26,8 @@
#include <Kernel/Net/LoopbackAdapter.h>
namespace Kernel {
LoopbackAdapter& LoopbackAdapter::the()
{
static LoopbackAdapter* the;
@ -50,3 +52,5 @@ void LoopbackAdapter::send_raw(const u8* data, size_t size)
dbgprintf("LoopbackAdapter: Sending %d byte(s) to myself.\n", size);
did_receive(data, size);
}
}

View file

@ -28,6 +28,8 @@
#include <Kernel/Net/NetworkAdapter.h>
namespace Kernel {
class LoopbackAdapter final : public NetworkAdapter {
AK_MAKE_ETERNAL
public:
@ -41,3 +43,5 @@ public:
private:
LoopbackAdapter();
};
}

View file

@ -34,6 +34,8 @@
#include <Kernel/Net/NetworkAdapter.h>
#include <LibBareMetal/StdLib.h>
namespace Kernel {
static Lockable<HashTable<NetworkAdapter*>>& all_adapters()
{
static Lockable<HashTable<NetworkAdapter*>>* table;
@ -193,3 +195,5 @@ void NetworkAdapter::set_interface_name(const StringView& basename)
builder.append('0');
m_name = builder.to_string();
}
}

View file

@ -38,6 +38,8 @@
#include <Kernel/Net/IPv4.h>
#include <Kernel/Net/MACAddress.h>
namespace Kernel {
class NetworkAdapter;
class NetworkAdapter : public RefCounted<NetworkAdapter> {
@ -99,3 +101,5 @@ private:
u32 m_bytes_out { 0 };
u32 m_mtu { 1500 };
};
}

View file

@ -48,6 +48,8 @@
//#define UDP_DEBUG
//#define TCP_DEBUG
namespace Kernel {
static void handle_arp(const EthernetFrameHeader&, size_t frame_size);
static void handle_ipv4(const EthernetFrameHeader&, size_t frame_size);
static void handle_icmp(const EthernetFrameHeader&, const IPv4Packet&);
@ -622,3 +624,5 @@ void handle_tcp(const IPv4Packet& ipv4_packet)
}
}
}
}

View file

@ -26,4 +26,8 @@
#pragma once
namespace Kernel {
void NetworkTask_main();
}

View file

@ -29,6 +29,8 @@
//#define RTL8139_DEBUG
namespace Kernel {
#define REG_MAC 0x00
#define REG_MAR0 0x08
#define REG_MAR4 0x12
@ -394,3 +396,5 @@ u32 RTL8139NetworkAdapter::in32(u16 address)
{
return IO::in32(m_io_base + address);
}
}

View file

@ -31,6 +31,8 @@
#include <Kernel/Net/NetworkAdapter.h>
#include <Kernel/PCI/Access.h>
namespace Kernel {
#define RTL8139_TX_BUFFER_COUNT 4
class RTL8139NetworkAdapter final : public NetworkAdapter
@ -70,3 +72,5 @@ private:
u32 m_packet_buffer { 0 };
bool m_link_up { false };
};
}

View file

@ -30,6 +30,8 @@
//#define ROUTING_DEBUG
namespace Kernel {
Lockable<HashMap<IPv4Address, MACAddress>>& arp_table()
{
static Lockable<HashMap<IPv4Address, MACAddress>>* the;
@ -68,7 +70,6 @@ RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source)
gateway_adapter = adapter;
});
if (local_adapter && target == local_adapter->ipv4_address())
return { local_adapter, local_adapter->mac_address() };
@ -161,3 +162,5 @@ RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source)
return { nullptr, {} };
}
}

View file

@ -28,6 +28,8 @@
#include <Kernel/Net/NetworkAdapter.h>
namespace Kernel {
struct RoutingDecision
{
RefPtr<NetworkAdapter> adapter;
@ -39,3 +41,5 @@ struct RoutingDecision
RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source);
Lockable<HashMap<IPv4Address, MACAddress>>& arp_table();
}

View file

@ -35,6 +35,8 @@
//#define SOCKET_DEBUG
namespace Kernel {
KResultOr<NonnullRefPtr<Socket>> Socket::create(int domain, int type, int protocol)
{
switch (domain) {
@ -175,3 +177,5 @@ KResult Socket::shutdown(int how)
m_shut_down_for_writing |= (how & SHUT_WR) != 0;
return KSuccess;
}
}

View file

@ -35,6 +35,8 @@
#include <Kernel/Lock.h>
#include <Kernel/UnixTypes.h>
namespace Kernel {
enum class ShouldBlock {
No = 0,
Yes = 1
@ -207,3 +209,5 @@ public:
private:
RefPtr<SocketType> m_socket;
};
}

View file

@ -28,6 +28,8 @@
#include <Kernel/Net/IPv4.h>
namespace Kernel {
struct TCPFlags {
enum : u16 {
FIN = 0x01,
@ -95,3 +97,5 @@ private:
};
static_assert(sizeof(TCPPacket) == 20);
}

View file

@ -36,6 +36,8 @@
//#define TCP_SOCKET_DEBUG
namespace Kernel {
void TCPSocket::for_each(Function<void(TCPSocket&)> callback)
{
LOCKER(sockets_by_tuple().lock());
@ -465,3 +467,5 @@ void TCPSocket::close()
LOCKER(closing_sockets().lock());
closing_sockets().resource().set(tuple(), *this);
}
}

View file

@ -32,6 +32,8 @@
#include <AK/WeakPtr.h>
#include <Kernel/Net/IPv4Socket.h>
namespace Kernel {
class TCPSocket final : public IPv4Socket
, public Weakable<TCPSocket> {
public:
@ -207,3 +209,5 @@ private:
Lock m_not_acked_lock { "TCPSocket unacked packets" };
SinglyLinkedList<OutgoingPacket> m_not_acked;
};
}

View file

@ -28,6 +28,8 @@
#include <Kernel/Net/IPv4.h>
namespace Kernel {
class [[gnu::packed]] UDPPacket
{
public:
@ -57,3 +59,5 @@ private:
};
static_assert(sizeof(UDPPacket) == 8);
}

View file

@ -32,6 +32,8 @@
#include <Kernel/Process.h>
#include <Kernel/Random.h>
namespace Kernel {
void UDPSocket::for_each(Function<void(UDPSocket&)> callback)
{
LOCKER(sockets_by_port().lock());
@ -147,3 +149,5 @@ KResult UDPSocket::protocol_bind()
sockets_by_port().resource().set(local_port(), this);
return KSuccess;
}
}

View file

@ -28,6 +28,8 @@
#include <Kernel/Net/IPv4Socket.h>
namespace Kernel {
class UDPSocket final : public IPv4Socket {
public:
static NonnullRefPtr<UDPSocket> create(int protocol);
@ -47,3 +49,5 @@ private:
virtual int protocol_allocate_local_port() override;
virtual KResult protocol_bind() override;
};
}