guix-commits
[Top][All Lists]
Advanced

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

03/03: services: static-networking: Add netmask.


From: Ludovic Courtès
Subject: 03/03: services: static-networking: Add netmask.
Date: Thu, 17 Nov 2016 22:22:36 +0000 (UTC)

civodul pushed a commit to branch master
in repository guix.

commit 1f9803c2a49e853ca5721f13888a61a816c4dc09
Author: Ludovic Courtès <address@hidden>
Date:   Thu Nov 17 23:19:45 2016 +0100

    services: static-networking: Add netmask.
    
    Reported by Mathieu Lirzin and Andreas Enge.
    
    * gnu/services/networking.scm (<static-networking>)[netmask]: New
    field.
    (static-networking-service-type): Honor it.
    * gnu/services/networking.scm (static-networking-service): Add #:netmask
    and honor it.
    * doc/guix.texi (Networking Services): Adjust accordingly.
---
 doc/guix.texi               |    6 +++---
 gnu/services/networking.scm |   22 +++++++++++++++-------
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 1a809c3..0e70830 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -8363,10 +8363,10 @@ Protocol (DHCP) client, on all the non-loopback network 
interfaces.
 @end deffn
 
 @deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
-       [#:gateway #f] [#:name-servers @code{'()}]
+       [#:netmask #f] [#:gateway #f] [#:name-servers @code{'()}]
 Return a service that starts @var{interface} with address @var{ip}.  If
address@hidden is true, it must be a string specifying the default network
-gateway.
address@hidden is true, use it as the network mask.  If @var{gateway} is true,
+it must be a string specifying the default network gateway.
 @end deffn
 
 @cindex wicd
diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm
index 2adde23..884c542 100644
--- a/gnu/services/networking.scm
+++ b/gnu/services/networking.scm
@@ -112,6 +112,8 @@ fe80::1%lo0 apps.facebook.com\n")
   static-networking?
   (interface static-networking-interface)
   (ip static-networking-ip)
+  (netmask static-networking-netmask
+           (default #f))
   (gateway static-networking-gateway)
   (provision static-networking-provision)
   (name-servers static-networking-name-servers)
@@ -121,7 +123,7 @@ fe80::1%lo0 apps.facebook.com\n")
   (shepherd-service-type
    'static-networking
    (match-lambda
-     (($ <static-networking> interface ip gateway provision
+     (($ <static-networking> interface ip netmask gateway provision
                              name-servers net-tools)
       (let ((loopback? (memq 'loopback provision)))
 
@@ -139,12 +141,18 @@ fe80::1%lo0 apps.facebook.com\n")
          (start #~(lambda _
                     ;; Return #t if successfully started.
                     (let* ((addr     (inet-pton AF_INET #$ip))
-                           (sockaddr (make-socket-address AF_INET addr 0)))
+                           (sockaddr (make-socket-address AF_INET addr 0))
+                           (mask     (and #$netmask
+                                          (inet-pton AF_INET #$netmask)))
+                           (maskaddr (and mask
+                                          (make-socket-address AF_INET
+                                                               mask 0))))
                       (configure-network-interface #$interface sockaddr
                                                    (logior IFF_UP
                                                            #$(if loopback?
                                                                  #~IFF_LOOPBACK
-                                                                 0))))
+                                                                 0))
+                                                   #:netmask maskaddr))
                     #$(if gateway
                           #~(zero? (system* (string-append #$net-tools
                                                            "/sbin/route")
@@ -176,16 +184,16 @@ fe80::1%lo0 apps.facebook.com\n")
 
 (define* (static-networking-service interface ip
                                     #:key
-                                    gateway
+                                    netmask gateway
                                     (provision '(networking))
                                     (name-servers '())
                                     (net-tools net-tools))
   "Return a service that starts @var{interface} with address @var{ip}.  If
address@hidden is true, it must be a string specifying the default network
-gateway."
address@hidden is true, use it as the network mask.  If @var{gateway} is true,
+it must be a string specifying the default network gateway."
   (service static-networking-service-type
            (static-networking (interface interface) (ip ip)
-                              (gateway gateway)
+                              (netmask netmask) (gateway gateway)
                               (provision provision)
                               (name-servers name-servers)
                               (net-tools net-tools))))



reply via email to

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