]> git.proxmox.com Git - pve-network.git/blobdiff - PVE/Network/SDN/Subnets.pm
ipams: add mac address
[pve-network.git] / PVE / Network / SDN / Subnets.pm
index 74a538c647053c76c81433b71f18112dcec50f41..b752e2c3e08ba0d2d74a4cfbe700d10d80009807 100644 (file)
@@ -5,6 +5,7 @@ use warnings;
 
 use Net::Subnet qw(subnet_matcher);
 use Net::IP;
+use NetAddr::IP qw(:lower);
 
 use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
 use PVE::Network::SDN::Dns;
@@ -161,7 +162,7 @@ my $del_dns_ptr_record = sub {
 };
 
 sub next_free_ip {
-    my ($zone, $subnetid, $subnet, $hostname, $description) = @_;
+    my ($zone, $subnetid, $subnet, $hostname, $mac, $description) = @_;
 
     my $cidr = undef;
     my $ip = undef;
@@ -183,7 +184,7 @@ sub next_free_ip {
        my $plugin_config = $ipam_cfg->{ids}->{$ipamid};
        my $plugin = PVE::Network::SDN::Ipams::Plugin->lookup($plugin_config->{type});
        eval {
-           $cidr = $plugin->add_next_freeip($plugin_config, $subnetid, $subnet, $hostname, $description);
+           $cidr = $plugin->add_next_freeip($plugin_config, $subnetid, $subnet, $hostname, $mac, $description);
            ($ip, undef) = split(/\//, $cidr);
        };
        die $@ if $@;
@@ -209,10 +210,13 @@ sub next_free_ip {
 }
 
 sub add_ip {
-    my ($zone, $subnetid, $subnet, $ip, $hostname, $description) = @_;
+    my ($zone, $subnetid, $subnet, $ip, $hostname, $mac, $description) = @_;
 
     return if !$subnet || !$ip; 
 
+    my $ipaddr = new NetAddr::IP($ip);
+    $ip = $ipaddr->canon();
+
     my $ipamid = $zone->{ipam};
     my $dns = $zone->{dns};
     my $dnszone = $zone->{dnszone};
@@ -231,7 +235,7 @@ sub add_ip {
        my $plugin_config = $ipam_cfg->{ids}->{$ipamid};
        my $plugin = PVE::Network::SDN::Ipams::Plugin->lookup($plugin_config->{type});
        eval {
-           $plugin->add_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $description);
+           $plugin->add_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description);
        };
        die $@ if $@;
     }
@@ -255,7 +259,10 @@ sub add_ip {
 sub del_ip {
     my ($zone, $subnetid, $subnet, $ip, $hostname) = @_;
 
-    return if !$subnet;
+    return if !$subnet || !$ip;
+
+    my $ipaddr = new NetAddr::IP($ip);
+    $ip = $ipaddr->canon();
 
     my $ipamid = $zone->{ipam};
     my $dns = $zone->{dns};