diff --git a/xCAT-genesis-scripts/usr/bin/allowcred.awk b/xCAT-genesis-scripts/usr/bin/allowcred.awk index 341138d3e4..2e1cee75c2 100755 --- a/xCAT-genesis-scripts/usr/bin/allowcred.awk +++ b/xCAT-genesis-scripts/usr/bin/allowcred.awk @@ -1,9 +1,23 @@ #!/usr/bin/awk -f +# +# The Genesis copy of xCAT/postscripts/allowcred.awk. A /inet/ listener on this gawk +# accepts no IPv6 connection, so an IPv6-only node got no credentials during discovery. BEGIN { - listener = "/inet/tcp/300/0/0" + port = ("XCAT_CREDENTIAL_CALLBACK_PORT" in ENVIRON) ? ENVIRON["XCAT_CREDENTIAL_CALLBACK_PORT"] : 300 + if (port !~ /^[0-9]+$/ || port < 1 || port > 65535) { + port = 300 + } + + master = ("MASTER_IP" in ENVIRON) ? ENVIRON["MASTER_IP"] : "" + if (master == "") { + master = ("MASTER" in ENVIRON) ? ENVIRON["MASTER"] : "" + } + if (master ~ /:/) { + listener = "/inet6/tcp/" port "/0/0" + } else { + listener = "/inet/tcp/" port "/0/0" + } quit = "no" - - while (match(quit,"no")) { while ((listener |& getline) > 0) { if (match($0,"CREDOKBYYOU?")) { diff --git a/xCAT-genesis-scripts/usr/bin/updateflag.awk b/xCAT-genesis-scripts/usr/bin/updateflag.awk index 96848f4bb7..397f70b20e 100755 --- a/xCAT-genesis-scripts/usr/bin/updateflag.awk +++ b/xCAT-genesis-scripts/usr/bin/updateflag.awk @@ -1,32 +1,46 @@ #!/usr/bin/awk -f # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +# +# The Genesis copy of xCAT/postscripts/updateflag.awk. It writes no file: Genesis has no +# /var/log/xcat directory, rsyslog sends everything to /var/log/xcat.genesis, and gawk is +# fatal when it cannot open a redirect. BEGIN { xcatdhost = ARGV[1] xcatdport = ARGV[2] flag = ARGV[3] - if (!flag) flag = "next" + if (!flag) flag = "next" - ns = "/inet/tcp/0/" ARGV[1] "/" xcatdport + if (xcatdhost ~ /^\[.*\]$/) { + sub(/^\[/, "", xcatdhost) + sub(/\]$/, "", xcatdhost) + } + netfamily = index(xcatdhost, ":") ? "inet6" : "inet" + ns = "/" netfamily "/tcp/0/" xcatdhost "/" xcatdport - while(1) { - if((ns |& getline) > 0) - print $0 | "logger -t xcat -p local4.info" + loop = 0 + while(1) { + if((ns |& getline) > 0) + print $0 | "logger -t xcat -p local4.info" else { print "Retrying flag update" | "logger -t xcat -p local4.info" close(ns) system("sleep 10") + loop = loop + 1 } - if($0 == "ready") - print flag |& ns - if($0 == "done") - break - } + if($0 == "ready") + print flag |& ns + if($0 == "done") + break + if(loop > 10) { + print "flag update failed" | "logger -t xcat -p local4.info" + break + } + } - close(ns) + close(ns) - exit 0 + exit 0 } - diff --git a/xCAT-server/lib/xcat/plugins/dhcp.pm b/xCAT-server/lib/xcat/plugins/dhcp.pm index f89b450787..0e99c38b06 100644 --- a/xCAT-server/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server/lib/xcat/plugins/dhcp.pm @@ -693,11 +693,68 @@ sub listnode } } +#------------------------------------------------------------------------------- + +=head3 delnode6_commands + + Descriptions: The omshell commands that remove the DHCPv6 host of a node. + Arguments: $node + Returns: the commands, or the empty string when there is no node to remove. + + The sequence is the one addnode6 uses to clear a name conflict before it + creates the host, so a removal and a replacement act on the same object. + +=cut + +#------------------------------------------------------------------------------- +sub delnode6_commands +{ + my ($node) = @_; + + return '' unless defined($node) && length($node); + + my $commands = "new host\n"; + $commands .= "set name = \"$node\"\n"; + $commands .= "open\n"; + $commands .= "remove\n"; + $commands .= "close\n"; + return $commands; +} + +#------------------------------------------------------------------------------- + +=head3 delnode6 + + Descriptions: Remove the DHCPv6 host of a node over an open omapi session. + Arguments: $node, $writer -- the omshell handle, or undef + Returns: 1 when the commands were written, 0 when there was nothing to do. + + makedhcp -d removed the DHCPv4 host alone. addnode6 creates the DHCPv6 host + as a separate object on a separate omapi port, so the reservation survived + the delete and kept the address and the boot file of a node that makedhcp + reported as removed. + +=cut + +#------------------------------------------------------------------------------- +sub delnode6 +{ + my ($node, $writer) = @_; + + return 0 unless defined($writer); + my $commands = delnode6_commands($node); + return 0 unless length($commands); + print {$writer} $commands; + return 1; +} + sub delnode { my $node = shift; my $inetn = inet_aton($node); + delnode6($node, $omshell6) if $usingipv6; + if (_isc_static_host_fallback()) { _delete_isc_static_host($node); $restartdhcp = 1; @@ -5524,6 +5581,77 @@ sub putmyselffirst { #------------------------------------------------------------------------------- +=head3 net_config_for + + Descriptions: The %netcfgs entry of a subnet. + Arguments: the subnet, with or without a prefix length + Returns: the configuration hash reference, or undef when there is none. + + addrangedetection keys %netcfgs on networks.net, which a conf may write + with no prefix length, while addnet6 names a subnet "/" from + the "ip -6 route" output. A lookup under the long form alone found nothing, + so the subnet6 lost its domain-search list and its name servers, while + dynamic_range_for, which already falls back, still found the range. + +=cut + +#------------------------------------------------------------------------------- +sub net_config_for +{ + my ($net) = @_; + + return unless defined $net; + return $netcfgs{$net} if $netcfgs{$net}; + (my $bare = $net) =~ s{/.*$}{}; + return $netcfgs{$bare}; +} + +#------------------------------------------------------------------------------- + +=head3 isc_dhcp6_subnet_statements + + Descriptions: The domain and resolver statements of an ISC subnet6. + Arguments: + %args - net, config (the net_config_for entry), site_domain, + alldomains (arrayref), domain_search (0 on sles10 and rh5, + whose dhcpd does not know the option) + Returns: the statements, as a list. Empty when the subnet has nothing to say. + +=cut + +#------------------------------------------------------------------------------- +sub isc_dhcp6_subnet_statements +{ + my (%args) = @_; + + my $cfg = $args{config} || {}; + my @lines; + + my $netdomain = $cfg->{domain} || $args{site_domain}; + $netdomain = '' unless defined $netdomain; + push @lines, " option domain-name \"" . $netdomain . "\";\n"; + + if ($args{domain_search} and $cfg->{domain}) { + + # We want something like "option domain-search "foo.com", "bar.com";" + my $domainstring = qq~"$cfg->{domain}"~; + foreach my $dom (@{ $args{alldomains} || [] }) { + chomp $dom; + if ($dom ne $cfg->{domain}) { + $domainstring .= qq~, "$dom"~; + } + } + push @lines, " option domain-search $domainstring;\n"; + } + + my $nsstatement = isc_dhcp6_nameserver_statement($args{net}, $cfg->{nameservers}); + push @lines, " $nsstatement\n" if $nsstatement; + + return @lines; +} + +#------------------------------------------------------------------------------- + =head3 dynamic_range_for Descriptions: The dynamic range of a subnet, as ISC writes it. @@ -5606,37 +5734,30 @@ sub addnet6 #posix timezone rfc 4833/tzdb timezone #phase 3 will include whatever is required to do Netboot6. That might be in the october timeframe for lack of implementations to test #boot url/param (rfc 59070) - my $netdomain = $netcfgs{$net}->{domain}; + # The lookup falls back to the bare net, as dynamic_range_for does. See + # net_config_for: a conf may write networks.net with no prefix length, + # while $net names the subnet "/". + my $netcfg = net_config_for($net) || {}; + + my $netdomain = $netcfg->{domain}; unless ($netdomain) { $netdomain = $site_domain; } - push @netent, " option domain-name \"" . $netdomain . "\";\n"; # add domain-search if not sles10 or rh5 my $osv = xCAT::Utils->osver(); - unless (($osv =~ /^sle[sc]10/) || ($osv =~ /^rh.*5$/)) { + push @netent, isc_dhcp6_subnet_statements( + net => $net, + config => $netcfg, + site_domain => $site_domain, + alldomains => \@alldomains, + domain_search => (($osv =~ /^sle[sc]10/) || ($osv =~ /^rh.*5$/)) ? 0 : 1, + ); - # We want something like "option domain-search "foo.com", "bar.com";" - my $domainstring = qq~"$netcfgs{$net}->{domain}"~; - foreach my $dom (@alldomains) { - chomp $dom; - if ($dom ne $netcfgs{$net}->{domain}) { - $domainstring .= qq~, "$dom"~; - } - } - - if ($netcfgs{$net}->{domain}) { - push @netent, " option domain-search $domainstring;\n"; - } - } - - - my $nameservers = $netcfgs{$net}->{nameservers}; - my $nsstatement = isc_dhcp6_nameserver_statement( $net, $nameservers ); - push @netent, " $nsstatement\n" if $nsstatement; + my $nameservers = $netcfg->{nameservers}; my $ddnserver = defined($nameservers) ? $nameservers : ''; $ddnserver =~ s/,.*//; my $ddnsdomain; - if ($netcfgs{$net}->{ddnsdomain}) { - $ddnsdomain = $netcfgs{$net}->{ddnsdomain}; + if ($netcfg->{ddnsdomain}) { + $ddnsdomain = $netcfg->{ddnsdomain}; } my $ddns_on = $::XCATSITEVALS{dnshandler} =~ /ddns/ ? 1 : 0; my $settings; diff --git a/xCAT-test/bats/ipv6_configeth_install_nic.bats b/xCAT-test/bats/ipv6_configeth_install_nic.bats index 1baa8061a9..cd7de1df90 100644 --- a/xCAT-test/bats/ipv6_configeth_install_nic.bats +++ b/xCAT-test/bats/ipv6_configeth_install_nic.bats @@ -81,3 +81,77 @@ IPSTUB run run_discover '' '3: ens3 inet6 fe80::1/64 scope link' [ "$status" -ne 0 ] } + +# --------------------------------------------------------------------------- +# The keyfile configeth renders during Anaconda's chrooted %post. +# +# nmcli cannot persist a connection into the target root there, so the profile is rendered with +# "nmcli --offline" into a temporary file and moved into place. A node whose profile keeps IPv4 +# enabled waits for a DHCPv4 lease that never arrives, and a temporary file left behind in +# system-connections is read by NetworkManager as a second profile for the same interface. + +# render_keyfile -- run the real function with nmcli stubbed to +# echo the arguments it was given, so the profile shows what reached it. +render_keyfile() +{ + local file lib bin keyfile="$1" rc="$2" + file="$(require_repo_file 'xCAT/postscripts/configeth')" + lib="${BATS_TEST_TMPDIR}/keyfile.sh" + extract_shell_function "$file" 'configure_install_nic_ipv6_connection' >"$lib" || return 1 + extract_shell_function "$file" 'configure_install_nic_ipv6_keyfile' >>"$lib" || return 1 + + bin="${BATS_TEST_TMPDIR}/bin" + mkdir -p "$bin" + cat >"$bin/nmcli" </dev/null || skip 'gawk is required' + command -v socat >/dev/null || skip 'socat is required' + command -v ss >/dev/null || skip 'ss is required' + SERVER_PID= +} + +teardown() +{ + [ -n "${SERVER_PID:-}" ] || return 0 + kill -- "-${SERVER_PID}" 2>/dev/null + kill "$SERVER_PID" 2>/dev/null + return 0 +} + +# --------------------------------------------------------------------------- +# allowcred.awk -- the credential listener. + +# listen_cred