Multiple routers and better rfc3442 implementation
Change-Id: I8bdaed91e0ee723dea871208e8085ef57b224087
diff --git a/README.md b/README.md
index f991ed6..48aa29a 100644
--- a/README.md
+++ b/README.md
@@ -9,8 +9,9 @@
A few assumptions are made by this role:
- 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
+ then the first usable address is set as the router.
+- If `routers` is set and has a list of IP addresses as a part of the
+ `rfc3442routes` key, RFC3442 classless static routes (option 121) will be
added in addition to the standard `routers` (option 3)
## Configuration docs
@@ -62,7 +63,8 @@
- name: "dns"
ip_addr: "192.168.0.2"
mac_addr: "a1:b2:c3:d4:e5:f6"
-
+ routers:
+ - ip: "192.168.0.1"
roles:
- dhcpd
diff --git a/templates/dhcpd.conf.j2 b/templates/dhcpd.conf.j2
index 4839a8c..bda9bec 100644
--- a/templates/dhcpd.conf.j2
+++ b/templates/dhcpd.conf.j2
@@ -17,8 +17,14 @@
# 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('\.', ', ')}};
+ option routers {{ subnet.routers | map(attribute="ip") | join (",") }};
+{% for rtr in subnet.routers %}
+{% if "rfc3442routes" in rtr %}
+{% for r3442r in rtr.rfc3442routes %}
+ option rfc3442-classless-static-routes {{ r3442r | ipaddr('prefix') }}, {{ r3442r | ipaddr('network') | regex_replace('\.', ', ')}}, {{ rtr.ip | ipaddr('network') | regex_replace('\.', ', ')}};
+{% endfor %}
+{% endif %}
+{% endfor %}
{% else %}
# first IP address in range used as router
option routers {{ subnet.subnet | ipaddr('next_usable') }};