ethtool

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: Apache-2.0 Imports: 8 Imported by: 94

README

ethtool go package

Build Status GoDoc

The ethtool package aims to provide a library that provides easy access to the Linux SIOCETHTOOL ioctl operations. It can be used to retrieve information from a network device such as statistics, driver related information or even the peer of a VETH interface.

Installation

go get github.com/safchain/ethtool

How to use

package main

import (
	"fmt"

	"github.com/safchain/ethtool"
)

func main() {
	ethHandle, err := ethtool.NewEthtool()
	if err != nil {
		panic(err.Error())
	}
	defer ethHandle.Close()

	// Retrieve tx from eth0
	stats, err := ethHandle.Stats("eth0")
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("TX: %d\n", stats["tx_bytes"])

	// Retrieve peer index of a veth interface
	stats, err = ethHandle.Stats("veth0")
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("Peer Index: %d\n", stats["peer_ifindex"])
}

LICENSE

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Overview

The ethtool package aims to provide a library that provides easy access to the Linux SIOCETHTOOL ioctl operations. It can be used to retrieve information from a network device such as statistics, driver related information or even the peer of a VETH interface.

Package ethtool aims to provide a library giving a simple access to the Linux SIOCETHTOOL ioctl operations. It can be used to retrieve informations from a network device like statistics, driver related informations or even the peer of a VETH interface.

Package ethtool aims to provide a library giving a simple access to the Linux SIOCETHTOOL ioctl operations. It can be used to retrieve informations from a network device like statistics, driver related informations or even the peer of a VETH interface.

Index

Constants

View Source
const (
	ETH_GSTRING_LEN = 32
	ETH_SS_STATS    = 1
	ETH_SS_FEATURES = 4

	// CMD supported
	ETHTOOL_GDRVINFO = 0x00000003 /* Get driver info. */
	ETHTOOL_GSTRINGS = 0x0000001b /* get specified string set */
	ETHTOOL_GSTATS   = 0x0000001d /* get NIC-specific statistics */
	// other CMDs from ethtool-copy.h of ethtool-3.5 package
	ETHTOOL_GSET      = 0x00000001 /* Get settings. */
	ETHTOOL_SSET      = 0x00000002 /* Set settings. */
	ETHTOOL_GMSGLVL   = 0x00000007 /* Get driver message level */
	ETHTOOL_SMSGLVL   = 0x00000008 /* Set driver msg level. */
	ETHTOOL_GCHANNELS = 0x0000003c /* Get no of channels */
	ETHTOOL_SCHANNELS = 0x0000003d /* Set no of channels */
	ETHTOOL_GCOALESCE = 0x0000000e /* Get coalesce config */
	/* Get link status for host, i.e. whether the interface *and* the
	 * physical port (if there is one) are up (ethtool_value). */
	ETHTOOL_GLINK         = 0x0000000a
	ETHTOOL_GMODULEINFO   = 0x00000042 /* Get plug-in module information */
	ETHTOOL_GMODULEEEPROM = 0x00000043 /* Get plug-in module eeprom */
	ETHTOOL_GPERMADDR     = 0x00000020 /* Get permanent hardware address */
	ETHTOOL_GFEATURES     = 0x0000003a /* Get device offload settings */
	ETHTOOL_SFEATURES     = 0x0000003b /* Change device offload settings */
	ETHTOOL_GFLAGS        = 0x00000025 /* Get flags bitmap(ethtool_value) */
	ETHTOOL_GSSET_INFO    = 0x00000037 /* Get string set info */
	ETHTOOL_GET_TS_INFO   = 0x00000041 /* Get time stamping and PHC info */
)

ethtool stats related constants.

View Source
const (
	MAX_GSTRINGS       = 32768
	MAX_FEATURE_BLOCKS = (MAX_GSTRINGS + 32 - 1) / 32
	EEPROM_LEN         = 640
	PERMADDR_LEN       = 32
)

MAX_GSTRINGS maximum number of stats entries that ethtool can retrieve currently.

View Source
const (
	SOF_TIMESTAMPING_TX_HARDWARE  = (1 << 0)
	SOF_TIMESTAMPING_TX_SOFTWARE  = (1 << 1)
	SOF_TIMESTAMPING_RX_HARDWARE  = (1 << 2)
	SOF_TIMESTAMPING_RX_SOFTWARE  = (1 << 3)
	SOF_TIMESTAMPING_SOFTWARE     = (1 << 4)
	SOF_TIMESTAMPING_SYS_HARDWARE = (1 << 5)
	SOF_TIMESTAMPING_RAW_HARDWARE = (1 << 6)
	SOF_TIMESTAMPING_OPT_ID       = (1 << 7)
	SOF_TIMESTAMPING_TX_SCHED     = (1 << 8)
	SOF_TIMESTAMPING_TX_ACK       = (1 << 9)
	SOF_TIMESTAMPING_OPT_CMSG     = (1 << 10)
	SOF_TIMESTAMPING_OPT_TSONLY   = (1 << 11)
	SOF_TIMESTAMPING_OPT_STATS    = (1 << 12)
	SOF_TIMESTAMPING_OPT_PKTINFO  = (1 << 13)
	SOF_TIMESTAMPING_OPT_TX_SWHW  = (1 << 14)
	SOF_TIMESTAMPING_BIND_PHC     = (1 << 15)
)
View Source
const (
	/*
	 * No outgoing packet will need hardware time stamping;
	 * should a packet arrive which asks for it, no hardware
	 * time stamping will be done.
	 */
	HWTSTAMP_TX_OFF = iota

	/*
	 * Enables hardware time stamping for outgoing packets;
	 * the sender of the packet decides which are to be
	 * time stamped by setting %SOF_TIMESTAMPING_TX_SOFTWARE
	 * before sending the packet.
	 */
	HWTSTAMP_TX_ON

	/*
	 * Enables time stamping for outgoing packets just as
	 * HWTSTAMP_TX_ON does, but also enables time stamp insertion
	 * directly into Sync packets. In this case, transmitted Sync
	 * packets will not received a time stamp via the socket error
	 * queue.
	 */
	HWTSTAMP_TX_ONESTEP_SYNC

	/*
	 * Same as HWTSTAMP_TX_ONESTEP_SYNC, but also enables time
	 * stamp insertion directly into PDelay_Resp packets. In this
	 * case, neither transmitted Sync nor PDelay_Resp packets will
	 * receive a time stamp via the socket error queue.
	 */
	HWTSTAMP_TX_ONESTEP_P2P
)
View Source
const (
	HWTSTAMP_FILTER_NONE                = iota /* time stamp no incoming packet at all */
	HWTSTAMP_FILTER_ALL                        /* time stamp any incoming packet */
	HWTSTAMP_FILTER_SOME                       /* return value: time stamp all packets requested plus some others */
	HWTSTAMP_FILTER_PTP_V1_L4_EVENT            /* PTP v1, UDP, any kind of event packet */
	HWTSTAMP_FILTER_PTP_V1_L4_SYNC             /* PTP v1, UDP, Sync packet */
	HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ        /* PTP v1, UDP, Delay_req packet */
	HWTSTAMP_FILTER_PTP_V2_L4_EVENT            /* PTP v2, UDP, any kind of event packet */
	HWTSTAMP_FILTER_PTP_V2_L4_SYNC             /* PTP v2, UDP, Sync packet */
	HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ        /* PTP v2, UDP, Delay_req packet */
	HWTSTAMP_FILTER_PTP_V2_L2_EVENT            /* 802.AS1, Ethernet, any kind of event packet */
	HWTSTAMP_FILTER_PTP_V2_L2_SYNC             /* 802.AS1, Ethernet, Sync packet */
	HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ        /* 802.AS1, Ethernet, Delay_req packet */
	HWTSTAMP_FILTER_PTP_V2_EVENT               /* PTP v2/802.AS1, any layer, any kind of event packet */
	HWTSTAMP_FILTER_PTP_V2_SYNC                /* PTP v2/802.AS1, any layer, Sync packet */
	HWTSTAMP_FILTER_PTP_V2_DELAY_REQ           /* PTP v2/802.AS1, any layer, Delay_req packet */
	HWTSTAMP_FILTER_NTP_ALL                    /* NTP, UDP, all versions and packet modes */
)
View Source
const (
	IFNAMSIZ = 16
)

Maximum size of an interface name

View Source
const (
	SIOCETHTOOL = 0x8946
)

ioctl ethtool request

Variables

This section is empty.

Functions

func BusInfo

func BusInfo(intf string) (string, error)

BusInfo returns bus information of the given interface name.

func CmdGetMapped

func CmdGetMapped(intf string) (map[string]uint64, error)

func DriverName

func DriverName(intf string) (string, error)

DriverName returns the driver name of the given interface name.

func MsglvlGet

func MsglvlGet(intf string) (uint32, error)

MsglvlGet returns the msglvl of the given interface.

func MsglvlSet

func MsglvlSet(intf string, valset uint32) (uint32, uint32, error)

MsglvlSet returns the read-msglvl, post-set-msglvl of the given interface.

func PermAddr

func PermAddr(intf string) (string, error)

PermAddr returns permanent address of the given interface name.

func Stats

func Stats(intf string) (map[string]uint64, error)

Stats retrieves stats of the given interface name.

Types

type Channels

type Channels struct {
	Cmd           uint32
	MaxRx         uint32
	MaxTx         uint32
	MaxOther      uint32
	MaxCombined   uint32
	RxCount       uint32
	TxCount       uint32
	OtherCount    uint32
	CombinedCount uint32
}

Channels contains the number of channels for a given interface.

type Coalesce

type Coalesce struct {
	Cmd                      uint32
	RxCoalesceUsecs          uint32
	RxMaxCoalescedFrames     uint32
	RxCoalesceUsecsIrq       uint32
	RxMaxCoalescedFramesIrq  uint32
	TxCoalesceUsecs          uint32
	TxMaxCoalescedFrames     uint32
	TxCoalesceUsecsIrq       uint32
	TxMaxCoalescedFramesIrq  uint32
	StatsBlockCoalesceUsecs  uint32
	UseAdaptiveRxCoalesce    uint32
	UseAdaptiveTxCoalesce    uint32
	PktRateLow               uint32
	RxCoalesceUsecsLow       uint32
	RxMaxCoalescedFramesLow  uint32
	TxCoalesceUsecsLow       uint32
	TxMaxCoalescedFramesLow  uint32
	PktRateHigh              uint32
	RxCoalesceUsecsHigh      uint32
	RxMaxCoalescedFramesHigh uint32
	TxCoalesceUsecsHigh      uint32
	TxMaxCoalescedFramesHigh uint32
	RateSampleInterval       uint32
}

Coalesce is a coalesce config for an interface

type DrvInfo

type DrvInfo struct {
	Cmd         uint32
	Driver      string
	Version     string
	FwVersion   string
	BusInfo     string
	EromVersion string
	Reserved2   string
	NPrivFlags  uint32
	NStats      uint32
	TestInfoLen uint32
	EedumpLen   uint32
	RegdumpLen  uint32
}

DrvInfo contains driver information ethtool.h v3.5: struct ethtool_drvinfo

type Ethtool

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

func NewEthtool

func NewEthtool() (*Ethtool, error)

NewEthtool returns a new ethtool handler

func (*Ethtool) BusInfo

func (e *Ethtool) BusInfo(intf string) (string, error)

BusInfo returns the bus information of the given interface name.

func (*Ethtool) Change

func (e *Ethtool) Change(intf string, config map[string]bool) error

Change requests a change in the given device's features.

func (*Ethtool) Close

func (e *Ethtool) Close()

Close closes the ethool handler

func (*Ethtool) CmdGet

func (e *Ethtool) CmdGet(ecmd *EthtoolCmd, intf string) (uint32, error)

CmdGet returns the interface settings in the receiver struct and returns speed

func (*Ethtool) CmdGetMapped

func (e *Ethtool) CmdGetMapped(intf string) (map[string]uint64, error)

CmdGetMapped returns the interface settings in a map

func (*Ethtool) CmdSet

func (e *Ethtool) CmdSet(ecmd *EthtoolCmd, intf string) (uint32, error)

CmdSet sets and returns the settings in the receiver struct and returns speed

func (*Ethtool) DriverInfo

func (e *Ethtool) DriverInfo(intf string) (DrvInfo, error)

DriverInfo returns driver information of the given interface name.

func (*Ethtool) DriverName

func (e *Ethtool) DriverName(intf string) (string, error)

DriverName returns the driver name of the given interface name.

func (*Ethtool) FeatureNames

func (e *Ethtool) FeatureNames(intf string) (map[string]uint, error)

FeatureNames shows supported features by their name.

func (*Ethtool) Features

func (e *Ethtool) Features(intf string) (map[string]bool, error)

Features retrieves features of the given interface name.

func (*Ethtool) GetChannels

func (e *Ethtool) GetChannels(intf string) (Channels, error)

GetChannels returns the number of channels for the given interface name.

func (*Ethtool) GetCoalesce

func (e *Ethtool) GetCoalesce(intf string) (Coalesce, error)

GetCoalesce returns the coalesce config for the given interface name.

func (*Ethtool) GetTimestampingInformation added in v0.3.0

func (e *Ethtool) GetTimestampingInformation(intf string) (TimestampingInformation, error)

GetTimestampingInformation returns the PTP timestamping information for the given interface name.

func (*Ethtool) LinkState

func (e *Ethtool) LinkState(intf string) (uint32, error)

Get state of a link.

func (*Ethtool) ModuleEeprom

func (e *Ethtool) ModuleEeprom(intf string) ([]byte, error)

ModuleEeprom returns Eeprom information of the given interface name.

func (*Ethtool) ModuleEepromHex

func (e *Ethtool) ModuleEepromHex(intf string) (string, error)

ModuleEeprom returns Eeprom information of the given interface name.

func (*Ethtool) MsglvlGet

func (e *Ethtool) MsglvlGet(intf string) (uint32, error)

MsglvlGet returns the msglvl of the given interface.

func (*Ethtool) MsglvlSet

func (e *Ethtool) MsglvlSet(intf string, valset uint32) (uint32, uint32, error)

MsglvlSet returns the read-msglvl, post-set-msglvl of the given interface.

func (*Ethtool) PermAddr

func (e *Ethtool) PermAddr(intf string) (string, error)

PermAddr returns permanent address of the given interface name.

func (*Ethtool) SetChannels

func (e *Ethtool) SetChannels(intf string, channels Channels) (Channels, error)

SetChannels sets the number of channels for the given interface name and returns the new number of channels.

func (*Ethtool) Stats

func (e *Ethtool) Stats(intf string) (map[string]uint64, error)

Stats retrieves stats of the given interface name.

type EthtoolCmd

type EthtoolCmd struct {
	Cmd            uint32
	Supported      uint32
	Advertising    uint32
	Speed          uint16
	Duplex         uint8
	Port           uint8
	Phy_address    uint8
	Transceiver    uint8
	Autoneg        uint8
	Mdio_support   uint8
	Maxtxpkt       uint32
	Maxrxpkt       uint32
	Speed_hi       uint16
	Eth_tp_mdix    uint8
	Reserved2      uint8
	Lp_advertising uint32
	Reserved       [2]uint32
}

func (*EthtoolCmd) CmdGet

func (ecmd *EthtoolCmd) CmdGet(intf string) (uint32, error)

CmdGet returns the interface settings in the receiver struct and returns speed

func (*EthtoolCmd) CmdSet

func (ecmd *EthtoolCmd) CmdSet(intf string) (uint32, error)

CmdSet sets and returns the settings in the receiver struct and returns speed

type TimestampingInformation added in v0.3.0

type TimestampingInformation struct {
	Cmd            uint32
	SoTimestamping uint32 /* SOF_TIMESTAMPING_* bitmask */
	PhcIndex       int32
	TxTypes        uint32 /* HWTSTAMP_TX_* */

	RxFilters uint32 /* HWTSTAMP_FILTER_ */
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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