# ISC DHCP Server Configuration for PXE Boot
# Supports both BIOS and UEFI boot via iPXE
#
# This configuration:
# - Detects client architecture (BIOS vs UEFI) via option 93
# - Serves iPXE bootloaders via TFTP
# - Chainloads to iPXE boot scripts served over HTTP
# - Supports bare-metal provisioning for Centra Cloud infrastructure

# Global Options
option space pxelinux;
option architecture-type code 93 = unsigned integer 16;

# Default lease times
default-lease-time 600;
max-lease-time 7200;

# DHCP server should be authoritative on this network
authoritative;

# Logging
log-facility local7;

# Subnet Configuration
# IMPORTANT: Adjust this subnet configuration to match your network
subnet 10.0.100.0 netmask 255.255.255.0 {
    # IP address range for PXE clients
    range 10.0.100.100 10.0.100.200;

    # Network configuration
    option routers 10.0.100.1;
    option subnet-mask 255.255.255.0;
    option broadcast-address 10.0.100.255;
    option domain-name-servers 10.0.100.1, 8.8.8.8;
    option domain-name "centra.local";

    # PXE Boot Server Configuration
    # This is the IP address of the PXE/TFTP/HTTP server
    # IMPORTANT: Change this to your provisioning server's IP
    next-server 10.0.100.10;

    # Client Architecture Detection and Boot File Selection
    # This class-based approach handles BIOS vs UEFI boot

    # Architecture types:
    # 0x0000 = x86 BIOS
    # 0x0006 = x86 UEFI (32-bit)
    # 0x0007 = x86-64 UEFI (64-bit)
    # 0x0009 = x86-64 UEFI (64-bit, HTTP)

    if exists user-class and option user-class = "iPXE" {
        # Client is already running iPXE
        # Serve the iPXE boot script via HTTP
        # iPXE will request this via HTTP from next-server
        filename "http://10.0.100.10/boot/ipxe/boot.ipxe";
    } elsif option architecture-type = 00:00 {
        # BIOS x86 client
        # Serve iPXE bootloader for BIOS via TFTP
        filename "undionly.kpxe";
    } elsif option architecture-type = 00:06 {
        # UEFI x86 32-bit client (rare)
        filename "ipxe-i386.efi";
    } elsif option architecture-type = 00:07 {
        # UEFI x86-64 64-bit client (most common for modern servers)
        filename "ipxe.efi";
    } elsif option architecture-type = 00:09 {
        # UEFI x86-64 with HTTP support
        # Some UEFI implementations support HTTP natively
        filename "ipxe.efi";
    } else {
        # Fallback to BIOS bootloader for unknown architectures
        filename "undionly.kpxe";
    }
}

# Host-Specific Configurations
# You can define specific configurations for known MAC addresses
# This allows pre-assigning IP addresses and node profiles

# Example: Control-plane node
host control-plane-01 {
    hardware ethernet 52:54:00:12:34:56;
    fixed-address 10.0.100.50;
    option host-name "control-plane-01";
    # Custom DHCP options can be added here for node identification
}

# Example: Worker node
host worker-01 {
    hardware ethernet 52:54:00:12:34:57;
    fixed-address 10.0.100.60;
    option host-name "worker-01";
}

# Example: All-in-one node (testing/homelab)
host all-in-one-01 {
    hardware ethernet 52:54:00:12:34:58;
    fixed-address 10.0.100.70;
    option host-name "all-in-one-01";
}

# Additional subnet for different network segments (if needed)
# Uncomment and configure if you have multiple provisioning networks
#
# subnet 10.0.101.0 netmask 255.255.255.0 {
#     range 10.0.101.100 10.0.101.200;
#     option routers 10.0.101.1;
#     option subnet-mask 255.255.255.0;
#     option broadcast-address 10.0.101.255;
#     option domain-name-servers 10.0.101.1, 8.8.8.8;
#     next-server 10.0.100.10;
#
#     if exists user-class and option user-class = "iPXE" {
#         filename "http://10.0.100.10/boot/ipxe/boot.ipxe";
#     } elsif option architecture-type = 00:00 {
#         filename "undionly.kpxe";
#     } elsif option architecture-type = 00:07 {
#         filename "ipxe.efi";
#     } else {
#         filename "undionly.kpxe";
#     }
# }

# DHCP Relay Configuration Notes
# If your DHCP server is on a different network segment than the PXE clients,
# you'll need to configure DHCP relay on your network routers:
#
# For Cisco IOS:
#   interface vlan 100
#     ip helper-address 10.0.100.10
#
# For Linux (using dhcp-helper or dhcrelay):
#   dhcrelay -i eth0 -i eth1 10.0.100.10
#
# Ensure UDP ports 67/68 are allowed through firewalls between segments.
