relayd: remove old start-stop-service related code
[openwrt/staging/lynxis/omap.git] / package / network / services / relayd / files / relay.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (c) 2011-2012 OpenWrt.org
3
4 START=80
5
6 USE_PROCD=1
7 PROG=/usr/sbin/relayd
8
9 validate_proto_relayd()
10 {
11 uci_validate_section network "interface" "${1}" \
12 'network:list(string)' \
13 'expiry:uinteger:30' \
14 'retry:uinteger:5' \
15 'table:range(0, 65535):16800' \
16 'forward_bcast:bool:1' \
17 'forward_dhcp:bool:1'
18 }
19
20 resolve_ifname() {
21 grep -qs "^ *$1:" /proc/net/dev && {
22 procd_append_param command -I "$1"
23 procd_append_param netdev "$1"
24 }
25 }
26
27 resolve_network() {
28 local ifn
29 fixup_interface "$1"
30 config_get ifn "$1" ifname
31 [ -z "$ifn" ] && return 1
32 resolve_ifname "$ifn"
33 }
34
35 start_relay() {
36 local cfg="$1"
37
38 config_get proto "$cfg" proto
39 [ "$proto" = "relay" ] || return 0
40
41 config_get_bool disabled "$cfg" disabled 0
42 [ "$disabled" -gt 0 ] && return 0
43
44 procd_open_instance
45 procd_set_param command "$PROG"
46
47 local net networks
48 config_get networks "$cfg" network
49 for net in $networks; do
50 resolve_network "$net" || {
51 return 1
52 }
53 done
54
55 local ifn ifnames
56 config_get ifnames "$cfg" ifname
57 for ifn in $ifnames; do
58 resolve_ifname "$ifn"
59 done
60
61 local ipaddr
62 config_get ipaddr "$cfg" ipaddr
63 [ -n "$ipaddr" ] && procd_append_param command -L "$ipaddr"
64
65 local gateway
66 config_get gateway "$cfg" gateway
67 [ -n "$gateway" ] && procd_append_param command -G "$gateway"
68
69 local expiry # = 30
70 config_get expiry "$cfg" expiry
71 [ -n "$expiry" ] && procd_append_param command -t "$expiry"
72
73 local retry # = 5
74 config_get retry "$cfg" retry
75 [ -n "$retry" ] && procd_append_param command -p "$retry"
76
77 local table # = 16800
78 config_get table "$cfg" table
79 [ -n "$table" ] && procd_append_param command -T "$table"
80
81 local fwd_bcast # = 1
82 config_get_bool fwd_bcast "$cfg" forward_bcast 1
83 [ $fwd_bcast -eq 1 ] && procd_append_param command "-B"
84
85 local fwd_dhcp # = 1
86 config_get_bool fwd_dhcp "$cfg" forward_dhcp 1
87 [ $fwd_dhcp -eq 1 ] && procd_append_param command "-D"
88
89 procd_close_instance
90 }
91
92 service_triggers()
93 {
94 procd_add_reload_trigger "network"
95 procd_add_raw_trigger "interface.*" 2000 /etc/init.d/relayd reload
96 }
97
98 start_service() {
99 include /lib/network
100 config_load network
101 config_foreach start_relay interface
102 }