summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStoiko Ivanov <s.ivanov@proxmox.com>2024-11-18 21:55:37 +0100
committerThomas Lamprecht <t.lamprecht@proxmox.com>2024-11-18 22:18:28 +0100
commit478e17c7e07fb9db656a6d32479d4d8ca3d10fb3 (patch)
tree50c0164f5e98e95ea7c9d15abfe505e702e9590e /src
parent89dfb8f879d90ef906f78213d7edfd6140733972 (diff)
ipam: move mac-cache.db to unprivileged sdn/ subdirectory
follows commit: 0f48bc6 ("ipam: move state file of PVE plugin over to common sdn directory") as far as reasoning goes, and also closely code-wise (if only to make the clean-up with PVE 9.0 a bit more straight-forward): files in priv/ are sensitive in the sense that access there can be used to hijack (external systems) - the mac-cache can be kept next to the remaining sdn-config. minimally tested on my machine. depends on the pve-cluster commit sent with this. Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
Diffstat (limited to 'src')
-rw-r--r--src/PVE/Network/SDN/Ipams.pm29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/PVE/Network/SDN/Ipams.pm b/src/PVE/Network/SDN/Ipams.pm
index 926df90..c689b8f 100644
--- a/src/PVE/Network/SDN/Ipams.pm
+++ b/src/PVE/Network/SDN/Ipams.pm
@@ -20,9 +20,34 @@ PVE::Network::SDN::Ipams::NetboxPlugin->register();
PVE::Network::SDN::Ipams::PhpIpamPlugin->register();
PVE::Network::SDN::Ipams::Plugin->init();
-my $macdb_filename = 'priv/macs.db';
+my $macdb_filename = "sdn/mac-cache.json";
+my $macdb_filename_legacy = 'priv/macs.db';
+
+cfs_register_file(
+ $macdb_filename,
+ sub {
+ my ($filename , $data) = @_;
+ if (defined($data)) {
+ return json_reader($filename, $data);
+ } else {
+ # TODO: remove legacy cache file handling with PVE 9+ after ensuring all call sites got
+ # switched over.
+ return cfs_read_file($macdb_filename_legacy);
+ }
+ },
+ sub {
+ my ($filename , $data) = @_;
+ # TODO: remove below with PVE 9+, add a pve8to9 check to allow doing so.
+ if (-e $macdb_filename_legacy && -e $macdb_filename) {
+ # only clean-up if we succeeded to write the new path at least once
+ unlink $macdb_filename_legacy or $!{ENOENT} or warn "failed to unlink legacy MAC cache - $!\n";
+ }
+ return json_writer->($filename, $data);
+ }
+);
-cfs_register_file($macdb_filename, \&json_reader, \&json_writer);
+# drop reading $macdb_filename_legacy with PVE 9+ - for now do not write it anymore.
+cfs_register_file($macdb_filename_legacy, \&json_reader, undef);
sub json_reader {
my ($filename, $data) = @_;