From 41fc149dc97c37e812d4589f60828abb85b8d895 Mon Sep 17 00:00:00 2001 From: bybai Date: Tue, 19 Sep 2017 04:36:58 -0400 Subject: [PATCH] nic interface check to avoid dot in short host name --- perl-xCAT/xCAT/Schema.pm | 4 ++-- xCAT-server/lib/xcat/plugins/hosts.pm | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/perl-xCAT/xCAT/Schema.pm b/perl-xCAT/xCAT/Schema.pm index f4f9965cc..c38db16d2 100755 --- a/perl-xCAT/xCAT/Schema.pm +++ b/perl-xCAT/xCAT/Schema.pm @@ -1551,14 +1551,14 @@ passed as argument rather than by table value', If multiple ip addresses are associated with each NIC: !|,!|,..., for example, eth0!-eth0|-eth0-ipv6,ib0!-ib0|-ib0-ipv6. The xCAT object definition commands support to use nichostnamesuffixes. as the sub attributes. - Note: According to DNS rules a hostname must be a text string up to 24 characters drawn from the alphabet (A-Z), digits (0-9), minus sign (-),and period (.). When you are specifying "nichostnamesuffixes" or "nicaliases" make sure the resulting hostnames will conform to this naming convention', + Note: According to DNS rules a hostname must be a text string up to 24 characters drawn from the alphabet (A-Z), digits (0-9) and minus sign (-). When you are specifying "nichostnamesuffixes" or "nicaliases" make sure the resulting hostnames will conform to this naming convention', nichostnameprefixes => 'Comma-separated list of hostname prefixes per NIC. If only one ip address is associated with each NIC: !,!,..., for example, eth0!eth0-,ib0!ib- If multiple ip addresses are associated with each NIC: !|,!|,..., for example, eth0!eth0-|eth0-ipv6i-,ib0!ib-|ib-ipv6-. The xCAT object definition commands support to use nichostnameprefixes. as the sub attributes. - Note: According to DNS rules a hostname must be a text string up to 24 characters drawn from the alphabet (A-Z), digits (0-9), minus sign (-),and period (.). When you are specifying "nichostnameprefixes" or "nicaliases" make sure the resulting hostnames will conform to this naming convention', + Note: According to DNS rules a hostname must be a text string up to 24 characters drawn from the alphabet (A-Z), digits (0-9) and minus sign (-). When you are specifying "nichostnameprefixes" or "nicaliases" make sure the resulting hostnames will conform to this naming convention', nictypes => 'Comma-separated list of NIC types per NIC. !,!, e.g. eth0!Ethernet,ib0!Infiniband. The xCAT object definition commands support to use nictypes. as the sub attributes.', niccustomscripts => 'Comma-separated list of custom scripts per NIC. !,!, e.g. eth0!configeth eth0, ib0!configib ib0. The xCAT object definition commands support to use niccustomscripts. as the sub attribute .', diff --git a/xCAT-server/lib/xcat/plugins/hosts.pm b/xCAT-server/lib/xcat/plugins/hosts.pm index f2a8f3327..0ef05ace2 100755 --- a/xCAT-server/lib/xcat/plugins/hosts.pm +++ b/xCAT-server/lib/xcat/plugins/hosts.pm @@ -165,7 +165,7 @@ sub build_line $longname = "$node.$domain"; } - # if shortname contains a dot then we have a bad syntax for name + # if shortname contains a dot then we have a bad syntax for name if ($shortname =~ /\./) { my $rsp; push @{ $rsp->{data} }, "Invalid short node name \'$shortname\'. The short node name may not contain a dot. The short node name is considered to be anything preceeding the network domain name in the fully qualified node name \'$longname\'.\n"; @@ -729,9 +729,28 @@ sub donics for (my $i = 0 ; $i < $nicindex{$nic} ; $i++) { if (!$nich->{$nic}->{nicsufx}->[$i] && !$nich->{$nic}->{nicprfx}->[$i]) { + if ($nic =~ /\./) { + my $rsp; + push @{ $rsp->{data} }, "$node: since \'$nic\' contains dot, nics.nichostnamesuffixes should be configured without dot for \'$nic\' interface."; + xCAT::MsgUtils->message("E", $rsp, $callback); + next; + } # then we have no suffix at all for this # so set a default $nich->{$nic}->{nicsufx}->[$i] = "-$nic"; + + } elsif ($nich->{$nic}->{nicsufx}->[$i] && $nich->{$nic}->{nicsufx}->[$i] =~ /\./) { + my $rsp; + push @{ $rsp->{data} }, "$node: the value \'$nich->{$nic}->{nicsufx}->[$i]\' of nics.nichostnamesuffixes should not contain dot."; + xCAT::MsgUtils->message("E", $rsp, $callback); + delete $nich->{$nic}->{nicsufx}->[$i]; + next; + } elsif ($nich->{$nic}->{nicprfx}->[$i] && $nich->{$nic}->{nicprfx}->[$i] =~ /\./) { + my $rsp; + push @{ $rsp->{data} }, "$node: the value \'$nich->{$nic}->{nicprfx}->[$i]\' of nics.nichostnameprefixes should not contain dot."; + xCAT::MsgUtils->message("E", $rsp, $callback); + delete $nich->{$nic}->{nicprfx}->[$i]; + next; } } }