From a8ce2d5f8ca5ce1bc990ecd5375724cb7f2a1e09 Mon Sep 17 00:00:00 2001 From: jow Date: Fri, 18 Oct 2013 11:39:56 +0000 Subject: [PATCH] isc-dhcp: dhcrelay: Add more UCI options Add more options to dhcrelay UCI and init script: - enabled - interfaces: Listen interfaces - relay_mode: What to do about packets that already have a relay option Also mark /etc/config/dhcrelay as conffile Signed-off-by: Bruno Randolf git-svn-id: svn://svn.openwrt.org/openwrt/packages@38446 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- net/isc-dhcp/Makefile | 8 ++++++ net/isc-dhcp/files/dhcrelay4.init | 36 +++++++++++++++++++++----- net/isc-dhcp/files/etc/config/dhcrelay | 24 +++++++++++++---- 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/net/isc-dhcp/Makefile b/net/isc-dhcp/Makefile index aa27aca0a..5e5471f9d 100644 --- a/net/isc-dhcp/Makefile +++ b/net/isc-dhcp/Makefile @@ -55,11 +55,19 @@ $(call Package/isc-dhcp-relay-ipv6/description) This package is compiled with IPv4 support only. endef +define Package/isc-dhcp-relay-ipv4/conffiles +/etc/config/dhcrelay +endef + define Package/isc-dhcp-relay-ipv6/description $(call Package/isc-dhcp-relay/description) This package is compiled with IPv4 and IPv6 support. endef +define Package/isc-dhcp-relay-ipv6/conffiles +/etc/config/dhcrelay +endef + define Package/isc-dhcp-client-ipv4 $(call Package/isc-dhcp/Default) TITLE+= client (without IPv6) diff --git a/net/isc-dhcp/files/dhcrelay4.init b/net/isc-dhcp/files/dhcrelay4.init index 70905cfa4..e1e68711e 100644 --- a/net/isc-dhcp/files/dhcrelay4.init +++ b/net/isc-dhcp/files/dhcrelay4.init @@ -8,15 +8,39 @@ SERVICE_PID_FILE="/var/run/dhcrelay4.pid" SERVICE_USE_PID=1 start() { - local relay_dhcpserver + . /lib/functions/network.sh + config_load dhcrelay + local args="" - config_load dhcrelay - config_get relay_dhcpserver ipv4 dhcpserver + local enabled + config_get_bool enabled ipv4 enabled 0 + [ "$enabled" -eq 0 ] && return 0 - service_start /usr/sbin/dhcrelay -4 -q \ - -pf $SERVICE_PID_FILE $relay_dhcpserver + # listen interfaces + local interfaces + local ifname + config_get interfaces ipv4 interfaces + for net in $interfaces; do + if network_get_device ifname "$net"; then + append args "-i $ifname" + fi + done + + # relay mode + local relay_mode + config_get relay_mode ipv4 relay_mode + [ -n "$relay_mode" ] && append args "-m $relay_mode" + + # dhcp server address + local server + config_get server ipv4 dhcpserver + [ -n "$server" ] || return 0 + append args "$server" + + service_start /usr/sbin/dhcrelay -4 -q \ + -pf $SERVICE_PID_FILE $args } stop() { - service_stop /usr/sbin/dhcrelay + service_stop /usr/sbin/dhcrelay } diff --git a/net/isc-dhcp/files/etc/config/dhcrelay b/net/isc-dhcp/files/etc/config/dhcrelay index 5fde2399e..1b8978256 100644 --- a/net/isc-dhcp/files/etc/config/dhcrelay +++ b/net/isc-dhcp/files/etc/config/dhcrelay @@ -1,10 +1,24 @@ config dhcrelay ipv4 - option dhcpserver '192.0.2.10' + option 'enabled' '0' + + # IP address of the server + option 'dhcpserver' '192.0.2.10' + + # network interfaces to listen on (e.g. lan or wan) + option 'interfaces' '' + + # What to do about packets that already have a relay option: + # 'append': Forward and append our own relay option + # 'replace': Forward, but replace theirs with ours (default) + # 'forward': Forward without changes + # 'discard': Don't forward + option 'relay_mode' '' + config dhcrelay ipv6 -# option dhcpserver '2001:db8:1::1' - option upper 'eth1' - list lower 'eth0.2' - list lower 'eth0.3' +# option dhcpserver '2001:db8:1::1' + option upper 'eth1' + list lower 'eth0.2' + list lower 'eth0.3'