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 2422197841 for ; Tue, 5 Mar 2024 13:54:41 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 044B27E09 for ; Tue, 5 Mar 2024 13:54:41 +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 ; Tue, 5 Mar 2024 13:54:40 +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 3A9BF44127 for ; Tue, 5 Mar 2024 13:54:40 +0100 (CET) From: Christian Ebner To: pve-devel@lists.proxmox.com Date: Tue, 5 Mar 2024 13:54:29 +0100 Message-Id: <20240305125431.273796-2-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240305125431.273796-1-c.ebner@proxmox.com> References: <20240305125431.273796-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.041 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 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [nodes.pm, nodeconfig.pm] Subject: [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: Tue, 05 Mar 2024 12:54:41 -0000 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, + }, 'startall-onboot-delay' => { description => 'Initial delay in seconds, before starting all the Virtual Guests with on-boot enabled.', type => 'integer', -- 2.39.2