OpenWrt – Diff between revs 2 and 3

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 2 Rev 3
Line 1... Line 1...
1 #!/bin/sh /etc/rc.common 1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2018 OpenWrt.org 2 # Copyright (C) 2010-2014 OpenWrt.org
Line 3... Line 3...
3   3  
4 START=99 4 START=99
5 USE_PROCD=1 5 USE_PROCD=1
Line 6... Line 6...
6 PROG=/usr/sbin/omcproxy 6 PROG=/usr/sbin/omcproxy
7   7  
8 # Uncomment to enable verbosity 8 # Uncomment to enable verbosity
Line 9... Line -...
9 #OPTIONS="-v" -  
10 PROXIES="" -  
Line -... Line 9...
-   9 #OPTIONS="-v"
-   10 PROXIES=""
11   11  
-   12  
-   13 omcproxy_add_proxy() {
-   14 local uplink downlink scope proxy
-   15 config_get uplink $1 uplink
-   16 config_get downlink $1 downlink
-   17 config_get scope $1 scope
12 omcproxy_add_proxy() { 18  
Line 13... Line -...
13 local proxy scope uplink updevice downlinks -  
14   -  
15 config_get uplink $1 uplink -  
16 [ -n "$uplink" ] || return -  
17   -  
18 network_get_device updevice "$uplink" || { -  
19 procd_append_param error "$uplink is not up" 19 proxy=""
20 return; -  
21 } -  
22   20  
23 config_get downlinks $1 downlink -  
24 for downlink in $downlinks; do -  
25 local device -  
26   -  
27 network_get_device device "$downlink" || { 21 network_get_device updev $uplink
28 procd_append_param error "$downlink is not up" 22 [ -n "$updev" ] || return 0
29 continue; 23  
30 } 24 for network in $downlink; do
31   25 network_get_device downdev $network
32 proxy="$proxy,$device" 26 [ -n "$downdev" ] && proxy="$proxy,$downdev"
Line 33... Line 27...
33   27  
34 # Disable in-kernel querier while ours is active, default is 1. -  
35 [ -f /sys/class/net/$device/bridge/multicast_querier ] && \ -  
36 echo 0 > /sys/class/net/$device/bridge/multicast_querier 28 # Disable in-kernel querier while ours is active
Line 37... Line 29...
37 done 29 [ -f /sys/class/net/$downdev/bridge/multicast_querier ] && \
38   -  
Line 39... Line -...
39 [ -n "$proxy" ] || return 0 -  
40   -  
-   30 echo 0 > /sys/class/net/$downdev/bridge/multicast_querier
Line -... Line 31...
-   31 done
-   32  
41 config_get scope $1 scope 33 [ -n "$proxy" ] || return 0
42 [ -n "$scope" ] && proxy="$proxy,scope=$scope" 34 [ -n "$scope" ] && proxy="$proxy,scope=$scope"
Line 43... Line 35...
43   35  
44 PROXIES="$PROXIES $updevice$proxy" -  
45 } -  
46   -  
47 omcproxy_add_network_triggers() { -  
48 local uplink downlinks -  
49   -  
50 config_get uplink $1 uplink -  
51 config_get downlinks $1 downlink -  
52   36 PROXIES="$PROXIES $updev$proxy"
53 for link in $uplink $downlinks; do -  
54 local duplicate=0 37  
55   38 }
Line 56... Line 39...
56 for l in $LINKS; do 39  
57 [ "$l" = "$link" ] && duplicate=1 -  
58 done -  
59   40 omcproxy_add_trigger() {
60 [ "$duplicate" = 0 ] && { 41 local uplink downlink
Line 61... Line 42...
61 LINKS="$LINKS $link" 42 config_get uplink $1 uplink
62 procd_add_interface_trigger "interface.*" $link /etc/init.d/omcproxy restart 43 config_get downlink $1 downlink
Line 63... Line 44...
63 } 44  
64 done 45 for network in $uplink $downlink; do
65 } 46 procd_add_interface_trigger "interface.*" $network /etc/init.d/omcproxy restart
66   -  
67 omcproxy_add_firewall_rules() { 47 done
68 local uplink downlinks 48 }
69   49  
Line 70... Line 50...
70 config_get uplink $1 uplink 50 omcproxy_add_firewall() {
Line 94... Line 74...
94 json_add_string "" 143/0 74 json_add_string "" 143/0
95 json_close_array 75 json_close_array
96 json_add_string target ACCEPT 76 json_add_string target ACCEPT
97 json_close_object 77 json_close_object
Line 98... Line 78...
98   78  
99 for downlink in $downlinks; do 79 for network in $downlink; do
100 downzone=$(fw3 -q network $downlink 2>/dev/null) 80 downzone=$(fw3 -q network $network 2>/dev/null)
Line 101... Line 81...
101 [ -n "$downzone" ] || continue 81 [ -n "$downzone" ] || continue
102   82  
103 json_add_object "" 83 json_add_object ""
104 json_add_string type rule 84 json_add_string type rule
105 json_add_string src "$upzone" 85 json_add_string src "$upzone"
106 json_add_string dest "$downzone" 86 json_add_string dest "$downzone"
107 json_add_string family ipv4 87 json_add_string family ipv4
108 json_add_string proto udp 88 json_add_string proto any
109 json_add_string dest_ip "224.0.0.0/4" 89 json_add_string dest_ip "224.0.0.0/4"
Line 110... Line 90...
110 json_add_string target ACCEPT 90 json_add_string target ACCEPT
111 json_close_object 91 json_close_object
112   92  
113 json_add_object "" 93 json_add_object ""
114 json_add_string type rule 94 json_add_string type rule
115 json_add_string src "$upzone" 95 json_add_string src "$upzone"
116 json_add_string dest "$downzone" 96 json_add_string dest "$downzone"
117 json_add_string family ipv6 97 json_add_string family ipv6
118 json_add_string proto udp 98 json_add_string proto any
119 json_add_string dest_ip "ff00::/8" 99 json_add_string dest_ip "ff00::/8"
120 json_add_string target ACCEPT 100 json_add_string target ACCEPT
Line 121... Line 101...
121 json_close_object 101 json_close_object
122 done -  
123 } -  
124   102 done
125 service_triggers() { -  
126 LINKS="" 103 }
Line 127... Line 104...
127   104  
128 procd_add_reload_trigger "omcproxy" 105 service_triggers() {
Line 129... Line 106...
129 config_foreach omcproxy_add_network_triggers proxy 106 procd_add_reload_trigger "omcproxy"
130 } -  
131   107 }
-   108  
132 start_service() { 109 start_service() {
Line 133... Line 110...
133 . /lib/functions/network.sh 110 include /lib/functions
134   111  
135 config_load omcproxy 112 config_load omcproxy
136   113 config_foreach omcproxy_add_proxy proxy
137 config_foreach omcproxy_add_proxy proxy 114  
Line -... Line 115...
-   115 [ -n "$PROXIES" ] || return 0
-   116  
-   117 procd_open_instance
-   118 procd_set_param command $PROG
138 [ -n "$PROXIES" ] || return 0 119 [ -n "$OPTIONS" ] && procd_append_param command $OPTIONS
Line 139... Line 120...
139   120 procd_append_param command $PROXIES
140 procd_open_instance 121 procd_set_param respawn
141 procd_set_param command $PROG 122  
Line 142... Line 123...
142 [ -n "$OPTIONS" ] && procd_append_param command $OPTIONS 123 procd_open_trigger
Line 143... Line 124...
143 procd_append_param command $PROXIES 124 config_foreach omcproxy_add_trigger proxy
Line 144... Line 125...
144 procd_set_param respawn 125 procd_close_trigger
145   126  
146 procd_open_data 127 procd_open_data
Line 147... Line 128...
147   128  
148 json_add_array firewall 129 json_add_array firewall
149 config_foreach omcproxy_add_firewall_rules proxy 130 config_foreach omcproxy_add_firewall proxy
150 json_close_array -  
151   -  
152 procd_close_data -  
153   -