Support RFC3442 classless routing
Change-Id: I83ff68394edc894cbc92e4ee8a60b574d0006dd4
diff --git a/README.md b/README.md
index 230a9e8..f991ed6 100644
--- a/README.md
+++ b/README.md
@@ -6,20 +6,36 @@
Installs/configure a DHCP server and TFTP server
-## dhcpd
+A few assumptions are made by this role:
-Documentation:
+- If `routers` is not set in the `subnet` dictionary (within `dhcpd_subnets`),
+ then the first usable address is assumed to be the router.
+- If `routers` is set, RFC3442 classless static routes (option 121) will be
+ added in addition to the standard `routers` (option 3)
+
+## Configuration docs
+
+dhcpd - ISC's docs:
- https://kb.isc.org/docs/isc-dhcp-44-manual-pages-dhcpd
- https://kb.isc.org/docs/isc-dhcp-44-manual-pages-dhcpdconf
- https://kb.isc.org/docs/isc-dhcp-44-manual-pages-dhcp-options
-## tftpd
-
-Documentation is scarce. Upstream source repo:
+tftpd - Documentation is scarce. Upstream source repo:
- https://git.kernel.org/pub/scm/network/tftp/tftp-hpa.git
+## Reference docs
+
+DHCP:
+
+- [RFC2131 - DHCP Protocol](https://tools.ietf.org/html/rfc2131)
+- [RFC2132 - DHCP Options](https://tools.ietf.org/html/rfc2132)
+- [RFC3442 - Classless Static routes](https://tools.ietf.org/html/rfc3442)
+
+TFTP:
+
+- [RFC1350 - TFTP protocol v2](https://tools.ietf.org/html/rfc1350)
## Requirements
diff --git a/templates/dhcpd.conf.j2 b/templates/dhcpd.conf.j2
index 2a67a37..4839a8c 100644
--- a/templates/dhcpd.conf.j2
+++ b/templates/dhcpd.conf.j2
@@ -8,13 +8,19 @@
default-lease-time {{ subnet.lease_time | default("240") }};
max-lease-time {{ subnet.max_lease_time | default("480") }};
+# option definitions
+option rfc3442-classless-static-routes code 121 = array of integer 8;
+
{% for subnet in dhcpd_subnets %}
subnet {{ subnet.subnet | ipaddr('network') }} netmask {{ subnet.subnet | ipaddr('netmask') }} {
# routing
{% if subnet.routers is defined %}
+ # custom router IP set
option routers {{ subnet.routers }};
+ option rfc3442-classless-static-routes {{ subnet.subnet | ipaddr('prefix') }}, {{ subnet.subnet | ipaddr('network') | regex_replace('\.', ', ')}}, {{ subnet.routers | ipaddr('network') | regex_replace('\.', ', ')}};
{% else %}
+ # first IP address in range used as router
option routers {{ subnet.subnet | ipaddr('next_usable') }};
{% endif %}