2012-04-30 18:23:52 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
|
|
|
# Copyright (c) 2011-2012 OpenWrt.org
|
|
|
|
START=80
|
|
|
|
|
2013-09-17 21:45:30 +00:00
|
|
|
USE_PROCD=1
|
|
|
|
PROG=/usr/sbin/relayd
|
|
|
|
|
2012-04-30 18:23:52 +00:00
|
|
|
resolve_ifname() {
|
|
|
|
grep -qs "^ *$1:" /proc/net/dev && {
|
2013-09-17 21:45:30 +00:00
|
|
|
procd_append_param command -I "$1"
|
2012-04-30 18:23:52 +00:00
|
|
|
append ifaces "$1"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resolve_network() {
|
|
|
|
local ifn
|
2012-04-30 18:27:12 +00:00
|
|
|
fixup_interface "$1"
|
2012-04-30 18:23:52 +00:00
|
|
|
config_get ifn "$1" ifname
|
|
|
|
[ -z "$ifn" ] && return 1
|
|
|
|
resolve_ifname "$ifn"
|
|
|
|
}
|
|
|
|
|
|
|
|
start_relay() {
|
|
|
|
local cfg="$1"
|
|
|
|
|
|
|
|
local args=""
|
|
|
|
local ifaces=""
|
|
|
|
|
|
|
|
config_get proto "$cfg" proto
|
|
|
|
[[ "$proto" == relay ]] || return 0
|
|
|
|
|
|
|
|
SERVICE_DAEMONIZE=1
|
|
|
|
SERVICE_WRITE_PID=1
|
|
|
|
SERVICE_PID_FILE="/var/run/relay-$cfg.pid"
|
|
|
|
[ -f "$SERVICE_PID_FILE" ] && {
|
|
|
|
if grep -q relayd "/proc/$(cat $SERVICE_PID_FILE)/cmdline"; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
rm -f "$SERVICE_PID_FILE"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-09-17 21:45:30 +00:00
|
|
|
procd_open_instance
|
|
|
|
procd_set_param command "$PROG"
|
|
|
|
|
2012-04-30 18:23:52 +00:00
|
|
|
local net networks
|
|
|
|
config_get networks "$cfg" network
|
|
|
|
for net in $networks; do
|
|
|
|
resolve_network "$net" || {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
done
|
|
|
|
|
|
|
|
local ifn ifnames
|
|
|
|
config_get ifnames "$cfg" ifname
|
|
|
|
for ifn in $ifnames; do
|
|
|
|
resolve_ifname "$ifn"
|
|
|
|
done
|
|
|
|
|
|
|
|
local ipaddr
|
|
|
|
config_get ipaddr "$cfg" ipaddr
|
2013-09-17 21:45:30 +00:00
|
|
|
[ -n "$ipaddr" ] && procd_append_param command -L "$ipaddr"
|
2012-04-30 18:23:52 +00:00
|
|
|
|
|
|
|
local gateway
|
|
|
|
config_get gateway "$cfg" gateway
|
2013-09-17 21:45:30 +00:00
|
|
|
[ -n "$gateway" ] && procd_append_param command -G "$gateway"
|
2012-04-30 18:23:52 +00:00
|
|
|
|
|
|
|
local expiry # = 30
|
|
|
|
config_get expiry "$cfg" expiry
|
2013-09-17 21:45:30 +00:00
|
|
|
[ -n "$expiry" ] && procd_append_param command "$expiry"
|
2012-04-30 18:23:52 +00:00
|
|
|
|
|
|
|
local retry # = 5
|
|
|
|
config_get retry "$cfg" retry
|
2013-09-17 21:45:30 +00:00
|
|
|
[ -n "$retry" ] && procd_append_param command -p "$retry"
|
2012-04-30 18:23:52 +00:00
|
|
|
|
|
|
|
local table # = 16800
|
|
|
|
config_get table "$cfg" table
|
2013-09-17 21:45:30 +00:00
|
|
|
[ -n "$table" ] && procd_append_param command -T "$table"
|
2012-04-30 18:23:52 +00:00
|
|
|
|
|
|
|
local fwd_bcast # = 1
|
|
|
|
config_get_bool fwd_bcast "$cfg" forward_bcast 1
|
2013-09-17 21:45:30 +00:00
|
|
|
[ $fwd_bcast -eq 1 ] && procd_append_param command "-B"
|
2012-04-30 18:23:52 +00:00
|
|
|
|
|
|
|
local fwd_dhcp # = 1
|
|
|
|
config_get_bool fwd_dhcp "$cfg" forward_dhcp 1
|
2013-09-17 21:45:30 +00:00
|
|
|
[ $fwd_dhcp -eq 1 ] && procd_append_param command"-D"
|
2012-04-30 18:23:52 +00:00
|
|
|
|
2013-09-17 21:45:30 +00:00
|
|
|
procd_close_instance
|
2012-04-30 18:23:52 +00:00
|
|
|
}
|
|
|
|
|
2013-09-17 21:45:30 +00:00
|
|
|
service_triggers()
|
|
|
|
{
|
|
|
|
procd_add_reload_trigger "network"
|
2012-04-30 18:23:52 +00:00
|
|
|
}
|
|
|
|
|
2013-09-17 21:45:30 +00:00
|
|
|
start_service() {
|
2012-04-30 18:23:52 +00:00
|
|
|
include /lib/network
|
2012-04-30 18:24:00 +00:00
|
|
|
config_load network
|
2012-04-30 18:23:52 +00:00
|
|
|
config_foreach start_relay interface
|
|
|
|
}
|