# Contributed by: Thibaut Sautereau <thibaut@sautereau.fr>

. "$SUBR_DIR/ip"

# Make sure BindsToInterfaces is set
BindsToInterfaces=("${BindsToInterfaces[@]}")

wireguard_up() {
    if is_interface "$Interface"; then
        report_error "Interface '$Interface' already exists"
        return 1
    fi

    # Treat $MACAddress as in other connections, but it has no effect here
    interface_add wireguard "$Interface" "$MACAddress" || return
    wg setconf "$Interface" "${WGConfigFile:-/etc/wireguard/$Interface.conf}"
    bring_interface_up "$Interface"
    ip_set
}

wireguard_down() {
    ip_unset
    interface_delete "$Interface"
}


# vim: ft=sh ts=4 et sw=4:
