services: networking: Add netmask to loopback address.

Previously, we would get a fishy 127.0.0.1/0 interface:

  $ ip a show dev lo
  1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
      link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
      inet 127.0.0.1/8 scope host lo
	 valid_lft forever preferred_lft forever
      inet 127.0.0.1/0 scope global lo
	 valid_lft forever preferred_lft forever
      inet6 ::1/128 scope host
	 valid_lft forever preferred_lft forever

With this change, we get nothing but the "/8" version:

  $ ip a show dev lo
  1: lo: <LOOPBACK,MULTICAST,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
      link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
      inet 127.0.0.1/8 scope global lo
	 valid_lft forever preferred_lft forever
      inet6 ::1/128 scope host
	 valid_lft forever preferred_lft forever

Reported by Yann Dupont <Yann.Dupont@univ-nantes.fr>.

* gnu/services/base.scm (assert-valid-address): Remove special cases for
127.0.0.1 and ::1.
(%loopback-static-networking): Add "/8".
This commit is contained in:
Ludovic Courtès 2022-01-06 10:23:43 +01:00 committed by Ludovic Courtès
parent c487b05d5f
commit 5c354c204d
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2013-2022 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2015, 2016 Alex Kost <alezost@gmail.com>
;;; Copyright © 2015, 2016, 2020 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
@ -2393,11 +2393,7 @@ (define (ipv6-address? str)
(define-compile-time-procedure (assert-valid-address (address string?))
"Ensure ADDRESS has a valid netmask."
(unless (or (cidr->netmask address)
(and=> (false-if-exception (inet-pton AF_INET address))
(cut = INADDR_LOOPBACK <>))
(and=> (false-if-exception (inet-pton AF_INET6 address))
(cut = 1 <>)))
(unless (cidr->netmask address)
(raise
(make-compound-condition
(formatted-message (G_ "address '~a' lacks a network mask")
@ -2741,7 +2737,7 @@ (define %loopback-static-networking
(static-networking
(addresses (list (network-address
(device "lo")
(value "127.0.0.1"))))
(value "127.0.0.1/8"))))
(requirement '())
(provision '(loopback))))