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 1E331BAE48 for ; Thu, 21 Mar 2024 18:28:07 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EBDFF32C0C for ; Thu, 21 Mar 2024 18:27:36 +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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 21 Mar 2024 18:27:35 +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 9FB7640EF9 for ; Thu, 21 Mar 2024 18:27:35 +0100 (CET) Message-ID: Date: Thu, 21 Mar 2024 18:27:34 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta To: Proxmox VE development discussion , Christian Ebner References: <20240305125431.273796-1-c.ebner@proxmox.com> <20240305125431.273796-2-c.ebner@proxmox.com> Content-Language: en-GB From: Thomas Lamprecht In-Reply-To: <20240305125431.273796-2-c.ebner@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.054 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pve-devel] [PATCH manager 1/3] fix #5255: node: wol: add optional bind interface 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: Thu, 21 Mar 2024 17:28:07 -0000 On 05/03/2024 13:54, Christian Ebner wrote: > Allows to optionally configure a local interface name to which to > bind to when sending a wake on lan packet to wake a remote node. > > Default behaviour remains to send the packet via the interface for > the default gateway. > > Signed-off-by: Christian Ebner > --- > PVE/API2/Nodes.pm | 13 ++++++++++++- > PVE/NodeConfig.pm | 6 ++++++ > 2 files changed, 18 insertions(+), 1 deletion(-) > > diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm > index cc5ee65e..620dac1c 100644 > --- a/PVE/API2/Nodes.pm > +++ b/PVE/API2/Nodes.pm > @@ -682,9 +682,10 @@ __PACKAGE__->register_method({ > my ($param) = @_; > > my $node = $param->{node}; > + my $local_node = PVE::INotify::nodename(); > > die "'$node' is local node, cannot wake my self!\n" > - if $node eq 'localhost' || $node eq PVE::INotify::nodename(); > + if $node eq 'localhost' || $node eq $local_node; > > PVE::Cluster::check_node_exists($node); > > @@ -694,6 +695,9 @@ __PACKAGE__->register_method({ > die "No wake on LAN MAC address defined for '$node'!\n"; > } > > + my $local_config = PVE::NodeConfig::load_config($local_node); > + my $bind_iface = $local_config->{'wakeonlan-bind-interface'}; > + > $mac_addr =~ s/://g; > my $packet = chr(0xff) x 6 . pack('H*', $mac_addr) x 16; > > @@ -706,6 +710,13 @@ __PACKAGE__->register_method({ > setsockopt($sock, Socket::SOL_SOCKET, Socket::SO_BROADCAST, 1) > || die "Unable to set socket option: $!\n"; > > + if (defined($bind_iface)) { > + # Null terminated interface name > + my $bind_iface_raw = pack('Z*', $bind_iface); > + setsockopt($sock, Socket::SOL_SOCKET, Socket::SO_BINDTODEVICE, $bind_iface_raw) > + || die "Unable to bind socket to interface '$bind_iface': $!\n"; > + } > + > send($sock, $packet, 0, $to) > || die "Unable to send packet: $!\n"; > > diff --git a/PVE/NodeConfig.pm b/PVE/NodeConfig.pm > index 941e6009..5450ab2f 100644 > --- a/PVE/NodeConfig.pm > +++ b/PVE/NodeConfig.pm > @@ -91,6 +91,12 @@ my $confdesc = { > format => 'mac-addr', > optional => 1, > }, > + 'wakeonlan-bind-interface' => { > + type => 'string', > + description => 'Bind to this interface when sending wake on LAN packet', > + format => 'pve-iface', > + optional => 1, > + }, we could transform the existing "wakeonlan" property into a format string, keep the new mac property as default_key there for backwards compat, kinda like "acme" is a format string in the same config. For such a config option that would be IMO fitting and avoid bloating the "top-level" format. > 'startall-onboot-delay' => { > description => 'Initial delay in seconds, before starting all the Virtual Guests with on-boot enabled.', > type => 'integer',