1
0

ipv6on 2.0 KB

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