mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
Kernel/Net: Make interfaces to have persistent names
There's no good reason to distinguish between network interfaces based on their model. It's probably a good idea to try keep the names more persistent so scripts written for a specific network interface will be useable after hotplug event (or after rebooting with new hardware setup).
This commit is contained in:
parent
1c6d2ff21c
commit
8d0280ca09
|
@ -176,7 +176,7 @@ UNMAP_AFTER_INIT E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address address,
|
|||
, m_rx_descriptors_region(MM.allocate_contiguous_kernel_region(page_round_up(sizeof(e1000_rx_desc) * number_of_rx_descriptors + 16), "E1000 RX", Region::Access::Read | Region::Access::Write))
|
||||
, m_tx_descriptors_region(MM.allocate_contiguous_kernel_region(page_round_up(sizeof(e1000_tx_desc) * number_of_tx_descriptors + 16), "E1000 TX", Region::Access::Read | Region::Access::Write))
|
||||
{
|
||||
set_interface_name("e1k");
|
||||
set_interface_name(address);
|
||||
|
||||
dmesgln("E1000: Found @ {}", pci_address());
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ LoopbackAdapter& LoopbackAdapter::the()
|
|||
|
||||
LoopbackAdapter::LoopbackAdapter()
|
||||
{
|
||||
set_interface_name("loop");
|
||||
set_loopback_name();
|
||||
set_mtu(65536);
|
||||
set_mac_address({ 19, 85, 2, 9, 0x55, 0xaa });
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ UNMAP_AFTER_INIT NE2000NetworkAdapter::NE2000NetworkAdapter(PCI::Address address
|
|||
: PCI::Device(address, irq)
|
||||
, m_io_base(PCI::get_BAR0(pci_address()) & ~3)
|
||||
{
|
||||
set_interface_name("ne2k");
|
||||
set_interface_name(address);
|
||||
|
||||
dmesgln("NE2000: Found @ {}", pci_address());
|
||||
|
||||
|
|
|
@ -218,15 +218,18 @@ void NetworkAdapter::set_ipv4_gateway(const IPv4Address& gateway)
|
|||
m_ipv4_gateway = gateway;
|
||||
}
|
||||
|
||||
void NetworkAdapter::set_interface_name(const StringView& basename)
|
||||
void NetworkAdapter::set_interface_name(const PCI::Address& pci_address)
|
||||
{
|
||||
for (int i = 0; i < NumericLimits<int>::max(); i++) {
|
||||
auto name = String::formatted("{}{}", basename, i);
|
||||
if (!lookup_by_name(name)) {
|
||||
m_name = name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 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(!lookup_by_name(name));
|
||||
m_name = move(name);
|
||||
}
|
||||
|
||||
void NetworkAdapter::set_loopback_name()
|
||||
{
|
||||
auto name = String("loop");
|
||||
VERIFY(!lookup_by_name(name));
|
||||
m_name = move(name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <Kernel/Net/ARP.h>
|
||||
#include <Kernel/Net/ICMP.h>
|
||||
#include <Kernel/Net/IPv4.h>
|
||||
#include <Kernel/PCI/Definitions.h>
|
||||
#include <Kernel/UserOrKernelBuffer.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
@ -73,11 +74,13 @@ public:
|
|||
|
||||
protected:
|
||||
NetworkAdapter();
|
||||
void set_interface_name(const StringView& basename);
|
||||
void set_interface_name(const PCI::Address&);
|
||||
void set_mac_address(const MACAddress& mac_address) { m_mac_address = mac_address; }
|
||||
virtual void send_raw(ReadonlyBytes) = 0;
|
||||
void did_receive(ReadonlyBytes);
|
||||
|
||||
void set_loopback_name();
|
||||
|
||||
private:
|
||||
static Lockable<HashTable<NetworkAdapter*>>& all_adapters();
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ UNMAP_AFTER_INIT RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address addre
|
|||
, m_packet_buffer(MM.allocate_contiguous_kernel_region(page_round_up(PACKET_SIZE_MAX), "RTL8139 Packet buffer", Region::Access::Read | Region::Access::Write))
|
||||
{
|
||||
m_tx_buffers.ensure_capacity(RTL8139_TX_BUFFER_COUNT);
|
||||
set_interface_name("rtl8139");
|
||||
set_interface_name(address);
|
||||
|
||||
dmesgln("RTL8139: Found @ {}", pci_address());
|
||||
|
||||
|
|
Loading…
Reference in a new issue