use random_ether_addr() from PVE::Tools

This commit is contained in:
Dietmar Maurer 2011-10-05 09:24:49 +02:00
parent e5f7f8ed0f
commit 9f91ff0281

View File

@ -984,7 +984,7 @@ sub parse_net {
if ($kvp =~ m/^(ne2k_pci|e1000|rtl8139|pcnet|virtio|ne2k_isa|i82551|i82557b|i82559er)(=([0-9a-f]{2}(:[0-9a-f]{2}){5}))?$/i) {
my $model = lc($1);
my $mac = uc($3) || random_ether_addr();
my $mac = uc($3) || PVE::Tools::random_ether_addr();
$res->{model} = $model;
$res->{macaddr} = $mac;
} elsif ($kvp =~ m/^bridge=(\S+)$/) {
@ -2217,29 +2217,6 @@ sub pidfile_name {
return "${var_run_tmpdir}/$vmid.pid";
}
sub random_ether_addr {
my $rand = Digest::SHA1::sha1_hex(rand(), time());
my $mac = '';
for (my $i = 0; $i < 6; $i++) {
my $ss = hex(substr($rand, $i*2, 2));
if (!$i) {
$ss &= 0xfe; # clear multicast
$ss |= 2; # set local id
}
$ss = sprintf("%02X", $ss);
if (!$i) {
$mac .= "$ss";
} else {
$mac .= ":$ss";
}
}
return $mac;
}
sub next_migrate_port {
for (my $p = 60000; $p < 60010; $p++) {