diff --git a/perl-xCAT/xCAT/DHCP/BootPolicy.pm b/perl-xCAT/xCAT/DHCP/BootPolicy.pm index 0d64c47256..6c0f40b401 100644 --- a/perl-xCAT/xCAT/DHCP/BootPolicy.pm +++ b/perl-xCAT/xCAT/DHCP/BootPolicy.pm @@ -199,6 +199,26 @@ sub kea_bootfile_url6_option { #--- sub dhcp6_ipxe_user_class_test { return "substring(option[15].hex, 2, 4) == 'iPXE'"; } +#--- +# =head3 isc_dhcp6_boot_stage_statement +# Descriptions: The ISC DHCPv6 host statement that gives a chainloading node its boot file by +# boot stage. It makes the same split as kea_node_boot_classes6: iPXE sends option +# 15, the User Class, as the length-prefixed string iPXE, and the firmware sends no +# option 15. The DUID cannot make this split, because which UUID order the firmware +# sends depends on the UUID of the libvirt domain. +# Arguments: loader_url -- the first-stage loader, which the firmware fetches over tftp +# script_url -- the boot script of the node, which only iPXE can fetch +# Returns: the statement, unescaped, or undef unless both URLs are given +#--- +sub isc_dhcp6_boot_stage_statement { + my ( $class, %opts ) = @_; + + return unless defined( $opts{loader_url} ) && defined( $opts{script_url} ); + return 'if substring(option dhcp6.user-class, 2, 4) = "iPXE" { ' + . qq(option dhcp6.bootfile-url "$opts{script_url}"; } else { ) + . qq(option dhcp6.bootfile-url "$opts{loader_url}"; }); +} + #--- # =head3 kea_node_boot_classes6 # Descriptions: The two DHCPv6 client classes that give one chainloading node its boot file, one diff --git a/xCAT-server/lib/xcat/plugins/dhcp.pm b/xCAT-server/lib/xcat/plugins/dhcp.pm index 5fffbbfd84..2fe0236826 100644 --- a/xCAT-server/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server/lib/xcat/plugins/dhcp.pm @@ -952,13 +952,12 @@ sub addnode6 { # to load, so EDK2 reports "PXE-E21: Remote boot cancelled" and tries the next boot entry. my $nrent = $nrhash ? $nrhash->{$node}->[0] : undef; my $ntent = $nodetypeents ? $nodetypeents->{$node}->[0] : undef; - # mac.duid decides which client this host answers. With canonical it is iPXE, which needs the - # boot script of the node and not the shim. my ($primary) = dhcp6_node_clients( $identity->{duids}, $nrent ); - my $bootfile_url = dhcp6_bootfile_url_for_node( $node, $node, $nrent, $ntent, + my $bootfile = isc_dhcp6_bootfile_statement( $node, $nrent, $ntent, $primary ? $primary->{client} : undef ); - my $statements6 = 'ddns-hostname \"' . $node . '\";'; - $statements6 .= ' option dhcp6.bootfile-url \"' . $bootfile_url . '\";' if $bootfile_url; + my $statements6 = 'ddns-hostname "' . $node . '";'; + $statements6 .= " $bootfile" if $bootfile; + $statements6 =~ s/"/\\"/g; $commands .= 'set statements = "' . $statements6 . '";' . "\n"; if ($ip) { @@ -971,6 +970,31 @@ sub addnode6 { return $commands; } +#--- +# =head3 isc_dhcp6_bootfile_statement +# Descriptions: The ISC DHCPv6 statement that names the boot file for one client of a node. The +# firmware and iPXE of a chainloading node send the two UUID orders, but which one +# sends which depends on the libvirt domain, so their hosts choose the file by boot +# stage and not by the label of the DUID. +# Arguments: $node, $nrent -- noderes, $ntent -- nodetype, $client -- the client label +# Returns: the statement, unescaped, or undef when the client needs no boot file +#--- +sub isc_dhcp6_bootfile_statement +{ + my ( $node, $nrent, $ntent, $client ) = @_; + + $client ||= 'firmware'; + if ( dhcp6_chainloads($nrent) && $client =~ /\A(?:firmware|ipxe)\z/ ) { + return xCAT::DHCP::BootPolicy->isc_dhcp6_boot_stage_statement( + loader_url => dhcp6_bootfile_url_for_node( $node, $node, $nrent, $ntent, 'firmware' ), + script_url => dhcp6_bootfile_url_for_node( $node, $node, $nrent, $ntent, 'ipxe' ), + ); + } + my $url = dhcp6_bootfile_url_for_node( $node, $node, $nrent, $ntent, $client ); + return unless $url; + return qq(option dhcp6.bootfile-url "$url";); +} + #--- # =head3 addnode6_other_clients # Descriptions: The omshell commands for the DHCPv6 clients of a node that hold no address. The @@ -991,8 +1015,9 @@ sub addnode6_other_clients my %created; foreach my $client (@clients) { next unless $client->{duid}; - my $url = dhcp6_bootfile_url_for_node( $node, $node, $nrent, $ntent, $client->{client} ); - next unless $url; + my $statement = isc_dhcp6_bootfile_statement( $node, $nrent, $ntent, $client->{client} ); + next unless $statement; + $statement =~ s/"/\\"/g; my $name = "$node-$client->{client}"; $created{$name} = 1; @@ -1002,7 +1027,7 @@ sub addnode6_other_clients $commands .= "new host\n"; $commands .= "set name = \"$name\"\n"; $commands .= "set dhcp-client-identifier = $client->{duid}\n"; - $commands .= 'set statements = "option dhcp6.bootfile-url \"' . $url . '\";";' . "\n"; + $commands .= 'set statements = "' . $statement . '";' . "\n"; $commands .= "create\n"; $commands .= "close\n"; } diff --git a/xCAT-test/unit/dhcp_dhcpv6_duid.t b/xCAT-test/unit/dhcp_dhcpv6_duid.t index 230d0345e8..e0fdfe1a33 100644 --- a/xCAT-test/unit/dhcp_dhcpv6_duid.t +++ b/xCAT-test/unit/dhcp_dhcpv6_duid.t @@ -1053,8 +1053,10 @@ is( xCAT_plugin::dhcp::radvd_needs_restart( 0, 1 ), 0, 'an unchanged file with t is( $hosts->{'cn02-ipxe'}, undef, 'ISC: a grub2 node has one host' ); my ($statements) = ( $sessions->[1] // '' ) =~ /^set name = "cn01-ipxe"\nset dhcp-client-identifier = \S+\nset statements = "(.*)";\ncreate$/m; - is( $statements, 'option dhcp6.bootfile-url \\"' . $script_url . '\\";', - 'ISC: that host is given the boot script' ); + is( $statements, 'if substring(option dhcp6.user-class, 2, 4) = \\"iPXE\\" { ' + . 'option dhcp6.bootfile-url \\"' . $script_url . '\\"; } else { ' + . 'option dhcp6.bootfile-url \\"' . $shim_url . '\\"; }', + 'ISC: that host gives iPXE the boot script and any other client the shim' ); } # ---- The Genesis image is a third client, and it sends a DUID-LL ---------------------------- @@ -1183,8 +1185,8 @@ is( xCAT_plugin::dhcp::radvd_needs_restart( 0, 1 ), 0, 'an unchanged file with t # ---- mac.duid=canonical makes iPXE the client that holds the address ------------------------ # The canonical order is the DUID that iPXE sends, so the host named after the node answers iPXE -# and the firmware gets the host -firmware. Each host carries the boot file of its own -# client: iPXE that is given the shim again never reaches the boot script of the node. +# and the firmware gets the host -firmware. iPXE that is given the shim again never reaches +# the boot script of the node. { local %DUIDTable::rows = node_rows(%settings); @@ -1207,12 +1209,16 @@ is( xCAT_plugin::dhcp::radvd_needs_restart( 0, 1 ), 0, 'an unchanged file with t is( $hosts->{cn03}, $cn03_canonical, 'ISC: the host of a canonical node is keyed on the DUID iPXE sends' ); is( $hosts->{'cn03-firmware'}, $cn03_firmware, '... and the firmware has a host of its own' ); - my %url; - while ( $session =~ /^set name = "([^"]+)"\nset dhcp-client-identifier = \S+\nset statements = "[^\n]*?bootfile-url \\"([^\\]+)\\"/mg ) { - $url{$1} = $2; + # Option 15 decides the stage on both hosts, so each gives iPXE the boot script and the + # firmware the shim, whichever client its DUID belongs to. + my %stage; + while ( $session =~ /^set name = "([^"]+)"\nset dhcp-client-identifier = \S+\nset statements = "[^\n]*?if substring\(option dhcp6\.user-class, 2, 4\) = \\"iPXE\\" \{ option dhcp6\.bootfile-url \\"([^\\]+)\\"; \} else \{ option dhcp6\.bootfile-url \\"([^\\]+)\\"; \}";$/mg ) { + $stage{$1} = [ $2, $3 ]; } - is( $url{cn03}, $script_url, 'ISC: the host that answers iPXE is given the boot script' ); - is( $url{'cn03-firmware'}, $shim_url, 'ISC: the host that answers the firmware is given the shim' ); + is_deeply( $stage{cn03}, [ $script_url, $shim_url ], + 'ISC: the host of the canonical order gives iPXE the boot script and the firmware the shim' ); + is_deeply( $stage{'cn03-firmware'}, [ $script_url, $shim_url ], + 'ISC: and so does the host of the firmware order' ); # makedhcp -d removes the DHCPv6 hosts by name, so a name it does not list stays behind with # the boot file of a node that makedhcp reported as removed.