From a8bfec6b68b9c2e31402bcd3f79891965c1fc8e1 Mon Sep 17 00:00:00 2001 From: Tobias Schwarz Date: Sun, 6 Aug 2023 13:08:16 +0000 Subject: [PATCH] dhcp: add options for static leases, custom domain names and olsrd-services --- .../templates/corerouter/config/dhcp.j2 | 22 +++++++++++++++++++ .../templates/corerouter/config/olsrd.j2 | 10 +++++++++ 2 files changed, 32 insertions(+) diff --git a/roles/cfg_openwrt/templates/corerouter/config/dhcp.j2 b/roles/cfg_openwrt/templates/corerouter/config/dhcp.j2 index dacbcdf4e..2e044b1b9 100644 --- a/roles/cfg_openwrt/templates/corerouter/config/dhcp.j2 +++ b/roles/cfg_openwrt/templates/corerouter/config/dhcp.j2 @@ -75,3 +75,25 @@ config odhcpd 'odhcpd' option leasefile '/tmp/hosts/odhcpd' option leasetrigger '/usr/sbin/odhcpd-update' option loglevel '4' + +{% for dhcp_static_lease in dhcp_static_leases | default([]) %} +{% if dhcp_static_lease['name'] is defined and dhcp_static_lease['mac'] is defined and dhcp_static_lease['ip'] is defined %} +config host + option name '{{ dhcp_static_lease['name'] }}' + option mac '{{ dhcp_static_lease['mac'] }}' + option ip '{{ dhcp_static_lease['ip'] }}' + {% if dhcp_static_lease['dns'] is defined %} + option dns '{{ dhcp_static_lease['dns'] }}' + {% endif %} + +{% endif %} +{% endfor %} + +{% for dhcp_custom_domain_name in dhcp_custom_domain_names | default([]) %} +{% if dhcp_custom_domain_name['name'] is defined and dhcp_custom_domain_name['ip'] is defined %} +config domain + option name '{{ dhcp_custom_domain_name['name'] }}' + option ip '{{ dhcp_custom_domain_name['ip'] }}' + +{% endif %} +{% endfor %} diff --git a/roles/cfg_openwrt/templates/corerouter/config/olsrd.j2 b/roles/cfg_openwrt/templates/corerouter/config/olsrd.j2 index 59880bdc4..903052350 100644 --- a/roles/cfg_openwrt/templates/corerouter/config/olsrd.j2 +++ b/roles/cfg_openwrt/templates/corerouter/config/olsrd.j2 @@ -13,6 +13,16 @@ config LoadPlugin list hosts '{{ network['prefix'] | ansible.utils.ipaddr(ip_num) | ansible.utils.ipaddr('address') }} {{ host }}' {% endfor %} {% endfor %} +{% for dhcp_static_lease in dhcp_static_leases | default([]) %} +{% if dhcp_static_lease['name'] is defined and dhcp_static_lease['ip'] is defined and dhcp_static_lease['olsrd_nameservice'] is defined and dhcp_static_lease['olsrd_nameservice'] == 1 %} + list hosts '{{ dhcp_static_lease['ip'] }} {{ dhcp_static_lease['name'] }}' +{% endif %} +{% endfor %} +{% for olsrd_service in olsrd_services | default([]) %} + {% if olsrd_service['url'] is defined and olsrd_service['protocol'] is defined and olsrd_service['name'] is defined and olsrd_service['url'] | regex_search('.*\\|.*') is none and olsrd_service['protocol'] | regex_search('^(tcp|udp)$') is defined and olsrd_service['name'] | regex_search('^[a-zA-Z0-9 \-]{1,75}$') is defined %} + list service '{{ olsrd_service['url'] }}|{{ olsrd_service['protocol'] }}|{{ olsrd_service['name'] }}' + {% endif %} +{% endfor %} config LoadPlugin option accept '0.0.0.0'