#!/bin/sh

# $FreeBSD$
#
# sslh startup script
#
# PROVIDE: sslh
# REQUIRE: LOGIN FILESYSTEMS ldconfig sshd
# KEYWORD: shutdown
#
# Add the following to /etc/rc.conf[.local] to enable this service:
# sslh_enable="YES"
#
# You can fine tune other variables too:
# sslh_mode="fork | select"
# fork: stable but slow performance
# select: new but high performance
# sslh_fib: routing table number

sslh_precmd() {
	if command -v check_namevarlist > /dev/null 2>&1; then
		check_namevarlist fib && return 0
	fi
	sysctl net.fibs > /dev/null 2>&1 || return 0

	sslh_fib=${sslh_fib:-"NONE"}
	case "$sslh_fib" in
	[Nn][Oo][Nn][Ee])
		;;
	*)
		command="setfib -F ${sslh_fib} ${command}"
		;;
	esac
}

. /etc/rc.subr

name="sslh"
rcvar=sslh_enable

start_precmd="sslh_precmd"

load_rc_config $name
sslh_enable=${sslh_enable:-"NO"}
sslh_mode=${sslh_mode:-"fork"}

required_files="/usr/local/etc/${name}.conf"

for value in listening openvpntarget sshtarget sshtimeout ssltarget \
    tinctarget xmpptarget; do
	eval "[ -n \"\${sslh_${value}}\" ]" && \
	    warn "${name}_${value} no longer used: configuration file available"
done

command="/usr/local/sbin/${name}-${sslh_mode}"
command_args="-F/usr/local/etc/${name}.conf"

run_rc_command "$1"
