ndp

package module
Version: v0.0.0-...-f982b87 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: MIT Imports: 14 Imported by: 5

README

ndp builds.sr.ht status GoDoc Go Report Card

Package ndp implements the Neighbor Discovery Protocol, as described in RFC 4861. MIT Licensed.

The command ndp is a utility for working with the Neighbor Discovery Protocol.

Install the package and utility using go get:

$ go get github.com/mdlayher/ndp/...

To learn more about NDP, and how to use this package, check out my blog: Network Protocol Breakdown: NDP and Go.

Examples

Listen for incoming NDP messages on interface eth0 to one of the interface's global unicast addresses.

$ sudo ndp -i eth0 -a global listen
$ sudo ndp -i eth0 -a 2001:db8::1 listen

Send router solicitations on interface eth0 from the interface's link-local address until a router advertisement is received.

$ sudo ndp -i eth0 -a linklocal rs

Send neighbor solicitations on interface eth0 to a neighbor's link-local address until a neighbor advertisement is received.

$ sudo ndp -i eth0 -a linklocal -t fe80::1 ns

An example of the tool sending a router solicitation and receiving a router advertisement on the WAN interface of a Ubiquiti router:

$ sudo ndp -i eth1 -a linklocal rs
ndp> interface: eth1, link-layer address: 04:18:d6:a1:ce:b8, IPv6 address: fe80::618:d6ff:fea1:ceb8
ndp rs> router solicitation:
    - source link-layer address: 04:18:d6:a1:ce:b8

ndp rs> router advertisement from: fe80::201:5cff:fe69:f246:
    - hop limit:        0
    - flags:            [MO]
    - preference:       0
    - router lifetime:  2h30m0s
    - reachable time:   1h0m0s
    - retransmit timer: 0s
    - options:
        - prefix information: 2600:6c4a:7002:100::/64, flags: [], valid: 720h0m0s, preferred: 168h0m0s

Documentation

Overview

Package ndp implements the Neighbor Discovery Protocol, as described in RFC 4861.

Index

Constants

View Source
const HopLimit = 255

HopLimit is the expected IPv6 hop limit for all NDP messages.

View Source
const Infinity = time.Duration(0xffffffff) * time.Second

Infinity indicates that a prefix is valid for an infinite amount of time, unless a new, finite, value is received in a subsequent router advertisement.

Variables

This section is empty.

Functions

func MarshalMessage

func MarshalMessage(m Message) ([]byte, error)

MarshalMessage marshals a Message into its binary form and prepends an ICMPv6 message with the correct type.

It is assumed that the operating system or caller will calculate and place the ICMPv6 checksum in the result.

func MarshalMessageChecksum

func MarshalMessageChecksum(m Message, source, destination net.IP) ([]byte, error)

MarshalMessageChecksum marshals a Message into its binary form and prepends an ICMPv6 message with the correct type.

The source and destination IP addresses are used to compute an IPv6 pseudo header for checksum calculation.

func SolicitedNodeMulticast

func SolicitedNodeMulticast(ip net.IP) (net.IP, error)

SolicitedNodeMulticast returns the solicited-node multicast address for an IPv6 address.

func TestConns

func TestConns(ifi *net.Interface) (*Conn, *Conn, net.IP, error)

TestConns sets up a pair of testing NDP peer Conns over UDP using the specified interface, and returns the address which can be used to send messages between them.

TestConns is useful for environments and tests which do not allow direct ICMPv6 communications.

Types

type Addr

type Addr string

An Addr is an IPv6 unicast address.

const (
	Unspecified Addr = "unspecified"
	LinkLocal   Addr = "linklocal"
	UniqueLocal Addr = "uniquelocal"
	Global      Addr = "global"
)

Possible Addr types for an IPv6 unicast address.

type CaptivePortal

type CaptivePortal string

A CaptivePortal is a Captive-Portal option, as described in RFC 8910, Section 2.3.

func NewCaptivePortal

func NewCaptivePortal(uri string) *CaptivePortal

NewCaptivePortal produces a CaptivePortal Option for the input URI string.

func (CaptivePortal) Code

func (CaptivePortal) Code() byte

Code implements Option.

type Conn

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

A Conn is a Neighbor Discovery Protocol connection.

func Listen

func Listen(ifi *net.Interface, addr Addr) (*Conn, net.IP, error)

Listen creates a NDP connection using the specified interface and address type.

As a special case, literal IPv6 addresses may be specified to bind to a specific address for an interface. If the IPv6 address does not exist on the interface, an error will be returned.

Listen returns a Conn and the chosen IPv6 address of the interface.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the Conn's underlying connection.

func (*Conn) JoinGroup

func (c *Conn) JoinGroup(group net.IP) error

JoinGroup joins the specified multicast group.

func (*Conn) LeaveGroup

func (c *Conn) LeaveGroup(group net.IP) error

LeaveGroup leaves the specified multicast group.

func (*Conn) ReadFrom

func (c *Conn) ReadFrom() (Message, *ipv6.ControlMessage, net.IP, error)

ReadFrom reads a Message from the Conn and returns its control message and source network address. Messages sourced from this machine and malformed or unrecognized ICMPv6 messages are filtered.

If more control and/or a more efficient low-level API are required, see ReadRaw.

func (*Conn) ReadRaw

func (c *Conn) ReadRaw(b []byte) (int, *ipv6.ControlMessage, net.IP, error)

ReadRaw reads ICMPv6 message bytes into b from the Conn and returns the number of bytes read, the control message, and the source network address.

Most callers should use ReadFrom instead, which parses bytes into Messages and also handles malformed and unrecognized ICMPv6 messages.

func (*Conn) SetControlMessage

func (c *Conn) SetControlMessage(cf ipv6.ControlFlags, on bool) error

SetControlMessage enables the reception of *ipv6.ControlMessages based on the specified flags.

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines for Conn. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.

func (*Conn) SetICMPFilter

func (c *Conn) SetICMPFilter(f *ipv6.ICMPFilter) error

SetICMPFilter applies the specified ICMP filter. This option can be used to ensure a Conn only accepts certain kinds of NDP messages.

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline sets a deadline for the next NDP message to arrive.

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets a deadline for the next NDP message to be written.

func (*Conn) WriteTo

func (c *Conn) WriteTo(m Message, cm *ipv6.ControlMessage, dst net.IP) error

WriteTo writes a Message to the Conn, with an optional control message and destination network address.

If cm is nil, a default control message will be sent.

type DNSSearchList

type DNSSearchList struct {
	Lifetime    time.Duration
	DomainNames []string
}

A DNSSearchList is a DNS search list option, as described in RFC 8106, Section 5.2.

func (*DNSSearchList) Code

func (*DNSSearchList) Code() byte

Code implements Option.

type Direction

type Direction int

A Direction specifies the direction of a LinkLayerAddress Option as a source or target.

const (
	Source Direction = optSourceLLA
	Target Direction = optTargetLLA
)

Possible Direction values.

type LinkLayerAddress

type LinkLayerAddress struct {
	Direction Direction
	Addr      net.HardwareAddr
}

A LinkLayerAddress is a Source or Target Link-Layer Address option, as described in RFC 4861, Section 4.6.1.

func (*LinkLayerAddress) Code

func (lla *LinkLayerAddress) Code() byte

Code implements Option.

type MTU

type MTU uint32

An MTU is an MTU option, as described in RFC 4861, Section 4.6.1.

func NewMTU

func NewMTU(mtu uint32) *MTU

NewMTU creates an MTU Option from an MTU value.

func (*MTU) Code

func (*MTU) Code() byte

Code implements Option.

type Message

type Message interface {
	// Type specifies the ICMPv6 type for a Message.
	Type() ipv6.ICMPType
	// contains filtered or unexported methods
}

A Message is a Neighbor Discovery Protocol message.

func ParseMessage

func ParseMessage(b []byte) (Message, error)

ParseMessage parses a Message from its binary form after determining its type from a leading ICMPv6 message.

type NeighborAdvertisement

type NeighborAdvertisement struct {
	Router        bool
	Solicited     bool
	Override      bool
	TargetAddress net.IP
	Options       []Option
}

A NeighborAdvertisement is a Neighbor Advertisement message as described in RFC 4861, Section 4.4.

func (*NeighborAdvertisement) Type

func (na *NeighborAdvertisement) Type() ipv6.ICMPType

Type implements Message.

type NeighborSolicitation

type NeighborSolicitation struct {
	TargetAddress net.IP
	Options       []Option
}

A NeighborSolicitation is a Neighbor Solicitation message as described in RFC 4861, Section 4.3.

func (*NeighborSolicitation) Type

func (ns *NeighborSolicitation) Type() ipv6.ICMPType

Type implements Message.

type Option

type Option interface {
	// Code specifies the NDP option code for an Option.
	Code() uint8
	// contains filtered or unexported methods
}

An Option is a Neighbor Discovery Protocol option.

type Preference

type Preference int

A Preference is a NDP router selection or route preference value as described in RFC 4191, Section 2.1.

const (
	Medium Preference = 0
	High   Preference = 1

	Low Preference = 3
)

Possible Preference values.

func (Preference) String

func (i Preference) String() string

type PrefixInformation

type PrefixInformation struct {
	PrefixLength                   uint8
	OnLink                         bool
	AutonomousAddressConfiguration bool
	ValidLifetime                  time.Duration
	PreferredLifetime              time.Duration
	Prefix                         net.IP
}

A PrefixInformation is a a Prefix Information option, as described in RFC 4861, Section 4.6.1.

func (*PrefixInformation) Code

func (*PrefixInformation) Code() byte

Code implements Option.

type RawOption

type RawOption struct {
	Type   uint8
	Length uint8
	Value  []byte
}

A RawOption is an Option in its raw and unprocessed format. Options which are not recognized by this package can be represented using a RawOption.

func (*RawOption) Code

func (r *RawOption) Code() byte

Code implements Option.

type RecursiveDNSServer

type RecursiveDNSServer struct {
	Lifetime time.Duration
	Servers  []net.IP
}

A RecursiveDNSServer is a Recursive DNS Server option, as described in RFC 8106, Section 5.1.

func (*RecursiveDNSServer) Code

func (*RecursiveDNSServer) Code() byte

Code implements Option.

type RouteInformation

type RouteInformation struct {
	PrefixLength  uint8
	Preference    Preference
	RouteLifetime time.Duration
	Prefix        net.IP
}

A RouteInformation is a Route Information option, as described in RFC 4191, Section 2.3.

func (*RouteInformation) Code

func (*RouteInformation) Code() byte

Code implements Option.

type RouterAdvertisement

type RouterAdvertisement struct {
	CurrentHopLimit           uint8
	ManagedConfiguration      bool
	OtherConfiguration        bool
	MobileIPv6HomeAgent       bool
	RouterSelectionPreference Preference
	NeighborDiscoveryProxy    bool
	RouterLifetime            time.Duration
	ReachableTime             time.Duration
	RetransmitTimer           time.Duration
	Options                   []Option
}

A RouterAdvertisement is a Router Advertisement message as described in RFC 4861, Section 4.1.

func (*RouterAdvertisement) Type

func (ra *RouterAdvertisement) Type() ipv6.ICMPType

Type implements Message.

type RouterSolicitation

type RouterSolicitation struct {
	Options []Option
}

A RouterSolicitation is a Router Solicitation message as described in RFC 4861, Section 4.1.

func (*RouterSolicitation) Type

func (rs *RouterSolicitation) Type() ipv6.ICMPType

Type implements Message.

Directories

Path Synopsis
cmd
ndp
Command ndp is a utility for working with the Neighbor Discovery Protocol.
Command ndp is a utility for working with the Neighbor Discovery Protocol.
internal
ndpcmd
Package ndpcmd provides the commands for the ndp utility.
Package ndpcmd provides the commands for the ndp utility.
ndptest
Package ndptest provides test functions and types for package ndp.
Package ndptest provides test functions and types for package ndp.

Jump to

Keyboard shortcuts

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