Exemple #1
0
def test_v4_hooks_flexid_replace_client_id_renew_2():
    misc.test_setup()
    srv_control.config_srv_subnet('192.168.50.0/24',
                                  '192.168.50.1-192.168.50.5')
    srv_control.host_reservation_in_subnet('ip-address', '192.168.50.10', 0,
                                           'flex-id', '\'docsis3.0\'')
    srv_control.add_line(
        {"host-reservation-identifiers": ["hw-address", "flex-id"]})
    srv_control.add_hooks('libdhcp_flex_id.so')
    srv_control.add_parameter_to_hook(1, 'identifier-expression',
                                      'option[60].hex')
    srv_control.add_parameter_to_hook(1, 'replace-client-id', True)
    # enable matching client id
    srv_control.set_conf_parameter_global('match-client-id', True)
    srv_control.build_and_send_config_files()
    srv_control.start_srv('DHCP', 'started')

    # server should act normally, mac address should not be replaced
    misc.test_procedure()
    srv_msg.client_does_include_with_value('client_id',
                                           'ff:01:02:03:ff:04:11:22')
    srv_msg.client_does_include_with_value('vendor_class_id', 'docsis3.0')
    srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04')
    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.10')

    misc.test_procedure()
    srv_msg.client_does_include_with_value('client_id',
                                           'ff:01:02:03:ff:04:11:22')
    srv_msg.client_copy_option('server_id')
    srv_msg.client_does_include_with_value('requested_addr', '192.168.50.10')
    srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04')
    srv_msg.client_does_include_with_value('vendor_class_id', 'docsis3.0')
    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.10')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_option_content(1, 'value', '255.255.255.0')

    misc.test_procedure()
    srv_msg.client_does_include_with_value('client_id',
                                           'ff:01:02:03:ff:04:11:22')
    # Client adds to the message vendor_class_id with value docsis3.0.
    srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04')
    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.10', expected=False)
    srv_msg.response_check_include_option(61)
    srv_msg.response_check_include_option(54)

    srv_msg.lease_file_doesnt_contain('ff:01:02:03:ff:04:11:22:33')
    srv_msg.lease_file_contains(
        '192.168.50.10,ff:01:02:03:ff:04,00:64:6f:63:73:69:73:33:2e:30,4000')
Exemple #2
0
def test_hook_v6_lease_cmds_legal_logging_update():
    misc.test_procedure()
    srv_msg.remove_file_from_server(world.f_cfg.data_join('kea-legal*.txt'))

    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8:1::/64', '2001:db8:1::1-2001:db8:1::2')
    srv_control.open_control_channel()
    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.add_hooks('libdhcp_legal_log.so')
    srv_control.build_and_send_config_files()

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

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID', '00:03:00:01:66:55:44:33:22:11')
    srv_msg.client_sets_value('Client', 'ia_id', 666)
    srv_msg.client_does_include('Client', 'client-id')
    srv_msg.client_does_include('Client', 'IA-NA')
    srv_msg.client_send_msg('SOLICIT')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'ADVERTISE')
    srv_msg.response_check_include_option(3)
    srv_msg.response_check_option_content(3, 'sub-option', 5)

    misc.test_procedure()
    srv_msg.client_copy_option('IA_NA')
    srv_msg.client_copy_option('server-id')
    srv_msg.client_sets_value('Client', 'DUID', '00:03:00:01:66:55:44:33:22:11')
    srv_msg.client_does_include('Client', 'client-id')
    srv_msg.client_send_msg('REQUEST')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'REPLY')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_include_option(2)
    srv_msg.response_check_include_option(3)
    srv_msg.response_check_option_content(3, 'sub-option', 5)

    srv_msg.lease_file_contains('2001:db8:1::1,00:03:00:01:66:55:44:33:22:11,4000,')
    srv_msg.lease_file_contains(',1,3000,0,666,128,0,0,,66:55:44:33:22:11,0')

    srv_msg.lease_file_doesnt_contain('2001:db8:1::1,01:02:03:04:05:06:07:08')
    srv_msg.lease_file_doesnt_contain(',urania.example.org,1a:1b:1c:1d:1e:1f,')

    srv_msg.send_ctrl_cmd_via_socket('{"command":"lease6-update", "arguments":{"subnet-id": 1,"ip-address": "2001:db8:1::1","duid": "01:02:03:04:05:06:07:08","iaid": 1234,"hw-address": "1a:1b:1c:1d:1e:1f","preferred-lft": 500,"valid-lft": 1000,"hostname": "urania.example.org"}}')
    srv_msg.lease_file_contains(',1,500,0,1234,128,0,0,urania.example.org,1a:1b:1c:1d:1e:1f,0')
    srv_msg.lease_file_contains('2001:db8:1::1,01:02:03:04:05:06:07:08,1000')

    srv_msg.copy_remote(world.f_cfg.data_join('kea-legal*.txt'))
    srv_msg.file_contains_line(world.f_cfg.data_join('kea-legal*.txt'),
                               None,
                               'Administrator updated information on the lease of address: 2001:db8:1::1 to a device with DUID: 01:02:03:04:05:06:07:08, hardware address: 1a:1b:1c:1d:1e:1f for 0 hrs 16 mins 40 secs')
Exemple #3
0
def test_hook_v4_lease_cmds_update():
    misc.test_setup()
    srv_control.config_srv_subnet('192.168.50.0/24',
                                  '192.168.50.1-192.168.50.1')
    srv_control.config_srv_another_subnet_no_interface('10.0.0.0/24',
                                                       '10.0.0.5-10.0.0.5')
    srv_control.open_control_channel()
    srv_control.add_hooks('libdhcp_lease_cmds.so')
    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_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04')
    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_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04')
    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.lease_file_contains('192.168.50.1,ff:01:02:03:ff:04,,')
    srv_msg.lease_file_contains(',1,0,0,,0')

    srv_msg.lease_file_doesnt_contain('192.168.50.1,1a:1b:1c:1d:1e:1f,,4000')
    srv_msg.lease_file_doesnt_contain('1,0,0,newhostname.example.org,0')

    srv_msg.send_ctrl_cmd_via_socket(
        '{"command":"lease4-get","arguments":{"ip-address": "192.168.50.1"}}')
    srv_msg.send_ctrl_cmd_via_socket(
        '{"command":"lease4-update","arguments":{"ip-address": "192.168.50.1","hostname": "newhostname.example.org","hw-address": "1a:1b:1c:1d:1e:1f","subnet-id":1}}'
    )
    srv_msg.send_ctrl_cmd_via_socket(
        '{"command":"lease4-get","arguments":{"ip-address": "192.168.50.1"}}')

    srv_msg.lease_file_contains('192.168.50.1,1a:1b:1c:1d:1e:1f,,4000')
    srv_msg.lease_file_contains('1,0,0,newhostname.example.org,0')
def test_hook_v6_lease_cmds_update():
    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8:1::/64', '2001:db8:1::1-2001:db8:1::2')
    srv_control.open_control_channel()
    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.build_and_send_config_files('SSH', 'config-file')

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

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID', '00:03:00:01:66:55:44:33:22:11')
    srv_msg.client_sets_value('Client', 'ia_id', '666')
    srv_msg.client_does_include('Client', None, 'client-id')
    srv_msg.client_does_include('Client', None, 'IA-NA')
    srv_msg.client_send_msg('SOLICIT')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', None, 'ADVERTISE')
    srv_msg.response_check_include_option('Response', None, '3')
    srv_msg.response_check_option_content('Response', '3', None, 'sub-option', '5')

    misc.test_procedure()
    srv_msg.client_copy_option('IA_NA')
    srv_msg.client_copy_option('server-id')
    srv_msg.client_sets_value('Client', 'DUID', '00:03:00:01:66:55:44:33:22:11')
    srv_msg.client_does_include('Client', None, 'client-id')
    srv_msg.client_send_msg('REQUEST')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', None, 'REPLY')
    srv_msg.response_check_include_option('Response', None, '1')
    srv_msg.response_check_include_option('Response', None, '2')
    srv_msg.response_check_include_option('Response', None, '3')
    srv_msg.response_check_option_content('Response', '3', None, 'sub-option', '5')

    srv_msg.lease_file_contains('2001:db8:1::1,00:03:00:01:66:55:44:33:22:11,4000,')
    srv_msg.lease_file_contains(',1,3000,0,666,128,0,0,,66:55:44:33:22:11,0')

    srv_msg.lease_file_doesnt_contain('2001:db8:1::1,01:02:03:04:05:06:07:08')
    srv_msg.lease_file_doesnt_contain(',urania.example.org,1a:1b:1c:1d:1e:1f,')

    srv_msg.send_ctrl_cmd_via_socket('{"command":"lease6-update", "arguments":{"subnet-id": 1,"ip-address": "2001:db8:1::1","duid": "01:02:03:04:05:06:07:08","iaid": 1234,"hw-address": "1a:1b:1c:1d:1e:1f","preferred-lft": 500,"valid-lft": 1000,"hostname": "urania.example.org"}}')
    srv_msg.lease_file_contains(',1,500,0,1234,128,0,0,urania.example.org,1a:1b:1c:1d:1e:1f,0')
    srv_msg.lease_file_contains('2001:db8:1::1,01:02:03:04:05:06:07:08,1000')
Exemple #5
0
def test_v6_sanity_check_subnet_id_del_renew():
    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8::/64', '2001:db8::1-2001:db8::1')
    srv_control.set_conf_parameter_subnet('id', '666', '0')
    srv_control.set_conf_parameter_global('sanity-checks',
                                          '{"lease-checks":"del"}')
    srv_control.open_control_channel()

    srv_control.build_and_send_config_files('SSH', 'config-file')

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

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.client_does_include('Client', None, 'client-id')
    srv_msg.client_sets_value('Client', 'ia_id', '1234567')
    srv_msg.client_does_include('Client', None, 'IA-NA')
    srv_msg.client_send_msg('SOLICIT')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', None, 'ADVERTISE')
    srv_msg.response_check_include_option('Response', None, '1')
    srv_msg.response_check_include_option('Response', None, '2')
    srv_msg.response_check_include_option('Response', None, '3')
    srv_msg.response_check_option_content('Response', '3', None, 'sub-option',
                                          '5')

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.client_copy_option('IA_NA')
    srv_msg.client_copy_option('server-id')
    srv_msg.client_does_include('Client', None, 'client-id')
    srv_msg.client_send_msg('REQUEST')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', None, 'REPLY')
    srv_msg.response_check_include_option('Response', None, '1')
    srv_msg.response_check_include_option('Response', None, '2')
    srv_msg.response_check_include_option('Response', None, '3')
    srv_msg.response_check_option_content('Response', '3', None, 'sub-option',
                                          '5')
    srv_msg.response_check_suboption_content('Response', '5', '3', None,
                                             'addr', '2001:db8::1')

    srv_msg.lease_file_contains('2001:db8::1,00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.lease_file_contains(
        '666,3000,0,1234567,128,0,0,,f6:f5:f4:f3:f2:01')

    srv_control.start_srv('DHCP', 'stopped')

    srv_control.clear_leases('logs')

    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8::/64', '2001:db8::1-2001:db8::1')
    srv_control.set_conf_parameter_subnet('id', '999', '0')
    srv_control.set_conf_parameter_global('sanity-checks',
                                          '{"lease-checks":"del"}')
    srv_control.open_control_channel()

    srv_control.build_and_send_config_files('SSH', 'config-file')

    srv_control.start_srv('DHCP', 'started')
    srv_msg.forge_sleep('2', 'seconds')

    srv_msg.log_contains(
        'DHCPSRV_LEASE_SANITY_FAIL_DISCARD The lease 2001:db8::1 with subnet-id 666 failed subnet-id checks and was dropped.'
    )

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.client_copy_option('server-id')
    srv_msg.client_copy_option('IA_NA')
    srv_msg.client_does_include('Client', None, 'client-id')
    srv_msg.client_send_msg('RENEW')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', None, 'REPLY')
    srv_msg.response_check_include_option('Response', None, '1')
    srv_msg.response_check_include_option('Response', None, '2')
    srv_msg.response_check_include_option('Response', None, '3')
    srv_msg.response_check_option_content('Response', '3', None, 'sub-option',
                                          '5')
    srv_msg.response_check_suboption_content('Response', '5', '3', None,
                                             'addr', '2001:db8::1')

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:22')
    srv_msg.client_does_include('Client', None, 'client-id')
    srv_msg.client_sets_value('Client', 'ia_id', '1234567')
    srv_msg.client_does_include('Client', None, 'IA-NA')
    srv_msg.client_send_msg('SOLICIT')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', None, 'ADVERTISE')
    srv_msg.response_check_include_option('Response', None, '1')
    srv_msg.response_check_include_option('Response', None, '2')
    srv_msg.response_check_include_option('Response', None, '3')
    srv_msg.response_check_option_content('Response', '3', None, 'sub-option',
                                          '13')
    srv_msg.response_check_suboption_content('Response', '13', '3', None,
                                             'statuscode', '2')

    srv_msg.lease_file_contains('2001:db8::1,00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.lease_file_contains(
        '666,3000,0,1234567,128,0,0,,f6:f5:f4:f3:f2:01')

    srv_msg.lease_file_contains('2001:db8::1,00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.lease_file_contains(
        '999,3000,0,1234567,128,0,0,,f6:f5:f4:f3:f2:01')

    srv_msg.lease_file_doesnt_contain(
        '2001:db8::1,00:03:00:01:f6:f5:f4:f3:f2:22')
    srv_msg.lease_file_doesnt_contain(
        '999,3000,0,1234567,128,0,0,,f6:f5:f4:f3:f2:22')
Exemple #6
0
def test_v6_sanity_check_subnet_id_del():
    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8::/64', '2001:db8::1-2001:db8::1')
    srv_control.set_conf_parameter_subnet('id', 666, 0)
    srv_control.set_conf_parameter_global('sanity-checks',
                                          {"lease-checks": "del"})
    srv_control.open_control_channel()
    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.build_and_send_config_files()

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

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.client_does_include('Client', 'client-id')
    srv_msg.client_sets_value('Client', 'ia_id', '1234567')
    srv_msg.client_does_include('Client', 'IA-NA')
    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)
    srv_msg.response_check_include_option(3)
    srv_msg.response_check_option_content(3, 'sub-option', 5)

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.client_copy_option('IA_NA')
    srv_msg.client_copy_option('server-id')
    srv_msg.client_does_include('Client', 'client-id')
    srv_msg.client_send_msg('REQUEST')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'REPLY')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_include_option(2)
    srv_msg.response_check_include_option(3)
    srv_msg.response_check_option_content(3, 'sub-option', 5)
    srv_msg.response_check_suboption_content(5, 3, 'addr', '2001:db8::1')

    # lease should be available via lease6-get
    resp = srv_msg.send_ctrl_cmd_via_socket(
        '{"command":"lease6-get","arguments":{"ip-address": "2001:db8::1"}}')
    assert resp['arguments']['subnet-id'] == 666

    # it should be in lease file as well
    srv_msg.lease_file_contains('2001:db8::1,00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.lease_file_contains(
        '666,3000,0,1234567,128,0,0,,f6:f5:f4:f3:f2:01')

    srv_control.start_srv('DHCP', 'stopped')

    srv_control.clear_some_data('logs')

    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8::/64', '2001:db8::1-2001:db8::1')
    srv_control.set_conf_parameter_subnet('id', 999, 0)
    srv_control.set_conf_parameter_global('sanity-checks',
                                          {"lease-checks": "del"})
    srv_control.open_control_channel()
    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.build_and_send_config_files()

    srv_control.start_srv('DHCP', 'started')
    srv_msg.forge_sleep(2, 'seconds')

    srv_msg.log_contains(
        'DHCPSRV_LEASE_SANITY_FAIL_DISCARD The lease 2001:db8::1 with subnet-id 666 failed subnet-id checks (the lease should have subnet-id 999) and was dropped.'
    )

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:22')
    srv_msg.client_does_include('Client', 'client-id')
    srv_msg.client_sets_value('Client', 'ia_id', '7654321')
    srv_msg.client_does_include('Client', 'IA-NA')
    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)
    srv_msg.response_check_include_option(3)
    srv_msg.response_check_option_content(3, 'sub-option', 5)
    srv_msg.response_check_suboption_content(5, 3, 'addr', '2001:db8::1')

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:22')
    srv_msg.client_copy_option('IA_NA')
    srv_msg.client_copy_option('server-id')
    srv_msg.client_does_include('Client', 'client-id')
    srv_msg.client_send_msg('REQUEST')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'REPLY')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_include_option(2)
    srv_msg.response_check_include_option(3)
    srv_msg.response_check_option_content(3, 'sub-option', 5)
    srv_msg.response_check_suboption_content(5, 3, 'addr', '2001:db8::1')

    # old lease from subnet-id 666 should not be available while new lease from subnet-id 999 should be
    resp = srv_msg.send_ctrl_cmd_via_socket(
        '{"command":"lease6-get","arguments":{"ip-address": "2001:db8::1"}}')
    assert resp['arguments']['subnet-id'] == 999
    # explict query for old lease should return error
    srv_msg.send_ctrl_cmd_via_socket(
        '{"command":"lease6-get","arguments":{"subnet-id":666,"identifier-type":"duid", "identifier": "00:03:00:01:f6:f5:f4:f3:f2:01"}}',
        exp_result=3)

    # old lease should not be present in the lease file
    # bug: #1618, closed as designed
    srv_msg.lease_file_doesnt_contain(
        '2001:db8::1,00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.lease_file_doesnt_contain(
        '666,3000,0,1234567,128,0,0,,f6:f5:f4:f3:f2:01')
    # new one should be in the lease file
    srv_msg.lease_file_contains('2001:db8::1,00:03:00:01:f6:f5:f4:f3:f2:22')
    srv_msg.lease_file_contains(
        '999,3000,0,7654321,128,0,0,,f6:f5:f4:f3:f2:22,0')