Selaa lähdekoodia

Allow mesh on an interface other than wlanX

Bob Mottram 7 vuotta sitten
vanhempi
commit
e209eef34e
2 muutettua tiedostoa jossa 60 lisäystä ja 38 poistoa
  1. 54
    34
      src/freedombone-mesh-batman
  2. 6
    4
      src/freedombone-utils-mesh

+ 54
- 34
src/freedombone-mesh-batman Näytä tiedosto

@@ -74,15 +74,17 @@ function stop {
74 74
 
75 75
     # shellcheck disable=SC2153
76 76
     if [ "$EIFACE" ]; then
77
-        brctl delif "$BRIDGE" bat0
78
-        ifconfig "$BRIDGE" down || true
79
-        ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier")
80
-        if [[ "$ethernet_connected" != "0" ]]; then
81
-            systemctl stop hostapd
82
-            brctl delif "$BRIDGE" "$EIFACE"
83
-            ifconfig "$EIFACE" down -promisc
77
+        if [[ "$EIFACE" != "$IFACE" ]] ; then
78
+            brctl delif "$BRIDGE" bat0
79
+            ifconfig "$BRIDGE" down || true
80
+            ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier")
81
+            if [[ "$ethernet_connected" != "0" ]]; then
82
+                systemctl stop hostapd
83
+                brctl delif "$BRIDGE" "$EIFACE"
84
+                ifconfig "$EIFACE" down -promisc
85
+            fi
86
+            brctl delbr "$BRIDGE"
84 87
         fi
85
-        brctl delbr "$BRIDGE"
86 88
     fi
87 89
 
88 90
     ifconfig bat0 down -promisc
@@ -90,7 +92,9 @@ function stop {
90 92
     batctl if del "$IFACE"
91 93
     ifconfig "$IFACE" mtu 1500
92 94
     ifconfig "$IFACE" down
93
-    iwconfig "$IFACE" mode managed
95
+    if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
96
+        iwconfig "$IFACE" mode managed
97
+    fi
94 98
 
95 99
     if [ "$IFACE_SECONDARY" ]; then
96 100
         systemctl stop hostapd
@@ -98,7 +102,9 @@ function stop {
98 102
         batctl if del "$IFACE_SECONDARY"
99 103
         ifconfig "$IFACE_SECONDARY" mtu 1500
100 104
         ifconfig "$IFACE_SECONDARY" down
101
-        iwconfig "$IFACE_SECONDARY" mode managed
105
+        if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
106
+            iwconfig "$IFACE_SECONDARY" mode managed
107
+        fi
102 108
     fi
103 109
 
104 110
     rmmod batman-adv
@@ -149,8 +155,10 @@ function add_wifi_interface {
149 155
     fi
150 156
     ifconfig "$ifname" hw ether "$peermac"
151 157
     echo $"$ifname assigned MAC address $peermac"
152
-    iwconfig "$ifname" enc off
153
-    iwconfig "$ifname" mode "$ifmode" essid "$ifssid" channel "$ifchannel"
158
+    if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
159
+        iwconfig "$ifname" enc off
160
+        iwconfig "$ifname" mode "$ifmode" essid "$ifssid" channel "$ifchannel"
161
+    fi
154 162
 
155 163
     batctl if add "$ifname"
156 164
     ifconfig "$ifname" up
@@ -184,13 +192,15 @@ function start {
184 192
     rfkill unblock "$(rfkill list|awk -F: "/phy/ {print $1}")" || true
185 193
 
186 194
     secondary_wifi_available=
187
-    if [ "$IFACE_SECONDARY" ]; then
188
-        if [[ "$IFACE" != "$IFACE_SECONDARY" ]]; then
189
-            if [ -d /etc/hostapd ]; then
190
-                if [ ${#HOTSPOT_PASSPHRASE} -gt 4 ]; then
191
-                    secondary_wifi_available=1
192
-                else
193
-                    echo $'Hotspot passphrase is too short'
195
+    if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
196
+        if [ "$IFACE_SECONDARY" ]; then
197
+            if [[ "$IFACE" != "$IFACE_SECONDARY" ]]; then
198
+                if [ -d /etc/hostapd ]; then
199
+                    if [ ${#HOTSPOT_PASSPHRASE} -gt 4 ]; then
200
+                        secondary_wifi_available=1
201
+                    else
202
+                        echo $'Hotspot passphrase is too short'
203
+                    fi
194 204
                 fi
195 205
             fi
196 206
         fi
@@ -219,21 +229,23 @@ function start {
219 229
     ifconfig bat0 0.0.0.0
220 230
     ethernet_connected='0'
221 231
     if [ "$EIFACE" ] ; then
222
-        ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier")
223
-        if [[ "$ethernet_connected" != "0" ]]; then
224
-            echo $'Trying ethernet bridge to the internet'
225
-            brctl addif "$BRIDGE" "$EIFACE"
226
-            ifconfig "$EIFACE" 0.0.0.0
227
-            ifconfig "$EIFACE" up promisc
228
-            echo $'End of internet bridge'
229
-
230
-            sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service
231
-            sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx7 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx7.service
232
-            sed -i "s|ExecStart=.*|ExecStart=/usr/local/sbin/olsrd2_static ${IFACE} ${EIFACE}|g" /etc/systemd/system/olsr2.service
233
-            sed -i "s|ExecStart=.*|ExecStart=/usr/local/bin/babeld ${IFACE} ${EIFACE}|g" /etc/systemd/system/babel.service
234
-            systemctl daemon-reload
235
-        else
236
-            echo $"$EIFACE is not connected"
232
+        if [[ "$EIFACE" != "$IFACE" ]] ; then
233
+            ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier")
234
+            if [[ "$ethernet_connected" != "0" ]]; then
235
+                echo $'Trying ethernet bridge to the internet'
236
+                brctl addif "$BRIDGE" "$EIFACE"
237
+                ifconfig "$EIFACE" 0.0.0.0
238
+                ifconfig "$EIFACE" up promisc
239
+                echo $'End of internet bridge'
240
+
241
+                sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service
242
+                sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx7 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx7.service
243
+                sed -i "s|ExecStart=.*|ExecStart=/usr/local/sbin/olsrd2_static ${IFACE} ${EIFACE}|g" /etc/systemd/system/olsr2.service
244
+                sed -i "s|ExecStart=.*|ExecStart=/usr/local/bin/babeld ${IFACE} ${EIFACE}|g" /etc/systemd/system/babel.service
245
+                systemctl daemon-reload
246
+            else
247
+                echo $"$EIFACE is not connected"
248
+            fi
237 249
         fi
238 250
     fi
239 251
     ifconfig "$BRIDGE" up
@@ -292,6 +304,9 @@ function start {
292 304
 }
293 305
 
294 306
 function monitor {
307
+    if [[ "$MESH_INTERFACE_TYPE" != 'wlan'* ]]; then
308
+        return
309
+    fi
295 310
     if [ -z "$IFACE" ] ; then
296 311
         echo 'error: unable to find wifi interface, not enabling batman-adv mesh'
297 312
         exit 723657
@@ -360,6 +375,11 @@ if [ -f "$mesh_interface_type_file" ]; then
360 375
 fi
361 376
 
362 377
 mesh_protocol_init
378
+
379
+if [[ "$MESH_INTERFACE_TYPE" == 'eth'* ]]; then
380
+    MESH_INTERFACE_TYPE='eth'
381
+fi
382
+
363 383
 update_wifi_adaptors "${MESH_INTERFACE_TYPE}"
364 384
 
365 385
 if [ ! "$IFACE" ]; then

+ 6
- 4
src/freedombone-utils-mesh Näytä tiedosto

@@ -99,11 +99,13 @@ function mesh_protocol_init {
99 99
     IFACE=
100 100
     IFACE_SECONDARY=
101 101
     EIFACE=eth0
102
-    WLAN_ADAPTORS=$(count_wlan)
102
+    if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
103
+        WLAN_ADAPTORS=$(count_wlan)
103 104
 
104
-    if [ "$WLAN_ADAPTORS" -eq 0 ]; then
105
-        echo $'No wlan adaptors found'
106
-        exit 0
105
+        if [ "$WLAN_ADAPTORS" -eq 0 ]; then
106
+            echo $'No wlan adaptors found'
107
+            exit 0
108
+        fi
107 109
     fi
108 110
 }
109 111