Generate ACL files correctly instead of hardcoded values. Send them also to the remote client if required. Signed-off-by: Janusz Dziedzic <janusz.dziedzic@xxxxxxxxx> --- tests/hwsim/hostapd.accept | 2 -- tests/hwsim/hostapd.accept2 | 3 --- tests/hwsim/hostapd.macaddr | 7 ------ tests/hwsim/hostapd_conf.py | 34 +++++++++++++++++++++++++ tests/hwsim/test_ap_ft.py | 47 +++++++++++++++++++++++++---------- tests/hwsim/test_ap_params.py | 13 +++++++--- tests/hwsim/test_ap_vlan.py | 33 ++++++++++++++++++------ tests/hwsim/test_hapd_ctrl.py | 13 +++++++--- 8 files changed, 113 insertions(+), 39 deletions(-) delete mode 100644 tests/hwsim/hostapd.accept delete mode 100644 tests/hwsim/hostapd.accept2 delete mode 100644 tests/hwsim/hostapd.macaddr create mode 100644 tests/hwsim/hostapd_conf.py diff --git a/tests/hwsim/hostapd.accept b/tests/hwsim/hostapd.accept deleted file mode 100644 index ce455b1a2..000000000 --- a/tests/hwsim/hostapd.accept +++ /dev/null @@ -1,2 +0,0 @@ -02:00:00:00:00:00 1 -02:00:00:00:01:00 2 diff --git a/tests/hwsim/hostapd.accept2 b/tests/hwsim/hostapd.accept2 deleted file mode 100644 index 3d41e348a..000000000 --- a/tests/hwsim/hostapd.accept2 +++ /dev/null @@ -1,3 +0,0 @@ -02:00:00:00:00:00 1 -02:00:00:00:01:00 2 -02:00:00:00:02:00 3 diff --git a/tests/hwsim/hostapd.macaddr b/tests/hwsim/hostapd.macaddr deleted file mode 100644 index a3b7878b5..000000000 --- a/tests/hwsim/hostapd.macaddr +++ /dev/null @@ -1,7 +0,0 @@ -02:00:00:00:00:00 -02:00:00:00:00:12 -02:00:00:00:00:34 --02:00:00:00:00:12 --02:00:00:00:00:34 -01:01:01:01:01:01 -03:01:01:01:01:03 diff --git a/tests/hwsim/hostapd_conf.py b/tests/hwsim/hostapd_conf.py new file mode 100644 index 000000000..2243d1f24 --- /dev/null +++ b/tests/hwsim/hostapd_conf.py @@ -0,0 +1,34 @@ +import hostapd +import os + +def acl_file(dev, apdev, conf): + filename = os.path.join("/tmp", conf) + + if conf == 'hostapd.macaddr': + with open(filename, 'w') as f: + mac0 = dev[0].get_status_field("address") + f.write(mac0 + '\n') + f.write("02:00:00:00:00:12\n") + f.write("02:00:00:00:00:34\n") + f.write("-02:00:00:00:00:12\n") + f.write("-02:00:00:00:00:34\n") + f.write("01:01:01:01:01:01\n") + f.write("03:01:01:01:01:03\n") + elif conf == 'hostapd.accept': + with open(filename, 'w') as f: + mac0 = dev[0].get_status_field("address") + mac1 = dev[1].get_status_field("address") + f.write(mac0 + " 1\n") + f.write(mac1 + " 2\n") + elif conf == 'hostapd.accept2': + with open(filename, 'w') as f: + mac0 = dev[0].get_status_field("address") + mac1 = dev[1].get_status_field("address") + mac2 = dev[2].get_status_field("address") + f.write(mac0 + " 1\n") + f.write(mac1 + " 2\n") + f.write(mac2 + " 3\n") + else: + return conf + + return filename diff --git a/tests/hwsim/test_ap_ft.py b/tests/hwsim/test_ap_ft.py index 51a070e8e..035be6c79 100644 --- a/tests/hwsim/test_ap_ft.py +++ b/tests/hwsim/test_ap_ft.py @@ -23,6 +23,7 @@ from wlantest import Wlantest from test_ap_psk import check_mib, find_wpas_process, read_process_memory, verify_not_present, get_key_locations from test_rrm import check_beacon_req from test_suite_b import check_suite_b_192_capa +import hostapd_conf def ft_base_rsn(): params = {"wpa": "2", @@ -336,15 +337,18 @@ def test_ap_ft_vlan(dev, apdev): """WPA2-PSK-FT AP with VLAN""" ssid = "test-ft" passphrase = "12345678" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.accept') + hostapd.send_file(apdev[0], filename, filename) + hostapd.send_file(apdev[1], filename, filename) params = ft_params1(ssid=ssid, passphrase=passphrase) params['dynamic_vlan'] = "1" - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename hapd0 = hostapd.add_ap(apdev[0]['ifname'], params) params = ft_params2(ssid=ssid, passphrase=passphrase) params['dynamic_vlan'] = "1" - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename hapd1 = hostapd.add_ap(apdev[1]['ifname'], params) run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, conndev="brvlan1") @@ -355,16 +359,19 @@ def test_ap_ft_vlan_disconnected(dev, apdev): """WPA2-PSK-FT AP with VLAN and local key generation""" ssid = "test-ft" passphrase = "12345678" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.accept') + hostapd.send_file(apdev[0], filename, filename) + hostapd.send_file(apdev[1], filename, filename) params = ft_params1a(ssid=ssid, passphrase=passphrase) params['dynamic_vlan'] = "1" - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename params['ft_psk_generate_local'] = "1" hapd0 = hostapd.add_ap(apdev[0]['ifname'], params) params = ft_params2a(ssid=ssid, passphrase=passphrase) params['dynamic_vlan'] = "1" - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename params['ft_psk_generate_local'] = "1" hapd1 = hostapd.add_ap(apdev[1]['ifname'], params) @@ -376,10 +383,12 @@ def test_ap_ft_vlan_2(dev, apdev): """WPA2-PSK-FT AP with VLAN and dest-AP does not have VLAN info locally""" ssid = "test-ft" passphrase = "12345678" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.accept') + hostapd.send_file(apdev[0], filename, filename) params = ft_params1(ssid=ssid, passphrase=passphrase) params['dynamic_vlan'] = "1" - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename hapd0 = hostapd.add_ap(apdev[0]['ifname'], params) params = ft_params2(ssid=ssid, passphrase=passphrase) @@ -407,15 +416,18 @@ def test_ap_ft_many_vlan(dev, apdev): """WPA2-PSK-FT AP with VLAN multiple times""" ssid = "test-ft" passphrase = "12345678" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.accept') + hostapd.send_file(apdev[0], filename, filename) + hostapd.send_file(apdev[1], filename, filename) params = ft_params1(ssid=ssid, passphrase=passphrase) params['dynamic_vlan'] = "1" - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename hapd0 = hostapd.add_ap(apdev[0]['ifname'], params) params = ft_params2(ssid=ssid, passphrase=passphrase) params['dynamic_vlan'] = "1" - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename hapd1 = hostapd.add_ap(apdev[1]['ifname'], params) run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, roams=50, @@ -707,14 +719,17 @@ def test_ap_ft_vlan_over_ds(dev, apdev): """WPA2-PSK-FT AP over DS with VLAN""" ssid = "test-ft" passphrase = "12345678" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.accept') + hostapd.send_file(apdev[0], filename, filename) + hostapd.send_file(apdev[1], filename, filename) params = ft_params1(ssid=ssid, passphrase=passphrase) params['dynamic_vlan'] = "1" - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename hapd0 = hostapd.add_ap(apdev[0]['ifname'], params) params = ft_params2(ssid=ssid, passphrase=passphrase) params['dynamic_vlan'] = "1" - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename hapd1 = hostapd.add_ap(apdev[1]['ifname'], params) run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True, @@ -739,14 +754,17 @@ def test_ap_ft_vlan_over_ds_many(dev, apdev): """WPA2-PSK-FT AP over DS with VLAN multiple times""" ssid = "test-ft" passphrase = "12345678" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.accept') + hostapd.send_file(apdev[0], filename, filename) + hostapd.send_file(apdev[1], filename, filename) params = ft_params1(ssid=ssid, passphrase=passphrase) params['dynamic_vlan'] = "1" - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename hapd0 = hostapd.add_ap(apdev[0]['ifname'], params) params = ft_params2(ssid=ssid, passphrase=passphrase) params['dynamic_vlan'] = "1" - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename hapd1 = hostapd.add_ap(apdev[1]['ifname'], params) run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True, @@ -944,16 +962,19 @@ def test_ap_ft_over_ds_pull_vlan(dev, apdev): """WPA2-PSK-FT AP over DS (pull PMK) with VLAN""" ssid = "test-ft" passphrase = "12345678" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.accept') + hostapd.send_file(apdev[0], filename, filename) + hostapd.send_file(apdev[1], filename, filename) params = ft_params1(ssid=ssid, passphrase=passphrase) params["pmk_r1_push"] = "0" params['dynamic_vlan'] = "1" - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename hapd0 = hostapd.add_ap(apdev[0]['ifname'], params) params = ft_params2(ssid=ssid, passphrase=passphrase) params["pmk_r1_push"] = "0" params['dynamic_vlan'] = "1" - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename hapd1 = hostapd.add_ap(apdev[1]['ifname'], params) run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True, diff --git a/tests/hwsim/test_ap_params.py b/tests/hwsim/test_ap_params.py index 8e4ab8e3b..303c14464 100644 --- a/tests/hwsim/test_ap_params.py +++ b/tests/hwsim/test_ap_params.py @@ -16,6 +16,7 @@ import hwsim_utils import hostapd from tshark import run_tshark from utils import alloc_fail, HwsimSkip, parse_ie +import hostapd_conf @remote_compatible def test_ap_fragmentation_rts_set_high(dev, apdev): @@ -140,8 +141,10 @@ def test_ap_acl_accept(dev, apdev): """MAC ACL accept list""" ssid = "acl" params = {} + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.macaddr') + hostapd.send_file(apdev[0], filename, filename) params['ssid'] = ssid - params['accept_mac_file'] = "hostapd.macaddr" + params['accept_mac_file'] = filename hapd = hostapd.add_ap(apdev[0], params) dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412") @@ -161,8 +164,10 @@ def test_ap_acl_deny(dev, apdev): """MAC ACL deny list""" ssid = "acl" params = {} + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.macaddr') + hostapd.send_file(apdev[0], filename, filename) params['ssid'] = ssid - params['deny_mac_file'] = "hostapd.macaddr" + params['deny_mac_file'] = filename hapd = hostapd.add_ap(apdev[0], params) dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", passive=True) dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False) @@ -176,8 +181,10 @@ def test_ap_acl_mgmt(dev, apdev): """MAC ACL accept/deny management""" ssid = "acl" params = {} + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.macaddr') + hostapd.send_file(apdev[0], filename, filename) params['ssid'] = ssid - params['deny_mac_file'] = "hostapd.macaddr" + params['deny_mac_file'] = filename hapd = hostapd.add_ap(apdev[0], params) accept = hapd.request("ACCEPT_ACL SHOW").splitlines() diff --git a/tests/hwsim/test_ap_vlan.py b/tests/hwsim/test_ap_vlan.py index 305889aa1..510ce7dcd 100644 --- a/tests/hwsim/test_ap_vlan.py +++ b/tests/hwsim/test_ap_vlan.py @@ -23,12 +23,15 @@ import hostapd from utils import iface_is_in_bridge, HwsimSkip, alloc_fail import os from tshark import run_tshark +import hostapd_conf def test_ap_vlan_open(dev, apdev): """AP VLAN with open network""" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.accept') + hostapd.send_file(apdev[0], filename, filename) params = {"ssid": "test-vlan-open", "dynamic_vlan": "1", - "accept_mac_file": "hostapd.accept"} + "accept_mac_file": filename} hapd = hostapd.add_ap(apdev[0], params) dev[0].connect("test-vlan-open", key_mgmt="NONE", scan_freq="2412") @@ -40,10 +43,12 @@ def test_ap_vlan_open(dev, apdev): def test_ap_vlan_file_open(dev, apdev): """AP VLAN with open network and vlan_file mapping""" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.accept') + hostapd.send_file(apdev[0], filename, filename) params = {"ssid": "test-vlan-open", "dynamic_vlan": "1", "vlan_file": "hostapd.vlan", - "accept_mac_file": "hostapd.accept"} + "accept_mac_file": filename} hapd = hostapd.add_ap(apdev[0], params) dev[0].connect("test-vlan-open", key_mgmt="NONE", scan_freq="2412") @@ -55,10 +60,12 @@ def test_ap_vlan_file_open(dev, apdev): def test_ap_vlan_file_open2(dev, apdev): """AP VLAN with open network and vlan_file mapping (2)""" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.accept2') + hostapd.send_file(apdev[0], filename, filename) params = {"ssid": "test-vlan-open", "dynamic_vlan": "1", "vlan_file": "hostapd.vlan2", - "accept_mac_file": "hostapd.accept2"} + "accept_mac_file": filename} hapd = hostapd.add_ap(apdev[0], params) dev[0].connect("test-vlan-open", key_mgmt="NONE", scan_freq="2412") @@ -109,10 +116,12 @@ def test_ap_vlan_file_parsing(dev, apdev, params): def test_ap_vlan_wpa2(dev, apdev): """AP VLAN with WPA2-PSK""" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.accept') + hostapd.send_file(apdev[0], filename, filename) params = hostapd.wpa2_params(ssid="test-vlan", passphrase="12345678") params['dynamic_vlan'] = "1" - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename hapd = hostapd.add_ap(apdev[0], params) dev[0].connect("test-vlan", psk="12345678", scan_freq="2412") @@ -166,11 +175,13 @@ def test_ap_vlan_wpa2_radius_2(dev, apdev): def test_ap_vlan_wpa2_radius_local(dev, apdev): """AP VLAN with WPA2-Enterprise and local file setting VLAN IDs""" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.accept') + hostapd.send_file(apdev[0], filename, filename) params = hostapd.wpa2_eap_params(ssid="test-vlan") params['dynamic_vlan'] = "0" params['vlan_file'] = "hostapd.vlan" params['vlan_bridge'] = "test_br_vlan" - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename hapd = hostapd.add_ap(apdev[0], params) dev[0].connect("test-vlan", key_mgmt="WPA-EAP", eap="PAX", @@ -340,10 +351,12 @@ def test_ap_vlan_wpa2_radius_required(dev, apdev): def test_ap_vlan_tagged(dev, apdev): """AP VLAN with tagged interface""" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.accept') + hostapd.send_file(apdev[0], filename, filename) params = {"ssid": "test-vlan-open", "dynamic_vlan": "1", "vlan_tagged_interface": "lo", - "accept_mac_file": "hostapd.accept"} + "accept_mac_file": filename} hapd = hostapd.add_ap(apdev[0], params) dev[0].connect("test-vlan-open", key_mgmt="NONE", scan_freq="2412") @@ -546,6 +559,8 @@ def test_ap_vlan_iface_cleanup_multibss_per_sta_vif(dev, apdev): def test_ap_vlan_without_station(dev, apdev, p): """AP VLAN with WPA2-PSK and no station""" try: + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.accept') + hostapd.send_file(apdev[0], filename, filename) subprocess.call(['brctl', 'addbr', 'brvlan1']) subprocess.call(['brctl', 'setfd', 'brvlan1', '0']) subprocess.call(['ifconfig', 'brvlan1', 'up']) @@ -555,7 +570,7 @@ def test_ap_vlan_without_station(dev, apdev, p): passphrase="12345678x") params['dynamic_vlan'] = "1" params['vlan_file'] = 'hostapd.wlan3.vlan' - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename hapd = hostapd.add_ap(apdev[0], params) # inject some traffic @@ -707,10 +722,12 @@ def test_ap_vlan_wpa2_radius_mixed(dev, apdev): def test_ap_vlan_reconnect(dev, apdev): """AP VLAN with WPA2-PSK connect, disconnect, connect""" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.accept') + hostapd.send_file(apdev[0], filename, filename) params = hostapd.wpa2_params(ssid="test-vlan", passphrase="12345678") params['dynamic_vlan'] = "1" - params['accept_mac_file'] = "hostapd.accept" + params['accept_mac_file'] = filename hapd = hostapd.add_ap(apdev[0], params) logger.info("connect sta") diff --git a/tests/hwsim/test_hapd_ctrl.py b/tests/hwsim/test_hapd_ctrl.py index 5b802e478..f7ac231dc 100644 --- a/tests/hwsim/test_hapd_ctrl.py +++ b/tests/hwsim/test_hapd_ctrl.py @@ -10,6 +10,7 @@ from remotehost import remote_compatible import hostapd import hwsim_utils from utils import skip_with_fips, alloc_fail, fail_test, HwsimSkip +import hostapd_conf @remote_compatible def test_hapd_ctrl_status(dev, apdev): @@ -283,11 +284,13 @@ def test_hapd_ctrl_ess_disassoc(dev, apdev): def test_hapd_ctrl_set_deny_mac_file(dev, apdev): """hostapd and SET deny_mac_file ctrl_iface command""" ssid = "hapd-ctrl" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.macaddr') params = {"ssid": ssid} hapd = hostapd.add_ap(apdev[0], params) dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412") dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412") - if "OK" not in hapd.request("SET deny_mac_file hostapd.macaddr"): + hapd.send_file(filename, filename) + if "OK" not in hapd.request("SET deny_mac_file " + filename): raise Exception("Unexpected SET failure") dev[0].wait_disconnected(timeout=15) ev = dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"], 1) @@ -297,12 +300,14 @@ def test_hapd_ctrl_set_deny_mac_file(dev, apdev): def test_hapd_ctrl_set_accept_mac_file(dev, apdev): """hostapd and SET accept_mac_file ctrl_iface command""" ssid = "hapd-ctrl" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.macaddr') params = {"ssid": ssid} hapd = hostapd.add_ap(apdev[0], params) dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412") dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412") + hapd.send_file(filename, filename) hapd.request("SET macaddr_acl 1") - if "OK" not in hapd.request("SET accept_mac_file hostapd.macaddr"): + if "OK" not in hapd.request("SET accept_mac_file " + filename): raise Exception("Unexpected SET failure") dev[1].wait_disconnected(timeout=15) ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], 1) @@ -312,12 +317,14 @@ def test_hapd_ctrl_set_accept_mac_file(dev, apdev): def test_hapd_ctrl_set_accept_mac_file_vlan(dev, apdev): """hostapd and SET accept_mac_file ctrl_iface command (VLAN ID)""" ssid = "hapd-ctrl" + filename = hostapd_conf.acl_file(dev, apdev, 'hostapd.accept') params = {"ssid": ssid} hapd = hostapd.add_ap(apdev[0], params) dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412") dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412") + hapd.send_file(filename, filename) hapd.request("SET macaddr_acl 1") - if "OK" not in hapd.request("SET accept_mac_file hostapd.accept"): + if "OK" not in hapd.request("SET accept_mac_file " + filename): raise Exception("Unexpected SET failure") dev[1].wait_disconnected(timeout=15) dev[0].wait_disconnected(timeout=15) -- 2.17.1 _______________________________________________ Hostap mailing list Hostap@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/hostap