ipv6on 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. if (~ $#* 0) {
  14. netdir=/net
  15. ndbf=/lib/ndb/local
  16. }
  17. if not {
  18. netdir=$1
  19. ndbf=$2
  20. }
  21. if (~ $netdir /net) {
  22. xsfx=()
  23. xdir=()
  24. }
  25. if not {
  26. xsfx=(-x `{echo $netdir | sed 's;^/net;;'})
  27. xdir=(-x $netdir)
  28. }
  29. fn nonnil { # variable
  30. if (~ $#$1 0) {
  31. echo ipv6on: no ip for $1 >[1=2]
  32. exit no-ip
  33. }
  34. if (! ~ $#$1 1) {
  35. echo ipv6on: multiple ips for $1 >[1=2]
  36. exit multiple-ips
  37. }
  38. }
  39. #
  40. # configure v6 for link-local addresses (fe80::) & multicast (ff02::).
  41. # accept router advertisements, which will contain a default route.
  42. #
  43. if (! ip/ipconfig -6 $xdir ether $netdir/ether?)
  44. exit 'ipconfig -6 failed'
  45. ip/ipconfig $xdir ether $netdir/ether? ra6 recvra 1
  46. # lookup any v6 address for me in ndb, else use slaac
  47. myeth=`{cat $netdir/ether?/addr}
  48. mev6=`{ndb/query -f $ndbf ether $myeth ipv6}
  49. if (~ $#mev6 0 || ~ $mev6 '')
  50. mev6=`{ndb/query -f $ndbf sys $sysname ipv6}
  51. if (~ $#mev6 0 || ~ $mev6 '') {
  52. # slaac: could perhaps get prefix from above RA
  53. ipnet=`{ipq ether $myeth ipnet}
  54. if (~ $#ipnet 0 || ~ $ipnet '')
  55. ipnet=`{ipq sys $sysname ipnet}
  56. nonnil ipnet
  57. v6pfx=`{ipq ipnet $ipnet ipv6pfx}
  58. nonnil v6pfx
  59. mev6=`{ip/linklocal $myeth | sed 's/^fe80:/'$v6pfx'/'}
  60. }
  61. nonnil mev6
  62. #
  63. # configure my global v6 addresses
  64. #
  65. v6mask=`{ipq ip $mev6 ipmask}
  66. ip/ipconfig $xdir ether $netdir/ether? add $mev6 $v6mask
  67. ip/ipconfig $xdir loopback /dev/null add $mev6 /128