From 0e8322da2a110d60a067cc9f28bef6dbb89c5cff Mon Sep 17 00:00:00 2001
From: Emil Renner Berthing <esmil@labitat.dk>
Date: Tue, 2 Apr 2019 21:03:51 +0200
Subject: space_server: dhcpd: add hosts to .dhcp zone

Only requests with the host-name header set will be added to
the dhcp zone (so it can be looked up at <hostname>.dhcp).
This will fail if the host-name is not a valid dns name though.

Also leases on the member wired, member wireless, and free
are added to the zone, but just like the s zone the
dhcp zone and reverse dns for 10.42.0.0/16 cannot be queried
from Labitat (free). This way you can connect gadgets to
Labitat (free), but still look them up in dns and connect
to them from the member networks.
---
 roles/space_server/templates/dhcpd.conf.j2 | 53 ++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/roles/space_server/templates/dhcpd.conf.j2 b/roles/space_server/templates/dhcpd.conf.j2
index 23e08da..8e02112 100644
--- a/roles/space_server/templates/dhcpd.conf.j2
+++ b/roles/space_server/templates/dhcpd.conf.j2
@@ -8,7 +8,30 @@
 # attempt to do a DNS update when a lease is confirmed. We default to the
 # behavior of the version 2 packages ('none', since DHCP v2 didn't
 # have support for DDNS.)
+{% if ddns_secret is defined %}
+ddns-update-style interim;
+ddns-local-address4 127.0.0.1;
+ddns-local-address6 ::1;
+
+key dhcpupdate {
+	algorithm {{ ddns_secret.algorithm }};
+	secret {{ ddns_secret.key }};
+}
+
+zone dhcp. {
+	primary 127.0.0.1;
+	primary6 ::1;
+	key dhcpupdate;
+}
+
+zone 42.10.in-addr.arpa. {
+	primary 127.0.0.1;
+	primary6 ::1;
+	key dhcpupdate;
+}
+{% else %}
 ddns-update-style none;
+{% endif %}
 
 # option definitions common to all supported networks...
 #option domain-name "labitat.dk";
@@ -35,6 +58,7 @@ subnet 10.42.0.0 netmask 255.255.255.0 {
 	option routers 10.42.0.1;
 	option domain-name-servers 185.38.175.0;
 	#option ntp-servers 90.185.0.18;
+	ddns-updates off;
 
 	deny bootp;
 	allow duplicates;
@@ -52,6 +76,13 @@ subnet 10.42.1.0 netmask 255.255.255.0 {
 	next-server 10.42.1.1;
 	filename "pxelinux.0";
 
+	if exists host-name {
+		ddns-hostname = option host-name;
+		ddns-domainname "dhcp";
+	} else {
+		ddns-updates off;
+	}
+
 	allow bootp;
 	allow duplicates;
 	allow declines;
@@ -68,6 +99,13 @@ subnet 10.42.2.0 netmask 255.255.255.0 {
 	next-server 10.42.2.1;
 	filename "pxelinux.0";
 
+	if exists host-name {
+		ddns-hostname = option host-name;
+		ddns-domainname "dhcp";
+	} else {
+		ddns-updates off;
+	}
+
 	allow bootp;
 	allow duplicates;
 	allow declines;
@@ -82,6 +120,13 @@ subnet 10.42.3.0 netmask 255.255.255.0 {
 	option domain-name-servers 185.38.175.0;
 	#option ntp-servers 90.185.0.18;
 
+	if exists host-name {
+		ddns-hostname = option host-name;
+		ddns-domainname "dhcp";
+	} else {
+		ddns-updates off;
+	}
+
 	allow bootp;
 	allow duplicates;
 	deny declines;
@@ -96,6 +141,13 @@ subnet 10.42.3.0 netmask 255.255.255.0 {
 #	option domain-name-servers 185.38.175.0;
 #	#option ntp-servers 90.185.0.18;
 #
+#	if exists host-name {
+#		ddns-hostname = option host-name;
+#		ddns-domainname "dhcp";
+#	} else {
+#		ddns-updates off;
+#	}
+#
 #	allow bootp;
 #	allow duplicates;
 #	allow declines;
@@ -104,6 +156,7 @@ subnet 10.42.3.0 netmask 255.255.255.0 {
 
 group {
 	use-host-decl-names on;
+	ddns-updates off;
 {% for host in local_hosts %}
 {% if 'mac' in host and 'ipv4' in host %}
 
-- 
cgit v1.2.1