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 2773B65FF8 for ; Tue, 5 Jan 2021 10:36:11 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E593D254FC for ; Tue, 5 Jan 2021 10:35:40 +0100 (CET) Received: from kvmformation1.odiso.net (globalOdiso.M6Lille.odiso.net [89.248.211.242]) by firstgate.proxmox.com (Proxmox) with ESMTP id 761A5254B8 for ; Tue, 5 Jan 2021 10:35:37 +0100 (CET) Received: by kvmformation1.odiso.net (Postfix, from userid 0) id 49FAEA0BD5; Tue, 5 Jan 2021 10:35:37 +0100 (CET) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Date: Tue, 5 Jan 2021 10:35:23 +0100 Message-Id: <20210105093536.1727641-3-aderumier@odiso.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210105093536.1727641-1-aderumier@odiso.com> References: <20210105093536.1727641-1-aderumier@odiso.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 1 AWL -0.141 Adjusted score from AWL reputation of From: address HEADER_FROM_DIFFERENT_DOMAINS 0.248 From and EnvelopeFrom 2nd level mail domains are different 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 KHOP_HELO_FCRDNS 0.287 Relay HELO differs from its IP's reverse DNS NO_DNS_FOR_FROM 0.379 Envelope sender has no MX or A DNS records 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [plugin.pm, subnets.pm, netboxplugin.pm, phpipamplugin.pm, pveplugin.pm, subnetplugin.pm, vnets.pm] Subject: [pve-devel] [PATCH pve-network 02/15] ipams: add mac address 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: Tue, 05 Jan 2021 09:36:11 -0000 Signed-off-by: Alexandre Derumier --- PVE/Network/SDN/Ipams/NetboxPlugin.pm | 6 ++++-- PVE/Network/SDN/Ipams/PVEPlugin.pm | 4 ++-- PVE/Network/SDN/Ipams/PhpIpamPlugin.pm | 7 +++++-- PVE/Network/SDN/Ipams/Plugin.pm | 4 ++-- PVE/Network/SDN/SubnetPlugin.pm | 4 +++- PVE/Network/SDN/Subnets.pm | 8 ++++---- PVE/Network/SDN/Vnets.pm | 8 ++++---- 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/PVE/Network/SDN/Ipams/NetboxPlugin.pm b/PVE/Network/SDN/Ipams/NetboxPlugin.pm index 298634d..3c99218 100644 --- a/PVE/Network/SDN/Ipams/NetboxPlugin.pm +++ b/PVE/Network/SDN/Ipams/NetboxPlugin.pm @@ -77,13 +77,14 @@ sub del_subnet { } sub add_ip { - my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $description, $is_gateway) = @_; + my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway) = @_; my $mask = $subnet->{mask}; my $url = $plugin_config->{url}; my $token = $plugin_config->{token}; my $section = $plugin_config->{section}; my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Authorization' => "token $token"]; + $description .= " mac:$mac" if $mac && $description; my $params = { address => "$ip/$mask", dns_name => $hostname, description => $description }; @@ -97,7 +98,7 @@ sub add_ip { } sub add_next_freeip { - my ($class, $plugin_config, $subnetid, $subnet, $hostname, $description) = @_; + my ($class, $plugin_config, $subnetid, $subnet, $hostname, $mac, $description) = @_; my $cidr = $subnet->{cidr}; @@ -106,6 +107,7 @@ sub add_next_freeip { my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Authorization' => "token $token"]; my $internalid = get_prefix_id($url, $cidr, $headers); + $description .= " mac:$mac" if $mac && $description; my $params = { dns_name => $hostname, description => $description }; diff --git a/PVE/Network/SDN/Ipams/PVEPlugin.pm b/PVE/Network/SDN/Ipams/PVEPlugin.pm index 4925274..c02b6db 100644 --- a/PVE/Network/SDN/Ipams/PVEPlugin.pm +++ b/PVE/Network/SDN/Ipams/PVEPlugin.pm @@ -82,7 +82,7 @@ sub del_subnet { } sub add_ip { - my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $description, $is_gateway) = @_; + my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway) = @_; my $cidr = $subnet->{cidr}; my $zone = $subnet->{zone}; @@ -106,7 +106,7 @@ sub add_ip { } sub add_next_freeip { - my ($class, $plugin_config, $subnetid, $subnet, $hostname, $description) = @_; + my ($class, $plugin_config, $subnetid, $subnet, $hostname, $mac, $description) = @_; my $cidr = $subnet->{cidr}; my $network = $subnet->{network}; diff --git a/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm b/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm index 6261764..ab06f7b 100644 --- a/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm +++ b/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm @@ -95,7 +95,7 @@ sub del_subnet { } sub add_ip { - my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $description, $is_gateway) = @_; + my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway) = @_; my $cidr = $subnet->{cidr}; my $url = $plugin_config->{url}; @@ -111,6 +111,7 @@ sub add_ip { hostname => $hostname, description => $description, }; + $params->{mac} = $mac if $mac; eval { PVE::Network::SDN::Ipams::Plugin::api_request("POST", "$url/addresses/", $headers, $params); @@ -122,7 +123,7 @@ sub add_ip { } sub add_next_freeip { - my ($class, $plugin_config, $subnetid, $subnet, $hostname, $description) = @_; + my ($class, $plugin_config, $subnetid, $subnet, $hostname, $mac, $description) = @_; my $cidr = $subnet->{cidr}; my $mask = $subnet->{mask}; @@ -137,6 +138,8 @@ sub add_next_freeip { description => $description, }; + $params->{mac} = $mac if $mac; + my $ip = undef; eval { my $result = PVE::Network::SDN::Ipams::Plugin::api_request("POST", "$url/addresses/first_free/$internalid/", $headers, $params); diff --git a/PVE/Network/SDN/Ipams/Plugin.pm b/PVE/Network/SDN/Ipams/Plugin.pm index 065225c..10e5212 100644 --- a/PVE/Network/SDN/Ipams/Plugin.pm +++ b/PVE/Network/SDN/Ipams/Plugin.pm @@ -75,12 +75,12 @@ sub del_subnet { } sub add_ip { - my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $description, $is_gateway) = @_; + my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway) = @_; } sub add_next_freeip { - my ($class, $plugin_config, $subnetid, $subnet) = @_; + my ($class, $plugin_config, $subnetid, $subnet, $hostname, $mac, $description) = @_; } sub del_ip { diff --git a/PVE/Network/SDN/SubnetPlugin.pm b/PVE/Network/SDN/SubnetPlugin.pm index 2d6d808..68efeb6 100644 --- a/PVE/Network/SDN/SubnetPlugin.pm +++ b/PVE/Network/SDN/SubnetPlugin.pm @@ -113,11 +113,13 @@ sub on_update_hook { my $reversedns = $zone->{reversedns}; my $old_gateway = $old_subnet->{gateway} if $old_subnet; + my $mac = undef; if($vnetid) { my $vnet = PVE::Network::SDN::Vnets::get_vnet($vnetid); raise_param_exc({ vnet => "$vnetid don't exist"}) if !$vnet; raise_param_exc({ vnet => "you can't add a subnet on a vlanaware vnet"}) if $vnet->{vlanaware}; + $mac = $vnet->{mac}; } my $pointopoint = 1 if Net::IP::ip_is_ipv4($gateway) && $mask == 32; @@ -145,7 +147,7 @@ sub on_update_hook { if(!$old_gateway || $gateway && $gateway ne $old_gateway) { my $hostname = "$vnetid-gw"; my $description = "$vnetid gw"; - PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $gateway, $hostname, $description, 1); + PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $gateway, $hostname, $mac, $description, 1); } #delete old gateway after update diff --git a/PVE/Network/SDN/Subnets.pm b/PVE/Network/SDN/Subnets.pm index 81970a1..b752e2c 100644 --- a/PVE/Network/SDN/Subnets.pm +++ b/PVE/Network/SDN/Subnets.pm @@ -162,7 +162,7 @@ my $del_dns_ptr_record = sub { }; sub next_free_ip { - my ($zone, $subnetid, $subnet, $hostname, $description) = @_; + my ($zone, $subnetid, $subnet, $hostname, $mac, $description) = @_; my $cidr = undef; my $ip = undef; @@ -184,7 +184,7 @@ sub next_free_ip { my $plugin_config = $ipam_cfg->{ids}->{$ipamid}; my $plugin = PVE::Network::SDN::Ipams::Plugin->lookup($plugin_config->{type}); eval { - $cidr = $plugin->add_next_freeip($plugin_config, $subnetid, $subnet, $hostname, $description); + $cidr = $plugin->add_next_freeip($plugin_config, $subnetid, $subnet, $hostname, $mac, $description); ($ip, undef) = split(/\//, $cidr); }; die $@ if $@; @@ -210,7 +210,7 @@ sub next_free_ip { } sub add_ip { - my ($zone, $subnetid, $subnet, $ip, $hostname, $description) = @_; + my ($zone, $subnetid, $subnet, $ip, $hostname, $mac, $description) = @_; return if !$subnet || !$ip; @@ -235,7 +235,7 @@ sub add_ip { my $plugin_config = $ipam_cfg->{ids}->{$ipamid}; my $plugin = PVE::Network::SDN::Ipams::Plugin->lookup($plugin_config->{type}); eval { - $plugin->add_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $description); + $plugin->add_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description); }; die $@ if $@; } diff --git a/PVE/Network/SDN/Vnets.pm b/PVE/Network/SDN/Vnets.pm index 1da1d57..d68ffab 100644 --- a/PVE/Network/SDN/Vnets.pm +++ b/PVE/Network/SDN/Vnets.pm @@ -80,7 +80,7 @@ sub get_subnets { } sub get_next_free_cidr { - my ($vnetid, $hostname, $description, $ipversion) = @_; + my ($vnetid, $hostname, $mac, $description, $ipversion) = @_; my $vnet = PVE::Network::SDN::Vnets::get_vnet($vnetid); my $zoneid = $vnet->{zone}; @@ -99,7 +99,7 @@ sub get_next_free_cidr { $subnetcount++; if ($zone->{ipam}) { eval { - $ip = PVE::Network::SDN::Subnets::next_free_ip($zone, $subnetid, $subnet, $hostname, $description); + $ip = PVE::Network::SDN::Subnets::next_free_ip($zone, $subnetid, $subnet, $hostname, $mac, $description); }; warn $@ if $@; } @@ -111,7 +111,7 @@ sub get_next_free_cidr { } sub add_cidr { - my ($vnetid, $cidr, $hostname, $description) = @_; + my ($vnetid, $cidr, $hostname, $mac, $description) = @_; my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid, 1); my $vnet = PVE::Network::SDN::Vnets::get_vnet($vnetid); @@ -122,7 +122,7 @@ sub add_cidr { die "ip address is not in cidr format" if !$mask; my ($subnetid, $subnet) = PVE::Network::SDN::Subnets::find_ip_subnet($ip, $mask, $subnets); - PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $description); + PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $description); } sub del_cidr { -- 2.20.1