Skip to content

Commit

Permalink
dhcp: add options for static leases, custom domain names and olsrd-se…
Browse files Browse the repository at this point in the history
…rvices
  • Loading branch information
Noki committed Sep 18, 2023
1 parent 0d82ff8 commit 1572660
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
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'] }}'

{% 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'] }}'
{% 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

0 comments on commit 1572660

Please sign in to comment.