Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dhcp: add options for static leases, custom domain names and olsrd services #524

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,56 @@ airos_dfs_reset:
daytime_limit: "2-7"
```
#### dhcp.yml
This optional file allows to set static dhcp leases and custom domain names. The syntax is as follows:
```yml
---
dhcp_static_leases:
- name: hostname1
mac: AA:AA:AA:AA:AA:AA
ip: 10.10.10.1
- name: hostname2
mac: BB:BB:BB:BB:BB:BB
ip: 10.10.10.2
dns: 1
- name: webcam1
mac: CC:CC:CC:CC:CC:CC
ip: 10.10.10.3
dns: 1
olsrd_nameservice: 1
- name: webcam2
mac: DD:DD:DD:DD:DD:DD
ip: 10.10.10.4
dns: 1
olsrd_nameservice: 1

dhcp_custom_domain_names:
- name: unifi
ip: 10.10.10.2
```
A hostname, mac address and ip is required. The option `dns: 1` ensures that the entry is added without the `.lan` suffix.
The option `olsrd_nameservice` also announces the host via the olsrd nameservice, which is useful for olsrd services.

#### olsrd.yml

This optional file allows to announce services via olsrd. The syntax is as follows:

```yml
---
olsrd_services:
- name: Webcam 1
protocol: tcp
url: http://webcam1.olsr:80/
- name: Webcam 2
protocol: tcp
url: http://webcam2.olsr:80/
```

The name, protocol and URL are mandatory. The name has a length constraint of 75 characters. Special chars should not be used.

## host_vars/

The `host-vars`-dir contains a host directory for every OpenWrt-device.
Expand Down
25 changes: 24 additions & 1 deletion roles/cfg_openwrt/templates/corerouter/config/dhcp.j2
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ config dhcp 'dhcp_{{ name }}'

{% for network in networks | selectattr('role','equalto','dhcp') %}
{% for assignment in network['assignments'] %}
config host
config domain
option name '{{ assignment }}'
option ip '{{ network['prefix'] | ansible.utils.ipaddr(network['assignments'][assignment]) | ansible.utils.ipaddr('address') }}'
{% endfor %}
Expand All @@ -75,3 +75,26 @@ 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 %}

# TODO: check that host names are not repeated from the assignments list and throw an error otherwise; make sure to compare hostname and IPv4/IPv6 for this
{% 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'] }}'

Noki marked this conversation as resolved.
Show resolved Hide resolved
{% endif %}
{% endfor %}
11 changes: 11 additions & 0 deletions roles/cfg_openwrt/templates/corerouter/config/olsrd.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ config LoadPlugin
list hosts '{{ network['prefix'] | ansible.utils.ipaddr(ip_num) | ansible.utils.ipaddr('address') }} {{ host }}'
{% endfor %}
{% endfor %}
# TODO: check that host names are not repeated from the assignments list and throw an error otherwise
{% 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'] }}'
Noki marked this conversation as resolved.
Show resolved Hide resolved
{% 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'
Expand Down