diff options
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/FileSystem/ProcFS.cpp | 1 | ||||
-rw-r--r-- | Kernel/Net/LoopbackAdapter.cpp | 1 | ||||
-rw-r--r-- | Kernel/Net/NetworkAdapter.cpp | 14 | ||||
-rw-r--r-- | Kernel/Net/NetworkAdapter.h | 4 |
4 files changed, 16 insertions, 4 deletions
diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index 95e5d220ea..140834484d 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -345,6 +345,7 @@ Optional<KBuffer> procfs$net_adapters(InodeIdentifier) obj.add("packets_out", adapter.packets_out()); obj.add("bytes_out", adapter.bytes_out()); obj.add("link_up", adapter.link_up()); + obj.add("mtu", adapter.mtu()); }); array.finish(); return builder.build(); diff --git a/Kernel/Net/LoopbackAdapter.cpp b/Kernel/Net/LoopbackAdapter.cpp index 7e5c44adb0..f304c7680b 100644 --- a/Kernel/Net/LoopbackAdapter.cpp +++ b/Kernel/Net/LoopbackAdapter.cpp @@ -11,6 +11,7 @@ LoopbackAdapter& LoopbackAdapter::the() LoopbackAdapter::LoopbackAdapter() { set_interface_name("loop"); + set_mtu(65536); } LoopbackAdapter::~LoopbackAdapter() diff --git a/Kernel/Net/NetworkAdapter.cpp b/Kernel/Net/NetworkAdapter.cpp index b1617109b4..f20a963966 100644 --- a/Kernel/Net/NetworkAdapter.cpp +++ b/Kernel/Net/NetworkAdapter.cpp @@ -70,8 +70,14 @@ void NetworkAdapter::send(const MACAddress& destination, const ARPPacket& packet void NetworkAdapter::send_ipv4(const MACAddress& destination_mac, const IPv4Address& destination_ipv4, IPv4Protocol protocol, const u8* payload, size_t payload_size, u8 ttl) { - size_t size_in_bytes = sizeof(EthernetFrameHeader) + sizeof(IPv4Packet) + payload_size; - auto buffer = ByteBuffer::create_zeroed(size_in_bytes); + size_t ipv4_packet_size = sizeof(IPv4Packet) + payload_size; + if (ipv4_packet_size > mtu()) { + // FIXME: Implement IP fragmentation. + ASSERT_NOT_REACHED(); + } + + size_t ethernet_frame_size = sizeof(EthernetFrameHeader) + sizeof(IPv4Packet) + payload_size; + auto buffer = ByteBuffer::create_zeroed(ethernet_frame_size); auto& eth = *(EthernetFrameHeader*)buffer.data(); eth.set_source(mac_address()); eth.set_destination(destination_mac); @@ -87,9 +93,9 @@ void NetworkAdapter::send_ipv4(const MACAddress& destination_mac, const IPv4Addr ipv4.set_ttl(ttl); ipv4.set_checksum(ipv4.compute_checksum()); m_packets_out++; - m_bytes_out += size_in_bytes; + m_bytes_out += ethernet_frame_size; memcpy(ipv4.payload(), payload, payload_size); - send_raw((const u8*)ð, size_in_bytes); + send_raw((const u8*)ð, ethernet_frame_size); } void NetworkAdapter::did_receive(const u8* data, int length) diff --git a/Kernel/Net/NetworkAdapter.h b/Kernel/Net/NetworkAdapter.h index f1270ef552..b776121a20 100644 --- a/Kernel/Net/NetworkAdapter.h +++ b/Kernel/Net/NetworkAdapter.h @@ -41,6 +41,9 @@ public: bool has_queued_packets() const { return !m_packet_queue.is_empty(); } + u32 mtu() const { return m_mtu; } + void set_mtu(u32 mtu) { m_mtu = mtu; } + u32 packets_in() const { return m_packets_in; } u32 bytes_in() const { return m_bytes_in; } u32 packets_out() const { return m_packets_out; } @@ -66,4 +69,5 @@ private: u32 m_bytes_in { 0 }; u32 m_packets_out { 0 }; u32 m_bytes_out { 0 }; + u32 m_mtu { 1500 }; }; |