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 gateway "$cfg" gateway
53 [ -n "$gateway" ] && append args "-G $gateway"
56 config_get expiry "$cfg" expiry
57 [ -n "$expiry" ] && append args "-t $expiry"
60 config_get retry "$cfg" retry
61 [ -n "$retry" ] && append args "-p $retry"
64 config_get table "$cfg" table
65 [ -n "$table" ] && append args "-T $table"
68 config_get_bool fwd_bcast "$cfg" forward_bcast 1
69 [ $fwd_bcast -eq 1 ] && append args "-B"
72 config_get_bool fwd_dhcp "$cfg" forward_dhcp 1
73 [ $fwd_dhcp -eq 1 ] && append args "-D"
75 start-stop-daemon -b -S -m -p /var/run/$link.pid \
76 -x /usr/sbin/relayd -- $args
78 uci_set_state network "$cfg" device "$ifaces"
80 env -i ACTION="ifup" DEVICE="$link" INTERFACE="$cfg" PROTO="relay" \
81 /sbin/hotplug-call iface
84 stop_interface_relay() {
86 local link="relay-$cfg"
88 env -i ACTION="ifdown" DEVICE="$link" INTERFACE="$cfg" PROTO="relay" \
89 /sbin/hotplug-call iface
91 service_kill relayd "/var/run/$link.pid"