From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: Christoph Heiss <c.heiss@proxmox.com>
Cc: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] applied: [PATCH pmg-api v4] fix #4410: Remove non-null host bits from CIDR when writing postfix config
Date: Thu, 29 Dec 2022 17:54:16 +0100 [thread overview]
Message-ID: <20221229175416.67d85840@rosa.proxmox.com> (raw)
In-Reply-To: <20221229094515.1295216-1-c.heiss@proxmox.com>
Thanks for the patch!
On Thu, 29 Dec 2022 10:45:17 +0100
Christoph Heiss <c.heiss@proxmox.com> 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 <c.heiss@proxmox.com>
> ---
>
> 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
>
>
prev parent reply other threads:[~2022-12-29 16:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-29 9:45 [pmg-devel] " Christoph Heiss
2022-12-29 16:54 ` Stoiko Ivanov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221229175416.67d85840@rosa.proxmox.com \
--to=s.ivanov@proxmox.com \
--cc=c.heiss@proxmox.com \
--cc=pmg-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox