From: Michael Tremer Date: Fri, 6 Dec 2024 19:01:48 +0000 (+0100) Subject: wireguard-functions.pl: Unify fetching the endpoint X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6dcd2c24bba008952469414b6d560863793e6001;p=people%2Fms%2Fipfire-2.x.git wireguard-functions.pl: Unify fetching the endpoint Signed-off-by: Michael Tremer --- diff --git a/config/cfgroot/wireguard-functions.pl b/config/cfgroot/wireguard-functions.pl index a571f262e..553169af9 100644 --- a/config/cfgroot/wireguard-functions.pl +++ b/config/cfgroot/wireguard-functions.pl @@ -46,6 +46,18 @@ our %peers = (); "CLIENT_DNS" => $Network::ethernet{'GREEN_ADDRESS'}, }); +# Returns the local endpoint +sub get_endpoint() { + my $endpoint = $settings{'ENDPOINT'}; + + # If no endpoint is set, we fall back to the FQDN of the firewall + if ($endpoint eq "") { + $endpoint = $General::mainsettings{'HOSTNAME'} . "." . $General::mainsettings{'DOMAINNAME'}; + } + + return $endpoint; +} + # This function generates a set of keys for this host if none exist sub generate_keys($) { my $force = shift || 0; @@ -364,12 +376,8 @@ sub generate_net_configuration($$) { push(@allowed_ips, "${netaddress}/${prefix}"); } - my $endpoint = $settings{'ENDPOINT'}; - - # If no endpoint is set, we fall back to the FQDN of the firewall - if ($endpoint eq "") { - $endpoint = $General::mainsettings{'HOSTNAME'} . "." . $General::mainsettings{'DOMAINNAME'}; - } + # Fetch the endpoint + my $endpoint = &get_endpoint(); # Derive our own public key my $public_key = &derive_public_key($peer{'PRIVATE_KEY'}); @@ -416,12 +424,8 @@ sub generate_host_configuration($) { push(@allowed_ips, "${netaddress}/${prefix}"); } - my $endpoint = $settings{'ENDPOINT'}; - - # If no endpoint is set, we fall back to the FQDN of the firewall - if ($endpoint eq "") { - $endpoint = $General::mainsettings{'HOSTNAME'} . "." . $General::mainsettings{'DOMAINNAME'}; - } + # Fetch the endpoint + my $endpoint = &get_endpoint(); my $port = $settings{'PORT'};