4be165d8afe015fb849b2467f1740665014eb83f
[openwrt/svn-archive/archive.git] / ipv6 / wide-dhcpv6 / files / dhcp6c.init
1 #!/bin/sh /etc/rc.common
2
3 DHCP6C_REQUEST_OPTIONS='domain_name_servers domain_name ntp_servers sip_server_address sip_domain_name nis_server_address nis_domain_name nisp_server_address nisp_domain_name bcmcs_server_address bcmcs_domain_name'
4
5 get_ifname() {
6 local interface=$1
7 local ifname
8 scan_interfaces
9 config_get ifname "$interface" ifname
10 printf '%s\n' "$ifname"
11 return 0
12 }
13
14 dhcp6c_write_interface() {
15 local cfg=$1
16 local sla_id
17 local sla_len
18 local enabled
19
20 config_get_bool enabled "$cfg" enabled 0
21
22 if [ $enabled -ne 0 ]; then
23
24 config_get sla_id "$cfg" sla_id
25 config_get sla_len "$cfg" sla_len
26
27 printf '\tprefix-interface %s {\n' "$(get_ifname $cfg)"
28 printf '\t\tsla-id %s;\n' "$sla_id"
29 printf '\t\tsla-len %s;\n' "$sla_len"
30 printf '\t};\n'
31
32 fi
33
34 }
35
36 dhcp6c_write_request() {
37 printf '\trequest %s;\n' $1 | sed -e s/_/-/g
38 }
39
40 dhcp6c_write_config() {
41
42 local pd
43 local na
44 config_get_bool pd basic pd 0
45 config_get_bool na basic na 0
46
47 printf 'interface %s {\n' "$client_ifname"
48
49 if [ $pd -ne 0 ]; then
50 printf '\tsend ia-pd 0;\n'
51 fi
52
53 if [ $na -ne 0 ]; then
54 printf '\tsend ia-na 0;\n'
55 fi
56
57 local rapid_commit
58 config_get_bool rapid_commit basic rapid_commit 0
59 [ $rapid_commit -ne 0 ] && printf '\tsend rapid-commit;\n'
60
61 local script
62 config_get script basic script
63 [ "$script" != "" ] && printf '\tscript "%s";\n' "$script"
64
65 local request
66 local value
67 for request in $DHCP6C_REQUEST_OPTIONS; do
68 config_get_bool value basic "$request" 0
69 [ $value -ne 0 ] && dhcp6c_write_request "$request"
70 done
71
72 printf '};\n\n'
73
74 if [ $pd -ne 0 ]; then
75 printf 'id-assoc pd 0 {\n'
76 config_foreach dhcp6c_write_interface interface
77 printf '};\n\n'
78 fi
79
80 if [ $na -ne 0 ]; then
81 printf 'id-assoc na 0 {\n'
82 printf '};\n\n'
83 fi
84
85 return 0
86 }
87
88 start() {
89
90 [ ! -e /etc/dhcp6cctlkey ] && `dd if=/dev/urandom count=1 2> /dev/null | md5sum | cut -d" " -f1 > /etc/dhcp6cctlkey`
91
92 [ -e /var/run/dhcp6c.pid ] && return 0
93
94 include /lib/network
95
96 config_load "dhcp6c"
97
98 local enabled
99 config_get_bool enabled basic enabled 0
100 [ $enabled -eq 0 ] && return 0
101
102 logger starting dhcp6c
103
104 local client_interface
105 config_get client_interface basic interface
106 local client_ifname=$(get_ifname "$client_interface")
107
108 local config_file="/var/etc/dhcp6c.conf"
109 mkdir -m 755 -p /var/etc
110 dhcp6c_write_config > $config_file
111
112 /usr/sbin/dhcp6c -c $config_file $client_ifname
113
114 sleep 3
115 ACTION=start /sbin/hotplug-call dhcp6c
116
117 return 0
118
119 }
120
121 stop() {
122
123 logger stopping dhcp6c
124 rm -f /var/etc/dhcp6c.conf
125 kill -TERM `cat /var/run/dhcp6c.pid`
126 ACTION=stop /sbin/hotplug-call dhcp6c
127 return 0
128
129 }
130
131