Files
edgeguard-native/internal/models/dhcp.go
Debian bac7c7e349 feat(dhcp): DHCPv4-Server via Kea (kea-dhcp4-server) — v1.2.92
Verwalteter DHCPv4-Server analog Unbound/Squid/Chrony.
- Migration 0041: dhcp_settings (singleton, node-lokal), dhcp_subnets, dhcp_reservations.
- internal/kea: Renderer baut Kea-JSON via Go-Struct→Marshal (garantiert valide), managed /etc/edgeguard/kea/kea-dhcp4.conf (Symlink von /etc/kea), Service-Lifecycle an enabled gekoppelt (default AUS, kein rogue DHCP). Interface per NAME (cluster-sicher, kein node-lokaler FK).
- internal/services/dhcp + internal/handlers/dhcp.go: Settings + Subnet/Reservation-CRUD, Validierung (CIDR/IP/MAC/interface exists).
- configgen: Stop/Enable/DisableService. Firewall: AutoFWRule.Iface → udp/67 pro LAN-Interface gescopt (kein WAN). Cluster: subnets/reservations repliziert (hashSpec), dhcp_settings node-lokal (localOnlyTables).
- main.go + render.go + WithAllReloaders Wiring. Packaging: kea-dhcp4-server Dependency, /etc/edgeguard/kea Dir, Symlink, disable-on-install, sudoers (restart/stop/enable/disable).
- UI: DHCP-Seite (Settings + Subnets + Reservierungen pro Subnet), Route/Nav/i18n de/en, HA-Warnung 'nur auf einer Node aktivieren'.
- Tests (guarded EG_FWTEST_DSN): Kea-Renderer gegen DB (valides JSON + Felder), FW-Auto-Rule-Iface inkl. nft -c. Scope v1: DHCPv4.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 18:56:30 +02:00

54 lines
2.8 KiB
Go

package models
import "time"
// DHCPSettings ist die node-lokale Singleton-Konfiguration des Kea-DHCPv4-
// Servers (ob diese Node DHCP betreibt + globale Defaults).
type DHCPSettings struct {
ID int `gorm:"column:id;primaryKey" json:"id"`
Enabled bool `gorm:"column:enabled" json:"enabled"`
DefaultLease int `gorm:"column:default_lease" json:"default_lease"`
MaxLease int `gorm:"column:max_lease" json:"max_lease"`
DomainName string `gorm:"column:domain_name" json:"domain_name"`
DNSServers string `gorm:"column:dns_servers" json:"dns_servers"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
}
func (DHCPSettings) TableName() string { return "dhcp_settings" }
// DHCPSubnet ist ein vom DHCP-Server bedientes Subnetz (an ein Interface
// per NAME gebunden — cluster-sicher, da interface_id node-lokal wäre).
type DHCPSubnet struct {
ID int64 `gorm:"column:id;primaryKey" json:"id"`
Name string `gorm:"column:name" json:"name"`
InterfaceName string `gorm:"column:interface_name" json:"interface_name"`
SubnetCIDR string `gorm:"column:subnet_cidr" json:"subnet_cidr"`
PoolStart string `gorm:"column:pool_start" json:"pool_start"`
PoolEnd string `gorm:"column:pool_end" json:"pool_end"`
Gateway string `gorm:"column:gateway" json:"gateway"`
DNSServers string `gorm:"column:dns_servers" json:"dns_servers"`
LeaseTime *int `gorm:"column:lease_time" json:"lease_time,omitempty"`
Active bool `gorm:"column:active" json:"active"`
Description string `gorm:"column:description" json:"description"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
}
func (DHCPSubnet) TableName() string { return "dhcp_subnets" }
// DHCPReservation ist eine statische MAC→IP-Zuordnung innerhalb eines Subnets.
type DHCPReservation struct {
ID int64 `gorm:"column:id;primaryKey" json:"id"`
SubnetID int64 `gorm:"column:subnet_id" json:"subnet_id"`
Name string `gorm:"column:name" json:"name"`
MACAddress string `gorm:"column:mac_address" json:"mac_address"`
IPAddress string `gorm:"column:ip_address" json:"ip_address"`
Hostname string `gorm:"column:hostname" json:"hostname"`
Active bool `gorm:"column:active" json:"active"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
}
func (DHCPReservation) TableName() string { return "dhcp_reservations" }