From 5541ca3faf4e0100cd64e79022d4c0a4eed658fd Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 30 Sep 2024 18:49:07 +0200 Subject: [PATCH] wireguard-functions.pl: Store networks in CIDR notation only wg(8) does not accept anything else. Signed-off-by: Michael Tremer --- config/cfgroot/wireguard-functions.pl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/config/cfgroot/wireguard-functions.pl b/config/cfgroot/wireguard-functions.pl index fe3abb719..ef8bf9b0c 100644 --- a/config/cfgroot/wireguard-functions.pl +++ b/config/cfgroot/wireguard-functions.pl @@ -228,8 +228,20 @@ sub decode_remarks($) { sub encode_subnets($) { my @subnets = @_; + my @formatted = (); + + # wg only handles the CIDR notation + foreach my $subnet (@subnets) { + my $netaddr = &Network::get_netaddress($subnet); + my $prefix = &Network::get_prefix($subnet); + + next unless (defined $netaddr && defined $prefix); + + push(@formatted, "${netaddr}/${prefix}"); + } + # Join subnets together separated by | - return join("|", @subnets); + return join("|", @formatted); } sub decode_subnets($) { -- 2.39.5