diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 17:14:36 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 17:14:36 +0300 |
commit | 2959e1ede0ebc6fdffd7b8660f43c2ce14c9696f (patch) | |
tree | f6343b1ce11a8c87251dd27cf3d3e26b50693fa7 /rc/bin/ipv6on | |
parent | e463eb40363ff4c68b1d903f4e0cdd0ac1c5977f (diff) |
Import sources from 2011-03-30 iso image - rc
Diffstat (limited to 'rc/bin/ipv6on')
-rwxr-xr-x | rc/bin/ipv6on | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/rc/bin/ipv6on b/rc/bin/ipv6on new file mode 100755 index 000000000..996e8478d --- /dev/null +++ b/rc/bin/ipv6on @@ -0,0 +1,94 @@ +#!/bin/rc +# ipv6on [netdir ndbfile [gwv4]] - configure an interface for ipv6, +# once ipv4 is configured. +if (! ~ $#* 0 2 3) { + echo usage: $0 '[netdir ndbfile [gw-v4-name]]' >[1=2] + exit usage +} +rfork e +if (~ $#* 0) { + netdir=/net + ndbf=/lib/ndb/local + gw=`{ndb/ipquery sys $sysname ipgw | sed 's/ipgw=//'} +} +if not { + netdir=$1 + ndbf=$2 + if (~ $#* 2) + # gw=() + gw=`{ndb/ipquery sys $sysname ipgw | sed 's/ipgw=//'} + if not + gw=$3 +} +if (~ $netdir /net) { + xsfx=() + xdir=() +} +if not { + xsfx=(-x `{echo $netdir | sed 's;^/net;;'}) + xdir=(-x $netdir) +} + +fn nonnil { # variable + if (~ $#$1 0) { + echo no ip for $1 + exit no-ip + } + if (! ~ $#$1 1) { + echo multiple ips for $1 + exit multiple-ips + } +} + +# +# configure v6 for link-local addresses (fe80::) & multicast (ff02::) +# +if (! ip/ipconfig -6 $xdir ether $netdir/ether?) + exit 'ipconfig -6 failed' +ip/ipconfig $xdir ether $netdir/ether? ra6 recvra 1 + +mev6=`{ndb/query -f $ndbf sys $sysname ipv6} +if (~ $#sysname 0 || ~ $sysname '') + mev6=`{ndb/query -f $ndbf sys $sysname ip | grep :} +# mev4=`{ndb/query -f $ndbf sys $sysname ip | grep -v :} + +# for testing +mylnk=`{ip/linklocal `{cat $netdir/ether?/addr}} +nonnil mylnk + +if (~ $#gw 1) { + if (~ $gw [0-9]*.[0-9]*.[0-9]*.[0-9]*) + gwv4 = $gw + if (~ $#gwv4 0 || ~ $gwv4 '') # assume namev6 and name + gwv4=`{ndb/query -f $ndbf sys $gw ip} + gwv6=`{ndb/query -f $ndbf sys $gw ipv6} + + if (! ~ $#gwv4 0) { + # echo ping gw $gwv4... + # load arp cache with gw mac + ip/ping -qn 3 $netdir/icmp!$gwv4 >/dev/null >[2=1] & + sleep 1 # wait for ping + + gweth=`{grep '* '^$gwv4^' ' $netdir/arp | awk '{print $4}' } + nonnil gweth + gwlnk=`{ip/linklocal $gweth} + nonnil gwlnk + } +} +nonnil mev6 +# +# configure my global v6 addresses +# +ip/ipconfig $xdir ether $netdir/ether? add $mev6 /64 +ip/ipconfig $xdir loopback /dev/null add $mev6 /128 + +if (~ $#gw 1) { + if (~ $#gwv6 0 || ~ $gwv6 '') + gwv6=`{ip/linklocal $gweth} + nonnil gwv6 + # + # add default v6 route to v6 addr of v4 gw + # + echo add :: /0 $gwv6 >$netdir/iproute # need not be link-local +} +exit '' |