[pmg-devel] [PATCH pmg-api v2 2/5] allow for optional 'ipv6:' prefix in transports
Stoiko Ivanov
s.ivanov at proxmox.com
Wed Mar 18 11:23:43 CET 2020
according to the smtp(8) and transport(5) manuals literal ipv6 addresses must
be written as '[ipv6:2001:db8::ff]', in accordance with rfc2821 [0].
Postfix does work irrespective of this prefix (as it has been working until
now), but we should allow for administrators to enter the addresses with the
prefix present.
[0] http://www.postfix.org/IPV6_README.html
Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
src/PMG/API2/Transport.pm | 4 ++--
src/PMG/Config.pm | 24 ++++++++++++++++++++----
2 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/src/PMG/API2/Transport.pm b/src/PMG/API2/Transport.pm
index 6a370fe..54edbc5 100644
--- a/src/PMG/API2/Transport.pm
+++ b/src/PMG/API2/Transport.pm
@@ -72,7 +72,7 @@ __PACKAGE__->register_method ({
},
host => {
description => "Target host (name or IP address).",
- type => 'string', format => 'address',
+ type => 'string', format => 'transport-address',
},
protocol => {
description => "Transport protocol.",
@@ -188,7 +188,7 @@ __PACKAGE__->register_method ({
},
host => {
description => "Target host (name or IP address).",
- type => 'string', format => 'address',
+ type => 'string', format => 'transport-address',
optional => 1,
},
protocol => {
diff --git a/src/PMG/Config.pm b/src/PMG/Config.pm
index 3c83944..9f23970 100755
--- a/src/PMG/Config.pm
+++ b/src/PMG/Config.pm
@@ -1102,6 +1102,22 @@ sub postmap_pmg_transport {
PMG::Utils::run_postmap($transport_map_filename);
}
+PVE::JSONSchema::register_format(
+ 'transport-address', \&pmg_verify_transport_address);
+
+sub pmg_verify_transport_address {
+ my ($name, $noerr) = @_;
+
+ if ($name =~ m/^ipv6:($IPV6RE)$/i) {
+ return $name;
+ } elsif (PVE::JSONSchema::pve_verify_address($name, 1)) {
+ return $name;
+ } else {
+ return undef if $noerr;
+ die "value does not look like a valid address\n";
+ }
+}
+
sub read_transport_map {
my ($filename, $fh) = @_;
@@ -1140,7 +1156,7 @@ sub read_transport_map {
}
$use_mx = 0 if ($protocol eq "lmtp");
- eval { PVE::JSONSchema::pve_verify_address($host); };
+ eval { pmg_verify_transport_address($host); };
if (my $err = $@) {
$parse_error->($err);
next;
@@ -1184,7 +1200,7 @@ sub write_transport_map {
$data->{protocol} .= ":inet";
}
- $bracket_host = 1 if $data->{host} =~ m/^(?:$IPV4RE|$IPV6RE)$/i;
+ $bracket_host = 1 if $data->{host} =~ m/^(?:$IPV4RE|(?:ipv6:)?$IPV6RE)$/i;
if ($bracket_host) {
PVE::Tools::safe_print(
@@ -1238,8 +1254,8 @@ sub get_template_vars {
my $host = $data->{host};
if ($host =~ m/^$IPV4RE$/) {
push @$transportnets, "$host/32";
- } elsif ($host =~ m/^$IPV6RE$/) {
- push @$transportnets, "[$host]/128";
+ } elsif ($host =~ m/^(?:ipv6:)?($IPV6RE)$/i) {
+ push @$transportnets, "[$1]/128";
}
}
}
--
2.20.1
More information about the pmg-devel
mailing list