diff mbox series

[bug#35652] services: dhcp-client: Ignore non-ARP networkinterfaces.

Message ID 87d0krd4s6.fsf@fastmail.com
State Accepted
Headers show
Series [bug#35652] services: dhcp-client: Ignore non-ARP networkinterfaces. | expand

Checks

Context Check Description
cbaines/applying patch fail Apply failed

Commit Message

Marius Bakke May 9, 2019, 3:30 p.m. UTC
Guix,

While testing #35563, I found that "dhcp-client" does not work on a
kernel that has CONFIG_IPV6_SIT=y.

The reason is that the system has a virtual "sit0" interface that is not
capable of ARP traffic, which dhclient does not approve of:

May  9 16:18:37 localhost dhclient: Unsupported device type 776 for "sit0"

You can `modprobe sit` on your system if you want to reproduce the
failure.

The attached patch solves it for me.

Comments

Ludovic Courtès May 9, 2019, 3:39 p.m. UTC | #1
Hi Marius,

Good catch!

Marius Bakke <mbakke@fastmail.com> skribis:

> From 7724f24443392fdfc2c075909d9b64350f6578b2 Mon Sep 17 00:00:00 2001
> From: Marius Bakke <mbakke@fastmail.com>
> Date: Thu, 9 May 2019 17:03:03 +0200
> Subject: [PATCH] services: dhcp-client: Ignore interfaces that are not ARP
>  capable.
>
> * guix/build/syscalls.scm (IFF_NOARP): New variable.
> (arp-network-interface?): New public variable.
> * gnu/services/networking.scm (dhcp-client-service-type): Filter interfaces
> that do not support the ARP protocol.

Could you make it two patches (one for syscalls.scm, and another one for
the rest)?

Otherwise LGTM, thank you!

Ludo’.
Marius Bakke May 9, 2019, 6:12 p.m. UTC | #2
Ludovic Courtès <ludo@gnu.org> writes:

> Hi Marius,
>
> Good catch!
>
> Marius Bakke <mbakke@fastmail.com> skribis:
>
>> From 7724f24443392fdfc2c075909d9b64350f6578b2 Mon Sep 17 00:00:00 2001
>> From: Marius Bakke <mbakke@fastmail.com>
>> Date: Thu, 9 May 2019 17:03:03 +0200
>> Subject: [PATCH] services: dhcp-client: Ignore interfaces that are not ARP
>>  capable.
>>
>> * guix/build/syscalls.scm (IFF_NOARP): New variable.
>> (arp-network-interface?): New public variable.
>> * gnu/services/networking.scm (dhcp-client-service-type): Filter interfaces
>> that do not support the ARP protocol.
>
> Could you make it two patches (one for syscalls.scm, and another one for
> the rest)?
>
> Otherwise LGTM, thank you!

Thanks for the amazingly fast review :-)

Pushed in a0dc97a5..6c2180f5.
diff mbox series

Patch

From 7724f24443392fdfc2c075909d9b64350f6578b2 Mon Sep 17 00:00:00 2001
From: Marius Bakke <mbakke@fastmail.com>
Date: Thu, 9 May 2019 17:03:03 +0200
Subject: [PATCH] services: dhcp-client: Ignore interfaces that are not ARP
 capable.

* guix/build/syscalls.scm (IFF_NOARP): New variable.
(arp-network-interface?): New public variable.
* gnu/services/networking.scm (dhcp-client-service-type): Filter interfaces
that do not support the ARP protocol.
---
 gnu/services/networking.scm | 4 +++-
 guix/build/syscalls.scm     | 9 +++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm
index 03b2c6e1ec..082a85f63d 100644
--- a/gnu/services/networking.scm
+++ b/gnu/services/networking.scm
@@ -190,7 +190,9 @@  fe80::1%lo0 apps.facebook.com\n")
                  ;; interfaces are typically down at this point.  Thus we perform
                  ;; our own interface discovery here.
                  (define valid?
-                   (negate loopback-network-interface?))
+                   (lambda (interface)
+                     (and (arp-network-interface? interface)
+                          (not (loopback-network-interface? interface)))))
                  (define ifaces
                    (filter valid? (all-network-interface-names)))
 
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 749616ceb1..74428dbf56 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -104,6 +104,7 @@ 
             network-interface-netmask
             network-interface-running?
             loopback-network-interface?
+            arp-network-interface?
             network-interface-address
             set-network-interface-netmask
             set-network-interface-up
@@ -1160,6 +1161,7 @@  bytes."
 (define-as-needed IFF_BROADCAST #x2)              ;Broadcast address valid.
 (define-as-needed IFF_LOOPBACK #x8)               ;Is a loopback net.
 (define-as-needed IFF_RUNNING #x40)               ;interface RFC2863 OPER_UP
+(define-as-needed IFF_NOARP #x80)                 ;no ARP protocol
 
 (define IF_NAMESIZE 16)                           ;maximum interface name size
 
@@ -1341,6 +1343,13 @@  interface NAME."
     (close-port sock)
     (not (zero? (logand flags IFF_RUNNING)))))
 
+(define (arp-network-interface? name)
+  "Return true if NAME supports the ARP protocol."
+  (let* ((sock  (socket SOCK_STREAM AF_INET 0))
+         (flags (network-interface-flags sock name)))
+    (close-port sock)
+    (zero? (logand flags IFF_NOARP))))
+
 (define-as-needed (set-network-interface-flags socket name flags)
   "Set the flag of network interface NAME to FLAGS."
   (let ((req (make-bytevector ifreq-struct-size)))
-- 
2.21.0