Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUACAMOLE-1686: Make WOL functionality capable of testing connectivity to the server. #470

Merged
merged 5 commits into from
May 22, 2024

Conversation

necouchman
Copy link
Contributor

This PR adds to the Wake-on-LAN functionality, implementing a new function that checks the connection to the destination server both before sending the WOL packet and, again, after sending the packet. If the host responds before sending the WOL packet, there is no need to actually send the WOL packet. If the packet does get sent, then the function will attempt to connect, then wait for the specified time period and then re-try the connection.

As a by-product of this implementation, I've also added a couple of other things:

  • Centralized the TCP socket connection functionality into a common function, and updated the protocols that use it (SSH and Telnet, at the moment) to use that function. I'm not sure I got this in the right place, so if there are opinions about where to move it, I'm happy to adjust.
  • Implemented a shared function to convert an integer to a string.

src/libguac/string.c Outdated Show resolved Hide resolved
src/libguac/string.c Outdated Show resolved Hide resolved
@kohrar
Copy link

kohrar commented Mar 15, 2024

Thanks for the PR. I gave it a try after merging it with master but can't seem to get my VNC connection to work as designed.

It seems as though the guacd thread stops immediately after sending the WoL packet, possibly after calling guac_wol_wake_and_wait. This is what I see in the debug logs:

guacd[216]: INFO:       User "@129a3167-dfc7-4826-80cd-89b938108cd8" joined connection "$9068079c-9de1-4f0c-b29e-f8651ba25cf1" (1 users now present)
guacd[216]: DEBUG:      Sending Wake-on-LAN packet, and pausing for 2 seconds.
guacd[216]: DEBUG:      Client is using protocol version "VERSION_1_5_0"
guacd[1]: INFO: Connection "$9068079c-9de1-4f0c-b29e-f8651ba25cf1" removed.
guacd[1]: DEBUG:        Unable to request termination of client process: No such process
guacd[1]: DEBUG:        All child processes for connection "$9068079c-9de1-4f0c-b29e-f8651ba25cf1" have been terminated.

If I set wol-wake-time to 0 which (which bypasses the call to guac_wol_wake_and_wait), the VNC connection works once the machine comes up.

@kohrar
Copy link

kohrar commented Mar 18, 2024

Just a quick update -- the segfault comes from str_port being uninitialized before getting passed to guac_itoa. After fixing that (I just hard coded a malloc of 6 bytes to it) and it seems to be working OK.

@necouchman
Copy link
Contributor Author

Thanks, @kohrar! I suspect that after I converted the guac_itoa() function to not do the allocation itself I forgot to go back and allocate. I'll fix this up...

@necouchman
Copy link
Contributor Author

Just a quick update -- the segfault comes from str_port being uninitialized before getting passed to guac_itoa. After fixing that (I just hard coded a malloc of 6 bytes to it) and it seems to be working OK.

Apparently I had already fixed this in my git code, but not pushed it 🤦. Should be fixed, now.

@NickVStepin
Copy link

NickVStepin commented Apr 4, 2024

For RDP connection "guac_socket_tcp_connect" don't work. Function "guac_wol_wake_and_wait" allways wait "wait_time" seconds.

I found error. Function guac_itoa for port number "3389" return 338.

Correct text for guac_itoa:

int guac_itoa(char* restrict dest, unsigned int integer) {

/* Determine size of string. */
int str_size = snprintf(dest, 0, "%u", integer) + 1;

/* Do the conversion and return. */
return snprintf(dest, str_size, "%u", integer);

}

src/libguac/string.c Show resolved Hide resolved
@necouchman
Copy link
Contributor Author

@jmuehlner Any further changes that need to be made on this one?

@NickVStepin
Copy link

NickVStepin commented May 22, 2024 via email

@jmuehlner
Copy link
Contributor

@jmuehlner Any further changes that need to be made on this one?

Nope, looks reasonable to me.

@jmuehlner jmuehlner merged commit c91b0ef into apache:main May 22, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants