Documentation
¶
Overview ¶
Package wg helps with the creation and usage of userland wireguard networks.
Index ¶
- Constants
- Variables
- func IsBogon(ip net.IP) bool
- func IsLinkLocal(ip net.IP) bool
- func IsLoopback(ip net.IP) bool
- func IsPrivateNetwork(ip net.IP) bool
- type Bind
- type Device
- type Dialer
- type Net
- type Netstack
- func (d *Netstack) BatchSize() int
- func (d *Netstack) Close() error
- func (d *Netstack) Events() <-chan tun.Event
- func (d *Netstack) File() *os.File
- func (d *Netstack) MTU() (int, error)
- func (d *Netstack) Name() (string, error)
- func (d *Netstack) Net() *Net
- func (d *Netstack) Read(buf [][]byte, sizes []int, offset int) (n int, err error)
- func (d *Netstack) Write(buf [][]byte, offset int) (int, error)
- type Option
- type TCPIPError
- type Wireguard
Constants ¶
const ( // WireguardHeaderSize is the size of a wireguard header. The MTU needed for the [Netstack] is <actual hardware MTU> - [WireguardHeaderSize]. WireguardHeaderSize = 80 // DefaultMTU is the default MTU as specified from wireguard-go DefaultMTU = device.DefaultMTU // DefaultBatchSize is the default number of packets read/written from the [tun.Device] in one operation. DefaultBatchSize = conn.IdealBatchSize // DefaultChannelSize is the size of the packet queue for the underlaying [channel.Endpoint] DefaultChannelSize = 8 * DefaultBatchSize )
Variables ¶
var ( ErrInvalidLocalIP = errors.New("local ip is invalid") ErrInvalidRemoteIP = errors.New("remote ip is invalid") )
var DefaultBind = defaultBind
var (
ErrNoDeviceSpecified = errors.New("no device specified")
)
var SetStackOptions = func(s *stack.Stack, ep *channel.Endpoint, id *tcpip.NICID) error { // Wireguard-go does this var enableSACK tcpip.TCPSACKEnabled = true if err := s.SetTransportProtocolOption(tcp.ProtocolNumber, &enableSACK); err != nil { return &TCPIPError{Err: err} } *id = tcpip.NICID(s.UniqueID()) if err := s.CreateNICWithOptions(*id, ep, stack.NICOptions{Name: ""}); err != nil { return &TCPIPError{Err: err} } return nil }
Functions ¶
func IsBogon ¶ added in v0.0.5
IsBogon returns true if dialing the address would fail due to gonet. IsPrivateNetwork is left out because it will still remote, but it can be used to help check incoming ip addresses.
func IsLinkLocal ¶ added in v0.0.5
func IsLoopback ¶ added in v0.0.5
func IsPrivateNetwork ¶ added in v0.0.5
Types ¶
type Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
Dialer handles dialing with a given local address
type Net ¶
type Net Netstack
Net handles the application level dialing/listening.
func (*Net) ListenPacket ¶
ListenPacket listens with the UDP protocol on the given address
type Netstack ¶
type Netstack struct {
// contains filtered or unexported fields
}
Netstack is a wireguard device that takes the raw packets communicated through wireguard and turns them into meaningful TCP/UDP connections.
func NewDefaultNetstack ¶
NewDefaultNetstack calls NewNetstack with the default values.
func NewNetstack ¶
NewNetstack creates a new wireguard network stack.
func (*Netstack) BatchSize ¶
BatchSize implements tun.Device.BatchSize and returns the configured BatchSize
func (*Netstack) Events ¶
Events implements tun.Device.Events
func (*Netstack) File ¶
File implements tun.Device.File and always returns nil
func (*Netstack) MTU ¶
MTU implements tun.Device.MTU and returns the configured MTU
func (*Netstack) Name ¶
Name implements tun.Device.Name and always returns "point-c"
type Option ¶
type Option func(*options) error
func OptionBind ¶
OptionBind sets the Bind in the [options] struct. If this is not specified DefaultBind will be used.
func OptionCloser ¶
OptionCloser adds a closer function to the [options] struct. Closer functions are called to gracefully close resources when needed.
func OptionConfig ¶
func OptionConfig(cfg wgapi.Configurable) Option
OptionConfig specifies a wireguard config to load before the interface is brought up.
func OptionDevice ¶
OptionDevice specifies the Device in the [options] struct.
func OptionLogger ¶
OptionLogger adds a logger to the [options] struct.
func OptionNetDevice ¶
OptionNetDevice initializes a userspace networking stack. Note: The pointer *p becomes valid and usable only if the New function successfully completes without returning an error. In case of errors, *p should not be considered reliable.
type TCPIPError ¶
TCPIPError turn a tcpip.Error into a normal error.
func (*TCPIPError) Error ¶
func (err *TCPIPError) Error() string
type Wireguard ¶
type Wireguard struct {
// contains filtered or unexported fields
}
Wireguard handles configuring and closing a wireguard client/server.
func (*Wireguard) Close ¶
Close closes the wireguard server/client, rendering it unusable in the future.