mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-08-11 01:03:24 +00:00
net devs: avoid registering MAC to fdb if not static
In theory we can have a config with netX records that do not specify a `macaddr` property, we just auto-generate on in config2cmd for startup transitively, but don't save that explicitly back to the config; so while we could parse the /proc/$pid/cmdline or try to get the info from QMP (not fully straight forward) it seems rather a hassle; especially if one has in mind that this cannot happen via the API FWICT; as there a "deletion" *saves* a newly auto generated value out to the config, same with clone of a VM and restore of a backup. So, in basically all reasonable cases we got the `macaddr` available, but if we don't it makes no sense to add a FDB variable for a *newly* generated one by the parse_net call, as the VM won't use that (well, at least if one doesn't get "lucky" and it randomly re-generates the same as on startup), so allow telling parse_net to skip auto generating MACs and use that in the add-fdb-entries helper Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
1b5ba4ddc6
commit
4ddd2ca293
@ -1941,14 +1941,14 @@ sub parse_numa {
|
||||
|
||||
# netX: e1000=XX:XX:XX:XX:XX:XX,bridge=vmbr0,rate=<mbps>
|
||||
sub parse_net {
|
||||
my ($data) = @_;
|
||||
my ($data, $disable_mac_autogen) = @_;
|
||||
|
||||
my $res = eval { parse_property_string($net_fmt, $data) };
|
||||
if ($@) {
|
||||
warn $@;
|
||||
return;
|
||||
}
|
||||
if (!defined($res->{macaddr})) {
|
||||
if (!defined($res->{macaddr}) && !$disable_mac_autogen) {
|
||||
my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
|
||||
$res->{macaddr} = PVE::Tools::random_ether_addr($dc->{mac_prefix});
|
||||
}
|
||||
@ -4038,6 +4038,7 @@ sub config_to_command {
|
||||
next if !$conf->{$netname};
|
||||
my $d = parse_net($conf->{$netname});
|
||||
next if !$d;
|
||||
# save the MAC addr here (could be auto-gen. in some odd setups) for FDB registering later?
|
||||
|
||||
$use_virtio = 1 if $d->{model} eq 'virtio';
|
||||
|
||||
@ -8319,8 +8320,15 @@ sub add_nets_bridge_fdb {
|
||||
for my $opt (keys %$conf) {
|
||||
next if $opt !~ m/^net(\d+)$/;
|
||||
my $iface = "tap${vmid}i$1";
|
||||
my $net = parse_net($conf->{$opt}) or next;
|
||||
my $mac = $net->{macaddr} or next;
|
||||
# NOTE: expect setups with learning off to *not* use auto-random-generation of MAC on start
|
||||
my $net = parse_net($conf->{$opt}, 1) or next;
|
||||
|
||||
my $mac = $net->{macaddr};
|
||||
if (!$mac) {
|
||||
log_warn("MAC learning disabled, but vNIC '$iface' has no static MAC to add to forwarding DB!")
|
||||
if !file_read_firstline("/sys/class/net/$iface/brport/learning");
|
||||
next;
|
||||
}
|
||||
|
||||
if ($have_sdn) {
|
||||
PVE::Network::SDN::Zones::add_bridge_fdb($iface, $mac, $net->{bridge}, $net->{firewall});
|
||||
|
Loading…
Reference in New Issue
Block a user