dhcpv6.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 'defaultreqopts:bool'
  12. proto_config_add_string 'noslaaconly:bool'
  13. proto_config_add_string 'forceprefix:bool'
  14. proto_config_add_string 'extendprefix:bool'
  15. proto_config_add_string 'norelease:bool'
  16. proto_config_add_string 'noserverunicast:bool'
  17. proto_config_add_string 'noclientfqdn:bool'
  18. proto_config_add_string 'noacceptreconfig:bool'
  19. proto_config_add_array 'ip6prefix:list(ip6addr)'
  20. proto_config_add_string iface_dslite
  21. proto_config_add_string zone_dslite
  22. proto_config_add_string encaplimit_dslite
  23. proto_config_add_string iface_map
  24. proto_config_add_string zone_map
  25. proto_config_add_string encaplimit_map
  26. proto_config_add_string iface_464xlat
  27. proto_config_add_string zone_464xlat
  28. proto_config_add_string zone
  29. proto_config_add_string 'ifaceid:ip6addr'
  30. proto_config_add_string "userclass"
  31. proto_config_add_string "vendorclass"
  32. proto_config_add_array "sendopts:list(string)"
  33. proto_config_add_boolean delegate
  34. proto_config_add_int "soltimeout"
  35. proto_config_add_boolean fakeroutes
  36. proto_config_add_boolean sourcefilter
  37. proto_config_add_boolean keep_ra_dnslifetime
  38. proto_config_add_int "ra_holdoff"
  39. }
  40. proto_dhcpv6_add_prefix() {
  41. append "$3" "$1"
  42. }
  43. proto_dhcpv6_add_sendopts() {
  44. [ -n "$1" ] && append "$3" "-x$1"
  45. }
  46. proto_dhcpv6_setup() {
  47. local config="$1"
  48. local iface="$2"
  49. local reqaddress reqprefix clientid reqopts defaultreqopts noslaaconly forceprefix extendprefix norelease noserverunicast noclientfqdn noacceptreconfig ip6prefix ip6prefixes iface_dslite iface_map iface_464xlat ifaceid userclass vendorclass sendopts delegate zone_dslite zone_map zone_464xlat zone encaplimit_dslite encaplimit_map soltimeout fakeroutes sourcefilter keep_ra_dnslifetime ra_holdoff
  50. json_get_vars reqaddress reqprefix clientid reqopts defaultreqopts noslaaconly forceprefix extendprefix norelease noserverunicast noclientfqdn noacceptreconfig iface_dslite iface_map iface_464xlat ifaceid userclass vendorclass delegate zone_dslite zone_map zone_464xlat zone encaplimit_dslite encaplimit_map soltimeout fakeroutes sourcefilter keep_ra_dnslifetime ra_holdoff
  51. json_for_each_item proto_dhcpv6_add_prefix ip6prefix ip6prefixes
  52. # Configure
  53. local opts=""
  54. [ -n "$reqaddress" ] && append opts "-N$reqaddress"
  55. [ -z "$reqprefix" -o "$reqprefix" = "auto" ] && reqprefix=0
  56. [ "$reqprefix" != "no" ] && append opts "-P$reqprefix"
  57. [ -n "$clientid" ] && append opts "-c$clientid"
  58. [ "$defaultreqopts" = "0" ] && append opts "-R"
  59. [ "$noslaaconly" = "1" ] && append opts "-S"
  60. [ "$forceprefix" = "1" ] && append opts "-F"
  61. [ "$norelease" = "1" ] && append opts "-k"
  62. [ "$noserverunicast" = "1" ] && append opts "-U"
  63. [ "$noclientfqdn" = "1" ] && append opts "-f"
  64. [ "$noacceptreconfig" = "1" ] && append opts "-a"
  65. [ -n "$ifaceid" ] && append opts "-i$ifaceid"
  66. [ -n "$vendorclass" ] && append opts "-V$vendorclass"
  67. [ -n "$userclass" ] && append opts "-u$userclass"
  68. [ "$keep_ra_dnslifetime" = "1" ] && append opts "-L"
  69. [ -n "$ra_holdoff" ] && append opts "-m$ra_holdoff"
  70. local opt
  71. for opt in $reqopts; do
  72. append opts "-r$opt"
  73. done
  74. json_for_each_item proto_dhcpv6_add_sendopts sendopts opts
  75. append opts "-t${soltimeout:-120}"
  76. [ -n "$ip6prefixes" ] && proto_export "USERPREFIX=$ip6prefixes"
  77. [ -n "$iface_dslite" ] && proto_export "IFACE_DSLITE=$iface_dslite"
  78. [ -n "$iface_map" ] && proto_export "IFACE_MAP=$iface_map"
  79. [ -n "$iface_464xlat" ] && proto_export "IFACE_464XLAT=$iface_464xlat"
  80. [ "$delegate" = "0" ] && proto_export "IFACE_DSLITE_DELEGATE=0"
  81. [ "$delegate" = "0" ] && proto_export "IFACE_MAP_DELEGATE=0"
  82. [ -n "$zone_dslite" ] && proto_export "ZONE_DSLITE=$zone_dslite"
  83. [ -n "$zone_map" ] && proto_export "ZONE_MAP=$zone_map"
  84. [ -n "$zone_464xlat" ] && proto_export "ZONE_464XLAT=$zone_464xlat"
  85. [ -n "$zone" ] && proto_export "ZONE=$zone"
  86. [ -n "$encaplimit_dslite" ] && proto_export "ENCAPLIMIT_DSLITE=$encaplimit_dslite"
  87. [ -n "$encaplimit_map" ] && proto_export "ENCAPLIMIT_MAP=$encaplimit_map"
  88. [ "$fakeroutes" != "0" ] && proto_export "FAKE_ROUTES=1"
  89. [ "$sourcefilter" = "0" ] && proto_export "NOSOURCEFILTER=1"
  90. [ "$extendprefix" = "1" ] && proto_export "EXTENDPREFIX=1"
  91. proto_export "INTERFACE=$config"
  92. proto_run_command "$config" odhcp6c \
  93. -s /lib/netifd/dhcpv6.script \
  94. $opts $iface
  95. }
  96. proto_dhcpv6_renew() {
  97. local interface="$1"
  98. # SIGUSR1 forces odhcp6c to renew its lease
  99. local sigusr1="$(kill -l SIGUSR1)"
  100. [ -n "$sigusr1" ] && proto_kill_command "$interface" $sigusr1
  101. }
  102. proto_dhcpv6_teardown() {
  103. local interface="$1"
  104. proto_kill_command "$interface"
  105. }
  106. add_protocol dhcpv6