transport

package
v0.0.0-...-67cf1be Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const Port = 5353

Port is the mDNS port number.

Variables

View Source
var (
	// IPv4Group is the multicast group used for mDNS over IPv4.
	//
	// See https://tools.ietf.org/html/rfc6762#section-3.
	IPv4Group = net.ParseIP("224.0.0.251")

	// IPv4GroupAddress is the address to which mDNS queries are sent when using IPv4.
	//
	// See https://tools.ietf.org/html/rfc6762#section-3.
	IPv4GroupAddress = &net.UDPAddr{IP: IPv4Group, Port: Port}

	// IPv4ListenAddress is the address to which the mDNS server binds when using
	// IPv4. Note that the multicast group address is NOT used in order to control
	// more precisely which network interfaces join the multicast group.
	IPv4ListenAddress = &net.UDPAddr{IP: net.ParseIP("224.0.0.0"), Port: Port}
)
View Source
var (
	// IPv6Group is the multicast group used for mDNS over IPv6.
	//
	// See https://tools.ietf.org/html/rfc6762#section-3.
	IPv6Group = net.ParseIP("ff02::fb")

	// IPv6GroupAddress is the address to which mDNS queries are sent when using IPv6.
	//
	// See https://tools.ietf.org/html/rfc6762#section-3.
	IPv6GroupAddress = &net.UDPAddr{IP: IPv6Group, Port: Port}

	// IPv6ListenAddress is the address to which the mDNS server binds when using
	// IPv6. Note that the multicast group address is NOT used in order to control
	// more precisely which network interfaces join the multicast group.
	IPv6ListenAddress = &net.UDPAddr{IP: net.ParseIP("ff02::"), Port: Port}
)

Functions

func SendMulticastResponse

func SendMulticastResponse(in *InboundPacket, m *dns.Msg) (bool, error)

SendMulticastResponse sends a DNS message as a multicast response to an inbound packet.

func SendResponse

func SendResponse(in *InboundPacket, to *net.UDPAddr, m *dns.Msg) (bool, error)

SendResponse sends a DNS message as a response to an inbound packet.

func SendUnicastResponse

func SendUnicastResponse(in *InboundPacket, m *dns.Msg) (bool, error)

SendUnicastResponse sends a DNS message as a unicast response to an inbound packet.

Types

type Endpoint

type Endpoint struct {
	InterfaceIndex int
	Address        *net.UDPAddr
}

Endpoint is the origin or destination of a packet.

func (*Endpoint) IsLegacy

func (ep *Endpoint) IsLegacy() bool

IsLegacy returns true if this endpoint is a "legacy" endpoint.

A legacy endpoints is DNS querier that does not implement the full mDNS specification, and is expecting a "standard" unicast response.

See https://tools.ietf.org/html/rfc6762#section-6.7.

type IPv4Transport

type IPv4Transport struct {
	Logger twelf.Logger
	// contains filtered or unexported fields
}

IPv4Transport is an IPv4-based UDP transport.

func (*IPv4Transport) Close

func (t *IPv4Transport) Close() error

Close closes the transport, preventing further reads and writes.

func (*IPv4Transport) Group

func (t *IPv4Transport) Group() *net.UDPAddr

Group returns the multicast group address for this transport.

func (*IPv4Transport) Listen

func (t *IPv4Transport) Listen(iface *net.Interface) error

Listen starts listening for UDP packets on the given interfaces.

func (*IPv4Transport) Read

func (t *IPv4Transport) Read() (*InboundPacket, error)

Read reads the next packet from the transport.

func (*IPv4Transport) Write

func (t *IPv4Transport) Write(p *OutboundPacket) error

Write sends a packet via the transport.

type IPv6Transport

type IPv6Transport struct {
	Logger twelf.Logger
	// contains filtered or unexported fields
}

IPv6Transport is an IPv6-based UDP transport.

func (*IPv6Transport) Close

func (t *IPv6Transport) Close() error

Close closes the transport, preventing further reads and writes.

func (*IPv6Transport) Group

func (t *IPv6Transport) Group() *net.UDPAddr

Group returns the multicast group address for this transport.

func (*IPv6Transport) Listen

func (t *IPv6Transport) Listen(iface *net.Interface) error

Listen starts listening for UDP packets on the given interfaces.

func (*IPv6Transport) Read

func (t *IPv6Transport) Read() (*InboundPacket, error)

Read reads the next packet from the transport.

func (*IPv6Transport) Write

func (t *IPv6Transport) Write(p *OutboundPacket) error

Write sends a packet via the transport.

type InboundPacket

type InboundPacket struct {
	Transport Transport
	Source    Endpoint
	Data      []byte
}

InboundPacket is a UDP packet received from a transport.

func (*InboundPacket) Close

func (p *InboundPacket) Close()

Close returns the packet's data buffer to the pool.

func (*InboundPacket) Message

func (p *InboundPacket) Message() (*dns.Msg, error)

Message returns the DNS message contained in a packet.

type OutboundPacket

type OutboundPacket struct {
	Destination Endpoint
	Data        []byte
}

OutboundPacket is a UDP packet to be sent by a transport.

func NewOutboundPacket

func NewOutboundPacket(dest Endpoint, m *dns.Msg) (*OutboundPacket, error)

NewOutboundPacket marshals the message m into p.Data.

func (*OutboundPacket) Close

func (p *OutboundPacket) Close()

Close returns the packet's data buffer to the pool.

type Transport

type Transport interface {
	// Listen starts listening for UDP packets on the given interface.
	Listen(iface *net.Interface) error

	// Read reads the next packet from the transport.
	Read() (*InboundPacket, error)

	// Write sends a packet via the transport.
	Write(*OutboundPacket) error

	// Group returns the multicast group address for this transport.
	Group() *net.UDPAddr

	// Close closes the transport, preventing further reads and writes.
	Close() error
}

Transport is an interface for communicating via UDP.

Jump to

Keyboard shortcuts

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