[packages] ahcpd: add ahcp proto, use service_kill
authorGabriel Kerneis <kerneis@pps.jussieu.fr>
Fri, 30 Sep 2011 17:31:33 +0000 (17:31 +0000)
committerGabriel Kerneis <kerneis@pps.jussieu.fr>
Fri, 30 Sep 2011 17:31:33 +0000 (17:31 +0000)
SVN-Revision: 28337

ipv6/ahcpd/Makefile
ipv6/ahcpd/files/ahcp.sh
ipv6/ahcpd/files/ahcpd.init

index 60e49235922b3cc19f14ee17d1350bccedc07ae6..dbaa664b2b88de5efce71ae5df41691afa07bbf9 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=ahcpd
 PKG_VERSION:=0.52
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://www.pps.jussieu.fr/~jch/software/files/
index 5b7b55b2016ccc65e6ae7227e75d30896a5bcf2d..6dc8c97585e38679ca0df545cf7150165181c3de 100644 (file)
@@ -1,77 +1,13 @@
-append_bool() {
-       local section="$1"
-       local option="$2"
-       local value="$3"
-       local _loctmp
-       config_get_bool _loctmp "$section" "$option" 0
-       [ "$_loctmp" -gt 0 ] && append args "$value"
-}
-
-append_parm() {
-       local section="$1"
-       local option="$2"
-       local switch="$3"
-       local _loctmp
-       config_get _loctmp "$section" "$option"
-       [ -z "$_loctmp" ] && return 0
-       append args "$switch $_loctmp"
-}
-
-append_stmt() {
-       local name="$1"
-       local switch="$2"
-       append args "-C '$switch $name'"
-}
-
-append_opt_stmt() {
-       local section="$1"
-       local option="$2"
-       local switch="$3"
-       local _loctmp
-       config_get _loctmp "$section" "$option"
-       [ -z "$_loctmp" ] && return 0
-       append args "-C '$switch $_loctmp'"
-}
-
-ahcp_addif() {
-       local ifname=$(uci_get_state network "$1" ifname "$1")
-       append interfaces "$ifname"
-}
-
-ahcp_server() {
-       local cfg="$1"
-
-       append_opt_stmt "$cfg" 'mode' 'mode'
-       append_opt_stmt "$cfg" 'lease_dir' 'lease-dir'
-       config_list_foreach "$cfg" 'prefix' append_stmt 'prefix'
-       config_list_foreach "$cfg" 'name_server' append_stmt 'name-server'
-       config_list_foreach "$cfg" 'ntp_server' append_stmt 'ntp-server'
-
-       append_parm "$cfg" 'id_file' '-i'
-       append_parm "$cfg" 'log_file' '-L'
-}
-
-ahcp_config() {
-       local cfg="$1"
-
-       config_list_foreach "$cfg" 'interface' ahcp_addif
-
-       append_bool "$cfg" 'ipv4_only' '-4'
-       append_bool "$cfg" 'ipv6_only' '-6'
-       append_bool "$cfg" 'no_dns' '-N'
-
-       append_parm "$cfg" 'multicast_address' '-m'
-       append_parm "$cfg" 'port' '-p'
-       append_parm "$cfg" 'lease_time' '-t'
-       append_parm "$cfg" 'debug' '-d'
-       append_parm "$cfg" 'conf_file' '-c'
-       append_parm "$cfg" 'script' '-s'
-}
-
 setup_interface_ahcp() {
        local interface="$1"
        local config="$2"
 
-    echo "WARNING: ahcp client cannot be configured in /etc/config/network anymore."
-    echo "Please add $interface to /etc/config/ahcpd instead."
+       local mode=$(uci_get_state ahcpd "@ahcpd[0]" mode "client")
+       if [ "$mode" != "client" ]; then
+               echo "Warning: ahcp ignored for $interface (mode is $mode, should be client)."
+               echo "Fix ahcp mode in /etc/config/ahcpd."
+               return
+       fi
+       setup_interface_none "$interface" "$config"
+       /etc/init.d/ahcpd restart
 }
index 38b520891d4ff06f6e0cb021d423f41411a4c040..bd1ecc9154df538ac4ee05940b822e878e465ed1 100644 (file)
@@ -5,7 +5,86 @@ PID_F="/var/run/ahcpd.pid"
 EXTRA_COMMANDS="status"
 EXTRA_HELP="        status Print ahcpd's status to the log file."
 
-. /lib/network/ahcp.sh
+append_bool() {
+       local section="$1"
+       local option="$2"
+       local value="$3"
+       local _loctmp
+       config_get_bool _loctmp "$section" "$option" 0
+       [ "$_loctmp" -gt 0 ] && append args "$value"
+}
+
+append_parm() {
+       local section="$1"
+       local option="$2"
+       local switch="$3"
+       local _loctmp
+       config_get _loctmp "$section" "$option"
+       [ -z "$_loctmp" ] && return 0
+       append args "$switch $_loctmp"
+}
+
+append_stmt() {
+       local name="$1"
+       local switch="$2"
+       append args "-C '$switch $name'"
+}
+
+append_opt_stmt() {
+       local section="$1"
+       local option="$2"
+       local switch="$3"
+       local _loctmp
+       config_get _loctmp "$section" "$option"
+       [ -z "$_loctmp" ] && return 0
+       append args "-C '$switch $_loctmp'"
+}
+
+ahcp_addif() {
+       local ifname=$(uci_get_state network "$1" ifname "$1")
+       append interfaces "$ifname"
+}
+
+ahcp_server() {
+       local cfg="$1"
+
+       append_opt_stmt "$cfg" 'mode' 'mode'
+       append_opt_stmt "$cfg" 'lease_dir' 'lease-dir'
+       config_list_foreach "$cfg" 'prefix' append_stmt 'prefix'
+       config_list_foreach "$cfg" 'name_server' append_stmt 'name-server'
+       config_list_foreach "$cfg" 'ntp_server' append_stmt 'ntp-server'
+
+       append_parm "$cfg" 'id_file' '-i'
+       append_parm "$cfg" 'log_file' '-L'
+}
+
+ahcp_config() {
+       local cfg="$1"
+       local interface
+       local _loctmp
+
+       config_list_foreach "$cfg" 'interface' ahcp_addif
+
+       # Add interfaces with "option proto ahcp" in /etc/config/network
+       # (only for client mode)
+       config_get _loctmp "$cfg" "mode"
+       if [ -z "$_loctmp" -o "$_loctmp" = "client" ]; then
+               for interface in $(uci -P /var/state show network|grep proto=ahcp|cut -d. -f2); do
+                       ahcp_addif $interface
+               done
+       fi
+
+       append_bool "$cfg" 'ipv4_only' '-4'
+       append_bool "$cfg" 'ipv6_only' '-6'
+       append_bool "$cfg" 'no_dns' '-N'
+
+       append_parm "$cfg" 'multicast_address' '-m'
+       append_parm "$cfg" 'port' '-p'
+       append_parm "$cfg" 'lease_time' '-t'
+       append_parm "$cfg" 'debug' '-d'
+       append_parm "$cfg" 'conf_file' '-c'
+       append_parm "$cfg" 'script' '-s'
+}
 
 start() {
        mkdir -p /var/lib
@@ -19,7 +98,7 @@ start() {
 }
 
 stop() {
-       [ -f "$PID_F" ] && kill $(cat "$PID_F")
+       service_kill "ahcpd" "$PID_F"
 }
 
 status() {