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