Allow mesh on an interface other than wlanX

This commit is contained in:
Bob Mottram 2018-03-07 15:59:09 +00:00
parent 9f14c00645
commit e209eef34e
2 changed files with 59 additions and 37 deletions

View File

@ -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

View File

@ -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
}