mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-22 06:57:57 +00:00
odhcp6c: Add preliminary proto-handler
SVN-Revision: 35135
This commit is contained in:
parent
b58a13cb2c
commit
f0df2006af
@ -8,7 +8,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=odhcp6c
|
||||
PKG_VERSION:=2013-01-02
|
||||
PKG_VERSION:=2013-01-11
|
||||
PKG_RELEASE=$(PKG_SOURCE_VERSION)
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
|
||||
@ -31,6 +31,9 @@ endef
|
||||
define Package/odhcp6c/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin/
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/odhcp6c $(1)/usr/sbin/
|
||||
$(INSTALL_DIR) $(1)/lib/netifd/proto
|
||||
$(INSTALL_BIN) ./files/dhcpv6.sh $(1)/lib/netifd/proto/dhcpv6.sh
|
||||
$(INSTALL_BIN) ./files/dhcpv6.script $(1)/lib/netifd/
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,odhcp6c))
|
||||
|
77
package/network/ipv6/odhcp6c/files/dhcpv6.script
Executable file
77
package/network/ipv6/odhcp6c/files/dhcpv6.script
Executable file
@ -0,0 +1,77 @@
|
||||
#!/bin/sh
|
||||
[ -z "$2" ] && echo "Error: should be run by odhcpc6c" && exit 1
|
||||
. /lib/functions.sh
|
||||
. /lib/netifd/netifd-proto.sh
|
||||
|
||||
ipv6_conf() {
|
||||
echo "$3" > "/proc/sys/net/ipv6/conf/$1/$2"
|
||||
}
|
||||
|
||||
# RFC 6204 requires us to block forwarding until address acquisition is complete
|
||||
ipv6_block_forwarding() {
|
||||
ip6tables "-$2" forwarding_rule -o "$1" -j REJECT --reject-with no-route 2>/dev/null
|
||||
}
|
||||
|
||||
prepare_interface() {
|
||||
local device="$1"
|
||||
|
||||
ipv6_block_forwarding "$device" A
|
||||
|
||||
ipv6_conf "$device" accept_ra 2
|
||||
ipv6_conf "$device" forwarding 2
|
||||
}
|
||||
|
||||
cleanup_interface() {
|
||||
local device="$1"
|
||||
ipv6_conf "$device" accept_ra 1
|
||||
ipv6_conf "$device" forwarding 1
|
||||
ipv6_block_forwarding "$device" D
|
||||
}
|
||||
|
||||
setup_interface () {
|
||||
local device="$1"
|
||||
ipv6_block_forwarding "$device" D
|
||||
|
||||
proto_init_update "*" 1
|
||||
|
||||
for dns in $RDNSS; do
|
||||
proto_add_dns_server "$dns"
|
||||
done
|
||||
|
||||
for domain in $DOMAINS; do
|
||||
proto_add_dns_search "$domain"
|
||||
done
|
||||
|
||||
for prefix in $PREFIXES; do
|
||||
proto_add_ipv6_prefix "$prefix"
|
||||
done
|
||||
|
||||
proto_send_update "$INTERFACE"
|
||||
|
||||
# TODO: $SNTP_IP $SIP_IP $SNTP_FQDN $SIP_DOMAIN
|
||||
}
|
||||
|
||||
teardown_interface() {
|
||||
proto_init_update "*" 0
|
||||
proto_send_update "$INTERFACE"
|
||||
}
|
||||
|
||||
case "$2" in
|
||||
started)
|
||||
prepare_interface "$1"
|
||||
;;
|
||||
stopped)
|
||||
cleanup_interface "$1"
|
||||
;;
|
||||
informed|bound|updated|rebound)
|
||||
setup_interface "$1"
|
||||
;;
|
||||
unbound|timeout)
|
||||
teardown_interface "$1"
|
||||
;;
|
||||
esac
|
||||
|
||||
# user rules
|
||||
[ -f /etc/odhcp6c.user ] && . /etc/odhcp6c.user
|
||||
|
||||
exit 0
|
48
package/network/ipv6/odhcp6c/files/dhcpv6.sh
Executable file
48
package/network/ipv6/odhcp6c/files/dhcpv6.sh
Executable file
@ -0,0 +1,48 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
. ../netifd-proto.sh
|
||||
init_proto "$@"
|
||||
|
||||
proto_dhcpv6_init_config() {
|
||||
proto_config_add_string "reqaddress"
|
||||
proto_config_add_string "reqprefix"
|
||||
proto_config_add_string "clientid"
|
||||
proto_config_add_string "reqopts"
|
||||
}
|
||||
|
||||
proto_dhcpv6_setup() {
|
||||
local config="$1"
|
||||
local iface="$2"
|
||||
|
||||
local reqaddress reqprefix clientid reqopts
|
||||
json_get_vars reqaddress reqprefix clientid reqopts
|
||||
|
||||
|
||||
# Configure
|
||||
local opts=""
|
||||
[ -n "$reqaddress" ] && append opts "-N$reqaddress"
|
||||
|
||||
[ -z "$reqprefix" -o "$reqprefix" = "auto" ] && reqprefix=0
|
||||
[ "$reqprefix" != "no" ] && append opts "-P$reqprefix"
|
||||
|
||||
[ -n "$clientid" ] && append opts "-c$clientid"
|
||||
|
||||
for opt in $reqopts; do
|
||||
append opts "-r$opt"
|
||||
done
|
||||
|
||||
|
||||
proto_export "INTERFACE=$config"
|
||||
proto_run_command "$config" odhcp6c \
|
||||
-s /lib/netifd/dhcpv6.script \
|
||||
$opts $iface
|
||||
}
|
||||
|
||||
proto_dhcpv6_teardown() {
|
||||
local interface="$1"
|
||||
proto_kill_command "$interface"
|
||||
}
|
||||
|
||||
add_protocol dhcpv6
|
||||
|
Loading…
Reference in New Issue
Block a user