[pve-devel] [PATCH v4 container 1/3] net: Pass network config directly to net_tap_plug()
Christoph Heiss
c.heiss at proxmox.com
Wed Feb 22 13:49:01 CET 2023
No functional changes.
Signed-off-by: Christoph Heiss <c.heiss at proxmox.com>
---
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
More information about the pve-devel
mailing list