all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH pve-cluster] pmxcfs: lookup_node_ip : skip local ips
@ 2023-06-28  9:39 Alexandre Derumier
  2023-07-01 16:03 ` Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandre Derumier @ 2023-06-28  9:39 UTC (permalink / raw)
  To: pve-devel

stock debian or some hosting company like ovh through cloudinit at each boot,
add 127.0.1.1 <hostname> in /etc/hosts.

fix:
https://forum.proxmox.com/threads/proxmox-7-to-8-upgrade-problem-ovh.129678/
https://forum.proxmox.com/threads/update-7-to-8-issue-with-cloud-init.129669/#post-568172
https://forum.proxmox.com/threads/bookworm-installation-fails-with-pve-manager-dependency-error.129398/#post-568290
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/pmxcfs/pmxcfs.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/pmxcfs/pmxcfs.c b/src/pmxcfs/pmxcfs.c
index d78a248..e0f5f27 100644
--- a/src/pmxcfs/pmxcfs.c
+++ b/src/pmxcfs/pmxcfs.c
@@ -726,26 +726,34 @@ static char *
 lookup_node_ip(const char *nodename)
 {
 	char buf[INET6_ADDRSTRLEN];
-	struct addrinfo *ainfo;
+	struct addrinfo *ainfo, *rp;
 	struct addrinfo ahints;
 	char *res = NULL;
 	memset(&ahints, 0, sizeof(ahints));
+	ahints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
+	ahints.ai_socktype = SOCK_STREAM; /* Datagram socket */
+	ahints.ai_flags = AI_V4MAPPED | AI_ALL;
 
 	if (getaddrinfo(nodename, NULL, &ahints, &ainfo))
 		return NULL;
 
-	if (ainfo->ai_family == AF_INET) {
-		struct sockaddr_in *sa = (struct sockaddr_in *)ainfo->ai_addr;
-		inet_ntop(ainfo->ai_family, &sa->sin_addr, buf, sizeof(buf));
+	for (rp = ainfo; rp != NULL; rp = rp->ai_next) {
+
+	    if (ainfo->ai_family == AF_INET) {
+		struct sockaddr_in *sa = (struct sockaddr_in *)rp->ai_addr;
+		inet_ntop(rp->ai_family, &sa->sin_addr, buf, sizeof(buf));
 		if (strncmp(buf, "127.", 4) != 0) {
 			res = g_strdup(buf);
+			break;
 		}
-	} else if (ainfo->ai_family == AF_INET6) {
-		struct sockaddr_in6 *sa = (struct sockaddr_in6 *)ainfo->ai_addr;
-		inet_ntop(ainfo->ai_family, &sa->sin6_addr, buf, sizeof(buf));
+	    } else if (ainfo->ai_family == AF_INET6) {
+		struct sockaddr_in6 *sa = (struct sockaddr_in6 *)rp->ai_addr;
+		inet_ntop(rp->ai_family, &sa->sin6_addr, buf, sizeof(buf));
 		if (strcmp(buf, "::1") != 0) {
 			res = g_strdup(buf);
+			break;
 		}
+	    }
 	}
 
 	freeaddrinfo(ainfo);
-- 
2.39.2




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

* Re: [pve-devel] [PATCH pve-cluster] pmxcfs: lookup_node_ip : skip local ips
  2023-06-28  9:39 [pve-devel] [PATCH pve-cluster] pmxcfs: lookup_node_ip : skip local ips Alexandre Derumier
@ 2023-07-01 16:03 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2023-07-01 16:03 UTC (permalink / raw)
  To: Proxmox VE development discussion, Alexandre Derumier

Am 28/06/2023 um 11:39 schrieb Alexandre Derumier:
> stock debian or some hosting company like ovh through cloudinit at each boot,
> add 127.0.1.1 <hostname> in /etc/hosts.
> 
> fix:
> https://forum.proxmox.com/threads/proxmox-7-to-8-upgrade-problem-ovh.129678/
> https://forum.proxmox.com/threads/update-7-to-8-issue-with-cloud-init.129669/#post-568172
> https://forum.proxmox.com/threads/bookworm-installation-fails-with-pve-manager-dependency-error.129398/#post-568290
> Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
> ---
>  src/pmxcfs/pmxcfs.c | 22 +++++++++++++++-------
>  1 file changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/src/pmxcfs/pmxcfs.c b/src/pmxcfs/pmxcfs.c
> index d78a248..e0f5f27 100644
> --- a/src/pmxcfs/pmxcfs.c
> +++ b/src/pmxcfs/pmxcfs.c
> @@ -726,26 +726,34 @@ static char *
>  lookup_node_ip(const char *nodename)
>  {
>  	char buf[INET6_ADDRSTRLEN];
> -	struct addrinfo *ainfo;
> +	struct addrinfo *ainfo, *rp;
>  	struct addrinfo ahints;
>  	char *res = NULL;
>  	memset(&ahints, 0, sizeof(ahints));
> +	ahints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */

this is the default

> +	ahints.ai_socktype = SOCK_STREAM; /* Datagram socket */

setting to SOCK_STREAM is slightly odd, as we don't really care here, keeping
it at 0 (any type) seems more sensible

> +	ahints.ai_flags = AI_V4MAPPED | AI_ALL;

>  
>  	if (getaddrinfo(nodename, NULL, &ahints, &ainfo))
>  		return NULL;
>  
> -	if (ainfo->ai_family == AF_INET) {
> -		struct sockaddr_in *sa = (struct sockaddr_in *)ainfo->ai_addr;
> -		inet_ntop(ainfo->ai_family, &sa->sin_addr, buf, sizeof(buf));
> +	for (rp = ainfo; rp != NULL; rp = rp->ai_next) {
> +

did you not trust my proposal and copied this straight outa the getaddrinfo
man page? ;-P While those example can help to understand what's going on,
they're often in C89 and not the easiest to read.

As the change is rather small, if ignoring whitespace, I just wrote it up
myself, using designated initializers for setting the addrinfo and C99 for
loop initializers:

https://git.proxmox.com/?p=pve-cluster.git;a=commitdiff;h=c78963b1c65cca9d812aed8fe97813bd6d4a12bd

Also tried to slightly improve logging here for both, the failure and the
success case:

https://git.proxmox.com/?p=pve-cluster.git;a=commitdiff;h=175ad01c61858e7a51cbd2cba8d0671cc056b812


thanks




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

end of thread, other threads:[~2023-07-01 16:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-28  9:39 [pve-devel] [PATCH pve-cluster] pmxcfs: lookup_node_ip : skip local ips Alexandre Derumier
2023-07-01 16:03 ` Thomas Lamprecht

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal