summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-03-23 19:56:01 +0100
committerChristian Poessinger <christian@poessinger.com>2020-03-23 19:56:01 +0100
commit71561a27a0338cba7c54ea8ae9bf14b75006ddbd (patch)
tree35c4f8a8935c6ebd30ccd9a449a85dc570e8738f /src
parentaa4ba0b2ae79245c60b6cf04d666d21a18c858ab (diff)
downloadvyos-1x-71561a27a0338cba7c54ea8ae9bf14b75006ddbd.tar.gz
vyos-1x-71561a27a0338cba7c54ea8ae9bf14b75006ddbd.zip
wireless: T2151: switch to iw when adding and deleting interfaces
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/interfaces-wireless.py68
1 files changed, 40 insertions, 28 deletions
diff --git a/src/conf_mode/interfaces-wireless.py b/src/conf_mode/interfaces-wireless.py
index 8132a396c..54299b609 100755
--- a/src/conf_mode/interfaces-wireless.py
+++ b/src/conf_mode/interfaces-wireless.py
@@ -29,7 +29,7 @@ from psutil import pid_exists
from netifaces import interfaces
from netaddr import *
-from vyos.ifconfig import EthernetIf
+from vyos.ifconfig import WiFiIf
from vyos.ifconfig_vlan import apply_vlan_config, verify_vlan_config
from vyos.configdict import list_diff, vlan_to_dict
from vyos.config import Config
@@ -59,12 +59,6 @@ interface={{ intf }}
# not control any wireless/wired driver.
driver=nl80211
-#
-# What about bridge?
-# bridge=br0
-# wds_sta=1
-#
-
# Levels (minimum value for logged events):
# 0 = verbose debugging
# 1 = debugging
@@ -1420,13 +1414,24 @@ def generate(wifi):
return None
def apply(wifi):
- w = EthernetIf(wifi['intf'])
if wifi['deleted']:
+ w = WiFiIf(wifi['intf'])
# delete interface
w.remove()
else:
- # Some parts e.g. MAC address can't be changed when interface is up
- w.set_state('down')
+ # WiFi interface needs to be created on-block (e.g. mode or physical
+ # interface) instead of passing a ton of arguments, I just use a dict
+ # that is managed by vyos.ifconfig
+ conf = deepcopy(WiFiIf.get_config())
+
+ # Assign WiFi instance configuration parameters to config dict
+ conf['phy'] = wifi['phy']
+
+ # Finally create the new interface
+ w = WiFiIf(wifi['intf'], **conf)
+
+ # assign/remove VRF
+ w.set_vrf(wifi['vrf'])
# update interface description used e.g. within SNMP
w.set_alias(wifi['description'])
@@ -1461,9 +1466,6 @@ def apply(wifi):
# ignore link state changes
w.set_link_detect(wifi['disable_link_detect'])
- # assign/remove VRF
- w.set_vrf(wifi['vrf'])
-
# Change interface MAC address - re-set to real hardware address (hw-id)
# if custom mac is removed
if wifi['mac']:
@@ -1480,12 +1482,6 @@ def apply(wifi):
# configure ARP ignore
w.set_arp_ignore(wifi['ip_enable_arp_ignore'])
- # Enable/Disable interface
- if wifi['disable']:
- w.set_state('down')
- else:
- w.set_state('up')
-
# Configure interface address(es)
# - not longer required addresses get removed first
# - newly addresses will be added second
@@ -1513,27 +1509,43 @@ def apply(wifi):
vlan = e.add_vlan(vif['id'])
apply_vlan_config(vlan, vif)
+ # Enable/Disable interface - interface is always placed in
+ # administrative down state in WiFiIf class
+ if not wifi['disable']:
+ w.set_state('up')
+
+
# Physical interface is now configured. Proceed by starting hostapd or
# wpa_supplicant daemon. When type is monitor we can just skip this.
if wifi['op_mode'] == 'ap':
- cmd = 'start-stop-daemon --start --quiet'
+ cmd = 'start-stop-daemon'
+ cmd += ' --start '
+ cmd += ' --quiet'
+ cmd += ' --oknodo'
+ cmd += ' --pidfile ' + get_pid('hostapd', wifi['intf'])
cmd += ' --exec /usr/sbin/hostapd'
# now pass arguments to hostapd binary
- cmd += ' -- -B'
- cmd += ' -P {}'.format(get_pid('hostapd', wifi['intf']))
- cmd += ' {}'.format(get_conf_file('hostapd', wifi['intf']))
+ cmd += ' -- '
+ cmd += ' -B'
+ cmd += ' -P ' + get_pid('hostapd', wifi['intf'])
+ cmd += ' ' + get_conf_file('hostapd', wifi['intf'])
# execute assembled command
subprocess_cmd(cmd)
elif wifi['op_mode'] == 'station':
- cmd = 'start-stop-daemon --start --quiet'
+ cmd = 'start-stop-daemon'
+ cmd += ' --start '
+ cmd += ' --quiet'
+ cmd += ' --oknodo'
+ cmd += ' --pidfile ' + get_pid('hostapd', wifi['intf'])
cmd += ' --exec /sbin/wpa_supplicant'
# now pass arguments to hostapd binary
- cmd += ' -- -s -B -D nl80211'
- cmd += ' -P {}'.format(get_pid('wpa_supplicant', wifi['intf']))
- cmd += ' -i {}'.format(wifi['intf'])
- cmd += ' -c {}'.format(get_conf_file('wpa_supplicant', wifi['intf']))
+ cmd += ' -- '
+ cmd += ' -s -B -D nl80211'
+ cmd += ' -P ' + get_pid('wpa_supplicant', wifi['intf'])
+ cmd += ' -i ' + wifi['intf']
+ cmd += ' -c ' + get_conf_file('wpa_supplicant', wifi['intf'])
# execute assembled command
subprocess_cmd(cmd)