[bug] WireGuard backend renders IPv6 peer endpoints without brackets

Aperta Adatta ai principianti
#443 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
networking

Direzione di ricerca

Il bug si trova in netjsonconfig/backends/wireguard/converters.py, che costruisce il valore Endpoint come f"{host}:{port}". Inizia eseguendo la riproduzione dalla issue per confermare che un endpoint_host IPv6 viene reso senza parentesi quadre. È completato quando gli endpoint IPv6 vengono resi come [addr]:port, gli IPv4 e i nomi host restano invariati e il parsing rimuove di nuovo le parentesi quadre. Confrontati prima con i maintainer, perché l'autore vuole attendere il merge della PR #441, che tocca lo stesso converter.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug
When a WireGuard peer's endpoint_host is an IPv6 address, the WireGuard backend renders
Endpoint without square brackets, which wg rejects.

Steps To Reproduce

from netjsonconfig import Wireguard
Wireguard({"wireguard": [{
    "name": "wg0", "port": 51820, "address": "10.0.0.1/24",
    "private_key": "QFdbnuYr7rVVt3rIzDQHIjJvl3Z9IrDM1W/0oBYPThg=",
    "peers": [{
        "public_key": "94a+MnZSdzHCzOy5y2K+0+Xe7lQzaa4v7lEiBZ7elVE=",
        "allowed_ips": "10.0.0.2/32",
        "endpoint_host": "2001:db8::1",
        "endpoint_port": 51820,
    }],
}]}).render()

renders Endpoint = 2001:db8::1:51820.

Expected behavior
Endpoint = [2001:db8::1]:51820 (WireGuard requires brackets for IPv6 endpoints, see wg(8)).

Cause
netjsonconfig/backends/wireguard/converters.py builds the value as f"{host}:{port}".
The OpenWrt backend is not affected because it writes host and port as separate UCI options.

Possible fix
Add the brackets when endpoint_host is an IPv6 address (and strip them when parsing).
I noticed this while working on #441, which adds the WireGuard parser; since the fix touches the
same converter, I'd send it after #441, if this is confirmed.

Lingua principale
Python
Stelle
390
Fork
98
Merge medio
20h 17m
PR unite (30g)
13

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openwisp/netjsonconfig

Tutte le issue di openwisp/netjsonconfig

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.