From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 161F79ADB9 for ; Sat, 18 Nov 2023 15:14:02 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E5BDD6E7D for ; Sat, 18 Nov 2023 15:13:31 +0100 (CET) Received: from bastionodiso.odiso.net (bastionodiso.odiso.net [IPv6:2a0a:1580:2000::2d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Sat, 18 Nov 2023 15:13:27 +0100 (CET) Received: from kvmformation3.odiso.net (formationkvm3.odiso.net [10.3.94.12]) by bastionodiso.odiso.net (Postfix) with ESMTP id E0FB27F88; Sat, 18 Nov 2023 15:13:15 +0100 (CET) Received: by kvmformation3.odiso.net (Postfix, from userid 0) id DFDC4180045; Sat, 18 Nov 2023 15:13:15 +0100 (CET) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Date: Sat, 18 Nov 2023 15:13:13 +0100 Message-Id: <20231118141314.2785997-7-aderumier@odiso.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231118141314.2785997-1-aderumier@odiso.com> References: <20231118141314.2785997-1-aderumier@odiso.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.019 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy HEADER_FROM_DIFFERENT_DOMAINS 0.25 From and EnvelopeFrom 2nd level mail domains are different KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods SPF_NONE 0.001 SPF: sender does not publish an SPF Record T_SCC_BODY_TEXT_LINE -0.01 - T_SPF_HELO_TEMPERROR 0.01 SPF: test of HELO record failed (temperror) Subject: [pve-devel] [PATCH pve-network 6/7] dnsmasq: fix ipv6 support X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Nov 2023 14:14:02 -0000 ether file should have 1 line by mac address with ip4+ip6 ip6 address should be in braced [ip6] for now: don't update ip6 through bus as it seem to be incorrect Signed-off-by: Alexandre Derumier --- src/PVE/Network/SDN/Dhcp/Dnsmasq.pm | 64 +++++++++++++++++------------ 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm index b469272..0dd6436 100644 --- a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm +++ b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm @@ -25,44 +25,54 @@ sub add_ip_mapping { my $ethers_file = "$DNSMASQ_CONFIG_ROOT/$dhcpid/ethers"; my $ethers_tmp_file = "$ethers_file.tmp"; - my $change = undef; - my $match4 = undef; - my $match6 = undef; + my $reload = undef; my $appendFn = sub { open(my $in, '<', $ethers_file) or die "Could not open file '$ethers_file' $!\n"; open(my $out, '>', $ethers_tmp_file) or die "Could not open file '$ethers_tmp_file' $!\n"; - while (my $line = <$in>) { + my $match = undef; + + while (my $line = <$in>) { chomp($line); - my ($parsed_mac, $parsed_ip) = split(/,/, $line); - #delete removed mac - if (!defined($macdb->{macs}->{$parsed_mac})) { - $change = 1; - next; + my $parsed_ip4 = undef; + my $parsed_ip6 = undef; + my ($parsed_mac, $parsed_ip1, $parsed_ip2) = split(/,/, $line); + + if ($parsed_ip2) { + $parsed_ip4 = $parsed_ip1; + $parsed_ip6 = $parsed_ip2; + } elsif (Net::IP::ip_is_ipv4($parsed_ip1)) { + $parsed_ip4 = $parsed_ip1; + } else { + $parsed_ip6 = $parsed_ip1; + } + $parsed_ip6 = $1 if $parsed_ip6 && $parsed_ip6 =~ m/\[(\S+)\]/; + + #delete changed + if (!defined($macdb->{macs}->{$parsed_mac}) || + ($parsed_ip4 && $macdb->{macs}->{$parsed_mac}->{'ip4'} && $macdb->{macs}->{$parsed_mac}->{'ip4'} ne $parsed_ip4) || + ($parsed_ip6 && $macdb->{macs}->{$parsed_mac}->{'ip6'} && $macdb->{macs}->{$parsed_mac}->{'ip6'} ne $parsed_ip6)) { + $reload = 1; + next; } - #delete changed ip - my $ipversion = Net::IP::ip_is_ipv4($parsed_ip) ? "ip4" : "ip6"; - if ($macdb->{macs}->{$parsed_mac}->{$ipversion} && $macdb->{macs}->{$parsed_mac}->{$ipversion} ne $parsed_ip) { - $change = 1; - next; + if ($parsed_mac eq $mac) { + $match = 1 if $ip4 && $parsed_ip4 && $ip4; + $match = 1 if $ip6 && $parsed_ip6 && $ip6; } - print $out "$parsed_mac,$parsed_ip\n"; - #check if mac/ip already exist - $match4 = 1 if $parsed_mac eq $mac && $macdb->{macs}->{$mac}->{'ip4'} && $macdb->{macs}->{$mac}->{'ip4'} eq $ip4; - $match6 = 1 if $parsed_mac eq $mac && $macdb->{macs}->{$mac}->{'ip6'} && $macdb->{macs}->{$mac}->{'ip6'} eq $ip6; - } - if(!$match4 && $ip4) { - print $out "$mac,$ip4\n"; - $change = 1; + print $out "$line\n"; } - if(!$match6 && $ip6) { - print $out "$mac,$ip6\n"; - $change = 1; + if(!$match) { + my $reservation = $mac; + $reservation .= ",$ip4" if $ip4; + $reservation .= ",[$ip6]" if $ip6; + print $out "$reservation\n"; + $reload = 1; } + close $in; close $out; move $ethers_tmp_file, $ethers_file; @@ -77,7 +87,7 @@ sub add_ip_mapping { } my $service_name = "dnsmasq\@$dhcpid"; - PVE::Tools::run_command(['systemctl', 'reload', $service_name]) if $change; + PVE::Tools::run_command(['systemctl', 'reload', $service_name]) if $reload; #update lease as ip could still be associated to an old removed mac my $bus = Net::DBus->system(); @@ -86,7 +96,7 @@ sub add_ip_mapping { my @hostname = unpack("C*", "*"); $manager->AddDhcpLease($ip4, $mac, \@hostname, undef, 0, 0, 0) if $ip4; - $manager->AddDhcpLease($ip6, $mac, \@hostname, undef, 0, 0, 0) if $ip6; +# $manager->AddDhcpLease($ip6, $mac, \@hostname, undef, 0, 0, 0) if $ip6; } -- 2.39.2