source: packages/ipv6/ahcpd/files/ahcp.sh @ 21644

Last change on this file since 21644 was 21644, checked in by kerneis, 7 years ago

[package] ahcpd: Fix server mode (broken script)

Signed-off-by: Gabriel Kerneis <kerneis@…>

File size: 2.1 KB
Line 
1append_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
10append_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
20append_stmt() {
21        local name="$1"
22        local switch="$2"
23        append args "-C '$switch $name'"
24}
25
26append_opt_stmt() {
27        local section="$1"
28        local option="$2"
29        local switch="$3"
30        local _loctmp
31        config_get _loctmp "$section" "$option"
32        [ -z "$_loctmp" ] && return 0
33        append args "-C '$switch $_loctmp'"
34}
35
36ahcp_addif() {
37        local name="$1"
38        local _uciname=`uci get -q -P /var/state network.$name.ifname`
39        append interfaces "${_uciname:-$name}"
40}
41
42ahcp_server() {
43        local cfg="$1"
44
45        append_opt_stmt "$cfg" 'mode' 'mode'
46        append_opt_stmt "$cfg" 'lease_dir' 'lease-dir'
47        config_list_foreach "$cfg" 'prefix' append_stmt 'prefix'
48        config_list_foreach "$cfg" 'name_server' append_stmt 'name-server'
49        config_list_foreach "$cfg" 'ntp_server' append_stmt 'ntp-server'
50
51        append_parm "$cfg" 'id_file' '-i'
52        append_parm "$cfg" 'log_file' '-L'
53}
54
55ahcp_config() {
56        local cfg="$1"
57
58        config_list_foreach "$cfg" 'interface' ahcp_addif
59
60        append_bool "$cfg" 'ipv4_only' '-4'
61        append_bool "$cfg" 'ipv6_only' '-6'
62        append_bool "$cfg" 'no_dns' '-N'
63
64        append_parm "$cfg" 'multicast_address' '-m'
65        append_parm "$cfg" 'port' '-p'
66        append_parm "$cfg" 'lease_time' '-t'
67        append_parm "$cfg" 'debug' '-d'
68        append_parm "$cfg" 'conf_file' '-c'
69        append_parm "$cfg" 'script' '-s'
70}
71
72setup_interface_ahcp() {
73        local interface="$1"
74        local config="$2"
75        local pid_file="/var/run/ahcpd-$interface.pid"
76        local id_file="/var/lib/ahcp-unique-id-$interface"
77        local log_file="/var/log/ahcpd-$interface.log"
78        unset args
79
80        mkdir -p /var/lib
81
82        ahcp_config "$config"
83        eval "/usr/sbin/ahcpd -D -I $pid_file -i $id_file -L $log_file $args $interface"
84}
85
86stop_interface_ahcp() {
87        local cfg="$1"
88        local interface
89        config_get interface "$cfg" device
90        local pid_file="/var/run/ahcpd-$interface.pid"
91        [ -f "$pid_file" ] && kill $(cat "$pid_file")
92}
Note: See TracBrowser for help on using the repository browser.