diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f555506 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +ifeq ($(PREFIX),) + PREFIX := /usr +endif + +install: naxalnet + install -d $(DESTDIR)$(PREFIX)/bin + install -d $(DESTDIR)$(PREFIX)/lib/systemd/system/ + install naxalnet@.service $(DESTDIR)$(PREFIX)/lib/systemd/system/ + install naxalnet $(DESTDIR)$(PREFIX)/bin/ + install -d $(DESTDIR)$(PREFIX)/share/naxalnet + install systemd-networkd/* $(DESTDIR)$(PREFIX)/share/naxalnet/ diff --git a/README.md b/README.md index 011fc11..89f4c5f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,55 @@ # naxalnet -script to setup a batman-advanced network with systemd-networkd \ No newline at end of file +Naxalnet is an experiment to create an intranet and use it for +communicating during an internet shutdown. It tries to use +existing software and tech as much as possible. Currently +you can only communicate with other peers running the same software. + +The name naxal comes from Naxalbari, a village in Darjeeling, +West Bengal. + + + +## Requirements + +* systemd v248 or more +* Linux kernel (batman-adv only works on Linux) +* iwd +* wifi adapter with ad-hoc support + +Any network managers such as NetworkManager should be disabled: + +``` +sudo systemctl disable --now NetworkManager +``` + +## Installing + +Run `make install` to install naxalnet. + +Enable the naxalnet service on the device `wlan0`: + +``` +sudo systemctl enable naxalnet@wlan0.service +``` +Now naxalnet will configure a batman interface on every boot. + +## TODO + +- add support for wireless ap (WiFi hotspot) + +Add list of things here. + +This project is in pre-alpha stage. Documentation is incomplete. diff --git a/naxalnet b/naxalnet new file mode 100755 index 0000000..c4e109d --- /dev/null +++ b/naxalnet @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + + + +DATADIR="$(dirname "$0")/../share/naxalnet" +NETWORKD_DIR=/run/systemd/network +SSID="Hello World" + +if [[ $# != 1 ]] +then + echo "Usage: $0 {wireless device}" + echo "Example: $0 wlan0" + exit 1 +fi + +echo "creating and copying file to tmp dir" +TMPDIR=$(mktemp -d) +cd "$TMPDIR" +cp -r $DATADIR/* . + + +echo "Setting $1 as wireless device" +sed -i "s/{ADHOC_NETWORK}/$1/" *.network + +if [[ ! -d "$NETWORKD_DIR" ]] +then + mkdir "$NETWORKD_DIR" +fi + +echo "Copying systemd-networkd config files" +cp * "$NETWORKD_DIR" + +echo "Linking resolv.conf to resolved stub-resolved.conf" +ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf + +echo "Starting services" +systemctl reload-or-restart systemd-resolved iwd systemd-networkd + +# wait five seconds for iwd to start +sleep 5 +echo "Configuring iwd" +iwctl device $1 set-property Mode ad-hoc +iwctl ad-hoc $1 start_open "$SSID" + +echo "Done" diff --git a/naxalnet@.service b/naxalnet@.service new file mode 100644 index 0000000..3380768 --- /dev/null +++ b/naxalnet@.service @@ -0,0 +1,10 @@ +[Unit] +Description=Naxalnet on %i + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/bin/naxalnet %i + +[Install] +WantedBy=multi-user.target diff --git a/systemd-networkd/01-batman.netdev b/systemd-networkd/01-batman.netdev new file mode 100644 index 0000000..73b57f9 --- /dev/null +++ b/systemd-networkd/01-batman.netdev @@ -0,0 +1,9 @@ +# Create the BATMAN interface +[NetDev] +Name=bat0 +Description=BATMAN interface +Kind=batadv + +# Use default settings. Uncomment to change +# see man:systemd.netdev(5) § [BATMANADVANCED] SECTION OPTIONS +#[BatmanAdvanced] diff --git a/systemd-networkd/02-bridge.netdev b/systemd-networkd/02-bridge.netdev new file mode 100644 index 0000000..eded271 --- /dev/null +++ b/systemd-networkd/02-bridge.netdev @@ -0,0 +1,10 @@ +# Create a bridge interface +# The batman interface be will later linked to this bridge +[NetDev] +Name=bridge0 +Description=Bridge +Kind=bridge + +# uncomment to change the default settings +# see man:systemd.netdev(5) § [BRIDGE] SECTION OPTIONS +#[Bridge] diff --git a/systemd-networkd/03-wireless-ad-hoc.network b/systemd-networkd/03-wireless-ad-hoc.network new file mode 100644 index 0000000..cd47b29 --- /dev/null +++ b/systemd-networkd/03-wireless-ad-hoc.network @@ -0,0 +1,14 @@ +[Match] +# this line will be changed by sed +WLANInterfaceType={ADHOC_NETWORK} + +[Network] +Description=ad-hoc network connecting to other nodes +BatmanAdvanced=bat0 +# this interface should not have any ip addresses assigned +# ip will be given later to the bridge +DHCP=no +DHCPServer=no +LinkLocalAddressing=no +LLMNR=no +MulticastDNS=no diff --git a/systemd-networkd/04-batman.network b/systemd-networkd/04-batman.network new file mode 100644 index 0000000..4e17c61 --- /dev/null +++ b/systemd-networkd/04-batman.network @@ -0,0 +1,15 @@ +[Match] +Name=bat0 + +[Network] +Description=The BATMAN interface +Bridge=bridge0 + +# like in 03, this interface also shouldn't have ip address +# the address will be assigned to the bridge +DHCP=no +DHCPServer=no +LinkLocalAddressing=no +LLMNR=no +MulticastDNS=no + diff --git a/systemd-networkd/05-bridge.network b/systemd-networkd/05-bridge.network new file mode 100644 index 0000000..ff1f02f --- /dev/null +++ b/systemd-networkd/05-bridge.network @@ -0,0 +1,17 @@ +# this is the interface userspace applications will be using to +# communicate with others devices + +[Match] +Name=bridge0 + +[Network] +# use DHCP to assign an IP +DHCP=yes + +# if DHCP fails, assign a random address +LinkLocalAddressing=yes + +# LLMNR and MulticastDNS are used for hostname discovery +# on +LLMNR=yes +MulticastDNS=yes diff --git a/systemd-networkd/06-wireless-ap.network b/systemd-networkd/06-wireless-ap.network new file mode 100644 index 0000000..b00b1f2 --- /dev/null +++ b/systemd-networkd/06-wireless-ap.network @@ -0,0 +1,22 @@ +# This file links any interface in ap mode +# to the bridge we created earlier +# This file won't do anything if an ap interface is not found. + +[Match] +WLANInterfaceType=ap + +[Network] +Description=Wireless AP + +# link the interface to the bridge +Bridge=bridge0 + +# Like in the ad-hoc network and bat0, this interface +# should not have any ip address assigned to it. +# The address will be assigned to the bridge +DHCP=no +DHCPServer=no +LinkLocalAddressing=no +LLMNR=no +MulticastDNS=no +