From 89444ffae2b5bdb73aaedf56d09192a81b24545d Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Fri, 11 Jul 2008 21:31:04 +0000 Subject: [PATCH] [PATCH] IPv6 Router Advertisement Daemon 1.1 with UCI Support This patch updates radvd to version 1.1 and adds a uci'ed init.d script. Signed-off-by: "Alina Friedrichsen" SVN-Revision: 11772 --- ipv6/radvd/Makefile | 12 +- ipv6/radvd/files/radvd.conf | 22 -- ipv6/radvd/files/radvd.config | 21 ++ ipv6/radvd/files/radvd.init | 380 ++++++++++++++++++++++- ipv6/radvd/patches/001-bridge_name.patch | 12 - 5 files changed, 399 insertions(+), 48 deletions(-) delete mode 100644 ipv6/radvd/files/radvd.conf create mode 100644 ipv6/radvd/files/radvd.config delete mode 100644 ipv6/radvd/patches/001-bridge_name.patch diff --git a/ipv6/radvd/Makefile b/ipv6/radvd/Makefile index 95a0a46fa6..5b66f3c1eb 100644 --- a/ipv6/radvd/Makefile +++ b/ipv6/radvd/Makefile @@ -9,14 +9,14 @@ include $(TOPDIR)/rules.mk PKG_NAME:=radvd -PKG_VERSION:=1.0 +PKG_VERSION:=1.1 PKG_RELEASE:=1 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=http://v6web.litech.org/radvd/dist \ http://download.sourcemage.org/mirror -PKG_MD5SUM:=8bce4a21757cf069f5a69e2f9bee9e5b +PKG_MD5SUM:=9ee449e4b89171432cb9e9100e0b5648 PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install @@ -33,10 +33,6 @@ define Package/radvd/description IPv6 Routing Advertisement Daemon. endef -define Package/radvd/conffiles -/etc/radvd.conf -endef - define Build/Configure (cd $(PKG_BUILD_DIR); rm -f config.cache; \ $(TARGET_CONFIGURE_OPTS) \ @@ -78,8 +74,8 @@ define Build/Compile endef define Package/radvd/install - $(INSTALL_DIR) $(1)/etc - $(INSTALL_DATA) ./files/radvd.conf $(1)/etc/radvd.conf + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_DATA) ./files/radvd.config $(1)/etc/config/radvd $(INSTALL_DIR) $(1)/etc/init.d $(INSTALL_BIN) ./files/radvd.init $(1)/etc/init.d/radvd $(INSTALL_DIR) $(1)/usr/sbin diff --git a/ipv6/radvd/files/radvd.conf b/ipv6/radvd/files/radvd.conf deleted file mode 100644 index 06d8357041..0000000000 --- a/ipv6/radvd/files/radvd.conf +++ /dev/null @@ -1,22 +0,0 @@ -# For more examples, see the radvd documentation. - -interface br0 -{ - AdvSendAdvert off; - -# -# Disable Mobile IPv6 support -# - AdvHomeAgentFlag off; - -# -# example of a standard prefix -# - prefix fec0:0:0:1::/64 - { - AdvOnLink on; - AdvAutonomous on; - AdvRouterAddr off; - }; - -}; diff --git a/ipv6/radvd/files/radvd.config b/ipv6/radvd/files/radvd.config new file mode 100644 index 0000000000..437e3b743f --- /dev/null +++ b/ipv6/radvd/files/radvd.config @@ -0,0 +1,21 @@ +config interface + option interface 'lan' + option AdvSendAdvert 1 + option AdvManagedFlag 0 + option AdvOtherConfigFlag 0 + option ignore 1 + +config prefix + option interface 'lan' + # If not specified, a non-link-local prefix of the interface is used + option prefix '' + option AdvOnLink 1 + option AdvAutonomous 1 + option AdvRouterAddr 0 + option ignore 1 + +config rdnss + option interface 'lan' + # If not specified, the link-local address of the interface is used + option addr '' + option ignore 1 diff --git a/ipv6/radvd/files/radvd.init b/ipv6/radvd/files/radvd.init index 29d8c06d65..ff867bf2b2 100644 --- a/ipv6/radvd/files/radvd.init +++ b/ipv6/radvd/files/radvd.init @@ -1,15 +1,383 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2006 OpenWrt.org +# Copyright (C) 2008 Alina Friedrichsen START=50 +RADVD_INTERFACE_STRING_OPTIONS='MaxRtrAdvInterval MinRtrAdvInterval MinDelayBetweenRAs AdvLinkMTU AdvReachableTime AdvRetransTimer AdvCurHopLimit AdvDefaultLifetime AdvDefaultPreference HomeAgentLifetime HomeAgentPreference' +RADVD_INTERFACE_BOOLEAN_OPTIONS='IgnoreIfMissing AdvSendAdvert UnicastOnly AdvManagedFlag AdvOtherConfigFlag AdvSourceLLAddress AdvHomeAgentFlag AdvHomeAgentInfo AdvMobRtrSupportFlag AdvIntervalOpt' + +RADVD_PREFIX_STRING_OPTIONS='AdvValidLifetime AdvPreferredLifetime' +RADVD_PREFIX_BOOLEAN_OPTIONS='AdvOnLink AdvAutonomous AdvRouterAddr' + +RADVD_ROUTE_STRING_OPTIONS='AdvRouteLifetime AdvRoutePreference' +RADVD_ROUTE_BOOLEAN_OPTIONS='' + +RADVD_RDNSS_STRING_OPTIONS='AdvRDNSSPreference AdvRDNSSLifetime' +RADVD_RDNSS_BOOLEAN_OPTIONS='AdvRDNSSOpen' + +validate_varname() { + local varname=$1 + [ -z "$varname" -o "$varname" != "${varname%%[!A-Za-z0-9_]*}" ] && return 1 + return 0 +} + +validate_ifname() { + local ifname=$1 + [ -z "$ifname" -o "$ifname" != "${ifname%%[!A-Za-z0-9.:_-]*}" ] && return 1 + return 0 +} + +validate_ip6addr() { + local ip6addr=$1 + [ -z "$ip6addr" -o "$ip6addr" != "${ip6addr%%[!A-Fa-f0-9.:]*}" ] && return 1 + return 0 +} + +validate_ip6prefix() { + local ip6prefix=$1 + [ -z "$ip6prefix" -o "$ip6prefix" != "${ip6prefix%%[!A-Fa-f0-9./:]*}" ] && return 1 + return 0 +} + +validate_radvd_string() { + local radvd_string=$1 + [ -z "$radvd_string" -o "$radvd_string" != "${radvd_string%%[!a-z0-9.:_-]*}" ] && return 1 + return 0 +} + +get_ifname() { + local interface=$1 + validate_varname "$interface" || return 1 + local cfgt + local ifname + + scan_interfaces + config_get cfgt "$interface" TYPE + [ "$cfgt" != "interface" ] && return 1 + config_get ifname "$interface" ifname + validate_ifname "$ifname" || return 1 + printf '%s\n' "$ifname" + + return 0 +} + +get_ip6addr() { + local ifname=$1 + local scope=$2 + local iproute2_scope + local ifconfig_scope + local ip6addr + + case "$scope" in + host) iproute2_scope=host ifconfig_scope=Host;; + link) iproute2_scope=link ifconfig_scope=Link;; + site) iproute2_scope=site ifconfig_scope=Site;; + global) iproute2_scope=global ifconfig_scope=Global;; + "") get_ip6addr "$ifname" global || get_ip6addr "$ifname" site; return;; + *) return 1;; + esac + + ip6addr=$(LANG=C ip -f inet6 -- addr show dev "$ifname" 2> /dev/null | sed -n -e 's/^ *inet6 \([A-Fa-f0-9.:]*[/][0-9]*\) scope '"$iproute2_scope"' $/\1/p' | head -n 1) + if [ -z "$ip6addr" ]; then + ip6addr=$(LANG=C ifconfig "$ifname" 2> /dev/null | sed -n -e 's/^ *inet6 addr: \([A-Fa-f0-9.:]*[/][0-9]*\) Scope:'"$ifconfig_scope"'$/\1/p' | tail -n 1) + [ -z "$ip6addr" ] && return 1 + fi + + printf '%s\n' "$ip6addr" + + return 0 +} + +radvd_find_config_file() { + local cfg=$1 + validate_varname "$cfg" || return 0 + + config_get_bool ignore "$cfg" ignore 0 + [ "$ignore" -ne 0 ] && return 0 + config_get RADVD_CONFIG_FILE "$cfg" config_file + + return 0 +} + +radvd_add_interface() { + local cfg=$1 + validate_varname "$cfg" || return 0 + local ignore + local interfaces + local interface + local list_interface + local exist + + config_get ignore "$cfg" ignore + [ "$ignore" -ne 0 ] && return 0 + + config_get interfaces "$cfg" interface + for interface in $interfaces; do + validate_varname "$interface" || continue + exist=0 + for list_interface in $RADVD_INTERFACES; do + [ "$interface" = "$list_interface" ] && exist=1 + done + [ "$exist" -eq 0 ] && RADVD_INTERFACES="$RADVD_INTERFACES $interface" + done + + return 0 +} + +radvd_write_interface() { + local cfg=$1 + validate_varname "$cfg" || return 0 + local ignore + local interfaces + local interface + local name + local value + + config_get_bool ignore "$cfg" ignore 0 + [ "$ignore" -ne 0 ] && return 0 + + config_get interfaces "$cfg" interface + exist=0 + for interface in $interfaces; do + [ "$INTERFACE" = "$interface" ] && exist=1 + done + [ "$exist" -eq 0 ] && return 0 + + for name in $RADVD_INTERFACE_STRING_OPTIONS; do + config_get value "$cfg" "$name" + validate_radvd_string "$value" || continue + printf '\t%s %s;\n' "$name" "$value" + done + + for name in $RADVD_INTERFACE_BOOLEAN_OPTIONS; do + config_get value "$cfg" "$name" + [ -z "$value" ] && continue + config_get_bool value "$cfg" "$name" 0 + if [ "$value" -ne 0 ]; then + printf '\t%s on;\n' "$name" + else + printf '\t%s off;\n' "$name" + fi + done + + return 0 +} + +radvd_write_prefix() { + local cfg=$1 + validate_varname "$cfg" || return 0 + local ignore + local interfaces + local interface + local prefixes + local prefix + local name + local value + local cfgt + + config_get_bool ignore "$cfg" ignore 0 + [ "$ignore" -ne 0 ] && return 0 + + config_get interfaces "$cfg" interface + exist=0 + for interface in $interfaces; do + [ "$INTERFACE" = "$interface" ] && exist=1 + done + [ "$exist" -eq 0 ] && return 0 + + config_get prefixes "$cfg" prefix + if [ -z "$prefixes" ]; then + prefixes=$(get_ip6addr "$IFNAME") || return 0 + fi + + for prefix in $prefixes; do + validate_ip6prefix "$prefix" || continue + printf '\n\tprefix %s\n\t{\n' "$prefix" + + for name in $RADVD_PREFIX_STRING_OPTIONS; do + config_get value "$cfg" "$name" + validate_radvd_string "$value" || continue + printf '\t\t%s %s;\n' "$name" "$value" + done + + for name in $RADVD_PREFIX_BOOLEAN_OPTIONS; do + config_get value "$cfg" "$name" + [ -z "$value" ] && continue + config_get_bool value "$cfg" "$name" 0 + if [ "$value" -ne 0 ]; then + printf '\t\t%s on;\n' "$name" + else + printf '\t\t%s off;\n' "$name" + fi + done + + config_get value "$cfg" Base6to4Interface + if [ -n "$value" ]; then + if ifname=$(get_ifname "$value"); then + printf '\t\t%s %s;\n' "Base6to4Interface" "$ifname" + fi + fi + + printf '\t};\n' + done + + return 0 +} + +radvd_write_route() { + local cfg=$1 + validate_varname "$cfg" || return 0 + local ignore + local interfaces + local interface + local prefixes + local prefix + local name + local value + + config_get_bool ignore "$cfg" ignore 0 + [ "$ignore" -ne 0 ] && return 0 + + config_get interfaces "$cfg" interface + exist=0 + for interface in $interfaces; do + [ "$INTERFACE" = "$interface" ] && exist=1 + done + [ "$exist" -eq 0 ] && return 0 + + config_get prefixes "$cfg" prefix + for prefix in $prefixes; do + validate_ip6prefix "$prefix" || continue + printf '\n\troute %s\n\t{\n' "$prefix" + + for name in $RADVD_ROUTE_STRING_OPTIONS; do + config_get value "$cfg" "$name" + validate_radvd_string "$value" || continue + printf '\t\t%s %s;\n' "$name" "$value" + done + + for name in $RADVD_ROUTE_BOOLEAN_OPTIONS; do + config_get value "$cfg" "$name" + [ -z "$value" ] && continue + config_get_bool value "$cfg" "$name" 0 + if [ "$value" -ne 0 ]; then + printf '\t\t%s on;\n' "$name" + else + printf '\t\t%s off;\n' "$name" + fi + done + + printf '\t};\n' + done + + return 0 +} + +radvd_write_rdnss() { + local cfg=$1 + validate_varname "$cfg" || return 0 + local ignore + local interfaces + local interface + local addrs + local addr + local addr_list + local name + local value + local i + + config_get_bool ignore "$cfg" ignore 0 + [ "$ignore" -ne 0 ] && return 0 + + config_get interfaces "$cfg" interface + exist=0 + for interface in $interfaces; do + [ "$INTERFACE" = "$interface" ] && exist=1 + done + [ "$exist" -eq 0 ] && return 0 + + config_get addrs "$cfg" addr + i=0 + for addr in $addrs; do + [ "$i" -ge 3 ] && break + validate_ip6addr "$addr" || continue + addr_list="$addr_list $addr" + i=$(($i+1)) + done + + if [ -z "$addr_list" ]; then + addr=$(get_ip6addr "$IFNAME" link) || return 0 + addr_list=" ${addr%%[/]*}" + fi + + printf '\n\tRDNSS%s\n\t{\n' "$addr_list" + + for name in $RADVD_RDNSS_STRING_OPTIONS; do + config_get value "$cfg" "$name" + validate_radvd_string "$value" || continue + printf '\t\t%s %s;\n' "$name" "$value" + done + + for name in $RADVD_RDNSS_BOOLEAN_OPTIONS; do + config_get value "$cfg" "$name" + [ -z "$value" ] && continue + config_get_bool value "$cfg" "$name" 0 + if [ "$value" -ne 0 ]; then + printf '\t\t%s on;\n' "$name" + else + printf '\t\t%s off;\n' "$name" + fi + done + + printf '\t};\n' + + return 0 +} + +radvd_write_config() { + include /lib/network + + RADVD_INTERFACES= + config_foreach radvd_add_interface interface + config_foreach radvd_add_interface prefix + config_foreach radvd_add_interface route + config_foreach radvd_add_interface RDNSS + + for INTERFACE in $RADVD_INTERFACES; do + IFNAME=$(get_ifname "$INTERFACE") || continue + printf 'interface %s\n{\n' "$IFNAME" + config_foreach radvd_write_interface interface + config_foreach radvd_write_prefix prefix + config_foreach radvd_write_route route + config_foreach radvd_write_rdnss rdnss + printf '};\n\n' + done + + return 0 +} + start() { - echo 1 > /proc/sys/net/ipv6/conf/all/forwarding - mkdir -p /var/log - mkdir -p /var/run - /usr/sbin/radvd + config_load radvd + + RADVD_CONFIG_FILE= + config_foreach radvd_find_config_file radvd + + if [ -z "$RADVD_CONFIG_FILE" ]; then + mkdir -p -- /var/etc/ + radvd_write_config > /var/etc/radvd.conf + if [ -s "/var/etc/radvd.conf" ]; then + RADVD_CONFIG_FILE=/var/etc/radvd.conf + fi + fi + + [ -z "$RADVD_CONFIG_FILE" ] && return 1 + + if grep '^net.ipv6.conf.all.forwarding=1$' /etc/sysctl.conf > /dev/null 2> /dev/null; then + sysctl -w net.ipv6.conf.all.forwarding=1 > /dev/null 2> /dev/null + fi + + radvd -C "$RADVD_CONFIG_FILE" -m stderr_syslog -p /var/run/radvd.pid } stop() { killall radvd - echo 0 > /proc/sys/net/ipv6/conf/all/forwarding } diff --git a/ipv6/radvd/patches/001-bridge_name.patch b/ipv6/radvd/patches/001-bridge_name.patch deleted file mode 100644 index 0a3a2f71bf..0000000000 --- a/ipv6/radvd/patches/001-bridge_name.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff -urN radvd-1.0/scanner.l radvd-1.0.new/scanner.l ---- radvd-1.0/scanner.l 2006-08-24 13:39:00.000000000 +0200 -+++ radvd-1.0.new/scanner.l 2006-12-09 17:40:06.000000000 +0100 -@@ -34,7 +34,7 @@ - addr3 ({hexdigit}{1,4}":"){7}{hexdigit}{1,4} - addr ({addr1}|{addr2}|{addr3}|"::") - whitespace ([ \t])+ --string [a-z]([a-z]|{digit}|_)*([:.]{digit}+)? -+string [a-z]([a-z]|{digit}|_|\-)*([:.]{digit}+)? - %% - - #.*$ {/* ignore comments */} -- 2.30.2