NAME

Linux::WireGuard - WireGuard in Perl

SYNOPSIS

my @names = Linux::WireGuard::list_device_names();

my %device = map { $_ => Linux::WireGuard::get_device($_) } @names;

DESCRIPTION

Linux::WireGuard provides an interface to WireGuard via Linux’s embedded WireGuard C library.

NB: Although WireGuard itself is cross-platform, its embedded C library is Linux-specific.

CHARACTER ENCODING

All strings into & out of this module are byte strings.

ERROR HANDLING

Failures become Perl exceptions. Currently those exceptions are plain strings. Errors that come from WireGuard also manifest as changes to Perl’s $! global; for example, if you try to get_device() while non-root, you’ll probably see (besides the thrown exception) $! become Errno::EPERM.

FUNCTIONS

@names = list_device_names()

Returns a list of strings.

$dev_hr = get_device( $NAME )

Returns a reference to a hash that describes the $NAME’d device:

add_device( $NAME )

Adds a WireGuard device with the given $NAME.

del_device( $NAME )

Deletes a WireGuard device with the given $NAME.

$bin = generate_private_key()

Returns a newly-generated private key (raw string).

$bin = generate_public_key( $PRIVATE_KEY )

Takes a private key and returns its public key. (Both raw strings.)

$bin = generate_preshared_key()

Returns a newly-generated preshared key (raw string).

TODO

An implementation of set_device() would be nice to have.

LICENSE & COPYRIGHT

Copyright 2022 Gasper Software Consulting. All rights reserved.

Linux::WireGuard is licensed under the same terms as Perl itself (cf. perlartistic); HOWEVER, the embedded C wireguard library has its own copyright terms. Use of Linux::WireGuard may imply acceptance of that embedded C library’s own copyright terms. See this distribution’s wireguard-tools/contrib/embeddable-wg-library/README for details.