diff --git a/contrib/libremesh/install.sh b/contrib/libremesh/install.sh new file mode 100644 index 000000000..fdfc8215b --- /dev/null +++ b/contrib/libremesh/install.sh @@ -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 diff --git a/scripts/install2 b/scripts/install2 index 717974f4a..45deaf07f 100755 --- a/scripts/install2 +++ b/scripts/install2 @@ -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" @@ -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 @@ -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 diff --git a/scripts/libremesh/babeld.conf b/scripts/libremesh/babeld.conf new file mode 100644 index 000000000..7aa483c01 --- /dev/null +++ b/scripts/libremesh/babeld.conf @@ -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 diff --git a/scripts/libremesh/bat0 b/scripts/libremesh/bat0 new file mode 100644 index 000000000..943b7b64a --- /dev/null +++ b/scripts/libremesh/bat0 @@ -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 diff --git a/scripts/libremesh/eth0-babeld b/scripts/libremesh/eth0-babeld new file mode 100644 index 000000000..f93a2916a --- /dev/null +++ b/scripts/libremesh/eth0-babeld @@ -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__ diff --git a/scripts/libremesh/install b/scripts/libremesh/install new file mode 100755 index 000000000..843c61aef --- /dev/null +++ b/scripts/libremesh/install @@ -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 diff --git a/scripts/libremesh/set-config.sh b/scripts/libremesh/set-config.sh new file mode 100755 index 000000000..1321c6cab --- /dev/null +++ b/scripts/libremesh/set-config.sh @@ -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 diff --git a/scripts/libremesh/set-defaults.sh b/scripts/libremesh/set-defaults.sh new file mode 100755 index 000000000..b70fcf879 --- /dev/null +++ b/scripts/libremesh/set-defaults.sh @@ -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 diff --git a/scripts/libremesh/updateConfig.sh b/scripts/libremesh/updateConfig.sh new file mode 100755 index 000000000..b5c4e4d9f --- /dev/null +++ b/scripts/libremesh/updateConfig.sh @@ -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 diff --git a/scripts/libremesh/wlan0-babeld b/scripts/libremesh/wlan0-babeld new file mode 100644 index 000000000..349ae5a3e --- /dev/null +++ b/scripts/libremesh/wlan0-babeld @@ -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__ diff --git a/scripts/libremesh/wlan0-bat b/scripts/libremesh/wlan0-bat new file mode 100644 index 000000000..baccf431b --- /dev/null +++ b/scripts/libremesh/wlan0-bat @@ -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__ diff --git a/scripts/shared/hostname/install b/scripts/shared/hostname/install index a9674425c..ea34dcf1c 100644 --- a/scripts/shared/hostname/install +++ b/scripts/shared/hostname/install @@ -2,6 +2,15 @@ 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 @@ -9,7 +18,7 @@ if [ -f '/etc/cjdroute.conf' ]; then 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