hostapd: Find device by MAC address

With wireless device as members in bridges, we cannot predict the name
very well. So we will use the MAC address and find the correct device
name when we launch hostapd.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
Michael Tremer
2021-04-16 11:53:30 +02:00
parent 46f445b1a7
commit 53d03ef352
4 changed files with 100 additions and 18 deletions

View File

@@ -332,6 +332,28 @@ sub setup_upstream_proxy() {
}
}
sub list_wireless_interfaces() {
my %interfaces = ();
opendir(INTERFACES, "/sys/class/net");
my $intf;
while ($intf = readdir(INTERFACES)) {
# Is this a wireless interface?
opendir(PHY80211, "/sys/class/net/$intf/phy80211") or next;
closedir(PHY80211);
# Read the MAC address
my $address = &get_nic_property($intf, "address");
$interfaces{$address} = "$address ($intf)";
}
closedir(INTERFACES);
return %interfaces;
}
my %wireless_status = ();
sub _get_wireless_status($) {
@@ -416,7 +438,7 @@ sub get_nic_property {
my $property = shift;
my $result;
open(FILE, "/sys/class/net/$nicname/$property") or die("Could not read property");
open(FILE, "/sys/class/net/$nicname/$property") or die("Could not read property $property for $nicname");
$result = <FILE>;
close(FILE);
@@ -465,6 +487,28 @@ sub get_mac_by_name($) {
return $mac;
}
sub get_intf_by_address($) {
my $address = shift;
opendir(INTERFACES, "/sys/class/net");
while (my $intf = readdir(INTERFACES)) {
next if ($intf eq "." or $intf eq "..");
my $intf_address = &get_nic_property($intf, "address");
# Skip interfaces without addresses
next if ($intf_address eq "");
# Return a match
return $intf if ($intf_address eq $address);
}
closedir(INTERFACES);
return undef;
}
#
## Function to get a list of all available network zones.
#