1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +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:
Liav A 2021-05-22 01:35:46 +03:00 committed by Linus Groh
parent 1c6d2ff21c
commit 8d0280ca09
6 changed files with 19 additions and 13 deletions

View file

@ -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);
}
}