From e68791f5ab1e920680ae4db01c2c80867cda9e8c Mon Sep 17 00:00:00 2001 From: Robert Pluim Date: Wed, 18 Dec 2024 14:50:06 +0100 Subject: [PATCH] Fix network test failure when using VPN client When using certain VPN clients, the interface info returned by 'getifaddrs' does not have the address family filled in for the ifa_netmask component (this is allowed by the standard, since the value is not specified). The resulting address info causes network tests suite failures. Fix by copying the address family from the returned interface address. * src/process.c (network_interface_list): Copy the interface address sa_family to the netmask address. (Fnetwork_lookup_address_info): Fix test for non-IP addresses to properly account for IPv6. * test/src/process-tests.el (process-tests-check-bug-74907): New test, checks that 'network-interface-list' output is as expected. (Bug#74907) (cherry picked from commit d8e8e1d5ed260222e2630141d26572a361a5c75f) --- src/process.c | 20 ++++++++++++++------ test/src/process-tests.el | 11 +++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/process.c b/src/process.c index 398603613da..928fae09ef6 100644 --- a/src/process.c +++ b/src/process.c @@ -4351,6 +4351,10 @@ network_interface_list (bool full, unsigned short match) if (full) { + /* Sometimes sa_family is only filled in correctly in the + interface address, not the netmask, so copy it across + (Bug#74907). */ + it->ifa_netmask->sa_family = it->ifa_addr->sa_family; elt = Fcons (conv_sockaddr_to_lisp (it->ifa_netmask, len), elt); /* There is an it->ifa_broadaddr field, but its contents are unreliable, so always calculate the broadcast address from @@ -4765,13 +4769,17 @@ returned from the lookup. */) { for (lres = res; lres; lres = lres->ai_next) { -#ifndef AF_INET6 - if (lres->ai_family != AF_INET) - continue; + /* Avoid converting non-IP addresses (Bug#74907). */ + if (lres->ai_family == AF_INET +#ifdef AF_INET6 + || lres->ai_family == AF_INET6 #endif - addresses = Fcons (conv_sockaddr_to_lisp (lres->ai_addr, - lres->ai_addrlen), - addresses); + ) + addresses = Fcons (conv_sockaddr_to_lisp (lres->ai_addr, + lres->ai_addrlen), + addresses); + else + continue; } addresses = Fnreverse (addresses); diff --git a/test/src/process-tests.el b/test/src/process-tests.el index 862416a49a9..f34faba829b 100644 --- a/test/src/process-tests.el +++ b/test/src/process-tests.el @@ -519,6 +519,17 @@ See Bug#30460." ;; End of tests requiring DNS +(ert-deftest process-tests-check-bug-74907 () + "Check that the result of `network-interface-list' is well-formed. +(Bug#74907)" + (dolist (info (network-interface-list t)) + (should (stringp (car info))) + (should (length= info 4)) + (should (cl-every #'vectorp (cdr info))) + (let ((alen (length (cadr info)))) + (should (memq alen '(5 9))) ; Address info also has a port number + (should (cl-every (lambda (elt) (length= elt alen)) (cdr info)))))) + (defmacro process-tests--ignore-EMFILE (&rest body) "Evaluate BODY, ignoring EMFILE errors." (declare (indent 0) (debug t)) -- 2.39.5