Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #17868 - dhcp: convert next-server ip correctly #486

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/dhcp_isc/isc_file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
module Proxy::DHCP::ISC
class FileParser
include Common
include Proxy::Validations

attr_reader :service

Expand Down Expand Up @@ -146,7 +147,7 @@ def parse_record_options text
when /^supersede server.next-server\s+=\s+(\S+)/
begin
ns = validate_ip hex2ip($1)
rescue
rescue Proxy::Validations::Error
ns = $1.gsub("\"","")
end
options[:nextServer] = ns
Expand Down
11 changes: 11 additions & 0 deletions test/dhcp_isc/dhcp_isc_parser_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'test_helper'
require 'dhcp_common/dhcp_common'
require 'dhcp_common/subnet'
require 'dhcp_common/subnet_service'
require 'dhcp_isc/isc_file_parser'
Expand Down Expand Up @@ -47,6 +48,7 @@ class "pxeclients" {
host test.example.com {
hardware ethernet 00:11:bb:cc:dd:ee;
fixed-address 192.168.122.1;
supersede server.next-server = ac:17:23:1d;
}
END

Expand Down Expand Up @@ -158,6 +160,15 @@ def test_parse_config_and_leases
assert_not_nil parsed.find {|record| record.ip == "192.168.122.35"}
end

def test_convert_next_server_ip_from_hex
subnet = Proxy::DHCP::Subnet.new("192.168.122.0", "255.255.255.0")
@subnet_service.add_subnet(subnet)
parsed = @parser.parse_config_and_leases_for_records(DHCPD_CONFIG)

record = parsed.find {|r| r.is_a?(::Proxy::DHCP::Reservation) && r.name == "test.example.com" }
assert_equal "172.23.35.29", record.nextServer
end

def test_get_ip_list_from_config_line
assert_equal ["192.168.1.1"], @parser.get_ip_list_from_config_line("option foo-bar 192.168.1.1")
assert_equal ["192.168.1.1", "192.168.20.10"], @parser.get_ip_list_from_config_line("option foo-bar 192.168.1.1,192.168.20.10")
Expand Down