Exemplo n.º 1
0
def test_v4_request_selecting_success_chaddr(backend):

    misc.test_setup()
    srv_control.define_temporary_lease_db_backend(backend)
    srv_control.config_srv_subnet('192.168.50.0/24',
                                  '192.168.50.1-192.168.50.1')
    srv_control.build_and_send_config_files()
    srv_control.start_srv('DHCP', 'started')

    misc.test_procedure()
    srv_msg.client_requests_option(1)
    srv_msg.client_send_msg('DISCOVER')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'OFFER')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_content('yiaddr', '192.168.50.1')
    srv_msg.response_check_option_content(1, 'value', '255.255.255.0')

    misc.test_procedure()
    srv_msg.client_copy_option('server_id')
    srv_msg.client_does_include_with_value('requested_addr', '192.168.50.1')
    srv_msg.client_requests_option(1)
    srv_msg.client_send_msg('REQUEST')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'ACK')
    srv_msg.response_check_content('yiaddr', '192.168.50.1')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
    srv_msg.check_leases(srv_msg.get_all_leases(), backend=backend)
Exemplo n.º 2
0
def test_v4_host_reservation_duplicate_ip_reservations_allowed(backend):
    the_same_ip_address = '192.168.50.10'
    misc.test_setup()
    srv_control.config_srv_subnet('192.168.50.0/24',
                                  '192.168.50.1-192.168.50.50')
    srv_control.add_hooks('libdhcp_host_cmds.so')
    srv_control.open_control_channel()
    srv_control.agent_control_channel(world.f_cfg.mgmt_address)
    srv_control.enable_db_backend_reservation(backend)
    # allow non-unique IP address in multiple reservations
    srv_control.set_conf_parameter_global('ip-reservations-unique', False)
    if backend == 'memfile':
        srv_control.host_reservation_in_subnet(
            'ip-address',
            the_same_ip_address,  # the same IP
            0,
            'hw-address',
            'aa:aa:aa:aa:aa:aa')
        srv_control.host_reservation_in_subnet(
            'ip-address',
            the_same_ip_address,  # the same IP
            0,
            'hw-address',
            'bb:bb:bb:bb:bb:bb')

    srv_control.build_and_send_config_files()
    srv_control.start_srv('DHCP', 'started')

    if backend != "memfile":
        assert _add_reservation({
            "hw-address": "aa:aa:aa:aa:aa:aa",
            "ip-address": the_same_ip_address
        })["text"] == "Host added."
        assert _add_reservation({
            "hw-address": "bb:bb:bb:bb:bb:bb",
            "ip-address": the_same_ip_address
        })["text"] == "Host added."

    # these error logs should not appear
    srv_msg.log_doesnt_contain(r'ERROR \[kea-dhcp4.dhcp4')
    srv_msg.log_doesnt_contain(r'failed to add new host using the HW address')

    # first request address by aa:aa:aa:aa:aa:aa
    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'chaddr', 'aa:aa:aa:aa:aa:aa')
    srv_msg.client_send_msg('DISCOVER')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'OFFER')
    srv_msg.response_check_content('yiaddr', the_same_ip_address)

    misc.test_procedure()
    srv_msg.client_copy_option('server_id')
    srv_msg.client_does_include_with_value('requested_addr',
                                           the_same_ip_address)
    srv_msg.client_sets_value('Client', 'chaddr', 'aa:aa:aa:aa:aa:aa')
    srv_msg.client_send_msg('REQUEST')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'ACK')
    srv_msg.response_check_content('yiaddr', the_same_ip_address)
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
    srv_msg.check_leases(srv_msg.get_all_leases(), )

    # release taken IP address
    misc.test_procedure()
    srv_msg.client_copy_option('server_id')
    srv_msg.client_sets_value('Client', 'ciaddr', the_same_ip_address)
    srv_msg.client_send_msg('RELEASE')

    misc.pass_criteria()
    srv_msg.send_dont_wait_for_message()

    # and now request address by bb:bb:bb:bb:bb:bb again, the IP should be the same ie. 192.168.50.10
    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'chaddr', 'bb:bb:bb:bb:bb:bb')
    srv_msg.client_send_msg('DISCOVER')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'OFFER')
    srv_msg.response_check_content('yiaddr', the_same_ip_address)

    misc.test_procedure()
    srv_msg.client_copy_option('server_id')
    srv_msg.client_does_include_with_value('requested_addr',
                                           the_same_ip_address)
    srv_msg.client_sets_value('Client', 'chaddr', 'bb:bb:bb:bb:bb:bb')
    srv_msg.client_send_msg('REQUEST')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'ACK')
    srv_msg.response_check_content('yiaddr', the_same_ip_address)
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
    srv_msg.check_leases(srv_msg.get_all_leases(), )

    # try to request address by aa:aa:aa:aa:aa:aa again, the IP address should be just
    # from the pool (ie. 192.168.50.1) as 192.168.50.10 is already taken by bb:bb:bb:bb:bb:bb
    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'chaddr', 'aa:aa:aa:aa:aa:aa')
    srv_msg.client_send_msg('DISCOVER')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'OFFER')
    srv_msg.response_check_content('yiaddr', '192.168.50.1')

    misc.test_procedure()
    srv_msg.client_copy_option('server_id')
    srv_msg.client_does_include_with_value('requested_addr', '192.168.50.1')
    srv_msg.client_sets_value('Client', 'chaddr', 'aa:aa:aa:aa:aa:aa')
    srv_msg.client_send_msg('REQUEST')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'ACK')
    srv_msg.response_check_content('yiaddr', '192.168.50.1')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
    srv_msg.check_leases(
        srv_msg.get_all_leases())  # backend for leases is still memfile
Exemplo n.º 3
0
def generate_leases(leases_count=1,
                    iaid=1,
                    iapd=1,
                    dhcp_version='v6',
                    mac="01:02:0c:03:0a:00"):
    """
    Function will perform message exchanges to get specified number of leases,
    will assert if at the end number of leases will be smaller
    :param leases_count: how many leases we want to generate
    :param iaid: how many v6 addresses we want in single exchange (ignored for v4)
    :param iapd: how many prefixes we want in single exchange (ignored for v4)
    :param dhcp_version: version of dhcp
    :param mac: mac we will start increase, to get different set of macs increase just first octet
    :return: list of leases generated
    """
    all_leases = []
    tmp = world.f_cfg.show_packets_from
    world.f_cfg.show_packets_from = ""
    if dhcp_version == 'v6':
        for _ in range(leases_count):
            mac = _increase_mac(mac)
            duid = "00:03:00:01:" + mac
            ia_1 = random.randint(2000, 7000)
            pd_1 = random.randint(7001, 9999)

            misc.test_procedure()
            srv_msg.client_sets_value('Client', 'DUID', duid)
            srv_msg.client_does_include('Client', 'client-id')

            for ia in range(iaid):
                this_iaid = ia_1 + ia
                srv_msg.client_sets_value('Client', 'ia_id', this_iaid)
                srv_msg.client_does_include('Client', 'IA-NA')
            for pd in range(iapd):
                this_iapd = pd_1 + pd
                srv_msg.client_sets_value('Client', 'ia_pd', this_iapd)
                srv_msg.client_does_include('Client', 'IA-PD')
            srv_msg.client_send_msg('SOLICIT')

            misc.pass_criteria()
            srv_msg.send_wait_for_message('MUST', 'ADVERTISE')
            srv_msg.response_check_include_option(1)
            srv_msg.response_check_include_option(2)
            if iaid > 0:
                srv_msg.response_check_include_option(3)
            if iapd > 0:
                srv_msg.response_check_include_option(25)

            misc.test_procedure()
            srv_msg.client_sets_value('Client', 'DUID', duid)
            srv_msg.client_does_include('Client', 'client-id')

            # this should be copy not generated
            for ia in range(iaid):
                srv_msg.client_sets_value('Client', 'ia_id', ia_1 + ia)
                srv_msg.client_does_include('Client', 'IA-NA')

            for pd in range(iapd):
                srv_msg.client_sets_value('Client', 'ia_pd', pd_1 + pd)
                srv_msg.client_does_include('Client', 'IA-PD')

            srv_msg.client_copy_option('server-id')
            srv_msg.client_send_msg('REQUEST')

            misc.pass_criteria()
            # TODO check server-id!
            srv_msg.send_wait_for_message('MUST', 'REPLY')
            srv_msg.response_check_include_option(1)
            srv_msg.response_check_include_option(2)
            if iaid > 0:
                srv_msg.response_check_include_option(3)
                # srv_msg.response_check_include_option(4)
                # some times load balancing can't assign we cant check it for now
            if iapd > 0:
                srv_msg.response_check_include_option(25)
                # srv_msg.response_check_include_option(26)

            all_leases += srv_msg.get_all_leases()

    elif dhcp_version == 'v4':
        for _ in range(leases_count):
            mac = _increase_mac(mac)
            misc.test_procedure()
            srv_msg.client_sets_value('Client', 'chaddr', mac)
            srv_msg.client_requests_option(1)
            srv_msg.client_send_msg('DISCOVER')

            misc.pass_criteria()
            srv_msg.send_wait_for_message('MUST', 'OFFER')
            yiaddr = world.srvmsg[0].yiaddr

            misc.test_procedure()
            srv_msg.client_sets_value('Client', 'chaddr', mac)
            srv_msg.client_copy_option('server_id')
            srv_msg.client_does_include_with_value('requested_addr', yiaddr)
            srv_msg.client_requests_option(1)
            srv_msg.client_send_msg('REQUEST')

            misc.pass_criteria()
            srv_msg.send_wait_for_message('MUST', 'ACK')
            srv_msg.response_check_content('yiaddr', yiaddr)

            all_leases.append(srv_msg.get_all_leases())
    world.f_cfg.show_packets_from = tmp
    return all_leases