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;
};
sub next_free_ip {
- my ($zone, $subnetid, $subnet, $hostname, $description) = @_;
+ my ($zone, $subnetid, $subnet, $hostname, $mac, $description) = @_;
my $cidr = undef;
my $ip = undef;
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 $@;
}
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};
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 $@;
}
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};