This rc.d script reimplements most features of wg-quick(8) in FreeBSD
/bin/sh instead of bash.
The following features have not been reimplemented:
- The daemon syncing a routing table the AllowedIPs settings.
- Saving the active configuration back to a config file.
The PreUp/PostUp/PreDown/PostDown hooks are implemented, but the hooks
are executed in sh instead of bash. Additionally the successful execution
is tracked to avoid (re-)execution of hooks because it's expected that users will rerun rc.d scripts.
Since the WireGuard rc.d script is supposed to make using WireGuard on FreeBSD as easy as possible it handles the creation and destruction of WireGuard interfaces instead of forcing users to configure the netif script to clone and rename WireGuard interfaces I added one feature not present in wg-quick(8): the Sticky setting. Sticky interfaces are only deconfigured (IP addresses removed, link brought down, configuration replaced with the empty configuration), but not destroyed by service wireguard stop $ifn. To avoid having to add a FreeBSD specific setting to the configuration files the rc.d script also looks at the sticky bit of interface configuration files.
The rc.d script uses per interface lock files (implemented using lockf) to protect against race conditions (e.g. restarting an interface via devd and ifstated at the same time), because otherwise users would have to implement similar locking in their {Pre,Post}{Up,Down} hooks.