conn

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2022 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const SocketControlMessageBufferSize = 128

SocketControlMessageBufferSize specifies the buffer size for receiving socket control messages.

View Source
const UIO_MAXIOV = 1024

Source: include/uapi/linux/uio.h

Variables

View Source
var (
	ErrMessageTruncated        = errors.New("the packet is larger than the supplied buffer")
	ErrControlMessageTruncated = errors.New("the control message is larger than the supplied buffer")
)

Functions

func AddrPortMappedEqual added in v1.1.0

func AddrPortMappedEqual(l, r netip.AddrPort) bool

AddrPortMappedEqual returns whether the two addresses point to the same endpoint. An IPv4 address and an IPv4-mapped IPv6 address pointing to the same endpoint are considered equal. For example, 1.1.1.1:53 and [::ffff:1.1.1.1]:53 are considered equal.

func AddrPortToSockaddr

func AddrPortToSockaddr(addrPort netip.AddrPort) (name *byte, namelen uint32)

func AddrPortToSockaddrInet4

func AddrPortToSockaddrInet4(addrPort netip.AddrPort) unix.RawSockaddrInet4

func AddrPortToSockaddrInet6

func AddrPortToSockaddrInet6(addrPort netip.AddrPort) unix.RawSockaddrInet6

func AddrPortv4Mappedv6 added in v1.1.0

func AddrPortv4Mappedv6(addrPort netip.AddrPort) netip.AddrPort

AddrPortv4Mappedv6 converts an IPv4 address to an IPv4-mapped IPv6 address. This function does nothing if addrPort is an IPv6 address.

func DialTFOWithPayload

func DialTFOWithPayload(dialer *tfo.Dialer, address string, payload []byte) (n int, conn tfo.Conn, err error)

DialTFOWithPayload uses a TFO dialer to dial the target and writes the initial payload. TFO is disabled if initial payload is empty.

func ListenUDP

func ListenUDP(network string, laddr string, pktinfo bool, fwmark int) (conn *net.UDPConn, err error, serr error)

ListenUDP wraps Go's net.ListenConfig.ListenPacket and sets socket options on supported platforms.

On Linux and Windows, IP_MTU_DISCOVER and IPV6_MTU_DISCOVER are set to IP_PMTUDISC_DO to disable IP fragmentation and encourage correct MTU settings. If pktinfo is true, IP_PKTINFO and IPV6_RECVPKTINFO are set to 1.

On Linux, SO_MARK is set to user-specified value.

On macOS and FreeBSD, IP_DONTFRAG, IPV6_DONTFRAG are set to 1 (Don't Fragment).

func NewDialer

func NewDialer(dialerTFO bool, dialerFwmark int) (dialer tfo.Dialer)

NewDialer returns a tfo.Dialer with the specified options applied.

func NewListenConfig

func NewListenConfig(listenerTFO bool, listenerFwmark int) (lc tfo.ListenConfig)

NewListenConfig returns a tfo.ListenConfig with the specified options applied.

func ParseFlagsForError

func ParseFlagsForError(flags int) error

ParseFlagsForError parses the message flags returned by the ReadMsgUDPAddrPort method and returns an error if MSG_TRUNC is set, indicating that the returned packet was truncated.

The check is skipped on Windows, because an error (WSAEMSGSIZE) is also returned when MSG_PARTIAL is set.

func Recvmmsg

func Recvmmsg(conn *net.UDPConn, msgvec []Mmsghdr) (n int, err error)

func ResolveAddr

func ResolveAddr(host string, preferIPv6 bool) (netip.Addr, error)

ResolveAddr resolves a domain name string into netip.Addr. String representations of IP addresses are not supported.

func Sendmmsg

func Sendmmsg(conn *net.UDPConn, msgvec []Mmsghdr) (n int, err error)

func SockaddrToAddrPort

func SockaddrToAddrPort(name *byte, namelen uint32) (netip.AddrPort, error)

func UpdatePktinfoCache added in v1.2.0

func UpdatePktinfoCache(pktinfoCache, cmsgs []byte, logger *zap.Logger) ([]byte, error)

On Linux and Windows, UpdatePktinfoCache filters out irrelevant socket control messages, saves IP_PKTINFO or IPV6_PKTINFO socket control messages to the pktinfo cache, and returns the updated pktinfo cache slice.

The returned pktinfo cache is unchanged if no relevant control messages are found.

On other platforms, this is a no-op.

func WriteMsgvec

func WriteMsgvec(conn *net.UDPConn, msgvec []Mmsghdr) error

WriteMsgvec repeatedly calls sendmmsg(2) until all messages in msgvec are written to the socket.

If the syscall returns an error, this function drops the message that caused the error, and continues sending. Only the last encountered error is returned.

Types

type Addr added in v1.1.0

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

Addr is the base address type used throughout the package.

An Addr is a port number combined with either an IP address or a domain name.

func AddrFromDomainPort added in v1.1.0

func AddrFromDomainPort(domain string, port uint16) (Addr, error)

AddrFromDomainPort returns an Addr from the provided domain name and port number.

func AddrFromHostPort added in v1.1.0

func AddrFromHostPort(host string, port uint16) (Addr, error)

AddrFromHostPort returns an Addr from the provided host string and port number. The host string may be a string representation of an IP address or a domain name.

func AddrFromIPPort added in v1.1.0

func AddrFromIPPort(addrPort netip.AddrPort) (addr Addr)

AddrFromIPPort returns an Addr from the provided netip.AddrPort.

func MustAddrFromDomainPort added in v1.1.0

func MustAddrFromDomainPort(domain string, port uint16) Addr

MustAddrFromDomainPort calls AddrFromDomainPort and panics on error.

func ParseAddr added in v1.1.0

func ParseAddr(s string) (Addr, error)

ParseAddr parses the provided string representation of an address and returns the parsed address or an error.

func (Addr) AppendTo added in v1.1.0

func (a Addr) AppendTo(b []byte) []byte

AppendTo appends the string representation of the address to the provided buffer.

func (Addr) Domain added in v1.1.0

func (a Addr) Domain() string

Domain returns the domain name. If the address is an IP address, the returned domain name is an empty string.

func (Addr) Host added in v1.1.0

func (a Addr) Host() string

Host returns the string representation of the IP address or the domain name.

func (Addr) IP added in v1.1.0

func (a Addr) IP() netip.Addr

IP returns the IP address. If the address is a domain name, the returned netip.Addr is a zero value.

func (Addr) IPPort added in v1.1.0

func (a Addr) IPPort() netip.AddrPort

IPPort returns a netip.AddrPort. If the address is a domain name, the returned netip.AddrPort contains a zero-value netip.Addr and the port number.

func (Addr) IsIP added in v1.1.0

func (a Addr) IsIP() bool

IsIP returns whether the address is an IP address. If false, the address is a domain name.

func (Addr) MappedEquals added in v1.1.0

func (a Addr) MappedEquals(b Addr) bool

MappedEquals returns whether the two addresses point to the same endpoint. An IPv4 address and an IPv4-mapped IPv6 address pointing to the same endpoint are considered equal. For example, 1.1.1.1:53 and [::ffff:1.1.1.1]:53 are considered equal.

func (Addr) MarshalText added in v1.1.0

func (a Addr) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler MarshalText method.

func (Addr) Port added in v1.1.0

func (a Addr) Port() uint16

Port returns the port number.

func (Addr) ResolveIP added in v1.1.0

func (a Addr) ResolveIP(preferIPv6 bool) (netip.Addr, error)

ResolveIP returns the IP address itself or the resolved IP address of the domain name.

func (Addr) ResolveIPPort added in v1.1.0

func (a Addr) ResolveIPPort(preferIPv6 bool) (netip.AddrPort, error)

ResolveIPPort returns the IP address itself or the resolved IP address of the domain name and the port number as a netip.AddrPort.

func (Addr) String added in v1.1.0

func (a Addr) String() string

String returns the string representation of the address.

func (*Addr) UnmarshalText added in v1.1.0

func (a *Addr) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler UnmarshalText method.

type Mmsghdr

type Mmsghdr struct {
	Msghdr unix.Msghdr
	Msglen uint32
}

Jump to

Keyboard shortcuts

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