sharedsock

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2023 License: BSD-3-Clause Imports: 14 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, 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 NewSTUNFilter

func NewSTUNFilter() BPFFilter

NewSTUNFilter creates an instance of a STUNFilter

type STUNFilter

type STUNFilter struct {
}

STUNFilter implements BPFFilter by filtering on STUN packets. Other packets (non STUN) will be forwarded to the process that own the port (e.g., WireGuard).

func (STUNFilter) GetInstructions

func (sf STUNFilter) GetInstructions(port 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., STUNFilter that checks and sends only STUN packets to the listeners (ReadFrom)).

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 writter

Jump to

Keyboard shortcuts

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