Opennet Firmware
 Alle Dateien Funktionen Variablen Gruppen Seiten
on-configure-network
gehe zur Dokumentation dieser Datei
1 #!/bin/sh
2 #
3 # Konfiguriere uebliche Opennet-Interfaces sowie ein lokales Interface.
4 #
5 # Dieses Skript wird nur ein einziges Mal nach einem Upgrade oder der Erstinstallation ausgefuehrt:
6 # http://wiki.openwrt.org/doc/uci#defaults
7 #
8 
9 
10 . "${IPKG_INSTROOT:-}/usr/lib/opennet/on-helper.sh"
11 
12 
13 configure_local_network() {
14  local uci_prefix=network.lan
15  local flag_uci_key=on-core.settings.default_ip_configured
16  prepare_on_uci_settings
17  # das Netzwerk wurde bereits konfiguriert
18  [ -n "$(uci_get "$flag_uci_key")" ] && return 0
19  uci set "${uci_prefix}.ipaddr=$(get_on_core_default lan_ipaddr)"
20  uci set "${uci_prefix}.netmask=$(get_on_core_default lan_netmask)"
21  apply_changes network
22  # diese Aktion soll nur ein einziges Mal stattfinden
23  uci set "$flag_uci_key=1"
24  uci commit on-core
25 }
26 
27 
28 configure_opennet_zone() {
29  local uci_prefix=$(find_first_uci_section firewall zone "name=$ZONE_MESH")
30  # Zone existiert? Keine Aenderungen ...
31  [ -n "$uci_prefix" ] && return 0
32  uci_prefix=firewall.$(uci add firewall zone)
33  uci set "$uci_prefix=zone"
34  uci set "$uci_prefix.name=$ZONE_MESH"
35  # Opennet-APs bieten ueblicherweise keine privaten Dienste an
36  uci set "$uci_prefix.input=ACCEPT"
37  # ausgehende Pakete sind OK
38  uci set "$uci_prefix.output=ACCEPT"
39  # Verkehr aus dem opennet-Netz darf nicht in lokale oder tunnel-Netze
40  uci set "$uci_prefix.forward=REJECT"
41  # via "masq_src" ersetzen wir die ehemalige "/etc/firewall.opennet" fuer Quell-basiertes Masquerading
42  add_zone_forward "$ZONE_LOCAL" "$ZONE_MESH"
43  update_opennet_zone_masquerading
44  # intra-Zone-Verkehr muss explizit erlaubt werden
45  add_zone_forward "$ZONE_MESH" "$ZONE_MESH"
46 }
47 
48 
49 configure_olsr_radio() {
50  trap "error_trap configure_olsr_radio '$*'" $GUARD_TRAPS
51  local iface_index=$1
52  local iface_logical=$2
53  local iface_phys=$3
54 
55  local uci_wifi=wireless.@wifi-iface[$iface_index]
56  local uci_radio=wireless.$(uci_get "${uci_wifi}.device")
57  local radio_hwmode=$(uci_get "${uci_radio}.hwmode")
58  local bssid=$(get_on_core_default wifi_bssid)
59 
60  uci set "${uci_wifi}.network=$iface_logical"
61  uci set "${uci_wifi}.ifname=$iface_phys"
62 
63  uci set "wireless.radio${iface_index}.country=$(get_on_core_default wifi_country)"
64  uci_delete "wireless.radio${iface_index}.disabled"
65 
66  # typ-spezifische Attribute
67  if echo "$radio_hwmode" | grep -q "a"; then
68  # 5 GHz: kein Mesh-Modus verfuegbar
69  uci set "${uci_wifi}.ssid=$(get_on_core_default wifi_ssid_5ghz)"
70  uci set "${uci_wifi}.mode=$(get_on_core_default wifi_mode_5ghz)"
71  uci set "${uci_radio}.channel=$(get_on_core_default wifi_channel_5ghz)"
72  uci set "${uci_wifi}.isolate=1"
73  else
74  # 2,4 GHz: Ad-hoc-Modus
75  uci set "${uci_wifi}.ssid=$(get_on_core_default wifi_ssid)"
76  uci set "${uci_wifi}.mode=$(get_on_core_default wifi_mode)"
77  [ -n "$bssid" ] && uci set "${uci_wifi}.bssid=$bssid"
78  uci set "${uci_radio}.channel=$(get_on_core_default wifi_channel)"
79  fi
80  return
81 }
82 
83 
84 configure_olsr_single_interface() {
85  trap "error_trap configure_olsr_single_interface '$*'" $GUARD_TRAPS
86  local iface_logical=$1
87  local iface_addr=$2
88  local iface_netmask=$3
89  local iface_phys=$4
90 
91  # configure on_wifi
92  uci set "network.${iface_logical}=interface"
93  uci set "network.${iface_logical}.proto=static"
94  uci set "network.${iface_logical}.ifname=$iface_phys"
95  uci set "network.${iface_logical}.netmask=$iface_netmask"
96  uci set "network.${iface_logical}.defaultroute=0"
97  uci set "network.${iface_logical}.peerdns=0"
98  uci set "network.${iface_logical}.ipaddr=$iface_addr"
99 
100  # disable dhcp on on_wifi
101  uci set "dhcp.${iface_logical}=dhcp"
102  uci set "dhcp.${iface_logical}.interface=${iface_logical}"
103  uci set "dhcp.${iface_logical}.dynamicdhcp=0"
104  uci set "dhcp.${iface_logical}.ignore=1"
105 }
106 
107 
108 configure_olsr_interfaces() {
109  trap "error_trap configure_olsr_interfaces '$*'" $GUARD_TRAPS
110 
111  # diese Aktion ist bereits abgeschlossen
112  uci show network | grep -q "^network\.on_eth_0\." && return 0
113 
114  local on_id=$(uci_get on-core.settings.on_id "$(get_on_core_default on_id_preset)")
115  local on_ipschema=$(get_on_core_default on_ipschema)
116  local on_netmask=$(get_on_core_default on_netmask)
117  local on_ipaddr
118  local iface_phys
119  local iface_logical
120 
121  # Suche nach WLAN-Interfaces
122  /sbin/wifi detect > /etc/config/wireless
123 
124  iface_index=0
125  while [ -n "$(uci_get "wireless.@wifi-iface[${iface_index}]")" ]; do
126  on_ipaddr=$(get_on_ip "$on_id" "$on_ipschema" "$iface_index")
127  iface_phys=wlan$iface_index
128  iface_logical=on_wifi_$iface_index
129 
130  configure_olsr_single_interface "$iface_logical" "$on_ipaddr" "$on_netmask" "$iface_phys"
131  configure_olsr_radio "$iface_index" "$iface_logical" "$iface_phys"
132 
133  add_interface_to_zone "$ZONE_MESH" "$iface_logical"
134 
135  : $((iface_index++))
136  done
137 
138  on_ipaddr=$(get_on_ip "$on_id" "$on_ipschema" "$iface_index")
139  iface_phys=none
140  iface_logical=on_eth_0
141  configure_olsr_single_interface "$iface_logical" "$on_ipaddr" "$on_netmask" "$iface_phys"
142  add_interface_to_zone "$ZONE_MESH" "$iface_logical"
143 }
144 
145 
146 # jede Funktion sollte selbst pruefen, ob ihre Aktion bereits abgeschlossen ist
147 configure_local_network
148 configure_opennet_zone
149 configure_olsr_interfaces
150 
151 # schreibe alle ui-Anederungen
152 uci commit network
153 uci commit wireless
154 uci commit dhcp
155 uci commit firewall
156 # loese via procd alle erforderlichen Dienste-Reloads aus
157 # Fehler duerfen hier passieren
158 reload_config || true
159 
160 exit 0
161