* [pve-devel] [PATCH manager docs 0/3] add optional WoL config options
@ 2024-03-05 12:54 Christian Ebner
2024-03-05 12:54 ` [pve-devel] [PATCH manager 1/3] fix #5255: node: wol: add optional bind interface Christian Ebner
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Christian Ebner @ 2024-03-05 12:54 UTC (permalink / raw)
To: pve-devel
For certain network setups the default values currently used to send
a wake on lan magic packet are not correct, e.g. it will get send via
the interface for which the default gateway is configured.
This patches add optional configuration options to set a bind
interface, over which to send the WoL packet and/or set a broadcast
address to use.
The functionality was tested by listening on all interfaces of the
sending host via `tcpdump -i any udp port 9`, and testing the
combinations of
`pvenode config set -wakeonlan-bind-interface <iface-name>` and
`pvenode config set -wakeonlan-broadcast-address <broadcast-address>`.
See also the thread in the community forum
https://forum.proxmox.com/threads/123459/
pve-manager:
Christian Ebner (2):
fix #5255: node: wol: add optional bind interface
fix #5255: node: wol: configurable broadcast address
PVE/API2/Nodes.pm | 16 ++++++++++++++--
PVE/NodeConfig.pm | 12 ++++++++++++
2 files changed, 26 insertions(+), 2 deletions(-)
pve-docs:
Christian Ebner (1):
pvenode/wake-on-lan: mention optional config options
pvenode.adoc | 14 ++++++++++++++
1 file changed, 14 insertions(+)
--
2.39.2
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pve-devel] [PATCH manager 1/3] fix #5255: node: wol: add optional bind interface
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
2024-03-21 17:27 ` Thomas Lamprecht
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
2 siblings, 1 reply; 7+ messages in thread
From: Christian Ebner @ 2024-03-05 12:54 UTC (permalink / raw)
To: pve-devel
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pve-devel] [PATCH manager 2/3] fix #5255: node: wol: configurable broadcast address
2024-03-05 12:54 [pve-devel] [PATCH manager docs 0/3] add optional WoL config options Christian Ebner
2024-03-05 12:54 ` [pve-devel] [PATCH manager 1/3] fix #5255: node: wol: add optional bind interface Christian Ebner
@ 2024-03-05 12:54 ` Christian Ebner
2024-03-05 12:54 ` [pve-devel] [PATCH docs 3/3] pvenode/wake-on-lan: mention optional config options Christian Ebner
2 siblings, 0 replies; 7+ messages in thread
From: Christian Ebner @ 2024-03-05 12:54 UTC (permalink / raw)
To: pve-devel
Allows to configure a custom broadcast address to use when sending a
wake on lan packet to wake a remote node.
Default behaviour remains to fallback to 255.255.255.255.
Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
PVE/API2/Nodes.pm | 3 ++-
PVE/NodeConfig.pm | 6 ++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index 620dac1c..e73fc28f 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -697,11 +697,12 @@ __PACKAGE__->register_method({
my $local_config = PVE::NodeConfig::load_config($local_node);
my $bind_iface = $local_config->{'wakeonlan-bind-interface'};
+ my $broadcast_addr = $local_config->{'wakeonlan-broadcast-address'} // '255.255.255.255';
$mac_addr =~ s/://g;
my $packet = chr(0xff) x 6 . pack('H*', $mac_addr) x 16;
- my $addr = gethostbyname('255.255.255.255');
+ my $addr = gethostbyname($broadcast_addr);
my $port = getservbyname('discard', 'udp');
my $to = Socket::pack_sockaddr_in($port, $addr);
diff --git a/PVE/NodeConfig.pm b/PVE/NodeConfig.pm
index 5450ab2f..e3feaaa6 100644
--- a/PVE/NodeConfig.pm
+++ b/PVE/NodeConfig.pm
@@ -97,6 +97,12 @@ my $confdesc = {
format => 'pve-iface',
optional => 1,
},
+ 'wakeonlan-broadcast-address' => {
+ type => 'string',
+ description => 'IPv4 broadcast address to use when sending wake on LAN packet',
+ format => 'ipv4',
+ 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pve-devel] [PATCH docs 3/3] pvenode/wake-on-lan: mention optional config options
2024-03-05 12:54 [pve-devel] [PATCH manager docs 0/3] add optional WoL config options Christian Ebner
2024-03-05 12:54 ` [pve-devel] [PATCH manager 1/3] fix #5255: node: wol: add optional bind interface 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 ` Christian Ebner
2 siblings, 0 replies; 7+ messages in thread
From: Christian Ebner @ 2024-03-05 12:54 UTC (permalink / raw)
To: pve-devel
Show how to configure the optional bind interface and broadcast address
options via `pvenode`.
Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
pvenode.adoc | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/pvenode.adoc b/pvenode.adoc
index 59eeecb..8a1da08 100644
--- a/pvenode.adoc
+++ b/pvenode.adoc
@@ -87,6 +87,20 @@ of `<node>` obtained from the `wakeonlan` property. The node-specific
pvenode config set -wakeonlan XX:XX:XX:XX:XX:XX
----
+Optionally, the interface via which to send the WoL packet can be specified by
+setting the `wakeonlan-bind-interface` via the following command:
+
+----
+pvenode config set -wakeonlan-bind-interface <iface-name>
+----
+
+The broadcast address used when sending the WoL packet can further be set by
+specifying the `wakeonlan-broadcast-address` using the following command:
+
+----
+pvenode config set -wakeonlan-broadcast-address <broadcast-address>
+----
+
Task History
~~~~~~~~~~~~
--
2.39.2
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [pve-devel] [PATCH manager 1/3] fix #5255: node: wol: add optional bind interface
2024-03-05 12:54 ` [pve-devel] [PATCH manager 1/3] fix #5255: node: wol: add optional bind interface Christian Ebner
@ 2024-03-21 17:27 ` Thomas Lamprecht
2024-03-22 14:37 ` Christian Ebner
0 siblings, 1 reply; 7+ messages in thread
From: Thomas Lamprecht @ 2024-03-21 17:27 UTC (permalink / raw)
To: Proxmox VE development discussion, Christian Ebner
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 <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,
> + },
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',
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [pve-devel] [PATCH manager 1/3] fix #5255: node: wol: add optional bind interface
2024-03-21 17:27 ` Thomas Lamprecht
@ 2024-03-22 14:37 ` Christian Ebner
2024-03-26 9:21 ` Christian Ebner
0 siblings, 1 reply; 7+ messages in thread
From: Christian Ebner @ 2024-03-22 14:37 UTC (permalink / raw)
To: Thomas Lamprecht, Proxmox VE development discussion
> On 21.03.2024 18:27 CET Thomas Lamprecht <t.lamprecht@proxmox.com> wrote:
>
>
> On 05/03/2024 13:54, Christian Ebner wrote:
> > + '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.
Agreed, will send a new version with the suggested changes to the format
string.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [pve-devel] [PATCH manager 1/3] fix #5255: node: wol: add optional bind interface
2024-03-22 14:37 ` Christian Ebner
@ 2024-03-26 9:21 ` Christian Ebner
0 siblings, 0 replies; 7+ messages in thread
From: Christian Ebner @ 2024-03-26 9:21 UTC (permalink / raw)
To: Thomas Lamprecht, Proxmox VE development discussion
> On 22.03.2024 15:37 CET Christian Ebner <c.ebner@proxmox.com> wrote:
>
> Agreed, will send a new version with the suggested changes to the format
> string.
Version 2 of the patches:
https://lists.proxmox.com/pipermail/pve-devel/2024-March/062397.html
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-03-26 9:21 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-05 12:54 [pve-devel] [PATCH manager docs 0/3] add optional WoL config options Christian Ebner
2024-03-05 12:54 ` [pve-devel] [PATCH manager 1/3] fix #5255: node: wol: add optional bind interface Christian Ebner
2024-03-21 17:27 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox