public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH pve-network 0/7] dhcp v4
@ 2023-11-18 14:13 Alexandre Derumier
  2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 1/7] fix subnet tests Alexandre Derumier
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Alexandre Derumier @ 2023-11-18 14:13 UTC (permalink / raw)
  To: pve-devel

Apply on top of stefan patch v4 series

changes:
 - fix tests from last stefan patches changes
 - dnsmasq: update lease cache through bus (for ipv4 only)
 - dnsmasq: use static range to avoid to distribute dynamic ips
 - dnsmasq: fix ipv6 config && ethers format


dhcpv6 ip distribution works fine for me, but I can't get router avertisement
working. I don't see any RA packet sent by dnsmasq.
(works fine with radvd daemon for example).


Alexandre Derumier (7):
  fix subnet tests
  api2: ipam : remove add|del_mapping in mac/ip management
  dhcp : remove del_ip_mapping
  dnsmasq: configure static range for each subnet
  dnsmasq: enable dbus && purge old ip lease on reservation
  dnsmasq: fix ipv6 support
  dhcp : dnsmasq: generate dbus policy

 src/PVE/API2/Network/SDN/Ipam.pm    |   7 --
 src/PVE/Network/SDN/Dhcp/Dnsmasq.pm | 148 ++++++++++++++++------------
 src/PVE/Network/SDN/Dhcp/Plugin.pm  |   5 -
 src/test/run_test_subnets.pl        |  20 ++--
 4 files changed, 94 insertions(+), 86 deletions(-)

-- 
2.39.2




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

* [pve-devel] [PATCH pve-network 1/7] fix subnet tests
  2023-11-18 14:13 [pve-devel] [PATCH pve-network 0/7] dhcp v4 Alexandre Derumier
@ 2023-11-18 14:13 ` Alexandre Derumier
  2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 2/7] api2: ipam : remove add|del_mapping in mac/ip management Alexandre Derumier
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Alexandre Derumier @ 2023-11-18 14:13 UTC (permalink / raw)
  To: pve-devel

- add vmid in in ipam.db
- remove ip value in ipam.db (is already the key)

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/test/run_test_subnets.pl | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/test/run_test_subnets.pl b/src/test/run_test_subnets.pl
index 578b5c1..49b4205 100755
--- a/src/test/run_test_subnets.pl
+++ b/src/test/run_test_subnets.pl
@@ -79,7 +79,7 @@ foreach my $path (@plugins) {
     my $ip3 = undef;
     my $hostname = "myhostname";
     my $mac = "da:65:8f:18:9b:6f";
-    my $description = "mydescription";
+    my $vmid = "100";
     my $is_gateway = 1;
     my $ipamdb = {};
 
@@ -144,7 +144,7 @@ foreach my $path (@plugins) {
     $expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{"'.$ip.'":{"gateway":1}}}}}}}';
 
     eval {
-	PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway);
+	PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $vmid, $is_gateway);
     };
 
     if ($@) {
@@ -162,7 +162,7 @@ foreach my $path (@plugins) {
 	$name = "$testid $test";
 
 	eval {
-	    PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $description);
+	    PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $vmid);
 	};
 
 	if ($@) {
@@ -176,10 +176,10 @@ foreach my $path (@plugins) {
     $test = "add_second_ip $ip2";
     $name = "$testid $test";
     $result = undef;
-    $expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{"'.$ip.'":{"gateway":1},"'.$ip2.'":{"hostname":"'.$hostname.'","ip":"'.$ip2.'","mac":"'.$mac.'"}}}}}}}';
+    $expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{"'.$ip.'":{"gateway":1},"'.$ip2.'":{"hostname":"'.$hostname.'","mac":"'.$mac.'","vmid":"'.$vmid.'"}}}}}}}';
 
     eval {
-	PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip2, $hostname, $mac, $description);
+	PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip2, $hostname, $mac, $vmid);
     };
 
     if ($@) {
@@ -195,10 +195,10 @@ foreach my $path (@plugins) {
     $test = "find_next_freeip ($ipnextfree)";
     $name = "$testid $test";
     $result = undef;
-    $expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{"'.$ip.'":{"gateway":1},"'.$ipnextfree.'":{},"'.$ip2.'":{"hostname":"'.$hostname.'","ip":"'.$ip2.'","mac":"'.$mac.'"}}}}}}}';
+    $expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{"'.$ip.'":{"gateway":1},"'.$ipnextfree.'":{},"'.$ip2.'":{"hostname":"'.$hostname.'","mac":"'.$mac.'","vmid":"'.$vmid.'"}}}}}}}';
 
     eval {
-	$ip3 = PVE::Network::SDN::Subnets::add_next_free_ip($zone, $subnetid, $subnet, $hostname, $mac, $description);
+	$ip3 = PVE::Network::SDN::Subnets::add_next_free_ip($zone, $subnetid, $subnet, $hostname, $mac, $vmid);
     };
 
     if ($@) {
@@ -212,7 +212,7 @@ foreach my $path (@plugins) {
     $test = "del_ip $ip";
     $name = "$testid $test";
     $result = undef;
-    $expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{"'.$ipnextfree.'":{},"'.$ip2.'":{"hostname":"'.$hostname.'","ip":"'.$ip2.'","mac":"'.$mac.'"}}}}}}}';
+    $expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{"'.$ipnextfree.'":{},"'.$ip2.'":{"hostname":"'.$hostname.'","mac":"'.$mac.'","vmid":"'.$vmid.'"}}}}}}}';
 
     eval {
 	PVE::Network::SDN::Subnets::del_ip($zone, $subnetid, $subnet, $ip, $hostname);
@@ -264,10 +264,10 @@ foreach my $path (@plugins) {
 
     $name = "$testid $test";
     $result = undef;
-    $expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{"'.$ipnextfree.'":{},"'.$ip2.'":{"hostname":"'.$hostname.'","ip":"'.$ip2.'","mac":"'.$mac.'"}}}}}}}';
+    $expected = '{"zones":{"myzone":{"subnets":{"'.$subnet_cidr.'":{"ips":{"'.$ipnextfree.'":{},"'.$ip2.'":{"hostname":"'.$hostname.'","mac":"'.$mac.'","vmid":"'.$vmid.'"}}}}}}}';
 
     eval {
-	PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $description);
+	PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $vmid);
     };
 
     if ($@) {
-- 
2.39.2




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

* [pve-devel] [PATCH pve-network 2/7] api2: ipam : remove add|del_mapping in mac/ip management
  2023-11-18 14:13 [pve-devel] [PATCH pve-network 0/7] dhcp v4 Alexandre Derumier
  2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 1/7] fix subnet tests Alexandre Derumier
@ 2023-11-18 14:13 ` Alexandre Derumier
  2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 3/7] dhcp : remove del_ip_mapping Alexandre Derumier
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Alexandre Derumier @ 2023-11-18 14:13 UTC (permalink / raw)
  To: pve-devel

only register/del ip in ipam here.

The dhcp mapping is done a vm start.

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/PVE/API2/Network/SDN/Ipam.pm | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/src/PVE/API2/Network/SDN/Ipam.pm b/src/PVE/API2/Network/SDN/Ipam.pm
index e71ca7d..722baa4 100644
--- a/src/PVE/API2/Network/SDN/Ipam.pm
+++ b/src/PVE/API2/Network/SDN/Ipam.pm
@@ -114,14 +114,11 @@ __PACKAGE__->register_method ({
 	my $vnet = extract_param($param, 'vnet');
 	my $mac = extract_param($param, 'mac');
 
-	PVE::Network::SDN::Dhcp::remove_mapping($vnet, $mac);
-
 	eval {
 	    PVE::Network::SDN::Vnets::del_ips_from_mac($vnet, $mac);
 	};
 	my $error = $@;
 
-	PVE::Network::SDN::Vnets::add_dhcp_mapping($vnet, $mac) if $error;
 	die "$error\n" if $error;
 
 	return undef;
@@ -159,7 +156,6 @@ __PACKAGE__->register_method ({
 	my $ip = extract_param($param, 'ip');
 
 	PVE::Network::SDN::Vnets::add_ip($vnet, $ip, '', $mac, undef);
-	PVE::Network::SDN::Vnets::add_dhcp_mapping($vnet, $mac);
 
 	return undef;
     },
@@ -198,7 +194,6 @@ __PACKAGE__->register_method ({
 	my $vmid = extract_param($param, 'vmid');
 	my $ip = extract_param($param, 'ip');
 
-	PVE::Network::SDN::Dhcp::remove_mapping($vnet, $mac);
 	my ($old_ip4, $old_ip6) = PVE::Network::SDN::Vnets::del_ips_from_mac($vnet, $mac, '');
 
 	eval {
@@ -211,8 +206,6 @@ __PACKAGE__->register_method ({
 	    PVE::Network::SDN::Vnets::add_ip($vnet, $old_ip6, '', $mac, $vmid) if $old_ip6;
 	}
 
-	PVE::Network::SDN::Vnets::add_dhcp_mapping($vnet, $mac);
-
 	die "$error\n" if $error;
 	return undef;
     },
-- 
2.39.2




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

* [pve-devel] [PATCH pve-network 3/7] dhcp : remove del_ip_mapping
  2023-11-18 14:13 [pve-devel] [PATCH pve-network 0/7] dhcp v4 Alexandre Derumier
  2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 1/7] fix subnet tests Alexandre Derumier
  2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 2/7] api2: ipam : remove add|del_mapping in mac/ip management Alexandre Derumier
@ 2023-11-18 14:13 ` Alexandre Derumier
  2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 4/7] dnsmasq: configure static range for each subnet Alexandre Derumier
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Alexandre Derumier @ 2023-11-18 14:13 UTC (permalink / raw)
  To: pve-devel

The cleanup is done in add_ip_mapping

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/PVE/Network/SDN/Dhcp/Dnsmasq.pm | 34 -----------------------------
 src/PVE/Network/SDN/Dhcp/Plugin.pm  |  5 -----
 2 files changed, 39 deletions(-)

diff --git a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
index c4b6bde..763ad09 100644
--- a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
+++ b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
@@ -18,40 +18,6 @@ sub type {
     return 'dnsmasq';
 }
 
-sub del_ip_mapping {
-    my ($class, $dhcpid, $mac) = @_;
-
-    my $ethers_file = "$DNSMASQ_CONFIG_ROOT/$dhcpid/ethers";
-    my $ethers_tmp_file = "$ethers_file.tmp";
-
-    my $removeFn = sub {
-	open(my $in, '<', $ethers_file) or die "Could not open file '$ethers_file' $!\n";
-	open(my $out, '>', $ethers_tmp_file) or die "Could not open file '$ethers_tmp_file' $!\n";
-
-        while (my $line = <$in>) {
-	    next if $line =~ m/^$mac/;
-	    print $out $line;
-	}
-
-	close $in;
-	close $out;
-
-	move $ethers_tmp_file, $ethers_file;
-
-	chmod 0644, $ethers_file;
-    };
-
-    PVE::Tools::lock_file($ethers_file, 10, $removeFn);
-
-    if ($@) {
-	warn "Unable to remove $mac from the dnsmasq configuration: $@\n";
-	return;
-    }
-
-    my $service_name = "dnsmasq\@$dhcpid";
-    PVE::Tools::run_command(['systemctl', 'reload', $service_name]);
-}
-
 sub add_ip_mapping {
     my ($class, $dhcpid, $macdb, $mac, $ip4, $ip6) = @_;
 
diff --git a/src/PVE/Network/SDN/Dhcp/Plugin.pm b/src/PVE/Network/SDN/Dhcp/Plugin.pm
index 8d0f7ba..d05378d 100644
--- a/src/PVE/Network/SDN/Dhcp/Plugin.pm
+++ b/src/PVE/Network/SDN/Dhcp/Plugin.pm
@@ -27,11 +27,6 @@ sub add_ip_mapping {
     die 'implement in sub class';
 }
 
-sub del_ip_mapping {
-    my ($class, $dhcp_config, $mac) = @_;
-    die 'implement in sub class';
-}
-
 sub configure_range {
     my ($class, $dhcp_config, $subnet_config, $range_config) = @_;
     die 'implement in sub class';
-- 
2.39.2




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

* [pve-devel] [PATCH pve-network 4/7] dnsmasq: configure static range for each subnet
  2023-11-18 14:13 [pve-devel] [PATCH pve-network 0/7] dhcp v4 Alexandre Derumier
                   ` (2 preceding siblings ...)
  2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 3/7] dhcp : remove del_ip_mapping Alexandre Derumier
@ 2023-11-18 14:13 ` Alexandre Derumier
  2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 5/7] dnsmasq: enable dbus && purge old ip lease on reservation Alexandre Derumier
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Alexandre Derumier @ 2023-11-18 14:13 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 763ad09..652b146 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] 9+ messages in thread

* [pve-devel] [PATCH pve-network 5/7] dnsmasq: enable dbus && purge old ip lease on reservation
  2023-11-18 14:13 [pve-devel] [PATCH pve-network 0/7] dhcp v4 Alexandre Derumier
                   ` (3 preceding siblings ...)
  2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 4/7] dnsmasq: configure static range for each subnet Alexandre Derumier
@ 2023-11-18 14:13 ` Alexandre Derumier
  2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 6/7] dnsmasq: fix ipv6 support Alexandre Derumier
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Alexandre Derumier @ 2023-11-18 14:13 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 652b146..b469272 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] 9+ messages in thread

* [pve-devel] [PATCH pve-network 6/7] dnsmasq: fix ipv6 support
  2023-11-18 14:13 [pve-devel] [PATCH pve-network 0/7] dhcp v4 Alexandre Derumier
                   ` (4 preceding siblings ...)
  2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 5/7] dnsmasq: enable dbus && purge old ip lease on reservation Alexandre Derumier
@ 2023-11-18 14:13 ` Alexandre Derumier
  2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 7/7] dhcp : dnsmasq: generate dbus policy Alexandre Derumier
  2023-11-20 16:42 ` [pve-devel] applied-series: [PATCH pve-network 0/7] dhcp v4 Thomas Lamprecht
  7 siblings, 0 replies; 9+ messages in thread
From: Alexandre Derumier @ 2023-11-18 14:13 UTC (permalink / raw)
  To: pve-devel

ether file should have 1 line by mac address with ip4+ip6

ip6 address should be in braced [ip6]

for now: don't update ip6 through bus as it seem to be incorrect

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

diff --git a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
index b469272..0dd6436 100644
--- a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
+++ b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
@@ -25,44 +25,54 @@ sub add_ip_mapping {
     my $ethers_file = "$DNSMASQ_CONFIG_ROOT/$dhcpid/ethers";
     my $ethers_tmp_file = "$ethers_file.tmp";
 
-    my $change = undef;
-    my $match4 = undef;
-    my $match6 = undef;
+    my $reload = undef;
 
     my $appendFn = sub {
 	open(my $in, '<', $ethers_file) or die "Could not open file '$ethers_file' $!\n";
 	open(my $out, '>', $ethers_tmp_file) or die "Could not open file '$ethers_tmp_file' $!\n";
 
-        while (my $line = <$in>) {
+	my $match = undef;
+
+ 	while (my $line = <$in>) {
 	    chomp($line);
-	    my ($parsed_mac, $parsed_ip) = split(/,/, $line);
-	    #delete removed mac
-	    if (!defined($macdb->{macs}->{$parsed_mac})) {
-		$change = 1;
-		next;
+	    my $parsed_ip4 = undef;
+	    my $parsed_ip6 = undef;
+	    my ($parsed_mac, $parsed_ip1, $parsed_ip2) = split(/,/, $line);
+
+	    if ($parsed_ip2) {
+		$parsed_ip4 = $parsed_ip1;
+		$parsed_ip6 = $parsed_ip2;
+	    } elsif (Net::IP::ip_is_ipv4($parsed_ip1)) {
+		$parsed_ip4 = $parsed_ip1;
+	    } else {
+		$parsed_ip6 = $parsed_ip1;
+	    }
+	    $parsed_ip6 = $1 if $parsed_ip6 && $parsed_ip6 =~ m/\[(\S+)\]/;
+
+	    #delete changed
+	    if (!defined($macdb->{macs}->{$parsed_mac}) ||
+		($parsed_ip4 && $macdb->{macs}->{$parsed_mac}->{'ip4'} && $macdb->{macs}->{$parsed_mac}->{'ip4'} ne $parsed_ip4) ||
+		($parsed_ip6 && $macdb->{macs}->{$parsed_mac}->{'ip6'} && $macdb->{macs}->{$parsed_mac}->{'ip6'} ne $parsed_ip6)) {
+                    $reload = 1;
+		    next;
 	    }
 
-	    #delete changed ip
-	    my $ipversion = Net::IP::ip_is_ipv4($parsed_ip) ? "ip4" : "ip6";
-	    if ($macdb->{macs}->{$parsed_mac}->{$ipversion} && $macdb->{macs}->{$parsed_mac}->{$ipversion} ne $parsed_ip) {
-		$change = 1;
-		next;
+	    if ($parsed_mac eq $mac) {
+		$match = 1 if $ip4 && $parsed_ip4 && $ip4;
+		$match = 1 if $ip6 && $parsed_ip6 && $ip6;
 	    }
-	    print $out "$parsed_mac,$parsed_ip\n";
-	    #check if mac/ip already exist
-	    $match4 = 1 if $parsed_mac eq $mac && $macdb->{macs}->{$mac}->{'ip4'} && $macdb->{macs}->{$mac}->{'ip4'} eq $ip4;
-	    $match6 = 1 if $parsed_mac eq $mac && $macdb->{macs}->{$mac}->{'ip6'} && $macdb->{macs}->{$mac}->{'ip6'} eq $ip6;
-	}
 
-	if(!$match4 && $ip4) {
-	    print $out "$mac,$ip4\n";
-	    $change = 1;
+	    print $out "$line\n";
 	}
 
-	if(!$match6 && $ip6) {
-	    print $out "$mac,$ip6\n";
-	    $change = 1;
+	if(!$match) {
+	    my $reservation = $mac;
+	    $reservation .= ",$ip4" if $ip4;
+	    $reservation .= ",[$ip6]" if $ip6;
+	    print $out "$reservation\n";
+	    $reload = 1;
 	}
+
 	close $in;
 	close $out;
 	move $ethers_tmp_file, $ethers_file;
@@ -77,7 +87,7 @@ sub add_ip_mapping {
     }
 
     my $service_name = "dnsmasq\@$dhcpid";
-    PVE::Tools::run_command(['systemctl', 'reload', $service_name]) if $change;
+    PVE::Tools::run_command(['systemctl', 'reload', $service_name]) if $reload;
 
     #update lease as ip could still be associated to an old removed mac
     my $bus = Net::DBus->system();
@@ -86,7 +96,7 @@ sub add_ip_mapping {
 
     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;
+#    $manager->AddDhcpLease($ip6, $mac, \@hostname, undef, 0, 0, 0) if $ip6;
 
 }
 
-- 
2.39.2




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

* [pve-devel] [PATCH pve-network 7/7] dhcp : dnsmasq: generate dbus policy
  2023-11-18 14:13 [pve-devel] [PATCH pve-network 0/7] dhcp v4 Alexandre Derumier
                   ` (5 preceding siblings ...)
  2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 6/7] dnsmasq: fix ipv6 support Alexandre Derumier
@ 2023-11-18 14:13 ` Alexandre Derumier
  2023-11-20 16:42 ` [pve-devel] applied-series: [PATCH pve-network 0/7] dhcp v4 Thomas Lamprecht
  7 siblings, 0 replies; 9+ messages in thread
From: Alexandre Derumier @ 2023-11-18 14:13 UTC (permalink / raw)
  To: pve-devel

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

diff --git a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
index 0dd6436..7b54532 100644
--- a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
+++ b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
@@ -151,6 +151,31 @@ sub configure_range {
 sub before_configure {
     my ($class, $dhcpid) = @_;
 
+    my $dbus_config = <<DBUSCFG;
+<!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="uk.org.thekelleys.dnsmasq.$dhcpid"/>
+                <allow send_destination="uk.org.thekelleys.dnsmasq.$dhcpid"/>
+        </policy>
+        <policy user="dnsmasq">
+                <allow own="uk.org.thekelleys.dnsmasq.$dhcpid"/>
+                <allow send_destination="uk.org.thekelleys.dnsmasq.$dhcpid"/>
+        </policy>
+        <policy context="default">
+                <deny own="uk.org.thekelleys.dnsmasq.$dhcpid"/>
+                <deny send_destination="uk.org.thekelleys.dnsmasq.$dhcpid"/>
+        </policy>
+</busconfig>
+DBUSCFG
+
+    PVE::Tools::file_set_contents(
+	"/etc/dbus-1/system.d/dnsmasq.$dhcpid.conf",
+	$dbus_config
+    );
+
     my $config_directory = "$DNSMASQ_CONFIG_ROOT/$dhcpid";
 
     mkdir($config_directory, 755) if !-d $config_directory;
@@ -201,6 +226,7 @@ sub after_configure {
 
     my $service_name = "dnsmasq\@$dhcpid";
 
+    PVE::Tools::run_command(['systemctl', 'reload', 'dbus']);
     PVE::Tools::run_command(['systemctl', 'enable', $service_name]);
     PVE::Tools::run_command(['systemctl', 'restart', $service_name]);
 }
-- 
2.39.2




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

* [pve-devel] applied-series:  [PATCH pve-network 0/7] dhcp v4
  2023-11-18 14:13 [pve-devel] [PATCH pve-network 0/7] dhcp v4 Alexandre Derumier
                   ` (6 preceding siblings ...)
  2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 7/7] dhcp : dnsmasq: generate dbus policy Alexandre Derumier
@ 2023-11-20 16:42 ` Thomas Lamprecht
  7 siblings, 0 replies; 9+ messages in thread
From: Thomas Lamprecht @ 2023-11-20 16:42 UTC (permalink / raw)
  To: Proxmox VE development discussion, Alexandre Derumier

Am 18/11/2023 um 15:13 schrieb Alexandre Derumier:
> Apply on top of stefan patch v4 series
> 
> changes:
>  - fix tests from last stefan patches changes
>  - dnsmasq: update lease cache through bus (for ipv4 only)
>  - dnsmasq: use static range to avoid to distribute dynamic ips
>  - dnsmasq: fix ipv6 config && ethers format
> 
> 
> dhcpv6 ip distribution works fine for me, but I can't get router avertisement
> working. I don't see any RA packet sent by dnsmasq.
> (works fine with radvd daemon for example).
> 
> 
> Alexandre Derumier (7):
>   fix subnet tests
>   api2: ipam : remove add|del_mapping in mac/ip management
>   dhcp : remove del_ip_mapping
>   dnsmasq: configure static range for each subnet
>   dnsmasq: enable dbus && purge old ip lease on reservation
>   dnsmasq: fix ipv6 support
>   dhcp : dnsmasq: generate dbus policy
> 
>  src/PVE/API2/Network/SDN/Ipam.pm    |   7 --
>  src/PVE/Network/SDN/Dhcp/Dnsmasq.pm | 148 ++++++++++++++++------------
>  src/PVE/Network/SDN/Dhcp/Plugin.pm  |   5 -
>  src/test/run_test_subnets.pl        |  20 ++--
>  4 files changed, 94 insertions(+), 86 deletions(-)
> 


applied, thanks!




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

end of thread, other threads:[~2023-11-20 16:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-18 14:13 [pve-devel] [PATCH pve-network 0/7] dhcp v4 Alexandre Derumier
2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 1/7] fix subnet tests Alexandre Derumier
2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 2/7] api2: ipam : remove add|del_mapping in mac/ip management Alexandre Derumier
2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 3/7] dhcp : remove del_ip_mapping Alexandre Derumier
2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 4/7] dnsmasq: configure static range for each subnet Alexandre Derumier
2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 5/7] dnsmasq: enable dbus && purge old ip lease on reservation Alexandre Derumier
2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 6/7] dnsmasq: fix ipv6 support Alexandre Derumier
2023-11-18 14:13 ` [pve-devel] [PATCH pve-network 7/7] dhcp : dnsmasq: generate dbus policy Alexandre Derumier
2023-11-20 16:42 ` [pve-devel] applied-series: [PATCH pve-network 0/7] dhcp v4 Thomas Lamprecht

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