]> git.proxmox.com Git - pmg-api.git/commit
use postgres inet functions for greylist matching
authorStoiko Ivanov <s.ivanov@proxmox.com>
Mon, 20 Apr 2020 11:22:40 +0000 (13:22 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 20 Apr 2020 15:18:19 +0000 (17:18 +0200)
commitf61d54891d4820b21ef9e53f7ce0ebb1d5be1f73
tree8c1880b338a5466e68e2f00a1959e4e00a802aaf
parente68a3b477c0113481f88f52a0dbef46ff80ad322
use postgres inet functions for greylist matching

In preparation for adding support for a configurable greylist netmask [0]
and greylisting for ipv6 hosts the width of the IPNet column of the cgreylist
table needs to be extended to 49 [1].

Instead of comparing the first 3 octets of a ipv4 address we store the
complete network definition (i.e. for 192.0.2.127/24 - 192.0.2.0/24)
The last octet is not saved, but written as 0 (the information is not
needed, and not used currently). The generation of the network is done
with postgresql's functions for the inet and cidr datatypes [2,3].

The change of the column width instead of using the inet datatype prevents
errors while syncing or downgrading, although older nodes in a cluster (or
downgraded nodes) will not match new records.

When syncing from a node with old-style data the rows are inserted in the
new format.

Upon upgrade (`pmgdb init` in the postinst script) the data is changed to
the new format and matched for duplicates (in case one node in the cluster
got upgraded and it's contents were synced we should not edit the data
again). This process does cause the Cgreylist table to be scanned, which
takes time linear in the number of rows (e.g. with a test-dataset of
~ 1 million rows the upgrade is blocked for ~50 seconds on an
average testinstallation).
Changing only the column datatype does not lock the table and is almost
instantenous [4].

[0] defining from which neighbors a mail is accepted on the second attempt
[1] INET6_ADDRSTRLEN is 46 + 4 for the netmask ('/128) - \0
[2] https://www.postgresql.org/docs/11/datatype-net-types.html
[3] https://www.postgresql.org/docs/11/functions-net.html
[4] Notes section of https://www.postgresql.org/docs/11/sql-altertable.html

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
src/PMG/Cluster.pm
src/PMG/DBTools.pm
src/bin/pmgpolicy