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 OPENWRT_DEFAULT_LOCAL_IP=192.168.1.1
14 
15 
16 configure_local_network() {
17  local uci_prefix="network.$NETWORK_LOCAL"
18  # wurde die Standard-IP bereits veraendert?
19  [ "$(uci_get "${uci_prefix}.ipaddr")" != "$OPENWRT_DEFAULT_LOCAL_IP" ] && return 0
20  uci set "${uci_prefix}.ipaddr=$(get_on_core_default lan_ipaddr)"
21  uci set "${uci_prefix}.netmask=$(get_on_core_default lan_netmask)"
22 }
23 
24 
25 configure_opennet_zone() {
26  local uci_prefix
27  # Forwarding (die letzte Aktion dieses Ablaufs) existiert? Keine Aenderungen ...
28  [ -n "$(find_first_uci_section "firewall" "forwarding" "src=$ZONE_MESH" "dest=$ZONE_MESH")" ] && return 0
29  uci_prefix=$(find_first_uci_section "firewall" "zone" "name=$ZONE_MESH")
30  # Zone anlegen, falls leer
31  [ -z "$uci_prefix" ] && uci_prefix=firewall.$(uci add firewall zone)
32  uci set "$uci_prefix=zone"
33  uci set "$uci_prefix.name=$ZONE_MESH"
34  # Opennet-APs bieten ueblicherweise keine privaten Dienste an
35  uci set "$uci_prefix.input=ACCEPT"
36  # ausgehende Pakete sind OK
37  uci set "$uci_prefix.output=ACCEPT"
38  # Verkehr aus dem opennet-Netz darf nicht in lokale oder tunnel-Netze
39  uci set "$uci_prefix.forward=REJECT"
40  # via "masq_src" ersetzen wir die ehemalige "/etc/firewall.opennet" fuer Quell-basiertes Masquerading
41  add_zone_forward "$ZONE_LOCAL" "$ZONE_MESH"
42  update_opennet_zone_masquerading
43  # intra-Zone-Verkehr muss explizit erlaubt werden
44  add_zone_forward "$ZONE_MESH" "$ZONE_MESH"
45 }
46 
47 
48 configure_olsr_radio() {
49  trap "error_trap configure_olsr_radio '$*'" $GUARD_TRAPS
50  local iface_index=$1
51  local iface_logical=$2
52  local iface_phys=$3
53 
54  local uci_wifi=wireless.@wifi-iface[$iface_index]
55  local uci_radio=wireless.$(uci_get "${uci_wifi}.device")
56  local radio_hwmode
57  local bssid
58  radio_hwmode=$(uci_get "${uci_radio}.hwmode")
59  bssid=$(get_on_core_default wifi_bssid)
60 
61  uci set "${uci_wifi}.network=$iface_logical"
62  uci set "${uci_wifi}.ifname=$iface_phys"
63 
64  uci set "wireless.radio${iface_index}.country=$(get_on_core_default wifi_country)"
65  uci_delete "wireless.radio${iface_index}.disabled"
66 
67  # typ-spezifische Attribute
68  if echo "$radio_hwmode" | grep -q "a"; then
69  # 5 GHz: kein Mesh-Modus verfuegbar
70  uci set "${uci_wifi}.ssid=$(get_on_core_default wifi_ssid_5ghz)"
71  uci set "${uci_wifi}.mode=$(get_on_core_default wifi_mode_5ghz)"
72  uci set "${uci_radio}.channel=$(get_on_core_default wifi_channel_5ghz)"
73  uci set "${uci_wifi}.isolate=1"
74  else
75  # 2,4 GHz: Ad-hoc-Modus
76  uci set "${uci_wifi}.ssid=$(get_on_core_default wifi_ssid)"
77  uci set "${uci_wifi}.mode=$(get_on_core_default wifi_mode)"
78  [ -n "$bssid" ] && uci set "${uci_wifi}.bssid=$bssid"
79  uci set "${uci_radio}.channel=$(get_on_core_default wifi_channel)"
80  fi
81  return
82 }
83 
84 
85 configure_olsr_single_interface() {
86  trap "error_trap configure_olsr_single_interface '$*'" $GUARD_TRAPS
87  local iface_logical=$1
88  local iface_addr=$2
89  local iface_netmask=$3
90  local iface_phys=$4
91 
92  # configure on_wifi
93  uci set "network.${iface_logical}=interface"
94  uci set "network.${iface_logical}.proto=static"
95  uci set "network.${iface_logical}.ifname=$iface_phys"
96  uci set "network.${iface_logical}.netmask=$iface_netmask"
97  uci set "network.${iface_logical}.defaultroute=0"
98  uci set "network.${iface_logical}.peerdns=0"
99  uci set "network.${iface_logical}.ipaddr=$iface_addr"
100 
101  # disable dhcp on on_wifi
102  uci set "dhcp.${iface_logical}=dhcp"
103  uci set "dhcp.${iface_logical}.interface=${iface_logical}"
104  uci set "dhcp.${iface_logical}.dynamicdhcp=0"
105  uci set "dhcp.${iface_logical}.ignore=1"
106 }
107 
108 
109 configure_olsr_interfaces() {
110  trap "error_trap configure_olsr_interfaces '$*'" $GUARD_TRAPS
111 
112  # diese Aktion ist bereits abgeschlossen
113  uci -q show "network" | grep -q "^network\.on_eth_0\." && return 0
114 
115  local on_id
116  local on_ipschema
117  local on_netmask
118  on_id=$(uci_get on-core.settings.on_id "$(get_on_core_default on_id_preset)")
119  on_ipschema=$(get_on_core_default on_ipschema)
120  on_netmask=$(get_on_core_default on_netmask)
121  local on_ipaddr
122  local iface_phys
123  local iface_logical
124 
125  # Suche nach WLAN-Interfaces
126  /sbin/wifi detect > /etc/config/wireless
127 
128  local iface_index=0
129  while [ -n "$(uci_get "wireless.@wifi-iface[${iface_index}]")" ]; do
130  on_ipaddr=$(get_on_ip "$on_id" "$on_ipschema" "$iface_index")
131  iface_phys=wlan$iface_index
132  iface_logical=on_wifi_$iface_index
133 
134  configure_olsr_single_interface "$iface_logical" "$on_ipaddr" "$on_netmask" "$iface_phys"
135  configure_olsr_radio "$iface_index" "$iface_logical" "$iface_phys"
136 
137  add_interface_to_zone "$ZONE_MESH" "$iface_logical"
138 
139  : $((iface_index++))
140  done
141 
142  on_ipaddr=$(get_on_ip "$on_id" "$on_ipschema" "$iface_index")
143  iface_phys=none
144  iface_logical=on_eth_0
145  configure_olsr_single_interface "$iface_logical" "$on_ipaddr" "$on_netmask" "$iface_phys"
146  add_interface_to_zone "$ZONE_MESH" "$iface_logical"
147 }
148 
149 
150 # jede Funktion sollte selbst pruefen, ob ihre Aktion bereits abgeschlossen ist
151 configure_local_network
152 configure_opennet_zone
153 configure_olsr_interfaces
154 
155 apply_changes network wireless dhcp firewall
uci_delete(uci_path)
Lösche ein UCI-Element.
Definition: uci.sh:38
add_interface_to_zone()
Fuege ein logisches Netzwerk-Interface zu einer Firewall-Zone hinzu.
Definition: network.sh:39
done
Definition: core.sh:81