diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-09-27 17:49:56 -0700 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-10-01 17:22:17 +0000 |
commit | 2770433d300e0892498014173f57794291e3f4ba (patch) | |
tree | 8192486c7e88c8f6889c4fa0192e9371484e07ef | |
parent | 33a9f908a6bd56f5a52550b9208365b5ac0d5a07 (diff) | |
download | serenity-2770433d300e0892498014173f57794291e3f4ba.zip |
Kernel: Convert network adapter names to Kernel::KString
Another step of incremental progress of removing `AK::String` from the
kernel, to harden against OOM.
-rw-r--r-- | Kernel/Net/E1000ENetworkAdapter.cpp | 8 | ||||
-rw-r--r-- | Kernel/Net/E1000ENetworkAdapter.h | 4 | ||||
-rw-r--r-- | Kernel/Net/E1000NetworkAdapter.cpp | 10 | ||||
-rw-r--r-- | Kernel/Net/E1000NetworkAdapter.h | 4 | ||||
-rw-r--r-- | Kernel/Net/LoopbackAdapter.cpp | 9 | ||||
-rw-r--r-- | Kernel/Net/LoopbackAdapter.h | 2 | ||||
-rw-r--r-- | Kernel/Net/NE2000NetworkAdapter.cpp | 11 | ||||
-rw-r--r-- | Kernel/Net/NE2000NetworkAdapter.h | 4 | ||||
-rw-r--r-- | Kernel/Net/NetworkAdapter.cpp | 17 | ||||
-rw-r--r-- | Kernel/Net/NetworkAdapter.h | 9 | ||||
-rw-r--r-- | Kernel/Net/NetworkingManagement.cpp | 20 | ||||
-rw-r--r-- | Kernel/Net/RTL8139NetworkAdapter.cpp | 10 | ||||
-rw-r--r-- | Kernel/Net/RTL8139NetworkAdapter.h | 4 | ||||
-rw-r--r-- | Kernel/Net/RTL8168NetworkAdapter.cpp | 11 | ||||
-rw-r--r-- | Kernel/Net/RTL8168NetworkAdapter.h | 4 | ||||
-rw-r--r-- | Kernel/Net/Socket.cpp | 5 |
16 files changed, 64 insertions, 68 deletions
diff --git a/Kernel/Net/E1000ENetworkAdapter.cpp b/Kernel/Net/E1000ENetworkAdapter.cpp index e33a2d577c..15a0699a13 100644 --- a/Kernel/Net/E1000ENetworkAdapter.cpp +++ b/Kernel/Net/E1000ENetworkAdapter.cpp @@ -180,14 +180,14 @@ static bool is_valid_device_id(u16 device_id) } } -UNMAP_AFTER_INIT RefPtr<E1000ENetworkAdapter> E1000ENetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier) +UNMAP_AFTER_INIT RefPtr<E1000ENetworkAdapter> E1000ENetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier, NonnullOwnPtr<KString> interface_name) { if (pci_device_identifier.hardware_id().vendor_id != PCI::VendorID::Intel) return {}; if (!is_valid_device_id(pci_device_identifier.hardware_id().device_id)) return {}; u8 irq = pci_device_identifier.interrupt_line().value(); - auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000ENetworkAdapter(pci_device_identifier.address(), irq)); + auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000ENetworkAdapter(pci_device_identifier.address(), irq, move(interface_name))); if (!adapter) return {}; if (adapter->initialize()) @@ -228,8 +228,8 @@ UNMAP_AFTER_INIT bool E1000ENetworkAdapter::initialize() return true; } -UNMAP_AFTER_INIT E1000ENetworkAdapter::E1000ENetworkAdapter(PCI::Address address, u8 irq) - : E1000NetworkAdapter(address, irq) +UNMAP_AFTER_INIT E1000ENetworkAdapter::E1000ENetworkAdapter(PCI::Address address, u8 irq, NonnullOwnPtr<KString> interface_name) + : E1000NetworkAdapter(address, irq, move(interface_name)) { } diff --git a/Kernel/Net/E1000ENetworkAdapter.h b/Kernel/Net/E1000ENetworkAdapter.h index 9b44f7b451..2203820632 100644 --- a/Kernel/Net/E1000ENetworkAdapter.h +++ b/Kernel/Net/E1000ENetworkAdapter.h @@ -21,7 +21,7 @@ namespace Kernel { class E1000ENetworkAdapter final : public E1000NetworkAdapter { public: - static RefPtr<E1000ENetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&); + static RefPtr<E1000ENetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&, NonnullOwnPtr<KString>); virtual bool initialize() override; @@ -30,7 +30,7 @@ public: virtual StringView purpose() const override { return class_name(); } private: - E1000ENetworkAdapter(PCI::Address, u8 irq); + E1000ENetworkAdapter(PCI::Address, u8 irq, NonnullOwnPtr<KString>); virtual StringView class_name() const override { return "E1000ENetworkAdapter"sv; } diff --git a/Kernel/Net/E1000NetworkAdapter.cpp b/Kernel/Net/E1000NetworkAdapter.cpp index 04679da459..46097bb9af 100644 --- a/Kernel/Net/E1000NetworkAdapter.cpp +++ b/Kernel/Net/E1000NetworkAdapter.cpp @@ -158,14 +158,14 @@ UNMAP_AFTER_INIT static bool is_valid_device_id(u16 device_id) } } -UNMAP_AFTER_INIT RefPtr<E1000NetworkAdapter> E1000NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier) +UNMAP_AFTER_INIT RefPtr<E1000NetworkAdapter> E1000NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier, NonnullOwnPtr<KString> interface_name) { if (pci_device_identifier.hardware_id().vendor_id != PCI::VendorID::Intel) return {}; if (!is_valid_device_id(pci_device_identifier.hardware_id().device_id)) return {}; u8 irq = pci_device_identifier.interrupt_line().value(); - auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000NetworkAdapter(pci_device_identifier.address(), irq)); + auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000NetworkAdapter(pci_device_identifier.address(), irq, move(interface_name))); if (!adapter) return {}; if (adapter->initialize()) @@ -219,13 +219,13 @@ UNMAP_AFTER_INIT bool E1000NetworkAdapter::initialize() return true; } -UNMAP_AFTER_INIT E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address address, u8 irq) - : PCI::Device(address) +UNMAP_AFTER_INIT E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address address, u8 irq, NonnullOwnPtr<KString> interface_name) + : NetworkAdapter(move(interface_name)) + , PCI::Device(address) , IRQHandler(irq) , m_rx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(e1000_rx_desc) * number_of_rx_descriptors + 16), "E1000 RX Descriptors", Memory::Region::Access::ReadWrite).release_value()) , m_tx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(e1000_tx_desc) * number_of_tx_descriptors + 16), "E1000 TX Descriptors", Memory::Region::Access::ReadWrite).release_value()) { - set_interface_name(pci_address()); } UNMAP_AFTER_INIT E1000NetworkAdapter::~E1000NetworkAdapter() diff --git a/Kernel/Net/E1000NetworkAdapter.h b/Kernel/Net/E1000NetworkAdapter.h index c8fe19ce91..e695e4fd07 100644 --- a/Kernel/Net/E1000NetworkAdapter.h +++ b/Kernel/Net/E1000NetworkAdapter.h @@ -20,7 +20,7 @@ class E1000NetworkAdapter : public NetworkAdapter , public PCI::Device , public IRQHandler { public: - static RefPtr<E1000NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&); + static RefPtr<E1000NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&, NonnullOwnPtr<KString>); virtual bool initialize(); @@ -37,7 +37,7 @@ protected: void setup_interrupts(); void setup_link(); - E1000NetworkAdapter(PCI::Address, u8 irq); + E1000NetworkAdapter(PCI::Address, u8 irq, NonnullOwnPtr<KString>); virtual bool handle_irq(const RegisterState&) override; virtual StringView class_name() const override { return "E1000NetworkAdapter"sv; } diff --git a/Kernel/Net/LoopbackAdapter.cpp b/Kernel/Net/LoopbackAdapter.cpp index 28f5a2e7f4..b0027ca6d9 100644 --- a/Kernel/Net/LoopbackAdapter.cpp +++ b/Kernel/Net/LoopbackAdapter.cpp @@ -13,14 +13,17 @@ static bool s_loopback_initialized = false; RefPtr<LoopbackAdapter> LoopbackAdapter::try_create() { - return adopt_ref_if_nonnull(new LoopbackAdapter()); + auto interface_name = KString::try_create("loop"sv); + if (interface_name.is_error()) + return {}; + return adopt_ref_if_nonnull(new LoopbackAdapter(interface_name.release_value())); } -LoopbackAdapter::LoopbackAdapter() +LoopbackAdapter::LoopbackAdapter(NonnullOwnPtr<KString> interface_name) + : NetworkAdapter(move(interface_name)) { VERIFY(!s_loopback_initialized); s_loopback_initialized = true; - set_loopback_name(); set_mtu(65536); set_mac_address({ 19, 85, 2, 9, 0x55, 0xaa }); } diff --git a/Kernel/Net/LoopbackAdapter.h b/Kernel/Net/LoopbackAdapter.h index fb75abb3c0..62d6770f93 100644 --- a/Kernel/Net/LoopbackAdapter.h +++ b/Kernel/Net/LoopbackAdapter.h @@ -14,7 +14,7 @@ class LoopbackAdapter final : public NetworkAdapter { AK_MAKE_ETERNAL private: - LoopbackAdapter(); + LoopbackAdapter(NonnullOwnPtr<KString>); public: static RefPtr<LoopbackAdapter> try_create(); diff --git a/Kernel/Net/NE2000NetworkAdapter.cpp b/Kernel/Net/NE2000NetworkAdapter.cpp index 0277a8e7d2..7319262b27 100644 --- a/Kernel/Net/NE2000NetworkAdapter.cpp +++ b/Kernel/Net/NE2000NetworkAdapter.cpp @@ -137,7 +137,7 @@ struct [[gnu::packed]] received_packet_header { u16 length; }; -UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier) +UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier, NonnullOwnPtr<KString> interface_name) { constexpr auto ne2k_ids = Array { PCI::HardwareID { 0x10EC, 0x8029 }, // RealTek RTL-8029(AS) @@ -157,16 +157,15 @@ UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initi if (!ne2k_ids.span().contains_slow(pci_device_identifier.hardware_id())) return {}; u8 irq = pci_device_identifier.interrupt_line().value(); - return adopt_ref_if_nonnull(new (nothrow) NE2000NetworkAdapter(pci_device_identifier.address(), irq)); + return adopt_ref_if_nonnull(new (nothrow) NE2000NetworkAdapter(pci_device_identifier.address(), irq, move(interface_name))); } -UNMAP_AFTER_INIT NE2000NetworkAdapter::NE2000NetworkAdapter(PCI::Address address, u8 irq) - : PCI::Device(address) +UNMAP_AFTER_INIT NE2000NetworkAdapter::NE2000NetworkAdapter(PCI::Address address, u8 irq, NonnullOwnPtr<KString> interface_name) + : NetworkAdapter(move(interface_name)) + , PCI::Device(address) , IRQHandler(irq) , m_io_base(PCI::get_BAR0(pci_address()) & ~3) { - set_interface_name(address); - dmesgln("NE2000: Found @ {}", pci_address()); dmesgln("NE2000: Port base: {}", m_io_base); diff --git a/Kernel/Net/NE2000NetworkAdapter.h b/Kernel/Net/NE2000NetworkAdapter.h index 9fb65d057d..51e2c33769 100644 --- a/Kernel/Net/NE2000NetworkAdapter.h +++ b/Kernel/Net/NE2000NetworkAdapter.h @@ -20,7 +20,7 @@ class NE2000NetworkAdapter final : public NetworkAdapter , public PCI::Device , public IRQHandler { public: - static RefPtr<NE2000NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&); + static RefPtr<NE2000NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&, NonnullOwnPtr<KString>); virtual ~NE2000NetworkAdapter() override; @@ -41,7 +41,7 @@ public: virtual StringView purpose() const override { return class_name(); } private: - NE2000NetworkAdapter(PCI::Address, u8 irq); + NE2000NetworkAdapter(PCI::Address, u8, NonnullOwnPtr<KString>); virtual bool handle_irq(const RegisterState&) override; virtual StringView class_name() const override { return "NE2000NetworkAdapter"sv; } diff --git a/Kernel/Net/NetworkAdapter.cpp b/Kernel/Net/NetworkAdapter.cpp index fa19933643..3b82ef1598 100644 --- a/Kernel/Net/NetworkAdapter.cpp +++ b/Kernel/Net/NetworkAdapter.cpp @@ -15,7 +15,8 @@ namespace Kernel { -NetworkAdapter::NetworkAdapter() +NetworkAdapter::NetworkAdapter(NonnullOwnPtr<KString> interface_name) + : m_name(move(interface_name)) { } @@ -165,18 +166,4 @@ void NetworkAdapter::set_ipv4_gateway(const IPv4Address& gateway) m_ipv4_gateway = gateway; } -void NetworkAdapter::set_interface_name(const PCI::Address& pci_address) -{ - // Note: This stands for e - "Ethernet", p - "Port" as for PCI bus, "s" for slot as for PCI slot - auto name = String::formatted("ep{}s{}", pci_address.bus(), pci_address.device()); - VERIFY(!NetworkingManagement::the().lookup_by_name(name)); - m_name = move(name); -} - -void NetworkAdapter::set_loopback_name() -{ - auto name = String("loop"); - VERIFY(!NetworkingManagement::the().lookup_by_name(name)); - m_name = move(name); -} } diff --git a/Kernel/Net/NetworkAdapter.h b/Kernel/Net/NetworkAdapter.h index 6ffe197c0f..b793ef2cd8 100644 --- a/Kernel/Net/NetworkAdapter.h +++ b/Kernel/Net/NetworkAdapter.h @@ -50,7 +50,7 @@ public: virtual StringView class_name() const = 0; - const String& name() const { return m_name; } + StringView name() const { return m_name->view(); } MACAddress mac_address() { return m_mac_address; } IPv4Address ipv4_address() const { return m_ipv4_address; } IPv4Address ipv4_netmask() const { return m_ipv4_netmask; } @@ -94,14 +94,11 @@ public: void send_packet(ReadonlyBytes); protected: - NetworkAdapter(); - void set_interface_name(const PCI::Address&); + NetworkAdapter(NonnullOwnPtr<KString>); void set_mac_address(const MACAddress& mac_address) { m_mac_address = mac_address; } void did_receive(ReadonlyBytes); virtual void send_raw(ReadonlyBytes) = 0; - void set_loopback_name(); - private: MACAddress m_mac_address; IPv4Address m_ipv4_address; @@ -116,7 +113,7 @@ private: PacketList m_packet_queue; size_t m_packet_queue_size { 0 }; PacketList m_unused_packets; - String m_name; + NonnullOwnPtr<KString> m_name; u32 m_packets_in { 0 }; u32 m_bytes_in { 0 }; u32 m_packets_out { 0 }; diff --git a/Kernel/Net/NetworkingManagement.cpp b/Kernel/Net/NetworkingManagement.cpp index 8737271d1b..0f2106193b 100644 --- a/Kernel/Net/NetworkingManagement.cpp +++ b/Kernel/Net/NetworkingManagement.cpp @@ -8,6 +8,7 @@ #include <Kernel/Arch/x86/IO.h> #include <Kernel/Bus/PCI/API.h> #include <Kernel/CommandLine.h> +#include <Kernel/KString.h> #include <Kernel/Memory/AnonymousVMObject.h> #include <Kernel/Multiboot.h> #include <Kernel/Net/E1000ENetworkAdapter.h> @@ -75,15 +76,24 @@ RefPtr<NetworkAdapter> NetworkingManagement::lookup_by_name(const StringView& na UNMAP_AFTER_INIT RefPtr<NetworkAdapter> NetworkingManagement::determine_network_device(PCI::DeviceIdentifier const& device_identifier) const { - if (auto candidate = E1000NetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null()) + // Note: This stands for e - "Ethernet", p - "Port" as for PCI bus, "s" for slot as for PCI slot + auto name = String::formatted("ep{}s{}", device_identifier.address().bus(), device_identifier.address().device()); + VERIFY(!NetworkingManagement::the().lookup_by_name(name)); + + // TODO: We need some way to to format data into a `KString`. + auto interface_name_or_error = KString::try_create(name.view()); + if (interface_name_or_error.is_error()) + return {}; + auto interface_name = interface_name_or_error.release_value(); + if (auto candidate = E1000NetworkAdapter::try_to_initialize(device_identifier, move(interface_name)); !candidate.is_null()) return candidate; - if (auto candidate = E1000ENetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null()) + if (auto candidate = E1000ENetworkAdapter::try_to_initialize(device_identifier, move(interface_name)); !candidate.is_null()) return candidate; - if (auto candidate = RTL8139NetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null()) + if (auto candidate = RTL8139NetworkAdapter::try_to_initialize(device_identifier, move(interface_name)); !candidate.is_null()) return candidate; - if (auto candidate = RTL8168NetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null()) + if (auto candidate = RTL8168NetworkAdapter::try_to_initialize(device_identifier, move(interface_name)); !candidate.is_null()) return candidate; - if (auto candidate = NE2000NetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null()) + if (auto candidate = NE2000NetworkAdapter::try_to_initialize(device_identifier, move(interface_name)); !candidate.is_null()) return candidate; return {}; } diff --git a/Kernel/Net/RTL8139NetworkAdapter.cpp b/Kernel/Net/RTL8139NetworkAdapter.cpp index 0a10542bf7..91bb8a797f 100644 --- a/Kernel/Net/RTL8139NetworkAdapter.cpp +++ b/Kernel/Net/RTL8139NetworkAdapter.cpp @@ -112,24 +112,24 @@ namespace Kernel { #define RX_BUFFER_SIZE 32768 #define TX_BUFFER_SIZE PACKET_SIZE_MAX -UNMAP_AFTER_INIT RefPtr<RTL8139NetworkAdapter> RTL8139NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier) +UNMAP_AFTER_INIT RefPtr<RTL8139NetworkAdapter> RTL8139NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier, NonnullOwnPtr<KString> interface_name) { constexpr PCI::HardwareID rtl8139_id = { 0x10EC, 0x8139 }; if (pci_device_identifier.hardware_id() != rtl8139_id) return {}; u8 irq = pci_device_identifier.interrupt_line().value(); - return adopt_ref_if_nonnull(new (nothrow) RTL8139NetworkAdapter(pci_device_identifier.address(), irq)); + return adopt_ref_if_nonnull(new (nothrow) RTL8139NetworkAdapter(pci_device_identifier.address(), irq, move(interface_name))); } -UNMAP_AFTER_INIT RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address address, u8 irq) - : PCI::Device(address) +UNMAP_AFTER_INIT RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address address, u8 irq, NonnullOwnPtr<KString> interface_name) + : NetworkAdapter(move(interface_name)) + , PCI::Device(address) , IRQHandler(irq) , m_io_base(PCI::get_BAR0(pci_address()) & ~1) , m_rx_buffer(MM.allocate_contiguous_kernel_region(Memory::page_round_up(RX_BUFFER_SIZE + PACKET_SIZE_MAX), "RTL8139 RX", Memory::Region::Access::ReadWrite).release_value()) , m_packet_buffer(MM.allocate_contiguous_kernel_region(Memory::page_round_up(PACKET_SIZE_MAX), "RTL8139 Packet buffer", Memory::Region::Access::ReadWrite).release_value()) { m_tx_buffers.ensure_capacity(RTL8139_TX_BUFFER_COUNT); - set_interface_name(address); dmesgln("RTL8139: Found @ {}", pci_address()); diff --git a/Kernel/Net/RTL8139NetworkAdapter.h b/Kernel/Net/RTL8139NetworkAdapter.h index 929bea09f3..b365fb45b9 100644 --- a/Kernel/Net/RTL8139NetworkAdapter.h +++ b/Kernel/Net/RTL8139NetworkAdapter.h @@ -22,7 +22,7 @@ class RTL8139NetworkAdapter final : public NetworkAdapter , public PCI::Device , public IRQHandler { public: - static RefPtr<RTL8139NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&); + static RefPtr<RTL8139NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&, NonnullOwnPtr<KString>); virtual ~RTL8139NetworkAdapter() override; @@ -34,7 +34,7 @@ public: virtual StringView purpose() const override { return class_name(); } private: - RTL8139NetworkAdapter(PCI::Address, u8 irq); + RTL8139NetworkAdapter(PCI::Address, u8 irq, NonnullOwnPtr<KString>); virtual bool handle_irq(const RegisterState&) override; virtual StringView class_name() const override { return "RTL8139NetworkAdapter"sv; } diff --git a/Kernel/Net/RTL8168NetworkAdapter.cpp b/Kernel/Net/RTL8168NetworkAdapter.cpp index b3915084a7..8e77a3e975 100644 --- a/Kernel/Net/RTL8168NetworkAdapter.cpp +++ b/Kernel/Net/RTL8168NetworkAdapter.cpp @@ -181,14 +181,14 @@ namespace Kernel { #define TX_BUFFER_SIZE 0x1FF8 #define RX_BUFFER_SIZE 0x1FF8 // FIXME: this should be increased (0x3FFF) -UNMAP_AFTER_INIT RefPtr<RTL8168NetworkAdapter> RTL8168NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier) +UNMAP_AFTER_INIT RefPtr<RTL8168NetworkAdapter> RTL8168NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier, NonnullOwnPtr<KString> interface_name) { if (pci_device_identifier.hardware_id().vendor_id != PCI::VendorID::Realtek) return {}; if (pci_device_identifier.hardware_id().device_id != 0x8168) return {}; u8 irq = pci_device_identifier.interrupt_line().value(); - return adopt_ref_if_nonnull(new (nothrow) RTL8168NetworkAdapter(pci_device_identifier.address(), irq)); + return adopt_ref_if_nonnull(new (nothrow) RTL8168NetworkAdapter(pci_device_identifier.address(), irq, move(interface_name))); } bool RTL8168NetworkAdapter::determine_supported_version() const @@ -236,15 +236,14 @@ bool RTL8168NetworkAdapter::determine_supported_version() const } } -UNMAP_AFTER_INIT RTL8168NetworkAdapter::RTL8168NetworkAdapter(PCI::Address address, u8 irq) - : PCI::Device(address) +UNMAP_AFTER_INIT RTL8168NetworkAdapter::RTL8168NetworkAdapter(PCI::Address address, u8 irq, NonnullOwnPtr<KString> interface_name) + : NetworkAdapter(move(interface_name)) + , PCI::Device(address) , IRQHandler(irq) , m_io_base(PCI::get_BAR0(pci_address()) & ~1) , m_rx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(TXDescriptor) * (number_of_rx_descriptors + 1)), "RTL8168 RX", Memory::Region::Access::ReadWrite).release_value()) , m_tx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(RXDescriptor) * (number_of_tx_descriptors + 1)), "RTL8168 TX", Memory::Region::Access::ReadWrite).release_value()) { - set_interface_name(address); - dmesgln("RTL8168: Found @ {}", pci_address()); dmesgln("RTL8168: I/O port base: {}", m_io_base); diff --git a/Kernel/Net/RTL8168NetworkAdapter.h b/Kernel/Net/RTL8168NetworkAdapter.h index 0f03462184..6b65bc3d1b 100644 --- a/Kernel/Net/RTL8168NetworkAdapter.h +++ b/Kernel/Net/RTL8168NetworkAdapter.h @@ -22,7 +22,7 @@ class RTL8168NetworkAdapter final : public NetworkAdapter , public PCI::Device , public IRQHandler { public: - static RefPtr<RTL8168NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&); + static RefPtr<RTL8168NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&, NonnullOwnPtr<KString>); virtual ~RTL8168NetworkAdapter() override; @@ -38,7 +38,7 @@ private: static const size_t number_of_rx_descriptors = 64; static const size_t number_of_tx_descriptors = 16; - RTL8168NetworkAdapter(PCI::Address, u8 irq); + RTL8168NetworkAdapter(PCI::Address, u8 irq, NonnullOwnPtr<KString>); virtual bool handle_irq(const RegisterState&) override; virtual StringView class_name() const override { return "RTL8168NetworkAdapter"sv; } diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp index f8a7de1275..812448d784 100644 --- a/Kernel/Net/Socket.cpp +++ b/Kernel/Net/Socket.cpp @@ -170,9 +170,10 @@ KResult Socket::getsockopt(OpenFileDescription&, int level, int option, Userspac if (size < IFNAMSIZ) return EINVAL; if (m_bound_interface) { - const auto& name = m_bound_interface->name(); + auto name = m_bound_interface->name(); auto length = name.length() + 1; - TRY(copy_to_user(static_ptr_cast<char*>(value), name.characters(), length)); + auto characters = name.characters_without_null_termination(); + TRY(copy_to_user(static_ptr_cast<char*>(value), characters, length)); size = length; return copy_to_user(value_size, &size); } else { |