From 8d55082241244b6bd4bc677f6b9f71ae28a2edaf Mon Sep 17 00:00:00 2001 From: stdweird Date: Thu, 13 Sep 2018 13:57:17 +0200 Subject: [PATCH] aii-dhcp: support optional hostname ip verification --- .../src/main/pan/quattor/aii/dhcp/schema.pan | 2 ++ aii-dhcp/src/main/perl/dhcp.pm | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/aii-dhcp/src/main/pan/quattor/aii/dhcp/schema.pan b/aii-dhcp/src/main/pan/quattor/aii/dhcp/schema.pan index a7d2b41c..46fd78be 100644 --- a/aii-dhcp/src/main/pan/quattor/aii/dhcp/schema.pan +++ b/aii-dhcp/src/main/pan/quattor/aii/dhcp/schema.pan @@ -20,4 +20,6 @@ type structure_dhcp_dhcp_info = { the value you specify in templates. } "options" ? string{} + @{Verify hostname in DNS} + "verifyhostname" ? boolean }; diff --git a/aii-dhcp/src/main/perl/dhcp.pm b/aii-dhcp/src/main/perl/dhcp.pm index 0c5650df..f9918496 100644 --- a/aii-dhcp/src/main/perl/dhcp.pm +++ b/aii-dhcp/src/main/perl/dhcp.pm @@ -295,6 +295,9 @@ sub Configure my $tree = $config->getElement("/system/network")->getTree(); my $fqdn = $tree->{hostname} . "." . $tree->{domainname}; + + my $opts = $config->getElement("/system/aii/dhcp")->getTree(); + # Find the bootable interface my $cards = $config->getElement("/hardware/cards/nic")->getTree(); my $bootable = undef; @@ -310,6 +313,20 @@ sub Configure } my $ip = $self->get_ip($bootable, $tree); + if ($opts->{verifyhostname}) { + my $fqdn_ip = gethostbyname($fqdn); + $fqdn_ip = inet_ntoa($fqdn_ip) if defined($fqdn_ip); + if (defined($fqdn_ip)) { + if ($fqdn_ip ne $ip) { + $self->error("aii-dhcp: fqdn $fqdn ip $fqdn_ip does not match configured ip $ip"); + } + } else { + $self->error("aii-dhcp: failed to obtain IP address for fqdn $fqdn"); + return; + } + } + + my $server_ip = gethostbyname(hostname()); $server_ip = inet_ntoa($server_ip) if defined($server_ip); if (!defined($server_ip)) { @@ -317,7 +334,6 @@ sub Configure return; } - my $opts = $config->getElement("/system/aii/dhcp")->getTree(); my $tftpserver = ""; my $filename = ""; my $additional = "";