This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "IPFire 2.x development tree".
The branch, master has been updated via 758565ce8655e33a01cbcdd8ec5daac85b055a9f (commit) via 84624b2a3687ef3250c2fb8aeed0565f72e6c5de (commit) via 45b1fc5c7f9c7cba421293c3d93735916cc65d72 (commit) via 62cd95c2994deb7aaf4b740406ce5a827e4d3b88 (commit) from cea9d7b39810c91a12e7773217758abebe26466d (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- commit 758565ce8655e33a01cbcdd8ec5daac85b055a9f Author: Michael Tremer michael.tremer@ipfire.org Date: Fri Apr 16 10:05:02 2021 +0000
hostapd: Bump package version
Signed-off-by: Michael Tremer michael.tremer@ipfire.org
commit 84624b2a3687ef3250c2fb8aeed0565f72e6c5de Author: Michael Tremer michael.tremer@ipfire.org Date: Fri Apr 16 12:00:01 2021 +0200
hostaopd: Drop box with links to other configuration pages
We do not have this for any other feature and it clutters the UI.
Signed-off-by: Michael Tremer michael.tremer@ipfire.org
commit 45b1fc5c7f9c7cba421293c3d93735916cc65d72 Author: Michael Tremer michael.tremer@ipfire.org Date: Fri Apr 16 11:53:30 2021 +0200
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
commit 62cd95c2994deb7aaf4b740406ce5a827e4d3b88 Author: Michael Tremer michael.tremer@ipfire.org Date: Wed Apr 14 20:49:21 2021 +0200
hostapd: Drop custom configuration from initscript
The initscript it setting a lot of options which are set by hostapd which will fail to start the AP instead of using fire-and-forget.
Signed-off-by: Michael Tremer michael.tremer@ipfire.org
-----------------------------------------------------------------------
Summary of changes: config/cfgroot/network-functions.pl | 46 ++++++++++++++- html/cgi-bin/wlanap.cgi | 50 ++++++++--------- lfs/hostapd | 2 +- src/initscripts/packages/hostapd | 109 +++++++----------------------------- src/paks/hostapd/install.sh | 11 ++++ 5 files changed, 100 insertions(+), 118 deletions(-)
Difference in files: diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-functions.pl index 9908ee8ab..2f704dfbf 100644 --- a/config/cfgroot/network-functions.pl +++ b/config/cfgroot/network-functions.pl @@ -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. # diff --git a/html/cgi-bin/wlanap.cgi b/html/cgi-bin/wlanap.cgi index 01dcaeea2..602d4d3c1 100644 --- a/html/cgi-bin/wlanap.cgi +++ b/html/cgi-bin/wlanap.cgi @@ -81,6 +81,9 @@ $wlanapsettings{'IEEE80211W'} = 'off'; &General::readhash("/var/ipfire/wlanap/settings", %wlanapsettings); &Header::getcgihash(%wlanapsettings);
+# Find the selected interface +my $INTF = &Network::get_intf_by_address($wlanapsettings{'INTERFACE'}); + my @macs = $wlanapsettings{'MACS'};
delete $wlanapsettings{'__CGI__'}; @@ -193,8 +196,11 @@ my $wlan_card_status = 'dummy'; my $wlan_ap_status = ''; my $message = "";
-$selected{'INTERFACE'}{'green0'} = ''; -$selected{'INTERFACE'}{'blue0'} = ''; +my %INTERFACES = &Network::list_wireless_interfaces(); + +foreach my $intf (keys %INTERFACES) { + $selected{'INTERFACE'}{$intf} = ''; +} $selected{'ENC'}{$wlanapsettings{'INTERFACE'}} = "selected='selected'";
if ( ($wlanapsettings{'INTERFACE'} eq '') ){ @@ -206,11 +212,12 @@ $message<br /> <select name='INTERFACE'> END ; - if ( $netsettings{'BLUE_DEV'} ne ''){ - print "<option value='blue0' $selected{'INTERFACE'}{'blue0'}>blue0</option>"; + + foreach my $intf (sort keys %INTERFACES) { + print "<option value='${intf}' $selected{'INTERFACE'}{$intf}>$INTERFACES{$intf}</option>"; } + print <<END - <option value='green0' $selected{'INTERFACE'}{'green0'}>green0</option> </select> <br /><br /> <hr size='1'> @@ -222,18 +229,18 @@ END &Header::closepage(); exit; }else{ - my $cmd_out = `/usr/sbin/iwconfig $wlanapsettings{'INTERFACE'} 2>/dev/null`; + my $cmd_out = `/usr/sbin/iwconfig $INTF 2>/dev/null`;
if ( $cmd_out eq '' ){ $message = "$Lang::tr{'wlanap no interface'}"; $wlan_card_status = ''; }else{ - $cmd_out = `/sbin/ifconfig | /bin/grep $wlanapsettings{'INTERFACE'}`; + $cmd_out = `/sbin/ifconfig $INTF`; if ( $cmd_out eq '' ){ $wlan_card_status = 'down'; }else{ $wlan_card_status = 'up'; - $cmd_out = `/usr/sbin/iwconfig $wlanapsettings{'INTERFACE'} | /bin/grep "Mode:Master"`; + $cmd_out = `/usr/sbin/iwconfig $INTF | /bin/grep "Mode:Master"`; if ( $cmd_out ne '' ){ $wlan_ap_status = 'up'; } @@ -270,16 +277,16 @@ $selected{'TXPOWER'}{$wlanapsettings{'TXPOWER'}} = "selected='selected'"; $selected{'HW_MODE'}{$wlanapsettings{'HW_MODE'}} = "selected='selected'"; $selected{'MACMODE'}{$wlanapsettings{'MACMODE'}} = "selected='selected'";
-my $monwlaninterface = $wlanapsettings{'INTERFACE'}; -if ( -d '/sys/class/net/mon.'.$wlanapsettings{'INTERFACE'} ) { - $monwlaninterface = 'mon.'.$wlanapsettings{'INTERFACE'}; +my $monwlaninterface = $INTF; +if ( -d '/sys/class/net/mon.' . $INTF) { + $monwlaninterface = 'mon.' . $INTF; }
my @channellist_cmd; my @channellist = (0);
if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){ -my $wiphy = `iw dev $wlanapsettings{'INTERFACE'} info | grep wiphy | cut -d" " -f2`; +my $wiphy = `iw dev $INTF info | grep wiphy | cut -d" " -f2`; chomp $wiphy;
@channellist_cmd = `iw phy phy$wiphy info | grep " MHz \[" | grep -v "(disabled)" | grep -v "no IBSS" | grep -v "no IR" | grep -v "passive scanning" 2>/dev/null`; @@ -318,7 +325,7 @@ my @countrylist = @temp;
my @txpower_cmd = `iwlist $monwlaninterface txpower 2>/dev/null`; if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){ - # There is a bug with NL80211 only all devices can displayed + # There is a bug with NL80211 only all devices can displaye @txpower_cmd = `iwlist txpower 2>/dev/null | sed -e "s|unknown transmit-power information.||g"`; } # get available power @@ -488,7 +495,7 @@ print <<END </table> END ; -if ( $wlanapsettings{'INTERFACE'} =~ /green0/ ){ +if ( $INTF =~ /green0/ ){ print <<END <br /> <table width='80%' cellspacing='0' class='tbl' border='1'> @@ -523,7 +530,7 @@ END ; my @status; if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){ - @status = `iw dev $wlanapsettings{'INTERFACE'} info && iw dev $wlanapsettings{'INTERFACE'} station dump && echo ""`; + @status = `iw dev $INTF info && iw dev $INTF station dump && echo ""`; } print <<END <br /> @@ -564,17 +571,7 @@ for (my $i=0;$i<$#txpower_cmd;$i=$i+2){ print "<tr><td $col>@txpower_cmd[$i]</td></tr>"; $count++; } -print "</table><br>"; -print <<END -<br /> -<table width='80%' cellspacing='0' class='tbl' border='0'> -<tr><td bgcolor='$color{'color20'}' align='left'><strong>$Lang::tr{'wlan clients'}</strong></td></tr> -<tr><td> <a href="/cgi-bin/wireless.cgi">$Lang::tr{'wlanap link wireless'}</a></td></tr> -<tr><td> <a href="/cgi-bin/dhcp.cgi">$Lang::tr{'wlanap link dhcp'}</a></td></tr> -<tr><td><br></td></tr> -</table> -END -; +print "</table>"; &Header::closebox(); print "</form>"; &Header::closebigbox(); @@ -588,7 +585,6 @@ sub WriteConfig_hostapd{ driver=$wlanapsettings{'DRIVER_HOSTAPD'} ######################### basic hostapd configuration ########################## # -interface=$wlanapsettings{'INTERFACE'} country_code=$wlanapsettings{'COUNTRY'} ieee80211d=1 ieee80211h=1 diff --git a/lfs/hostapd b/lfs/hostapd index e6b92db3a..f89326f4a 100644 --- a/lfs/hostapd +++ b/lfs/hostapd @@ -32,7 +32,7 @@ DL_FROM = $(URL_IPFIRE) DIR_APP = $(DIR_SRC)/hostap-$(VER) TARGET = $(DIR_INFO)/$(THISAPP) PROG = hostapd -PAK_VER = 54 +PAK_VER = 55
DEPS =
diff --git a/src/initscripts/packages/hostapd b/src/initscripts/packages/hostapd index 5945375f3..c559b26f0 100644 --- a/src/initscripts/packages/hostapd +++ b/src/initscripts/packages/hostapd @@ -2,6 +2,20 @@ . /etc/sysconfig/rc . ${rc_functions}
+find_interface() { + local address="${1}" + + local path + for path in /sys/class/net/*; do + if [ -s "${path}/address" ] && [ "$(<${path}/address)" = "${address}" ]; then + basename "${path}" + return 0 + fi + done + + return 1; +} + CHANNEL="6" COUNTRY="00" TXPOWER="auto" @@ -12,102 +26,19 @@ eval $(/usr/local/bin/readhash /var/ipfire/wlanap/settings)
case "${1}" in start) - mkdir -p /var/run/hostapd - - boot_mesg "Starting hostapd... " - - # Check Interface configuration - if [ ! -d "/sys/class/net/${INTERFACE}" ]; then - boot_mesg "Interface $INTERFACE doesn't exist." ${FAILURE} - echo_failure - exit 0 - fi - - if [ "$(ip link show $INTERFACE | /bin/grep "ether")" == "" ]; then - boot_mesg "Interface $INTERFACE is assigned to wlan master device." ${FAILURE} - boot_mesg "Please reboot to fix this." ${FAILURE} + interface="$(find_interface "${INTERFACE}")" + if [ -z "${interface}" ]; then + boot_mesg "Could not find interface with address ${INTERFACE} for wireless access point" echo_failure - exit 0 + exit 1 fi
- # Check if INTERFACE is an actual wireless device - if [ ! -d "/sys/class/net/${INTERFACE}/wireless" ]; then - boot_mesg "Interface $INTERFACE is not a wireless device." ${FAILURE} - echo_failure - exit 0 - fi - - # Detect driver - if [ -e "/sys/class/net/$INTERFACE/phy80211" ]; then - DRIVER="NL80211" - driver="nl80211" - elif [ "$(/bin/grep hostap /sys/class/net/$INTERFACE/uevent)" != "" ]; then - DRIVER="HOSTAP" - driver="hostap" - else - boot_mesg "Interface $INTERFACE is a not supported wireless device." ${FAILURE} - echo_failure - exit 0 - fi - - echo driver=$driver > /etc/hostapd.conf.tmp - grep -v "^driver=" /etc/hostapd.conf >> /etc/hostapd.conf.tmp - mv /etc/hostapd.conf.tmp /etc/hostapd.conf - - echo DRIVER=$DRIVER > /var/ipfire/wlanap/settings.tmp - grep -v "^DRIVER=" /var/ipfire/wlanap/settings >> /var/ipfire/wlanap/settings.tmp - chown nobody:nobody /var/ipfire/wlanap/settings.tmp - chmod 644 /var/ipfire/wlanap/settings.tmp - mv /var/ipfire/wlanap/settings.tmp /var/ipfire/wlanap/settings - - if [ "$DRIVER" == "HOSTAP" ]; then - if [ "$(/usr/sbin/iwconfig $INTERFACE | /bin/grep "Mode:Master")" == "" ]; then - boot_mesg "Setting HOSTAP wlan $INTERFACE to Master mode... " - # Set Prism Cards to master mode - /usr/bin/iwconfig $INTERFACE mode master > /dev/null - fi - fi - - # First set to any country then reset to World (00) - # and then set new country because the card is only - # reprogrammed if the region was changed. - /usr/sbin/iw reg set DE - /usr/sbin/iw reg set 00 - /usr/sbin/iw reg set $COUNTRY - - /usr/sbin/iwconfig $INTERFACE channel $CHANNEL 2>/dev/null - - ip link set ${INTERFACE} up 2>/dev/null - /usr/sbin/iwconfig $INTERFACE txpower $TXPOWER 2>/dev/null - - /usr/bin/hostapd -P /var/run/hostapd /etc/hostapd.conf >/dev/null 2>&1 & - - sleep 3 - - if [ "$(/usr/sbin/iwconfig $INTERFACE | /bin/grep "Mode:Master")" == "" ]; then - killproc /usr/bin/hostapd > /dev/null 2>&1 - boot_mesg "Try to create additional AP device ..." - ip link set ${INTERFACE} down - ip link set ${INTERFACE} name ${INTERFACE}_man - iw dev ${INTERFACE}_man interface add ${INTERFACE} type __ap - evaluate_retval; - if [ -d /sys/class/net/${INTERFACE} ]; then - /usr/bin/hostapd -P /var/run/hostapd /etc/hostapd.conf >/dev/null 2>&1 & - else - ip link set ${INTERFACE}_man down - ip link set ${INTERFACE}_man name ${INTERFACE} - fi - exit 0; - else - echo_ok - fi + boot_mesg "Starting hostapd... " + loadproc /usr/bin/hostapd -B /etc/hostapd.conf -i "${interface}" ;;
stop) boot_mesg "Stopping hostapd..." - ip link set ${INTERFACE} down > /dev/null 2>&1 - ip link set ${INTERFACE} down_man > /dev/null 2>&1 - sleep 1 killproc /usr/bin/hostapd evaluate_retval ;; diff --git a/src/paks/hostapd/install.sh b/src/paks/hostapd/install.sh index bd2441e55..2dae5364e 100644 --- a/src/paks/hostapd/install.sh +++ b/src/paks/hostapd/install.sh @@ -24,6 +24,17 @@ . /opt/pakfire/lib/functions.sh extract_files restore_backup ${NAME} + +# Convert INTERFACE setting to MAC address +( + eval $(/usr/local/bin/readhash /var/ipfire/wlanap/settings) + + if [ -n "${INTERFACE}" -a -d "/sys/class/net/${INTERFACE}" ]; then + sed -i /var/ipfire/wlanap/settings \ + -e "s/^INTERFACE=.*/INTERFACE=$(</sys/class/net/${INTERFACE}/address)/" + fi +) + ln -s ../init.d/hostapd /etc/rc.d/rc3.d/S18hostapd ln -s ../init.d/hostapd /etc/rc.d/rc0.d/K81hostapd ln -s ../init.d/hostapd /etc/rc.d/rc6.d/K81hostapd
hooks/post-receive -- IPFire 2.x development tree