wireguard: Upgrade app to add IPv6 for server and its peers

Tests:

- Install WireGuard app without patches. Create a few clients. Both the server
and the clients don't have IPv6 addresses assigned to them. Apply the patches.
Restart FreedomBox. WireGuard app setup is run. Server gets an IPv6 address and
so do the clients.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2026-11-27 07:21:06 -05:00
1 parent d4340dc903
commit 006e3ae18a
2 files changed
+40 -2

No files matched your search

+4 -1
View File
@@ -37,7 +37,7 @@ class WireguardApp(app_module.App):
app_id = 'wireguard'
_version = 2
_version = 3
def __init__(self) -> None:
"""Create components for the app."""
@@ -95,6 +95,9 @@ class WireguardApp(app_module.App):
def setup(self, old_version):
"""Install and configure the app."""
super().setup(old_version)
if old_version and old_version <= 2:
utils.upgrade_server()
if not old_version:
self.enable()
+36 -1
View File
@@ -4,9 +4,10 @@
import datetime
import itertools
import logging
import socket
import subprocess
import time
from ipaddress import IPv4Address, IPv6Address
from ipaddress import IPv4Address, IPv6Address, ip_interface
from typing import Tuple
from freedombox import app as app_module
@@ -327,6 +328,40 @@ def setup_server():
logging.warning('Could not add server')
def upgrade_server():
"""Upgrade server to add IPv6 address."""
info = get_info()
if info['my_server']['ipv6_address']:
return
connection = _server_connection()
# Add an IPv6 address to server
settings_ipv6 = connection.get_setting_ip6_config()
ip_address = nm.IPAddress.new(socket.AF_INET6, str(_IPV6_ADDRESS), 128)
settings_ipv6.add_address(ip_address)
settings_ipv6.set_property(nm.SETTING_IP_CONFIG_METHOD,
nm.SETTING_IP6_CONFIG_METHOD_MANUAL)
# Add an IPv6 address to all clients
setting_name = nm.SETTING_WIREGUARD_SETTING_NAME
settings = connection.get_setting_by_name(setting_name)
for peer_index in range(settings.get_peers_len()):
peer = settings.get_peer(peer_index)
if peer.get_allowed_ips_len() == 1:
allowed_ip = ip_interface(peer.get_allowed_ip(0))
if allowed_ip.ip.version == 4:
number = int(str(allowed_ip.ip).rpartition('.')[2])
ipv6_address = _IPV6_ADDRESS + number - 1
new_peer = peer.new_clone(True)
new_peer.append_allowed_ip(str(ipv6_address), False)
settings.set_peer(new_peer, peer_index)
connection.commit_changes_async(True)
network.reactivate_connection(connection.get_uuid())
def get_next_available_ip_addresses(
settings=None) -> Tuple[IPv4Address, IPv6Address]:
"""Get the next available IPv4/IPv6 address to allocate to a client."""