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