services: Add 'simulated-wifi-service-type'.
* gnu/services/networking.scm (simulated-wifi-shepherd-services): New procedure. (simulated-wifi-service-type): New variable. * doc/guix.texi (Networking Services): Document it.
This commit is contained in:
		
							parent
							
								
									a03943ec00
								
							
						
					
					
						commit
						5e7076f2a5
					
				
					 2 changed files with 59 additions and 0 deletions
				
			
		| 
						 | 
					@ -13684,6 +13684,17 @@ configuration file reference.
 | 
				
			||||||
@end table
 | 
					@end table
 | 
				
			||||||
@end deftp
 | 
					@end deftp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@defvr {Scheme Variable} simulated-wifi-service-type
 | 
				
			||||||
 | 
					This is the type of a service to simulate WiFi networking, which can be
 | 
				
			||||||
 | 
					useful in virtual machines for testing purposes.  The service loads the
 | 
				
			||||||
 | 
					Linux kernel
 | 
				
			||||||
 | 
					@uref{https://www.kernel.org/doc/html/latest/networking/mac80211_hwsim/mac80211_hwsim.html,
 | 
				
			||||||
 | 
					@code{mac80211_hwsim} module} and starts hostapd to create a pseudo WiFi
 | 
				
			||||||
 | 
					network that can be seen on @code{wlan0}, by default.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The service's value is a @code{hostapd-configuration} record.
 | 
				
			||||||
 | 
					@end defvr
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@cindex iptables
 | 
					@cindex iptables
 | 
				
			||||||
@defvr {Scheme Variable} iptables-service-type
 | 
					@defvr {Scheme Variable} iptables-service-type
 | 
				
			||||||
This is the service type to set up an iptables configuration.  iptables is a
 | 
					This is the service type to set up an iptables configuration.  iptables is a
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -151,6 +151,8 @@
 | 
				
			||||||
            hostapd-configuration-driver
 | 
					            hostapd-configuration-driver
 | 
				
			||||||
            hostapd-service-type
 | 
					            hostapd-service-type
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            simulated-wifi-service-type
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            openvswitch-service-type
 | 
					            openvswitch-service-type
 | 
				
			||||||
            openvswitch-configuration
 | 
					            openvswitch-configuration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1429,6 +1431,52 @@ extra-settings "\n"))))
 | 
				
			||||||
    "Run the @uref{https://w1.fi/hostapd/, hostapd} daemon for Wi-Fi access
 | 
					    "Run the @uref{https://w1.fi/hostapd/, hostapd} daemon for Wi-Fi access
 | 
				
			||||||
points and authentication servers.")))
 | 
					points and authentication servers.")))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(define (simulated-wifi-shepherd-services config)
 | 
				
			||||||
 | 
					  "Return Shepherd services to run hostapd with CONFIG, a
 | 
				
			||||||
 | 
					<hostapd-configuration>, as well as services to set up WiFi hardware
 | 
				
			||||||
 | 
					simulation."
 | 
				
			||||||
 | 
					  (append (hostapd-shepherd-services config
 | 
				
			||||||
 | 
					                                     #:requirement
 | 
				
			||||||
 | 
					                                     '(unblocked-wifi
 | 
				
			||||||
 | 
					                                       mac-simulation-module))
 | 
				
			||||||
 | 
					          (list (shepherd-service
 | 
				
			||||||
 | 
					                 (provision '(unblocked-wifi))
 | 
				
			||||||
 | 
					                 (requirement '(file-systems mac-simulation-module))
 | 
				
			||||||
 | 
					                 (documentation
 | 
				
			||||||
 | 
					                  "Unblock WiFi devices for use by mac80211_hwsim.")
 | 
				
			||||||
 | 
					                 (start #~(lambda _
 | 
				
			||||||
 | 
					                            (invoke #$(file-append util-linux "/sbin/rfkill")
 | 
				
			||||||
 | 
					                                    "unblock" "0")
 | 
				
			||||||
 | 
					                            (invoke #$(file-append util-linux "/sbin/rfkill")
 | 
				
			||||||
 | 
					                                    "unblock" "1")))
 | 
				
			||||||
 | 
					                 (one-shot? #t))
 | 
				
			||||||
 | 
					                (shepherd-service
 | 
				
			||||||
 | 
					                 (provision '(mac-simulation-module))
 | 
				
			||||||
 | 
					                 (requirement '(file-systems))
 | 
				
			||||||
 | 
					                 (modules '((guix build utils)))
 | 
				
			||||||
 | 
					                 (documentation
 | 
				
			||||||
 | 
					                  "Load the mac80211_hwsim Linux kernel module.")
 | 
				
			||||||
 | 
					                 (start (with-imported-modules '((guix build utils))
 | 
				
			||||||
 | 
					                          #~(lambda _
 | 
				
			||||||
 | 
					                              ;; XXX: We can't use 'load-linux-module*' here because it
 | 
				
			||||||
 | 
					                              ;; expects a flat module directory.
 | 
				
			||||||
 | 
					                              (setenv "LINUX_MODULE_DIRECTORY"
 | 
				
			||||||
 | 
					                                      "/run/booted-system/kernel/lib/modules")
 | 
				
			||||||
 | 
					                              (invoke #$(file-append kmod "/bin/modprobe")
 | 
				
			||||||
 | 
					                                      "mac80211_hwsim"))))
 | 
				
			||||||
 | 
					                 (one-shot? #t)))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(define simulated-wifi-service-type
 | 
				
			||||||
 | 
					  (service-type
 | 
				
			||||||
 | 
					   (name 'simulated-wifi)
 | 
				
			||||||
 | 
					   (extensions
 | 
				
			||||||
 | 
					    (list (service-extension shepherd-root-service-type
 | 
				
			||||||
 | 
					                             simulated-wifi-shepherd-services)))
 | 
				
			||||||
 | 
					   (default-value (hostapd-configuration
 | 
				
			||||||
 | 
					                   (interface "wlan1")
 | 
				
			||||||
 | 
					                   (ssid "Test Network")))
 | 
				
			||||||
 | 
					   (description "Run hostapd to simulate WiFi connectivity.")))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
;;;
 | 
					;;;
 | 
				
			||||||
;;; Open vSwitch
 | 
					;;; Open vSwitch
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue