OpenRC notebook roaming How-To

Abstract
This articles show how to set up a OpenRC to act as a convenient, transparent and flexible networking client which supports roaming as an alternative to other solutions often used on notebooks.

Requirements
The currently stable version of these packages are all that is needed (no *kit software required)
 * OpenRC - management of services
 * wpa_supplicant - Wi-FI configuration and connection
 * enable the qt4 USE flag if you want to have a GUI for the Wi-FI client
 * - for hotplugging of ethernet interfaces
 * can be used as an alternative, but development has been discontinued

Configuration and setup
Before you start configuring the interfaces, make sure that they work (meaning you have the required drivers installed) and that you know their names. A convenient way is to make a Udev rule to give them human-readable names like ethernet0, wireless0.

OpenRC service management
For each interface an init script must be created for OpenRC to manage that interface by making a symlink to net.lo

where ${INTERFACE_NAME} is the name of the interface, e.g. eth0, wlan0, ethernet0, wireless0

If simple roaming is required, any network interface will satisfy the virtual net service. Therefore it is recommended to set rc_need_strict="NO" in /etc/rc.conf.

The services responsible for managing the interfaces must be added to one or more runlevel. This makes it possible to have network profiles by having most services in the default runlevel and then adding the interfaces to stacked runlevels and having different configuration files in /etc/conf.d/ for each runlevel as /etc/conf.d/net.${RUNELEVEL} The options and syntax of /etc/conf.d/net is decribed in the Gentoo Handbook which shows how to set up more complicated networks (this how-to assumes that all connections are initiated via DHCP)

Suspend to RAM example
With most services in the default runlevel and network services in a runlevel "network", which is stacked on the default runlevel, a PM hook for pm-utils can be crated which transparently stops network services before suspending, thus preventing timeouts and other problems.

The hook must be executable

Exclusive network interface example
It may be desirable to have always only one networking interface configured. This can be done by the postup or postdown functions defined in /etc/conf.d/net

Wi-Fi management
A minimal /etc/wpa_supplicant/wpa_cupplicant.conf is required to begin with. The permissions for the control interface should reflect who can configure the wireless interface. This minimal example assumes only users in the wheel group are allowed to configure the interface and that the configuration file can be updated by clients.

The use of the wpa_supplicant daemon on the interface may have to be enforced in /etc/conf.d/net

Clients
The wpa_supplicant daemon can be controlled via clients
 * wpa_cli - command-line client
 * wpa_gui - Qt4 based GUI client (only with the qt4 USE flag)
 * can be started in the system tray in the Xorg startup file .xinitrc

Ethernet management
OpenRC automatically hotplugs all interfaces if configured in /etc/rc.conf

so the respective services will be started if that interface becomes available and ifplugd will be automatically started for every ethernet interface to ensure that the device gets configured when a carrier is acquired (e.g. a cable is plugged in). Ifplugd will emit beeps on state change which can be disabled in /etc/ifplugd/ifplugd.conf