1 # relay.sh - Abstract relayd protocol backend
2 # Copyright (c) 2011 OpenWrt.org
4 # Hook into scan_interfaces() to synthesize a .device option
5 # This is needed for /sbin/ifup to properly dispatch control
6 # to setup_interface_relay() even if no .ifname is set in
9 config_set
"$1" device
"relay-$1"
12 # No coldplugging needed, relayd will be restarted if one of
13 # the member interfaces goes up or down
14 #coldplug_interface_relay() {
15 # setup_interface_relay "relay-$1" "$1"
18 setup_interface_relay
() {
21 local link
="relay-$cfg"
27 grep -qs "^ *$1:" /proc
/net
/dev
&& {
35 config_get ifn
"$1" ifname
40 config_get networks
"$cfg" network
41 for net
in $networks; do
42 resolve_network
"$net"
46 config_get ifnames
"$cfg" ifname
47 for ifn
in $ifnames; do
52 config_get ipaddr
"$cfg" ipaddr
53 [ -n "$ipaddr" ] && append args
"-L $ipaddr"
56 config_get gateway
"$cfg" gateway
57 [ -n "$gateway" ] && append args
"-G $gateway"
60 config_get expiry
"$cfg" expiry
61 [ -n "$expiry" ] && append args
"-t $expiry"
64 config_get retry
"$cfg" retry
65 [ -n "$retry" ] && append args
"-p $retry"
68 config_get table
"$cfg" table
69 [ -n "$table" ] && append args
"-T $table"
72 config_get_bool fwd_bcast
"$cfg" forward_bcast
1
73 [ $fwd_bcast -eq 1 ] && append args
"-B"
76 config_get_bool fwd_dhcp
"$cfg" forward_dhcp
1
77 [ $fwd_dhcp -eq 1 ] && append args
"-D"
79 start-stop-daemon
-b -S -m -p /var
/run
/$link.pid \
80 -x /usr
/sbin
/relayd
-- $args
82 uci_set_state network
"$cfg" device
"$ifaces"
84 env
-i ACTION
="ifup" DEVICE
="$link" INTERFACE
="$cfg" PROTO
="relay" \
85 /sbin
/hotplug-call iface
88 stop_interface_relay
() {
90 local link
="relay-$cfg"
92 env
-i ACTION
="ifdown" DEVICE
="$link" INTERFACE
="$cfg" PROTO
="relay" \
93 /sbin
/hotplug-call iface
95 service_kill relayd
"/var/run/$link.pid"