Skip to content

Commit

Permalink
switch to completely differetn config schema, more DNSvsDHCP oriented
Browse files Browse the repository at this point in the history
  • Loading branch information
f18m committed Dec 3, 2024
1 parent 9d59555 commit cfe3a86
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 124 deletions.
130 changes: 72 additions & 58 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,45 @@ ingress_port: 8100
panel_icon: mdi:ip-network-outline
panel_title: DHCP
options:
# default lease time for all DHCP clients except those having an IP address reservation.
default_lease: 1h
# the address reservation lease might also be 'infinite' but this is discouraged since
# it means that the dHCP clients will never come back to this server to ACK their IP
# and this makes the whole DHCP server less useful... it's better to force the clients
# to some frequent check-in, since that becomes a basic heartbeat / client health check.
address_reservation_lease: 1h

# network section defines a number of properties that help populate DHCP answers.
network:
# the interface on which the DHCP server will listen for DHCP requests on port 67
interface: enp1s0
# the interface on which the DHCP/DNS server will listen
# DHCP requests are listened on port 67
# DNS requests are listened on port 53
interface: enp1s0
dhcp_server:
# default lease time for all DHCP clients except those having an IP address reservation.
default_lease: 1h
# the address reservation lease might also be 'infinite' but this is discouraged since
# it means that the DHCP clients will never come back to this server to refresh their lease
# and this makes the whole DHCP server less useful... it's better to force the clients
# to some frequent check-in, since that becomes a basic heartbeat / client health check.
address_reservation_lease: 1h
# DHCP start-end IP pool
start_ip: 192.168.1.50
end_ip: 192.168.1.250
# the addon can detect whether the server which is running the addon has just rebooted;
# if that's the case and the following flag is set to "true", then the DHCP lease database
# is reset before starting the DHCP server; this is useful in case a loss of power of the
# HomeAssistant server means also a loss of power of several/all DHCP clients. In such a case
# the old DHCP lease database is not useful and actually misleading.
reset_dhcp_lease_database_on_reboot: false
# shall log every DHCP request?
log_requests: true
# network section defines a number of properties that are used to populate DHCP answers.
dhcp_network:
# the broadcast IP address to advertise in DHCP answers
broadcast: 192.168.1.255
# the gateway IP address to advertise in DHCP answers
gateway: 192.168.1.254
# the netmask to advertise in DHCP answers
netmask: 255.255.255.0
# dns servers to advertise in DHCP answers OR used as upstream DNS servers when
# dns_server.enable=true
dns:
# DNS servers to advertise in DHCP answers (primary, secondary, tertiary, etc)
dns_servers:
- 0.0.0.0 # the special value 0.0.0.0 indicates the IP address of this host -- useful only if dns_server.enable=true
- 8.8.8.8
- 8.8.4.4
dns_domain: home
ntp:
# DNS domain to advertise in DHCP answers
dns_domain: lan
ntp_servers:
# define NTP servers to provide to DHCP clients (not all clients will honor this setting though)
# example1: online NTP servers: check https://www.ntppool.org/zone/@ for details about continental zones:
- 0.europe.pool.ntp.org
Expand All @@ -59,16 +73,7 @@ options:
#- time3.google.com
# example3: the entry 0.0.0.0 means "the address of the machine running dnsmasq"
#- 0.0.0.0
dns_server:
# should this addon provide also a DNS server?
enable: true
# how many entries should be cached on the DNS server to reduce traffic to upstream DNS servers?
# the max size for this cache is 10k entries according to dnsmasq docs
cache_size: 10000
dhcp_range:
start_ip: 192.168.1.50
end_ip: 192.168.1.250
ip_address_reservations: # TODO: rename to dhcp_ip_address_reservations for consistency around DHCP-related opts
dhcp_ip_address_reservations:
- mac: aa:bb:cc:dd:ee:ff
name: "An-important-host-with-reserved-IP"
ip: 192.168.1.15
Expand All @@ -81,39 +86,43 @@ options:
# the 'link' property accepts a basic golang template. Available variables are 'mac', 'name' and 'ip'
# e.g. "http://{{ ip }}/landing/page/for/this/dynamic/host"
link:
log_dns: true
log_dhcp: true
log_web_ui: false
# this addon uses "host_network: true" so the internal HTTP server will bind on the interface
# provided as network.interface and will occupy a port there; the following parameter makes
# that port configurable to avoid conflicts with other services
web_ui_port: 8976
# the addon can detect whether the server which is running the addon has just rebooted;
# if that's the case and the following flag is set to "true", then the DHCP lease database
# is reset before starting the DHCP server; this is useful in case a loss of power of the
# HomeAssistant server means also a loss of power of several/all DHCP clients. In such a case
# the old DHCP lease database is not useful and actually misleading.
reset_dhcp_lease_database_on_reboot: false
dns_server:
# should this addon provide also a DNS server?
enable: true
# how many entries should be cached on the DNS server to reduce traffic to upstream DNS servers?
# the max size for this cache is 10k entries according to dnsmasq docs
cache_size: 10000
log_requests: true
# DNS domain to resolve locally
dns_domain: lan
dns_upstream_servers:
- 8.8.8.8
- 8.8.4.4
web_ui:
log_activity: false
# this addon uses "host_network: true" so the internal HTTP server will bind on the interface
# provided as network.interface and will occupy a port there; the following parameter makes
# that port configurable to avoid conflicts with other services
port: 8976
schema:
default_lease: str
address_reservation_lease: str
network:
interface: str
dhcp_server:
default_lease: str
address_reservation_lease: str
start_ip: str
end_ip: str
reset_dhcp_lease_database_on_reboot: bool
log_requests: bool
dhcp_network:
broadcast: str
gateway: str
interface: str
netmask: str
dns:
dns_servers:
- str
dns_domain: str
ntp:
ntp_servers:
- str
dns_server:
enable: bool
cache_size: int
dhcp_range:
start_ip: str
end_ip: str
ip_address_reservations:
dhcp_ip_address_reservations:
- ip: str
mac: match(^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$)
# the name in this case must be a valid hostname as per RFC 1123 since it is passed to dnsmasq
Expand All @@ -124,11 +133,16 @@ schema:
- mac: match(^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$)
name: str
link: "str?"
log_dns: bool
log_dhcp: bool
log_web_ui: bool
web_ui_port: int
reset_dhcp_lease_database_on_reboot: bool
dns_server:
enable: bool
cache_size: int
log_requests: bool
dns_domain: str
dns_upstream_servers:
- str
web_ui:
log_activity: bool
port: int
startup: system
privileged:
- NET_ADMIN
38 changes: 18 additions & 20 deletions rootfs/usr/share/tempio/dnsmasq.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Automatically generated do not edit
# See https://thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html

interface={{ .network.interface }}
interface={{ .interface }}
keep-in-foreground
log-facility=-
no-poll
Expand Down Expand Up @@ -29,13 +29,13 @@ no-hosts
cache-size={{ .dns_server.cache_size }}

# list of upstream DNS servers
{{ range .network.dns }}
{{ range .dns_upstream_servers }}
server={{ . }}
{{ end }}
local=/{{ .network.dns_domain }}/
domain={{ .network.dns_domain }}
local=/{{ .dns_server.dns_domain }}/
domain={{ .dns_server.dns_domain }}

{{ if .log_dns }}
{{ if .dns_server.log_requests }}
log-queries # log DNS related messages
{{ end }}

Expand All @@ -44,7 +44,7 @@ log-queries # log DNS related messages
# DHCP config
#

{{ if .log_dhcp }}
{{ if .dhcp_server.log_requests }}
log-dhcp # log dhcp related messages
{{ end }}

Expand All @@ -56,33 +56,31 @@ dhcp-script=/opt/bin/dnsmasq-dhcp-script.sh
script-on-renewal

# Activate DHCP by enabling a range of IP addresses to be provisioned by DHCP server
dhcp-range={{ .dhcp_range.start_ip }},{{ .dhcp_range.end_ip }},{{ .network.netmask }},{{ .default_lease }}
dhcp-range={{ .dhcp_server.start_ip }},{{ .dhcp_server.end_ip }},{{ .dhcp_network.netmask }},{{ .dhcp_server.default_lease }}

# Set gateway -- i.e. option #3 of DHCP specs
dhcp-option=3,{{ .network.gateway }}
dhcp-option=3,{{ .dhcp_network.gateway }}

# if this dnsmasq instance has DNS enabled; then leave dnsmasq defaults in place which mean
{{ if not .dns_server.enable }}
{{ if .network.dns }}
{{ if gt (len .network.dns) 0 }}
{{ if .dhcp_network.dns_servers }}
{{ if gt (len .dhcp_network.dns_servers) 0 }}
# Set DNS server(s) -- i.e. option #6 of DHCP specs
dhcp-option=6{{ range .network.dns }},{{ . }}{{ end }}
{{ end }}
dhcp-option=6{{ range .dhcp_network.dns_servers }},{{ . }}{{ end }}
{{ end }}
{{ end }}

{{ if .network.ntp_resolved }}
{{ if gt (len .network.ntp_resolved) 0 }}
{{ if .dhcp_network.ntp_resolved }}
{{ if gt (len .dhcp_network.ntp_resolved) 0 }}
# Set NTP server(s) -- i.e. option #42 of DHCP specs
dhcp-option=42{{ range .network.ntp_resolved }},{{ . }}{{ end }}
dhcp-option=42{{ range .dhcp_network.ntp_resolved }},{{ . }}{{ end }}
{{ end }}
{{ end }}

{{ if .ip_address_reservations }}
{{ if gt (len .ip_address_reservations) 0 }}
{{ range .ip_address_reservations }}
{{ if .dhcp_ip_address_reservations }}
{{ if gt (len .dhcp_ip_address_reservations) 0 }}
{{ range .dhcp_ip_address_reservations }}
# Set static IP address reservations
dhcp-host={{ .mac }},{{ .name }},{{ .ip }},{{ $.address_reservation_lease }}
dhcp-host={{ .mac }},{{ .name }},{{ .ip }},{{ $.dhcp_server.address_reservation_lease }}
{{ end }}
{{ end }}
{{ end }}
95 changes: 49 additions & 46 deletions translations/en.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
---
configuration:
default_lease:
name: Default DHCP lease time
description: This represents the default DHCP lease time for all DHCP clients except those having an IP address reservation. This can be given in seconds, minutes (m) or hours (h) or you can use 'infinite'.
address_reservation_lease:
name: DHCP lease time for IP address reservations
description: This can be given in seconds, minutes (m) or hours (h) or you can use 'infinite'.
interface:
name: Network interface
description: The interface on which the DHCP/DNS server will listen; DHCP requests are listened on port 67; DNS requests are listened on port 53

network:
name: Local Area Network Settings
description: Contains the definition of the network where the DHCP server will be listening
dhcp_range:
name: DHCP Server IP Pool
description: Defines the range of IP addresses to be served dynamically to the clients

dns_server:
name: DNS Server Settings
description: Enables the possibility to use dnsmasq as a local DNS resolver
dhcp_server:
name: DHCP Server settings
description: Contains some critical configs for the DHCP server
# default_lease:
# name: Default DHCP lease time
# description: This represents the default DHCP lease time for all DHCP clients except those having an IP address reservation. This can be given in seconds, minutes (m) or hours (h) or you can use 'infinite'.
# address_reservation_lease:
# name: DHCP lease time for IP address reservations
# description: This can be given in seconds, minutes (m) or hours (h) or you can use 'infinite'.
# start_ip:
# name: DHCP Start IP address
# description: The first IP address of the DHCP range that defines the DHCP address pool.
# end_ip:
# name: DHCP End IP address
# description: The last IP address of the DHCP range that defines the DHCP address pool.
# log_requests:
# name: Log DHCP
# description: Log all details about DHCP requests served by the server
# reset_dhcp_lease_database_on_reboot:
# name: Reset DHCP Lease Database On Reboot
# description: |
# The addon can detect whether the server which is running the addon has just rebooted;
# if that's the case and the following flag is set to "true", then the DHCP lease database
# is reset before starting the DHCP server; this is useful in case a loss of power of the
# HomeAssistant server means also a loss of power of several/all DHCP clients. In such a case
# the old DHCP lease database is not useful and actually misleading.

dhcp_network:
name: Local Area Network Settings
description: Contains the properties of the network where the DHCP server will be serving
# FIXME: somehow the below syntax does not work
# network:
# broadcast:
# name: Network Broadcast Address
# description: Check Wikipedia 'Broadcast Address' page for more info. Typical examples of broadcast addresses are 192.168.0.255 or 192.168.1.255.
Expand All @@ -36,38 +51,26 @@ configuration:
# name: List of DNS servers
# description: DNS servers to advertise inside DHCP OFFER messages.

# dhcp_range:
# start_ip:
# name: DHCP Start IP address
# description: The first IP address of the DHCP range that defines the DHCP address pool.
# end_ip:
# name: DHCP End IP address
# description: The last IP address of the DHCP range that defines the DHCP address pool.
ip_address_reservations:
dhcp_ip_address_reservations:
name: DHCP IP Address Reservations
description: List of MAC addresses / IP addresses pairs that are reserved. Strict regex validation is performed on MAC addresses and hostnames (use alphanumeric chars plus dot or hyphens only).
dhcp_clients_friendly_names:
name: DHCP Clients Friendly Names
description: List of MAC addresses / friendly-name pairs to help identify the DHCP clients in the Web UI. Strict regex validation is performed on MAC addresses.

log_dns:
name: Log DNS
description: Log all details about DNS requests served by the server
log_dhcp:
name: Log DHCP
description: Log all details about DHCP requests served by the server
log_web_ui:
name: Log Web UI
description: Log all HTTP requests served by the add-on UI
web_ui_port:
name: Web UI Port
description: Port used by the internal HTTP server. Change only if you get a conflict on the default port.

reset_dhcp_lease_database_on_reboot:
name: Reset DHCP Lease Database On Reboot
description: |
The addon can detect whether the server which is running the addon has just rebooted;
if that's the case and the following flag is set to "true", then the DHCP lease database
is reset before starting the DHCP server; this is useful in case a loss of power of the
HomeAssistant server means also a loss of power of several/all DHCP clients. In such a case
the old DHCP lease database is not useful and actually misleading.
dns_server:
name: DNS Server Settings
description: Enables the possibility to use dnsmasq as a local DNS resolver
# log_dns:
# name: Log DNS
# description: Log all details about DNS requests served by the server
dns_upstream_servers:
name: DNS Upstream Servers
description: List of DNS servers to which queries are forwarded when local DNS resolver does not have the answer in cache
web_ui:
name: Web UI Settings
description: All settings related to the web UI
# port:
# name: Web UI Port
# description: Port used by the internal HTTP server. Change only if you get a conflict on the default port.

0 comments on commit cfe3a86

Please sign in to comment.