diff --git a/security/tailscale/Makefile b/security/tailscale/Makefile index 0a336ea028c9..93a2c9db290a 100644 --- a/security/tailscale/Makefile +++ b/security/tailscale/Makefile @@ -1,29 +1,30 @@ PORTNAME= tailscale PORTVERSION= 1.24.2 +PORTREVISION= 1 DISTVERSIONPREFIX= v CATEGORIES= security MAINTAINER= ashish@FreeBSD.org COMMENT= Mesh VPN that makes it easy to connect your devices LICENSE= BSD3CLAUSE LICENSE_FILE= ${WRKSRC}/LICENSE RUN_DEPENDS= ca_root_nss>0:security/ca_root_nss USES= go:modules GO_MODULE= github.com/tailscale/tailscale USE_RC_SUBR= tailscaled GO_TARGET= ./cmd/tailscale \ ./cmd/tailscaled GO_BUILDFLAGS= -tags xversion -ldflags "\ -X tailscale.com/version.Long=${PORTVERSION} \ -X tailscale.com/version.Short=${PORTVERSION}" PLIST_FILES= bin/tailscale \ bin/tailscaled .include diff --git a/security/tailscale/files/tailscaled.in b/security/tailscale/files/tailscaled.in index b1cb480b92bc..9300e901357c 100644 --- a/security/tailscale/files/tailscaled.in +++ b/security/tailscale/files/tailscaled.in @@ -1,87 +1,93 @@ #!/bin/sh # PROVIDE: tailscaled # REQUIRE: NETWORKING # KEYWORD: shutdown # # Add the following lines to /etc/rc.conf.local or /etc/rc.conf # to enable this service: # # tailscaled_enable (bool): Set it to YES to enable tailscaled. # Default is "NO". # tailscaled_port (number): Set the port to listen on for incoming VPN packets. # Default is "41641". # tailscaled_syslog_output_enable (bool): Set to enable syslog output. # Default is "NO". See daemon(8). # tailscaled_syslog_output_priority (str): Set syslog priority if syslog enabled. # Default is "info". See daemon(8). # tailscaled_syslog_output_facility (str): Set syslog facility if syslog enabled. # Default is "daemon". See daemon(8). # tailscaled_exitnode_enable (bool): Set it to YES to announce tailscaled as # an exit node. Default is "NO". . /etc/rc.subr name=tailscaled rcvar=tailscaled_enable load_rc_config $name : ${tailscaled_enable:="NO"} : ${tailscaled_port:="41641"} : ${tailscaled_exitnode_enable:="NO"} DAEMON=$(/usr/sbin/daemon 2>&1 | grep -q syslog ; echo $?) if [ ${DAEMON} -eq 0 ]; then : ${tailscaled_syslog_output_enable:="NO"} : ${tailscaled_syslog_output_priority:="info"} : ${tailscaled_syslog_output_facility:="daemon"} if checkyesno tailscaled_syslog_output_enable; then tailscaled_syslog_output_flags="-t ${name} -T ${name}" if [ -n "${tailscaled_syslog_output_priority}" ]; then tailscaled_syslog_output_flags="${tailscaled_syslog_output_flags} -s ${tailscaled_syslog_output_priority}" fi if [ -n "${tailscaled_syslog_output_facility}" ]; then tailscaled_syslog_output_flags="${tailscaled_syslog_output_flags} -l ${tailscaled_syslog_output_facility}" fi fi else tailscaled_syslog_output_enable="NO" tailscaled_syslog_output_flags="" fi pidfile=/var/run/${name}.pid procname="%%PREFIX%%/bin/${name}" ctlname="%%PREFIX%%/bin/tailscale" # XXX: Can we have multiple interfaces? tailscale_tap_dev="tailscale0" start_cmd="${name}_start" start_postcmd="${name}_poststart" stop_postcmd="${name}_poststop" tailscaled_start() { + # Check for orphaned tailscale network interface + # And if it exists, then destroy it + /sbin/ifconfig ${tailscale_tap_dev} >/dev/null 2>&1 && ( + /sbin/ifconfig ${tailscale_tap_dev} | fgrep -qw PID || + /sbin/ifconfig ${tailscale_tap_dev} destroy + ) env CACHE_DIRECTORY=/var/db/tailscale /usr/sbin/daemon -f ${tailscaled_syslog_output_flags} -p ${pidfile} ${procname} --port ${tailscaled_port} } tailscaled_poststart() { if checkyesno tailscaled_exitnode_enable; then logger -s -t tailscale "Enabling Exit node mode" ${ctlname} up --advertise-exit-node fi } tailscaled_poststop() { /sbin/ifconfig ${tailscale_tap_dev} >/dev/null 2>&1 && ( logger -s -t tailscaled "Destroying tailscale0 adapter" /sbin/ifconfig ${tailscale_tap_dev} destroy || logger -s -t tailscaled "Failed to destroy ${tailscale_tap_dev} adapter" ) } run_rc_command "$1"