dhcpv6.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/sh
  2. . /lib/functions.sh
  3. . ../netifd-proto.sh
  4. init_proto "$@"
  5. proto_dhcpv6_init_config() {
  6. renew_handler=1
  7. proto_config_add_string 'reqaddress:or("try","force","none")'
  8. proto_config_add_string 'reqprefix:or("auto","no",range(0, 64))'
  9. proto_config_add_string clientid
  10. proto_config_add_string 'reqopts:list(uinteger)'
  11. proto_config_add_string 'noslaaconly:bool'
  12. proto_config_add_string 'forceprefix:bool'
  13. proto_config_add_string 'norelease:bool'
  14. proto_config_add_string 'ip6prefix:ip6addr'
  15. proto_config_add_string iface_dslite
  16. proto_config_add_string zone_dslite
  17. proto_config_add_string iface_map
  18. proto_config_add_string zone_map
  19. proto_config_add_string iface_464xlat
  20. proto_config_add_string zone_464xlat
  21. proto_config_add_string zone
  22. proto_config_add_string 'ifaceid:ip6addr'
  23. proto_config_add_string "userclass"
  24. proto_config_add_string "vendorclass"
  25. proto_config_add_boolean delegate
  26. proto_config_add_int "soltimeout"
  27. proto_config_add_boolean fakeroutes
  28. proto_config_add_boolean sourcefilter
  29. }
  30. proto_dhcpv6_setup() {
  31. local config="$1"
  32. local iface="$2"
  33. local reqaddress reqprefix clientid reqopts noslaaconly forceprefix norelease ip6prefix iface_dslite iface_map iface_464xlat ifaceid userclass vendorclass delegate zone_dslite zone_map zone_464xlat zone soltimeout fakeroutes sourcefilter
  34. json_get_vars reqaddress reqprefix clientid reqopts noslaaconly forceprefix norelease ip6prefix iface_dslite iface_map iface_464xlat ifaceid userclass vendorclass delegate zone_dslite zone_map zone_464xlat zone soltimeout fakeroutes sourcefilter
  35. # Configure
  36. local opts=""
  37. [ -n "$reqaddress" ] && append opts "-N$reqaddress"
  38. [ -z "$reqprefix" -o "$reqprefix" = "auto" ] && reqprefix=0
  39. [ "$reqprefix" != "no" ] && append opts "-P$reqprefix"
  40. [ -n "$clientid" ] && append opts "-c$clientid"
  41. [ "$noslaaconly" = "1" ] && append opts "-S"
  42. [ "$forceprefix" = "1" ] && append opts "-F"
  43. [ "$norelease" = "1" ] && append opts "-k"
  44. [ -n "$ifaceid" ] && append opts "-i$ifaceid"
  45. [ -n "$vendorclass" ] && append opts "-V$vendorclass"
  46. [ -n "$userclass" ] && append opts "-u$userclass"
  47. for opt in $reqopts; do
  48. append opts "-r$opt"
  49. done
  50. append opts "-t${soltimeout:-120}"
  51. [ -n "$ip6prefix" ] && proto_export "USERPREFIX=$ip6prefix"
  52. [ -n "$iface_dslite" ] && proto_export "IFACE_DSLITE=$iface_dslite"
  53. [ -n "$iface_map" ] && proto_export "IFACE_MAP=$iface_map"
  54. [ -n "$iface_464xlat" ] && proto_export "IFACE_464XLAT=$iface_464xlat"
  55. [ "$delegate" = "0" ] && proto_export "IFACE_DSLITE_DELEGATE=0"
  56. [ "$delegate" = "0" ] && proto_export "IFACE_MAP_DELEGATE=0"
  57. [ -n "$zone_dslite" ] && proto_export "ZONE_DSLITE=$zone_dslite"
  58. [ -n "$zone_map" ] && proto_export "ZONE_MAP=$zone_map"
  59. [ -n "$zone_464xlat" ] && proto_export "ZONE_464XLAT=$zone_464xlat"
  60. [ -n "$zone" ] && proto_export "ZONE=$zone"
  61. [ "$fakeroutes" != "0" ] && proto_export "FAKE_ROUTES=1"
  62. [ "$sourcefilter" = "0" ] && proto_export "NOSOURCEFILTER=1"
  63. proto_export "INTERFACE=$config"
  64. proto_run_command "$config" odhcp6c \
  65. -s /lib/netifd/dhcpv6.script \
  66. $opts $iface
  67. }
  68. proto_dhcpv6_renew() {
  69. local interface="$1"
  70. # SIGUSR1 forces odhcp6c to renew its lease
  71. local sigusr1="$(kill -l SIGUSR1)"
  72. [ -n "$sigusr1" ] && proto_kill_command "$interface" $sigusr1
  73. }
  74. proto_dhcpv6_teardown() {
  75. local interface="$1"
  76. proto_kill_command "$interface"
  77. }
  78. add_protocol dhcpv6