diff --git a/net/fastd/files/fastd.config b/net/fastd/files/fastd.config index a51de60..afba82c 100644 --- a/net/fastd/files/fastd.config +++ b/net/fastd/files/fastd.config @@ -12,7 +12,7 @@ config fastd sample_config # Sets a directory from which peers configurations are read # The peer list can be reloaded without restarting fastd - # This is currently the only way to configure the peers + # Peer can either be configured via UCI (see example below) or via peer dirs list config_peer_dir '/etc/fastd/sample_config/peers' # Sets the log level @@ -59,3 +59,36 @@ config fastd sample_config # command to execute before the tunnel interface is set down; $1 will be the interface name (optional) # option down '' + + +config peer sample_peer + + # Set to 1 to enable this peer: + option enabled 0 + + # Controls which instance this peer is associated with + option net 'sample_config' + + # The peer's public key + option key '0000000000000000000000000000000000000000000000000000000000000000' + + # A complete remote specification consists of an address or a hostname, and a port + # When a hostname is given, it is recommended to specify an address family to use + + # The address to connect to (optional) +# option address '192.0.2.1' +# option address '[2001:db8::1]' + + # The hostname to connect to (optional) +# option hostname 'example.com' + + # The address family to use to connect to the hostname (optional) + # Must be 'ipv4' or 'ipv6' + # Has no effect when an address is specified +# option address_family 'ipv4' + + # The remote port to connect to (optional) +# option port 1337 + + # Setting float to 1 allow incoming connections with this key from other addresses/hostnames/ports than the specified remote + option float 0 diff --git a/net/fastd/files/fastd.init b/net/fastd/files/fastd.init index dfae243..5cea2ee 100644 --- a/net/fastd/files/fastd.init +++ b/net/fastd/files/fastd.init @@ -54,6 +54,70 @@ error() { echo "${initscript}:" "$@" 1>&2 } +create_peer_config() { + local s="$2"; local peer="$1" + + config_get net "$peer" net + [ "$net" == "$s" ] || return 0 + + section_enabled "$peer" || return 0 + + config_get key "$peer" key + config_get address "$peer" address + config_get hostname "$peer" hostname + config_get address_family "$peer" address_family + config_get port "$peer" port + config_get_bool float "$peer" float 0 + + if [ -z "$key" ]; then + error "peer $peer: key is not set" + return 1 + fi + + local remote='' + if [ "$address" -o "$hostname" ]; then + if [ "$address" -a "$hostname" ]; then + error "peer $peer: both address and hostname given" + return 1 + fi + + if [ "$float" = 0 ]; then + float='' + else + float='float' + fi + + if [ "$port" ]; then + if [ "$address" ]; then + remote="remote $address port $port $float;" + else # $hostname + if [ "$address_family" -a "$address_family" != 'ipv4' -a "$address_family" != 'ipv6' ]; then + error "peer $peer: invalid address family given" + return 1 + fi + remote="remote $address_family \"$hostname\" port $port $float;" + fi + else + error "peer $peer: address or hostname, but no port given" + return 1 + fi + fi + + cat > "$TMP_FASTD/fastd.$s.peers/$peer" <