Security hardening: fix 19 of 22 vulnerabilities found in audit

Critical:
- Trunk HMAC-SHA1 auth: MsgTrunkHello now carries nonce+digest,
  peer disconnected on secret mismatch (was loaded but never verified)

High:
- Pre-hello guard: reject all trunk messages before handshake completes
- CSPRNG for password generator: random.choice -> secrets.choice

Medium:
- Path traversal protection on callsign-based file operations
- Replace assert() on network-derived UDP data with error handling
- HTTP server connection throttling (matching main TCP server)
- try/catch on regex compilation in callsignOk()/emailOk()
- Per-link trunk talker tracking (clearAllTrunkTalkers scoped to peer)
- Regenerate priority nonce on each new trunk connection
- Cap active TGs and trunk talkers at 10000 each
- Don't reset heartbeat for unauthenticated client app messages
- Fix RENEW_AFTER integer division (2/3 -> 2.0/3.0)

Low:
- JSON-escape HTTP method in error response
- snprintf for pidfile error message
- MsgAuthResponse::digest() null check on empty vector
- Check unpack() return values in AsyncMsg.h vector/map/string
- Replace stack VLA with std::string; reserve+push_back vs resize
- Require TalkerStart before accepting trunk audio
This commit is contained in:
Audric committed 2026-03-20 11:54:18 +01:00
commit fca7c33794
276 files changed
+73533

No files matched your search

+277
View File
@@ -0,0 +1,277 @@
# Italy Deployment Example
This document describes a full national deployment for Italy using one GeuReflector
instance per region, trunked together in a full-mesh topology.
## Why the trunk is necessary
A standard SvxReflector instance is a single centralized server. Without trunking,
a national deployment has only two options:
**Option A — one national reflector:**
all 20 regions connect their nodes to a single server. This works, but only
**one talk group can be active at a time across the entire country**. While Lazio
is in QSO on the national TG, no other region can have a simultaneous independent
conversation. Every transmission from every region travels through the same server,
and a single server outage takes the whole network down.
**Option B — independent regional reflectors bridged by SvxLink instances:**
it is possible to link two reflectors together by running a SvxLink instance that
connects to both as a client node, acting as an audio bridge. However, each such
bridge instance can only handle one TG at a time, and one instance is needed per
pair of reflectors. For 20 regions in full mesh that is 190 SvxLink bridge
instances just to cover one shared TG — and multiplied again for every additional
TG that needs to be shared. The operational complexity, resource usage, and
failure surface of managing hundreds of bridge processes makes this approach
impractical at national scale.
**With GeuReflector trunks:**
each region runs its own independent reflector (resilience, local autonomy), and
the trunk links connect them so they can share TGs selectively. All 20 regional
TGs can carry simultaneous independent QSOs, while a dedicated national TG is
available to all. The trunk handles talker arbitration automatically when two
regions try to use a shared TG at the same time.
| | Single reflector | Independent reflectors | GeuReflector trunk mesh |
|---|---|---|---|
| Simultaneous regional QSOs | No — one TG at a time | Yes, but one bridge per TG per pair | Yes |
| Inter-region communication | Yes | Yes, but 190+ bridge processes | Yes |
| Regional autonomy | No | Yes | Yes |
| Single point of failure | Yes | No | No |
---
## TG numbering
The TG numbers used here are **inspired by the Italian DMR TG numbering scheme**,
which is already well thought out, widely adopted, and recognised across the
amateur radio community. Reusing this structure avoids reinventing a numbering
plan and makes the allocation immediately familiar to Italian operators.
**This SvxLink/GeuReflector system is entirely independent of DMR and is not
connected to any DMR network.** The TG numbers are used here purely as a
convenient and meaningful identifier space — no DMR radio, hotspot, or repeater
is involved.
The Italian DMR TG numbers all start with the national prefix `222`. That prefix
is stripped when setting `LOCAL_PREFIX`, so each reflector is configured with the
2-digit regional code only (e.g. TG `22201` → `LOCAL_PREFIX=01`).
Both `LOCAL_PREFIX` and `REMOTE_PREFIX` accept a comma-separated list of prefixes,
so a single reflector instance can own multiple regions
(e.g. `LOCAL_PREFIX=11,12,13` for Liguria, Piemonte and Valle d'Aosta).
---
## Reflector inventory
| Region | TG | LOCAL_PREFIX | Suggested hostname |
|---------------------------|---------|--------------|-------------------------------------|
| LAZIO | 22201 | 01 | svxref-lazio.example.it |
| SARDEGNA | 22202 | 02 | svxref-sardegna.example.it |
| UMBRIA | 22203 | 03 | svxref-umbria.example.it |
| LIGURIA | 22211 | 11 | svxref-liguria.example.it |
| PIEMONTE | 22212 | 12 | svxref-piemonte.example.it |
| VALLE D'AOSTA | 22213 | 13 | svxref-valledaosta.example.it |
| LOMBARDIA | 22221 | 21 | svxref-lombardia.example.it |
| FRIULI VENEZIA GIULIA | 22231 | 31 | svxref-friuli.example.it |
| TRENTINO ALTO ADIGE | 22232 | 32 | svxref-trentino.example.it |
| VENETO | 22233 | 33 | svxref-veneto.example.it |
| EMILIA ROMAGNA | 22241 | 41 | svxref-emilia.example.it |
| TOSCANA | 22251 | 51 | svxref-toscana.example.it |
| ABRUZZO | 22261 | 61 | svxref-abruzzo.example.it |
| MARCHE | 22262 | 62 | svxref-marche.example.it |
| PUGLIA | 22271 | 71 | svxref-puglia.example.it |
| BASILICATA | 22281 | 81 | svxref-basilicata.example.it |
| CALABRIA | 22282 | 82 | svxref-calabria.example.it |
| CAMPANIA | 22283 | 83 | svxref-campania.example.it |
| MOLISE | 22284 | 84 | svxref-molise.example.it |
| SICILIA | 22291 | 91 | svxref-sicilia.example.it |
---
## Topology
20 reflectors × 19 trunk links each = **190 trunk TCP connections** total (full mesh).
Every pair shares a unique `SECRET`. Port `5302` is used for all trunk connections;
port `5300` remains for SvxLink client nodes.
---
## Shared secrets convention
Each pair of reflectors shares one secret. Use a naming convention to keep them
organised, for example `IT_<PREFIX_A>_<PREFIX_B>` (lower prefix first):
```
IT_01_02 # LAZIO ↔ SARDEGNA
IT_01_03 # LAZIO ↔ UMBRIA
…
IT_84_91 # MOLISE ↔ SICILIA
```
---
## Configuration: LAZIO (complete example)
```ini
[GLOBAL]
LISTEN_PORT=5300
LOCAL_PREFIX=01
HTTP_SRV_PORT=8080
COMMAND_PTY=/dev/shm/reflector_ctrl
[TRUNK_02]
HOST=svxref-sardegna.example.it
PORT=5302
SECRET=IT_01_02
REMOTE_PREFIX=02
[TRUNK_03]
HOST=svxref-umbria.example.it
PORT=5302
SECRET=IT_01_03
REMOTE_PREFIX=03
[TRUNK_11]
HOST=svxref-liguria.example.it
PORT=5302
SECRET=IT_01_11
REMOTE_PREFIX=11
[TRUNK_12]
HOST=svxref-piemonte.example.it
PORT=5302
SECRET=IT_01_12
REMOTE_PREFIX=12
[TRUNK_13]
HOST=svxref-valledaosta.example.it
PORT=5302
SECRET=IT_01_13
REMOTE_PREFIX=13
[TRUNK_21]
HOST=svxref-lombardia.example.it
PORT=5302
SECRET=IT_01_21
REMOTE_PREFIX=21
[TRUNK_31]
HOST=svxref-friuli.example.it
PORT=5302
SECRET=IT_01_31
REMOTE_PREFIX=31
[TRUNK_32]
HOST=svxref-trentino.example.it
PORT=5302
SECRET=IT_01_32
REMOTE_PREFIX=32
[TRUNK_33]
HOST=svxref-veneto.example.it
PORT=5302
SECRET=IT_01_33
REMOTE_PREFIX=33
[TRUNK_41]
HOST=svxref-emilia.example.it
PORT=5302
SECRET=IT_01_41
REMOTE_PREFIX=41
[TRUNK_51]
HOST=svxref-toscana.example.it
PORT=5302
SECRET=IT_01_51
REMOTE_PREFIX=51
[TRUNK_61]
HOST=svxref-abruzzo.example.it
PORT=5302
SECRET=IT_01_61
REMOTE_PREFIX=61
[TRUNK_62]
HOST=svxref-marche.example.it
PORT=5302
SECRET=IT_01_62
REMOTE_PREFIX=62
[TRUNK_71]
HOST=svxref-puglia.example.it
PORT=5302
SECRET=IT_01_71
REMOTE_PREFIX=71
[TRUNK_81]
HOST=svxref-basilicata.example.it
PORT=5302
SECRET=IT_01_81
REMOTE_PREFIX=81
[TRUNK_82]
HOST=svxref-calabria.example.it
PORT=5302
SECRET=IT_01_82
REMOTE_PREFIX=82
[TRUNK_83]
HOST=svxref-campania.example.it
PORT=5302
SECRET=IT_01_83
REMOTE_PREFIX=83
[TRUNK_84]
HOST=svxref-molise.example.it
PORT=5302
SECRET=IT_01_84
REMOTE_PREFIX=84
[TRUNK_91]
HOST=svxref-sicilia.example.it
PORT=5302
SECRET=IT_01_91
REMOTE_PREFIX=91
```
All other regional configs follow the same pattern: set `LOCAL_PREFIX` to the
region's 2-digit code and add one `[TRUNK_xx]` section for each of the other
19 regions, using the matching `SECRET` from the convention above.
---
## Concurrent conversations
There is **no hardcoded limit** on concurrent QSOs over the trunk. The trunk
between each pair of reflectors is a single TCP connection that multiplexes all
active TGs simultaneously — each `MsgTrunkAudio` frame is tagged with the TG
number, so any number of TGs can carry audio at the same time.
The only per-TG rule is that **one talker is allowed per TG at a time**
(enforced by the arbitration logic). Multiple TGs can all have active talkers
simultaneously without interfering.
### Practical bandwidth estimate
| Codec | Bitrate per active TG | Concurrent TGs on a 1 Mbps trunk |
|-------|-----------------------|-----------------------------------|
| OPUS | ~8–16 kbps | ~60–125 |
| GSM | ~13 kbps | ~75 |
In this Italian deployment, even if all 20 regional TGs carried a simultaneous
QSO, the total trunk load per reflector would be well under 1 Mbps. Bandwidth
is not a concern at this scale; the limiting factor in practice is the number of
licensed operators active at any given time.
---
## Per-region config checklist
1. Set `LOCAL_PREFIX` to the 2-digit code from the table above.
2. Add one `[TRUNK_xx]` section for **every other region** (19 sections total).
3. Use the same `SECRET` value as the matching section on the peer — mismatched
secrets will prevent the trunk from connecting.
4. Open TCP port `5302` inbound in the firewall (trunk) and `5300` inbound (clients).
5. Ensure `HOST` resolves to the peer's public IP from the server's network.
+281
View File
@@ -0,0 +1,281 @@
# Esempio di deployment nazionale — Italia
Questo documento descrive un deployment nazionale completo per l'Italia utilizzando
un'istanza di GeuReflector per regione, interconnesse in una topologia a maglia
piena (full-mesh).
## Perché il trunk è necessario
Un'istanza standard di SvxReflector è un server centralizzato unico. Senza il
trunk, un deployment nazionale dispone di sole due opzioni:
**Opzione A — un unico reflector nazionale:**
tutte e 20 le regioni collegano i propri nodi a un singolo server. Funziona, ma
**un solo talk group può essere attivo alla volta sull'intera rete nazionale**.
Mentre il Lazio è in QSO sul TG nazionale, nessun'altra regione può avere una
conversazione indipendente simultanea. Ogni trasmissione di ogni regione transita
per lo stesso server, e un'interruzione di quel server abbatte l'intera rete.
**Opzione B — reflector regionali indipendenti collegati da istanze SvxLink:**
è possibile collegare due reflector facendo girare un'istanza di SvxLink che si
connette ad entrambi come nodo client, fungendo da ponte audio. Tuttavia, ogni
istanza-ponte può gestire un solo TG alla volta, e serve un'istanza per ogni
coppia di reflector. Per 20 regioni in full mesh occorrono già 190 istanze SvxLink
solo per coprire un singolo TG condiviso — moltiplicate ulteriormente per ogni TG
aggiuntivo che si vuole condividere. La complessità operativa, il consumo di
risorse e la superficie di guasto derivanti dalla gestione di centinaia di processi
ponte rendono questo approccio impraticabile su scala nazionale.
**Con il trunk GeuReflector:**
ogni regione gestisce il proprio reflector indipendente (resilienza, autonomia
locale) e i link trunk li interconnettono permettendo di condividere i TG in modo
selettivo. Tutti e 20 i TG regionali possono ospitare QSO indipendenti simultanei,
mentre un TG nazionale dedicato è accessibile a tutti. Il trunk gestisce
automaticamente l'arbitraggio quando due regioni tentano di usare un TG condiviso
nello stesso momento.
| | Reflector unico | Reflector indipendenti | Trunk mesh GeuReflector |
|---|---|---|---|
| QSO regionali simultanei | No — un TG alla volta | Sì, ma un ponte per TG per coppia | Sì |
| Comunicazione inter-regionale | Sì | Sì, ma 190+ processi ponte | Sì |
| Autonomia regionale | No | Sì | Sì |
| Singolo punto di guasto | Sì | No | No |
---
## Numerazione dei TG
La numerazione dei TG utilizzata in questo documento è **ispirata al piano di
numerazione DMR italiano**, già ben strutturato, ampiamente adottato e riconosciuto
dalla comunità dei radioamatori. Riutilizzare questa struttura evita di dover
inventare un piano di numerazione alternativo e rende l'allocazione immediatamente
familiare agli operatori italiani.
**Questo sistema SvxLink/GeuReflector è completamente indipendente dal DMR e non
è connesso ad alcuna rete DMR.** I numeri di TG sono utilizzati qui esclusivamente
come spazio di identificatori comodo e significativo — non sono coinvolti radio,
hotspot o ripetitori DMR di alcun tipo.
I TG DMR italiani iniziano tutti con il prefisso nazionale `222`. Questo prefisso
viene rimosso quando si imposta `LOCAL_PREFIX`, quindi ogni reflector viene
configurato con il solo codice regionale a 2 cifre (es. TG `22201` → `LOCAL_PREFIX=01`).
Sia `LOCAL_PREFIX` che `REMOTE_PREFIX` accettano un elenco separato da virgole,
quindi una singola istanza può gestire più regioni
(es. `LOCAL_PREFIX=11,12,13` per Liguria, Piemonte e Valle d'Aosta).
---
## Inventario dei reflector
| Regione | TG | LOCAL_PREFIX | Hostname suggerito |
|---------------------------|---------|--------------|-------------------------------------|
| LAZIO | 22201 | 01 | svxref-lazio.example.it |
| SARDEGNA | 22202 | 02 | svxref-sardegna.example.it |
| UMBRIA | 22203 | 03 | svxref-umbria.example.it |
| LIGURIA | 22211 | 11 | svxref-liguria.example.it |
| PIEMONTE | 22212 | 12 | svxref-piemonte.example.it |
| VALLE D'AOSTA | 22213 | 13 | svxref-valledaosta.example.it |
| LOMBARDIA | 22221 | 21 | svxref-lombardia.example.it |
| FRIULI VENEZIA GIULIA | 22231 | 31 | svxref-friuli.example.it |
| TRENTINO ALTO ADIGE | 22232 | 32 | svxref-trentino.example.it |
| VENETO | 22233 | 33 | svxref-veneto.example.it |
| EMILIA ROMAGNA | 22241 | 41 | svxref-emilia.example.it |
| TOSCANA | 22251 | 51 | svxref-toscana.example.it |
| ABRUZZO | 22261 | 61 | svxref-abruzzo.example.it |
| MARCHE | 22262 | 62 | svxref-marche.example.it |
| PUGLIA | 22271 | 71 | svxref-puglia.example.it |
| BASILICATA | 22281 | 81 | svxref-basilicata.example.it |
| CALABRIA | 22282 | 82 | svxref-calabria.example.it |
| CAMPANIA | 22283 | 83 | svxref-campania.example.it |
| MOLISE | 22284 | 84 | svxref-molise.example.it |
| SICILIA | 22291 | 91 | svxref-sicilia.example.it |
---
## Topologia
20 reflector × 19 trunk link ciascuno = **190 connessioni TCP trunk** in totale (full mesh).
Ogni coppia condivide un `SECRET` univoco. La porta `5302` è utilizzata per tutte
le connessioni trunk; la porta `5300` rimane riservata ai nodi client SvxLink.
---
## Convenzione per i secret condivisi
Ogni coppia di reflector condivide un secret. Si consiglia una convenzione di
denominazione come `IT_<PREFISSO_A>_<PREFISSO_B>` (prefisso minore per primo):
```
IT_01_02 # LAZIO ↔ SARDEGNA
IT_01_03 # LAZIO ↔ UMBRIA
…
IT_84_91 # MOLISE ↔ SICILIA
```
---
## Configurazione: LAZIO (esempio completo)
```ini
[GLOBAL]
LISTEN_PORT=5300
LOCAL_PREFIX=01
HTTP_SRV_PORT=8080
COMMAND_PTY=/dev/shm/reflector_ctrl
[TRUNK_02]
HOST=svxref-sardegna.example.it
PORT=5302
SECRET=IT_01_02
REMOTE_PREFIX=02
[TRUNK_03]
HOST=svxref-umbria.example.it
PORT=5302
SECRET=IT_01_03
REMOTE_PREFIX=03
[TRUNK_11]
HOST=svxref-liguria.example.it
PORT=5302
SECRET=IT_01_11
REMOTE_PREFIX=11
[TRUNK_12]
HOST=svxref-piemonte.example.it
PORT=5302
SECRET=IT_01_12
REMOTE_PREFIX=12
[TRUNK_13]
HOST=svxref-valledaosta.example.it
PORT=5302
SECRET=IT_01_13
REMOTE_PREFIX=13
[TRUNK_21]
HOST=svxref-lombardia.example.it
PORT=5302
SECRET=IT_01_21
REMOTE_PREFIX=21
[TRUNK_31]
HOST=svxref-friuli.example.it
PORT=5302
SECRET=IT_01_31
REMOTE_PREFIX=31
[TRUNK_32]
HOST=svxref-trentino.example.it
PORT=5302
SECRET=IT_01_32
REMOTE_PREFIX=32
[TRUNK_33]
HOST=svxref-veneto.example.it
PORT=5302
SECRET=IT_01_33
REMOTE_PREFIX=33
[TRUNK_41]
HOST=svxref-emilia.example.it
PORT=5302
SECRET=IT_01_41
REMOTE_PREFIX=41
[TRUNK_51]
HOST=svxref-toscana.example.it
PORT=5302
SECRET=IT_01_51
REMOTE_PREFIX=51
[TRUNK_61]
HOST=svxref-abruzzo.example.it
PORT=5302
SECRET=IT_01_61
REMOTE_PREFIX=61
[TRUNK_62]
HOST=svxref-marche.example.it
PORT=5302
SECRET=IT_01_62
REMOTE_PREFIX=62
[TRUNK_71]
HOST=svxref-puglia.example.it
PORT=5302
SECRET=IT_01_71
REMOTE_PREFIX=71
[TRUNK_81]
HOST=svxref-basilicata.example.it
PORT=5302
SECRET=IT_01_81
REMOTE_PREFIX=81
[TRUNK_82]
HOST=svxref-calabria.example.it
PORT=5302
SECRET=IT_01_82
REMOTE_PREFIX=82
[TRUNK_83]
HOST=svxref-campania.example.it
PORT=5302
SECRET=IT_01_83
REMOTE_PREFIX=83
[TRUNK_84]
HOST=svxref-molise.example.it
PORT=5302
SECRET=IT_01_84
REMOTE_PREFIX=84
[TRUNK_91]
HOST=svxref-sicilia.example.it
PORT=5302
SECRET=IT_01_91
REMOTE_PREFIX=91
```
Tutte le altre configurazioni regionali seguono lo stesso schema: impostare
`LOCAL_PREFIX` al codice a 2 cifre della propria regione e aggiungere una sezione
`[TRUNK_xx]` per ciascuna delle altre 19 regioni, usando il `SECRET` corrispondente
secondo la convenzione sopra indicata.
---
## Conversazioni simultanee
Non esiste **nessun limite fisso** al numero di QSO simultanei sul trunk. Il trunk
tra ogni coppia di reflector è una singola connessione TCP che multiplexa tutti i
TG attivi contemporaneamente — ogni frame `MsgTrunkAudio` è etichettato con il
numero di TG, quindi qualsiasi numero di TG può trasmettere audio nello stesso momento.
L'unica regola per TG è che **un solo operatore alla volta può trasmettere su un
dato TG** (gestito dalla logica di arbitraggio). Più TG possono avere trasmissioni
attive simultaneamente senza interferire.
### Stima della banda necessaria
| Codec | Bitrate per TG attivo | TG simultanei su un trunk da 1 Mbps |
|-------|-----------------------|--------------------------------------|
| OPUS | ~8–16 kbps | ~60–125 |
| GSM | ~13 kbps | ~75 |
In questo deployment italiano, anche se tutti e 20 i TG regionali fossero
simultaneamente in QSO, il carico totale sul trunk per ogni reflector rimarrebbe
ampiamente sotto 1 Mbps. La banda non è un fattore limitante a questa scala;
il vero limite pratico è il numero di operatori patentati attivi in un dato momento.
---
## Lista di controllo per ogni regione
1. Impostare `LOCAL_PREFIX` al codice a 2 cifre dalla tabella sopra.
2. Aggiungere una sezione `[TRUNK_xx]` per **ciascuna delle altre regioni** (19 sezioni in totale).
3. Usare lo stesso valore di `SECRET` della sezione corrispondente sul peer — secret
non corrispondenti impediranno la connessione del trunk.
4. Aprire la porta TCP `5302` in ingresso nel firewall (trunk) e la porta `5300` (client).
5. Verificare che `HOST` risolva all'IP pubblico del peer dalla rete del server.
+149
View File
@@ -0,0 +1,149 @@
# Running GeuReflector in Docker
This guide covers building a Docker image and running the reflector as a
container. The image uses a two-stage build: a full build environment compiles
the binary, then only the runtime libraries and the binary are copied into a
minimal `debian:bookworm-slim` image.
---
## Prerequisites
- Docker Engine ≥ 20.10
- Docker Compose v2 (the `docker compose` plugin, not the legacy `docker-compose`)
---
## Quick start
### 1. Prepare the config directory
```bash
mkdir config
cp /path/to/your/svxreflector.conf config/svxreflector.conf
```
The config file is mounted read-only into the container. Edit it on the host;
restart the container to apply changes (or use the PTY interface for live
user/password reloads — see below).
At minimum, add `LOCAL_PREFIX` and any `[TRUNK_x]` sections you need. See
[`docs/INSTALL.md`](INSTALL.md) for the config additions required for trunking.
### 2. Build and start
```bash
docker compose up -d
```
This builds the image on first run. To rebuild after a source change:
```bash
docker compose up -d --build
```
### 3. Check logs
```bash
docker compose logs -f
```
A healthy trunk connection appears as:
```
TRUNK_2: Connected to reflector-b.example.com:5302
TRUNK_2: Trunk hello from peer 'TRUNK_1' local_prefix=2 priority=3847291042
```
---
## Ports
| Port | Protocol | Purpose |
|------------|----------|----------------------------------------------|
| 5300 | TCP | SvxLink client connections |
| 5300 | UDP | SvxLink client audio |
| 5302 | TCP | Server-to-server trunk links |
| 8080 | TCP | HTTP `/status` endpoint (optional) |
If you do not set `HTTP_SRV_PORT` in the config, remove the `8080` port mapping
from `docker-compose.yml`.
---
## Volumes
| Mount point | Purpose |
|--------------------------------------|-------------------------------------------------|
| `/etc/svxlink/svxreflector.conf` | Configuration file (mount from host, read-only) |
| `/etc/svxlink/pki/` | TLS certificates and CA state (persistent) |
The `pki` volume persists certificates across container restarts. If you manage
certificates externally, you can remove this volume and mount your cert directory
directly instead.
---
## Live user/password reload (PTY interface)
The command PTY is available inside the container at `/dev/shm/reflector_ctrl`
(set by `COMMAND_PTY` in the config). Use `docker exec` to write to it:
```bash
docker compose exec svxreflector \
sh -c 'echo "CFG PASSWORDS MyNodes newpassword" > /dev/shm/reflector_ctrl'
```
---
## Building the image manually (without Compose)
```bash
docker build -t geureflector .
docker run -d \
--name svxreflector \
--restart unless-stopped \
-p 5300:5300/tcp \
-p 5300:5300/udp \
-p 5302:5302/tcp \
-p 8080:8080/tcp \
-v ./config/svxreflector.conf:/etc/svxlink/svxreflector.conf:ro \
-v svxreflector_pki:/etc/svxlink/pki \
geureflector
```
---
## Passing additional flags
The container entrypoint is `svxreflector`. Append any supported flags after
the service definition or in the `command:` key of `docker-compose.yml`:
```yaml
command: ["--config", "/etc/svxlink/svxreflector.conf", "--logfile", "/var/log/svxreflector.log"]
```
Available flags:
| Flag | Description |
|------|-------------|
| `--config <file>` | Config file path (default used by the image: `/etc/svxlink/svxreflector.conf`) |
| `--logfile <file>` | Redirect stdout/stderr to a file instead of the container log |
| `--runasuser <user>` | Drop privileges to the given user after startup |
| `--pidfile <file>` | Write PID to file (not normally needed in containers) |
Do **not** pass `--daemon` — Docker manages the process lifecycle.
---
## Updating
To update to a new version of the source:
```bash
git pull
docker compose up -d --build
```
The old container is replaced; the `pki` volume is preserved.
+206
View File
@@ -0,0 +1,206 @@
# Installing GeuReflector as a replacement for SvxReflector
This guide is for sysops who already have a working SvxReflector installation
and want to replace it with GeuReflector. The binary name, config format, and
systemd service are all compatible — the transition is a drop-in replacement
plus a few config additions.
---
## Prerequisites
- A working SvxReflector installation (any recent version)
- Build tools: `git`, `cmake` (≥ 3.7), `g++` with C++11 support
- Development libraries (same as SvxReflector itself):
```bash
# Debian/Ubuntu
sudo apt install build-essential cmake libsigc++-2.0-dev libssl-dev \
libjsoncpp-dev libpopt-dev
# Optional codec support
sudo apt install libopus-dev libgsm1-dev libspeex-dev
```
---
## 1. Get the source
```bash
git clone https://github.com/IW1GEU/geureflector.git
cd geureflector
```
---
## 2. Build
```bash
cmake -S src -B build -DLOCAL_STATE_DIR=/var
cmake --build build
```
The compiled binary is at `build/bin/svxreflector`.
---
## 3. Stop the running service
```bash
sudo systemctl stop svxreflector
```
---
## 4. Back up the original binary
Find where your current binary lives:
```bash
which svxreflector
# typically /usr/bin/svxreflector or /usr/local/bin/svxreflector
```
Back it up:
```bash
sudo cp /usr/bin/svxreflector /usr/bin/svxreflector.orig
```
---
## 5. Install the new binary
```bash
sudo cp build/bin/svxreflector /usr/bin/svxreflector
```
Use the same destination path you found in step 4.
---
## 6. Update the configuration
Your existing `/etc/svxlink/svxreflector.conf` works as-is — GeuReflector is
fully backwards compatible. The trunk features are opt-in: if you add nothing,
the reflector behaves exactly like the original.
To enable trunking, add two things:
### 6a. Declare this reflector's TG prefix
In the `[GLOBAL]` section:
```ini
[GLOBAL]
# ... existing settings ...
LOCAL_PREFIX=1 # this reflector owns TGs starting with "1"
```
A comma-separated list is accepted if this reflector covers multiple prefix
groups:
```ini
LOCAL_PREFIX=11,12,13
```
### 6b. Add a trunk section for each peer
At the end of the config file, add one `[TRUNK_x]` section per peer reflector:
```ini
[TRUNK_2]
HOST=reflector-b.example.com
PORT=5302
SECRET=a_strong_shared_secret
REMOTE_PREFIX=2
```
- `PORT` defaults to `5302` if omitted.
- Both sides of each trunk must use the same `SECRET`.
- `REMOTE_PREFIX` also accepts a comma-separated list.
### 6c. Optional: enable the HTTP status endpoint
```ini
[GLOBAL]
# ... existing settings ...
HTTP_SRV_PORT=8080
```
The `/status` endpoint will include a `trunks` object showing connection state
and active talkers per link.
---
## 7. Open the trunk port in the firewall
The trunk uses TCP port `5302` (separate from the client port `5300`).
```bash
# firewalld
sudo firewall-cmd --permanent --add-port=5302/tcp
sudo firewall-cmd --reload
# ufw
sudo ufw allow 5302/tcp
# iptables
sudo iptables -A INPUT -p tcp --dport 5302 -j ACCEPT
```
---
## 8. Start the service
```bash
sudo systemctl start svxreflector
sudo systemctl status svxreflector
```
---
## 9. Verify the trunk is working
Check the logs for the handshake message:
```bash
journalctl -u svxreflector -f
```
A successful trunk connection looks like:
```
TRUNK_2: Connected to reflector-b.example.com:5302
TRUNK_2: Trunk hello from peer 'TRUNK_1' local_prefix=2 priority=3847291042
```
If `HTTP_SRV_PORT` is set, query the status endpoint:
```bash
curl -s http://localhost:8080/status | python3 -m json.tool
```
The `trunks` object will show `"connected": true` for each active link.
---
## Rolling back
If anything goes wrong, restore the original binary and restart:
```bash
sudo systemctl stop svxreflector
sudo cp /usr/bin/svxreflector.orig /usr/bin/svxreflector
sudo systemctl start svxreflector
```
No config changes are needed to roll back — the original binary simply ignores
the `LOCAL_PREFIX` and `[TRUNK_x]` entries.
---
## Further reading
- [`docs/TRUNK_PROTOCOL.md`](TRUNK_PROTOCOL.md) — wire protocol specification
- [`docs/DEPLOYMENT_ITALY.md`](DEPLOYMENT_ITALY.md) — full national deployment
example with configuration for all regions
+328
View File
@@ -0,0 +1,328 @@
# GeuReflector — Server-to-Server Trunk Protocol
## Overview
GeuReflector extends SvxReflector with a server-to-server trunk protocol that
allows two or more independent reflector instances to share talk groups (TGs)
as simultaneous, independent voice channels — analogous to telephone trunk lines.
TGs are routed by **numeric prefix**: each reflector owns all TGs whose decimal
string representation starts with a configured digit string. For example, a
reflector configured with `LOCAL_PREFIX=1` is authoritative for TG 1, 10, 100,
1000, 12345, 19999999, etc. This is analogous to E.164 telephone numbering
(country codes, area codes).
Multiple reflectors can be trunked together in a full mesh. Each pair of
reflectors has one `[TRUNK_x]` section per side. Each TG has exactly one
authoritative home reflector (the one whose prefix matches); all other
reflectors are transparent proxies for that TG.
Clients (SvxLink nodes) connect to their local reflector as normal and are
completely unaware of the trunk. When a remote talker is active on a TG whose
prefix belongs to another reflector, local clients receive a standard
`MsgTalkerStart` with the remote node's callsign, indistinguishable from a
local talker.
---
## Architecture
```
SvxLink nodes SvxLink nodes SvxLink nodes
│ │ │
▼ ▼ ▼
Reflector 1 ◄──trunk──► Reflector 2 ◄──trunk──► Reflector 3
prefix "1" prefix "2" prefix "3"
└──────────────────────────────────────────────►┘
(full mesh)
```
Each reflector runs one `TrunkLink` instance per configured peer. The trunk
is a persistent outbound TCP connection from each reflector to its peer on a
dedicated port (default 5302, separate from the client port 5300).
---
## TG Ownership and Routing
A TG number belongs to the reflector whose `LOCAL_PREFIX` is a string prefix
of the TG's decimal representation:
| TG number | Decimal string | Owned by |
|-----------|---------------|----------|
| 1 | "1" | prefix "1" |
| 10 | "10" | prefix "1" |
| 100 | "100" | prefix "1" |
| 1234567 | "1234567" | prefix "1" |
| 2 | "2" | prefix "2" |
| 25 | "25" | prefix "2" |
| 30 | "30" | prefix "3" |
Ownership check: `std::to_string(tg).substr(0, prefix.size()) == prefix`
In a full mesh of N reflectors, each `[TRUNK_x]` section on reflector A points
at reflector B and carries only TGs whose decimal string starts with B's prefix
(`REMOTE_PREFIX`). No multi-hop routing is needed because every pair has a
direct trunk.
---
## Connection and Handshake
On TCP connect, both sides immediately send `MsgTrunkHello`. No challenge/response
is used; authentication relies on network-level access control (firewall rules)
and the shared secret validated at the application level in future versions.
```
Reflector A (prefix "1") Reflector B (prefix "2")
│──── MsgTrunkHello(id, local_prefix="1", priority) ──►│
│◀─── MsgTrunkHello(id, local_prefix="2", priority) ───│
│ (both sides ready) │
```
`MsgTrunkHello` carries:
- `id` — the config section name (e.g. `TRUNK_2`), used for logging
- `local_prefix` — the sender's authoritative TG prefix (e.g. `"1"`)
- `priority` — random 32-bit nonce generated at startup, used for tie-breaking
---
## Normal Talker Flow
When a local client starts transmitting on a TG owned by the peer:
```
Reflector A (owns prefix "1") Reflector B (owns prefix "2")
│ SM0ABC starts on TG 25 │
│ setTalkerForTG(25, SM0ABC) │
│──── MsgTrunkTalkerStart(25, "SM0ABC") ──►│
│ setTrunkTalkerForTG(25, "SM0ABC")
│ broadcast MsgTalkerStart(25, "SM0ABC") to B clients
│──── MsgTrunkAudio(25, <frame>) ─►│
│ broadcast MsgUdpAudio to B TG25 clients
│ (repeats for each audio frame) │
│──── MsgTrunkFlush(25) ──────────►│
│ setTalkerForTG(25, null) │
│──── MsgTrunkTalkerStop(25) ─────►│
│ clearTrunkTalkerForTG(25)
│ broadcast MsgTalkerStop(25, "SM0ABC") to B clients
│ broadcast MsgUdpFlushSamples to B TG25 clients
```
The reverse direction (B client talking on a TG owned by A) is symmetric.
---
## Talker Arbitration and Tie-Breaking
Each reflector arbitrates talkers independently for its own clients. The trunk
adds a second layer of arbitration for shared TGs.
**Normal case (one side talking at a time):** the first `MsgTrunkTalkerStart`
to arrive locks the TG on the receiving side. Local clients on that side cannot
grab the talker slot while the trunk lock is held — their audio packets are
silently dropped by the existing `talker != client` check in the reflector's
UDP handler.
**Simultaneous claim (both sides start at the same instant):** resolved using
the `priority` nonce exchanged in `MsgTrunkHello`:
- The side with the **lower** priority value wins
- The losing side calls `setTalkerForTG(tg, nullptr)` to clear its local talker,
then calls `setTrunkTalkerForTG(tg, peer_callsign)` to accept the remote claim
- The losing side suppresses the spurious `MsgTrunkTalkerStop` that would
otherwise be sent when the local talker is cleared (tracked via `m_yielded_tgs`)
---
## Local Client Arbitration Guard
In `Reflector::udpDatagramReceived()`, before accepting a new local talker on a
TG that is shared with any trunk, the reflector checks whether the trunk already
holds the TG:
```cpp
if ((talker == 0) && !TGHandler::instance()->hasTrunkTalker(tg))
{
TGHandler::instance()->setTalkerForTG(tg, client);
...
}
```
This single guard ensures that remote conversations are protected from
interruption by local clients.
---
## Keepalive / Heartbeat
Both sides send `MsgTrunkHeartbeat` periodically to keep the TCP connection
alive and detect peer disconnection:
- TX: sent when no other message has been sent for 10 timer ticks (10 s)
- RX timeout: connection torn down if no message received for 15 ticks (15 s)
On disconnect, all trunk talker locks are immediately released so local clients
are not left blocked. The `TcpPrioClient` infrastructure handles automatic
reconnection.
---
## Protocol Messages
All messages use the existing SvxReflector TCP framing: a serialized
`ReflectorMsg` header (containing the type field) followed by the message
payload, packed using the `ASYNC_MSG_MEMBERS` macro.
| Type | Name | Fields |
|------|-----------------------|--------------------------------------------------|
| 115 | `MsgTrunkHello` | `string id`, `string local_prefix`, `uint32 priority` |
| 116 | `MsgTrunkTalkerStart` | `uint32 tg`, `string callsign` |
| 117 | `MsgTrunkTalkerStop` | `uint32 tg` |
| 118 | `MsgTrunkAudio` | `uint32 tg`, `uint8[] audio` |
| 119 | `MsgTrunkFlush` | `uint32 tg` |
| 120 | `MsgTrunkHeartbeat` | *(no fields)* |
Type numbers 115–120 are chosen to follow the last existing SvxReflector TCP
message type (114 = `MsgStartUdpEncryption`) without collision.
Audio is transported over TCP (not UDP) — the trunk is a reliable server-to-server
link, not a lossy radio gateway path, so TCP framing is appropriate and avoids
the complexity of a separate UDP cipher channel.
---
## TGHandler Changes
Trunk talker state is stored separately from the `ReflectorClient*` talker
pointer in `TGHandler`, in a parallel `std::map<uint32_t, std::string>` keyed
by TG number. This avoids any refactoring of the existing `ReflectorClient`
type hierarchy.
New methods:
- `setTrunkTalkerForTG(tg, callsign)` — lock TG, emit `trunkTalkerUpdated` signal
- `clearTrunkTalkerForTG(tg)` — release lock on one TG
- `clearAllTrunkTalkers()` — release all locks (used on disconnect)
- `trunkTalkerForTG(tg)` — returns callsign or `""` if none
- `hasTrunkTalker(tg)` — returns bool, used in arbitration guard
- `trunkTalkersSnapshot()` — returns const ref to the map (for HTTP status)
New signal:
- `trunkTalkerUpdated(tg, old_callsign, new_callsign)` — connected to
`Reflector::onTrunkTalkerUpdated()` which broadcasts `MsgTalkerStart`/`Stop`
to local clients with the correct remote callsign
---
## HTTP Status
The `/status` JSON endpoint includes a `trunks` object alongside `nodes`:
```json
{
"nodes": { ... },
"trunks": {
"TRUNK_2": {
"host": "reflector-b.example.com",
"port": 5302,
"connected": true,
"local_prefix": "1",
"remote_prefix": "2",
"active_talkers": {
"25": "SM0ABC",
"200": "LA8PV"
}
}
}
}
```
`active_talkers` contains only TGs with an active remote talker at the moment
of the request. It is empty when no trunk conversations are in progress.
---
## Configuration
### Global setting (both reflectors)
Add `LOCAL_PREFIX` to the `[GLOBAL]` section. This declares which TG prefix
this reflector is authoritative for:
```ini
[GLOBAL]
...
LOCAL_PREFIX=1 # this reflector owns TGs 1, 10, 100, 1000, ...
```
### Per-trunk section
Add one `[TRUNK_x]` section per peer. `REMOTE_PREFIX` declares which TG prefix
the peer owns:
```ini
[TRUNK_2]
HOST=reflector-b.example.com # peer hostname or IP
PORT=5302 # peer trunk port (default 5302)
SECRET=change_this_secret # shared secret
REMOTE_PREFIX=2 # peer owns TGs 2, 20, 200, 2000, ...
```
### Full-mesh example (three reflectors)
**Reflector 1** (`LOCAL_PREFIX=1`):
```ini
[TRUNK_2]
HOST=reflector-b.example.com
SECRET=secret_ab
REMOTE_PREFIX=2
[TRUNK_3]
HOST=reflector-c.example.com
SECRET=secret_ac
REMOTE_PREFIX=3
```
**Reflector 2** (`LOCAL_PREFIX=2`):
```ini
[TRUNK_1]
HOST=reflector-a.example.com
SECRET=secret_ab
REMOTE_PREFIX=1
[TRUNK_3]
HOST=reflector-c.example.com
SECRET=secret_bc
REMOTE_PREFIX=3
```
**Reflector 3** (`LOCAL_PREFIX=3`):
```ini
[TRUNK_1]
HOST=reflector-a.example.com
SECRET=secret_ac
REMOTE_PREFIX=1
[TRUNK_2]
HOST=reflector-b.example.com
SECRET=secret_bc
REMOTE_PREFIX=2
```
---
## Files Changed vs Upstream SvxLink
| File | Change |
|------|--------|
| `src/svxlink/reflector/ReflectorMsg.h` | Added `MsgTrunkHello`–`MsgTrunkHeartbeat` (types 115–120); `MsgTrunkHello` carries `local_prefix` string instead of TG list |
| `src/svxlink/reflector/TGHandler.h` | Added trunk talker map, 5 methods + snapshot accessor, `trunkTalkerUpdated` signal |
| `src/svxlink/reflector/TGHandler.cpp` | Implemented trunk talker methods including `clearAllTrunkTalkers` |
| `src/svxlink/reflector/Reflector.h` | Added `m_trunk_links`, `initTrunkLinks()`, `onTrunkTalkerUpdated()` |
| `src/svxlink/reflector/Reflector.cpp` | Wired trunk init, signals, audio relay, arbitration guard, HTTP status |
| `src/svxlink/reflector/TrunkLink.h` | **New** — `TrunkLink` class declaration |
| `src/svxlink/reflector/TrunkLink.cpp` | **New** — full trunk link implementation |
| `src/svxlink/reflector/CMakeLists.txt` | Added `TrunkLink.cpp` to sources |
| `src/svxlink/reflector/svxreflector.conf.in` | Added prefix-based trunk example config |
| `src/versions` | Version bumped to `1.3.99.12+trunk1` |
| `src/svxlink/reflector/svxreflector.cpp` | Updated startup banner |