diff --git a/Batman_setup_scripts/batman b/Batman_setup_scripts/batman new file mode 100644 index 0000000..746f2e8 --- /dev/null +++ b/Batman_setup_scripts/batman @@ -0,0 +1,23 @@ +# If not set, all the interfaces is used. +interface=bat0 + +# To disable dnsmasq's DNS server functionality. +#port=0 + +# Local domain +local=/batnet/ + +# To enable dnsmasq's DHCP server functionality. +dhcp-range=192.168.143.2,192.168.143.150,64d + +# Set static IPs of other PCs and the Router. +dhcp-host=aa:04:4b:5a:c1:a9,gate,192.168.143.1,infinite # Router +dhcp-host=aa:04:4b:66:2c:de,othertx,192.168.143.100,infinite # Other TX +#dhcp-host=98:3b:8f:c6:7a:a5,rover0,192.168.143.159,infinite + +# Set gateway as Router. Following two lines are identical. +#dhcp-option=option:router,192.168.0.1 +dhcp-option=3,192.168.143.1 + +# Set DNS server as Router. +dhcp-option=6,192.168.143.1 \ No newline at end of file diff --git a/Batman_setup_scripts/batman-cl@.service b/Batman_setup_scripts/batman-cl@.service new file mode 100644 index 0000000..1a93038 --- /dev/null +++ b/Batman_setup_scripts/batman-cl@.service @@ -0,0 +1,24 @@ +[Unit] +Description=Mesh creation +Wants=network.target sys-subsystem-net-devices-wlan0.device +After=sys-subsystem-net-devices-wlan0.device + +[Service] +RemainAfterExit=yes +ExecStartPre=/sbin/modprobe batman-adv +ExecStartPre=/sbin/ip link set up mtu 1500 dev %I +ExecStartPre=/sbin/iw %I set type ibss +ExecStartPre=/sbin/iw %I ibss join NVIDIA 5220 ca:92:26:4b:32:5a +ExecStartPre=/usr/local/sbin/batctl if add %I +ExecStartPre=/sbin/ip link set up mtu 1460 dev bat0 +#ExecStartPre=/usr/local/bin/copymac.sh %I +ExecStart=/sbin/dhclient -4 -v -pf /run/dhclient.bat0.pid -lf /var/lib/dhcp/dhclient.bat0.leases bat0 +ExecStop=/sbin/ip link set %I down +ExecStop=/sbin/ip addr flush dev %I +ExecStop=/sbin/iw %I set type managed +ExecStop=/sbin/rmmod batman-adv +Restart=on-failure +RestartSec=10 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/Batman_setup_scripts/batman.service b/Batman_setup_scripts/batman.service new file mode 100644 index 0000000..86310e1 --- /dev/null +++ b/Batman_setup_scripts/batman.service @@ -0,0 +1,32 @@ +[Unit] +Description=Batman gateway creation +After=network.target sys-subsystem-net-devices-wlan0.device +Wants=network.target sys-subsystem-net-devices-wlan0.device + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStartPre=/sbin/sysctl -w net.ipv4.ip_forward=1 +ExecStartPre=/sbin/ip link set up mtu 1560 dev wlan0 +ExecStartPre=/sbin/iw wlan0 set type ibss +ExecStartPre=/sbin/iw dev wlan0 ibss join NVIDIA 5180 ca:92:26:4b:32:5a +ExecStart=/usr/local/sbin/batctl if add wlan0 +ExecStart=/sbin/ip link set bat0 up +#ExecStart=/usr/local/sbin/batctl gw_mode server +ExecStart=/sbin/ip addr add 192.168.143.1/24 broadcast 192.168.143.255 dev bat0 +ExecStartPost=/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE +ExecStartPost=/sbin/iptables -A FORWARD -i eth0 -o bat0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT +ExecStartPost=/sbin/iptables -A FORWARD -i bat0 -o eth0 -j ACCEPT +ExecStop=/bin/echo 0 > /proc/sys/net/ipv4/ip_forward +ExecStop=/sbin/ip link set down wlan0 +ExecStop=/sbin/ip link set down bat0 +ExecStop=/sbin/ip addr flush dev bat0 +ExecStop=/sbin/ip route flush dev bat0 +ExecStop=/sbin/iw wlan0 set type managed +ExecStop=/sbin/iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE +ExecStop=/sbin/iptables -D FORWARD -i eth0 -o bat0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT +ExecStop=/sbin/iptables -D FORWARD -i bat0 -o eth0 -j ACCEPT +ExecStop=/sbin/sysctl -w net.ipv4.ip_forward=0 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/Batman_setup_scripts/copymac.sh b/Batman_setup_scripts/copymac.sh new file mode 100644 index 0000000..35f7783 --- /dev/null +++ b/Batman_setup_scripts/copymac.sh @@ -0,0 +1,2 @@ + +/sbin/ifconfig bat0 hw ether `/sbin/ifconifg $1 | grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}' | sed 's/..\(:..:..:..:..:..\)/aa\1/'` \ No newline at end of file diff --git a/Batman_setup_scripts/install_batman.sh b/Batman_setup_scripts/install_batman.sh new file mode 100644 index 0000000..9b76a35 --- /dev/null +++ b/Batman_setup_scripts/install_batman.sh @@ -0,0 +1,32 @@ +# /bin/bash + +VERSION=2020.4 + +apt-get install build-essential +apt-get install linux-headers-$(uname -r) +apt-get install pkg-config +apt-get install libnl-3-dev + +wget http://downloads.open-mesh.org/batman/releases/batman-adv-$VERSION/batman-adv-$VERSION.tar.gz +tar -xzf batman-adv-$VERSION.tar.gz +cd batman-adv-$VERSION/ +make +make install +cd .. +rm -rf batman-adv-$VERSION* + +wget http://downloads.open-mesh.org/batman/releases/batman-adv-$VERSION/batctl-$VERSION.tar.gz +tar -xzf batctl-$VERSION.tar.gz +cd batctl-$VERSION/ +make +make install +cd .. +rm -rf batctl-$VERSION* + +wget http://downloads.open-mesh.org/batman/stable/sources/alfred/alfred-$VERSION.tar.gz +tar -xzf alfred-$VERSION.tar.gz +cd alfred-$VERSION/ +make CONFIG_ALFRED_GPSD=n +make CONFIG_ALFRED_GPSD=n install +cd .. +rm -rf alfred-$VERSION* \ No newline at end of file diff --git a/Batman_setup_scripts/override.conf b/Batman_setup_scripts/override.conf new file mode 100644 index 0000000..be55d80 --- /dev/null +++ b/Batman_setup_scripts/override.conf @@ -0,0 +1,7 @@ +[Unit] +Requires=network.target batman.service +After=batman.service + + +[Service] +Restart=on-failure \ No newline at end of file diff --git a/batman-README.md b/batman-README.md new file mode 100644 index 0000000..2bf82d2 --- /dev/null +++ b/batman-README.md @@ -0,0 +1,50 @@ +Make sure you have at least one node that is configured as a gateway to connect to the internet and to obtain ip through DHCP. + + + +## Prerequisite. +Please make sure the batman module exists, one could test it as follows: +On a Nvidia Tx1/Tx2 or a Xavier you might have to compile the batman module from source and install it. `install_batman.sh` script inside Batman_setup_scripts will do it, as long as kernel headers are present. Otherwise you might have to get them, you could also pass in the kernel header location to the make file, if the headers are in a non-standard location. + +``` +$ modprobe batman-adv +``` +Copy the file that creates a unique Hardware address for the bat0 virtual interface. +``` +$ sudo cp Batman_setup_scripts/copymac.sh /usr/local/bin/copymac.sh +$ sudo chmod +x /usr/local/bin/copymac.sh +$ +``` +Check following file and make sure both eth0 and wlan0 are disabled and commented out in +$ sudo nano /etc/network/interfaces + +Make sure the wlan0 or the other interface that you are using is set unmanaged with the network manager. + +``` +$ sudo nano /etc/NetworkManager/conf.d/10-managed-devices.conf +``` +Add the following the 10-managed-devices.conf file: + +``` +[keyfile] +unmanaged-devices=wlan0 + +``` + +## Setting up the batman node + +``` +$ sudo cp Batman_setup_scripts/batman-cl@.service /etc/systemd/system/batman-cl@.service +$ sudo systemctl enable batman-cl@wlan0 +``` + +## Setting up the gateway + +``` +$ sudo cp Batman_setup_scripts/batman.service /etc/systemd/system/batman.service +$ sudo cp Batman_setup_scripts/batman /etc/dnsmasq.d/batman +$ sudo cp Batman_setup_scripts/override.conf /etc/systemd/system/dnsmasq.service.d/override.conf +$ sudo systemctl enable batman +$ sudo systemctl enable batman +$ sudo systemctl enable dnsmasq +```