scripts/download.pl: fix support for aria2c download tool on macos
[openwrt/openwrt.git] / package / network / ipv6 / odhcp6c / files / dhcpv6.sh
1 #!/bin/sh
2
3 . /lib/functions.sh
4 . ../netifd-proto.sh
5 init_proto "$@"
6
7 proto_dhcpv6_init_config() {
8 renew_handler=1
9
10 proto_config_add_string 'reqaddress:or("try","force","none")'
11 proto_config_add_string 'reqprefix:or("auto","no",range(0, 64))'
12 proto_config_add_string clientid
13 proto_config_add_string 'reqopts:list(uinteger)'
14 proto_config_add_string 'defaultreqopts:bool'
15 proto_config_add_string 'noslaaconly:bool'
16 proto_config_add_string 'forceprefix:bool'
17 proto_config_add_string 'extendprefix:bool'
18 proto_config_add_string 'norelease:bool'
19 proto_config_add_string 'noserverunicast:bool'
20 proto_config_add_string 'noclientfqdn:bool'
21 proto_config_add_string 'noacceptreconfig:bool'
22 proto_config_add_array 'ip6prefix:list(ip6addr)'
23 proto_config_add_string iface_dslite
24 proto_config_add_string zone_dslite
25 proto_config_add_string encaplimit_dslite
26 proto_config_add_string iface_map
27 proto_config_add_string zone_map
28 proto_config_add_string encaplimit_map
29 proto_config_add_string iface_464xlat
30 proto_config_add_string zone_464xlat
31 proto_config_add_string zone
32 proto_config_add_string 'ifaceid:ip6addr'
33 proto_config_add_string "userclass"
34 proto_config_add_string "vendorclass"
35 proto_config_add_array "sendopts:list(string)"
36 proto_config_add_boolean delegate
37 proto_config_add_int "soltimeout"
38 proto_config_add_boolean fakeroutes
39 proto_config_add_boolean sourcefilter
40 proto_config_add_boolean keep_ra_dnslifetime
41 proto_config_add_int "ra_holdoff"
42 }
43
44 proto_dhcpv6_add_prefix() {
45 append "$3" "$1"
46 }
47
48 proto_dhcpv6_add_sendopts() {
49 [ -n "$1" ] && append "$3" "-x$1"
50 }
51
52 proto_dhcpv6_setup() {
53 local config="$1"
54 local iface="$2"
55
56 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
57 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
58 json_for_each_item proto_dhcpv6_add_prefix ip6prefix ip6prefixes
59
60 # Configure
61 local opts=""
62 [ -n "$reqaddress" ] && append opts "-N$reqaddress"
63
64 [ -z "$reqprefix" -o "$reqprefix" = "auto" ] && reqprefix=0
65 [ "$reqprefix" != "no" ] && append opts "-P$reqprefix"
66
67 [ -n "$clientid" ] && append opts "-c$clientid"
68
69 [ "$defaultreqopts" = "0" ] && append opts "-R"
70
71 [ "$noslaaconly" = "1" ] && append opts "-S"
72
73 [ "$forceprefix" = "1" ] && append opts "-F"
74
75 [ "$norelease" = "1" ] && append opts "-k"
76
77 [ "$noserverunicast" = "1" ] && append opts "-U"
78
79 [ "$noclientfqdn" = "1" ] && append opts "-f"
80
81 [ "$noacceptreconfig" = "1" ] && append opts "-a"
82
83 [ -n "$ifaceid" ] && append opts "-i$ifaceid"
84
85 [ -n "$vendorclass" ] && append opts "-V$vendorclass"
86
87 [ -n "$userclass" ] && append opts "-u$userclass"
88
89 [ "$keep_ra_dnslifetime" = "1" ] && append opts "-L"
90
91 [ -n "$ra_holdoff" ] && append opts "-m$ra_holdoff"
92
93 local opt
94 for opt in $reqopts; do
95 append opts "-r$opt"
96 done
97
98 json_for_each_item proto_dhcpv6_add_sendopts sendopts opts
99
100 append opts "-t${soltimeout:-120}"
101
102 [ -n "$ip6prefixes" ] && proto_export "USERPREFIX=$ip6prefixes"
103 [ -n "$iface_dslite" ] && proto_export "IFACE_DSLITE=$iface_dslite"
104 [ -n "$iface_map" ] && proto_export "IFACE_MAP=$iface_map"
105 [ -n "$iface_464xlat" ] && proto_export "IFACE_464XLAT=$iface_464xlat"
106 [ "$delegate" = "0" ] && proto_export "IFACE_DSLITE_DELEGATE=0"
107 [ "$delegate" = "0" ] && proto_export "IFACE_MAP_DELEGATE=0"
108 [ -n "$zone_dslite" ] && proto_export "ZONE_DSLITE=$zone_dslite"
109 [ -n "$zone_map" ] && proto_export "ZONE_MAP=$zone_map"
110 [ -n "$zone_464xlat" ] && proto_export "ZONE_464XLAT=$zone_464xlat"
111 [ -n "$zone" ] && proto_export "ZONE=$zone"
112 [ -n "$encaplimit_dslite" ] && proto_export "ENCAPLIMIT_DSLITE=$encaplimit_dslite"
113 [ -n "$encaplimit_map" ] && proto_export "ENCAPLIMIT_MAP=$encaplimit_map"
114 [ "$fakeroutes" != "0" ] && proto_export "FAKE_ROUTES=1"
115 [ "$sourcefilter" = "0" ] && proto_export "NOSOURCEFILTER=1"
116 [ "$extendprefix" = "1" ] && proto_export "EXTENDPREFIX=1"
117
118 proto_export "INTERFACE=$config"
119 proto_run_command "$config" odhcp6c \
120 -s /lib/netifd/dhcpv6.script \
121 $opts $iface
122 }
123
124 proto_dhcpv6_renew() {
125 local interface="$1"
126 # SIGUSR1 forces odhcp6c to renew its lease
127 local sigusr1="$(kill -l SIGUSR1)"
128 [ -n "$sigusr1" ] && proto_kill_command "$interface" $sigusr1
129 }
130
131 proto_dhcpv6_teardown() {
132 local interface="$1"
133 proto_kill_command "$interface"
134 }
135
136 add_protocol dhcpv6
137