def _test_ip4_gtk_drop(devs, apdevs, params, dst):
    require_under_vm()
    procfile = '/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast' % devs[0].ifname
    if not os.path.exists(procfile):
        raise HwsimSkip("kernel doesn't have capability")

    [dev, hapd] = hs20_filters_connect(devs, apdevs)
    with IPAssign(dev.ifname, '10.0.0.1/24'):
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.bind(("10.0.0.1", 12345))
        s.settimeout(0.1)

        pkt = dst
        pkt += hapd.own_addr().replace(':', '')
        pkt += '0800'
        pkt += '45000020786840004011ae600a0000040a000001'
        pkt += '30393039000c0000'
        pkt += '61736466' # "asdf"
        if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
            raise Exception("DATA_TEST_FRAME failed")
        try:
            logger.info(s.recvfrom(1024))
            logger.info("procfile=" + procfile + " val=" + open(procfile,'r').read().rstrip())
            raise Exception("erroneously received frame!")
        except socket.timeout:
            # this is the expected behaviour
            pass
Example #2
0
def _test_ip4_gtk_drop(devs, apdevs, params, dst):
    require_under_vm()
    procfile = '/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast' % devs[
        0].ifname
    if not os.path.exists(procfile):
        raise HwsimSkip("kernel doesn't have capability")

    [dev, hapd] = hs20_filters_connect(devs, apdevs)
    with IPAssign(dev.ifname, '10.0.0.1/24'):
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.bind(("10.0.0.1", 12345))
        s.settimeout(0.1)

        pkt = dst
        pkt += hapd.own_addr().replace(':', '')
        pkt += '0800'
        pkt += '45000020786840004011ae600a0000040a000001'
        pkt += '30393039000c0000'
        pkt += '61736466'  # "asdf"
        if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
            raise Exception("DATA_TEST_FRAME failed")
        try:
            logger.info(s.recvfrom(1024))
            logger.info("procfile=" + procfile + " val=" +
                        open(procfile, 'r').read().rstrip())
            raise Exception("erroneously received frame!")
        except socket.timeout:
            # this is the expected behaviour
            pass
def test_ip6_drop_unsolicited_na(devs, apdevs, params):
    require_under_vm()
    procfile = '/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na' % devs[0].ifname
    if not os.path.exists(procfile):
        raise HwsimSkip("kernel doesn't have capability")

    [dev, hapd] = hs20_filters_connect(devs, apdevs)

    with IPAssign(dev.ifname, 'fdaa::1/48', ipv6=True):
        # add an entry that can be updated by unsolicited NA
        subprocess.call(['ip', '-6', 'neigh', 'add', 'fdaa::2', 'lladdr', '02:00:00:00:00:ff', 'nud', 'reachable', 'dev', dev.ifname])
        try:
            ap_addr = hapd.own_addr()
            cl_addr = dev.own_addr()
            pkt = build_na(ap_addr, 'fdaa::2', 'ff02::1', 'fdaa::2', flags=0x20,
                           opt=binascii.unhexlify('0201' + ap_addr.replace(':', '')))
            pkt = binascii.hexlify(pkt)

            if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
                raise Exception("DATA_TEST_FRAME failed")

            if hapd.own_addr() in subprocess.check_output(['ip', 'neigh', 'show']):
                raise Exception("unsolicited NA frame updated erroneously")
        finally:
            subprocess.call(['ip', '-6', 'neigh', 'del', 'fdaa::2', 'dev', dev.ifname])
Example #4
0
def test_radius_acct_unreachable3(dev, apdev):
    """RADIUS Accounting server initially unreachable, but then available"""
    require_under_vm()
    subprocess.call(['ip', 'ro', 'replace', 'blackhole', '192.168.213.18'])
    as_hapd = hostapd.Hostapd("as")
    as_mib_start = as_hapd.get_mib(param="radius_server")
    params = hostapd.wpa2_eap_params(ssid="radius-acct")
    params['acct_server_addr'] = "192.168.213.18"
    params['acct_server_port'] = "1813"
    params['acct_server_shared_secret'] = "radius"
    hostapd.add_ap(apdev[0]['ifname'], params)
    hapd = hostapd.Hostapd(apdev[0]['ifname'])
    connect(dev[0], "radius-acct")
    subprocess.call(['ip', 'ro', 'del', 'blackhole', '192.168.213.18'])
    time.sleep(0.1)
    dev[0].request("DISCONNECT")
    hapd.set('acct_server_addr_replace', '127.0.0.1')
    dev[0].request("RECONNECT")
    dev[0].wait_connected()
    time.sleep(1)
    as_mib_end = as_hapd.get_mib(param="radius_server")
    req_s = int(as_mib_start['radiusAccServTotalResponses'])
    req_e = int(as_mib_end['radiusAccServTotalResponses'])
    if req_e <= req_s:
        raise Exception("Unexpected RADIUS server acct MIB value")
Example #5
0
def test_ip4_drop_gratuitous_arp(devs, apdevs, params):
    require_under_vm()
    procfile = '/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp' % devs[0].ifname
    if not os.path.exists(procfile):
        raise HwsimSkip("kernel doesn't have capability")

    [dev, hapd] = hs20_filters_connect(devs, apdevs)

    with IPAssign(dev.ifname, '10.0.0.2/24'):
        # add an entry that can be updated by gratuitous ARP
        subprocess.call([
            'ip', 'neigh', 'add', '10.0.0.1', 'lladdr', '02:00:00:00:00:ff',
            'nud', 'reachable', 'dev', dev.ifname
        ])
        # wait for lock-time
        time.sleep(1)
        try:
            ap_addr = hapd.own_addr()
            cl_addr = dev.own_addr()
            pkt = build_arp(cl_addr, ap_addr, 2, ap_addr, '10.0.0.1', ap_addr,
                            '10.0.0.1')
            pkt = binascii.hexlify(pkt).decode()

            if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
                raise Exception("DATA_TEST_FRAME failed")

            if hapd.own_addr() in subprocess.check_output(
                ['ip', 'neigh', 'show']).decode():
                raise Exception("gratuitous ARP frame updated erroneously")
        finally:
            subprocess.call(
                ['ip', 'neigh', 'del', '10.0.0.1', 'dev', dev.ifname])
Example #6
0
def test_ip6_drop_unsolicited_na(devs, apdevs, params):
    require_under_vm()
    procfile = '/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na' % devs[0].ifname
    if not os.path.exists(procfile):
        raise HwsimSkip("kernel doesn't have capability")

    [dev, hapd] = hs20_filters_connect(devs, apdevs)

    with IPAssign(dev.ifname, 'fdaa::1/48', ipv6=True):
        # add an entry that can be updated by unsolicited NA
        subprocess.call([
            'ip', '-6', 'neigh', 'add', 'fdaa::2', 'lladdr',
            '02:00:00:00:00:ff', 'nud', 'reachable', 'dev', dev.ifname
        ])
        try:
            ap_addr = hapd.own_addr()
            cl_addr = dev.own_addr()
            pkt = build_na(ap_addr,
                           'fdaa::2',
                           'ff02::1',
                           'fdaa::2',
                           flags=0x20,
                           opt=binascii.unhexlify('0201' +
                                                  ap_addr.replace(':', '')))
            pkt = binascii.hexlify(pkt).decode()

            if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
                raise Exception("DATA_TEST_FRAME failed")

            if hapd.own_addr() in subprocess.check_output(
                ['ip', 'neigh', 'show']).decode():
                raise Exception("unsolicited NA frame updated erroneously")
        finally:
            subprocess.call(
                ['ip', '-6', 'neigh', 'del', 'fdaa::2', 'dev', dev.ifname])
def test_ip4_drop_gratuitous_arp(devs, apdevs, params):
    require_under_vm()
    procfile = '/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp' % devs[0].ifname
    if not os.path.exists(procfile):
        raise HwsimSkip("kernel doesn't have capability")

    [dev, hapd] = hs20_filters_connect(devs, apdevs)

    with IPAssign(dev.ifname, '10.0.0.2/24'):
        # add an entry that can be updated by gratuitous ARP
        subprocess.call(['ip', 'neigh', 'add', '10.0.0.1', 'lladdr', '02:00:00:00:00:ff', 'nud', 'reachable', 'dev', dev.ifname])
        # wait for lock-time
        time.sleep(1)
        try:
            ap_addr = hapd.own_addr()
            cl_addr = dev.own_addr()
            pkt = build_arp(cl_addr, ap_addr, 2, ap_addr, '10.0.0.1', ap_addr, '10.0.0.1')
            pkt = binascii.hexlify(pkt)

            if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
                raise Exception("DATA_TEST_FRAME failed")

            if hapd.own_addr() in subprocess.check_output(['ip', 'neigh', 'show']):
                raise Exception("gratuitous ARP frame updated erroneously")
        finally:
            subprocess.call(['ip', 'neigh', 'del', '10.0.0.1', 'dev', dev.ifname])
Example #8
0
def test_radius_acct_unreachable3(dev, apdev):
    """RADIUS Accounting server initially unreachable, but then available"""
    require_under_vm()
    subprocess.call(['ip', 'ro', 'replace', 'blackhole', '192.168.213.18'])
    as_hapd = hostapd.Hostapd("as")
    as_mib_start = as_hapd.get_mib(param="radius_server")
    params = hostapd.wpa2_eap_params(ssid="radius-acct")
    params['acct_server_addr'] = "192.168.213.18"
    params['acct_server_port'] = "1813"
    params['acct_server_shared_secret'] = "radius"
    hostapd.add_ap(apdev[0]['ifname'], params)
    hapd = hostapd.Hostapd(apdev[0]['ifname'])
    connect(dev[0], "radius-acct")
    subprocess.call(['ip', 'ro', 'del', 'blackhole', '192.168.213.18'])
    time.sleep(0.1)
    dev[0].request("DISCONNECT")
    hapd.set('acct_server_addr_replace', '127.0.0.1')
    dev[0].request("RECONNECT")
    dev[0].wait_connected()
    time.sleep(1)
    as_mib_end = as_hapd.get_mib(param="radius_server")
    req_s = int(as_mib_start['radiusAccServTotalResponses'])
    req_e = int(as_mib_end['radiusAccServTotalResponses'])
    if req_e <= req_s:
        raise Exception("Unexpected RADIUS server acct MIB value")
def test_ap_iapp(dev, apdev):
    """IAPP and multiple BSSes"""
    require_under_vm()
    try:
        _test_ap_iapp(dev, apdev)
    finally:
        subprocess.call(['ifconfig', 'br-multicast', 'down'],
                        stderr=open('/dev/null', 'w'))
        subprocess.call(['brctl', 'delbr', 'br-multicast'],
                        stderr=open('/dev/null', 'w'))
Example #10
0
def test_ap_iapp(dev, apdev):
    """IAPP and multiple BSSes"""
    require_under_vm()
    try:
        _test_ap_iapp(dev, apdev)
    finally:
        subprocess.call(['ifconfig', 'br-multicast', 'down'],
                        stderr=open('/dev/null', 'w'))
        subprocess.call(['brctl', 'delbr', 'br-multicast'],
                        stderr=open('/dev/null', 'w'))
Example #11
0
def test_ip6_drop_unsolicited_na(devs, apdevs, params):
    require_under_vm()
    dev = devs[0]
    procfile = '/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na' % dev.ifname
    if not os.path.exists(procfile):
        raise HwsimSkip("kernel doesn't have capability")

    ap_params = {'ssid': 'open', 'channel': '5'}
    hapd = hostapd.add_ap(apdevs[0]['ifname'], ap_params)
    dev.connect('open', key_mgmt="NONE", scan_freq="2432")

    with IPAssign(dev.ifname, 'fdaa::1/48', ipv6=True):
        # add an entry that can be updated by unsolicited NA
        subprocess.call([
            'ip', '-6', 'neigh', 'add', 'fdaa::2', 'lladdr',
            '02:00:00:00:00:ff', 'nud', 'reachable', 'dev', dev.ifname
        ])
        try:
            ap_addr = hapd.own_addr()
            cl_addr = dev.own_addr()
            pkt = build_na(ap_addr,
                           'fdaa::2',
                           'ff02::1',
                           'fdaa::2',
                           flags=0x20,
                           opt=binascii.unhexlify('0201' +
                                                  ap_addr.replace(':', '')))
            pkt = binascii.hexlify(pkt)

            if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
                raise Exception("DATA_TEST_FRAME failed")

            if not hapd.own_addr() in subprocess.check_output(
                ['ip', 'neigh', 'show']):
                raise Exception("unsolicited NA frame failed to update")

            subprocess.call([
                'ip', '-6', 'neigh', 'replace', 'fdaa::2', 'lladdr',
                '02:00:00:00:00:ff', 'nud', 'reachable', 'dev', dev.ifname
            ])

            open(procfile, 'w').write('1')

            if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
                raise Exception("DATA_TEST_FRAME failed")

            if hapd.own_addr() in subprocess.check_output(
                ['ip', 'neigh', 'show']):
                raise Exception("unsolicited NA frame updated erroneously")
        finally:
            subprocess.call(
                ['ip', '-6', 'neigh', 'del', 'fdaa::2', 'dev', dev.ifname])
            open(procfile, 'w').write('0')
Example #12
0
def test_ip4_drop_gratuitous_arp(devs, apdevs, params):
    require_under_vm()
    dev = devs[0]
    procfile = '/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp' % dev.ifname
    if not os.path.exists(procfile):
        raise HwsimSkip("kernel doesn't have capability")

    ap_params = {'ssid': 'open', 'channel': '5'}
    hapd = hostapd.add_ap(apdevs[0]['ifname'], ap_params)
    dev.connect('open', key_mgmt="NONE", scan_freq="2432")

    with IPAssign(dev.ifname, '10.0.0.2/24'):
        # add an entry that can be updated by gratuitous ARP
        subprocess.call([
            'ip', 'neigh', 'add', '10.0.0.1', 'lladdr', '02:00:00:00:00:ff',
            'nud', 'reachable', 'dev', dev.ifname
        ])
        # wait for lock-time
        time.sleep(1)
        try:
            ap_addr = hapd.own_addr()
            cl_addr = dev.own_addr()
            pkt = build_arp(cl_addr, ap_addr, 2, ap_addr, '10.0.0.1', ap_addr,
                            '10.0.0.1')
            pkt = binascii.hexlify(pkt)

            if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
                raise Exception("DATA_TEST_FRAME failed")

            if not hapd.own_addr() in subprocess.check_output(
                ['ip', 'neigh', 'show']):
                raise Exception("gratuitous ARP frame failed to update")

            subprocess.call([
                'ip', 'neigh', 'replace', '10.0.0.1', 'lladdr',
                '02:00:00:00:00:ff', 'nud', 'reachable', 'dev', dev.ifname
            ])
            # wait for lock-time
            time.sleep(1)

            open(procfile, 'w').write('1')

            if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
                raise Exception("DATA_TEST_FRAME failed")

            if hapd.own_addr() in subprocess.check_output(
                ['ip', 'neigh', 'show']):
                raise Exception("gratuitous ARP frame updated erroneously")
        finally:
            subprocess.call(
                ['ip', 'neigh', 'del', '10.0.0.1', 'dev', dev.ifname])
            open(procfile, 'w').write('0')
Example #13
0
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'))
Example #14
0
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'))
Example #15
0
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'))
Example #16
0
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 _test_ip6_gtk_drop(devs, apdevs, params, dst):
    require_under_vm()
    dev = devs[0]
    procfile = '/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast' % dev.ifname
    if not os.path.exists(procfile):
        raise HwsimSkip("kernel doesn't have capability")

    ap_params = { 'ssid': 'open', 'channel': '5' }
    hapd = hostapd.add_ap(apdevs[0]['ifname'], ap_params)
    dev.connect('open', key_mgmt="NONE", scan_freq="2432")

    with IPAssign(dev.ifname, 'fdaa::1/48', ipv6=True):
        s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
        s.bind(("fdaa::1", 12345))
        s.settimeout(0.1)

        pkt = dst
        pkt += hapd.own_addr().replace(':', '')
        pkt += '86dd'
        pkt += '60000000000c1140fdaa0000000000000000000000000002fdaa0000000000000000000000000001'
        pkt += '30393039000cde31'
        pkt += '61736466' # "asdf"
        if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
            raise Exception("DATA_TEST_FRAME failed")

        data, addr = s.recvfrom(1024)
        if data != 'asdf':
            raise Exception("invalid data received")

        open(procfile, 'w').write('1')
        try:
            if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
                raise Exception("DATA_TEST_FRAME failed")

            try:
                print s.recvfrom(1024)
                raise Exception("erroneously received frame!")
            except socket.timeout:
                # this is the expected behaviour
                pass
        finally:
            open(procfile, 'w').write('0')
Example #18
0
def _test_ip6_gtk_drop(devs, apdevs, params, dst):
    require_under_vm()
    dev = devs[0]
    procfile = '/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast' % dev.ifname
    if not os.path.exists(procfile):
        raise HwsimSkip("kernel doesn't have capability")

    ap_params = {'ssid': 'open', 'channel': '5'}
    hapd = hostapd.add_ap(apdevs[0]['ifname'], ap_params)
    dev.connect('open', key_mgmt="NONE", scan_freq="2432")

    with IPAssign(dev.ifname, 'fdaa::1/48', ipv6=True):
        s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
        s.bind(("fdaa::1", 12345))
        s.settimeout(0.1)

        pkt = dst
        pkt += hapd.own_addr().replace(':', '')
        pkt += '86dd'
        pkt += '60000000000c1140fdaa0000000000000000000000000002fdaa0000000000000000000000000001'
        pkt += '30393039000cde31'
        pkt += '61736466'  # "asdf"
        if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
            raise Exception("DATA_TEST_FRAME failed")

        data, addr = s.recvfrom(1024)
        if data != 'asdf':
            raise Exception("invalid data received")

        open(procfile, 'w').write('1')
        try:
            if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
                raise Exception("DATA_TEST_FRAME failed")

            try:
                print s.recvfrom(1024)
                raise Exception("erroneously received frame!")
            except socket.timeout:
                # this is the expected behaviour
                pass
        finally:
            open(procfile, 'w').write('0')
def test_ip4_drop_gratuitous_arp(devs, apdevs, params):
    require_under_vm()
    dev = devs[0]
    procfile = '/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp' % dev.ifname
    if not os.path.exists(procfile):
        raise HwsimSkip("kernel doesn't have capability")

    ap_params = { 'ssid': 'open', 'channel': '5' }
    hapd = hostapd.add_ap(apdevs[0]['ifname'], ap_params)
    dev.connect('open', key_mgmt="NONE", scan_freq="2432")

    with IPAssign(dev.ifname, '10.0.0.2/24'):
        # add an entry that can be updated by gratuitous ARP
        subprocess.call(['ip', 'neigh', 'add', '10.0.0.1', 'lladdr', '02:00:00:00:00:ff', 'nud', 'reachable', 'dev', dev.ifname])
        # wait for lock-time
        time.sleep(1)
        try:
            ap_addr = hapd.own_addr()
            cl_addr = dev.own_addr()
            pkt = build_arp(cl_addr, ap_addr, 2, ap_addr, '10.0.0.1', ap_addr, '10.0.0.1')
            pkt = binascii.hexlify(pkt)

            if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
                raise Exception("DATA_TEST_FRAME failed")

            if not hapd.own_addr() in subprocess.check_output(['ip', 'neigh', 'show']):
                raise Exception("gratuitous ARP frame failed to update")

            subprocess.call(['ip', 'neigh', 'replace', '10.0.0.1', 'lladdr', '02:00:00:00:00:ff', 'nud', 'reachable', 'dev', dev.ifname])
            # wait for lock-time
            time.sleep(1)

            open(procfile, 'w').write('1')

            if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
                raise Exception("DATA_TEST_FRAME failed")

            if hapd.own_addr() in subprocess.check_output(['ip', 'neigh', 'show']):
                raise Exception("gratuitous ARP frame updated erroneously")
        finally:
            subprocess.call(['ip', 'neigh', 'del', '10.0.0.1', 'dev', dev.ifname])
            open(procfile, 'w').write('0')
def test_ip6_drop_unsolicited_na(devs, apdevs, params):
    require_under_vm()
    dev = devs[0]
    procfile = '/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na' % dev.ifname
    if not os.path.exists(procfile):
        raise HwsimSkip("kernel doesn't have capability")

    ap_params = { 'ssid': 'open', 'channel': '5' }
    hapd = hostapd.add_ap(apdevs[0]['ifname'], ap_params)
    dev.connect('open', key_mgmt="NONE", scan_freq="2432")

    with IPAssign(dev.ifname, 'fdaa::1/48', ipv6=True):
        # add an entry that can be updated by unsolicited NA
        subprocess.call(['ip', '-6', 'neigh', 'add', 'fdaa::2', 'lladdr', '02:00:00:00:00:ff', 'nud', 'reachable', 'dev', dev.ifname])
        try:
            ap_addr = hapd.own_addr()
            cl_addr = dev.own_addr()
            pkt = build_na(ap_addr, 'fdaa::2', 'ff02::1', 'fdaa::2', flags=0x20,
                           opt=binascii.unhexlify('0201' + ap_addr.replace(':', '')))
            pkt = binascii.hexlify(pkt)

            if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
                raise Exception("DATA_TEST_FRAME failed")

            if not hapd.own_addr() in subprocess.check_output(['ip', 'neigh', 'show']):
                raise Exception("unsolicited NA frame failed to update")

            subprocess.call(['ip', '-6', 'neigh', 'replace', 'fdaa::2', 'lladdr', '02:00:00:00:00:ff', 'nud', 'reachable', 'dev', dev.ifname])

            open(procfile, 'w').write('1')

            if "OK" not in hapd.request('DATA_TEST_FRAME ' + pkt):
                raise Exception("DATA_TEST_FRAME failed")

            if hapd.own_addr() in subprocess.check_output(['ip', 'neigh', 'show']):
                raise Exception("unsolicited NA frame updated erroneously")
        finally:
            subprocess.call(['ip', '-6', 'neigh', 'del', 'fdaa::2', 'dev', dev.ifname])
            open(procfile, 'w').write('0')