source: packages/ipv6/ahcpd/files/ahcpd.init @ 28337

Last change on this file since 28337 was 28337, checked in by kerneis, 5 years ago

[packages] ahcpd: add ahcp proto, use service_kill

  • Property svn:copyright set to Copyright (C) 2007 OpenWrt.org
File size: 2.3 KB
Line 
1#!/bin/sh /etc/rc.common
2
3START=71
4PID_F="/var/run/ahcpd.pid"
5EXTRA_COMMANDS="status"
6EXTRA_HELP="        status Print ahcpd's status to the log file."
7
8append_bool() {
9        local section="$1"
10        local option="$2"
11        local value="$3"
12        local _loctmp
13        config_get_bool _loctmp "$section" "$option" 0
14        [ "$_loctmp" -gt 0 ] && append args "$value"
15}
16
17append_parm() {
18        local section="$1"
19        local option="$2"
20        local switch="$3"
21        local _loctmp
22        config_get _loctmp "$section" "$option"
23        [ -z "$_loctmp" ] && return 0
24        append args "$switch $_loctmp"
25}
26
27append_stmt() {
28        local name="$1"
29        local switch="$2"
30        append args "-C '$switch $name'"
31}
32
33append_opt_stmt() {
34        local section="$1"
35        local option="$2"
36        local switch="$3"
37        local _loctmp
38        config_get _loctmp "$section" "$option"
39        [ -z "$_loctmp" ] && return 0
40        append args "-C '$switch $_loctmp'"
41}
42
43ahcp_addif() {
44        local ifname=$(uci_get_state network "$1" ifname "$1")
45        append interfaces "$ifname"
46}
47
48ahcp_server() {
49        local cfg="$1"
50
51        append_opt_stmt "$cfg" 'mode' 'mode'
52        append_opt_stmt "$cfg" 'lease_dir' 'lease-dir'
53        config_list_foreach "$cfg" 'prefix' append_stmt 'prefix'
54        config_list_foreach "$cfg" 'name_server' append_stmt 'name-server'
55        config_list_foreach "$cfg" 'ntp_server' append_stmt 'ntp-server'
56
57        append_parm "$cfg" 'id_file' '-i'
58        append_parm "$cfg" 'log_file' '-L'
59}
60
61ahcp_config() {
62        local cfg="$1"
63        local interface
64        local _loctmp
65
66        config_list_foreach "$cfg" 'interface' ahcp_addif
67
68        # Add interfaces with "option proto ahcp" in /etc/config/network
69        # (only for client mode)
70        config_get _loctmp "$cfg" "mode"
71        if [ -z "$_loctmp" -o "$_loctmp" = "client" ]; then
72                for interface in $(uci -P /var/state show network|grep proto=ahcp|cut -d. -f2); do
73                        ahcp_addif $interface
74                done
75        fi
76
77        append_bool "$cfg" 'ipv4_only' '-4'
78        append_bool "$cfg" 'ipv6_only' '-6'
79        append_bool "$cfg" 'no_dns' '-N'
80
81        append_parm "$cfg" 'multicast_address' '-m'
82        append_parm "$cfg" 'port' '-p'
83        append_parm "$cfg" 'lease_time' '-t'
84        append_parm "$cfg" 'debug' '-d'
85        append_parm "$cfg" 'conf_file' '-c'
86        append_parm "$cfg" 'script' '-s'
87}
88
89start() {
90        mkdir -p /var/lib
91        config_load ahcpd
92        unset args
93        unset interfaces
94        config_foreach ahcp_config ahcpd
95        config_foreach ahcp_server ahcpd
96        [ -z "$interfaces" ] && return 0
97        eval "/usr/sbin/ahcpd -D -I $PID_F $args $interfaces"
98}
99
100stop() {
101        service_kill "ahcpd" "$PID_F"
102}
103
104status() {
105        [ -f $PID_F ] && kill -USR1 $(cat $PID_F)
106}
Note: See TracBrowser for help on using the repository browser.