From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 5D7C093D0A for ; Wed, 22 Feb 2023 13:49:49 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 409A51821F for ; Wed, 22 Feb 2023 13:49:19 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 22 Feb 2023 13:49:18 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 34CF848120 for ; Wed, 22 Feb 2023 13:49:18 +0100 (CET) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Wed, 22 Feb 2023 13:49:01 +0100 Message-Id: <20230222124903.326612-2-c.heiss@proxmox.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230222124903.326612-1-c.heiss@proxmox.com> References: <20230222124903.326612-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.099 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH v4 container 1/3] net: Pass network config directly to net_tap_plug() X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Feb 2023 12:49:49 -0000 No functional changes. Signed-off-by: Christoph Heiss --- Changes v3 -> v4: * New patch A note: The check in net_tap_plug() whether the MAC address is actually passed in $opts is removed, as this was always the case anyway. src/PVE/LXC.pm | 20 +++++++++----------- src/lxcnetaddbr | 9 +-------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index 54ee0d9..54afd97 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -918,15 +918,16 @@ sub vm_stop_cleanup { warn $@ if $@; # avoid errors - just warn } -sub net_tap_plug : prototype($$$$$$;$) { - my ($iface, $bridge, $tag, $firewall, $trunks, $rate, $opts) = @_; +sub net_tap_plug : prototype($$) { + my ($iface, $net) = @_; + my ($bridge, $tag, $firewall, $trunks, $rate, $hwaddr) = + $net->@{'bridge', 'tag', 'firewall', 'trunks', 'rate', 'hwaddr'}; if ($have_sdn) { PVE::Network::SDN::Zones::tap_plug($iface, $bridge, $tag, $firewall, $trunks, $rate); - PVE::Network::SDN::Zones::add_bridge_fdb($iface, $opts->{mac}, $bridge, $firewall) - if defined($opts->{mac}); + PVE::Network::SDN::Zones::add_bridge_fdb($iface, $hwaddr, $bridge, $firewall); } else { - PVE::Network::tap_plug($iface, $bridge, $tag, $firewall, $trunks, $rate, $opts); + PVE::Network::tap_plug($iface, $bridge, $tag, $firewall, $trunks, $rate, { mac => $hwaddr }); } } @@ -968,8 +969,7 @@ sub update_net { PVE::LXC::Config->write_config($vmid, $conf); } - my ($bridge, $mac, $firewall, $rate) = $newnet->@{'bridge', 'hwaddr', 'firewall', 'rate'}; - PVE::LXC::net_tap_plug($veth, $bridge, $newnet->{tag}, $firewall, $newnet->{trunks}, $rate, { mac => $mac }); + PVE::LXC::net_tap_plug($veth, $newnet); # This includes the rate: foreach (qw(bridge tag firewall rate)) { @@ -1003,10 +1003,8 @@ sub hotplug_net { } else { PVE::Network::veth_create($veth, $vethpeer, $newnet->{bridge}, $newnet->{hwaddr}); } - PVE::LXC::net_tap_plug( - $veth, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks}, - $newnet->{rate}, { mac => $newnet->{hwaddr} }, - ); + + PVE::LXC::net_tap_plug($veth, $newnet); # attach peer in container my $cmd = ['lxc-device', '-n', $vmid, 'add', $vethpeer, "$eth" ]; diff --git a/src/lxcnetaddbr b/src/lxcnetaddbr index ebd6baa..f2db433 100755 --- a/src/lxcnetaddbr +++ b/src/lxcnetaddbr @@ -36,13 +36,7 @@ die "unable to find network definition for interface '$iface'\n" my $net = PVE::LXC::Config->parse_lxc_network($netconf); -my $tag = $net->{tag}; -my $firewall = $net->{firewall}; my $bridge = $net->{bridge}; -my $trunks = $net->{trunks}; -my $rate = $net->{rate}; -my $hwaddr = $net->{hwaddr}; - die "missing bridge configuration" if !$bridge; if (-d "/sys/class/net/$iface") { @@ -54,8 +48,7 @@ if (-d "/sys/class/net/$iface") { PVE::Tools::run_command("/sbin/ip link set dev $iface up mtu $bridgemtu"); PVE::Tools::run_command("/sbin/ip addr add 0.0.0.0/0 dev $iface"); - - PVE::LXC::net_tap_plug($iface, $bridge, $tag, $firewall, $trunks, $rate, { mac => $hwaddr }); + PVE::LXC::net_tap_plug($iface, $net); } exit 0; -- 2.39.1