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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id F368F68DD3 for ; Fri, 28 Aug 2020 14:37:04 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B012420E82 for ; Fri, 28 Aug 2020 14:37:04 +0200 (CEST) Received: from mailpro.odiso.net (mailpro.odiso.net [89.248.211.110]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 0402320E2E for ; Fri, 28 Aug 2020 14:37:01 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mailpro.odiso.net (Postfix) with ESMTP id C596015F9E07; Fri, 28 Aug 2020 14:36:55 +0200 (CEST) Received: from mailpro.odiso.net ([127.0.0.1]) by localhost (mailpro.odiso.net [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id iEtHD5QXgFdI; Fri, 28 Aug 2020 14:36:55 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mailpro.odiso.net (Postfix) with ESMTP id AC81815F9E0A; Fri, 28 Aug 2020 14:36:55 +0200 (CEST) X-Virus-Scanned: amavisd-new at mailpro.odiso.com Received: from mailpro.odiso.net ([127.0.0.1]) by localhost (mailpro.odiso.net [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id I5IvsQaRbWLi; Fri, 28 Aug 2020 14:36:55 +0200 (CEST) Received: from pve.fritz.box (unknown [213.211.148.86]) by mailpro.odiso.net (Postfix) with ESMTPSA id 7915015F9E07; Fri, 28 Aug 2020 14:36:55 +0200 (CEST) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Date: Fri, 28 Aug 2020 14:36:33 +0200 Message-Id: <20200828123649.11125-6-aderumier@odiso.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200828123649.11125-1-aderumier@odiso.com> References: <20200828123649.11125-1-aderumier@odiso.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.000 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_NONE -0.0001 Sender listed at https://www.dnswl.org/, no trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [vnets.pm, vxlanplugin.pm, evpnplugin.pm, qinqplugin.pm, simpleplugin.pm, plugin.pm, vlanplugin.pm] Subject: [pve-devel] [PATCH v7 pve-network 05/21] zone: add vnet_update_hook 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: Fri, 28 Aug 2020 12:37:05 -0000 move verify_tag code in this hook add mac address generation for simple && evpn plugin --- PVE/API2/Network/SDN/Vnets.pm | 4 ++-- PVE/Network/SDN/Zones/EvpnPlugin.pm | 19 +++++++++++++++---- PVE/Network/SDN/Zones/Plugin.pm | 5 +++-- PVE/Network/SDN/Zones/QinQPlugin.pm | 8 ++++---- PVE/Network/SDN/Zones/SimplePlugin.pm | 14 +++++++++++--- PVE/Network/SDN/Zones/VlanPlugin.pm | 8 ++++---- PVE/Network/SDN/Zones/VxlanPlugin.pm | 8 ++++---- 7 files changed, 43 insertions(+), 23 deletions(-) diff --git a/PVE/API2/Network/SDN/Vnets.pm b/PVE/API2/Network/SDN/Vnets.p= m index 23bc8bb..58ec21f 100644 --- a/PVE/API2/Network/SDN/Vnets.pm +++ b/PVE/API2/Network/SDN/Vnets.pm @@ -131,7 +131,7 @@ __PACKAGE__->register_method ({ my $zoneid =3D $cfg->{ids}->{$id}->{zone}; my $plugin_config =3D $zone_cfg->{ids}->{$zoneid}; my $plugin =3D PVE::Network::SDN::Zones::Plugin->lookup($plugin_con= fig->{type}); - $plugin->verify_tag($opts->{tag}); + $plugin->vnet_update_hook($cfg->{ids}->{$id}); =20 my $subnet_cfg =3D PVE::Network::SDN::Subnets::config(); =20 @@ -174,7 +174,7 @@ __PACKAGE__->register_method ({ my $zoneid =3D $cfg->{ids}->{$id}->{zone}; my $plugin_config =3D $zone_cfg->{ids}->{$zoneid}; my $plugin =3D PVE::Network::SDN::Zones::Plugin->lookup($plugin_con= fig->{type}); - $plugin->verify_tag($opts->{tag}); + $plugin->vnet_update_hook($cfg->{ids}->{$id}); =20 my $subnet_cfg =3D PVE::Network::SDN::Subnets::config(); =20 diff --git a/PVE/Network/SDN/Zones/EvpnPlugin.pm b/PVE/Network/SDN/Zones/= EvpnPlugin.pm index 83ceb3a..0ebe13e 100644 --- a/PVE/Network/SDN/Zones/EvpnPlugin.pm +++ b/PVE/Network/SDN/Zones/EvpnPlugin.pm @@ -5,6 +5,9 @@ use warnings; use PVE::Network::SDN::Zones::VxlanPlugin; use PVE::Tools qw($IPV4RE); use PVE::INotify; +use PVE::Cluster; +use PVE::Tools; + use PVE::Network::SDN::Controllers::EvpnPlugin; =20 use base('PVE::Network::SDN::Zones::VxlanPlugin'); @@ -143,15 +146,23 @@ sub on_update_hook { die "vrf-vxlan $vrfvxlan is already declared in $id" if (defined($zone_cfg->{ids}->{$id}->{'vrf-vxlan'}) && $zone_cfg->{ids= }->{$id}->{'vrf-vxlan'} eq $vrfvxlan); } + } =20 -sub verify_tag { - my ($class, $tag) =3D @_; =20 - raise_param_exc({ tag =3D> "missing vxlan tag"}) if !defined($tag); - raise_param_exc({ tag =3D> "vxlan tag max value is 16777216"}) if $t= ag > 16777216; +sub vnet_update_hook { + my ($class, $vnet) =3D @_; + + raise_param_exc({ tag =3D> "missing vxlan tag"}) if !defined($vnet->= {tag}); + raise_param_exc({ tag =3D> "vxlan tag max value is 16777216"}) if $v= net->{tag} > 16777216; + + if (!defined($vnet->{mac})) { + my $dc =3D PVE::Cluster::cfs_read_file('datacenter.cfg'); + $vnet->{mac} =3D PVE::Tools::random_ether_addr($dc->{mac_prefix}); + } } =20 + 1; =20 =20 diff --git a/PVE/Network/SDN/Zones/Plugin.pm b/PVE/Network/SDN/Zones/Plug= in.pm index 451699f..7f6db0e 100644 --- a/PVE/Network/SDN/Zones/Plugin.pm +++ b/PVE/Network/SDN/Zones/Plugin.pm @@ -139,8 +139,9 @@ sub on_update_hook { # do nothing by default } =20 -sub verify_tag { - my ($class, $tag) =3D @_; +sub vnet_update_hook { + my ($class, $vnet) =3D @_; + # do nothing by default } =20 diff --git a/PVE/Network/SDN/Zones/QinQPlugin.pm b/PVE/Network/SDN/Zones/= QinQPlugin.pm index 5fffd15..c828af4 100644 --- a/PVE/Network/SDN/Zones/QinQPlugin.pm +++ b/PVE/Network/SDN/Zones/QinQPlugin.pm @@ -211,11 +211,11 @@ sub status { return $err_msg; } =20 -sub verify_tag { - my ($class, $tag) =3D @_; +sub vnet_update_hook { + my ($class, $vnet) =3D @_; =20 - raise_param_exc({ tag =3D> "missing vlan tag"}) if !defined($tag); - raise_param_exc({ tag =3D> "vlan tag max value is 4096"}) if $tag > = 4096; + raise_param_exc({ tag =3D> "missing vlan tag"}) if !defined($vnet->{= tag}); + raise_param_exc({ tag =3D> "vlan tag max value is 4096"}) if $vnet->= {tag} > 4096; } =20 1; diff --git a/PVE/Network/SDN/Zones/SimplePlugin.pm b/PVE/Network/SDN/Zone= s/SimplePlugin.pm index 312dcbf..7006b13 100644 --- a/PVE/Network/SDN/Zones/SimplePlugin.pm +++ b/PVE/Network/SDN/Zones/SimplePlugin.pm @@ -4,6 +4,8 @@ use strict; use warnings; use PVE::Network::SDN::Zones::Plugin; use PVE::Exception qw(raise raise_param_exc); +use PVE::Cluster; +use PVE::Tools; =20 use base('PVE::Network::SDN::Zones::Plugin'); =20 @@ -71,10 +73,16 @@ sub status { return $err_msg; } =20 -sub verify_tag { - my ($class, $tag) =3D @_; =20 - raise_param_exc({ tag =3D> "vlan tag is not allowed on simple bridge= "}) if defined($tag); +sub vnet_update_hook { + my ($class, $vnet) =3D @_; + + raise_param_exc({ tag =3D> "vlan tag is not allowed on simple bridge= "}) if defined($vnet->{tag}); + + if (!defined($vnet->{mac})) { + my $dc =3D PVE::Cluster::cfs_read_file('datacenter.cfg'); + $vnet->{mac} =3D PVE::Tools::random_ether_addr($dc->{mac_prefix}= ); + } } =20 1; diff --git a/PVE/Network/SDN/Zones/VlanPlugin.pm b/PVE/Network/SDN/Zones/= VlanPlugin.pm index 8485ae1..7f90d31 100644 --- a/PVE/Network/SDN/Zones/VlanPlugin.pm +++ b/PVE/Network/SDN/Zones/VlanPlugin.pm @@ -170,11 +170,11 @@ sub status { return $err_msg; } =20 -sub verify_tag { - my ($class, $tag) =3D @_; +sub vnet_update_hook { + my ($class, $vnet) =3D @_; =20 - raise_param_exc({ tag =3D> "missing vlan tag"}) if !defined($tag); - raise_param_exc({ tag =3D> "vlan tag max value is 4096"}) if $tag > = 4096; + raise_param_exc({ tag =3D> "missing vlan tag"}) if !defined($vnet->{= tag}); + raise_param_exc({ tag =3D> "vlan tag max value is 4096"}) if $vnet->= {tag} > 4096; } =20 1; diff --git a/PVE/Network/SDN/Zones/VxlanPlugin.pm b/PVE/Network/SDN/Zones= /VxlanPlugin.pm index 8386c43..79af054 100644 --- a/PVE/Network/SDN/Zones/VxlanPlugin.pm +++ b/PVE/Network/SDN/Zones/VxlanPlugin.pm @@ -89,11 +89,11 @@ sub generate_sdn_config { return $config; } =20 -sub verify_tag { - my ($class, $tag) =3D @_; +sub vnet_update_hook { + my ($class, $vnet) =3D @_; =20 - raise_param_exc({ tag =3D> "missing vxlan tag"}) if !defined($tag); - raise_param_exc({ tag =3D> "vxlan tag max value is 16777216"}) if $t= ag > 16777216; + raise_param_exc({ tag =3D> "missing vxlan tag"}) if !defined($vnet->= {tag}); + raise_param_exc({ tag =3D> "vxlan tag max value is 16777216"}) if $v= net->{tag} > 16777216; } =20 1; --=20 2.20.1