From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id B24A01FF16B for <inbox@lore.proxmox.com>; Thu, 17 Apr 2025 12:00:30 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id BE11B18124; Thu, 17 Apr 2025 12:00:27 +0200 (CEST) From: Stefan Hanreich <s.hanreich@proxmox.com> To: pve-devel@lists.proxmox.com Date: Thu, 17 Apr 2025 11:59:54 +0200 Message-Id: <20250417095954.104359-1-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.234 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Subject: [pve-devel] [PATCH qemu-server 1/1] net: pass host_mtu parameter when mtu is unset in netdev config X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> When creating a new network device from the UI and leaving the MTU field empty, the field hints that this means that the MTU is inherited from the bridge. Since leaving the field empty omits the key from the network device configuration, we need to inherit from the bridge MTU when this key is missing as well, instead of only inheriting from the bridge when the field is explicitly set to 1. The common case where this was encountered was with creating network devices on SDN VXLAN vnets. There the default MTU for bridges is 1450, since VXLAN adds some overhead and we automatically subtract that overhead from the default bridge MTU (1500) if no MTU is explicitly set in the zone configuration. I decided to fix this here, instead of in the UI, since the fix then also works for existing network devices where MTU is unset. This means that users would not have to re-apply the setting from the UI. It also seems like the sensible default to inherit the MTU value from the bridge when this key doesn't exist instead of just not setting host_mtu at all. Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com> --- PVE/QemuServer.pm | 28 +++++++++++++++------------- test/cfg2cmd/netdev_vxlan.conf | 8 ++++++++ test/cfg2cmd/netdev_vxlan.conf.cmd | 26 ++++++++++++++++++++++++++ test/run_config2command_tests.pl | 6 ++++++ 4 files changed, 55 insertions(+), 13 deletions(-) create mode 100644 test/cfg2cmd/netdev_vxlan.conf create mode 100644 test/cfg2cmd/netdev_vxlan.conf.cmd diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index ccdceedc..6a55d59f 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -1596,20 +1596,22 @@ sub print_netdevice_full { $tmpstr .= ",bootindex=$net->{bootindex}" if $net->{bootindex} ; - if (my $mtu = $net->{mtu}) { - if ($net->{model} eq 'virtio' && $net->{bridge}) { - my $bridge_mtu = PVE::Network::read_bridge_mtu($net->{bridge}); - if ($mtu == 1) { - $mtu = $bridge_mtu; - } elsif ($mtu < 576) { - die "netdev $netid: MTU '$mtu' is smaller than the IP minimum MTU '576'\n"; - } elsif ($mtu > $bridge_mtu) { - die "netdev $netid: MTU '$mtu' is bigger than the bridge MTU '$bridge_mtu'\n"; - } - $tmpstr .= ",host_mtu=$mtu"; - } else { - warn "WARN: netdev $netid: ignoring MTU '$mtu', not using VirtIO or no bridge configured.\n"; + my $mtu = $net->{mtu}; + + if ($net->{model} eq 'virtio' && $net->{bridge}) { + my $bridge_mtu = PVE::Network::read_bridge_mtu($net->{bridge}); + + if (!defined($mtu) || $mtu == 1) { + $mtu = $bridge_mtu; + } elsif ($mtu < 576) { + die "netdev $netid: MTU '$mtu' is smaller than the IP minimum MTU '576'\n"; + } elsif ($mtu > $bridge_mtu) { + die "netdev $netid: MTU '$mtu' is bigger than the bridge MTU '$bridge_mtu'\n"; } + + $tmpstr .= ",host_mtu=$mtu" if $mtu != 1500; + } elsif (defined($mtu)) { + warn "WARN: netdev $netid: ignoring MTU '$mtu', not using VirtIO or no bridge configured.\n"; } if ($use_old_bios_files) { diff --git a/test/cfg2cmd/netdev_vxlan.conf b/test/cfg2cmd/netdev_vxlan.conf new file mode 100644 index 00000000..222a66d4 --- /dev/null +++ b/test/cfg2cmd/netdev_vxlan.conf @@ -0,0 +1,8 @@ +# TEST: Simple test for netdev related stuff +# QEMU_VERSION: 5.0 +bootdisk: scsi0 +cores: 3 +memory: 768 +name: netdev +net0: virtio=A2:C0:43:77:08:A0,bridge=vxlan_bridge +ostype: l26 diff --git a/test/cfg2cmd/netdev_vxlan.conf.cmd b/test/cfg2cmd/netdev_vxlan.conf.cmd new file mode 100644 index 00000000..a9db44bf --- /dev/null +++ b/test/cfg2cmd/netdev_vxlan.conf.cmd @@ -0,0 +1,26 @@ +/usr/bin/kvm \ + -id 8006 \ + -name 'netdev,debug-threads=on' \ + -no-shutdown \ + -chardev 'socket,id=qmp,path=/var/run/qemu-server/8006.qmp,server=on,wait=off' \ + -mon 'chardev=qmp,mode=control' \ + -chardev 'socket,id=qmp-event,path=/var/run/qmeventd.sock,reconnect=5' \ + -mon 'chardev=qmp-event,mode=control' \ + -pidfile /var/run/qemu-server/8006.pid \ + -daemonize \ + -smp '3,sockets=1,cores=3,maxcpus=3' \ + -nodefaults \ + -boot 'menu=on,strict=on,reboot-timeout=1000,splash=/usr/share/qemu-server/bootsplash.jpg' \ + -vnc 'unix:/var/run/qemu-server/8006.vnc,password=on' \ + -cpu kvm64,enforce,+kvm_pv_eoi,+kvm_pv_unhalt,+lahf_lm,+sep \ + -m 768 \ + -device 'pci-bridge,id=pci.1,chassis_nr=1,bus=pci.0,addr=0x1e' \ + -device 'pci-bridge,id=pci.2,chassis_nr=2,bus=pci.0,addr=0x1f' \ + -device 'piix3-usb-uhci,id=uhci,bus=pci.0,addr=0x1.0x2' \ + -device 'usb-tablet,id=tablet,bus=uhci.0,port=1' \ + -device 'VGA,id=vga,bus=pci.0,addr=0x2' \ + -device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3' \ + -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \ + -netdev 'type=tap,id=net0,ifname=tap8006i0,script=/usr/libexec/qemu-server/pve-bridge,downscript=/usr/libexec/qemu-server/pve-bridgedown,vhost=on' \ + -device 'virtio-net-pci,mac=A2:C0:43:77:08:A0,netdev=net0,bus=pci.0,addr=0x12,id=net0,bootindex=300,host_mtu=1450' \ + -machine 'type=pc+pve0' diff --git a/test/run_config2command_tests.pl b/test/run_config2command_tests.pl index 209122c2..c2dfbd31 100755 --- a/test/run_config2command_tests.pl +++ b/test/run_config2command_tests.pl @@ -316,6 +316,12 @@ my $pve_common_network; $pve_common_network = Test::MockModule->new('PVE::Network'); $pve_common_network->mock( read_bridge_mtu => sub { + my ($bridge_name) = @_; + + if ($bridge_name eq 'vxlan_bridge') { + return 1450; + } + return 1500; }, ); -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel