1
0

dhcpv6.sh 3.6 KB

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