#---------------------------------------------------------------------------- # /etc/rc.d/rc305.ipv6-eth - ipv6 configuration ethernet cards __FLI4LVER__ # # # Creation: 23.02.2005 ow # Last Update: $Id$ #---------------------------------------------------------------------------- setlocalbit () { [ $1 -eq 0 -o $1 -eq 2 ] && result=2 [ $1 -eq 1 -o $1 -eq 3 ] && result=3 [ $1 -eq 4 -o $1 -eq 6 ] && result=6 [ $1 -eq 5 -o $1 -eq 7 ] && result=7 [ $1 -eq 8 -o $1 = "a" -o $1 = "A" ] && result="a" [ $1 -eq 9 -o $1 = "b" -o $1 = "B" ] && result="b" [ $1 = "c" -o $1 = "C" -o $1 = "e" -o $1 = "E" ] && result="e" [ $1 = "d" -o $1 = "D" -o $1 = "f" -o $1 = "F" ] && result="f" } ipv6_pops_file=/var/run/ipv6.pops if [ "$OPT_IPV6" = "yes" ] then begin_script IPV6 "configuring IPv6..." # ----------------------------- # log_info "loading IPv6 module..." # ----------------------------- # do_modprobe ipv6 # -----------------------------------------------------# log_info "binding IPv6 subnets to network interfaces..." # ---------------------------------------------------- # ( echo "option dhcp6.domain-search \"$DOMAIN_NAME\";" echo "option dhcp6.preference 255;" echo "option dhcp6.rapid-commit;" echo "dhcpv6-lease-file-name \"/tmp/dhcpd6.leases\";" ) > /etc/dhcpd6.conf for idx in `seq 1 $IPV6_NET_N` do eval dev='$IPV6_NET_'$idx'_DEV' eval net='$IPV6_NET_'$idx'' eval adv='$IPV6_NET_'$idx'_ADVERTISE' eval adv_dns='$IPV6_NET_'$idx'_ADVERTISE_DNS' eval dhcp='$IPV6_NET_'$idx'_DHCP' addr=`echo -n $net | cut -d '/' -f 1` prefix="`prefixcalc6 \`expandv6.sh $net\``" if [ "$dhcp" = "yes" ] then ( echo "subnet6 $prefix {" if [ "$OPT_DNS" = "yes" -a "$DNS_SUPPORT_IPV6" = "yes" ] then echo " option dhcp6.name-servers $addr;" fi echo "}" ) >> /etc/dhcpd6.conf echo -n "$dev " >> /var/run/dhcpd6.if fi if [ "$OPT_DNS" = "yes" -a "$DNS_SUPPORT_IPV6" = "yes" -a "$DNS_LISTENIP_N" != "0" ] then if [ "$dhcp" = "yes" -o "$adv_dns" = "yes" ] then mkdir -p /etc/dnsmasq.d echo "listen-address=$addr" >> /etc/dnsmasq.d/dns_ipv6.conf fi fi ip -6 addr add $net dev $dev ip link set $dev up if [ "$adv" = "yes" -a "`echo -n $devs|grep $dev`" = "" ] then if [ "$adv_dns" = "yes" ] then dnsservers="$addr" fi prefixes="$prefix" dhcp_dev="$dhcp" for idx1 in `seq \`expr $idx + 1\` $IPV6_NET_N` do eval dev1='$IPV6_NET_'$idx1'_DEV' eval net1='$IPV6_NET_'$idx1'' eval adv1='$IPV6_NET_'$idx1'_ADVERTISE' eval adv_dns1='$IPV6_NET_'$idx1'_ADVERTISE_DNS' eval dhcp1='$IPV6_NET_'$idx'_DHCP' if [ "$dev1" = "$dev" -a "$adv1" = "yes" ] then prefixes="$prefixes `prefixcalc6 \`expandv6.sh $net1\``" fi if [ "$dev1" = "$dev" -a "$adv_dns1" = "yes" ] then dnsservers="$dnsservers `echo -n $net1 | cut -d '/' -f 1`" fi if [ "$dhcp1" = "yes" ] then dhcp_dev="yes" fi done devs="$devs $dev" ( echo "interface $dev {" echo " IgnoreIfMissing on;" echo " AdvSendAdvert on;" if [ "$dhcp_dev" = "yes" ] then echo " AdvOtherConfigFlag on;" fi for i in $prefixes do echo " prefix $i {" echo " };" done if [ "$adv_dns" = "yes" ] then echo " RDNSS $dnsservers {" echo " };" fi echo "};" ) >> /etc/radvd.conf fi done # -------------------------------------- # log_info "performing IPv6 tunnel setup..." # -------------------------------------- # def_gateway="" for idx in `seq 1 $IPV6_ROUTE_N` do eval route='$IPV6_ROUTE_'$idx'' set $route gw_net="`expandv6.sh \"$1\"`" if [ "$gw_net" = "0:0:0:0:0:0:0:0/0" ] then def_gateway="$2" fi done mkdir -p /var/run/ipv6.tunnels for idx in `seq 1 $IPV6_TUNNEL_N` do eval localv4='$IPV6_TUNNEL_'$idx'_LOCALV4' eval remotev4='$IPV6_TUNNEL_'$idx'_REMOTEV4' eval localv6='$IPV6_TUNNEL_'$idx'_LOCALV6' eval dev='$IPV6_TUNNEL_'$idx'_DEV' eval mtu='$IPV6_TUNNEL_'$idx'_MTU' eval type='$IPV6_TUNNEL_'$idx'_TYPE' # assign defaults if necessary : ${dev:=6in4tun${idx}} : ${mtu:=1280} # SixXS recommendation : ${type:=sixxs-heartbeat} # for compatibility if [ "$localv4" = "dynamic" ] then localv4=127.0.0.1 echo "$dev" >>/var/run/ipv6.dyntunnelif fi echo "$remotev4" >>$ipv6_pops_file ip tunnel add $dev mode sit local $localv4 remote $remotev4 ip link set $dev up ip link set mtu $mtu dev $dev ip tunnel change $dev ttl 64 ip -6 addr add $localv6 dev $dev case $type in sixxs-heartbeat) eval username='$IPV6_TUNNEL_'$idx'_SIXXS_USERNAME' eval password='$IPV6_TUNNEL_'$idx'_SIXXS_PASSWORD' eval id='$IPV6_TUNNEL_'$idx'_SIXXS_ID' ( echo "localv6=$localv6" echo "remotev4=$remotev4" echo "username=$username" echo "password=$password" echo "id=$id" echo "ticserver=tic.sixxs.net" echo "ticport=3874" echo "heartbeatport=3740" ) > /var/run/ipv6.tunnels/$idx.conf if [ -n "$def_gateway" -a "$PF6_INPUT_ACCEPT_DEF" = 'yes' ] then # allow ping packets from the tunnel peer cat <<- EOF > /etc/rc.d/fwrules.ipv6.post.sixxs add_rule6 filter in-icmp "prot:icmpv6:echo-request [$def_gateway] ACCEPT" PF6_INPUT_ACCEPT_DEF EOF fi echo "pingsixxstunnel.sh $idx" >> /etc/ppp/ip-up100.heartbeat keepalivesixxstunnel.sh $idx & ;; static) # nothing to do ;; *) # unknown type log_warn "Unknown IPv6 tunnel type '$type' -- assuming static tunnel!" ;; esac done # ------------------------------ # log_info "creating IPv6 routes..." # ------------------------------ # for idx in `seq 1 $IPV6_ROUTE_N` do eval route='$IPV6_ROUTE_'$idx'' set $route ip -6 route add $1 via $2 $3 $4 done # ----------------------------------------------------- # log_info "adding IPv6 addresses of local hosts to DNS..." # ----------------------------------------------------- # if [ "$OPT_DNS" = "yes" -a "$DNS_SUPPORT_IPV6" = "yes" ] then iptmpl="" if [ $IPV6_NET_N -gt 0 ] then net=$IPV6_NET_1 prefixlen=`echo -n $net | cut -d '/' -f 2` if [ $prefixlen -eq 64 ] then iptmpl="`prefixcalc6 \`expandv6.sh $net\` | cut -d '/' -f 1`" fi fi if [ "$iptmpl" != "" ] then for idx in `seq 1 $HOSTS_N` do eval ip6='$HOST_'$idx'_IP6' eval type='$HOST_'$idx'_DHCPTYP' if [ "$ip6" = "" -a "$type" = "mac" ] then eval ip4='$HOST_'$idx'_IP4' if translate_ip_net $ip4 HOST_${idx}_IP4 then ip4=$res fi eval mac='$HOST_'$idx'_MAC' # compute EUI-64 from MAC set `echo -n $mac | cut -d ':' -f 1 | sed -e 's/^\(.\)\(.\).*$/\1 \2/'` first=$1 setlocalbit $2 eui="$first$result`echo -n $mac | cut -d ':' -f 2,3`ff:fe`echo -n $mac | cut -d ':' -f 4,5``echo -n $mac | cut -d ':' -f 6`" addr="`echo -n $iptmpl | sed -e \"s/0:0:0:0$/$eui/\"`" sed -i "s/^::ffff:$ip4 /$addr /" /etc/hosts /etc/hosts.d/hosts.dns 2>/dev/null fi done fi fi end_script fi