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 BAA13922BD for ; Tue, 27 Dec 2022 10:28:04 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 96F5818BD6 for ; Tue, 27 Dec 2022 10:27:34 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 27 Dec 2022 10:27:33 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 762E0451DD for ; Tue, 27 Dec 2022 10:27:33 +0100 (CET) Message-ID: <7d9764c5-59d7-ad7f-e5b1-d08ffc0a414a@proxmox.com> Date: Tue, 27 Dec 2022 10:27:32 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 To: Stoiko Ivanov Cc: pmg-devel@lists.proxmox.com References: <20221222101940.3610215-1-c.heiss@proxmox.com> <20221222162501.1cd288c5@rosa.proxmox.com> Content-Language: en-US, de-AT From: Christoph Heiss In-Reply-To: <20221222162501.1cd288c5@rosa.proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.629 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -1.147 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox.com] Subject: Re: [pmg-devel] [PATCH pmg-api] fix #4410: Remove non-null host-bits from CIDR when reading `mynetworks` X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Dec 2022 09:28:04 -0000 On 12/22/22 16:25, Stoiko Ivanov wrote: > Huge thanks for addressing this! It was a nice opportunity to get into Perl and PMG too :^) > > I like the approach in general - two comments inline: > > On Thu, 22 Dec 2022 11:19:40 +0100 > Christoph Heiss wrote: > [..] >> @@ -1008,13 +1009,13 @@ sub read_pmg_mynetworks { >> while (defined(my $line = <$fh>)) { >> chomp $line; >> next if $line =~ m/^\s*$/; >> - if ($line =~ m!^((?:$IPV4RE|$IPV6RE))/(\d+)\s*(?:#(.*)\s*)?$!) { >> - my ($network, $prefix_size, $comment) = ($1, $2, $3); >> - my $cidr = "$network/${prefix_size}"; >> - $mynetworks->{$cidr} = { >> - cidr => $cidr, >> - network_address => $network, >> - prefix_size => $prefix_size, >> + if ($line =~ m!^((?:$IPV4RE|$IPV6RE)/\d+)\s*(?:#(.*)\s*)?$!) { >> + my ($cidr, $comment) = ($1, $2); >> + my $ip = PVE::Network::IP_from_cidr($cidr); > this call expands the prefix to full-length - which I wouldn't have > noticed for ipv4 - but is quite visible with ipv6: > entering `2001:db8::/32` results in > `2001:0db8:0000:0000:0000:0000:0000:0000/32` > IIUC - Net::IP::ip_compress_prefix($ip->prefix(), $ip->version()) might > be an approach - but even that adds the last quad of zeros... > > If at all possible it would be great to keep the data as the user entered it. > (In this case - in all situations where it's actually a valid prefix w/o > host-bits set) Ack, I didn't really test it all that extensively with IPv6. I'll look into it again and send a v2. > > > >> + $mynetworks->{$ip->prefix()} = { >> + cidr => $ip->prefix(), >> + network_address => $ip->ip(), >> + prefix_size => $ip->prefixlen(), >> comment => $comment // '', >> }; >> } else { >> @@ -1336,11 +1337,11 @@ sub get_template_vars { >> } >> >> my $netlist = PVE::INotify::read_file('mynetworks'); >> - foreach my $cidr (keys %$netlist) { >> - if ($cidr =~ m/^($IPV6RE)\/(\d+)$/) { >> + foreach my $ip (values %$netlist) { > why switch here to iterating over the values - and then accessing the cidr > field twice, if it's by construction above the same as the key? This was a left-over from when working on the code. I'll remove it. > >> + if ($ip->{cidr} =~ m/^($IPV6RE)\/(\d+)$/) { >> $mynetworks->{"[$1]/$2"} = 1; >> } else { >> - $mynetworks->{$cidr} = 1; >> + $mynetworks->{$ip->{cidr}} = 1; >> } >> } >> >> -- >> 2.30.2 >> >> >> >> _______________________________________________ >> pmg-devel mailing list >> pmg-devel@lists.proxmox.com >> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel >> >> >