From: Christian Ebner <c.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager 1/3] fix #5255: node: wol: add optional bind interface
Date: Tue, 5 Mar 2024 13:54:29 +0100 [thread overview]
Message-ID: <20240305125431.273796-2-c.ebner@proxmox.com> (raw)
In-Reply-To: <20240305125431.273796-1-c.ebner@proxmox.com>
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 <c.ebner@proxmox.com>
---
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
next prev parent reply other threads:[~2024-03-05 12:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-05 12:54 [pve-devel] [PATCH manager docs 0/3] add optional WoL config options Christian Ebner
2024-03-05 12:54 ` Christian Ebner [this message]
2024-03-21 17:27 ` [pve-devel] [PATCH manager 1/3] fix #5255: node: wol: add optional bind interface Thomas Lamprecht
2024-03-22 14:37 ` Christian Ebner
2024-03-26 9:21 ` Christian Ebner
2024-03-05 12:54 ` [pve-devel] [PATCH manager 2/3] fix #5255: node: wol: configurable broadcast address Christian Ebner
2024-03-05 12:54 ` [pve-devel] [PATCH docs 3/3] pvenode/wake-on-lan: mention optional config options Christian Ebner
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=20240305125431.273796-2-c.ebner@proxmox.com \
--to=c.ebner@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox