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 ¶
var ( ErrInvalidRequest = &Error{ Number: 1, Message: "Invalid request", } ErrUnsupportedProtocol = &Error{ Number: 2, Message: "Unsupported protocol", } Number: 3, Message: "Chosen IP(s) unavailable", } )
Possible Error values.
Functions ¶
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 ¶
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 ¶
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 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.