wgdynamic

package module
v0.0.0-...-2e3a179 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2019 License: MIT Imports: 14 Imported by: 1

README

wgdynamic-go builds.sr.ht status GoDoc Go Report Card

Package wgdynamic implements a client and server for the the wg-dynamic protocol.

For more information about wg-dynamic, please see: https://git.zx2c4.com/wg-dynamic/about/.

This project is not affiliated with the WireGuard or wg-dynamic projects.

MIT Licensed.

Documentation

Overview

Package wgdynamic implements a client and server for the the wg-dynamic protocol.

For more information about wg-dynamic, please see: https://git.zx2c4.com/wg-dynamic/about/.

This project is not affiliated with the WireGuard or wg-dynamic projects.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRequest = &Error{
		Number:  1,
		Message: "Invalid request",
	}
	ErrUnsupportedProtocol = &Error{
		Number:  2,
		Message: "Unsupported protocol",
	}
	ErrIPUnavailable = &Error{
		Number:  3,
		Message: "Chosen IP(s) unavailable",
	}
)

Possible Error values.

Functions

func Listen

func Listen(iface string) (net.Listener, error)

Listen creates a net.Listener suitable for use with a Server and bound to the specified WireGuard interface. Listen will return an error if the does not have the well-known IPv6 link-local server address (fe80::/64) configured.

Types

type Client

type Client struct {
	// Dial specifies an optional function used to dial an arbitrary net.Conn
	// connection to a predetermined wg-dynamic server. This is only necessary
	// when using a net.Conn transport other than *net.TCPConn, and most callers
	// should use NewClient to construct a Client instead.
	Dial func(ctx context.Context) (net.Conn, error)
}

A Client can request IP address assignment using the wg-dynamic protocol. Most callers should construct a client using NewClient, which will bind to well-known addresses for wg-dynamic communications.

func NewClient

func NewClient(iface string) (*Client, error)

NewClient creates a new Client bound to the specified WireGuard interface. NewClient will return an error if the interface does not have an IPv6 link-local address configured.

func (*Client) RequestIP

func (c *Client) RequestIP(ctx context.Context, req *RequestIP) (*RequestIP, error)

RequestIP requests IP address assignment from a server. Fields within req can be specified to request specific IP address assignment parameters. If req is nil, the server will automatically perform IP address assignment.

The provided Context must be non-nil. If the context expires before the request is complete, an error is returned.

type Error

type Error struct {
	Number  int
	Message string
}

An Error is a wg-dynamic protocol error.

func (*Error) Error

func (e *Error) Error() string

Error implements error.

type RequestIP

type RequestIP struct {
	// IPs specify IP addresses with subnet masks.
	//
	// For clients, these request that specific IP addresses are assigned to
	// the client. If nil, no specific IP addresses are requested.
	//
	// For servers, these specify the IP address assignments which are sent
	// to a client. If nil, no IP addresses will be specified.
	IPs []*net.IPNet

	// LeaseStart specifies the time that an IP address lease begins.
	//
	// This option only applies to servers and an error will be returned if it
	// is used in a client request.
	LeaseStart time.Time

	// LeaseTime specifies the duration of an IP address lease. It can be used
	// along with LeaseStart to calculate when a lease expires.
	//
	// For clients, it indicates that the client would prefer a lease for at
	// least this duration of time.
	//
	// For servers, it indicates that the IP address assignment expires after
	// this duration of time has elapsed.
	LeaseTime time.Duration
}

RequestIP contains IP address requests or assignments, depending on whether the structure originated with a client or server.

type Server

type Server struct {
	// RequestIP handles requests for IP address assignment. If nil, a generic
	// protocol error is returned to the client.
	RequestIP func(src net.Addr, r *RequestIP) (*RequestIP, error)

	// Log specifies an error logger for the Server. If nil, all error logs
	// are discarded.
	Log *log.Logger
	// contains filtered or unexported fields
}

A Server serves wg-dynamic protocol requests.

Each exported function field implements a specific request. If any errors are returned, a protocol error is returned to the client. When the error is of type *Error, that protocol error is returned to the client. For generic errors, a generic protocol error is returned.

func (*Server) Close

func (s *Server) Close() error

Close closes the server listener and waits for all requests to complete.

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Serve serves incoming requests by accepting connections from l.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL