Browse Source

Beginning of support for batman

Bob Mottram 9 years ago
parent
commit
07fe5c9464
1 changed files with 85 additions and 0 deletions
  1. 85
    0
      src/freedombone

+ 85
- 0
src/freedombone View File

@@ -374,6 +374,10 @@ CJDNS_IPV6=
374 374
 CJDNS_PASSWORD=
375 375
 CJDNS_PORT=
376 376
 
377
+# B.A.T.M.A.N settings
378
+ENABLE_BATMAN="no"
379
+BATMAN_IP='10.47.254.254'
380
+
377 381
 function show_help {
378 382
   echo ''
379 383
   echo 'freedombone -c [configuration file]'
@@ -617,6 +621,11 @@ else
617 621
     shift
618 622
     ENABLE_CJDNS="yes"
619 623
     ;;
624
+    # Enable B.A.T.M.A.N
625
+    --batman)
626
+    shift
627
+    ENABLE_BATMAN="yes"
628
+    ;;
620 629
     # VoIP server password
621 630
     --vpass)
622 631
     shift
@@ -796,6 +805,12 @@ function read_configuration {
796 805
       if grep -q "LOCAL_NETWORK_STATIC_IP_ADDRESS" $CONFIGURATION_FILE; then
797 806
           LOCAL_NETWORK_STATIC_IP_ADDRESS=$(grep "LOCAL_NETWORK_STATIC_IP_ADDRESS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
798 807
       fi
808
+      if grep -q "ENABLE_BATMAN" $CONFIGURATION_FILE; then
809
+          ENABLE_BATMAN=$(grep "ENABLE_BATMAN" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
810
+      fi
811
+      if grep -q "BATMAN_IP" $CONFIGURATION_FILE; then
812
+          BATMAN_IP=$(grep "BATMAN_IP" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
813
+      fi
799 814
       if grep -q "ENABLE_CJDNS" $CONFIGURATION_FILE; then
800 815
           ENABLE_CJDNS=$(grep "ENABLE_CJDNS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
801 816
       fi
@@ -1495,6 +1510,76 @@ function mesh_cjdns_tools {
1495 1510
   echo 'mesh_cjdns_tools' >> $COMPLETION_FILE
1496 1511
 }
1497 1512
 
1513
+function mesh_batman {
1514
+  # https://sudoroom.org/wiki/Mesh/Relay_setup
1515
+  # also see http://www.netlore.co.uk/airmesh/
1516
+  if grep -Fxq "mesh_batman" $COMPLETION_FILE; then
1517
+      return
1518
+  fi
1519
+  if [[ $ENABLE_BATMAN != "yes" ]]; then
1520
+      return
1521
+  fi
1522
+
1523
+  modprobe batman-adv
1524
+  [ $? -ne 0 ] && echo "B.A.T.M.A.N module not available" && exit 76482
1525
+  if ! grep -q "batman_adv" /etc/modules; then
1526
+      echo 'batman_adv' >> /etc/modules
1527
+  fi
1528
+
1529
+  modprobe l2tp_core
1530
+  [ $? -ne 0 ] && echo "l2tp_core module not available" && exit 7358
1531
+  if ! grep -q "l2tp_core" /etc/modules; then
1532
+      echo 'l2tp_core' >> /etc/modules
1533
+  fi
1534
+
1535
+  modprobe l2tp_eth
1536
+  [ $? -ne 0 ] && echo "l2tp_eth module not available" && exit 8735
1537
+  if ! grep -q "l2tp_eth" /etc/modules; then
1538
+      echo 'l2tp_eth' >> /etc/modules
1539
+  fi
1540
+
1541
+  modprobe l2tp_netlink
1542
+  [ $? -ne 0 ] && echo "l2tp_netlink module not available" && exit 87367
1543
+  if ! grep -q "l2tp_netlink" /etc/modules; then
1544
+      echo 'l2tp_netlink' >> /etc/modules
1545
+  fi
1546
+
1547
+  if ! grep -q "Mesh Networking (B.A.T.M.A.N)" /etc/network/interfaces; then
1548
+      echo '' >> /etc/network/interfaces
1549
+      echo '# Mesh Networking (B.A.T.M.A.N)' >> /etc/network/interfaces
1550
+      echo 'iface bat0 inet static' >> /etc/network/interfaces
1551
+      echo "    address $BATMAN_IP" >> /etc/network/interfaces
1552
+      echo '    netmask 255.0.0.0' >> /etc/network/interfaces
1553
+  fi
1554
+
1555
+  apt-get -y install iproute bridge-utils libnetfilter-conntrack3 python-dev libevent-dev ebtables python-pip git
1556
+
1557
+  cd $BUILD_PATH
1558
+  git clone https://github.com/wlanslovenija/tunneldigger.git /opt/tunneldigger
1559
+  chown root:root -R /opt/tunneldigger
1560
+  cd /opt/tunneldigger/broker
1561
+  pip install -r requirements.txt
1562
+
1563
+  EXTERNAL_IP=$(TODO)
1564
+  sed -i 's|address=.*|address=$EXTERNAL_IP|g' l2tp_broker.cfg
1565
+  sed -i 's|interface=.*|interface=eth0|g' l2tp_broker.cfg
1566
+  sed -i 's|session.up=.*|session.up=/opt/tunneldigger/broker/scripts/up_hook.sh|g' l2tp_broker.cfg
1567
+
1568
+  cd /opt/tunneldigger/broker/scripts
1569
+  echo '#!/bin/sh' > /opt/tunneldigger/broker/scripts/up_hook.sh
1570
+  echo 'INTERFACE="$3"' >> /opt/tunneldigger/broker/scripts/up_hook.sh
1571
+  echo 'ifconfig $INTERFACE up' >> /opt/tunneldigger/broker/scripts/up_hook.sh
1572
+  echo 'batctl if add $INTERFACE' >> /opt/tunneldigger/broker/scripts/up_hook.sh
1573
+  echo 'if [ `cat /sys/class/net/bat0/operstate` != "up" ]; then' >> /opt/tunneldigger/broker/scripts/up_hook.sh
1574
+  echo "    ifconfig bat0 $BATMAN_IP netmask 255.0.0.0 up" >> /opt/tunneldigger/broker/scripts/up_hook.sh
1575
+  echo 'fi' >> /opt/tunneldigger/broker/scripts/up_hook.sh
1576
+  chmod 755 up_hook.sh
1577
+
1578
+  # TODO make a systemd service to run ./l2tp_broker.py l2tp_broker.cfg
1579
+
1580
+  echo 'mesh_batman' >> $COMPLETION_FILE
1581
+}
1582
+
1498 1583
 function remove_instructions_from_motd {
1499 1584
     sed -i '/## /d' /etc/motd
1500 1585
 }