ipv6on 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/rc
  2. # ipv6on [netdir ndbfile [gwv4]] - configure an interface for v6,
  3. # once v4 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. fn nonnil { # name ip
  32. if (~ $#2 0) {
  33. echo no ip for $1
  34. exit no-ip
  35. }
  36. }
  37. #
  38. # configure v6 for link-local addresses (fe80::) & multicast (ff02::)
  39. #
  40. if (! ip/ipconfig -6 $xdir ether $netdir/ether?)
  41. exit 'ipconfig -6 failed'
  42. ip/ipconfig $xdir ether $netdir/ether? ra6 recvra 1
  43. mev6=`{ndb/query -f $ndbf sys $sysname ipv6}
  44. mev4=`{ndb/query -f $ndbf sys $sysname ip}
  45. # for testing
  46. mylnk=`{ip/linklocal `{cat $netdir/ether?/addr}}
  47. nonnil mylnk $mylnk
  48. if (~ $#gw 1) {
  49. if (~ $gw [0-9]*.[0-9]*.[0-9]*.[0-9]*)
  50. gwv4 = $gw
  51. if (~ $#gwv4 0 || ~ $gwv4 '') # assume namev6 and name
  52. gwv4=`{ndb/query -f $ndbf sys $gw ip}
  53. gwv6=`{ndb/query -f $ndbf sys $gw ipv6}
  54. if (! ~ $#gwv4 0) {
  55. echo ping gw $gwv4...
  56. # load arp cache with gw mac
  57. ip/ping -qn 3 $netdir/icmp!$gwv4 >/dev/null >[2=1] &
  58. sleep 3 # wait for ping
  59. gweth=`{grep '* '^$gwv4^' ' $netdir/arp | awk '{print $4}' }
  60. nonnil gweth $gweth
  61. gwlnk=`{ip/linklocal $gweth}
  62. nonnil gwlnk $gwlnk
  63. }
  64. }
  65. nonnil mev6 $mev6
  66. #
  67. # configure my global v6 addresses
  68. #
  69. ip/ipconfig $xdir ether $netdir/ether? add $mev6 /64
  70. ip/ipconfig $xdir loopback /dev/null add $mev6 /128
  71. if (~ $#gw 1) {
  72. if (~ $#gwv6 0 || ~ $gwv6 '')
  73. gwv6=`{ip/linklocal $gweth}
  74. nonnil gwv6 $gwv6
  75. #
  76. # add default v6 route to v6 addr of v4 gw
  77. #
  78. echo add :: /0 $gwv6 >$netdir/iproute # need not be link-local
  79. }
  80. exit ''