]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix network test failure when using VPN client
authorRobert Pluim <rpluim@gmail.com>
Wed, 18 Dec 2024 13:50:06 +0000 (14:50 +0100)
committerEshel Yaron <me@eshelyaron.com>
Mon, 23 Dec 2024 15:16:50 +0000 (16:16 +0100)
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
test/src/process-tests.el

index 398603613da4ec9dc883d8aac6e44422accc776f..928fae09ef63e1633da1216204c66465dea9bf92 100644 (file)
@@ -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);
 
index 862416a49a9454055ea1b080515606f35fa9e411..f34faba829bf8cdc33a2b3918a831649c244c3de 100644 (file)
@@ -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))