浏览代码

Allow mesh on an interface other than wlanX

Bob Mottram 7 年前
父节点
当前提交
e209eef34e
共有 2 个文件被更改,包括 60 次插入38 次删除
  1. 54
    34
      src/freedombone-mesh-batman
  2. 6
    4
      src/freedombone-utils-mesh

+ 54
- 34
src/freedombone-mesh-batman 查看文件

74
 
74
 
75
     # shellcheck disable=SC2153
75
     # shellcheck disable=SC2153
76
     if [ "$EIFACE" ]; then
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
         fi
87
         fi
85
-        brctl delbr "$BRIDGE"
86
     fi
88
     fi
87
 
89
 
88
     ifconfig bat0 down -promisc
90
     ifconfig bat0 down -promisc
90
     batctl if del "$IFACE"
92
     batctl if del "$IFACE"
91
     ifconfig "$IFACE" mtu 1500
93
     ifconfig "$IFACE" mtu 1500
92
     ifconfig "$IFACE" down
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
     if [ "$IFACE_SECONDARY" ]; then
99
     if [ "$IFACE_SECONDARY" ]; then
96
         systemctl stop hostapd
100
         systemctl stop hostapd
98
         batctl if del "$IFACE_SECONDARY"
102
         batctl if del "$IFACE_SECONDARY"
99
         ifconfig "$IFACE_SECONDARY" mtu 1500
103
         ifconfig "$IFACE_SECONDARY" mtu 1500
100
         ifconfig "$IFACE_SECONDARY" down
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
     fi
108
     fi
103
 
109
 
104
     rmmod batman-adv
110
     rmmod batman-adv
149
     fi
155
     fi
150
     ifconfig "$ifname" hw ether "$peermac"
156
     ifconfig "$ifname" hw ether "$peermac"
151
     echo $"$ifname assigned MAC address $peermac"
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
     batctl if add "$ifname"
163
     batctl if add "$ifname"
156
     ifconfig "$ifname" up
164
     ifconfig "$ifname" up
184
     rfkill unblock "$(rfkill list|awk -F: "/phy/ {print $1}")" || true
192
     rfkill unblock "$(rfkill list|awk -F: "/phy/ {print $1}")" || true
185
 
193
 
186
     secondary_wifi_available=
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
                 fi
204
                 fi
195
             fi
205
             fi
196
         fi
206
         fi
219
     ifconfig bat0 0.0.0.0
229
     ifconfig bat0 0.0.0.0
220
     ethernet_connected='0'
230
     ethernet_connected='0'
221
     if [ "$EIFACE" ] ; then
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
         fi
249
         fi
238
     fi
250
     fi
239
     ifconfig "$BRIDGE" up
251
     ifconfig "$BRIDGE" up
292
 }
304
 }
293
 
305
 
294
 function monitor {
306
 function monitor {
307
+    if [[ "$MESH_INTERFACE_TYPE" != 'wlan'* ]]; then
308
+        return
309
+    fi
295
     if [ -z "$IFACE" ] ; then
310
     if [ -z "$IFACE" ] ; then
296
         echo 'error: unable to find wifi interface, not enabling batman-adv mesh'
311
         echo 'error: unable to find wifi interface, not enabling batman-adv mesh'
297
         exit 723657
312
         exit 723657
360
 fi
375
 fi
361
 
376
 
362
 mesh_protocol_init
377
 mesh_protocol_init
378
+
379
+if [[ "$MESH_INTERFACE_TYPE" == 'eth'* ]]; then
380
+    MESH_INTERFACE_TYPE='eth'
381
+fi
382
+
363
 update_wifi_adaptors "${MESH_INTERFACE_TYPE}"
383
 update_wifi_adaptors "${MESH_INTERFACE_TYPE}"
364
 
384
 
365
 if [ ! "$IFACE" ]; then
385
 if [ ! "$IFACE" ]; then

+ 6
- 4
src/freedombone-utils-mesh 查看文件

99
     IFACE=
99
     IFACE=
100
     IFACE_SECONDARY=
100
     IFACE_SECONDARY=
101
     EIFACE=eth0
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
     fi
109
     fi
108
 }
110
 }
109
 
111