From: Alexandre Derumier <aderumier@odiso.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-network] fix dhcpv6 router advertisement
Date: Wed, 22 Nov 2023 08:58:01 +0100 [thread overview]
Message-ID: <20231122075801.1224275-1-aderumier@odiso.com> (raw)
- 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
next reply other threads:[~2023-11-22 7:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-22 7:58 Alexandre Derumier [this message]
2023-11-22 9:46 ` Stefan Lendl
2023-11-22 12:10 ` [pve-devel] applied: " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231122075801.1224275-1-aderumier@odiso.com \
--to=aderumier@odiso.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.