From e209eef34eeeca8ac47636a0b8567c9031c45104 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 7 Mar 2018 15:59:09 +0000 Subject: [PATCH] Allow mesh on an interface other than wlanX --- src/freedombone-mesh-batman | 86 +++++++++++++++++++++++-------------- src/freedombone-utils-mesh | 10 +++-- 2 files changed, 59 insertions(+), 37 deletions(-) diff --git a/src/freedombone-mesh-batman b/src/freedombone-mesh-batman index 48177bd7..24bc1a71 100755 --- a/src/freedombone-mesh-batman +++ b/src/freedombone-mesh-batman @@ -74,15 +74,17 @@ function stop { # shellcheck disable=SC2153 if [ "$EIFACE" ]; then - brctl delif "$BRIDGE" bat0 - ifconfig "$BRIDGE" down || true - ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier") - if [[ "$ethernet_connected" != "0" ]]; then - systemctl stop hostapd - brctl delif "$BRIDGE" "$EIFACE" - ifconfig "$EIFACE" down -promisc + if [[ "$EIFACE" != "$IFACE" ]] ; then + brctl delif "$BRIDGE" bat0 + ifconfig "$BRIDGE" down || true + ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier") + if [[ "$ethernet_connected" != "0" ]]; then + systemctl stop hostapd + brctl delif "$BRIDGE" "$EIFACE" + ifconfig "$EIFACE" down -promisc + fi + brctl delbr "$BRIDGE" fi - brctl delbr "$BRIDGE" fi ifconfig bat0 down -promisc @@ -90,7 +92,9 @@ function stop { batctl if del "$IFACE" ifconfig "$IFACE" mtu 1500 ifconfig "$IFACE" down - iwconfig "$IFACE" mode managed + if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then + iwconfig "$IFACE" mode managed + fi if [ "$IFACE_SECONDARY" ]; then systemctl stop hostapd @@ -98,7 +102,9 @@ function stop { batctl if del "$IFACE_SECONDARY" ifconfig "$IFACE_SECONDARY" mtu 1500 ifconfig "$IFACE_SECONDARY" down - iwconfig "$IFACE_SECONDARY" mode managed + if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then + iwconfig "$IFACE_SECONDARY" mode managed + fi fi rmmod batman-adv @@ -149,8 +155,10 @@ function add_wifi_interface { fi ifconfig "$ifname" hw ether "$peermac" echo $"$ifname assigned MAC address $peermac" - iwconfig "$ifname" enc off - iwconfig "$ifname" mode "$ifmode" essid "$ifssid" channel "$ifchannel" + if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then + iwconfig "$ifname" enc off + iwconfig "$ifname" mode "$ifmode" essid "$ifssid" channel "$ifchannel" + fi batctl if add "$ifname" ifconfig "$ifname" up @@ -184,13 +192,15 @@ function start { rfkill unblock "$(rfkill list|awk -F: "/phy/ {print $1}")" || true secondary_wifi_available= - if [ "$IFACE_SECONDARY" ]; then - if [[ "$IFACE" != "$IFACE_SECONDARY" ]]; then - if [ -d /etc/hostapd ]; then - if [ ${#HOTSPOT_PASSPHRASE} -gt 4 ]; then - secondary_wifi_available=1 - else - echo $'Hotspot passphrase is too short' + if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then + if [ "$IFACE_SECONDARY" ]; then + if [[ "$IFACE" != "$IFACE_SECONDARY" ]]; then + if [ -d /etc/hostapd ]; then + if [ ${#HOTSPOT_PASSPHRASE} -gt 4 ]; then + secondary_wifi_available=1 + else + echo $'Hotspot passphrase is too short' + fi fi fi fi @@ -219,21 +229,23 @@ function start { ifconfig bat0 0.0.0.0 ethernet_connected='0' if [ "$EIFACE" ] ; then - ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier") - if [[ "$ethernet_connected" != "0" ]]; then - echo $'Trying ethernet bridge to the internet' - brctl addif "$BRIDGE" "$EIFACE" - ifconfig "$EIFACE" 0.0.0.0 - ifconfig "$EIFACE" up promisc - echo $'End of internet bridge' + if [[ "$EIFACE" != "$IFACE" ]] ; then + ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier") + if [[ "$ethernet_connected" != "0" ]]; then + echo $'Trying ethernet bridge to the internet' + brctl addif "$BRIDGE" "$EIFACE" + ifconfig "$EIFACE" 0.0.0.0 + ifconfig "$EIFACE" up promisc + echo $'End of internet bridge' - sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service - sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx7 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx7.service - sed -i "s|ExecStart=.*|ExecStart=/usr/local/sbin/olsrd2_static ${IFACE} ${EIFACE}|g" /etc/systemd/system/olsr2.service - sed -i "s|ExecStart=.*|ExecStart=/usr/local/bin/babeld ${IFACE} ${EIFACE}|g" /etc/systemd/system/babel.service - systemctl daemon-reload - else - echo $"$EIFACE is not connected" + sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service + sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx7 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx7.service + sed -i "s|ExecStart=.*|ExecStart=/usr/local/sbin/olsrd2_static ${IFACE} ${EIFACE}|g" /etc/systemd/system/olsr2.service + sed -i "s|ExecStart=.*|ExecStart=/usr/local/bin/babeld ${IFACE} ${EIFACE}|g" /etc/systemd/system/babel.service + systemctl daemon-reload + else + echo $"$EIFACE is not connected" + fi fi fi ifconfig "$BRIDGE" up @@ -292,6 +304,9 @@ function start { } function monitor { + if [[ "$MESH_INTERFACE_TYPE" != 'wlan'* ]]; then + return + fi if [ -z "$IFACE" ] ; then echo 'error: unable to find wifi interface, not enabling batman-adv mesh' exit 723657 @@ -360,6 +375,11 @@ if [ -f "$mesh_interface_type_file" ]; then fi mesh_protocol_init + +if [[ "$MESH_INTERFACE_TYPE" == 'eth'* ]]; then + MESH_INTERFACE_TYPE='eth' +fi + update_wifi_adaptors "${MESH_INTERFACE_TYPE}" if [ ! "$IFACE" ]; then diff --git a/src/freedombone-utils-mesh b/src/freedombone-utils-mesh index 6b1ddcc9..f6eae5aa 100755 --- a/src/freedombone-utils-mesh +++ b/src/freedombone-utils-mesh @@ -99,11 +99,13 @@ function mesh_protocol_init { IFACE= IFACE_SECONDARY= EIFACE=eth0 - WLAN_ADAPTORS=$(count_wlan) + if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then + WLAN_ADAPTORS=$(count_wlan) - if [ "$WLAN_ADAPTORS" -eq 0 ]; then - echo $'No wlan adaptors found' - exit 0 + if [ "$WLAN_ADAPTORS" -eq 0 ]; then + echo $'No wlan adaptors found' + exit 0 + fi fi }