Skip to content

[bug] WireGuard backend renders IPv6 peer endpoints without brackets #443

Backlog

Description

@rohanesor

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions