]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
wireguard-functions.pl: Store networks in CIDR notation only
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 30 Sep 2024 16:49:07 +0000 (18:49 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Apr 2025 14:48:53 +0000 (16:48 +0200)
wg(8) does not accept anything else.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/cfgroot/wireguard-functions.pl

index fe3abb7197382ebea6d1bd499c7d2b02727db457..ef8bf9b0ca1769840231d67ee26e9f9698abf4b0 100644 (file)
@@ -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($) {