diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-11-28 07:12:05 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-28 14:14:26 +0100 |
commit | 75ed262fe5153432bcf7ac4a1e36cf0c3008c210 (patch) | |
tree | b7e1ac93650f7f6c5881a9f2c653df6c323f084c /Kernel/Net | |
parent | 70fadbad37676500037a45778f6480399dc07623 (diff) | |
download | serenity-75ed262fe5153432bcf7ac4a1e36cf0c3008c210.zip |
Kernel+ifconfig: Add an MTU value to NetworkAdapter
This defaults to 1500 for all adapters, but LoopbackAdapter increases
it to 65536 on construction.
If an IPv4 packet is larger than the MTU, we'll need to break it into
smaller fragments before transmitting it. This part is a FIXME. :^)
Diffstat (limited to 'Kernel/Net')
-rw-r--r-- | Kernel/Net/LoopbackAdapter.cpp | 1 | ||||
-rw-r--r-- | Kernel/Net/NetworkAdapter.cpp | 14 | ||||
-rw-r--r-- | Kernel/Net/NetworkAdapter.h | 4 |
3 files changed, 15 insertions, 4 deletions
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 }; }; |