]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/ipv6on
fixing perms
[plan9front.git] / rc / bin / ipv6on
1 #!/bin/rc
2 # ipv6on [netdir ndbfile [gwv4]] - configure an interface for ipv6,
3 #       once ipv4 is configured.
4 if (! ~ $#* 0 2 3) {
5         echo usage: $0 '[netdir ndbfile [gw-v4-name]]' >[1=2]
6         exit usage
7 }
8 rfork e
9 if (~ $#* 0) {
10         netdir=/net
11         ndbf=/lib/ndb/local
12         gw=`{ndb/ipquery sys $sysname ipgw | sed 's/ipgw=//'}
13 }
14 if not {
15         netdir=$1
16         ndbf=$2
17         if (~ $#* 2)
18                 # gw=()
19                 gw=`{ndb/ipquery sys $sysname ipgw | sed 's/ipgw=//'}
20         if not
21                 gw=$3
22 }
23 if (~ $netdir /net) {
24         xsfx=()
25         xdir=()
26 }
27 if not {
28         xsfx=(-x `{echo $netdir | sed 's;^/net;;'})
29         xdir=(-x $netdir)
30 }
31
32 fn nonnil {             # variable
33         if (~ $#$1 0) {
34                 echo no ip for $1
35                 exit no-ip
36         }
37         if (! ~ $#$1 1) {
38                 echo multiple ips for $1
39                 exit multiple-ips
40         }
41 }
42
43 #
44 # configure v6 for link-local addresses (fe80::) & multicast (ff02::)
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 mev6=`{ndb/query -f $ndbf sys $sysname ipv6}
51 if (~ $#sysname 0 || ~ $sysname '')
52         mev6=`{ndb/query -f $ndbf sys $sysname ip | grep :}
53 # mev4=`{ndb/query -f $ndbf sys $sysname ip | grep -v :}
54
55 # for testing
56 mylnk=`{ip/linklocal `{cat $netdir/ether?/addr}}
57 nonnil mylnk
58
59 if (~ $#gw 1) {
60         if (~ $gw [0-9]*.[0-9]*.[0-9]*.[0-9]*)
61                 gwv4 = $gw
62         if (~ $#gwv4 0 || ~ $gwv4 '')           # assume namev6 and name
63                 gwv4=`{ndb/query -f $ndbf sys $gw ip}
64         gwv6=`{ndb/query -f $ndbf sys $gw ipv6}
65
66         if (! ~ $#gwv4 0) {
67                 # echo ping gw $gwv4...
68                 # load arp cache with gw mac
69                 ip/ping -qn 3 $netdir/icmp!$gwv4 >/dev/null >[2=1] &
70                 sleep 1                                 # wait for ping
71
72                 gweth=`{grep '* '^$gwv4^' ' $netdir/arp | awk '{print $4}' }
73                 nonnil gweth
74                 gwlnk=`{ip/linklocal $gweth}
75                 nonnil gwlnk
76         }
77 }
78 nonnil mev6
79 #
80 # configure my global v6 addresses
81 #
82 ip/ipconfig $xdir ether $netdir/ether?  add $mev6 /64
83 ip/ipconfig $xdir loopback /dev/null    add $mev6 /128
84
85 if (~ $#gw 1) {
86         if (~ $#gwv6 0 || ~ $gwv6 '')
87                 gwv6=`{ip/linklocal $gweth}
88         nonnil gwv6
89         #
90         # add default v6 route to v6 addr of v4 gw
91         #
92         echo add :: /0 $gwv6 >$netdir/iproute   # need not be link-local
93 }
94 exit ''