[LEDE-DEV,PATCHv2] odhcpd: don't enable server mode on non-static lan port

Message ID 1504264931-7435-1-git-send-email-karlp@etactica.com
State Accepted
Headers show
  • [LEDE-DEV,PATCHv2] odhcpd: don't enable server mode on non-static lan port
Related show

Commit Message

Karl Palsson Sept. 1, 2017, 11:22 a.m.
Instead of blindly enabling the odhcpd v6 server and RA server on the
lan port, only do that if the lan port protocol is "static"

This prevents the unhelpful case of a device being a dhcpv4 client and
v6 server on the same ethernet port.

Signed-off-by: Karl Palsson <karlp@etactica.com>
Changes since v1
* use /etc/board.json instead of assuming uci has been updated
* make server _only_ for static, instead of everything but dhcp
* remove logging, no other early service logs anything

 package/network/services/odhcpd/files/odhcpd.defaults | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)


diff --git a/package/network/services/odhcpd/files/odhcpd.defaults b/package/network/services/odhcpd/files/odhcpd.defaults
index e184da90acbb..e9b2353f063b 100644
--- a/package/network/services/odhcpd/files/odhcpd.defaults
+++ b/package/network/services/odhcpd/files/odhcpd.defaults
@@ -2,6 +2,21 @@ 
 uci -q get dhcp.odhcpd && exit 0
 touch /etc/config/dhcp
+. /usr/share/libubox/jshn.sh
+json_load "$(cat /etc/board.json)"
+json_select network
+json_select lan
+json_get_vars protocol
+json_select ..
+json_select ..
+case "$protocol" in
+# only enable server mode on statically addressed lan ports
+"static") MODE=server ;;
+*) MODE=disabled ;;
 uci batch <<EOF
 set dhcp.odhcpd=odhcpd
 set dhcp.odhcpd.maindhcp=0
@@ -10,5 +25,7 @@  set dhcp.odhcpd.leasetrigger=/usr/sbin/odhcpd-update
 set dhcp.odhcpd.loglevel=4
 set dhcp.lan.dhcpv6=server
 set dhcp.lan.ra=server
+set dhcp.lan.dhcpv6=$MODE
+set dhcp.lan.ra=$MODE
 commit dhcp