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