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'.
This commit is contained in:
Ludovic Courtès 2014-12-19 17:15:31 +01:00
parent c9bf64d6d7
commit 7f5c2a9cc1
1 changed files with 37 additions and 35 deletions

View File

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