Przeglądaj źródła

Moving batman to ipv6

Bob Mottram 10 lat temu
rodzic
commit
1842f04577
1 zmienionych plików z 62 dodań i 17 usunięć
  1. 62
    17
      src/freedombone

+ 62
- 17
src/freedombone Wyświetl plik

79
 # number of CPU cores
79
 # number of CPU cores
80
 CPU_CORES=1
80
 CPU_CORES=1
81
 
81
 
82
+# If the system is on an IPv6 network
83
+IPV6_NETWORK='2001:470:26:307'
84
+
82
 # The static IP address of the system within the local network
85
 # The static IP address of the system within the local network
83
 LOCAL_NETWORK_STATIC_IP_ADDRESS="192.168.1.60"
86
 LOCAL_NETWORK_STATIC_IP_ADDRESS="192.168.1.60"
84
 
87
 
376
 
379
 
377
 # B.A.T.M.A.N settings
380
 # B.A.T.M.A.N settings
378
 ENABLE_BATMAN="no"
381
 ENABLE_BATMAN="no"
379
-BATMAN_IP='10.47.254.254'
382
+BATMAN_IPV6=
380
 
383
 
381
 function show_help {
384
 function show_help {
382
   echo ''
385
   echo ''
713
   fi
716
   fi
714
 
717
 
715
   if [ -f $CONFIGURATION_FILE ]; then
718
   if [ -f $CONFIGURATION_FILE ]; then
719
+      if grep -q "IPV6_NETWORK" $CONFIGURATION_FILE; then
720
+          IPV6_NETWORK=$(grep "IPV6_NETWORK" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
721
+      fi
716
       if grep -q "HWRNG_TYPE" $CONFIGURATION_FILE; then
722
       if grep -q "HWRNG_TYPE" $CONFIGURATION_FILE; then
717
           HWRNG_TYPE=$(grep "HWRNG_TYPE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
723
           HWRNG_TYPE=$(grep "HWRNG_TYPE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
718
       fi
724
       fi
808
       if grep -q "ENABLE_BATMAN" $CONFIGURATION_FILE; then
814
       if grep -q "ENABLE_BATMAN" $CONFIGURATION_FILE; then
809
           ENABLE_BATMAN=$(grep "ENABLE_BATMAN" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
815
           ENABLE_BATMAN=$(grep "ENABLE_BATMAN" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
810
       fi
816
       fi
811
-      if grep -q "BATMAN_IP" $CONFIGURATION_FILE; then
812
-          BATMAN_IP=$(grep "BATMAN_IP" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
817
+      if grep -q "BATMAN_IPV6" $CONFIGURATION_FILE; then
818
+          BATMAN_IPV6=$(grep "BATMAN_IPV6" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
813
       fi
819
       fi
814
       if grep -q "ENABLE_CJDNS" $CONFIGURATION_FILE; then
820
       if grep -q "ENABLE_CJDNS" $CONFIGURATION_FILE; then
815
           ENABLE_CJDNS=$(grep "ENABLE_CJDNS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
821
           ENABLE_CJDNS=$(grep "ENABLE_CJDNS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
1202
   fi
1208
   fi
1203
 }
1209
 }
1204
 
1210
 
1211
+function enable_ipv6 {
1212
+  # endure that ipv6 is enabled and can route
1213
+  sed -i 's/net.ipv6.conf.all.disable_ipv6.*/net.ipv6.conf.all.disable_ipv6 = 0/g' /etc/sysctl.conf
1214
+  #sed -i "s/net.ipv6.conf.all.accept_redirects.*/net.ipv6.conf.all.accept_redirects = 1/g" /etc/sysctl.conf
1215
+  #sed -i "s/net.ipv6.conf.all.accept_source_route.*/net.ipv6.conf.all.accept_source_route = 1/g" /etc/sysctl.conf
1216
+  sed -i "s/net.ipv6.conf.all.forwarding.*/net.ipv6.conf.all.forwarding=1/g" /etc/sysctl.conf
1217
+  echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
1218
+}
1219
+
1205
 function mesh_cjdns {
1220
 function mesh_cjdns {
1206
   if grep -Fxq "mesh_cjdns" $COMPLETION_FILE; then
1221
   if grep -Fxq "mesh_cjdns" $COMPLETION_FILE; then
1207
       return
1222
       return
1282
       CJDNS_PORT=$(cat /etc/cjdns/cjdroute.conf | grep '"bind": "0.0.0.0:' | awk -F '"' '{print $4}' | awk -F ':' '{print $2}' | sed -n 1p)
1297
       CJDNS_PORT=$(cat /etc/cjdns/cjdroute.conf | grep '"bind": "0.0.0.0:' | awk -F '"' '{print $4}' | awk -F ':' '{print $2}' | sed -n 1p)
1283
   fi
1298
   fi
1284
 
1299
 
1285
-  # endure that ipv6 is enabled and can route
1286
-  sed -i 's/net.ipv6.conf.all.disable_ipv6.*/net.ipv6.conf.all.disable_ipv6 = 0/g' /etc/sysctl.conf
1287
-  #sed -i "s/net.ipv6.conf.all.accept_redirects.*/net.ipv6.conf.all.accept_redirects = 1/g" /etc/sysctl.conf
1288
-  #sed -i "s/net.ipv6.conf.all.accept_source_route.*/net.ipv6.conf.all.accept_source_route = 1/g" /etc/sysctl.conf
1289
-  sed -i "s/net.ipv6.conf.all.forwarding.*/net.ipv6.conf.all.forwarding=1/g" /etc/sysctl.conf
1290
-  echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
1300
+  enable_ipv6
1291
 
1301
 
1292
   echo '#!/bin/sh -e' > /etc/init.d/cjdns
1302
   echo '#!/bin/sh -e' > /etc/init.d/cjdns
1293
   echo '### BEGIN INIT INFO' >> /etc/init.d/cjdns
1303
   echo '### BEGIN INIT INFO' >> /etc/init.d/cjdns
1411
       exit 4395
1421
       exit 4395
1412
   fi
1422
   fi
1413
 
1423
 
1414
-  if ! grep -q "# Mesh network cjdns" /etc/network/interfaces; then
1424
+  if ! grep -q "# Mesh Networking (cjdns)" /etc/network/interfaces; then
1415
       echo '' >> /etc/network/interfaces
1425
       echo '' >> /etc/network/interfaces
1416
       echo '# Mesh Networking (cjdns)' >> /etc/network/interfaces
1426
       echo '# Mesh Networking (cjdns)' >> /etc/network/interfaces
1417
       echo 'iface eth0 inet6 static' >> /etc/network/interfaces
1427
       echo 'iface eth0 inet6 static' >> /etc/network/interfaces
1510
   echo 'mesh_cjdns_tools' >> $COMPLETION_FILE
1520
   echo 'mesh_cjdns_tools' >> $COMPLETION_FILE
1511
 }
1521
 }
1512
 
1522
 
1523
+function get_batman_ipv6_address {
1524
+  if [ -f /home/$MY_USERNAME/README ]; then
1525
+      if grep -q "BATMAN IPv6 address" /home/$MY_USERNAME/README; then
1526
+          if [ ! $BATMAN_IPV6 ]; then
1527
+              BATMAN_IPV6=$(cat /home/$MY_USERNAME/README | grep "BATMAN IPv6 address" | awk -F ':' '{print $2}' | sed 's/^ *//')
1528
+          fi
1529
+      fi
1530
+  fi
1531
+}
1532
+
1513
 function mesh_batman {
1533
 function mesh_batman {
1514
   # https://sudoroom.org/wiki/Mesh/Relay_setup
1534
   # https://sudoroom.org/wiki/Mesh/Relay_setup
1515
   # also see http://www.netlore.co.uk/airmesh/
1535
   # also see http://www.netlore.co.uk/airmesh/
1544
       echo 'l2tp_netlink' >> /etc/modules
1564
       echo 'l2tp_netlink' >> /etc/modules
1545
   fi
1565
   fi
1546
 
1566
 
1547
-  if ! grep -q "Mesh Networking (B.A.T.M.A.N)" /etc/network/interfaces; then
1567
+  get_batman_ipv6_address
1568
+
1569
+  # If no address has been given then create a ramdom one
1570
+  if [ ! $BATMAN_IPV6 ]; then
1571
+      hexarray=( 1 2 3 4 5 6 7 8 9 0 a b c d e f )
1572
+      a=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
1573
+      b=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
1574
+      c=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
1575
+      d=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
1576
+      BATMAN_IPV6="$IPV6_NETWORK:$a:$b:$c:$d"
1577
+  fi
1578
+
1579
+  if ! grep -q "# Mesh Networking (B.A.T.M.A.N)" /etc/network/interfaces; then
1548
       echo '' >> /etc/network/interfaces
1580
       echo '' >> /etc/network/interfaces
1549
       echo '# Mesh Networking (B.A.T.M.A.N)' >> /etc/network/interfaces
1581
       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
1582
+      echo 'iface bat0 inet6 static' >> /etc/network/interfaces
1583
+      echo '    pre-up modprobe ipv6' >> /etc/network/interfaces
1584
+      echo "    address $BATMAN_IPV6" >> /etc/network/interfaces
1585
+      echo '    netmask 64' >> /etc/network/interfaces
1586
+      service networking restart
1587
+      if [ ! "$?" = "0" ]; then
1588
+          systemctl status networking.service
1589
+          exit 6949
1590
+      fi
1553
   fi
1591
   fi
1554
 
1592
 
1555
   apt-get -y install iproute bridge-utils libnetfilter-conntrack3 python-dev libevent-dev ebtables python-pip git
1593
   apt-get -y install iproute bridge-utils libnetfilter-conntrack3 python-dev libevent-dev ebtables python-pip git
1560
   cd /opt/tunneldigger/broker
1598
   cd /opt/tunneldigger/broker
1561
   pip install -r requirements.txt
1599
   pip install -r requirements.txt
1562
 
1600
 
1563
-  EXTERNAL_IP=$(TODO)
1564
-  sed -i 's|address=.*|address=$EXTERNAL_IP|g' l2tp_broker.cfg
1601
+  sed -i 's|address=.*|address=$BATMAN_IPV6|g' l2tp_broker.cfg
1565
   sed -i 's|interface=.*|interface=eth0|g' l2tp_broker.cfg
1602
   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
1603
   sed -i 's|session.up=.*|session.up=/opt/tunneldigger/broker/scripts/up_hook.sh|g' l2tp_broker.cfg
1567
 
1604
 
1571
   echo 'ifconfig $INTERFACE up' >> /opt/tunneldigger/broker/scripts/up_hook.sh
1608
   echo 'ifconfig $INTERFACE up' >> /opt/tunneldigger/broker/scripts/up_hook.sh
1572
   echo 'batctl if add $INTERFACE' >> /opt/tunneldigger/broker/scripts/up_hook.sh
1609
   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
1610
   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
1611
+  echo "    ifconfig bat0 up" >> /opt/tunneldigger/broker/scripts/up_hook.sh
1575
   echo 'fi' >> /opt/tunneldigger/broker/scripts/up_hook.sh
1612
   echo 'fi' >> /opt/tunneldigger/broker/scripts/up_hook.sh
1576
   chmod 755 up_hook.sh
1613
   chmod 755 up_hook.sh
1577
 
1614
 
1578
   # TODO make a systemd service to run ./l2tp_broker.py l2tp_broker.cfg
1615
   # TODO make a systemd service to run ./l2tp_broker.py l2tp_broker.cfg
1579
 
1616
 
1617
+  if ! grep -q "Mesh Networking (B.A.T.M.A.N)" /home/$MY_USERNAME/README; then
1618
+      echo '' >> /home/$MY_USERNAME/README
1619
+      echo '' >> /home/$MY_USERNAME/README
1620
+      echo 'Mesh Networking (B.A.T.M.A.N)' >> /home/$MY_USERNAME/README
1621
+      echo '=============================' >> /home/$MY_USERNAME/README
1622
+      echo "BATMAN IPv6 address: $BATMAN_IPV6" >> /home/$MY_USERNAME/README
1623
+  fi
1624
+
1580
   echo 'mesh_batman' >> $COMPLETION_FILE
1625
   echo 'mesh_batman' >> $COMPLETION_FILE
1581
 }
1626
 }
1582
 
1627