mirror of
https://git.disroot.org/pranav/pybatmesh.git
synced 2024-12-24 17:19:46 +05:30
Updated rewrite and README.md
The rewrite is partly over, with only the iwd part remaining. The README was updated and a commented-out section which had no comment closing tag was fixed.
This commit is contained in:
parent
8aeacb0ecb
commit
715f4b7308
13
Makefile
13
Makefile
@ -3,7 +3,14 @@ PREFIX := /usr
|
||||
install: naxalnet
|
||||
install -d $(DESTDIR)$(PREFIX)/bin
|
||||
install -d $(DESTDIR)$(PREFIX)/lib/systemd/system/
|
||||
install naxalnet@.service $(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/
|
||||
install -d $(DESTDIR)$(PREFIX)/share/naxalnet/networkd
|
||||
install systemd-networkd/* $(DESTDIR)$(PREFIX)/share/naxalnet/networkd
|
||||
|
||||
testdeps:
|
||||
@for i in networkctl systemctl python3; do \
|
||||
echo "Checking for $$i"; \
|
||||
which $$i > /dev/null && echo " $$i found" || \
|
||||
(echo " $$i not found"; exit 1); \
|
||||
done
|
||||
|
45
README.md
45
README.md
@ -31,17 +31,18 @@ into networkd's runtime configuration directory. It uses iwctl to start
|
||||
an ad-hoc network named "Hello World". The wireless interface is linked to
|
||||
`bat0`, the batman interface. A bridge `bridge0` is created so that other
|
||||
devices such as wired connections and wireless ap can be bridged. `bat0` is
|
||||
added to the bridge, and the bridge gets an ip address (link-local, or DHCP if
|
||||
any of the computers have a DHCP server configured). If these were successful,
|
||||
an intranet is created. You can now use services like [IPFS](https://ipfs.io),
|
||||
[Jami](https://jami.net), [Secure Scuttlebutt](https://scuttlebutt.nz)
|
||||
and others which can work without internet access.
|
||||
added to the bridge, and the bridge gets an ip address (link-local, or
|
||||
DHCP if any of the computers have a DHCP server configured). If these
|
||||
were successful, an intranet is created. You can now use services
|
||||
like [IPFS](https://ipfs.io), [Jami](https://jami.net),
|
||||
[Secure Scuttlebutt](https://scuttlebutt.nz) and others which can work
|
||||
without internet access.
|
||||
|
||||
## Requirements
|
||||
|
||||
- systemd v248 or more (for batman support)
|
||||
- Linux kernel with batman-adv module (if `modinfo batman-adv` shows no error
|
||||
then you already have it)
|
||||
- Linux kernel with batman-adv module (if `modinfo batman-adv` shows
|
||||
no error then you already have it)
|
||||
- iwd (for starting ad-hoc network)
|
||||
- wifi adapter with ad-hoc support
|
||||
- two or more computers with wifi adapter
|
||||
@ -55,12 +56,10 @@ Clone the repo and cd into it.
|
||||
Run `sudo make install` to install naxalnet. This will install naxalnet in
|
||||
`/usr/{bin/naxalnet,share/naxalnet/,lib/systemd/system/naxalnet@.service}`.
|
||||
|
||||
<!-- commented out as you'll have to edit the systemd service for this to work
|
||||
To install in /usr/local instead, use `sudo make install PREFIX=/usr/local`.
|
||||
|
||||
After installing, reload systemd so that you can enable `naxalnet@.service`
|
||||
without rebooting:
|
||||
```
|
||||
|
||||
```sh
|
||||
sudo systemctl daemon-reload
|
||||
```
|
||||
|
||||
@ -76,24 +75,28 @@ sudo systemctl disable --now NetworkManager
|
||||
|
||||
Enable the naxalnet service on the device `wlan0` (iwd replaces interface
|
||||
names like wlp1s0 with wlan0):
|
||||
|
||||
```
|
||||
sudo systemctl enable --now naxalnet@wlan0.service
|
||||
sudo systemctl enable --now naxalnet.service
|
||||
```
|
||||
|
||||
Now naxalnet will configure a batman interface on every boot.
|
||||
|
||||
## Uninstalling
|
||||
|
||||
Currently there is now way to uninstall naxalnet than to manually removing
|
||||
Currently there is now way to uninstall naxalnet than manually removing
|
||||
the files:
|
||||
|
||||
```sh
|
||||
sudo rm -rf /usr/{bin,share}/naxalnet \
|
||||
/usr/lib/systemd/system/naxalnet.service
|
||||
```
|
||||
sudo rm -r /usr/{bin/naxalnet,share/naxalnet/,lib/systemd/system/naxalnet@.service}
|
||||
|
||||
If you were using NetworkManager before, enable it:
|
||||
|
||||
```sh
|
||||
sudo systemctl enable --now NetworkManager.service
|
||||
```
|
||||
<!--
|
||||
Or if you installed naxalnet in /usr/local:
|
||||
```
|
||||
sudo rm -r /usr/local/{bin/naxalnet,share/naxalnet/,lib/systemd/system/naxalnet@.service}
|
||||
```
|
||||
-->
|
||||
|
||||
## TODO
|
||||
|
||||
@ -101,4 +104,4 @@ sudo rm -r /usr/local/{bin/naxalnet,share/naxalnet/,lib/systemd/system/naxalnet@
|
||||
|
||||
Add list of things here.
|
||||
|
||||
This project is in pre-alpha stage. Documentation is incomplete.
|
||||
This project is in alpha stage. Documentation is incomplete.
|
||||
|
79
naxalnet
79
naxalnet
@ -5,44 +5,67 @@ Setup a working BATMAN Advanced network
|
||||
with systemd-networkd and iwd
|
||||
"""
|
||||
|
||||
# for linking resolv.conf
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from shutil import copy
|
||||
from dasbus.connection import SystemMessageBus
|
||||
|
||||
SYSTEMD_RESOLVED_STUB_RESOLVE = "/run/systemd/resolve/stub-resolv.conf"
|
||||
NETWORKD_CONFIGS = "/usr/share/naxalnet/networkd"
|
||||
NETWORKD_VOLATILE_DIR = "/run/systemd/network"
|
||||
RESOLVED_STUB_RESOLVE = "/run/systemd/resolve/stub-resolv.conf"
|
||||
RESOLV_CONF = "/etc/resolv.conf"
|
||||
|
||||
|
||||
def get_all_devices(proxy):
|
||||
"""
|
||||
Returns d-bus object path of all devices as a list of strings.
|
||||
proxy: usually what is returned by bus.get_proxy('net.connman.iwd','/')
|
||||
"""
|
||||
# Gets all D-Bus objects in the proxy.
|
||||
objects = proxy.GetManagedObjects()
|
||||
|
||||
# Now find out which of them are devices
|
||||
devices = []
|
||||
for name, obj in objects.items():
|
||||
if "net.connman.iwd.Device" in obj:
|
||||
# add all devices to the list
|
||||
devices.append(name)
|
||||
|
||||
return devices
|
||||
|
||||
|
||||
# Copy networkd configs
|
||||
|
||||
|
||||
# syslink resolvd
|
||||
# Copy networkd configs to volatile dir.
|
||||
# See man:systemd.networkm(5)
|
||||
try:
|
||||
Path(RESOLV_CONF).symlink_to(SYSTEMD_RESOLVED_STUB_RESOLVE)
|
||||
except FileExistsError:
|
||||
print("Resolv.conf already exists")
|
||||
print("Copying network config files")
|
||||
dest = Path(NETWORKD_VOLATILE_DIR)
|
||||
src = Path(NETWORKD_CONFIGS)
|
||||
|
||||
# Create the volatile directory if it doesn't exist
|
||||
dest.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Copy all files in src to dest
|
||||
for i in src.iterdir():
|
||||
copy(i, dest)
|
||||
except:
|
||||
sys.exit("An error occured")
|
||||
|
||||
|
||||
# Symlink resolvd.conf to systemd's stub-resolvd.conf
|
||||
# This is needed for DNS resolution to work.
|
||||
# see https://wiki.archlinux.org/title/Systemd-resolved#DNS
|
||||
try:
|
||||
print("Checking resolv.conf")
|
||||
r = Path(RESOLV_CONF)
|
||||
if r.exists():
|
||||
print(r, "already exists. Removing it")
|
||||
r.unlink()
|
||||
print("Linking resolv.conf")
|
||||
r.symlink_to(RESOLVED_STUB_RESOLVE)
|
||||
except:
|
||||
sys.exit("An error occured while linking resolv.conf")
|
||||
|
||||
|
||||
# connect to the System bus
|
||||
bus = SystemMessageBus()
|
||||
# iwd proxy
|
||||
proxy = bus.get_proxy("net.connman.iwd", "/")
|
||||
iwd = bus.get_proxy("net.connman.iwd", "/")
|
||||
|
||||
# Get list of all devices
|
||||
print("Finding connected devices")
|
||||
objects = iwd.GetManagedObjects()
|
||||
device_paths = []
|
||||
for name, obj in objects.items():
|
||||
if "net.connman.iwd.Device" in obj:
|
||||
# add all devices to the list
|
||||
print("Found device:", obj["net.connman.iwd.Device"]["Name"])
|
||||
device_paths.append(name)
|
||||
|
||||
|
||||
# TODO: On first devices, start ad-hoc
|
||||
# If there is a second device, start AP
|
||||
# in it
|
||||
|
||||
print("Bye")
|
||||
|
Loading…
Reference in New Issue
Block a user