ar71x: use raw squashfs images for TP-Link boards
[openwrt.git] / package / relayd / files / relay.sh
1 # relay.sh - Abstract relayd protocol backend
2 # Copyright (c) 2011 OpenWrt.org
3
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
7 # the configuration.
8 scan_relay() {
9 config_set "$1" device "relay-$1"
10 }
11
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"
16 #}
17
18 setup_interface_relay() {
19 local iface="$1"
20 local cfg="$2"
21 local link="relay-$cfg"
22
23 local args=""
24 local ifaces=""
25
26 resolve_ifname() {
27 grep -qs "^ *$1:" /proc/net/dev && {
28 append args "-I $1"
29 append ifaces "$1"
30 }
31 }
32
33 resolve_network() {
34 local ifn
35 config_get ifn "$1" ifname
36 resolve_ifname "$ifn"
37 }
38
39 local net networks
40 config_get networks "$cfg" network
41 for net in $networks; do
42 resolve_network "$net"
43 done
44
45 local ifn ifnames
46 config_get ifnames "$cfg" ifname
47 for ifn in $ifnames; do
48 resolve_ifname "$ifn"
49 done
50
51 local ipaddr
52 config_get ipaddr "$cfg" ipaddr
53 [ -n "$ipaddr" ] && append args "-L $ipaddr"
54
55 local gateway
56 config_get gateway "$cfg" gateway
57 [ -n "$gateway" ] && append args "-G $gateway"
58
59 local expiry # = 30
60 config_get expiry "$cfg" expiry
61 [ -n "$expiry" ] && append args "-t $expiry"
62
63 local retry # = 5
64 config_get retry "$cfg" retry
65 [ -n "$retry" ] && append args "-p $retry"
66
67 local table # = 16800
68 config_get table "$cfg" table
69 [ -n "$table" ] && append args "-T $table"
70
71 local fwd_bcast # = 1
72 config_get_bool fwd_bcast "$cfg" forward_bcast 1
73 [ $fwd_bcast -eq 1 ] && append args "-B"
74
75 local fwd_dhcp # = 1
76 config_get_bool fwd_dhcp "$cfg" forward_dhcp 1
77 [ $fwd_dhcp -eq 1 ] && append args "-D"
78
79 SERVICE_DAEMONIZE=1 \
80 SERVICE_WRITE_PID=1 \
81 SERVICE_PID_FILE="/var/run/$link.pid" \
82 service_start /usr/sbin/relayd $args
83
84 uci_set_state network "$cfg" device "$ifaces"
85
86 env -i ACTION="ifup" DEVICE="$link" INTERFACE="$cfg" PROTO="relay" \
87 /sbin/hotplug-call iface
88 }
89
90 stop_interface_relay() {
91 local cfg="$1"
92 local link="relay-$cfg"
93
94 env -i ACTION="ifdown" DEVICE="$link" INTERFACE="$cfg" PROTO="relay" \
95 /sbin/hotplug-call iface
96
97 SERVICE_PID_FILE="/var/run/$link.pid" \
98 service_stop /usr/sbin/relayd
99 }
100
This page took 0.04444 seconds and 5 git commands to generate.