From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager] api: network: fix #3385 check for used ports before writing
Date: Mon, 19 Apr 2021 20:11:28 +0200 [thread overview]
Message-ID: <20210419181128.4047-1-s.ivanov@proxmox.com> (raw)
Currently the check for used ports for bonds and bridges happens while
rendering '/etc/network/interfaces.new' in PVE::Inotify (pve-common).
However at that stage the new/updated interface is already merged with
the old settings, making it impossible to indicate where a NIC is
currently used.
The code is adapted from the renderer in
PVE::Inotify::__write_etc_network_interfaces.
Tested on a virtual PVE instance.
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
PVE/API2/Network.pm | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/PVE/API2/Network.pm b/PVE/API2/Network.pm
index 9ac289c4..2d8c4ca1 100644
--- a/PVE/API2/Network.pm
+++ b/PVE/API2/Network.pm
@@ -301,6 +301,39 @@ my $check_duplicate_gateway6 = sub {
return &$check_duplicate($config, $newiface, 'gateway6', 'Default ipv6 gateway');
};
+my $check_duplicate_ports = sub {
+ my ($config, $newiface, $newparam) = @_;
+
+ my $param_name;
+ my $get_portlist = sub {
+ my ($param) = @_;
+ my $ports = '';
+ for my $k (qw(bridge_ports ovs_ports slaves ovs_bonds)) {
+ if ($param->{$k}) {
+ $ports .= " $param->{$k}";
+ $param_name //= $k;
+ }
+ }
+ return PVE::Tools::split_list($ports);
+ };
+
+ my $new_ports = {};
+ for my $p ($get_portlist->($newparam)) {
+ $new_ports->{$p} = 1;
+ }
+ return if !(keys %$new_ports);
+
+ for my $iface (keys %$config) {
+ next if $iface eq $newiface;
+
+ my $d = $config->{$iface};
+ for my $p ($get_portlist->($d)) {
+ raise_param_exc({ $param_name => "$p is already used on interface '$iface'." })
+ if $new_ports->{$p};
+ }
+ }
+};
+
sub ipv6_tobin {
return Net::IP::ip_iptobin(Net::IP::ip_expand_address(shift, 6), 6);
}
@@ -387,6 +420,8 @@ __PACKAGE__->register_method({
&$check_duplicate_gateway6($ifaces, $iface)
if $param->{gateway6};
+ $check_duplicate_ports->($ifaces, $iface, $param);
+
$map_cidr_to_address_netmask->($param);
&$check_ipv6_settings($param->{address6}, int($param->{netmask6}))
@@ -488,6 +523,8 @@ __PACKAGE__->register_method({
&$check_duplicate_gateway6($ifaces, $iface)
if $param->{gateway6};
+ $check_duplicate_ports->($ifaces, $iface, $param);
+
if ($param->{address}) {
push @$families, 'inet' if !grep(/^inet$/, @$families);
} else {
--
2.20.1
next reply other threads:[~2021-04-19 18:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-19 18:11 Stoiko Ivanov [this message]
2021-04-22 19:35 ` [pve-devel] applied: " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210419181128.4047-1-s.ivanov@proxmox.com \
--to=s.ivanov@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal