relayd: add uci integration
SVN-Revision: 25714
This commit is contained in:
parent
73468de8d1
commit
c16efad428
3 changed files with 134 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (C) 2010 OpenWrt.org
|
||||
# Copyright (C) 2010-2011 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
|
@ -32,6 +32,10 @@ TARGET_CFLAGS += -I$(STAGING_DIR)/usr/include
|
|||
define Package/relayd/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/relayd $(1)/usr/sbin/relayd
|
||||
$(INSTALL_DIR) $(1)/etc/hotplug.d/iface
|
||||
$(INSTALL_DATA) ./files/relay.hotplug $(1)/etc/hotplug.d/iface/30-relay
|
||||
$(INSTALL_DIR) $(1)/lib/network
|
||||
$(INSTALL_DATA) ./files/relay.sh $(1)/lib/network/relay.sh
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,relayd))
|
||||
|
|
36
package/relayd/files/relay.hotplug
Normal file
36
package/relayd/files/relay.hotplug
Normal file
|
@ -0,0 +1,36 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Break recursion
|
||||
[ "$PROTO" = "relay" ] && exit 0
|
||||
|
||||
include /lib/network
|
||||
scan_interfaces
|
||||
|
||||
restart_relayd() {
|
||||
local cfg="$1"
|
||||
|
||||
local proto
|
||||
config_get proto "$1" proto
|
||||
[ "$proto" = "relay" ] || return 0
|
||||
|
||||
local net networks
|
||||
config_get networks "$cfg" network
|
||||
for net in $networks; do
|
||||
[ "$net" = "$INTERFACE" ] && {
|
||||
env -i /sbin/ifup "$cfg" &
|
||||
return 0
|
||||
}
|
||||
done
|
||||
|
||||
local ifn ifnames
|
||||
config_get ifnames "$cfg" ifname
|
||||
for ifn in $ifnames; do
|
||||
[ "$ifn" = "$DEVICE" ] && {
|
||||
env -i /sbin/ifup "$cfg" &
|
||||
return 0
|
||||
}
|
||||
done
|
||||
}
|
||||
|
||||
config_foreach restart_relayd interface
|
||||
|
93
package/relayd/files/relay.sh
Normal file
93
package/relayd/files/relay.sh
Normal file
|
@ -0,0 +1,93 @@
|
|||
# relay.sh - Abstract relayd protocol backend
|
||||
# Copyright (c) 2011 OpenWrt.org
|
||||
|
||||
# Hook into scan_interfaces() to synthesize a .device option
|
||||
# This is needed for /sbin/ifup to properly dispatch control
|
||||
# to setup_interface_relay() even if no .ifname is set in
|
||||
# the configuration.
|
||||
scan_relay() {
|
||||
config_set "$1" device "relay-$1"
|
||||
}
|
||||
|
||||
# No coldplugging needed, relayd will be restarted if one of
|
||||
# the member interfaces goes up or down
|
||||
#coldplug_interface_relay() {
|
||||
# setup_interface_relay "relay-$1" "$1"
|
||||
#}
|
||||
|
||||
setup_interface_relay() {
|
||||
local iface="$1"
|
||||
local cfg="$2"
|
||||
local link="relay-$cfg"
|
||||
|
||||
local args=""
|
||||
local ifaces=""
|
||||
|
||||
resolve_ifname() {
|
||||
grep -qs "^ *$1:" /proc/net/dev && {
|
||||
append args "-I $1"
|
||||
append ifaces "$1"
|
||||
}
|
||||
}
|
||||
|
||||
resolve_network() {
|
||||
local ifn
|
||||
config_get ifn "$1" ifname
|
||||
resolve_ifname "$ifn"
|
||||
}
|
||||
|
||||
local net networks
|
||||
config_get networks "$cfg" network
|
||||
for net in $networks; do
|
||||
resolve_network "$net"
|
||||
done
|
||||
|
||||
local ifn ifnames
|
||||
config_get ifnames "$cfg" ifname
|
||||
for ifn in $ifnames; do
|
||||
resolve_ifname "$ifn"
|
||||
done
|
||||
|
||||
local gateway
|
||||
config_get gateway "$cfg" gateway
|
||||
[ -n "$gateway" ] && append args "-G $gateway"
|
||||
|
||||
local expiry # = 30
|
||||
config_get expiry "$cfg" expiry
|
||||
[ -n "$expiry" ] && append args "-t $expiry"
|
||||
|
||||
local retry # = 5
|
||||
config_get retry "$cfg" retry
|
||||
[ -n "$retry" ] && append args "-p $retry"
|
||||
|
||||
local table # = 16800
|
||||
config_get table "$cfg" table
|
||||
[ -n "$table" ] && append args "-T $table"
|
||||
|
||||
local fwd_bcast # = 1
|
||||
config_get_bool fwd_bcast "$cfg" forward_bcast 1
|
||||
[ $fwd_bcast -eq 1 ] && append args "-B"
|
||||
|
||||
local fwd_dhcp # = 1
|
||||
config_get_bool fwd_dhcp "$cfg" forward_dhcp 1
|
||||
[ $fwd_dhcp -eq 1 ] && append args "-D"
|
||||
|
||||
start-stop-daemon -b -S -m -p /var/run/$link.pid \
|
||||
-x /usr/sbin/relayd -- $args
|
||||
|
||||
uci_set_state network "$cfg" device "$ifaces"
|
||||
|
||||
env -i ACTION="ifup" DEVICE="$link" INTERFACE="$cfg" PROTO="relay" \
|
||||
/sbin/hotplug-call iface
|
||||
}
|
||||
|
||||
stop_interface_relay() {
|
||||
local cfg="$1"
|
||||
local link="relay-$cfg"
|
||||
|
||||
env -i ACTION="ifdown" DEVICE="$link" INTERFACE="$cfg" PROTO="relay" \
|
||||
/sbin/hotplug-call iface
|
||||
|
||||
service_kill relayd "/var/run/$link.pid"
|
||||
}
|
||||
|
Loading…
Reference in a new issue