public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH pve-network 0/2] dnsmasq: fix dhcp leases
@ 2023-11-17 11:53 Alexandre Derumier
  2023-11-17 11:53 ` [pve-devel] [PATCH pve-network 1/2] dnsmasq: configure static range for each subnet Alexandre Derumier
  2023-11-17 11:53 ` [pve-devel] [PATCH pve-network 2/2] dnsmasq: enable dbus && purge old ip lease on reservation Alexandre Derumier
  0 siblings, 2 replies; 3+ messages in thread
From: Alexandre Derumier @ 2023-11-17 11:53 UTC (permalink / raw)
  To: pve-devel


This need to deploy permission for dbus uk.org.thekelleys.dnsmasq.*
/etc/dbus-1/system.d/dnsmasq-pve.conf
I don't have added patch for this.

<!DOCTYPE busconfig PUBLIC
 "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
        <policy user="root">
                <allow own_prefix="uk.org.thekelleys.dnsmasq"/>
                <allow send_destination_prefix="uk.org.thekelleys.dnsmasq"/>
        </policy>
        <policy user="dnsmasq">
                <allow own_prefix="uk.org.thekelleys.dnsmasq"/>
                <allow send_destination_prefix="uk.org.thekelleys.dnsmasq"/>
        </policy>
        <policy context="default">
                <deny own_prefix="uk.org.thekelleys.dnsmasq"/>
                <deny send_destination_prefix="uk.org.thekelleys.dnsmasq"/>
        </policy>
</busconfig>


Alexandre Derumier (2):
  dnsmasq: configure static range for each subnet
  dnsmasq: enable dbus && purge old ip lease on reservation

 src/PVE/Network/SDN/Dhcp/Dnsmasq.pm | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pve-devel] [PATCH pve-network 1/2] dnsmasq: configure static range for each subnet
  2023-11-17 11:53 [pve-devel] [PATCH pve-network 0/2] dnsmasq: fix dhcp leases Alexandre Derumier
@ 2023-11-17 11:53 ` Alexandre Derumier
  2023-11-17 11:53 ` [pve-devel] [PATCH pve-network 2/2] dnsmasq: enable dbus && purge old ip lease on reservation Alexandre Derumier
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Derumier @ 2023-11-17 11:53 UTC (permalink / raw)
  To: pve-devel

we don't want dynamic lease, simply define each subnet as a static range.

dhcp-range defined on a subnet is only used by ipam plugin.

This will also allow to use dhcp subnet without need to define a range.
Can be usefull for external ipam like phpipam, where you can't define ranges.

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/PVE/Network/SDN/Dhcp/Dnsmasq.pm | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
index 46172c5..2db7f4f 100644
--- a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
+++ b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
@@ -112,11 +112,18 @@ sub configure_subnet {
 sub configure_range {
     my ($class, $dhcpid, $subnet_config, $range_config) = @_;
 
-    my $range_file = "$DNSMASQ_CONFIG_ROOT/$dhcpid/10-$subnet_config->{id}.ranges.conf",
+    my $subnet_file = "$DNSMASQ_CONFIG_ROOT/$dhcpid/10-$subnet_config->{id}.conf";
     my $tag = $subnet_config->{id};
 
-    open(my $fh, '>>', $range_file) or die "Could not open file '$range_file' $!\n";
-    print $fh "dhcp-range=set:$tag,$range_config->{'start-address'},$range_config->{'end-address'}\n";
+    my ($zone, $network, $mask) = split(/-/, $tag);
+
+    if (Net::IP::ip_is_ipv4($network)) {
+	$mask = (2 ** $mask - 1) << (32 - $mask);
+	$mask = join( '.', unpack( "C4", pack( "N", $mask ) ) );
+    }
+
+    open(my $fh, '>>', $subnet_file) or die "Could not open file '$subnet_file' $!\n";
+    print $fh "dhcp-range=set:$tag,$network,static,$mask,infinite\n";
     close $fh;
 }
 
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pve-devel] [PATCH pve-network 2/2] dnsmasq: enable dbus && purge old ip lease on reservation
  2023-11-17 11:53 [pve-devel] [PATCH pve-network 0/2] dnsmasq: fix dhcp leases Alexandre Derumier
  2023-11-17 11:53 ` [pve-devel] [PATCH pve-network 1/2] dnsmasq: configure static range for each subnet Alexandre Derumier
@ 2023-11-17 11:53 ` Alexandre Derumier
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Derumier @ 2023-11-17 11:53 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/PVE/Network/SDN/Dhcp/Dnsmasq.pm | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
index 2db7f4f..f4225d0 100644
--- a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
+++ b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
@@ -9,6 +9,7 @@ use Net::IP qw(:PROC);
 use PVE::Tools qw(file_set_contents run_command lock_file);
 
 use File::Copy;
+use Net::DBus;
 
 my $DNSMASQ_CONFIG_ROOT = '/etc/dnsmasq.d';
 my $DNSMASQ_DEFAULT_ROOT = '/etc/default';
@@ -77,6 +78,16 @@ sub add_ip_mapping {
 
     my $service_name = "dnsmasq\@$dhcpid";
     PVE::Tools::run_command(['systemctl', 'reload', $service_name]) if $change;
+
+    #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;
+
 }
 
 sub configure_subnet {
@@ -136,7 +147,7 @@ sub before_configure {
 
     my $default_config = <<CFG;
 CONFIG_DIR='$config_directory,\*.conf'
-DNSMASQ_OPTS="--conf-file=/dev/null"
+DNSMASQ_OPTS="--conf-file=/dev/null --enable-dbus=uk.org.thekelleys.dnsmasq.$dhcpid"
 CFG
 
     PVE::Tools::file_set_contents(
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-17 11:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-17 11:53 [pve-devel] [PATCH pve-network 0/2] dnsmasq: fix dhcp leases Alexandre Derumier
2023-11-17 11:53 ` [pve-devel] [PATCH pve-network 1/2] dnsmasq: configure static range for each subnet Alexandre Derumier
2023-11-17 11:53 ` [pve-devel] [PATCH pve-network 2/2] dnsmasq: enable dbus && purge old ip lease on reservation Alexandre Derumier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal