public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH v2 pve-manager pve-docs 0/4] add optional WoL config options
@ 2024-03-26  9:16 Christian Ebner
  2024-03-26  9:16 ` [pve-devel] [PATCH v2 pve-manager 1/4] node: config: make wakeonlan a property string Christian Ebner
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Christian Ebner @ 2024-03-26  9:16 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 XX:XX:XX:XX:XX:XX,bind-interface=<iface-name>`

and

`pvenode config set -wakeonlan XX:XX:XX:XX:XX:XX,broadcast-address=<broadcast-address>`.

See also the thread in the community forum
https://forum.proxmox.com/threads/123459/

pve-manager:

Christian Ebner (3):
  node: config: make wakeonlan a property string
  fix #5255: node: wol: add optional bind interface
  fix #5255: node: wol: configurable broadcast address

 PVE/API2/Nodes.pm | 23 ++++++++++++++++----
 PVE/NodeConfig.pm | 53 +++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 66 insertions(+), 10 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 v2 pve-manager 1/4] node: config: make wakeonlan a property string
  2024-03-26  9:16 [pve-devel] [PATCH v2 pve-manager pve-docs 0/4] add optional WoL config options Christian Ebner
@ 2024-03-26  9:16 ` Christian Ebner
  2024-03-26  9:16 ` [pve-devel] [PATCH v2 pve-manager 2/4] fix #5255: node: wol: add optional bind interface Christian Ebner
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Christian Ebner @ 2024-03-26  9:16 UTC (permalink / raw)
  To: pve-devel

Moves the wakeonlan property to be a property string, with current mac
address as default key. This allows to later add further optional
properties such as bind-interface and broadcast-address.

Adds the `get_wakeonlan_config` helper function to parse the string
when read from the node config.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
changes since version 1:
- not present in previous version

 PVE/API2/Nodes.pm |  6 ++++--
 PVE/NodeConfig.pm | 39 +++++++++++++++++++++++++++++++++------
 2 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index cc5ee65e..6e75cd5f 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -25,6 +25,7 @@ use PVE::HA::Env::PVE2;
 use PVE::INotify;
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::LXC;
+use PVE::NodeConfig;
 use PVE::ProcFSTools;
 use PVE::QemuConfig;
 use PVE::QemuServer;
@@ -689,7 +690,8 @@ __PACKAGE__->register_method({
 	PVE::Cluster::check_node_exists($node);
 
 	my $config = PVE::NodeConfig::load_config($node);
-	my $mac_addr = $config->{wakeonlan};
+	my $wol_config = PVE::NodeConfig::get_wakeonlan_config($config);
+	my $mac_addr = $wol_config->{mac};
 	if (!defined($mac_addr)) {
 	    die "No wake on LAN MAC address defined for '$node'!\n";
 	}
@@ -711,7 +713,7 @@ __PACKAGE__->register_method({
 
 	close($sock);
 
-	return $config->{wakeonlan};
+	return $wol_config->{mac};
     }});
 
 __PACKAGE__->register_method({
diff --git a/PVE/NodeConfig.pm b/PVE/NodeConfig.pm
index 941e6009..a09c9be1 100644
--- a/PVE/NodeConfig.pm
+++ b/PVE/NodeConfig.pm
@@ -85,12 +85,6 @@ my $confdesc = {
 	maxLength => 64 * 1024,
 	optional => 1,
     },
-    wakeonlan => {
-	type => 'string',
-	description => 'MAC address for wake on LAN',
-	format => 'mac-addr',
-	optional => 1,
-    },
     'startall-onboot-delay' => {
 	description => 'Initial delay in seconds, before starting all the Virtual Guests with on-boot enabled.',
 	type => 'integer',
@@ -101,6 +95,23 @@ my $confdesc = {
     },
 };
 
+my $wakeonlan_desc = {
+    mac => {
+	type => 'string',
+	description => 'MAC address for wake on LAN',
+	format => 'mac-addr',
+	format_description => 'MAC address',
+	default_key => 1,
+    },
+};
+
+$confdesc->{wakeonlan} = {
+    type => 'string',
+    description => 'Node specific wake on LAN settings.',
+    format => $wakeonlan_desc,
+    optional => 1,
+};
+
 my $acme_domain_desc = {
     domain => {
 	type => 'string',
@@ -193,6 +204,22 @@ sub write_node_config {
     return $raw;
 }
 
+sub get_wakeonlan_config {
+    my ($node_conf) = @_;
+
+    $node_conf //= {};
+
+    my $res = {};
+    if (defined($node_conf->{wakeonlan})) {
+	$res = eval {
+	    PVE::JSONSchema::parse_property_string($wakeonlan_desc, $node_conf->{wakeonlan})
+	};
+	die $@ if $@;
+    }
+
+    return $res;
+}
+
 # we always convert domain values to lower case, since DNS entries are not case
 # sensitive and ACME implementations might convert the ordered identifiers
 # to lower case
-- 
2.39.2





^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pve-devel] [PATCH v2 pve-manager 2/4] fix #5255: node: wol: add optional bind interface
  2024-03-26  9:16 [pve-devel] [PATCH v2 pve-manager pve-docs 0/4] add optional WoL config options Christian Ebner
  2024-03-26  9:16 ` [pve-devel] [PATCH v2 pve-manager 1/4] node: config: make wakeonlan a property string Christian Ebner
@ 2024-03-26  9:16 ` Christian Ebner
  2024-03-26  9:16 ` [pve-devel] [PATCH v2 pve-manager 3/4] fix #5255: node: wol: configurable broadcast address Christian Ebner
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Christian Ebner @ 2024-03-26  9:16 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>
---
changes since version 1:
- Adapted to use property string

 PVE/API2/Nodes.pm | 14 +++++++++++++-
 PVE/NodeConfig.pm |  7 +++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index 6e75cd5f..9ffe7494 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -683,9 +683,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);
 
@@ -696,6 +697,10 @@ __PACKAGE__->register_method({
 	    die "No wake on LAN MAC address defined for '$node'!\n";
 	}
 
+	my $local_config = PVE::NodeConfig::load_config($local_node);
+	my $local_wol_config = PVE::NodeConfig::get_wakeonlan_config($local_config);
+	my $bind_iface = $local_wol_config->{'bind-interface'};
+
 	$mac_addr =~ s/://g;
 	my $packet = chr(0xff) x 6 . pack('H*', $mac_addr) x 16;
 
@@ -708,6 +713,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 a09c9be1..ee316296 100644
--- a/PVE/NodeConfig.pm
+++ b/PVE/NodeConfig.pm
@@ -103,6 +103,13 @@ my $wakeonlan_desc = {
 	format_description => 'MAC address',
 	default_key => 1,
     },
+    'bind-interface' => {
+	type => 'string',
+	description => 'Bind to this interface when sending wake on LAN packet',
+	format => 'pve-iface',
+	format_description => 'bind interface',
+	optional => 1,
+    },
 };
 
 $confdesc->{wakeonlan} = {
-- 
2.39.2





^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pve-devel] [PATCH v2 pve-manager 3/4] fix #5255: node: wol: configurable broadcast address
  2024-03-26  9:16 [pve-devel] [PATCH v2 pve-manager pve-docs 0/4] add optional WoL config options Christian Ebner
  2024-03-26  9:16 ` [pve-devel] [PATCH v2 pve-manager 1/4] node: config: make wakeonlan a property string Christian Ebner
  2024-03-26  9:16 ` [pve-devel] [PATCH v2 pve-manager 2/4] fix #5255: node: wol: add optional bind interface Christian Ebner
@ 2024-03-26  9:16 ` Christian Ebner
  2024-03-26  9:16 ` [pve-devel] [PATCH v2 pve-docs 4/4] pvenode/wake-on-lan: mention optional config options Christian Ebner
  2024-03-28 17:27 ` [pve-devel] applied-series: [PATCH v2 pve-manager pve-docs 0/4] add optional WoL " Thomas Lamprecht
  4 siblings, 0 replies; 7+ messages in thread
From: Christian Ebner @ 2024-03-26  9:16 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>
---
changes since version 1:
- Adapted to use property string

 PVE/API2/Nodes.pm | 3 ++-
 PVE/NodeConfig.pm | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index 9ffe7494..4f9640b2 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -700,11 +700,12 @@ __PACKAGE__->register_method({
 	my $local_config = PVE::NodeConfig::load_config($local_node);
 	my $local_wol_config = PVE::NodeConfig::get_wakeonlan_config($local_config);
 	my $bind_iface = $local_wol_config->{'bind-interface'};
+	my $broadcast_addr = $local_wol_config->{'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 ee316296..5fa8001c 100644
--- a/PVE/NodeConfig.pm
+++ b/PVE/NodeConfig.pm
@@ -110,6 +110,13 @@ my $wakeonlan_desc = {
 	format_description => 'bind interface',
 	optional => 1,
     },
+    'broadcast-address' => {
+	type => 'string',
+	description => 'IPv4 broadcast address to use when sending wake on LAN packet',
+	format => 'ipv4',
+	format_description => 'IPv4 broadcast address',
+	optional => 1,
+    },
 };
 
 $confdesc->{wakeonlan} = {
-- 
2.39.2





^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pve-devel] [PATCH v2 pve-docs 4/4] pvenode/wake-on-lan: mention optional config options
  2024-03-26  9:16 [pve-devel] [PATCH v2 pve-manager pve-docs 0/4] add optional WoL config options Christian Ebner
                   ` (2 preceding siblings ...)
  2024-03-26  9:16 ` [pve-devel] [PATCH v2 pve-manager 3/4] fix #5255: node: wol: configurable broadcast address Christian Ebner
@ 2024-03-26  9:16 ` Christian Ebner
  2024-03-28 17:27 ` [pve-devel] applied-series: [PATCH v2 pve-manager pve-docs 0/4] add optional WoL " Thomas Lamprecht
  4 siblings, 0 replies; 7+ messages in thread
From: Christian Ebner @ 2024-03-26  9:16 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..6cf5bc9 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 `bind-interface` via the following command:
+
+----
+pvenode config set -wakeonlan XX:XX:XX:XX:XX:XX,bind-interface=<iface-name>
+----
+
+The broadcast address used when sending the WoL packet can further be set by
+specifying the `broadcast-address` using the following command:
+
+----
+pvenode config set -wakeonlan XX:XX:XX:XX:XX:XX,broadcast-address=<broadcast-address>
+----
+
 Task History
 ~~~~~~~~~~~~
 
-- 
2.39.2





^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pve-devel] applied-series: [PATCH v2 pve-manager pve-docs 0/4] add optional WoL config options
  2024-03-26  9:16 [pve-devel] [PATCH v2 pve-manager pve-docs 0/4] add optional WoL config options Christian Ebner
                   ` (3 preceding siblings ...)
  2024-03-26  9:16 ` [pve-devel] [PATCH v2 pve-docs 4/4] pvenode/wake-on-lan: mention optional config options Christian Ebner
@ 2024-03-28 17:27 ` Thomas Lamprecht
  2024-03-29  7:44   ` Christian Ebner
  4 siblings, 1 reply; 7+ messages in thread
From: Thomas Lamprecht @ 2024-03-28 17:27 UTC (permalink / raw)
  To: Proxmox VE development discussion, Christian Ebner

Am 26/03/2024 um 10:16 schrieb Christian Ebner:
> 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 XX:XX:XX:XX:XX:XX,bind-interface=<iface-name>`
> 
> and
> 
> `pvenode config set -wakeonlan XX:XX:XX:XX:XX:XX,broadcast-address=<broadcast-address>`.
> 
> See also the thread in the community forum
> https://forum.proxmox.com/threads/123459/
> 
> pve-manager:
> 
> Christian Ebner (3):
>   node: config: make wakeonlan a property string
>   fix #5255: node: wol: add optional bind interface
>   fix #5255: node: wol: configurable broadcast address
> 
>  PVE/API2/Nodes.pm | 23 ++++++++++++++++----
>  PVE/NodeConfig.pm | 53 +++++++++++++++++++++++++++++++++++++++++------
>  2 files changed, 66 insertions(+), 10 deletions(-)
> 
> pve-docs:
> 
> Christian Ebner (1):
>   pvenode/wake-on-lan: mention optional config options
> 
>  pvenode.adoc | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 


applied, thanks!

I did some very minor follow-ups mostly to document the current default in
the schema and docs and a small style fix (well not even really style wise,
but rather making the part with assigning and checking the $bind_interface
variable slightly shorter).

While this is slightly niche it might still make sense to add this to the
web UI too (WoL is exposed via Node -> Options) for completeness sake.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [pve-devel] applied-series: [PATCH v2 pve-manager pve-docs 0/4] add optional WoL config options
  2024-03-28 17:27 ` [pve-devel] applied-series: [PATCH v2 pve-manager pve-docs 0/4] add optional WoL " Thomas Lamprecht
@ 2024-03-29  7:44   ` Christian Ebner
  0 siblings, 0 replies; 7+ messages in thread
From: Christian Ebner @ 2024-03-29  7:44 UTC (permalink / raw)
  To: Thomas Lamprecht, Proxmox VE development discussion

On 3/28/24 18:27, Thomas Lamprecht wrote:
>
> applied, thanks!
> 
> I did some very minor follow-ups mostly to document the current default in
> the schema and docs and a small style fix (well not even really style wise,
> but rather making the part with assigning and checking the $bind_interface
> variable slightly shorter).

Ah yes, that is indeed more compact :)

> 
> While this is slightly niche it might still make sense to add this to the
> web UI too (WoL is exposed via Node -> Options) for completeness sake.

Will send a patch for editing the properties via the UI as well, thanks 
for the hint.




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-29  7:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-26  9:16 [pve-devel] [PATCH v2 pve-manager pve-docs 0/4] add optional WoL config options Christian Ebner
2024-03-26  9:16 ` [pve-devel] [PATCH v2 pve-manager 1/4] node: config: make wakeonlan a property string Christian Ebner
2024-03-26  9:16 ` [pve-devel] [PATCH v2 pve-manager 2/4] fix #5255: node: wol: add optional bind interface Christian Ebner
2024-03-26  9:16 ` [pve-devel] [PATCH v2 pve-manager 3/4] fix #5255: node: wol: configurable broadcast address Christian Ebner
2024-03-26  9:16 ` [pve-devel] [PATCH v2 pve-docs 4/4] pvenode/wake-on-lan: mention optional config options Christian Ebner
2024-03-28 17:27 ` [pve-devel] applied-series: [PATCH v2 pve-manager pve-docs 0/4] add optional WoL " Thomas Lamprecht
2024-03-29  7:44   ` Christian Ebner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal