summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/src/Network
diff options
context:
space:
mode:
Diffstat (limited to 'dev/kernel/src/Network')
-rw-r--r--dev/kernel/src/Network/IPAddr.cc213
-rw-r--r--dev/kernel/src/Network/IPCAddr.cc35
-rw-r--r--dev/kernel/src/Network/IPCMsg.cc215
-rw-r--r--dev/kernel/src/Network/MACAddressGetter.cc14
-rw-r--r--dev/kernel/src/Network/NetworkDevice.cc49
5 files changed, 232 insertions, 294 deletions
diff --git a/dev/kernel/src/Network/IPAddr.cc b/dev/kernel/src/Network/IPAddr.cc
index 02e2c258..4437df22 100644
--- a/dev/kernel/src/Network/IPAddr.cc
+++ b/dev/kernel/src/Network/IPAddr.cc
@@ -1,129 +1,100 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
#include <NetworkKit/IP.h>
#include <NewKit/Utils.h>
-namespace Kernel
-{
- Char* RawIPAddress::Address()
- {
- return fAddr;
- }
-
- RawIPAddress::RawIPAddress(char bytes[4])
- {
- rt_copy_memory(bytes, fAddr, 4);
- }
-
- BOOL RawIPAddress::operator==(const RawIPAddress& ipv4)
- {
- for (Size index = 0; index < 4; ++index)
- {
- if (ipv4.fAddr[index] != fAddr[index])
- return false;
- }
-
- return true;
- }
-
- BOOL RawIPAddress::operator!=(const RawIPAddress& ipv4)
- {
- for (Size index = 0; index < 4; ++index)
- {
- if (ipv4.fAddr[index] == fAddr[index])
- return false;
- }
-
- return true;
- }
-
- Char& RawIPAddress::operator[](const Size& index)
- {
- kout << "[RawIPAddress::operator[]] Fetching Index...\r";
-
- static char IP_PLACEHOLDER = '0';
- if (index > 4)
- return IP_PLACEHOLDER;
-
- return fAddr[index];
- }
-
- RawIPAddress6::RawIPAddress6(char bytes[8])
- {
- rt_copy_memory(bytes, fAddr, 8);
- }
-
- char& RawIPAddress6::operator[](const Size& index)
- {
- kout << "[RawIPAddress6::operator[]] Fetching Index...\r";
-
- static char IP_PLACEHOLDER = '0';
- if (index > 8)
- return IP_PLACEHOLDER;
-
- return fAddr[index];
- }
-
- bool RawIPAddress6::operator==(const RawIPAddress6& ipv6)
- {
- for (SizeT index = 0; index < 8; ++index)
- {
- if (ipv6.fAddr[index] != fAddr[index])
- return false;
- }
-
- return true;
- }
-
- bool RawIPAddress6::operator!=(const RawIPAddress6& ipv6)
- {
- for (SizeT index = 0; index < 8; ++index)
- {
- if (ipv6.fAddr[index] == fAddr[index])
- return false;
- }
-
- return true;
- }
-
- ErrorOr<KString> IPFactory::ToKString(Ref<RawIPAddress6>& ipv6)
- {
- auto str = KStringBuilder::Construct(ipv6.Leak().Address());
- return str;
- }
-
- ErrorOr<KString> IPFactory::ToKString(Ref<RawIPAddress>& ipv4)
- {
- auto str = KStringBuilder::Construct(ipv4.Leak().Address());
- return str;
- }
-
- bool IPFactory::IpCheckVersion4(const Char* ip)
- {
- if (!ip)
- return NO;
-
- Int32 cnter = 0;
-
- for (SizeT base = 0; base < rt_string_len(ip); ++base)
- {
- if (ip[base] == '.')
- {
- cnter = 0;
- }
- else
- {
- if (cnter == 3)
- return false;
-
- ++cnter;
- }
- }
-
- return true;
- }
-} // namespace Kernel
+namespace Kernel {
+Char* RawIPAddress::Address() {
+ return fAddr;
+}
+
+RawIPAddress::RawIPAddress(char bytes[4]) {
+ rt_copy_memory(bytes, fAddr, 4);
+}
+
+BOOL RawIPAddress::operator==(const RawIPAddress& ipv4) {
+ for (Size index = 0; index < 4; ++index) {
+ if (ipv4.fAddr[index] != fAddr[index]) return false;
+ }
+
+ return true;
+}
+
+BOOL RawIPAddress::operator!=(const RawIPAddress& ipv4) {
+ for (Size index = 0; index < 4; ++index) {
+ if (ipv4.fAddr[index] == fAddr[index]) return false;
+ }
+
+ return true;
+}
+
+Char& RawIPAddress::operator[](const Size& index) {
+ kout << "[RawIPAddress::operator[]] Fetching Index...\r";
+
+ static char IP_PLACEHOLDER = '0';
+ if (index > 4) return IP_PLACEHOLDER;
+
+ return fAddr[index];
+}
+
+RawIPAddress6::RawIPAddress6(char bytes[8]) {
+ rt_copy_memory(bytes, fAddr, 8);
+}
+
+char& RawIPAddress6::operator[](const Size& index) {
+ kout << "[RawIPAddress6::operator[]] Fetching Index...\r";
+
+ static char IP_PLACEHOLDER = '0';
+ if (index > 8) return IP_PLACEHOLDER;
+
+ return fAddr[index];
+}
+
+bool RawIPAddress6::operator==(const RawIPAddress6& ipv6) {
+ for (SizeT index = 0; index < 8; ++index) {
+ if (ipv6.fAddr[index] != fAddr[index]) return false;
+ }
+
+ return true;
+}
+
+bool RawIPAddress6::operator!=(const RawIPAddress6& ipv6) {
+ for (SizeT index = 0; index < 8; ++index) {
+ if (ipv6.fAddr[index] == fAddr[index]) return false;
+ }
+
+ return true;
+}
+
+ErrorOr<KString> IPFactory::ToKString(Ref<RawIPAddress6>& ipv6) {
+ auto str = KStringBuilder::Construct(ipv6.Leak().Address());
+ return str;
+}
+
+ErrorOr<KString> IPFactory::ToKString(Ref<RawIPAddress>& ipv4) {
+ auto str = KStringBuilder::Construct(ipv4.Leak().Address());
+ return str;
+}
+
+bool IPFactory::IpCheckVersion4(const Char* ip) {
+ if (!ip) return NO;
+
+ Int32 cnter = 0;
+
+ for (SizeT base = 0; base < rt_string_len(ip); ++base) {
+ if (ip[base] == '.') {
+ cnter = 0;
+ } else {
+ if (cnter == 3) return false;
+
+ ++cnter;
+ }
+ }
+
+ return true;
+}
+} // namespace Kernel
diff --git a/dev/kernel/src/Network/IPCAddr.cc b/dev/kernel/src/Network/IPCAddr.cc
index a56aec14..4c1dd500 100644
--- a/dev/kernel/src/Network/IPCAddr.cc
+++ b/dev/kernel/src/Network/IPCAddr.cc
@@ -4,29 +4,24 @@
------------------------------------------- */
-#include <NetworkKit/IPC.h>
#include <KernelKit/KPC.h>
#include <KernelKit/ProcessScheduler.h>
+#include <NetworkKit/IPC.h>
-namespace Kernel
-{
- bool IPC_ADDR::operator==(const IPC_ADDR& addr) noexcept
- {
- return addr.UserProcessID == this->UserProcessID && addr.ProcessTeam == this->ProcessTeam;
- }
+namespace Kernel {
+bool IPC_ADDR::operator==(const IPC_ADDR& addr) noexcept {
+ return addr.UserProcessID == this->UserProcessID && addr.UserProcessTeam == this->UserProcessTeam;
+}
- bool IPC_ADDR::operator==(IPC_ADDR& addr) noexcept
- {
- return addr.UserProcessID == this->UserProcessID && addr.ProcessTeam == this->ProcessTeam;
- }
+bool IPC_ADDR::operator==(IPC_ADDR& addr) noexcept {
+ return addr.UserProcessID == this->UserProcessID && addr.UserProcessTeam == this->UserProcessTeam;
+}
- bool IPC_ADDR::operator!=(const IPC_ADDR& addr) noexcept
- {
- return addr.UserProcessID != this->UserProcessID || addr.ProcessTeam != this->ProcessTeam;
- }
+bool IPC_ADDR::operator!=(const IPC_ADDR& addr) noexcept {
+ return addr.UserProcessID != this->UserProcessID || addr.UserProcessTeam != this->UserProcessTeam;
+}
- bool IPC_ADDR::operator!=(IPC_ADDR& addr) noexcept
- {
- return addr.UserProcessID != this->UserProcessID || addr.ProcessTeam != this->ProcessTeam;
- }
-} // namespace Kernel
+bool IPC_ADDR::operator!=(IPC_ADDR& addr) noexcept {
+ return addr.UserProcessID != this->UserProcessID || addr.UserProcessTeam != this->UserProcessTeam;
+}
+} // namespace Kernel
diff --git a/dev/kernel/src/Network/IPCMsg.cc b/dev/kernel/src/Network/IPCMsg.cc
index ceb0ae98..b3c9d9fd 100644
--- a/dev/kernel/src/Network/IPCMsg.cc
+++ b/dev/kernel/src/Network/IPCMsg.cc
@@ -1,125 +1,106 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
-#include <NetworkKit/IPC.h>
#include <KernelKit/KPC.h>
#include <KernelKit/ProcessScheduler.h>
+#include <NetworkKit/IPC.h>
+
+namespace Kernel {
+/// @internal internal use for IPC system only.
+/// @brief The internal sanitize function.
+Bool ipc_int_sanitize_packet(IPC_MSG* pckt) {
+ auto endian = RTL_ENDIAN(pckt, ((Char*) pckt)[0]);
+
+ switch (endian) {
+ case Endian::kEndianBig: {
+ if (pckt->IpcEndianess == kIPCLittleEndian) goto ipc_check_failed;
+
+ break;
+ }
+ case Endian::kEndianLittle: {
+ if (pckt->IpcEndianess == kIPCBigEndian) goto ipc_check_failed;
+
+ break;
+ }
+ case Endian::kEndianMixed: {
+ if (pckt->IpcEndianess == kIPCMixedEndian) goto ipc_check_failed;
+
+ break;
+ }
+ default:
+ goto ipc_check_failed;
+ }
+
+ if (pckt->IpcFrom == pckt->IpcTo || pckt->IpcPacketSize > kIPCMsgSize) {
+ goto ipc_check_failed;
+ }
+
+ return pckt->IpcPacketSize > 1 && pckt->IpcHeaderMagic == kIPCHeaderMagic;
+
+ipc_check_failed:
+ err_local_get() = kErrorIPC;
+ return false;
+}
+
+/// @brief Sanitize packet function
+/// @retval true packet is correct.
+/// @retval false packet is incorrect and process has crashed.
+Bool ipc_sanitize_packet(IPC_MSG* pckt) {
+ if (!pckt || !ipc_int_sanitize_packet(pckt)) {
+ return false;
+ }
+
+ return true;
+}
+
+/// @brief Construct packet function
+/// @retval true packet is correct.
+/// @retval false packet is incorrect and process has crashed.
+Bool ipc_construct_packet(_Output IPC_MSG** pckt_in) {
+ // don't act if it's not even valid.
+ if (!pckt_in) return false;
+
+ if (!*pckt_in) *pckt_in = new IPC_MSG();
+
+ MUST_PASS(*pckt_in);
+
+ if (*pckt_in) {
+ const auto endianess = RTL_ENDIAN((*pckt_in), ((Char*) (*pckt_in))[0]);
+
+ (*pckt_in)->IpcHeaderMagic = kIPCHeaderMagic;
+
+ (*pckt_in)->IpcEndianess = static_cast<UInt8>(endianess);
+ (*pckt_in)->IpcPacketSize = sizeof(IPC_MSG);
+
+ (*pckt_in)->IpcTo.UserProcessID = 0;
+ (*pckt_in)->IpcTo.UserProcessTeam = 0;
+
+ (*pckt_in)->IpcFrom.UserProcessID = 0;
+ (*pckt_in)->IpcFrom.UserProcessTeam = 0;
+
+ return Yes;
+ }
+
+ return No;
+}
+
+/// @brief Pass message from **src** to **target**
+/// @param src Source message.
+/// @param target Target message.
+Bool IPC_MSG::Pass(IPC_MSG* src, IPC_MSG* target) noexcept {
+ if (src && target && (target != src)) {
+ if (src->IpcMsgSz > target->IpcMsgSz) return No;
+
+ if (target->IpcMsgSz > src->IpcMsgSz) return No;
+
+ rt_copy_memory(src->IpcData, target->IpcData, src->IpcMsgSz);
+
+ return Yes;
+ }
-namespace Kernel
-{
- /// @internal internal use for IPC system only.
- /// @brief The internal sanitize function.
- Bool ipc_int_sanitize_packet(IPC_MSG* pckt)
- {
- auto endian = RTL_ENDIAN(pckt, ((Char*)pckt)[0]);
-
- switch (endian)
- {
- case Endian::kEndianBig: {
- if (pckt->IpcEndianess == kIPCLittleEndian)
- goto ipc_check_failed;
-
- break;
- }
- case Endian::kEndianLittle: {
- if (pckt->IpcEndianess == kIPCBigEndian)
- goto ipc_check_failed;
-
- break;
- }
- case Endian::kEndianMixed: {
- if (pckt->IpcEndianess == kIPCMixedEndian)
- goto ipc_check_failed;
-
- break;
- }
- default:
- goto ipc_check_failed;
- }
-
- if (pckt->IpcFrom == pckt->IpcTo ||
- pckt->IpcPacketSize > kIPCMsgSize)
- {
- goto ipc_check_failed;
- }
-
- return pckt->IpcPacketSize > 1 && pckt->IpcHeaderMagic == kIPCHeaderMagic;
-
- ipc_check_failed:
- err_local_get() = kErrorIPC;
- return false;
- }
-
- /// @brief Sanitize packet function
- /// @retval true packet is correct.
- /// @retval false packet is incorrect and process has crashed.
- Bool ipc_sanitize_packet(IPC_MSG* pckt)
- {
- if (!pckt ||
- !ipc_int_sanitize_packet(pckt))
- {
- return false;
- }
-
- return true;
- }
-
- /// @brief Construct packet function
- /// @retval true packet is correct.
- /// @retval false packet is incorrect and process has crashed.
- Bool ipc_construct_packet(_Output IPC_MSG** pckt_in)
- {
- // don't act if it's not even valid.
- if (!pckt_in)
- return false;
-
- if (!*pckt_in)
- *pckt_in = new IPC_MSG();
-
- MUST_PASS(*pckt_in);
-
- if (*pckt_in)
- {
- const auto endianess = RTL_ENDIAN((*pckt_in), ((Char*)(*pckt_in))[0]);
-
- (*pckt_in)->IpcHeaderMagic = kIPCHeaderMagic;
-
- (*pckt_in)->IpcEndianess = static_cast<UInt8>(endianess);
- (*pckt_in)->IpcPacketSize = sizeof(IPC_MSG);
-
- (*pckt_in)->IpcTo.UserProcessID = 0;
- (*pckt_in)->IpcTo.ProcessTeam = 0;
-
- (*pckt_in)->IpcFrom.UserProcessID = 0;
- (*pckt_in)->IpcFrom.ProcessTeam = 0;
-
- return Yes;
- }
-
- return No;
- }
-
- /// @brief Pass message from **src** to **target**
- /// @param src Source message.
- /// @param target Target message.
- Bool IPC_MSG::Pass(IPC_MSG* src, IPC_MSG* target) noexcept
- {
- if (src && target && (target != src))
- {
- if (src->IpcMsgSz > target->IpcMsgSz)
- return No;
-
- if (target->IpcMsgSz > src->IpcMsgSz)
- return No;
-
- rt_copy_memory(src->IpcData, target->IpcData, src->IpcMsgSz);
-
- return Yes;
- }
-
- return No;
- }
-} // namespace Kernel
+ return No;
+}
+} // namespace Kernel
diff --git a/dev/kernel/src/Network/MACAddressGetter.cc b/dev/kernel/src/Network/MACAddressGetter.cc
index 192dbc70..736e1e27 100644
--- a/dev/kernel/src/Network/MACAddressGetter.cc
+++ b/dev/kernel/src/Network/MACAddressGetter.cc
@@ -1,15 +1,13 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
#include <NetworkKit/MAC.h>
-namespace Kernel
-{
- Array<UInt8, kMACAddrLen>& MacAddressGetter::AsBytes()
- {
- return this->fMacAddress;
- }
-} // namespace Kernel
+namespace Kernel {
+Array<UInt8, kMACAddrLen>& MacAddressGetter::AsBytes() {
+ return this->fMacAddress;
+}
+} // namespace Kernel
diff --git a/dev/kernel/src/Network/NetworkDevice.cc b/dev/kernel/src/Network/NetworkDevice.cc
index d7d78c28..6f77a244 100644
--- a/dev/kernel/src/Network/NetworkDevice.cc
+++ b/dev/kernel/src/Network/NetworkDevice.cc
@@ -1,36 +1,29 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
#include <NetworkKit/NetworkDevice.h>
#include <NewKit/Utils.h>
-namespace Kernel
-{
- /// \brief Getter for fNetworkName.
- /// \return Network device name.
- const Char* NetworkDevice::Name() const
- {
- return this->fNetworkName;
- }
-
- /// \brief Setter for fNetworkName.
- Boolean NetworkDevice::Name(const Char* name)
- {
- if (name == nullptr)
- return NO;
-
- if (*name == 0)
- return NO;
-
- if (rt_string_len(name) > cNetworkNameLen)
- return NO;
-
- rt_copy_memory((VoidPtr)name,
- (VoidPtr)this->fNetworkName, rt_string_len(name));
-
- return YES;
- }
-} // namespace Kernel
+namespace Kernel {
+/// \brief Getter for fNetworkName.
+/// \return Network device name.
+const Char* NetworkDevice::Name() const {
+ return this->fNetworkName;
+}
+
+/// \brief Setter for fNetworkName.
+Boolean NetworkDevice::Name(const Char* name) {
+ if (name == nullptr) return NO;
+
+ if (*name == 0) return NO;
+
+ if (rt_string_len(name) > cNetworkNameLen) return NO;
+
+ rt_copy_memory((VoidPtr) name, (VoidPtr) this->fNetworkName, rt_string_len(name));
+
+ return YES;
+}
+} // namespace Kernel