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

Last change on this file since 22309 was 22309, checked in by kerneis, 6 years ago

[packages] ahcpd: apply unreleased upstream patch

  • Tue Jul 20 00:25:27 CEST 2010 Juliusz Chroboczek <jch@…>
    • Fix typo -- ignore autoconf prefixes for plen > 64.
  • Use uci_get_state instead of invoking uci directly.

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 ifname=$(uci_get_state network "$1" ifname "$1")
38        append interfaces "$ifname"
39}
40
41ahcp_server() {
42        local cfg="$1"
43
44        append_opt_stmt "$cfg" 'mode' 'mode'
45        append_opt_stmt "$cfg" 'lease_dir' 'lease-dir'
46        config_list_foreach "$cfg" 'prefix' append_stmt 'prefix'
47        config_list_foreach "$cfg" 'name_server' append_stmt 'name-server'
48        config_list_foreach "$cfg" 'ntp_server' append_stmt 'ntp-server'
49
50        append_parm "$cfg" 'id_file' '-i'
51        append_parm "$cfg" 'log_file' '-L'
52}
53
54ahcp_config() {
55        local cfg="$1"
56
57        config_list_foreach "$cfg" 'interface' ahcp_addif
58
59        append_bool "$cfg" 'ipv4_only' '-4'
60        append_bool "$cfg" 'ipv6_only' '-6'
61        append_bool "$cfg" 'no_dns' '-N'
62
63        append_parm "$cfg" 'multicast_address' '-m'
64        append_parm "$cfg" 'port' '-p'
65        append_parm "$cfg" 'lease_time' '-t'
66        append_parm "$cfg" 'debug' '-d'
67        append_parm "$cfg" 'conf_file' '-c'
68        append_parm "$cfg" 'script' '-s'
69}
70
71setup_interface_ahcp() {
72        local interface="$1"
73        local config="$2"
74        local pid_file="/var/run/ahcpd-$interface.pid"
75        local id_file="/var/lib/ahcp-unique-id-$interface"
76        local log_file="/var/log/ahcpd-$interface.log"
77        unset args
78
79        mkdir -p /var/lib
80
81        ahcp_config "$config"
82        eval "/usr/sbin/ahcpd -D -I $pid_file -i $id_file -L $log_file $args $interface"
83}
84
85stop_interface_ahcp() {
86        local cfg="$1"
87        local interface
88        config_get interface "$cfg" device
89        local pid_file="/var/run/ahcpd-$interface.pid"
90        [ -f "$pid_file" ] && kill $(cat "$pid_file")
91}
Note: See TracBrowser for help on using the repository browser.