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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id BF64292835 for ; Thu, 29 Dec 2022 17:54:49 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 73FCB9830 for ; Thu, 29 Dec 2022 17:54:19 +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 ; Thu, 29 Dec 2022 17:54:17 +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 4F65342523 for ; Thu, 29 Dec 2022 17:54:17 +0100 (CET) Date: Thu, 29 Dec 2022 17:54:16 +0100 From: Stoiko Ivanov To: Christoph Heiss Cc: pmg-devel@lists.proxmox.com Message-ID: <20221229175416.67d85840@rosa.proxmox.com> In-Reply-To: <20221229094515.1295216-1-c.heiss@proxmox.com> References: <20221229094515.1295216-1-c.heiss@proxmox.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.24; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.158 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pmg-devel] applied: [PATCH pmg-api v4] fix #4410: Remove non-null host bits from CIDR when writing postfix config 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: Thu, 29 Dec 2022 16:54:49 -0000 Thanks for the patch! On Thu, 29 Dec 2022 10:45:17 +0100 Christoph Heiss wrote: > This will drop non-null host bits from `mynetworks` CIDRs when writing > the `main.cf` postfix template. > Backwards-compatibility with old entries in `/etc/pmg/mynetworks` is > thus also preserved. > > Add an additional comment to the mynetworks API, indicating that unused > fields can/should be dropped with the next PMG version. > > No GUI changes. The entries are written to `/etc/pmg/mynetworks` as the > user enters them. Suggested by Stoiko, see discussion in v2 thread [0]. > > [0] https://lists.proxmox.com/pipermail/pmg-devel/2022-December/002247.html > > Signed-off-by: Christoph Heiss > --- > > Changes v3 -> v4: > * Added warning on CIDR parse failures > > Changes v2 -> v3: > * Dropped validation of host-bits of new entries on creation > * Entries are now again written verbatim to `/etc/pmg/mynetworks` > * Host bits are now dropped when writing the postfix template > > Changes v1 -> v2: > * Reverted unneeded loop iterator change > * Display CIDRs in GUI as the user entered them > > src/PMG/Config.pm | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/src/PMG/Config.pm b/src/PMG/Config.pm > index 9ba5c76..a0b1866 100755 > --- a/src/PMG/Config.pm > +++ b/src/PMG/Config.pm > @@ -8,6 +8,7 @@ use Data::Dumper; > use PVE::Tools; > use PVE::JSONSchema qw(get_standard_option); > use PVE::SectionConfig; > +use PVE::Network; > > use base qw(PVE::SectionConfig); > > @@ -1011,6 +1012,7 @@ sub read_pmg_mynetworks { > if ($line =~ m!^((?:$IPV4RE|$IPV6RE))/(\d+)\s*(?:#(.*)\s*)?$!) { > my ($network, $prefix_size, $comment) = ($1, $2, $3); > my $cidr = "$network/${prefix_size}"; > + # FIXME: Drop unused `network_address` and `prefix_size` with PMG 8.0 > $mynetworks->{$cidr} = { > cidr => $cidr, > network_address => $network, > @@ -1337,10 +1339,15 @@ sub get_template_vars { > > my $netlist = PVE::INotify::read_file('mynetworks'); > foreach my $cidr (keys %$netlist) { > - if ($cidr =~ m/^($IPV6RE)\/(\d+)$/) { > - $mynetworks->{"[$1]/$2"} = 1; > + my $ip = PVE::Network::IP_from_cidr($cidr); > + > + if (!$ip) { > + warn "failed to parse mynetworks entry '$cidr', ignoring\n"; > + } elsif ($ip->version() == 4) { > + $mynetworks->{$ip->prefix()} = 1; > } else { > - $mynetworks->{$cidr} = 1; > + my $address = '[' . $ip->short() . ']/' . $ip->prefixlen(); > + $mynetworks->{$address} = 1; > } > } > > -- > 2.30.2 > > > > _______________________________________________ > pmg-devel mailing list > pmg-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel > >