sharedsock

package
v0.28.8 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: BSD-3-Clause Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSharedSockStopped = fmt.Errorf("shared socked stopped")

ErrSharedSockStopped indicates that shared socket has been stopped

Functions

func Listen

func Listen(port int, filter BPFFilter) (_ net.PacketConn, err error)

Listen creates an IPv4 and IPv6 raw sockets, starts a reader and routing table routines

Types

type BPFFilter

type BPFFilter interface {
	// GetInstructions returns raw BPF instructions for ipv4 and ipv6
	GetInstructions(port uint32) (ipv4 []bpf.RawInstruction, ipv6 []bpf.RawInstruction, err error)
}

BPFFilter is a generic filter that provides ipv4 and ipv6 BPF instructions

func NewIncomingSTUNFilter added in v0.20.0

func NewIncomingSTUNFilter() BPFFilter

NewIncomingSTUNFilter creates an instance of a IncomingSTUNFilter

type IncomingSTUNFilter added in v0.20.0

type IncomingSTUNFilter struct {
}

IncomingSTUNFilter implements BPFFilter and filters out anything but incoming STUN packets to a specified destination port. Other packets (non STUN) will be forwarded to the process that own the port (e.g., WireGuard).

func (*IncomingSTUNFilter) GetInstructions added in v0.20.0

func (filter *IncomingSTUNFilter) GetInstructions(dstPort uint32) (raw4 []bpf.RawInstruction, raw6 []bpf.RawInstruction, err error)

GetInstructions returns raw BPF instructions for ipv4 and ipv6 that filter out anything but STUN packets

type SharedSocket

type SharedSocket struct {
	// contains filtered or unexported fields
}

SharedSocket is a net.PacketConn that initiates two raw sockets (ipv4 and ipv6) and listens to UDP packets filtered by BPF instructions (e.g., IncomingSTUNFilter that checks and sends only STUN packets to the listeners (ReadFrom)). It is meant to be used when sharing a port with some other process.

func (*SharedSocket) Close

func (s *SharedSocket) Close() error

Close closes the underlying ipv4 and ipv6 conn sockets

func (*SharedSocket) LocalAddr

func (s *SharedSocket) LocalAddr() net.Addr

LocalAddr returns an IPv4 address using the supplied port

func (*SharedSocket) ReadFrom

func (s *SharedSocket) ReadFrom(b []byte) (n int, addr net.Addr, err error)

ReadFrom reads packets received in the packetDemux channel

func (*SharedSocket) SetDeadline

func (s *SharedSocket) SetDeadline(t time.Time) error

SetDeadline sets both the read and write deadlines associated with the ipv4 and ipv6 Conn sockets

func (*SharedSocket) SetReadDeadline

func (s *SharedSocket) SetReadDeadline(t time.Time) error

SetReadDeadline sets the read deadline associated with the ipv4 and ipv6 Conn sockets

func (*SharedSocket) SetWriteDeadline

func (s *SharedSocket) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the write deadline associated with the ipv4 and ipv6 Conn sockets

func (*SharedSocket) WriteTo

func (s *SharedSocket) WriteTo(buf []byte, rAddr net.Addr) (n int, err error)

WriteTo builds a UDP packet and writes it using the specific IP version writer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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