guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

03/03: services: static-networking-service: Switch to (guix build syscal


From: Ludovic Courtès
Subject: 03/03: services: static-networking-service: Switch to (guix build syscalls).
Date: Fri, 19 Dec 2014 16:16:07 +0000

civodul pushed a commit to branch master
in repository guix.

commit 7f5c2a9cc1d2fba5971826612befebaf79c9061e
Author: Ludovic Courtès <address@hidden>
Date:   Fri Dec 19 17:15:31 2014 +0100

    services: static-networking-service: Switch to (guix build syscalls).
    
    * gnu/services/networking.scm (static-networking-service): Remove
      #:inetutils parameter.  Rewrite using 'configure-network-interface'
      and 'set-network-interface-flags'.
---
 gnu/services/networking.scm |   72 ++++++++++++++++++++++---------------------
 1 files changed, 37 insertions(+), 35 deletions(-)

diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm
index 1cb501b..db9be8c 100644
--- a/gnu/services/networking.scm
+++ b/gnu/services/networking.scm
@@ -80,60 +80,62 @@ fe80::1%lo0 apps.facebook.com\n")
                                     gateway
                                     (provision '(networking))
                                     (name-servers '())
-                                    (inetutils inetutils)
                                     (net-tools net-tools))
   "Return a service that starts @var{interface} with address @var{ip}.  If
 @var{gateway} is true, it must be a string specifying the default network
 gateway."
+  (define loopback?
+    (memq 'loopback provision))
 
-  ;; TODO: Eventually we should do this using Guile's networking procedures,
-  ;; like 'configure-qemu-networking' does, but the patch that does this is
-  ;; not yet in stock Guile.
+  ;; TODO: Eventually replace 'route' with bindings for the appropriate
+  ;; ioctls.
   (with-monad %store-monad
     (return
      (service
 
       ;; Unless we're providing the loopback interface, wait for udev to be up
       ;; and running so that INTERFACE is actually usable.
-      (requirement (if (memq 'loopback provision)
-                       '()
-                       '(udev)))
+      (requirement (if loopback? '() '(udev)))
 
       (documentation
        "Bring up the networking interface using a static IP address.")
       (provision provision)
       (start #~(lambda _
                  ;; Return #t if successfully started.
-                 (and (zero? (system* (string-append #$inetutils
-                                                     "/bin/ifconfig")
-                                      "-i" #$interface "-A" #$ip
-                                      "-i" #$interface "--up"))
-                      #$(if gateway
-                            #~(zero? (system* (string-append #$net-tools
-                                                             "/sbin/route")
-                                              "add" "-net" "default"
-                                              "gw" #$gateway))
-                            #t)
-                      #$(if (pair? name-servers)
-                            #~(call-with-output-file "/etc/resolv.conf"
-                                (lambda (port)
-                                  (display
-                                   "# Generated by 
'static-networking-service'.\n"
-                                   port)
-                                  (for-each (lambda (server)
-                                              (format port "nameserver ~a~%"
-                                                      server))
-                                            '#$name-servers)))
-                            #t))))
+                 (let* ((addr     (inet-pton AF_INET #$ip))
+                        (sockaddr (make-socket-address AF_INET addr 0)))
+                   (configure-network-interface #$interface sockaddr
+                                                (logior IFF_UP
+                                                        #$(if loopback?
+                                                              #~IFF_LOOPBACK
+                                                              0))))
+                 #$(if gateway
+                       #~(zero? (system* (string-append #$net-tools
+                                                        "/sbin/route")
+                                         "add" "-net" "default"
+                                         "gw" #$gateway))
+                       #t)
+                 #$(if (pair? name-servers)
+                       #~(call-with-output-file "/etc/resolv.conf"
+                           (lambda (port)
+                             (display
+                              "# Generated by 'static-networking-service'.\n"
+                              port)
+                             (for-each (lambda (server)
+                                         (format port "nameserver ~a~%"
+                                                 server))
+                                       '#$name-servers)))
+                       #t)))
       (stop #~(lambda _
                 ;; Return #f is successfully stopped.
-                (not (and (system* (string-append #$inetutils "/bin/ifconfig")
-                                   #$interface "down")
-                          #$(if gateway
-                                #~(system* (string-append #$net-tools
-                                                          "/sbin/route")
-                                           "del" "-net" "default")
-                                #t)))))
+                (let ((sock (socket AF_INET SOCK_STREAM 0)))
+                  (set-network-interface-flags sock #$interface 0)
+                  (close-port sock))
+                (not #$(if gateway
+                           #~(system* (string-append #$net-tools
+                                                     "/sbin/route")
+                                      "del" "-net" "default")
+                           #t))))
       (respawn? #f)))))
 
 (define* (dhcp-client-service #:key (dhcp isc-dhcp))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]