diff options
| author | Stefan Lendl <s.lendl@proxmox.com> | 2024-04-05 15:18:01 +0200 |
|---|---|---|
| committer | Thomas Lamprecht <t.lamprecht@proxmox.com> | 2024-04-08 17:57:18 +0200 |
| commit | 40f020660d5bd2eb7e3e6450cd8f26094a4ccfd3 (patch) | |
| tree | 696c5006e448389311ef37a09818af7d172c62f4 | |
| parent | 23e7fe3197145e8ba5702ff832df11389a3a1f6a (diff) | |
sdn: dnsmasq: extract function that updates dnsmasq lease via dbus
Extract the dbus based interactions with dnsmasq so that it can be
mocked in tests.
Signed-off-by: Stefan Lendl <s.lendl@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
Tested-by: Max Carrara <m.carrara@proxmox.com>
Reviewed-by: Stefan Hanreich <s.hanreich@proxmox.com>
Tested-by: Stefan Hanreich <s.hanreich@proxmox.com>
| -rw-r--r-- | src/PVE/Network/SDN/Dhcp/Dnsmasq.pm | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm index 5a227ba..c14f5d7 100644 --- a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm +++ b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm @@ -38,6 +38,17 @@ sub ethers_file { return "$DNSMASQ_CONFIG_ROOT/$dhcpid/ethers"; } +sub update_lease { + my ($dhcpid, $ip4, $mac) = @_; + #update lease as ip could still be associated to an old removed mac + my $bus = Net::DBus->system(); + my $dnsmasq = $bus->get_service("uk.org.thekelleys.dnsmasq.$dhcpid"); + my $manager = $dnsmasq->get_object("/uk/org/thekelleys/dnsmasq","uk.org.thekelleys.dnsmasq.$dhcpid"); + + my @hostname = unpack("C*", "*"); + $manager->AddDhcpLease($ip4, $mac, \@hostname, undef, 0, 0, 0) if $ip4; +} + sub add_ip_mapping { my ($class, $dhcpid, $macdb, $mac, $ip4, $ip6) = @_; @@ -107,16 +118,7 @@ sub add_ip_mapping { my $service_name = "dnsmasq\@$dhcpid"; systemctl_service('reload', $service_name) if $reload; - - #update lease as ip could still be associated to an old removed mac - my $bus = Net::DBus->system(); - my $dnsmasq = $bus->get_service("uk.org.thekelleys.dnsmasq.$dhcpid"); - my $manager = $dnsmasq->get_object("/uk/org/thekelleys/dnsmasq","uk.org.thekelleys.dnsmasq.$dhcpid"); - - my @hostname = unpack("C*", "*"); - $manager->AddDhcpLease($ip4, $mac, \@hostname, undef, 0, 0, 0) if $ip4; -# $manager->AddDhcpLease($ip6, $mac, \@hostname, undef, 0, 0, 0) if $ip6; - + update_lease($dhcpid, $ip4, $mac); } sub configure_subnet { |
