Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] - Libremesh Support #477

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
114 changes: 114 additions & 0 deletions contrib/libremesh/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/bash

# Static libremesh vlan
# Source: https://github.com/libremesh/lime-packages/blob/master/packages/lime-docs/files/lime-example#L41
BABELD_VLAN=17

# Default SSID for LibreMesh is "LibreMesh.org"
# It is used to define NETWORK related settings
SSID="LibreMesh.org"
# MD5SUM hash for SSID will be used for the calculations (NOTE: ends in \n)
SSIDHASH=$(echo ${SSID} | md5sum) # Hash of the SSID

# First 4 bytes of the HASHED SSID will be used for differnt network settings
# We convert HEX to DEC
N1=$( printf "%d" "0x${SSIDHASH:0:2}" )
N2=$( printf "%d" "0x${SSIDHASH:2:2}" )
N3=$( printf "%d" "0x${SSIDHASH:4:2}" )
N4=$( printf "%d" "0x${SSIDHASH:6:2}" )

# MAC address of ethernet. Used to identify NODE specific settings
MAC=$(cat /sys/class/net/eth0/address ) # Get Mac
# Last 3 bytes of the MAC (make up the node name)
NODEID=$(echo $MAC | cut -f 4 -d \:)$(echo $MAC | cut -f 5 -d \:)$(echo $MAC | cut -f 6 -d \:)
# We convert HEX to DEC
M1=$( printf "%d" "0x${NODEID:0:2}" )
M2=$( printf "%d" "0x${NODEID:2:2}" )
M3=$( printf "%d" "0x${NODEID:4:2}" )

# BATMAN-ADV VLAN setting
# Each Unique SSID has (we hope) a unique VLANID so the two networks wont mesh together layer2
# Lots of legacy things in this calculations so its odd
# BATMAN-ADV vlan is 29 + (N1 - 13) % 254
# Notes (I THINK)
# N1-13 = 0 on Default Setups
# 29 is added to allow for lower VLANS being Layer 3 (i think)
# % 254 makes sure the number is between 0-254
BATMAN_VLAN=$(( 29 + $(( N1 -13 )) % 254 ))

NODEIP=10.$N1.$M2.$M3

# Install batman
apt-get install -y batctl


# Change mesh-point seattings to use channel 11 (Libremesh defailt) and set meshname of LiMe
confset general frequency 2462 /etc/mesh.conf
confset general mesh-name LiMe /etc/mesh.conf

# Always load batman on boot
echo batman-adv >> /etc/modules

# WLAN VLAN for layer 2 BATMAN
echo auto wlan0.${BATMAN_VLAN} > /etc/network/interfaces.d/wlan0.${BATMAN_VLAN}
echo iface wlan0.${BATMAN_VLAN} inet manual >> /etc/network/interfaces.d/wlan0.${BATMAN_VLAN}
echo post-up ip link del wlan0.${BATMAN_VLAN} >> /etc/network/interfaces.d/wlan0.${BATMAN_VLAN}
echo post-up ip link add link wlan0 name wlan0.${BATMAN_VLAN} type vlan proto 802.1ad id ${BATMAN_VLAN} >> /etc/network/interfaces.d/wlan0.${BATMAN_VLAN}
echo post-up batctl if add wlan0.${BATMAN_VLAN} >> /etc/network/interfaces.d/wlan0.${BATMAN_VLAN}
echo post-up ip link set wlan0.${BATMAN_VLAN} up >> /etc/network/interfaces.d/wlan0.${BATMAN_VLAN}
echo post-up batctl if add wlan0.${BATMAN_VLAN} >> /etc/network/interfaces.d/wlan0.${BATMAN_VLAN}



# WLAN VLAN for layer 3 BABELD meshing

echo auto wlan0.${BABELD_VLAN} > /etc/network/interfaces.d/wlan0.${BABELD_VLAN}
echo iface wlan0.${BABELD_VLAN} inet manual >> /etc/network/interfaces.d/wlan0.${BABELD_VLAN}
echo post-up ip link del wlan0.${BABELD_VLAN} >> /etc/network/interfaces.d/wlan0.${BABELD_VLAN}
echo post-up ip link add link wlan0 name wlan0.${BABELD_VLAN} type vlan proto 802.1ad id ${BABELD_VLAN} >> /etc/network/interfaces.d/wlan0.${BABELD_VLAN}
echo post-up ip link set wlan0.${BABELD_VLAN} up >> /etc/network/interfaces.d/wlan0.${BABELD_VLAN}
echo post-up ip addr add ${NODEIP}/16 dev wlan0.${BABELD_VLAN} >> /etc/network/interfaces.d/wlan0.${BABELD_VLAN}


# BAT0 configuration

echo auto bat0 > /etc/network/interfaces.d/bat0
echo iface bat0 inet manual >> /etc/network/interfaces.d/bat0
echo pre-up batctl if add wlan0.${BATMAN_VLAN} >> /etc/network/interfaces.d/bat0
echo post-up ip addr add ${NODEIP}/16 dev bat0 >> /etc/network/interfaces.d/bat0
echo post-up batctl bridge_loop_avoidance 1 >> /etc/network/interfaces.d/bat0
echo post-up batctl multicast_mode 0 >> /etc/network/interfaces.d/bat0
echo post-up batctl distributed_arp_table 0 >> /etc/network/interfaces.d/bat0
echo post-up batctl gw_mode client >> /etc/network/interfaces.d/bat0


# ETH VLAN for layer 3 BABELD meshing
echo auto eth0.${BABELD_VLAN} > /etc/network/interfaces.d/eth0.${BABELD_VLAN}
echo iface eth0.${BABELD_VLAN} inet manual >> /etc/network/interfaces.d/eth0.${BABELD_VLAN}
echo post-up ip link del eth0.${BABELD_VLAN} >> /etc/network/interfaces.d/eth0.${BABELD_VLAN}
echo post-up ip link add link eth0 name eth0.${BABELD_VLAN} type vlan proto 802.1ad id ${BABELD_VLAN} >> /etc/network/interfaces.d/eth0.${BABELD_VLAN}
echo post-up ip link set eth0.${BABELD_VLAN} up >> /etc/network/interfaces.d/eth0.${BABELD_VLAN}
echo post-up ip addr add ${NODEIP}/16 dev eth0.${BABELD_VLAN} >> /etc/network/interfaces.d/eth0.${BABELD_VLAN}


# Install BABELD
wget http://meshwithme.online/deb/repos/apt/debian/pool/main/b/babeld/babeld_1.9.1-dirty_armhf.deb
dpkg -i babeld_1.9.1-dirty_armhf.deb

# Configure BABELD
echo local-port 30003 > /etc/babeld.conf
echo interface eth0.17 >> /etc/babeld.conf
echo interface wlan0.17 >> /etc/babeld.conf
echo redistribute ip 2000::0/3 allow >> /etc/babeld.conf
echo redistribute ip 0::0/0 le 0 allow >> /etc/babeld.conf
echo redistribute ip 10.0.0.0/8 allow >> /etc/babeld.conf
echo redistribute ip 172.16.0.0/12 allow >> /etc/babeld.conf
echo redistribute ip 0.0.0.0/0 le 0 allow >> /etc/babeld.conf
echo redistribute local deny >> /etc/babeld.conf
echo redistribute deny >> /etc/babeld.conf

# Force meshpoint to run at higher mtu (1560) to prevent fragmentation of batman-adv
echo 'ip link set dev $mesh_dev mtu 1560' >> /usr/bin/mesh-point

# Try to add a second interface to mesh on the tomesh name (channel will still be differnt)
echo 'iw dev $mesh_dev interface add wlan0-tomesh type mesh mesh_id tomesh || true' >> /usr/bin/mesh-point
28 changes: 18 additions & 10 deletions scripts/install2
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ askModule "WITH_MESH_POINT" "Mesh Point Interface"
if [ "$WITH_MESH_POINT" == false ]; then
askModule "WITH_AD_HOC" "Ad-Hoc Interface"
fi
if [ "$WITH_MESH_POINT" == true ] || [ "$WITH_AD_HOC" == true ]; then
askModule "WITH_LIBREMESH" "LibreMesh Compatibility"
fi
askModule "WITH_WIFI_AP" "WiFi Access Point"
askModule "WITH_FIREWALL" "Basic Firewall"
askModule "WITH_IPFS" "IPFS"
Expand Down Expand Up @@ -287,6 +290,16 @@ sudo apt-get install haveged -y || true
# Install nginx
source nginx/install

# 802.11s Mesh Point interface
if [ "$(checkModule 'WITH_MESH_POINT')" ]; then
source mesh-point/install
fi

# IBSS Ad-hoc interface
if [ "$(checkModule 'WITH_AD_HOC')" ]; then
source mesh-adhoc/install
fi

# Install CJDNS
if [ "$(checkModule 'WITH_CJDNS')" ]; then
source cjdns/install
Expand All @@ -297,22 +310,17 @@ if [ "$(checkModule 'WITH_YGGDRASIL')" ]; then
source yggdrasil/install
fi

# Install LibreMesh
if [ "$(checkModule 'WITH_LIBREMESH')" ]; then
source libremesh/install
fi

# Install nodeinfo
source shared/nodeinfo/install

# Set hostname
source shared/hostname/install

# 802.11s Mesh Point interface
if [ "$(checkModule 'WITH_MESH_POINT')" ]; then
source mesh-point/install
fi

# IBSS Ad-hoc interface
if [ "$(checkModule 'WITH_AD_HOC')" ]; then
source mesh-adhoc/install
fi

# WiFi Access Point on supported boards
if [ "$(checkModule 'WITH_WIFI_AP')" ]; then
source hostapd/install
Expand Down
10 changes: 10 additions & 0 deletions scripts/libremesh/babeld.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local-port 30003
interface eth0.__BABELD_VLAN__
interface wlan0.__BABELD_VLAN__
redistribute ip 2000::0/3 allow
redistribute ip 0::0/0 le 0 allow
redistribute ip 10.0.0.0/8 allow
redistribute ip 172.16.0.0/12 allow
redistribute ip 0.0.0.0/0 le 0 allow
redistribute local deny
redistribute deny
8 changes: 8 additions & 0 deletions scripts/libremesh/bat0
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
auto bat0
iface bat0 inet manual
pre-up batctl if add wlan0.__BATMAN_VLAN__
post-up ip addr add __NODEIP__/16 dev bat0
post-up batctl bridge_loop_avoidance 1
post-up batctl multicast_mode 0
post-up batctl distributed_arp_table 0
post-up batctl gw_mode client
7 changes: 7 additions & 0 deletions scripts/libremesh/eth0-babeld
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ETH VLAN for layer 3 BABELD meshing
auto eth0.__BABELD_VLAN__
iface eth0.__BABELD_VLAN__ inet manual
post-up ip link del eth0.__BABELD_VLAN__
post-up ip link add link eth0 name eth0.__BABELD_VLAN__ type vlan proto 802.1ad id __BABELD_VLAN__
post-up ip link set eth0.__BABELD_VLAN__ up
post-up ip addr add __NODEIP__/16 dev eth0.__BABELD_VLAN__
57 changes: 57 additions & 0 deletions scripts/libremesh/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

ARCH="$(uname -m)"
case "$ARCH" in
x86_64)
ARCH="amd64"
;;
i386 | i586 | i686 )
ARCH="386"
;;
armv7l)
ARCH="armv7";
;;
armv6l)
ARCH="armv6";
;;
aarch64)
ARCH="arm64";
;;
*)
echo "Unknown Arch"
exit 1
;;
esac

# Set default settings for libremesh
./set-defaults.sh

# Update configs of libremesh
./set-config.sh

# Install batman
sudo apt-get install -y batctl

# Change mesh-point settings to use channel 11 (Libremesh default) and set meshname of LiMe
sudo confset general frequency 2462 /etc/mesh.conf
sudo confset general mesh-name LiMe /etc/mesh.conf

# Always load batman on boot
echo batman-adv >> /etc/modules

# Install Babled from meshwithme repos
wget http://meshwithme.online/deb/repos/apt/debian/pool/main/c/confset/confset_1_all.deb
sudo dpkg -i confset_1_all.deb
wget http://meshwithme.online/deb/repos/apt/debian/pool/main/b/babeld/babeld_1.9.1-dirty_${ARCH}.deb
sudo dpkg -i babeld_1.9.1-dirty_${ARCH}.deb
wget http://meshwithme.online/deb/repos/apt/debian/pool/main/b/babeld-tomesh/babeld-tomesh_1_all.deb
sudo dpkg -i babeld-tomesh_1_all.deb

# Force meshpoint to run at higher mtu (1560) to prevent fragmentation of batman-adv
echo 'ip link set dev $mesh_dev mtu 1560' | sudo tee --append /usr/bin/mesh-point

# Try to add a second interface to mesh on the tomesh name (channel will still be differnt)
echo 'iw dev $mesh_dev interface add wlan0-tomesh type mesh mesh_id tomesh || true' | sudo tee --append /usr/bin/mesh-point

# Generate network config
sudo ./updateConfig.sh
31 changes: 31 additions & 0 deletions scripts/libremesh/set-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Read core paramaters
BABELD_VLAN=$(confget -f /etc/mesh-libre.conf -s libremesh "BABELD_VLAN")
SSID=$(confget -f /etc/mesh-libre.conf -s libremesh "SSID")
MAC=$(confget -f /etc/mesh-libre.conf -s libremesh "MAC")

# MD5SUM hash for SSID will be used for the calculations (NOTE: ends in \n)
SSIDHASH="$(echo ${SSID} | md5sum | awk '{print $1}')"
sudo confset libremesh SSIDHASH ${SSIDHASH} /etc/mesh-libre.conf

# First 4 bytes of the HASHED SSID will be used for differnt network settings
# We convert HEX to DEC
N1=$( printf "%d" "0x${SSIDHASH:0:2}" )
N2=$( printf "%d" "0x${SSIDHASH:2:2}" )
N3=$( printf "%d" "0x${SSIDHASH:4:2}" )
N4=$( printf "%d" "0x${SSIDHASH:6:2}" )

# Last 3 bytes of the MAC (make up the node name)
NODEID=$(echo $MAC | cut -f 4 -d \:)$(echo $MAC | cut -f 5 -d \:)$(echo $MAC | cut -f 6 -d \:)
sudo confset libremesh NODEID ${NODEID} /etc/mesh-libre.conf

M1=$( printf "%d" "0x${NODEID:0:2}" )
M2=$( printf "%d" "0x${NODEID:2:2}" )
M3=$( printf "%d" "0x${NODEID:4:2}" )

BATMAN_VLAN=$(( 29 + $(( N1 - 13 )) % 254 ))
sudo confset libremesh BATMAN_VLAN ${BATMAN_VLAN} /etc/mesh-libre.conf

NODEIP=10.$N1.$M2.$M3
sudo confset libremesh NODEIP ${NODEIP} /etc/mesh-libre.conf
15 changes: 15 additions & 0 deletions scripts/libremesh/set-defaults.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Set Defaults
sudo touch /etc/mesh-libre.conf

# Static libremesh vlan
# Source: https://github.com/libremesh/lime-packages/blob/master/packages/lime-docs/files/lime-example#L41
sudo confset libremesh BABELD_VLAN 17 /etc/mesh-libre.conf

# Default SSID for LibreMesh is "LibreMesh.org"
# It is used to define NETWORK related settings
sudo confset libremesh SSID LibreMesh.org /etc/mesh-libre.conf

# MAC address of ethernet. Used to identify NODE specific settings
sudo confset libremesh MAC $(cat /sys/class/net/eth0/address ) /etc/mesh-libre.conf # Get Mac
31 changes: 31 additions & 0 deletions scripts/libremesh/updateConfig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

BABELD_VLAN=$(confget -f /etc/mesh-libre.conf -s libremesh "BABELD_VLAN")
BATMAN_VLAN=$(confget -f /etc/mesh-libre.conf -s libremesh "BATMAN_VLAN")
NODEIP=$(confget -f /etc/mesh-libre.conf -s libremesh "NODEIP")


cp wlan0-bat /tmp/wlan0.${BATMAN_VLAN}
sed -i "s/__BATMAN_VLAN__/$BATMAN_VLAN/g" "/tmp/wlan0.${BATMAN_VLAN}"
sudo mv /tmp/wlan0.${BATMAN_VLAN} /etc/network/interfaces.d/wlan0.${BATMAN_VLAN}

cp bat0 /tmp/bat0
sed -i "s/__BATMAN_VLAN__/$BATMAN_VLAN/g" "/tmp/bat0"
sed -i "s/__NODEIP__/$NODEIP/g" "/tmp/bat0"
sudo mv /tmp/bat0 /etc/network/interfaces.d/bat0

cp wlan0-babeld /tmp/wlan0.${BABELD_VLAN}
sed -i "s/__BABELD_VLAN__/$BABELD_VLAN/g" "/tmp/wlan0.${BABELD_VLAN}"
sed -i "s/__NODEIP__/$NODEIP/g" "/tmp/wlan0.${BABELD_VLAN}"
sudo mv /tmp/wlan0.${BABELD_VLAN} /etc/network/interfaces.d/wlan0.${BABELD_VLAN}

# ETH VLAN for layer 3 BABELD meshing
cp eth0-babeld /tmp/eth0.${BABELD_VLAN}
sed -i "s/__BABELD_VLAN__/$BABELD_VLAN/g" "/tmp/eth0.${BABELD_VLAN}"
sed -i "s/__NODEIP__/$NODEIP/g" "/tmp/eth0.${BABELD_VLAN}"
sudo mv /tmp/eth0.${BABELD_VLAN} /etc/network/interfaces.d/eth0.${BABELD_VLAN}

# ETH VLAN for layer 3 BABELD meshing
cp babeld.conf /tmp/babeld.conf
sed -i "s/__BABELD_VLAN__/$BABELD_VLAN/g" "/tmp/babeld.conf"
sudo mv /tmp/babeld.conf /etc/babeld.d/libremesh
6 changes: 6 additions & 0 deletions scripts/libremesh/wlan0-babeld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
auto wlan0.__BABELD_VLAN__
iface wlan0.__BABELD_VLAN__ inet manual
post-up ip link del wlan0.__BABELD_VLAN__
post-up ip link add link wlan0 name wlan0.__BABELD_VLAN__ type vlan proto 802.1ad id __BABELD_VLAN__
post-up ip link set wlan0.__BABELD_VLAN__ up
post-up ip addr add __NODEIP__/16 dev wlan0.__BABELD_VLAN__
7 changes: 7 additions & 0 deletions scripts/libremesh/wlan0-bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
auto wlan0.__BATMAN_VLAN__
iface wlan0.__BATMAN_VLAN__ inet manual
post-up ip link del wlan0.__BATMAN_VLAN__
post-up ip link add link wlan0 name wlan0.__BATMAN_VLAN__ type vlan proto 802.1ad id __BATMAN_VLAN__
post-up batctl if add wlan0.__BATMAN_VLAN__
post-up ip link set wlan0.__BATMAN_VLAN__ up
post-up batctl if add wlan0.__BATMAN_VLAN__
11 changes: 10 additions & 1 deletion scripts/shared/hostname/install
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@

MESH_NAME=$(confget -f /etc/mesh.conf -s general "mesh-name")

# Define hostname based off LibreMesh if installed
if [ -f '/etc/mesh-libre.conf' ]; then
# Define new hostname
if [ -z "${NEWHOSTNAME}" ]; then
NEWHOSTNAME="$MESH_NAME-$(confget -f /etc/mesh-libre.conf -s libremesh NODEID)"
fi
fi

# Define hostname based on CJDNS if installed
if [ -f '/etc/cjdroute.conf' ]; then
# Define new hostname
if [ -z "${NEWHOSTNAME}" ]; then
NEWHOSTNAME=$(sudo grep -m 1 '"ipv6"' /etc/cjdroute.conf | awk '{ print $2 }' | sed 's/[",]//g' | sed "s/.*:/$MESH_NAME-/g")
fi
fi

# Define hostname based off Yggdrasil if CJDNS isn't installed
# Define hostname based off Yggdrasil if Installed
if ! [ -z "$(ifconfig | grep ygg0:)" ]; then
# Define new hostname
if [ -z "${NEWHOSTNAME}" ]; then
Expand Down