#!/bin/sh #---------------------------------------------------------------------------- # /etc/rc.d/rc305.ipv6-eth - ipv6 configuration ethernet cards __FLI4LVER__ # # # Creation: 23.02.2005 ow # Last Update: $Id$ #---------------------------------------------------------------------------- # include IPv6 helper functions (especially translate_ip6_net) . /etc/rc.d/base-helper.ipv6 add_sit_tunnel() { # try to determine tunnel configuration if [ ! -x /etc/rc.d/ipv6-tunnel-provider/${type}.sh ] then log_error " IPV6_TUNNEL_$idx: setup of $type tunnel failed: provider script missing" return 1 fi set | grep -e "^IPV6_TUNNEL_${idx}_" > /tmp/ipv6.config set | grep -e "^PF6_" >> /tmp/ipv6.config if ! /etc/rc.d/ipv6-tunnel-provider/${type}.sh setup $idx "$config" /tmp/ipv6.config then log_error " IPV6_TUNNEL_$idx: setup of $type tunnel failed: provider script returned error $?" return 1 else . "$config" if [ ! -n "$remotev4" ]; then log_error " IPV6_TUNNEL_$idx: setup of $type tunnel failed: remotev4 missing" return 1 elif [ ! -n "$localv6" ]; then log_error " IPV6_TUNNEL_$idx: setup of $type tunnel failed: localv6 missing" return 1 elif [ ! -n "$remotev6" ]; then log_error " IPV6_TUNNEL_$idx: setup of $type tunnel failed: remotev6 missing" return 1 fi fi if [ "$localv4" = "dynamic" ] then localv4=127.0.0.1 echo $idx >> /var/run/ipv6.dyntunnels fi echo "$remotev4" >> $ipv6_pops_file ip tunnel add name $dev mode sit local $localv4 remote $remotev4 echo 0 > /proc/sys/net/ipv6/conf/$dev/disable_ipv6 ip link set dev $dev up ip link set dev $dev mtu $mtu ip tunnel change name $dev ttl 64 ip -6 addr add $localv6 dev $dev log_info " IPV6_TUNNEL_$idx: $type tunnel configured on $dev: prefix=$prefix localv4=$localv4 remotev4=$remotev4 localv6=$localv6 remotev6=$remotev6 mtu=$mtu" if ! /etc/rc.d/ipv6-tunnel-provider/${type}.sh post-setup $idx "$config" /tmp/ipv6.config then log_warn " IPV6_TUNNEL_$idx: post-setup of $type tunnel failed: provider script returned error $?" fi return 0 } write_etc_hosts_header() { # ------------------------------------------# log_info " setting up /etc/hosts (IPv6) ..." # ------------------------------------------# { cat <> /etc/hosts } create_tunnels() { # ----------------------------------# log_info " creating IPv6 tunnels..." # ----------------------------------# tunnel_config_dir="/var/run/ipv6.tunnels" ipv6_pops_file="/var/run/ipv6.pops" ipv6_tunnel_dev_file="/var/run/ipv6.tunnel-devs" mkdir -p "$tunnel_config_dir" > "$ipv6_pops_file" > "$ipv6_tunnel_dev_file" ppp='' for idx in $(seq 1 $IPV6_TUNNEL_N) do eval localv4='$IPV6_TUNNEL_'$idx'_LOCALV4' eval dev='$IPV6_TUNNEL_'$idx'_DEV' eval mtu='$IPV6_TUNNEL_'$idx'_MTU' eval type='$IPV6_TUNNEL_'$idx'_TYPE' eval default='$IPV6_TUNNEL_'$idx'_DEFAULT' # assign defaults if necessary : ${default:='no'} case $type in ppp) : ${dev:=ppp0} ;; *) : ${dev:=v6tun${idx}} : ${mtu:=1280} # SixXS recommendation ;; esac config="$tunnel_config_dir/$idx.conf" echo "IPV6_TUNNEL_${idx}_DEV='$dev'" >> "$ipv6_tunnel_dev_file" { echo "index=$idx" echo "tunneldev=$dev" echo "type=$type" echo "default=$default" } > "$config" case $type in ppp) if [ -n "$ppp" ] then log_error " IPV6_TUNNEL_$idx: more than one ppp tunnel is not supported" else ppp=$dev log_info " IPV6_TUNNEL_$idx: $type tunnel configured on $dev" fi ;; *) add_sit_tunnel [ "$default" = "yes" ] && ipv6_up_events=yes ;; esac grep -q "^prefix=" "$config" || echo "prefix=" >> "$config" done rm -f /tmp/ipv6.config } setup_nets() { # ---------------------------------------# log_info " setting up IPv6 networks..." # ---------------------------------------# # needed for dynamically created interfaces, e.g. ppp0, which need at least # IPv6 link-local addresses in order to make IPv6 over PPP work echo 0 > /proc/sys/net/ipv6/conf/default/disable_ipv6 # loopback device needs an IPv6 address, too echo 0 > /proc/sys/net/ipv6/conf/lo/disable_ipv6 net_config_dir="/var/run/ipv6.nets" mkdir -p "$net_config_dir" dhcpdevices=/var/run/dhcpd6.if > $dhcpdevices for idx in $(seq 1 $IPV6_NET_N) do eval net='$IPV6_NET_'$idx eval dev='$IPV6_NET_'$idx'_DEV' eval tunnel='$IPV6_NET_'$idx'_TUNNEL' eval adv='$IPV6_NET_'$idx'_ADVERTISE' eval advvalidlft='$IPV6_NET_'$idx'_ADVERTISE_VALID_LIFETIME' eval advpreflft='$IPV6_NET_'$idx'_ADVERTISE_PREF_LIFETIME' eval adv_dns='$IPV6_NET_'$idx'_ADVERTISE_DNS' eval dhcp='$IPV6_NET_'$idx'_DHCP' eval canonical='$IPV6_NET_'$idx'_NAME' if ! translate_ip_dev $dev realdev then log_error " IPV6_NET_$idx: not configured as device $dev could not be mapped" continue else dev=$realdev fi echo 0 > /proc/sys/net/ipv6/conf/$dev/disable_ipv6 # assign defaults if necessary : ${adv:='no'} : ${adv_dns='no'} : ${dhcp='no'} net=$(expandv6.sh $net) netaddr=$(echo $net | cut -d '/' -f 1) netlen=$(echo $net | cut -d '/' -f 2) if [ -z "$tunnel" ] then # statically configured networks should have 'forever' lifetimes : ${advvalidlft:='forever'} : ${advpreflft:='forever'} fi netfile="$net_config_dir/$idx.conf" { echo "netaddr=$netaddr" echo "netlen=$netlen" echo "dev=$dev" echo "tunnel=$tunnel" echo "adv=$adv" echo "advvalidlft=$advvalidlft" echo "advpreflft=$advpreflft" echo "adv_dns=$adv_dns" echo "dhcp=$dhcp" echo "ifnet=" echo "ifnetvalidlft=" echo "ifnetpreflft=" } > "$netfile" if [ ! -n "$tunnel" ] then ipv6-interface-up.sh "$netfile" "$net" fi ip link set dev $dev up done } setup_dhcpc6() { # -------------------------------------# log_info " setting up DHCPv6 client..." # -------------------------------------# mkdir -p /var/lib/dibbler mkdir -p /etc/dibbler { echo "script \"/usr/local/bin/dhcpv6-notify.sh\"" echo "iface $ppp {" echo " pd" echo "}" } > /etc/dibbler/client.conf ipv6_up_events='yes' } start_tunnels() { # --------------------------------------------------------- # log_info " setting up statically configured IPv6 tunnels..." # --------------------------------------------------------- # for idx in $(seq 1 $IPV6_TUNNEL_N) do config="$tunnel_config_dir/$idx.conf" unset prefix . "$config" if [ -n "$prefix" ] then sed -i "s,^prefix=.*,prefix=," "$config" ipv6-configure-tunnel.sh "$config" "$prefix" fi done } write_etc_hosts_router_entries() { # ---------------------------------------# log_info " filling /etc/hosts (IPv6) ..." # ---------------------------------------# # host-entry for the router aliases= [ 0$HOSTNAME_ALIAS_N -eq 0 ] || for j in $(seq 1 $HOSTNAME_ALIAS_N) do eval alias='$HOSTNAME_ALIAS_'$j aliases="$aliases $alias" done ipaddr= if [ -n "$HOSTNAME_IP6" ] then translate_ip6_net "$HOSTNAME_IP6" HOSTNAME_IP6 ipaddr else # look for first subnet with a configured prefix [ 0$IPV6_NET_N -eq 0 ] || for i in $(seq 1 $IPV6_NET_N) do eval tunnel='$'IPV6_NET_${i}_TUNNEL if [ -n "$tunnel" ] then tunnelfile="$tunnel_config_dir/$tunnel.conf" if [ -f "$tunnelfile" ] then unset prefix . "$tunnelfile" if [ -n "$prefix" ] then translate_ip6_net "IPV6_NET_${i}_IPADDR" "" ipaddr break fi else log_warn " IPV6_NET_${i}: tunnel IPV6_NET_${i}_TUNNEL='$tunnel' does not exist, ignoring" fi else eval net='$'IPV6_NET_${i} ipaddr=$(echo $net | sed 's/\/.*//') break fi done fi [ -n "$ipaddr" ] && echo "$ipaddr $HOSTNAME.$DOMAIN_NAME $HOSTNAME $aliases" >> /etc/hosts } create_routes() { if [ 0$IPV6_ROUTE_N -gt 0 ] then # -------------------------------- # log_info " creating IPv6 routes..." # -------------------------------- # for idx in $(seq 1 $IPV6_ROUTE_N) do eval route='$IPV6_ROUTE_'$idx set -- $route route=$1 shift log_info " IPv6: adding route $route via $*" ip -6 route add $route via $* done fi } if [ "$OPT_IPV6" = "yes" ] then begin_script IPV6 "configuring IPv6..." write_etc_hosts_header create_tunnels setup_nets [ -n "$ppp" ] && setup_dhcpc6 write_etc_hosts_router_entries start_tunnels create_routes end_script fi