added files

This commit is contained in:
Pranav Jerry 2021-05-10 15:15:42 +05:30
parent 6c36fbdcca
commit b2727231d0
10 changed files with 206 additions and 1 deletions

11
Makefile Normal file
View File

@ -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/

View File

@ -1,3 +1,55 @@
# naxalnet
script to setup a batman-advanced network with systemd-networkd
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.
<!-- UNCOMMENT WHEN NECESSARY
**Disclaimer**:
In case you are either 1) a complete idiot; or 2) the prime minister of India;
or 3) both, please be aware that this project is not affiliated with
any groups designated as terrorist groups in India.
Using the name Naxal does not imply any form of connection
with anyone the government collectively calles Urban Naxals (human rights
activists, lawyers, poets, writers, journalists or anyone else
advocating the proper implementaion of constitutional or universal rights).
-->
## 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.

45
naxalnet Executable file
View File

@ -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"

10
naxalnet@.service Normal file
View File

@ -0,0 +1,10 @@
[Unit]
Description=Naxalnet on %i
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/naxalnet %i
[Install]
WantedBy=multi-user.target

View File

@ -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]

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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