NAME

Tailscale - Perl bindings for tailscale-rs

SYNOPSIS

use Tailscale;

my $ts = Tailscale->new(
    config_path => "state.json",
    auth_key    => "tskey-auth-...",
);

my $ip = $ts->ipv4_addr();    # e.g. "100.64.0.5"

# Connect to a peer
my $stream = $ts->tcp_connect("100.100.100.100:80");
$stream->send_all("GET / HTTP/1.0\r\nHost: peer\r\n\r\n");
my $data = $stream->recv(4096);

# Listen for connections
my $listener = $ts->tcp_listen(8080);
my $conn = $listener->accept();

DESCRIPTION

Tailscale provides Perl bindings for tailscale-rs, a Rust implementation of Tailscale similar to Go's tsnet. It lets you join a Tailscale network directly from a Perl program with no tailscaled daemon required.

The module uses FFI::Platypus to call the C FFI functions exported by the libtailscalers.so shared library built from tailscale-rs.

Finding the shared library

Set the TS_LIB_PATH environment variable to the directory containing libtailscalers.so:

export TS_LIB_PATH=/path/to/tailscale-rs/target/release

CONSTRUCTOR

new

my $ts = Tailscale->new(%args);

Creates a new Tailscale node and connects it to the tailnet. This call blocks until the node is registered with the coordination server.

Arguments:

config_path (required)

Path to a JSON file that stores the node's cryptographic identity. Created automatically on first run.

auth_key

A Tailscale auth key (tskey-auth-...) used to authorize the node. May be omitted if the node is already authorized from a previous run.

hostname

The hostname this node requests on the tailnet. Defaults to the OS hostname.

control_url

URL of the Tailscale coordination server. Defaults to the production server. Useful for testing with a custom control plane.

METHODS

ipv4_addr

my $ip = $ts->ipv4_addr();

Returns the node's Tailscale IPv4 address as a dotted-quad string (e.g. "100.64.0.1"). Blocks until an address is assigned.

tcp_connect

my $stream = $ts->tcp_connect("100.64.0.2:80");

Opens a TCP connection to the given ip:port on the tailnet. Returns a Tailscale::TcpStream object. Dies on failure.

tcp_listen

my $listener = $ts->tcp_listen(8080);

Starts listening for TCP connections on the given port, bound to the node's Tailscale IPv4 address. Returns a Tailscale::TcpListener object. Dies on failure.

close

$ts->close();

Shuts down the Tailscale node and releases all resources. Also called automatically when the object is destroyed.

SEE ALSO

Tailscale::TcpStream, Tailscale::TcpListener, Tailscale::HttpServer, https://github.com/tailscale/tailscale-rs

AUTHOR

Brad Fitzpatrick <brad@danga.com>

LICENSE

BSD-3-Clause