netdevs

package
v0.0.0-...-ba09d25 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: Apache-2.0, MIT Imports: 7 Imported by: 0

Documentation

Overview

Package netdevs contains utilities for working with network devices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MACToIP

func MACToIP(mac net.HardwareAddr) net.IP

MACToIP converts the MAC address to an IPv6 link local address as described in RFC 4291 page 20: https://tools.ietf.org/html/rfc4291#page-20

func ParseDevices

func ParseDevices(cmdOutput string) (map[string]DeviceInfo, error)

ParseDevices parses the output from `ip addr show` into a map from device name to information about the device.

Note: if multiple IPv6 addresses are assigned to a device, the last address displayed by `ip addr show` will be used. This is fine for packetimpact because we will always only have at most one IPv6 address assigned to each device.

func ParseDevicesWithRegex

func ParseDevicesWithRegex(cmdOutput string, deviceLine, linkLine, inetLine, inet6Line *regexp.Regexp) (map[string]DeviceInfo, error)

ParseDevicesWithRegex will parse the output with the given regexps to produce a map from device name to device information. It is assumed that deviceLine contains both a name and an ID.

Types

type DeviceInfo

type DeviceInfo struct {
	ID       uint32
	MAC      net.HardwareAddr
	IPv4Addr net.IP
	IPv4Net  *net.IPNet
	IPv6Addr net.IP
	IPv6Net  *net.IPNet
}

A DeviceInfo represents a network device.

func FindDeviceByIP

func FindDeviceByIP(ip net.IP, devices map[string]DeviceInfo) (string, DeviceInfo, error)

FindDeviceByIP finds a DeviceInfo and device name from an IP address in the output of ParseDevices.

Directories

Path Synopsis
Package netlink has routines to get interfaces information through netlink.
Package netlink has routines to get interfaces information through netlink.

Jump to

Keyboard shortcuts

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