[pve-devel] [pve-network 1/4] vnets: use ipam without dhcp

Alexandre Derumier aderumier at odiso.com
Thu Jan 4 17:27:30 CET 2024


User should be able to use ipam without need to use dhcp.

(with static configuration for example).

Could be use to firewall rules or other rules based on ipam

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 src/PVE/Network/SDN/Vnets.pm | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/PVE/Network/SDN/Vnets.pm b/src/PVE/Network/SDN/Vnets.pm
index 0dfdfd7..060cb3c 100644
--- a/src/PVE/Network/SDN/Vnets.pm
+++ b/src/PVE/Network/SDN/Vnets.pm
@@ -103,7 +103,7 @@ sub add_next_free_cidr {
     my $zoneid = $vnet->{zone};
     my $zone = PVE::Network::SDN::Zones::get_zone($zoneid);
 
-    return if !$zone->{ipam} || !$zone->{dhcp};
+    return if !$zone->{ipam};
 
     my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid, 1);
 
@@ -170,7 +170,7 @@ sub get_ips_from_mac {
     my $zoneid = $vnet->{zone};
     my $zone = PVE::Network::SDN::Zones::get_zone($zoneid);
 
-    return if !$zone->{ipam} || !$zone->{dhcp};
+    return if !$zone->{ipam};
 
     return PVE::Network::SDN::Ipams::get_ips_from_mac($mac, $zoneid, $zone);
 }
@@ -193,7 +193,7 @@ sub add_dhcp_mapping {
     my $zoneid = $vnet->{zone};
     my $zone = PVE::Network::SDN::Zones::get_zone($zoneid);
 
-    return if !$zone->{ipam} || !$zone->{dhcp};
+    return if !$zone->{ipam};
 
     my ($ip4, $ip6) = PVE::Network::SDN::Vnets::get_ips_from_mac($vnetid, $mac);
     if ( ! ($ip4 || $ip6) ) {
@@ -202,7 +202,7 @@ sub add_dhcp_mapping {
 	($ip4, $ip6) = PVE::Network::SDN::Vnets::get_ips_from_mac($vnetid, $mac);
 	print "got new IP from IPAM: $ip4 $ip6\n";
     }
-    PVE::Network::SDN::Dhcp::add_mapping($vnetid, $mac, $ip4, $ip6) if $ip4 || $ip6;
+    PVE::Network::SDN::Dhcp::add_mapping($vnetid, $mac, $ip4, $ip6) if $zone->{dhcp} && ($ip4 || $ip6);
 }
 
 1;
-- 
2.39.2




More information about the pve-devel mailing list