packages/vrrpd: use uci config

git-svn-id: svn://svn.openwrt.org/openwrt/packages@29214 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
nico 2011-11-17 10:47:22 +00:00
parent 25a812b377
commit e82916f0a1
4 changed files with 125 additions and 23 deletions

View File

@ -1,5 +1,5 @@
#
# Copyright (C) 2006 OpenWrt.org
# Copyright (C) 2006-2011 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=vrrpd
PKG_VERSION:=1.0
PKG_RELEASE:=1
PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/vrrpd
@ -33,11 +33,7 @@ define Package/vrrpd/description
routers.
endef
define Package/vrrpd/conffiles
/etc/default/vrrpd
endef
define Build/Compile
define Build/Compile
$(call Build/Compile/Default, \
DBG_OPT="" \
MAIN_OPT="$(TARGET_CFLAGS)" \
@ -45,13 +41,17 @@ define Build/Compile
)
endef
define Package/vrrpd/install
define Package/vrrpd/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/vrrpd $(1)/usr/sbin/
$(INSTALL_DIR) $(1)/etc/default
$(INSTALL_DATA) ./files/vrrpd.default $(1)/etc/default/vrrpd
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DATA) ./files/vrrpd.config $(1)/etc/config/vrrpd
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/vrrpd.init $(1)/etc/init.d/vrrpd
endef
define Package/vrrpd/conffiles
/etc/config/vrrpd
endef
$(eval $(call BuildPackage,vrrpd))

View File

@ -0,0 +1,29 @@
package 'vrrpd'
config 'vrrpd' 'vid1'
option enabled 0
# set the interface to run on
# (default: lan)
# option interface 'lan'
# set the ID of the virtual server (1-255)
# (default: 1)
# option virtual_id '1'
# set the IP address(es) of the virtual server
list virtual_ip '192.168.1.253'
# list virtual_ip '192.168.1.252'
# list virtual_ip '192.168.1.251'
# set the priority of this host in the virtual server
# (default: 100)
# option priority '100'
# set the advertisement interval (in seconds)
# (default: 1)
# option delay '1'
# don't handle the virtual MAC address
# (default: false)
# option no_virtual_mac '0'

View File

@ -1,4 +0,0 @@
ID=1
IF=vlan1
IP=10.0.0.1
OPTIONS="-i $IF -v $ID $IP"

View File

@ -1,18 +1,95 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org
# Copyright (C) 2006-2011 OpenWrt.org
START=50
BIN=vrrpd
DEFAULT=/etc/default/$BIN
RUN_D=/var/run
PID_F=$RUN_D/$BIN_${IF}_${ID}.pid
append_list_item() {
local val="$1"
local var="$2"
append "$var" "$val"
}
append_bool() {
local var="$1"
local section="$2"
local option="$3"
local value="$4"
local _val
config_get_bool _val "$section" "$option" 0
[ $_val -gt 0 ] && append "$var" "$value"
}
append_string() {
local var="$1"
local section="$2"
local option="$3"
local val="$4"
local _val
config_get _val "$section" "$option"
[ -n "$_val" ] && append "$var" "$val $_val"
}
config_get_ifname() {
local var="$1"
local section="$2"
local option="$3"
local val="$4"
local _val
config_get _val "$section" "$option" "$val"
config_get "$var" "$_val" 'ifname' "$_val"
}
section_enabled() {
local enabled
config_get_bool enabled "$1" 'enabled' 0
[ $enabled -gt 0 ]
}
start_instance() {
local section="$1"
local id
local if
local args
section_enabled "$section" || return 1
config_get id "$section" 'virtual_id' '1'
config_get_ifname if "$section" 'interface' 'lan'
args="-v $id -i $if"
append_string args "$section" 'delay' '-d'
append_string args "$section" 'priority' '-p'
append_bool args "$section" 'no_virtual_mac' '-n'
config_list_foreach "$section" 'virtual_ip' append_list_item args
SERVICE_PID_FILE="/var/run/vrrpd_${if}_${id}.pid"
service_start /usr/sbin/vrrpd $args
}
stop_instance() {
local section="$1"
local id
local if
section_enabled "$section" || return 1
config_get id "$section" 'virtual_id' '1'
config_get_ifname if "$section" 'interface' 'lan'
SERVICE_PID_FILE="/var/run/vrrpd_${if}_${id}.pid"
service_stop /usr/sbin/vrrpd
}
start() {
[ -f $DEFAULT ] && . $DEFAULT
$BIN $OPTIONS
include /lib/network
scan_interfaces
config_load 'vrrpd'
config_foreach start_instance 'vrrpd'
}
stop() {
[ -f $PID_F ] && kill $(cat $PID_F) >/dev/null 2>&1
include /lib/network
scan_interfaces
config_load 'vrrpd'
config_foreach stop_instance 'vrrpd'
}