![dependabot[bot]](/assets/img/avatar_default.png)
Bumps the golang group with 6 updates in the / directory: | Package | From | To | | --- | --- | --- | | [github.com/Microsoft/hcsshim](https://github.com/Microsoft/hcsshim) | `0.12.7` | `0.12.9` | | [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) | `2.20.2` | `2.22.0` | | [github.com/onsi/gomega](https://github.com/onsi/gomega) | `1.34.2` | `1.36.0` | | [github.com/opencontainers/selinux](https://github.com/opencontainers/selinux) | `1.11.0` | `1.11.1` | | [github.com/safchain/ethtool](https://github.com/safchain/ethtool) | `0.4.1` | `0.5.9` | | [sigs.k8s.io/knftables](https://github.com/kubernetes-sigs/knftables) | `0.0.17` | `0.0.18` | Updates `github.com/Microsoft/hcsshim` from 0.12.7 to 0.12.9 - [Release notes](https://github.com/Microsoft/hcsshim/releases) - [Commits](https://github.com/Microsoft/hcsshim/compare/v0.12.7...v0.12.9) Updates `github.com/onsi/ginkgo/v2` from 2.20.2 to 2.22.0 - [Release notes](https://github.com/onsi/ginkgo/releases) - [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/ginkgo/compare/v2.20.2...v2.22.0) Updates `github.com/onsi/gomega` from 1.34.2 to 1.36.0 - [Release notes](https://github.com/onsi/gomega/releases) - [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/gomega/compare/v1.34.2...v1.36.0) Updates `github.com/opencontainers/selinux` from 1.11.0 to 1.11.1 - [Release notes](https://github.com/opencontainers/selinux/releases) - [Commits](https://github.com/opencontainers/selinux/compare/v1.11.0...v1.11.1) Updates `github.com/safchain/ethtool` from 0.4.1 to 0.5.9 - [Release notes](https://github.com/safchain/ethtool/releases) - [Commits](https://github.com/safchain/ethtool/compare/v0.4.1...v0.5.9) Updates `golang.org/x/sys` from 0.26.0 to 0.27.0 - [Commits](https://github.com/golang/sys/compare/v0.26.0...v0.27.0) Updates `sigs.k8s.io/knftables` from 0.0.17 to 0.0.18 - [Changelog](https://github.com/kubernetes-sigs/knftables/blob/master/CHANGELOG.md) - [Commits](https://github.com/kubernetes-sigs/knftables/compare/v0.0.17...v0.0.18) --- updated-dependencies: - dependency-name: github.com/Microsoft/hcsshim dependency-type: direct:production update-type: version-update:semver-patch dependency-group: golang - dependency-name: github.com/onsi/ginkgo/v2 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang - dependency-name: github.com/onsi/gomega dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang - dependency-name: github.com/opencontainers/selinux dependency-type: direct:production update-type: version-update:semver-patch dependency-group: golang - dependency-name: github.com/safchain/ethtool dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang - dependency-name: golang.org/x/sys dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang - dependency-name: sigs.k8s.io/knftables dependency-type: direct:production update-type: version-update:semver-patch dependency-group: golang ... Signed-off-by: dependabot[bot] <support@github.com>
208 lines
5.1 KiB
Go
208 lines
5.1 KiB
Go
/*
|
|
*
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
* or more contributor license agreements. See the NOTICE file
|
|
* distributed with this work for additional information
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
* to you 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.
|
|
*
|
|
*/
|
|
|
|
// 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
|
|
|
|
import (
|
|
"math"
|
|
"reflect"
|
|
"unsafe"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// EthtoolCmd is the Go version of the Linux kerne ethtool_cmd struct
|
|
// see ethtool.c
|
|
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
|
|
}
|
|
|
|
// CmdGet returns the interface settings in the receiver struct
|
|
// and returns speed
|
|
func (ecmd *EthtoolCmd) CmdGet(intf string) (uint32, error) {
|
|
e, err := NewEthtool()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
defer e.Close()
|
|
return e.CmdGet(ecmd, intf)
|
|
}
|
|
|
|
// CmdSet sets and returns the settings in the receiver struct
|
|
// and returns speed
|
|
func (ecmd *EthtoolCmd) CmdSet(intf string) (uint32, error) {
|
|
e, err := NewEthtool()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
defer e.Close()
|
|
return e.CmdSet(ecmd, intf)
|
|
}
|
|
|
|
func (f *EthtoolCmd) reflect(retv *map[string]uint64) {
|
|
val := reflect.ValueOf(f).Elem()
|
|
|
|
for i := 0; i < val.NumField(); i++ {
|
|
valueField := val.Field(i)
|
|
typeField := val.Type().Field(i)
|
|
|
|
t := valueField.Interface()
|
|
// tt := reflect.TypeOf(t)
|
|
// fmt.Printf(" t %T %v tt %T %v\n", t, t, tt, tt)
|
|
switch tt := t.(type) {
|
|
case uint32:
|
|
// fmt.Printf(" t is uint32\n")
|
|
(*retv)[typeField.Name] = uint64(tt)
|
|
case uint16:
|
|
(*retv)[typeField.Name] = uint64(tt)
|
|
case uint8:
|
|
(*retv)[typeField.Name] = uint64(tt)
|
|
case int32:
|
|
(*retv)[typeField.Name] = uint64(tt)
|
|
case int16:
|
|
(*retv)[typeField.Name] = uint64(tt)
|
|
case int8:
|
|
(*retv)[typeField.Name] = uint64(tt)
|
|
default:
|
|
(*retv)[typeField.Name+"_unknown_type"] = 0
|
|
}
|
|
}
|
|
}
|
|
|
|
// CmdGet returns the interface settings in the receiver struct
|
|
// and returns speed
|
|
func (e *Ethtool) CmdGet(ecmd *EthtoolCmd, intf string) (uint32, error) {
|
|
ecmd.Cmd = ETHTOOL_GSET
|
|
|
|
var name [IFNAMSIZ]byte
|
|
copy(name[:], []byte(intf))
|
|
|
|
ifr := ifreq{
|
|
ifr_name: name,
|
|
ifr_data: uintptr(unsafe.Pointer(ecmd)),
|
|
}
|
|
|
|
_, _, ep := unix.Syscall(unix.SYS_IOCTL, uintptr(e.fd),
|
|
SIOCETHTOOL, uintptr(unsafe.Pointer(&ifr)))
|
|
if ep != 0 {
|
|
return 0, ep
|
|
}
|
|
|
|
var speedval uint32 = (uint32(ecmd.Speed_hi) << 16) |
|
|
(uint32(ecmd.Speed) & 0xffff)
|
|
if speedval == math.MaxUint16 {
|
|
speedval = math.MaxUint32
|
|
}
|
|
|
|
return speedval, nil
|
|
}
|
|
|
|
// CmdSet sets and returns the settings in the receiver struct
|
|
// and returns speed
|
|
func (e *Ethtool) CmdSet(ecmd *EthtoolCmd, intf string) (uint32, error) {
|
|
ecmd.Cmd = ETHTOOL_SSET
|
|
|
|
var name [IFNAMSIZ]byte
|
|
copy(name[:], []byte(intf))
|
|
|
|
ifr := ifreq{
|
|
ifr_name: name,
|
|
ifr_data: uintptr(unsafe.Pointer(ecmd)),
|
|
}
|
|
|
|
_, _, ep := unix.Syscall(unix.SYS_IOCTL, uintptr(e.fd),
|
|
SIOCETHTOOL, uintptr(unsafe.Pointer(&ifr)))
|
|
if ep != 0 {
|
|
return 0, unix.Errno(ep)
|
|
}
|
|
|
|
var speedval uint32 = (uint32(ecmd.Speed_hi) << 16) |
|
|
(uint32(ecmd.Speed) & 0xffff)
|
|
if speedval == math.MaxUint16 {
|
|
speedval = math.MaxUint32
|
|
}
|
|
|
|
return speedval, nil
|
|
}
|
|
|
|
// CmdGetMapped returns the interface settings in a map
|
|
func (e *Ethtool) CmdGetMapped(intf string) (map[string]uint64, error) {
|
|
ecmd := EthtoolCmd{
|
|
Cmd: ETHTOOL_GSET,
|
|
}
|
|
|
|
var name [IFNAMSIZ]byte
|
|
copy(name[:], []byte(intf))
|
|
|
|
ifr := ifreq{
|
|
ifr_name: name,
|
|
ifr_data: uintptr(unsafe.Pointer(&ecmd)),
|
|
}
|
|
|
|
_, _, ep := unix.Syscall(unix.SYS_IOCTL, uintptr(e.fd),
|
|
SIOCETHTOOL, uintptr(unsafe.Pointer(&ifr)))
|
|
if ep != 0 {
|
|
return nil, ep
|
|
}
|
|
|
|
result := make(map[string]uint64)
|
|
|
|
// ref https://gist.github.com/drewolson/4771479
|
|
// Golang Reflection Example
|
|
ecmd.reflect(&result)
|
|
|
|
var speedval uint32 = (uint32(ecmd.Speed_hi) << 16) |
|
|
(uint32(ecmd.Speed) & 0xffff)
|
|
result["speed"] = uint64(speedval)
|
|
|
|
return result, nil
|
|
}
|
|
|
|
// CmdGetMapped returns the interface settings in a map
|
|
func CmdGetMapped(intf string) (map[string]uint64, error) {
|
|
e, err := NewEthtool()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer e.Close()
|
|
return e.CmdGetMapped(intf)
|
|
}
|