public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Alexandre Derumier <aderumier@odiso.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-network 1/3] dhcp: add vrf support
Date: Mon, 18 Dec 2023 14:04:29 +0100	[thread overview]
Message-ID: <20231218130431.1857324-2-aderumier@odiso.com> (raw)
In-Reply-To: <20231218130431.1857324-1-aderumier@odiso.com>

launch dnsmasq in a vrf context with "ip vrf exec <vrfname> dnsmasq.."

use "default" vrf if plugin don't return a specific vrf

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/PVE/Network/SDN/Dhcp.pm             |  3 ++-
 src/PVE/Network/SDN/Dhcp/Dnsmasq.pm     |  3 ++-
 src/PVE/Network/SDN/Zones.pm            | 10 ++++++++++
 src/PVE/Network/SDN/Zones/EvpnPlugin.pm |  6 ++++++
 src/PVE/Network/SDN/Zones/Plugin.pm     |  6 ++++++
 5 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/PVE/Network/SDN/Dhcp.pm b/src/PVE/Network/SDN/Dhcp.pm
index 7876c08..7b5e31f 100644
--- a/src/PVE/Network/SDN/Dhcp.pm
+++ b/src/PVE/Network/SDN/Dhcp.pm
@@ -79,12 +79,13 @@ sub regenerate_config {
         my $zone = $zone_cfg->{ids}->{$zoneid};
         next if !$zone->{dhcp};
 
+	my $vrf = PVE::Network::SDN::Zones::get_vrf($zoneid);
 	my $dhcp_plugin_name = $zone->{dhcp};
 	my $dhcp_plugin = PVE::Network::SDN::Dhcp::Plugin->lookup($dhcp_plugin_name);
 
 	die "Could not find DHCP plugin: $dhcp_plugin_name" if !$dhcp_plugin;
 
-	eval { $dhcp_plugin->before_configure($zoneid) };
+	eval { $dhcp_plugin->before_configure($zoneid, $vrf) };
 	die "Could not run before_configure for DHCP server $zoneid $@\n" if $@;
 
 	for my $vnetid (sort keys %{$vnet_cfg->{ids}}) {
diff --git a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
index 2844943..755bc0b 100644
--- a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
+++ b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
@@ -164,7 +164,7 @@ sub configure_vnet {
 }
 
 sub before_configure {
-    my ($class, $dhcpid) = @_;
+    my ($class, $dhcpid, $vrf) = @_;
 
     my $dbus_config = <<DBUSCFG;
 <!DOCTYPE busconfig PUBLIC
@@ -198,6 +198,7 @@ DBUSCFG
     my $default_config = <<CFG;
 CONFIG_DIR='$config_directory,\*.conf'
 DNSMASQ_OPTS="--conf-file=/dev/null --enable-dbus=uk.org.thekelleys.dnsmasq.$dhcpid"
+VRF='$vrf'
 CFG
 
     PVE::Tools::file_set_contents(
diff --git a/src/PVE/Network/SDN/Zones.pm b/src/PVE/Network/SDN/Zones.pm
index 5bd3536..354cbe0 100644
--- a/src/PVE/Network/SDN/Zones.pm
+++ b/src/PVE/Network/SDN/Zones.pm
@@ -104,6 +104,16 @@ sub get_vnets {
     return $vnets;
 }
 
+sub get_vrf {
+    my ($zoneid) = @_;
+
+    my $zone_cfg = PVE::Network::SDN::Zones::config();
+    my $plugin_config = $zone_cfg->{ids}->{$zoneid};
+
+    my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($plugin_config->{type});
+    return $plugin->get_vrf($plugin_config, $zoneid);
+}
+
 sub generate_etc_network_config {
 
     my $cfg = PVE::Network::SDN::running_config();
diff --git a/src/PVE/Network/SDN/Zones/EvpnPlugin.pm b/src/PVE/Network/SDN/Zones/EvpnPlugin.pm
index 655a9f0..561d127 100644
--- a/src/PVE/Network/SDN/Zones/EvpnPlugin.pm
+++ b/src/PVE/Network/SDN/Zones/EvpnPlugin.pm
@@ -272,6 +272,12 @@ sub generate_sdn_config {
     return $config;
 }
 
+sub get_vrf {
+    my ($class, $plugin_config, $zoneid) = @_;
+
+    return "vrf_$zoneid";
+}
+
 sub on_update_hook {
     my ($class, $zoneid, $zone_cfg, $controller_cfg) = @_;
 
diff --git a/src/PVE/Network/SDN/Zones/Plugin.pm b/src/PVE/Network/SDN/Zones/Plugin.pm
index 69a6e5a..ee7bbb2 100644
--- a/src/PVE/Network/SDN/Zones/Plugin.pm
+++ b/src/PVE/Network/SDN/Zones/Plugin.pm
@@ -140,6 +140,12 @@ sub controller_reload {
     die "please implement inside plugin";
 }
 
+sub get_vrf {
+    my ($class, $plugin_config, $zoneid) = @_;
+
+    return 'default';
+}
+
 sub on_delete_hook {
     my ($class, $zoneid, $vnet_cfg) = @_;
 
-- 
2.39.2




  reply	other threads:[~2023-12-18 13:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-18 13:04 [pve-devel] [PATCH pve-network 0/3] add dhcp support for evpn Alexandre Derumier
2023-12-18 13:04 ` Alexandre Derumier [this message]
2023-12-18 17:10   ` [pve-devel] [PATCH pve-network 1/3] dhcp: add vrf support Stefan Hanreich
2023-12-18 13:04 ` [pve-devel] [PATCH pve-network 2/3] dnsmasq service: run service in vrf Alexandre Derumier
2023-12-18 13:04 ` [pve-devel] [PATCH pve-network 3/3] zones: evpn: add dhcp support Alexandre Derumier
2023-12-18 14:42 ` [pve-devel] [PATCH pve-network 0/3] add dhcp support for evpn Stefan Hanreich
2023-12-18 17:05   ` Stefan Hanreich

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=20231218130431.1857324-2-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 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