[OpenWrt-Devel] [PATCH 1/3 v2] netifd: implement zeroconf

Michel Stam m.stam at fugro.nl
Mon Oct 6 11:30:16 EDT 2014


The scripts were based on the netifd dhcp scripts,
and should add zeroconf support to /etc/config/network
Example:
	config interface 'lan'
        option ifname 'eth0'
        option auto '0'
        option proto 'zeroconf'

Optionally, the desired IP address can be added by:
        option ipaddr '169.254.200.100'

and the range from which addresses are desired can
be added by:
		option range '192.168.0.0'

Note that zcip in Busybox must be enabled for this to
work.

Signed-off-by: Michel Stam <m.stam at fugro.nl>
---
 .../netifd/files/lib/netifd/proto/zeroconf.sh      | 34 ++++++++++++++++++++++
 .../config/netifd/files/lib/netifd/zeroconf.script | 29 ++++++++++++++++++
 2 files changed, 63 insertions(+)
 create mode 100755 package/network/config/netifd/files/lib/netifd/proto/zeroconf.sh
 create mode 100755 package/network/config/netifd/files/lib/netifd/zeroconf.script

diff --git a/package/network/config/netifd/files/lib/netifd/proto/zeroconf.sh b/package/network/config/netifd/files/lib/netifd/proto/zeroconf.sh
new file mode 100755
index 0000000..f7a6f76
--- /dev/null
+++ b/package/network/config/netifd/files/lib/netifd/proto/zeroconf.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+. /lib/functions.sh
+. ../netifd-proto.sh
+init_proto "$@"
+
+proto_zeroconf_init_config() {
+	proto_config_add_string 'ipaddr:ipaddr'
+	proto_config_add_string 'range:ipaddr'
+}
+
+proto_zeroconf_setup() {
+	local config="$1"
+	local iface="$2"
+
+	local ipaddr
+	local range
+	json_get_vars ipaddr range
+
+	proto_export "INTERFACE=$config"
+	proto_run_command "$config" zcip \
+		${ipaddr:+-r $ipaddr} \
+		${range:+-l $range} \
+		-f "$iface" \
+		/lib/netifd/zeroconf.script
+}
+
+proto_zeroconf_teardown() {
+	local interface="$1"
+	proto_kill_command "$INTERFACE"
+}
+
+add_protocol zeroconf
+
diff --git a/package/network/config/netifd/files/lib/netifd/zeroconf.script b/package/network/config/netifd/files/lib/netifd/zeroconf.script
new file mode 100755
index 0000000..8d34a67
--- /dev/null
+++ b/package/network/config/netifd/files/lib/netifd/zeroconf.script
@@ -0,0 +1,29 @@
+#!/bin/sh
+[ -z "$1" ] && echo "Error: should be run by zcip" && exit 1
+
+. /lib/functions.sh
+. /lib/netifd/netifd-proto.sh
+
+setup_interface () {
+	proto_init_update "*" 1
+	proto_add_ipv4_address "$ip" '255.255.0.0'
+	proto_send_update "$INTERFACE"
+}
+
+deconfig_interface() {
+	proto_init_update "*" 0
+	proto_send_update "$INTERFACE"
+}
+
+case "$1" in
+	deconfig)
+		deconfig_interface
+	;;
+	config)
+		setup_interface
+	;;
+	*|init)
+	;;
+esac
+
+exit 0
-- 
1.7.12.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list