Преглед на файлове

Kernel: Collect IPv4 stuff in IPv4.h and ARP stuff in ARP.h.

Andreas Kling преди 6 години
родител
ревизия
c6a2012fe9
променени са 7 файла, в които са добавени 60 реда и са изтрити 66 реда
  1. 1 1
      Kernel/ARP.h
  2. 1 2
      Kernel/ICMP.h
  3. 52 1
      Kernel/IPv4.h
  4. 0 55
      Kernel/IPv4Address.h
  5. 2 3
      Kernel/NetworkAdapter.h
  6. 3 3
      Kernel/NetworkTask.cpp
  7. 1 1
      Kernel/Process.cpp

+ 1 - 1
Kernel/ARPPacket.h → Kernel/ARP.h

@@ -1,7 +1,7 @@
 #pragma once
 
 #include <Kernel/MACAddress.h>
-#include <Kernel/IPv4Address.h>
+#include <Kernel/IPv4.h>
 #include <Kernel/EtherType.h>
 
 struct ARPOperation {

+ 1 - 2
Kernel/ICMP.h

@@ -1,8 +1,7 @@
 #pragma once
 
 #include <Kernel/MACAddress.h>
-#include <Kernel/IPv4Packet.h>
-#include <Kernel/NetworkOrdered.h>
+#include <Kernel/IPv4.h>
 
 struct ICMPType {
 enum {

+ 52 - 1
Kernel/IPv4Packet.h → Kernel/IPv4.h

@@ -1,8 +1,10 @@
 #pragma once
 
+#include <AK/AKString.h>
+#include <AK/Assertions.h>
 #include <AK/Types.h>
-#include <Kernel/IPv4Address.h>
 #include <Kernel/NetworkOrdered.h>
+#include <Kernel/StdLib.h>
 
 enum class IPv4Protocol : word {
     ICMP = 1,
@@ -12,6 +14,55 @@ enum class IPv4Protocol : word {
 
 NetworkOrdered<word> internet_checksum(const void*, size_t);
 
+class [[gnu::packed]] IPv4Address {
+public:
+    IPv4Address() { }
+    IPv4Address(const byte data[4])
+    {
+        memcpy(m_data, data, 4);
+    }
+    IPv4Address(byte a, byte b, byte c, byte d)
+    {
+        m_data[0] = a;
+        m_data[1] = b;
+        m_data[2] = c;
+        m_data[3] = d;
+    }
+    ~IPv4Address() { }
+
+    byte operator[](int i) const
+    {
+        ASSERT(i >= 0 && i < 4);
+        return m_data[i];
+    }
+
+    String to_string() const
+    {
+        return String::format("%u.%u.%u.%u", m_data[0], m_data[1], m_data[2], m_data[3]);
+    }
+
+    bool operator==(const IPv4Address& other) const { return m_data_as_dword == other.m_data_as_dword; }
+    bool operator!=(const IPv4Address& other) const { return m_data_as_dword != other.m_data_as_dword; }
+
+private:
+    union {
+        byte m_data[4];
+        dword m_data_as_dword;
+    };
+};
+
+static_assert(sizeof(IPv4Address) == 4);
+
+namespace AK {
+
+template<>
+struct Traits<IPv4Address> {
+    static unsigned hash(const IPv4Address& address) { return string_hash((const char*)&address, sizeof(address)); }
+    static void dump(const IPv4Address& address) { kprintf("%s", address.to_string().characters()); }
+};
+
+}
+
 class [[gnu::packed]] IPv4Packet {
 public:
     byte version() const { return (m_version_and_ihl >> 4) & 0xf; }

+ 0 - 55
Kernel/IPv4Address.h

@@ -1,55 +0,0 @@
-#pragma once
-
-#include <AK/Assertions.h>
-#include <AK/AKString.h>
-#include <AK/Types.h>
-#include <Kernel/StdLib.h>
-
-class [[gnu::packed]] IPv4Address {
-public:
-    IPv4Address() { }
-    IPv4Address(const byte data[4])
-    {
-        memcpy(m_data, data, 4);
-    }
-    IPv4Address(byte a, byte b, byte c, byte d)
-    {
-        m_data[0] = a;
-        m_data[1] = b;
-        m_data[2] = c;
-        m_data[3] = d;
-    }
-    ~IPv4Address() { }
-
-    byte operator[](int i) const
-    {
-        ASSERT(i >= 0 && i < 4);
-        return m_data[i];
-    }
-
-    String to_string() const
-    {
-        return String::format("%u.%u.%u.%u", m_data[0], m_data[1], m_data[2], m_data[3]);
-    }
-
-    bool operator==(const IPv4Address& other) const { return m_data_as_dword == other.m_data_as_dword; }
-    bool operator!=(const IPv4Address& other) const { return m_data_as_dword != other.m_data_as_dword; }
-
-private:
-    union {
-        byte m_data[4];
-        dword m_data_as_dword;
-    };
-};
-
-static_assert(sizeof(IPv4Address) == 4);
-
-namespace AK {
-
-template<>
-struct Traits<IPv4Address> {
-    static unsigned hash(const IPv4Address& address) { return string_hash((const char*)&address, sizeof(address)); }
-    static void dump(const IPv4Address& address) { kprintf("%s", address.to_string().characters()); }
-};
-
-}

+ 2 - 3
Kernel/NetworkAdapter.h

@@ -4,9 +4,8 @@
 #include <AK/SinglyLinkedList.h>
 #include <AK/Types.h>
 #include <Kernel/MACAddress.h>
-#include <Kernel/IPv4Address.h>
-#include <Kernel/ARPPacket.h>
-#include <Kernel/IPv4Packet.h>
+#include <Kernel/IPv4.h>
+#include <Kernel/ARP.h>
 #include <Kernel/ICMP.h>
 
 class NetworkAdapter {

+ 3 - 3
Kernel/NetworkTask.cpp

@@ -1,8 +1,8 @@
 #include <Kernel/E1000NetworkAdapter.h>
 #include <Kernel/EthernetFrameHeader.h>
-#include <Kernel/ARPPacket.h>
+#include <Kernel/ARP.h>
 #include <Kernel/ICMP.h>
-#include <Kernel/IPv4Packet.h>
+#include <Kernel/IPv4.h>
 #include <Kernel/Process.h>
 #include <Kernel/EtherType.h>
 #include <AK/Lock.h>
@@ -33,7 +33,7 @@ void NetworkTask_main()
     for (;;) {
         auto packet = e1000.dequeue_packet();
         if (packet.is_null()) {
-            sleep(100);
+            sleep(1);
             continue;
         }
         if (packet.size() < (int)(sizeof(EthernetFrameHeader))) {

+ 1 - 1
Kernel/Process.cpp

@@ -24,7 +24,7 @@
 #include <AK/StringBuilder.h>
 #include <Kernel/E1000NetworkAdapter.h>
 #include <Kernel/EthernetFrameHeader.h>
-#include <Kernel/ARPPacket.h>
+#include <Kernel/ARP.h>
 
 //#define DEBUG_IO
 //#define TASK_DEBUG