[pve-devel] [RFC PATCH container] pass datacenter.cfg's mac_prefix to random_ether_addr

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Jul 13 16:25:43 CEST 2016


---
 src/PVE/LXC/Config.pm     | 5 ++++-
 src/pve-update-lxc-config | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index 6b0ed4f..7988203 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -1079,7 +1079,10 @@ sub parse_lxc_network {
     $res = PVE::JSONSchema::parse_property_string($netconf_desc, $data);
 
     $res->{type} = 'veth';
-    $res->{hwaddr} = PVE::Tools::random_ether_addr() if !$res->{hwaddr};
+    if (!$res->{hwaddr}) {
+	my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
+	$res->{hwaddr} = PVE::Tools::random_ether_addr($dc->{mac_prefix});
+    }
 
     return $res;
 }
diff --git a/src/pve-update-lxc-config b/src/pve-update-lxc-config
index 119e625..d7d8985 100755
--- a/src/pve-update-lxc-config
+++ b/src/pve-update-lxc-config
@@ -243,7 +243,10 @@ sub parse_lxc_config {
 	
 	foreach my $net (@{$network_list}) {
 	    next if $net->{type} eq 'empty'; # skip
-	    $net->{hwaddr} =  PVE::Tools::random_ether_addr() if !$net->{hwaddr};
+	    if (!$net->{hwaddr}) {
+		my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
+		$net->{hwaddr} =  PVE::Tools::random_ether_addr($dc->{mac_prefix});
+	    }
 	    die "unsupported network type '$net->{type}'\n" if $net->{type} ne 'veth';
 	    die "undefined veth network pair'\n" if !$net->{'veth.pair'};
 	    
-- 
2.1.4





More information about the pve-devel mailing list