diff --git a/package/gluon-ddhcpd/Makefile b/package/gluon-ddhcpd/Makefile new file mode 100644 index 00000000..8d46a022 --- /dev/null +++ b/package/gluon-ddhcpd/Makefile @@ -0,0 +1,13 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=gluon-ddhcpd +PKG_VERSION:=1 + +include ../gluon.mk + +define Package/gluon-ddhcpd + TITLE:=Distributed DHCP Daemon for Gluon + DEPENDS:=+gluon-core +ddhcpd +endef + +$(eval $(call BuildPackageGluon,gluon-ddhcpd)) diff --git a/package/gluon-ddhcpd/check_site.lua b/package/gluon-ddhcpd/check_site.lua new file mode 100644 index 00000000..54e5ff51 --- /dev/null +++ b/package/gluon-ddhcpd/check_site.lua @@ -0,0 +1,2 @@ + +need_string_match(in_domain({'next_node', 'ip4'}), '^%d+.%d+.%d+.%d+$', true) diff --git a/package/gluon-ddhcpd/files/etc/ddhcp-hook.sh b/package/gluon-ddhcpd/files/etc/ddhcp-hook.sh new file mode 100755 index 00000000..acacba92 --- /dev/null +++ b/package/gluon-ddhcpd/files/etc/ddhcp-hook.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +for i in /etc/ddhcpd.d/* +do + $i "$@" +done diff --git a/package/gluon-ddhcpd/files/etc/init.d/gluon-ddhcpd b/package/gluon-ddhcpd/files/etc/init.d/gluon-ddhcpd new file mode 100755 index 00000000..ec565b26 --- /dev/null +++ b/package/gluon-ddhcpd/files/etc/init.d/gluon-ddhcpd @@ -0,0 +1,53 @@ +#!/bin/sh /etc/rc.common + +START=90 +USE_PROCD=1 +NAME=ddhcpd +DAEMON=/usr/sbin/ddhcpd +MAXDELAY=10 + +validate_section_ddhcpd() { + uci_validate_section "$NAME" ddhcpd settings \ + 'dhcp_interface:string:br-client' \ + 'server_interface:string:br-client' \ + 'block_size_pow:uinteger:2' \ + 'spare_blocks:uinteger:1' \ + 'timeout:uinteger:30' \ + 'block_network:cidr4' \ + 'dhcp_lease_time:uinteger:300' + server_interface=$(ubus call network.interface dump | jsonfilter -e "@.interface[@.interface='$(cat /lib/gluon/respondd/client.dev 2>/dev/null)' && @.up=true].device") +} + +start_service() { + [ -x /lib/gluon/ddhcpd/arguments ] || exit 1 + + procd_open_instance + procd_set_param command $DAEMON -D + + config_load "${NAME}" + + validate_section_ddhcpd || { + echo "validation failed" + return 1 + } + + procd_append_param command -s "$spare_blocks" + procd_append_param command -b "$block_size_pow" + procd_append_param command -c "$dhcp_interface" + procd_append_param command -i "$server_interface" + procd_append_param command -N "$block_network" + procd_append_param command -o "51:4:0.0.1.44" + procd_append_param command -o "3:4:$(lua -e 'print(require("gluon.site").next_node.ip4())')" + procd_append_param command -o "6:4:$(lua -e 'print(require("gluon.site").next_node.ip4())')" + procd_append_param command $(/lib/gluon/ddhcpd/arguments) + procd_set_param respawn + procd_set_param netdev "$dhcp_interface" + [ "$dhcp_interface" == "$server_interface" ] || procd_append_param netdev "$server_interface" + procd_set_param stderr 1 + procd_close_instance +} + +service_triggers() { + procd_add_config_trigger "config.change" "ddhcpd" /etc/init.d/ddhcpd restart + procd_add_interface_trigger "interface.*" "$server_interface" /etc/init.d/ddhcpd restart +} diff --git a/package/gluon-ddhcpd/files/lib/gluon/ddhcpd/arguments b/package/gluon-ddhcpd/files/lib/gluon/ddhcpd/arguments new file mode 100755 index 00000000..e69de29b diff --git a/package/gluon-ddhcpd/files/lib/gluon/upgrade/317-ddhcpd-disable b/package/gluon-ddhcpd/files/lib/gluon/upgrade/317-ddhcpd-disable new file mode 100755 index 00000000..de08de78 --- /dev/null +++ b/package/gluon-ddhcpd/files/lib/gluon/upgrade/317-ddhcpd-disable @@ -0,0 +1,3 @@ +#!/bin/sh + +uci set ddhcpd.settings.enabled="0" diff --git a/package/gluon-ddhcpd/luasrc/lib/gluon/upgrade/315-dhcp-config-firewall b/package/gluon-ddhcpd/luasrc/lib/gluon/upgrade/315-dhcp-config-firewall new file mode 100755 index 00000000..e1d63a02 --- /dev/null +++ b/package/gluon-ddhcpd/luasrc/lib/gluon/upgrade/315-dhcp-config-firewall @@ -0,0 +1,22 @@ +#!/usr/bin/lua + +local uci = require('simple-uci').cursor() + +uci:section('firewall', 'rule', 'local_node_dhcp', { + src = 'local_client', + name = 'allow_dhcp_local_client', + dest_port = '67', + proto = 'udp', + target = 'ACCEPT' +}) + +uci:section('firewall', 'rule', 'ddhcpd_mmfd', { + dest_port = '1234', + src = 'mmfd', + src_ip = 'fe80::/64', + name = 'allow_ddhcp_to_reserve_blocks', + proto = 'udp', + target = 'ACCEPT' +}) + +uci:save('firewall') diff --git a/package/gluon-ddhcpd/luasrc/lib/gluon/upgrade/316-ddhcp b/package/gluon-ddhcpd/luasrc/lib/gluon/upgrade/316-ddhcp new file mode 100755 index 00000000..5630c697 --- /dev/null +++ b/package/gluon-ddhcpd/luasrc/lib/gluon/upgrade/316-ddhcp @@ -0,0 +1,9 @@ +#!/usr/bin/lua + +local site = require 'gluon.site' + +local uci = require('simple-uci').cursor() + +uci:set('ddhcpd', 'settings', 'block_network', site.prefix4()) + +uci:save('ddhcpd')