A small daemon that automates adding and removing dn42 peers, and provides a simple API.
The program uses a bundled version of SQLite, so a C compiler is required.
You can use cargo-zigbuild to easily build the musl version.
cargo zigbuild --release --target x86_64-unknown-linux-musl
- Linux with
systemdor Alpine Linux wireguard-tools-openrcpackage installed(for Alpine Linux)wg-quickis available- BIRD2 installed
- Run as root (or grant sufficient permissions to complete all operations)
The program assumes that you have a /etc/bird/peers folder based on the BIRD2 configuration from the DN42 wiki.
It does the following:
- Writes peer info to
peers.db - Generates WireGuard and BIRD configurations and places them in
/etc/wireguardand/etc/bird/peers - On systemd-based Linux, runs
systemctl start wg-quick@<interface_name>to start the tunnel andsystemctl enable wg-quick@<interface_name>to enable autostart - On Alpine Linux (OpenRC), create per-interface symlink
ln -s /etc/init.d/wg-quick /etc/init.d/wg-quick.<interface_name>, then runrc-service wg-quick.<interface_name> startto start the tunnel andrc-update add wg-quick.<interface_name> defaultto enable autostart - Runs
birdc configureto reload the BIRD configuration
The templates are limited to using WireGuard tunnels and BIRD with MP-BGP. This is currently the popular peering method in the DN42 community.
I have only tested on Debian and Alpine Linux.
Fill in config.toml
- Base URL:
http://<listen_address>:<api_port> - Auth: add
Authorization: Bearer <secret>whenAPI.secretis set. If the header is missing or invalid, the response is401 Unauthorizedwith bodyUnauthorized.
curl -sS -X POST http://127.0.0.1:4242/add \
-H "Authorization: Bearer $SECRET" \
-H "Content-Type: application/json" \
-d '{
"asn": 4242421234,
"wireguard_endpoint": null,
"wireguard_link_local": "fe80::beef",
"wireguard_public_key": "<peer_public_key>",
"wireguard_preshared_key": "<optional_preshared_key>",
"mtu": 1420
}'Notes on Optional Fields:
wireguard_endpoint: (Optional) If omitted or set tonull, the daemon configures the connection in passive mode (it listens for incoming connections but does not actively connect). If a valid endpoint address is provided (e.g.,"peer.example.net:51820"), it operates in active mode. Empty strings or invalid formats are rejected.wireguard_preshared_key: (Optional) If omitted or set tonull, the connection will be established without a Pre-Shared Key. If a valid 32-byte Base64 encoded key is provided, the WireGuard configuration will utilize it (PresharedKey). Empty strings ("") or incorrectly formatted keys are rejected.
Responses:
200 OK400 Bad Request401 Unauthorized409 Conflict500 Internal Server Error
Curl:
curl -sS -X POST http://127.0.0.1:4242/del \
-H "Authorization: Bearer $SECRET" \
-H "Content-Type: application/json" \
-d '{ "asn": 4242421234 }'Responses:
200 OK400 Bad Request401 Unauthorized404 Not Found500 Internal Server Error
Curl:
curl -sS -X POST http://127.0.0.1:4242/get \
-H "Authorization: Bearer $SECRET" \
-H "Content-Type: application/json" \
-d '{ "asn": 4242421234 }'Responses:
200 OKheader:Content-Type: application/json; charset=utf-8; body is the peer object:{ "asn": 4242420253, "wireguard_endpoint": null, "wireguard_link_local": "fe80::abcd", "wireguard_public_key": "<peer_public_key>", "wireguard_preshared_key": null, "mtu": 1420 }400 Bad Request401 Unauthorized404 Not Found500 Internal Server Error