(no commit message)
[project/luci.git] / module / admin-core / contrib / init.d / luci_freifunk
1 #!/bin/sh /etc/rc.common
2 START=70
3
4 start() {
5 include /lib/network
6 scan_interfaces
7
8
9 ### Read interface names
10 config_get wanif wan ifname
11 config_get lanif lan ifname
12 config_get ffif ff ifname
13 config_get ffdif ffdhcp ifname
14
15 config_get lanip lan ipaddr
16 config_get lanmask lan netmask
17
18 config_get ffip ff ipaddr
19 config_get ffmask ff netmask
20
21 config_get ffdip ffdhcp ipaddr
22 config_get ffdmask ffdhcp netmask
23
24 [ -n "$ffif" ] || return 0
25
26
27 ### Creating chains
28 iptables -N luci_freifunk_forwarding
29 iptables -t nat -N luci_freifunk_postrouting
30
31
32 ### Read from config
33 config_load freifunk
34
35 config_get_bool internal routing internal
36 [ -n "$wanif" ] && config_get_bool internet routing internet
37
38
39 ### Freifunk to Freifunk
40 [ "$internal" -gt 0 ] && {
41 iptables -A luci_freifunk_forwarding -i "$ffif" -o "$ffif" -j ACCEPT
42 }
43
44 ### Freifunk DHCP to Freifunk
45 [ "$internal" -gt 0 -a -n "$ffdif" ] && {
46 eval "$(ipcalc.sh $ffdip $ffdmask)"
47
48 iptables -t nat -A luci_freifunk_postrouting -s "$NETWORK/$PREFIX" -o "$ffif" -j MASQUERADE
49 }
50
51 ### Lan to Freifunk
52 [ -n "$lanif" ] && {
53 eval "$(ipcalc.sh $lanip $lanmask)"
54
55 iptables -A luci_freifunk_forwarding -i "$lanif" -o "$ffif" -j ACCEPT
56 iptables -t nat -A luci_freifunk_postrouting -s "$NETWORK/$PREFIX" -o "$ffif" -j MASQUERADE
57 }
58
59 ### Freifunk to Wan
60 [ "$internet" -gt 0 ] && {
61 eval "$(ipcalc.sh $ffip $ffmask)"
62
63 iptables -A luci_freifunk_forwarding -i "$ffif" -o "$wanif" -j ACCEPT
64 iptables -t nat -A luci_freifunk_postrouting -s "$NETWORK/$PREFIX" -o "$wanif" -j MASQUERADE
65 }
66
67 ### Freifunk DHCP to Wan
68 [ "$internet" -gt 0 -a -n "$ffdif" ] && {
69 eval "$(ipcalc.sh $ffdip $ffdmask)"
70
71 iptables -t nat -A luci_freifunk_postrouting -s "$NETWORK/$PREFIX" -o "$wanif" -j MASQUERADE
72 }
73
74 ### Hook in the chains
75 iptables -A forwarding_rule -j luci_freifunk_forwarding
76 iptables -t nat -A postrouting_rule -j luci_freifunk_postrouting
77 }
78
79 stop() {
80 ### Hook out the chains
81 iptables -D forwarding_rule -j luci_freifunk_forwarding
82 iptables -t nat -D postrouting_rule -j luci_freifunk_postrouting
83
84 ### Clear the chains
85 iptables -F luci_freifunk_forwarding
86 iptables -t nat -F luci_freifunk_postrouting
87
88 ### Delete chains
89 iptables -X luci_freifunk_forwarding
90 iptables -t nat -X luci_freifunk_postrouting
91 }