b97bda92548143a32173156dbdb6cfc7cffade26
[openwrt/svn-archive/archive.git] / ipv6 / ahcpd / files / ahcp.sh
1 append_bool() {
2 local section="$1"
3 local option="$2"
4 local value="$3"
5 local _loctmp
6 config_get_bool _loctmp "$section" "$option"
7 [ "$_loctmp" -gt 0 ] && append args "$value"
8 }
9
10 append_parm() {
11 local section="$1"
12 local option="$2"
13 local switch="$3"
14 local _loctmp
15 config_get _loctmp "$section" "$option"
16 [ -z "$_loctmp" ] && return 0
17 append args "$switch $_loctmp"
18 }
19
20 append_args() {
21 local name="$1"
22 local switch="$2"
23 append args "$switch $name"
24 }
25
26 ahcp_addif() {
27 local name="$1"
28 local _uciname=`uci get -q -P /var/state network.$name.ifname`
29 append interfaces "${_uciname:-$name}"
30 }
31
32 ahcp_server() {
33 local cfg="$1"
34
35 append args "-C '"
36
37 append_parm "$cfg" 'mode' 'mode'
38 append_parm "$cfg" 'lease_dir' 'lease-dir'
39 config_list_foreach "$cfg" 'prefix' append_args 'prefix'
40 config_list_foreach "$cfg" 'name_server' append_args 'name-server'
41 config_list_foreach "$cfg" 'ntp_server' append_args 'ntp-server'
42
43 append args ' ' "'"
44
45 append_parm "$cfg" 'id_file' '-i'
46 append_parm "$cfg" 'log_file' '-L'
47 }
48
49 ahcp_config() {
50 local cfg="$1"
51
52 config_list_foreach "$cfg" 'interface' ahcp_addif
53
54 append_bool "$cfg" 'ipv4_only' '-4'
55 append_bool "$cfg" 'ipv6_only' '-6'
56 append_bool "$cfg" 'no_dns' '-N'
57
58 append_parm "$cfg" 'multicast_address' '-m'
59 append_parm "$cfg" 'port' '-p'
60 append_parm "$cfg" 'lease_time' '-t'
61 append_parm "$cfg" 'debug' '-d'
62 append_parm "$cfg" 'conf_file' '-c'
63 append_parm "$cfg" 'script' '-s'
64 }
65
66 setup_interface_ahcp() {
67 local interface="$1"
68 local config="$2"
69 local pid_file="/var/run/ahcpd-$interface.pid"
70 local id_file="/var/lib/ahcp-unique-id-$interface"
71 local log_file="/var/log/ahcpd-$interface.log"
72 unset args
73
74 mkdir -p /var/lib
75
76 ahcp_config "$config"
77 eval "/usr/sbin/ahcpd -D -I $pid_file -i $id_file -L $log_file $args $interface"
78 }
79
80 stop_interface_ahcp() {
81 local cfg="$1"
82 local interface
83 config_get interface "$cfg" device
84 local pid_file="/var/run/ahcpd-$interface.pid"
85 [ -f "$pid_file" ] && kill $(cat "$pid_file")
86 }