From: Johannes Berg <johannes.berg@xxxxxxxxx> Add a decorator that disables IPv6 and requires running under a VM, rather than open-coding that many times. Signed-off-by: Johannes Berg <johannes.berg@xxxxxxxxx> --- tests/hwsim/test_ap_ciphers.py | 88 +++------------------------------- tests/hwsim/utils.py | 26 ++++++++++ 2 files changed, 32 insertions(+), 82 deletions(-) diff --git a/tests/hwsim/test_ap_ciphers.py b/tests/hwsim/test_ap_ciphers.py index d43831bc776a..302c16401ae6 100644 --- a/tests/hwsim/test_ap_ciphers.py +++ b/tests/hwsim/test_ap_ciphers.py @@ -663,24 +663,9 @@ def run_ap_cipher_replay_protection_sta(dev, apdev, cipher, keytype=KT_PTK): if replays < 1: raise Exception("Replays not reported") +@disable_ipv6 def test_ap_wpa2_delayed_m3_retransmission(dev, apdev): """Delayed M3 retransmission""" - require_under_vm() - try: - subprocess.call(['sysctl', '-w', 'net.ipv6.conf.all.disable_ipv6=1'], - stdout=open('/dev/null', 'w')) - subprocess.call(['sysctl', '-w', - 'net.ipv6.conf.default.disable_ipv6=1'], - stdout=open('/dev/null', 'w')) - run_ap_wpa2_delayed_m3_retransmission(dev, apdev) - finally: - subprocess.call(['sysctl', '-w', 'net.ipv6.conf.all.disable_ipv6=0'], - stdout=open('/dev/null', 'w')) - subprocess.call(['sysctl', '-w', - 'net.ipv6.conf.default.disable_ipv6=0'], - stdout=open('/dev/null', 'w')) - -def run_ap_wpa2_delayed_m3_retransmission(dev, apdev): params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678") hapd = hostapd.add_ap(apdev[0], params) @@ -726,44 +711,13 @@ def run_ap_wpa2_delayed_m3_retransmission(dev, apdev): if a < b: raise Exception("GTK RX counter decreased: idx=%d before=%d after=%d" % (i, b, a)) +@disable_ipv6 def test_ap_wpa2_delayed_m1_m3_retransmission(dev, apdev): """Delayed M1+M3 retransmission""" - require_under_vm() - try: - subprocess.call(['sysctl', '-w', 'net.ipv6.conf.all.disable_ipv6=1'], - stdout=open('/dev/null', 'w')) - subprocess.call(['sysctl', '-w', - 'net.ipv6.conf.default.disable_ipv6=1'], - stdout=open('/dev/null', 'w')) - run_ap_wpa2_delayed_m1_m3_retransmission(dev, apdev) - finally: - subprocess.call(['sysctl', '-w', 'net.ipv6.conf.all.disable_ipv6=0'], - stdout=open('/dev/null', 'w')) - subprocess.call(['sysctl', '-w', - 'net.ipv6.conf.default.disable_ipv6=0'], - stdout=open('/dev/null', 'w')) - -def test_ap_wpa2_delayed_m1_m3_retransmission2(dev, apdev): - """Delayed M1+M3 retransmission (change M1 ANonce)""" - require_under_vm() - try: - subprocess.call(['sysctl', '-w', 'net.ipv6.conf.all.disable_ipv6=1'], - stdout=open('/dev/null', 'w')) - subprocess.call(['sysctl', '-w', - 'net.ipv6.conf.default.disable_ipv6=1'], - stdout=open('/dev/null', 'w')) - run_ap_wpa2_delayed_m1_m3_retransmission(dev, apdev, True) - finally: - subprocess.call(['sysctl', '-w', 'net.ipv6.conf.all.disable_ipv6=0'], - stdout=open('/dev/null', 'w')) - subprocess.call(['sysctl', '-w', - 'net.ipv6.conf.default.disable_ipv6=0'], - stdout=open('/dev/null', 'w')) - -def run_ap_wpa2_delayed_m1_m3_retransmission(dev, apdev, - change_m1_anonce=False): params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678") hapd = hostapd.add_ap(apdev[0], params) + # not sure why this is here + change_m1_anonce=False Wlantest.setup(hapd) wt = Wlantest() @@ -812,24 +766,9 @@ def run_ap_wpa2_delayed_m1_m3_retransmission(dev, apdev, if a < b: raise Exception("GTK RX counter decreased: idx=%d before=%d after=%d" % (i, b, a)) +@disable_ipv6 def test_ap_wpa2_delayed_group_m1_retransmission(dev, apdev): """Delayed group M1 retransmission""" - require_under_vm() - try: - subprocess.call(['sysctl', '-w', 'net.ipv6.conf.all.disable_ipv6=1'], - stdout=open('/dev/null', 'w')) - subprocess.call(['sysctl', '-w', - 'net.ipv6.conf.default.disable_ipv6=1'], - stdout=open('/dev/null', 'w')) - run_ap_wpa2_delayed_group_m1_retransmission(dev, apdev) - finally: - subprocess.call(['sysctl', '-w', 'net.ipv6.conf.all.disable_ipv6=0'], - stdout=open('/dev/null', 'w')) - subprocess.call(['sysctl', '-w', - 'net.ipv6.conf.default.disable_ipv6=0'], - stdout=open('/dev/null', 'w')) - -def run_ap_wpa2_delayed_group_m1_retransmission(dev, apdev): params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678") hapd = hostapd.add_ap(apdev[0], params) @@ -867,24 +806,9 @@ def run_ap_wpa2_delayed_group_m1_retransmission(dev, apdev): if a < b: raise Exception("RX counter decreased: idx=%d before=%d after=%d" % (i, b, a)) +@disable_ipv6 def test_ap_wpa2_delayed_group_m1_retransmission_igtk(dev, apdev): """Delayed group M1 retransmission (check IGTK protection)""" - require_under_vm() - try: - subprocess.call(['sysctl', '-w', 'net.ipv6.conf.all.disable_ipv6=1'], - stdout=open('/dev/null', 'w')) - subprocess.call(['sysctl', '-w', - 'net.ipv6.conf.default.disable_ipv6=1'], - stdout=open('/dev/null', 'w')) - run_ap_wpa2_delayed_group_m1_retransmission_igtk(dev, apdev) - finally: - subprocess.call(['sysctl', '-w', 'net.ipv6.conf.all.disable_ipv6=0'], - stdout=open('/dev/null', 'w')) - subprocess.call(['sysctl', '-w', - 'net.ipv6.conf.default.disable_ipv6=0'], - stdout=open('/dev/null', 'w')) - -def run_ap_wpa2_delayed_group_m1_retransmission_igtk(dev, apdev): params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678", ieee80211w="2") hapd = hostapd.add_ap(apdev[0], params) diff --git a/tests/hwsim/utils.py b/tests/hwsim/utils.py index c259a766c0f0..007705f543e8 100644 --- a/tests/hwsim/utils.py +++ b/tests/hwsim/utils.py @@ -249,3 +249,29 @@ def set_world_reg(apdev0=None, apdev1=None, dev0=None): if dev0: dev0.cmd_execute(['iw', 'reg', 'set', '00']) time.sleep(0.1) + +def disable_ipv6(fn): + def wrapper(dev, apdev, params): + require_under_vm() + try: + subprocess.call(['sysctl', '-w', 'net.ipv6.conf.all.disable_ipv6=1'], + stdout=open('/dev/null', 'w')) + subprocess.call(['sysctl', '-w', + 'net.ipv6.conf.default.disable_ipv6=1'], + stdout=open('/dev/null', 'w')) + if fn.__code__.co_argcount > 2: + return fn(dev, apdev, params) + elif fn.__code__.co_argcount > 1: + return fn(dev, apdev) + return fn(dev) + finally: + subprocess.call(['sysctl', '-w', 'net.ipv6.conf.all.disable_ipv6=0'], + stdout=open('/dev/null', 'w')) + subprocess.call(['sysctl', '-w', + 'net.ipv6.conf.default.disable_ipv6=0'], + stdout=open('/dev/null', 'w')) + # we need the name set right for selecting / printing etc. + wrapper.__name__ = fn.__name__ + # reparent to the right module for module filtering + wrapper.__module__ = fn.__module__ + return wrapper -- 2.25.1 _______________________________________________ Hostap mailing list Hostap@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/hostap