{{if $.Dhcp.Enabled -}}
# This file is autogenerated by warewulf
# Host:   {{.BuildHost}}
# Time:   {{.BuildTime}}
# Source: {{.BuildSource}}

allow booting;
allow bootp;
ddns-update-style interim;
authoritative;

option space ipxe;

# Tell iPXE to not wait for ProxyDHCP requests to speed up boot.
option ipxe.no-pxedhcp code 176 = unsigned integer 8;
option ipxe.no-pxedhcp 1;

option space PXE;
option PXE.mtftp-ip    code 1 = ip-address;
option PXE.mtftp-cport code 2 = unsigned integer 16;
option PXE.mtftp-sport code 3 = unsigned integer 16;
option PXE.mtftp-tmout code 4 = unsigned integer 8;
option PXE.mtftp-delay code 5 = unsigned integer 8;

option architecture-type   code 93  = unsigned integer 16;

{{- if $.Warewulf.GrubBoot }}
if substring (option vendor-class-identifier, 0, 9) = "PXEClient" {
  next-server {{ $.Ipaddr }};
  if substring (option vendor-class-identifier, 15, 5) = "00000" {
    # pure BIOS clients will get iPXE configuration
    filename "http://{{$.Ipaddr}}:{{$.Warewulf.Port}}/ipxe/${mac:hexhyp}";
  } else {
    # EFI clients will get shim and grub instead
    filename "warewulf/shim.efi";
  }
} elsif substring (option vendor-class-identifier, 0, 10) = "HTTPClient" {
  filename "http://{{$.Ipaddr}}:{{$.Warewulf.Port}}/efiboot/shim.efi";
}
{{- else }}
if exists user-class and option user-class = "iPXE" {
    filename "http://{{$.Ipaddr}}:{{$.Warewulf.Port}}/ipxe/${mac:hexhyp}";
} else {
{{range $type,$name := $.Tftp.IpxeBinaries }}
    if option architecture-type = {{ $type }} {
        filename "/warewulf/{{ basename $name }}";
    }
{{- end }}{{/* range IpxeBinaries */}}
}
{{- end }}{{/* BootMethod */}}

subnet {{$.Network}} netmask {{$.Netmask}} {
    max-lease-time 120;
    range {{$.Dhcp.RangeStart}} {{$.Dhcp.RangeEnd}};
    next-server {{.Ipaddr}};
}

{{- if eq .Dhcp.Template "static" }}
{{- range $nodes := $.AllNodes}}
{{- range $netname, $netdevs := $nodes.NetDevs}}
host {{$nodes.Id.Get}}-{{$netname}}
{
    {{- if $netdevs.Primary.GetB}}
    {{- if $netdevs.Hwaddr.Defined}}
    hardware ethernet {{$netdevs.Hwaddr.Get}};
    {{- end }}
    {{- if $netdevs.Ipaddr.Defined}}
    fixed-address {{$netdevs.Ipaddr.Get}};
    {{- end }}
    option host-name "{{$nodes.Id.Get}}";
    {{- end }}
}
{{end -}}{{/* range NetDevs */}}
{{end -}}{{/* range AllNodes */}}
{{end -}}{{/* if static */}}

{{- else}}
{{abort}}
{{- end}}{{/* dhcp enabled */}}
