Documentation ¶
Overview ¶
Package intf implements mechanisms to access underlying interfaces in a manner that is agnostic to the underlying implementation. An implementation is included that uses netlink to write to a Linux kernl implementation. Additional implementations can be provided to allow writing to e.g. a gRPCwire implementation.
Index ¶
- Constants
- func ARPSubscribe(updates chan ARPUpdate, done chan struct{}) error
- func AddIP(intf string, addr *net.IPNet) error
- func AwaitARP(ctx context.Context, addr net.IP) (net.HardwareAddr, error)
- func InterfaceState(name string, state IntState) error
- func OverrideAccessor(acc NetworkAccessor)
- func ValidInterface(name string) bool
- type ARPEntry
- type ARPEvent
- type ARPUpdate
- type IntState
- type Interface
- type NetworkAccessor
Constants ¶
const ( // RTM_NEWNEIGH is the event sent from netlink when an ARP entry is added. RTM_NEWNEIGH uint16 = 28 // RTM_DELNEIGH is the event sent from netlink when an ARP entry is removed. RTM_DELNEIGH uint16 = 29 )
Variables ¶
This section is empty.
Functions ¶
func ARPSubscribe ¶
ARPSubscribe subscribes to ARP updates from the underlying accessor.
func AwaitARP ¶
AwaitARP waits for the IPv4 address addr to be resolved via ARP. It uses the supplied context to determine whether it should continue awaiting the entry. If the ARP entry is resolved, it is returned directly.
func InterfaceState ¶
InterfaceState changes the administrative state of an interface on the local system.
func OverrideAccessor ¶
func OverrideAccessor(acc NetworkAccessor)
OverrideAccessor overrides the package network accessor to custom implementation.
func ValidInterface ¶
ValidInterface determines whether the interface name is valid for the current system.
Types ¶
type ARPEntry ¶
type ARPEntry struct { // IP is the IP address of the neighbour. IP net.IP // Interface is the name of the interface on which the ARP entry was learnt. Interface *Interface // MAC is the MAC address of the neighbour. MAC net.HardwareAddr }
ARPEntry is a representation of an ARP entry on the underlying system.
type ARPEvent ¶
type ARPEvent int64
ARPEvent is used to describe a particular event on the ARP table.
type ARPUpdate ¶
type ARPUpdate struct { // Type indicates whether the event was an add or delete. Type ARPEvent // Neigh is the neighbour that the change corresponds to. Neigh ARPEntry }
ARPUpdate is used to describe a change to the ARP table.
type IntState ¶
type IntState int64
IntState sets enumerated state values that an interface can use.
type Interface ¶
type Interface struct { // Index is an integer index used to refer to the interface. Index int // Name is the name used to refer to the interface in the system. Name string // MAC is the MAC address of the interface. MAC net.HardwareAddr // OperState is the operational status of the interface. OperState IntState // AdminState is the administrative state of the interface. AdminState IntState }
Interface represents information corresponding to a single interface on the underlying system.
func InterfaceByName ¶
InterfaceByName returns an interface's attributes by the name of the interface.
func Interfaces ¶
Interfaces returns a list of interfaces from the local system.
type NetworkAccessor ¶
type NetworkAccessor interface { // Interfaces returns a set of interfaces that are present on the local system. Interfaces() ([]*Interface, error) // Interface retrieves the interface with the specified name. Interface(name string) (*Interface, error) // InterfaceAdddresses lists the IP addresses configured on a particular interface. InterfaceAddresses(name string) ([]*net.IPNet, error) // AddInterfaceIP adds address ip to the interface name. AddInterfaceIP(name string, ip *net.IPNet) error // ARPList lists the set of ARP neighbours on the system. ARPList() ([]*ARPEntry, error) // ARPSubscribe writes changes to the ARP table to the channel updates, and uses // done to indicate that the subscription is complete. The ARPSubscribe function // should not be blocking and rather return once it has started a separate goroutine // that writes updates to the updates channel, and can be cancelled by sending a // message to the done channel. ARPSubscribe(updates chan ARPUpdate, done chan struct{}) error // InterfaceState manipulates the state of the interface specified by name. InterfaceState(name string, state IntState) error }
NetworkAccessor is an interface implemented by the underlying system access interface. Through implementing the NetworkAccessor interface it is possible to use the functions within this package whilst using a different underlying implementation (e.g., netlink on Linux to access the kernel).