all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH pve-network] fix dhcpv6 router advertisement
@ 2023-11-22  7:58 Alexandre Derumier
  2023-11-22  9:46 ` Stefan Lendl
  2023-11-22 12:10 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 2 replies; 3+ messages in thread
From: Alexandre Derumier @ 2023-11-22  7:58 UTC (permalink / raw)
  To: pve-devel

- don't listen to ip address, but use interface= instead
- generate 1 config file by vnet instead 1 by subnet
- enable-ra is global to server, enable it in default conf

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/PVE/Network/SDN/Dhcp.pm         | 33 +++++++++++++++++---------
 src/PVE/Network/SDN/Dhcp/Dnsmasq.pm | 36 +++++++++++++++--------------
 src/PVE/Network/SDN/Dhcp/Plugin.pm  |  9 ++++++--
 3 files changed, 48 insertions(+), 30 deletions(-)

diff --git a/src/PVE/Network/SDN/Dhcp.pm b/src/PVE/Network/SDN/Dhcp.pm
index fc33f08..2c2d019 100644
--- a/src/PVE/Network/SDN/Dhcp.pm
+++ b/src/PVE/Network/SDN/Dhcp.pm
@@ -59,6 +59,7 @@ sub regenerate_config {
     my $cfg = PVE::Network::SDN::running_config();
 
     my $zone_cfg = $cfg->{zones};
+    my $vnet_cfg = $cfg->{vnets};
     my $subnet_cfg = $cfg->{subnets};
     return if !$zone_cfg && !$subnet_cfg;
 
@@ -84,22 +85,32 @@ sub regenerate_config {
 	eval { $dhcp_plugin->before_configure($zoneid) };
 	die "Could not run before_configure for DHCP server $zoneid $@\n" if $@;
 
+	for my $vnetid (sort keys %{$vnet_cfg->{ids}}) {
+	    my $vnet = $vnet_cfg->{ids}->{$vnetid};
+	    next if $vnet->{zone} ne $zoneid;
 
-	foreach my $subnet_id (keys %{$subnet_cfg->{ids}}) {
-	    my $subnet_config = PVE::Network::SDN::Subnets::sdn_subnets_config($subnet_cfg, $subnet_id);
-	    my $dhcp_ranges = PVE::Network::SDN::Subnets::get_dhcp_ranges($subnet_config);
+	    my $config = [];
+	    my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid);
 
-	    my ($zone, $subnet_network, $subnet_mask) = split(/-/, $subnet_id);
-	    next if $zone ne $zoneid;
-	    next if !$dhcp_ranges;
+	    foreach my $subnet_id (sort keys %{$subnets}) {
+		my $subnet_config = $subnets->{$subnet_id};
+		my $dhcp_ranges = PVE::Network::SDN::Subnets::get_dhcp_ranges($subnet_config);
 
-	    eval { $dhcp_plugin->configure_subnet($zoneid, $subnet_config) };
-	    warn "Could not configure subnet $subnet_id: $@\n" if $@;
+		my ($zone, $subnet_network, $subnet_mask) = split(/-/, $subnet_id);
+		next if $zone ne $zoneid;
+		next if !$dhcp_ranges;
 
-	    foreach my $dhcp_range (@$dhcp_ranges) {
-		eval { $dhcp_plugin->configure_range($zoneid, $subnet_config, $dhcp_range) };
-		warn "Could not configure DHCP range for $subnet_id: $@\n" if $@;
+		eval { $dhcp_plugin->configure_subnet($config, $zoneid, $vnetid, $subnet_config) };
+		warn "Could not configure subnet $subnet_id: $@\n" if $@;
+
+		foreach my $dhcp_range (@$dhcp_ranges) {
+		    eval { $dhcp_plugin->configure_range($config, $zoneid, $vnetid, $subnet_config, $dhcp_range) };
+		    warn "Could not configure DHCP range for $subnet_id: $@\n" if $@;
+		}
 	    }
+
+	    eval { $dhcp_plugin->configure_vnet($config, $zoneid, $vnetid, $vnet) };
+	    warn "Could not configure vnet $vnetid: $@\n" if $@;
 	}
 
 	eval { $dhcp_plugin->after_configure($zoneid) };
diff --git a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
index 7b54532..4c0de25 100644
--- a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
+++ b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
@@ -101,39 +101,29 @@ sub add_ip_mapping {
 }
 
 sub configure_subnet {
-    my ($class, $dhcpid, $subnet_config) = @_;
+    my ($class, $config, $dhcpid, $vnetid, $subnet_config) = @_;
 
     die "No gateway defined for subnet $subnet_config->{id}"
 	if !$subnet_config->{gateway};
 
     my $tag = $subnet_config->{id};
 
-    my @dnsmasq_config = (
-	"listen-address=$subnet_config->{gateway}",
-    );
-
     my $option_string;
     if (ip_is_ipv6($subnet_config->{network})) {
 	$option_string = 'option6';
-	push @dnsmasq_config, "enable-ra";
     } else {
 	$option_string = 'option';
-	push @dnsmasq_config, "dhcp-option=tag:$tag,$option_string:router,$subnet_config->{gateway}";
+	push @{$config}, "dhcp-option=tag:$tag,$option_string:router,$subnet_config->{gateway}";
     }
 
-    push @dnsmasq_config, "dhcp-option=tag:$tag,$option_string:dns-server,$subnet_config->{'dhcp-dns-server'}"
+    push @{$config}, "dhcp-option=tag:$tag,$option_string:dns-server,$subnet_config->{'dhcp-dns-server'}"
 	if $subnet_config->{'dhcp-dns-server'};
 
-    PVE::Tools::file_set_contents(
-	"$DNSMASQ_CONFIG_ROOT/$dhcpid/10-$subnet_config->{id}.conf",
-	join("\n", @dnsmasq_config) . "\n"
-    );
 }
 
 sub configure_range {
-    my ($class, $dhcpid, $subnet_config, $range_config) = @_;
+    my ($class, $config, $dhcpid, $vnetid, $subnet_config, $range_config) = @_;
 
-    my $subnet_file = "$DNSMASQ_CONFIG_ROOT/$dhcpid/10-$subnet_config->{id}.conf";
     my $tag = $subnet_config->{id};
 
     my ($zone, $network, $mask) = split(/-/, $tag);
@@ -143,9 +133,20 @@ sub configure_range {
 	$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;
+    push @{$config}, "dhcp-range=set:$tag,$network,static,$mask,infinite";
+}
+
+sub configure_vnet {
+    my ($class, $config, $dhcpid, $vnetid, $vnet_config) = @_;
+
+    return if @{$config} < 1;
+
+    push @{$config}, "interface=$vnetid";
+
+    PVE::Tools::file_set_contents(
+	"$DNSMASQ_CONFIG_ROOT/$dhcpid/10-$vnetid.conf",
+	join("\n", @{$config}) . "\n"
+    );
 }
 
 sub before_configure {
@@ -192,6 +193,7 @@ CFG
 
     my $default_dnsmasq_config = <<CFG;
 except-interface=lo
+enable-ra
 bind-dynamic
 no-resolv
 no-hosts
diff --git a/src/PVE/Network/SDN/Dhcp/Plugin.pm b/src/PVE/Network/SDN/Dhcp/Plugin.pm
index d05378d..b99f598 100644
--- a/src/PVE/Network/SDN/Dhcp/Plugin.pm
+++ b/src/PVE/Network/SDN/Dhcp/Plugin.pm
@@ -28,12 +28,17 @@ sub add_ip_mapping {
 }
 
 sub configure_range {
-    my ($class, $dhcp_config, $subnet_config, $range_config) = @_;
+    my ($class, $dhcpid, $vnetid, $subnet_config, $range_config) = @_;
     die 'implement in sub class';
 }
 
 sub configure_subnet {
-    my ($class, $dhcp_config, $subnet_config) = @_;
+    my ($class, $dhcpid, $vnetid, $subnet_config) = @_;
+    die 'implement in sub class';
+}
+
+sub configure_vnet {
+    my ($class, $config, $dhcpid, $vnetid, $vnet_config) = @_;
     die 'implement in sub class';
 }
 
-- 
2.39.2




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

* Re: [pve-devel] [PATCH pve-network] fix dhcpv6 router advertisement
  2023-11-22  7:58 [pve-devel] [PATCH pve-network] fix dhcpv6 router advertisement Alexandre Derumier
@ 2023-11-22  9:46 ` Stefan Lendl
  2023-11-22 12:10 ` [pve-devel] applied: " Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Lendl @ 2023-11-22  9:46 UTC (permalink / raw)
  To: Alexandre Derumier, pve-devel


Thank you for the update. This works now. I tested with IPv6 only and
dual stack.

- ping gateway
- ping VM
- hotplug NIC and get a new IP
- migration




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

* [pve-devel] applied: [PATCH pve-network] fix dhcpv6 router advertisement
  2023-11-22  7:58 [pve-devel] [PATCH pve-network] fix dhcpv6 router advertisement Alexandre Derumier
  2023-11-22  9:46 ` Stefan Lendl
@ 2023-11-22 12:10 ` Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2023-11-22 12:10 UTC (permalink / raw)
  To: Proxmox VE development discussion, Alexandre Derumier

Am 22/11/2023 um 08:58 schrieb Alexandre Derumier:
> - don't listen to ip address, but use interface= instead
> - generate 1 config file by vnet instead 1 by subnet
> - enable-ra is global to server, enable it in default conf
> 
> Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
> ---
>  src/PVE/Network/SDN/Dhcp.pm         | 33 +++++++++++++++++---------
>  src/PVE/Network/SDN/Dhcp/Dnsmasq.pm | 36 +++++++++++++++--------------
>  src/PVE/Network/SDN/Dhcp/Plugin.pm  |  9 ++++++--
>  3 files changed, 48 insertions(+), 30 deletions(-)
> 
>

applied, thanks!




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

end of thread, other threads:[~2023-11-22 12:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-22  7:58 [pve-devel] [PATCH pve-network] fix dhcpv6 router advertisement Alexandre Derumier
2023-11-22  9:46 ` Stefan Lendl
2023-11-22 12:10 ` [pve-devel] applied: " Thomas Lamprecht

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal