b1837a9c6a94413c374669c51cf1ff45424823a5
[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 proto_config_add_string "reqaddress"
9 proto_config_add_string "reqprefix"
10 proto_config_add_string "clientid"
11 proto_config_add_string "reqopts"
12 proto_config_add_string "noslaaconly"
13 proto_config_add_string "ip6prefix"
14 }
15
16 proto_dhcpv6_setup() {
17 local config="$1"
18 local iface="$2"
19
20 local reqaddress reqprefix clientid reqopts noslaaconly ip6prefix
21 json_get_vars reqaddress reqprefix clientid reqopts noslaaconly ip6prefix
22
23
24 # Configure
25 local opts=""
26 [ -n "$reqaddress" ] && append opts "-N$reqaddress"
27
28 [ -z "$reqprefix" -o "$reqprefix" = "auto" ] && reqprefix=0
29 [ "$reqprefix" != "no" ] && append opts "-P$reqprefix"
30
31 [ -n "$clientid" ] && append opts "-c$clientid"
32
33 [ "$noslaaconly" = "1" ] && append opts "-S"
34
35 for opt in $reqopts; do
36 append opts "-r$opt"
37 done
38
39 [ -n "$ip6prefix" ] && proto_export "USERPREFIX=$ip6prefix"
40
41 proto_export "INTERFACE=$config"
42 proto_run_command "$config" odhcp6c \
43 -s /lib/netifd/dhcpv6.script \
44 $opts $iface
45 }
46
47 proto_dhcpv6_teardown() {
48 local interface="$1"
49 proto_kill_command "$interface"
50 }
51
52 add_protocol dhcpv6
53