Subversion Repositories planix.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#!/bin/rc
2
# ipv6on [netdir ndbfile] - configure an interface for ipv6.
3
#	use ipv6 address from ndb if present,
4
#	else do stateless address autoconfiguration (SLAAC).
5
if (! ~ $#* 0 2 3) {
6
	echo usage: $0 '[netdir ndbfile [obs-gw-v4-name]]' >[1=2]
7
	exit usage
8
}
9
rfork e
10
fn ipq {			# attr val rattr
11
	ndb/ipquery $* | sed 's/^[a-z0-9]+=//'
12
}
13
 
14
if (~ $#* 0) {
15
	netdir=/net
16
	ndbf=/lib/ndb/local
17
}
18
if not {
19
	netdir=$1
20
	ndbf=$2
21
}
22
if (~ $netdir /net) {
23
	xsfx=()
24
	xdir=()
25
}
26
if not {
27
	xsfx=(-x `{echo $netdir | sed 's;^/net;;'})
28
	xdir=(-x $netdir)
29
}
30
 
31
fn nonnil {		# variable
32
	if (~ $#$1 0) {
33
		echo ipv6on: no ip for $1 >[1=2]
34
		exit no-ip
35
	}
36
	if (! ~ $#$1 1) {
37
		echo ipv6on: multiple ips for $1 >[1=2]
38
		exit multiple-ips
39
	}
40
}
41
 
42
#
43
# configure v6 for link-local addresses (fe80::) & multicast (ff02::).
44
# accept router advertisements, which will contain a default route.
45
#
46
if (! ip/ipconfig -6 $xdir ether $netdir/ether?)
47
	exit 'ipconfig -6 failed'
48
ip/ipconfig $xdir ether $netdir/ether? ra6 recvra 1
49
 
50
# lookup any v6 address for me in ndb, else use slaac
51
myeth=`{cat $netdir/ether?/addr}
52
mev6=`{ndb/query -f $ndbf ether $myeth ipv6}
53
if (~ $#mev6 0 || ~ $mev6 '')
54
	mev6=`{ndb/query -f $ndbf sys $sysname ipv6}
55
if (~ $#mev6 0 || ~ $mev6 '') {
56
	# slaac: could perhaps get prefix from above RA
57
	ipnet=`{ipq ether $myeth ipnet}
58
	if (~ $#ipnet 0 || ~ $ipnet '')
59
		ipnet=`{ipq sys $sysname ipnet}
60
	nonnil ipnet
61
	v6pfx=`{ipq ipnet $ipnet ipv6pfx}
62
	nonnil v6pfx
63
	mev6=`{ip/linklocal $myeth | sed 's/^fe80:/'$v6pfx'/'}
64
}
65
nonnil mev6
66
 
67
#
68
# configure my global v6 addresses
69
#
70
v6mask=`{ipq ip $mev6 ipmask}
71
ip/ipconfig $xdir ether $netdir/ether?	add $mev6 $v6mask
72
ip/ipconfig $xdir loopback /dev/null	add $mev6 /128