1
0

dhcpv6.sh 3.4 KB

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