[pve-devel] [PATCH v2 manager 11/14] api: ceph: mon: fix handling of IPv6 addresses in assert_mon_prerequisites

Fabian Ebner f.ebner at proxmox.com
Mon May 10 14:18:23 CEST 2021


by comparing their canonical forms.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

New in v2.

 PVE/API2/Ceph/MON.pm | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/PVE/API2/Ceph/MON.pm b/PVE/API2/Ceph/MON.pm
index e4e8ecfb..27278bc1 100644
--- a/PVE/API2/Ceph/MON.pm
+++ b/PVE/API2/Ceph/MON.pm
@@ -89,15 +89,26 @@ my $ips_from_mon_host = sub {
 my $assert_mon_prerequisites = sub {
     my ($cfg, $monhash, $monid, $monip) = @_;
 
-    my $ip_regex = '(?:^|[^\d])' . # start or nondigit
-	       "\Q$monip\E" .  # the ip not interpreted as regex
-	       '(?:[^\d]|$)';  # end or nondigit
+    $monip = PVE::Network::canonical_ip($monip);
 
-    if (($cfg->{global}->{mon_host} && $cfg->{global}->{mon_host} =~ m/$ip_regex/) ||
-	grep { $_->{addr} && $_->{addr}  =~ m/$ip_regex/ } values %$monhash) {
-	die "monitor address '$monip' already in use\n";
+    my $used_ips = {};
+
+    my $mon_host_ips = $ips_from_mon_host->($cfg->{global}->{mon_host});
+
+    for my $mon_host_ip (@{$mon_host_ips}) {
+	my $ip = PVE::Network::canonical_ip($mon_host_ip);
+	$used_ips->{$ip} = 1;
+    }
+
+    for my $mon (values %{$monhash}) {
+	next if !defined($mon->{addr});
+
+	my $ip = PVE::Network::canonical_ip($mon->{addr});
+	$used_ips->{$ip} = 1;
     }
 
+    die "monitor address '$monip' already in use\n" if $used_ips->{$monip};
+
     if (defined($monhash->{$monid})) {
 	die "monitor '$monid' already exists\n";
     }
-- 
2.20.1






More information about the pve-devel mailing list