summaryrefslogtreecommitdiff
path: root/gnu/services/networking.scm
diff options
context:
space:
mode:
authormuradm <mail@muradm.net>2023-12-17 15:49:21 +0300
committerMaxim Cournoyer <maxim.cournoyer@gmail.com>2024-01-22 09:51:32 -0500
commit1bdeec5d66cfeea3a5fc5d69690dd32cb32ee104 (patch)
treecc8ae666a501e97251e5a445fa3242a3047b8772 /gnu/services/networking.scm
parent2b04ebaa7411404d9800ebcd3818dc7eb3bc7aba (diff)
services: connman: Add 'connman-general-configuration'.
Currently connman has no main.conf as specified in 'man 5 connman.conf' which would allow setting NetworkInterfaceBalcklist and other useful options. This patch adds connman-general-configuration, serializes it and passes to connmad with --config= flag. All configuration fields are 'maybe-*' deliberately, to not disturb current users and not require supporting configuration changes for connmand. * gnu/services/networking.scm (<connman-general-configuration>): New configuration record to represent main.conf for connmand. (<connman-configuration>)[general-configuration]: New field. (connman-shepherd-service): Honor it. *doc/guix.texi (Networking Services): Add generated configuration. Change-Id: I5d78f49e8b2d5e0b3cbd7b8b604e8a254b6397e8 Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Modified-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Diffstat (limited to 'gnu/services/networking.scm')
-rw-r--r--gnu/services/networking.scm255
1 files changed, 252 insertions, 3 deletions
diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm
index 7c114fa53c0..495d0497289 100644
--- a/gnu/services/networking.scm
+++ b/gnu/services/networking.scm
@@ -21,6 +21,7 @@
21;;; Copyright © 2022, 2023 Andrew Tropin <andrew@trop.in> 21;;; Copyright © 2022, 2023 Andrew Tropin <andrew@trop.in>
22;;; Copyright © 2023 Declan Tsien <declantsien@riseup.net> 22;;; Copyright © 2023 Declan Tsien <declantsien@riseup.net>
23;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu> 23;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>
24;;; Copyright © 2023 muradm <mail@muradm.net>
24;;; 25;;;
25;;; This file is part of GNU Guix. 26;;; This file is part of GNU Guix.
26;;; 27;;;
@@ -78,6 +79,7 @@
78 #:use-module (srfi srfi-26) 79 #:use-module (srfi srfi-26)
79 #:use-module (srfi srfi-43) 80 #:use-module (srfi srfi-43)
80 #:use-module (ice-9 match) 81 #:use-module (ice-9 match)
82 #:use-module (ice-9 string-fun)
81 #:use-module (json) 83 #:use-module (json)
82 #:re-export (static-networking-service 84 #:re-export (static-networking-service
83 static-networking-service-type) 85 static-networking-service-type)
@@ -171,6 +173,8 @@
171 network-manager-configuration-vpn-plugins 173 network-manager-configuration-vpn-plugins
172 network-manager-service-type 174 network-manager-service-type
173 175
176 connman-general-configuration
177 connman-general-configuration?
174 connman-configuration 178 connman-configuration
175 connman-configuration? 179 connman-configuration?
176 connman-configuration-connman 180 connman-configuration-connman
@@ -1326,6 +1330,241 @@ wireless networking."))))
1326;;; Connman 1330;;; Connman
1327;;; 1331;;;
1328 1332
1333(define (connman-general-configuration-field-name field-name)
1334 (let* ((str->camel (lambda (s)
1335 (string-concatenate
1336 (map string-capitalize (string-split s #\-)))))
1337 (str (if (symbol? field-name)
1338 (str->camel (symbol->string field-name))
1339 field-name)))
1340 (cond
1341 ((string-suffix? "?" str) (connman-general-configuration-field-name
1342 (string-drop-right str 1)))
1343 ((string-contains str "RegulatoryDomain") (connman-general-configuration-field-name
1344 (string-replace-substring str "RegulatoryDomain" "Regdom")))
1345 ((string-contains str "Url") (connman-general-configuration-field-name
1346 (string-replace-substring str "Url" "URL")))
1347 ((string-contains str "Ip") (connman-general-configuration-field-name
1348 (string-replace-substring str "Ip" "IP")))
1349 ((string-contains str "6To4") (connman-general-configuration-field-name
1350 (string-replace-substring str "6To4" "6to4")))
1351 (#t str))))
1352
1353(define (connman-general-configuration-serialize-string field-name value)
1354 (let ((param (connman-general-configuration-field-name field-name)))
1355 #~(string-append #$param " = " #$value "\n")))
1356
1357(define (connman-general-configuration-serialize-number field-name value)
1358 (connman-general-configuration-serialize-string
1359 field-name (number->string value)))
1360
1361(define (connman-general-configuration-serialize-list field-name value)
1362 (connman-general-configuration-serialize-string
1363 field-name (string-join value ",")))
1364
1365(define (connman-general-configuration-serialize-boolean field-name value)
1366 (connman-general-configuration-serialize-string
1367 field-name (if value "true" "false")))
1368
1369(define-maybe boolean (prefix connman-general-configuration-))
1370(define-maybe number (prefix connman-general-configuration-))
1371(define-maybe string (prefix connman-general-configuration-))
1372(define-maybe list (prefix connman-general-configuration-))
1373
1374(define-configuration connman-general-configuration
1375 (input-request-timeout
1376 maybe-number
1377 "Set input request timeout. Default is 120 seconds. The request for inputs
1378like passphrase will timeout after certain amount of time. Use this setting to
1379increase the value in case of different user interface designs.")
1380 (browser-launch-timeout
1381 maybe-number
1382 "Set browser launch timeout. Default is 300 seconds. The request for
1383launching a browser for portal pages will timeout after certain amount of
1384time. Use this setting to increase the value in case of different user
1385interface designs.")
1386 (background-scanning?
1387 maybe-boolean
1388 "Enable background scanning. Default is true. If wifi is disconnected, the
1389background scanning will follow a simple back off mechanism from 3s up to 5
1390minutes. Then, it will stay in 5 minutes unless user specifically asks for
1391scanning through a D-Bus call. If so, the mechanism will start again from
13923s. This feature activates also the background scanning while being connected,
1393which is required for roaming on wifi. When @code{background-scanning?} is false,
1394ConnMan will not perform any scan regardless of wifi is connected or not,
1395unless it is requested by the user through a D-Bus call.")
1396 (use-gateways-as-timeservers?
1397 maybe-boolean
1398 "Assume that service gateways also function as timeservers. Default is false.")
1399 (fallback-timeservers
1400 maybe-list
1401 "List of Fallback timeservers. These timeservers are used for NTP sync
1402when there are no timeservers set by the user or by the service, and when
1403@code{use-gateways-as-timeservers?} is @code{#f}. These can contain a mixed
1404combination of fully qualified domain names, IPv4 and IPv6 addresses.")
1405 (fallback-nameservers
1406 maybe-list
1407 "List of fallback nameservers appended to the list of nameservers given
1408by the service. The nameserver entries must be in numeric format,
1409host names are ignored.")
1410 (default-auto-connect-technologies
1411 maybe-list
1412 "List of technologies that are marked autoconnectable by default. The
1413default value for this entry when empty is @code{\"ethernet\"}, @code{\"wifi\"},
1414@code{\"cellular\"}. Services that are automatically connected must have been
1415set up and saved to storage beforehand.")
1416 (default-favourite-technologies
1417 maybe-list
1418 "List of technologies that are marked favorite by default. The default
1419value for this entry when empty is @code{\"ethernet\"}. Connects to services
1420from this technology even if not setup and saved to storage.")
1421 (always-connected-technologies
1422 maybe-list
1423 "List of technologies which are always connected regardless of
1424preferred-technologies setting (@code{auto-connect?} @code{#t}). The default
1425value is empty and this feature is disabled unless explicitly enabled.")
1426 (preferred-technologies
1427 maybe-list
1428 "List of preferred technologies from the most preferred one to the least
1429preferred one. Services of the listed technology type will be tried one by
1430one in the order given, until one of them gets connected or they are all
1431tried. A service of a preferred technology type in state 'ready' will get
1432the default route when compared to another preferred type further down the
1433list with state 'ready' or with a non-preferred type; a service of a
1434preferred technology type in state 'online' will get the default route when
1435compared to either a non-preferred type or a preferred type further down
1436in the list.")
1437 (network-interface-blacklist
1438 maybe-list
1439 "List of blacklisted network interfaces. Found interfaces will be
1440compared to the list and will not be handled by ConnMan, if their first
1441characters match any of the list entries. Default value is @code{\"vmnet\"},
1442@code{\"vboxnet\"}, @code{\"virbr\"}, @code{\"ifb\"}.")
1443 (allow-hostname-updates?
1444 maybe-boolean
1445 "Allow ConnMan to change the system hostname. This can happen for
1446example if we receive DHCP hostname option. Default value is @code{#t}.")
1447 (allow-domainname-updates?
1448 maybe-boolean
1449 "Allow connman to change the system domainname. This can happen for
1450example if we receive DHCP domainname option. Default value is @code{#t}.")
1451 (single-connected-technology?
1452 maybe-boolean
1453 "Keep only a single connected technology at any time. When a new
1454service is connected by the user or a better one is found according to
1455preferred-technologies, the new service is kept connected and all the
1456other previously connected services are disconnected. With this setting
1457it does not matter whether the previously connected services are
1458in 'online' or 'ready' states, the newly connected service is the only
1459one that will be kept connected. A service connected by the user will
1460be used until going out of network coverage. With this setting enabled
1461applications will notice more network breaks than normal. Note this
1462options can't be used with VPNs. Default value is @code{#f}.")
1463 (tethering-technologies
1464 maybe-list
1465 "List of technologies that are allowed to enable tethering. The
1466default value is @code{\"wifi\"}, @code{\"bluetooth\"},
1467@code{\"gadget\"}. Only those technologies listed here are used for
1468tethering. If one wants to tether ethernet, then add @code{\"ethernet\"}
1469in the list. Note that if ethernet tethering is enabled, then a DHCP
1470server is started on all ethernet interfaces. Tethered ethernet should
1471never be connected to corporate or home network as it will disrupt normal
1472operation of these networks. Due to this ethernet is not tethered by
1473default. Do not activate ethernet tethering unless you really know
1474what you are doing.")
1475 (persistent-tethering-mode?
1476 maybe-boolean
1477 "Restore earlier tethering status when returning from offline mode,
1478re-enabling a technology, and after restarts and reboots. Default
1479value is @code{#f}.")
1480 (enable-6to4?
1481 maybe-boolean
1482 "Automatically enable anycast 6to4 if possible. This is not
1483recommended, as the use of 6to4 will generally lead to a severe
1484degradation of connection quality. See RFC6343. Default value
1485is @code{#f} (as recommended by RFC6343 section 4.1).")
1486 (vendor-class-id
1487 maybe-string
1488 "Set DHCP option 60 (Vendor Class ID) to the given string. This
1489option can be used by DHCP servers to identify specific clients
1490without having to rely on MAC address ranges, etc.")
1491 (enable-online-check?
1492 maybe-boolean
1493 "Enable or disable use of HTTP GET as an online status check. When
1494a service is in a READY state, and is selected as default, ConnMan will
1495issue an HTTP GET request to verify that end-to-end connectivity is
1496successful. Only then the service will be transitioned to ONLINE
1497state. If this setting is false, the default service will remain
1498in READY state. Default value is @code{#t}.")
1499 (online-check-ipv4-url
1500 maybe-string
1501 "IPv4 URL used during the online status check. Please refer to
1502the README for more detailed information. Default value is
1503@url{http://ipv4.connman.net/online/status.html}.")
1504 (online-check-ipv6-url
1505 maybe-string
1506 "IPv6 URL used during the online status check. Please refer to
1507the README for more detailed information. Default value is
1508@url{http://ipv6.connman.net/online/status.html}.")
1509 (online-check-initial-interval
1510 maybe-number
1511 "Range of intervals between two online check requests. Please
1512refer to the README for more detailed information. Default value
1513is @samp{1}.")
1514 (online-check-max-interval
1515 maybe-number
1516 "Range of intervals between two online check requests. Please
1517refer to the README for more detailed information. Default value
1518is @samp{1}.")
1519 (enable-online-to-ready-transition?
1520 maybe-boolean
1521 "WARNING: This is an experimental feature. In addition to
1522@code{enable-online-check} setting, enable or disable use of HTTP GET
1523to detect the loss of end-to-end connectivity. If this setting is
1524@code{#f}, when the default service transitions to ONLINE state, the
1525HTTP GET request is no more called until next cycle, initiated by a
1526transition of the default service to DISCONNECT state. If this
1527setting is @code{#t}, the HTTP GET request keeps being called to
1528guarantee that end-to-end connectivity is still successful. If not,
1529the default service will transition to READY state, enabling another
1530service to become the default one, in replacement. Default value
1531is @code{#f}.")
1532 (auto-connect-roaming-services?
1533 maybe-boolean
1534 "Automatically connect roaming services. This is not recommended
1535unless you know you won't have any billing problem. Default value
1536is @code{#f}.")
1537 (address-conflict-detection?
1538 maybe-boolean
1539 "Enable or disable the implementation of IPv4 address conflict
1540detection according to RFC5227. ConnMan will send probe ARP packets
1541to see if an IPv4 address is already in use before assigning the
1542address to an interface. If an address conflict occurs for a
1543statically configured address, an IPv4LL address will be chosen
1544instead (according to RFC3927). If an address conflict occurs for
1545an address offered via DHCP, ConnMan sends a DHCP DECLINE once
1546and for the second conflict resorts to finding an IPv4LL
1547address. Default value is @code{#f}.")
1548 (localtime
1549 maybe-string
1550 "Path to localtime file. Defaults to @file{/etc/localtime}.")
1551 (regulatory-domain-follows-timezone?
1552 maybe-boolean
1553 "Enable regulatory domain to be changed along timezone changes.
1554With this option set to true each time the timezone changes the first
1555present ISO3166 country code is read from
1556@file{/usr/share/zoneinfo/zone1970.tab} and set as regulatory domain
1557value. Default value is @code{#f}.")
1558 (resolv-conf
1559 maybe-string
1560 "Path to resolv.conf file. If the file does not exist, but
1561intermediate directories exist, it will be created. If this option
1562is not set, it tries to write into @file{/var/run/connman/resolv.conf}
1563if it fails (@file{/var/run/connman} does not exist or is not
1564writeable). If you do not want to update resolv.conf, you can
1565set @file{/dev/null}.")
1566 (prefix connman-general-configuration-))
1567
1329(define-record-type* <connman-configuration> 1568(define-record-type* <connman-configuration>
1330 connman-configuration make-connman-configuration 1569 connman-configuration make-connman-configuration
1331 connman-configuration? 1570 connman-configuration?
@@ -1337,7 +1576,9 @@ wireless networking."))))
1337 (default #f)) 1576 (default #f))
1338 (iwd? connman-configuration-iwd? 1577 (iwd? connman-configuration-iwd?
1339 (default #f) 1578 (default #f)
1340 (sanitize warn-iwd?-field-deprecation))) 1579 (sanitize warn-iwd?-field-deprecation))
1580 (general-configuration connman-configuration-general-configuration
1581 (default (connman-general-configuration))))
1341 1582
1342(define (connman-activation config) 1583(define (connman-activation config)
1343 (let ((disable-vpn? (connman-configuration-disable-vpn? config))) 1584 (let ((disable-vpn? (connman-configuration-disable-vpn? config)))
@@ -1350,10 +1591,17 @@ wireless networking."))))
1350 1591
1351(define (connman-shepherd-service config) 1592(define (connman-shepherd-service config)
1352 (match-record config <connman-configuration> (connman shepherd-requirement 1593 (match-record config <connman-configuration> (connman shepherd-requirement
1353 disable-vpn? iwd?) 1594 disable-vpn? iwd?
1595 general-configuration)
1354 (let ((iwd? (or iwd? ; TODO: deprecated field, remove later. 1596 (let ((iwd? (or iwd? ; TODO: deprecated field, remove later.
1355 (and shepherd-requirement 1597 (and shepherd-requirement
1356 (memq 'iwd shepherd-requirement))))) 1598 (memq 'iwd shepherd-requirement))))
1599 (config (mixed-text-file
1600 "main.conf"
1601 "[General]\n"
1602 (serialize-configuration
1603 general-configuration
1604 connman-general-configuration-fields))))
1357 (list (shepherd-service 1605 (list (shepherd-service
1358 (documentation "Run Connman") 1606 (documentation "Run Connman")
1359 (provision '(connman networking)) 1607 (provision '(connman networking))
@@ -1365,6 +1613,7 @@ wireless networking."))))
1365 (start #~(make-forkexec-constructor 1613 (start #~(make-forkexec-constructor
1366 (list (string-append #$connman 1614 (list (string-append #$connman
1367 "/sbin/connmand") 1615 "/sbin/connmand")
1616 (string-append "--config=" #$config)
1368 "--nodaemon" 1617 "--nodaemon"
1369 "--nodnsproxy" 1618 "--nodnsproxy"
1370 #$@(if disable-vpn? '("--noplugin=vpn") '()) 1619 #$@(if disable-vpn? '("--noplugin=vpn") '())