Skip to content

Commit

Permalink
Merge pull request #90 from safchain/safchain/improve-doc
Browse files Browse the repository at this point in the history
doc fixes and linter CI job
  • Loading branch information
safchain authored Nov 17, 2024
2 parents 17a8e4c + db772ae commit 4e3aff4
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 29 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: golangci-lint
on:
push:
branches:
- main
- master
pull_request:

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
10 changes: 7 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
linters:
disable:
- gosimple
- unused
enable:
- gosimple
- gci
- gofmt
- misspell
- goimports
- staticcheck
- errcheck
- govet
- misspell
- gocritic
linters-settings:
gci:
sections:
Expand Down
45 changes: 25 additions & 20 deletions ethtool.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ const (
ETHTOOL_GMSGLVL = 0x00000007 /* Get driver message level */
ETHTOOL_SMSGLVL = 0x00000008 /* Set driver msg level. */

/* Get link status for host, i.e. whether the interface *and* the
* physical port (if there is one) are up (ethtool_value). */
// 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_GCOALESCE = 0x0000000e /* Get coalesce config */
ETHTOOL_SCOALESCE = 0x0000000f /* Set coalesce config */
Expand Down Expand Up @@ -239,23 +239,25 @@ type WakeOnLan struct {
Opts uint32 // Bitmask of WAKE_* flags for enabled WoL modes
}

// Timestamping options
// see: https://www.kernel.org/doc/Documentation/networking/timestamping.txt
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)
SOF_TIMESTAMPING_TX_HARDWARE = (1 << 0) /* Request tx timestamps generated by the network adapter. */
SOF_TIMESTAMPING_TX_SOFTWARE = (1 << 1) /* Request tx timestamps when data leaves the kernel. */
SOF_TIMESTAMPING_RX_HARDWARE = (1 << 2) /* Request rx timestamps generated by the network adapter. */
SOF_TIMESTAMPING_RX_SOFTWARE = (1 << 3) /* Request rx timestamps when data enters the kernel. */
SOF_TIMESTAMPING_SOFTWARE = (1 << 4) /* Report any software timestamps when available. */
SOF_TIMESTAMPING_SYS_HARDWARE = (1 << 5) /* This option is deprecated and ignored. */
SOF_TIMESTAMPING_RAW_HARDWARE = (1 << 6) /* Report hardware timestamps. */
SOF_TIMESTAMPING_OPT_ID = (1 << 7) /* Generate a unique identifier along with each packet. */
SOF_TIMESTAMPING_TX_SCHED = (1 << 8) /* Request tx timestamps prior to entering the packet scheduler. */
SOF_TIMESTAMPING_TX_ACK = (1 << 9) /* Request tx timestamps when all data in the send buffer has been acknowledged. */
SOF_TIMESTAMPING_OPT_CMSG = (1 << 10) /* Support recv() cmsg for all timestamped packets. */
SOF_TIMESTAMPING_OPT_TSONLY = (1 << 11) /* Applies to transmit timestamps only. */
SOF_TIMESTAMPING_OPT_STATS = (1 << 12) /* Optional stats that are obtained along with the transmit timestamps. */
SOF_TIMESTAMPING_OPT_PKTINFO = (1 << 13) /* Enable the SCM_TIMESTAMPING_PKTINFO control message for incoming packets with hardware timestamps. */
SOF_TIMESTAMPING_OPT_TX_SWHW = (1 << 14) /* Request both hardware and software timestamps for outgoing packets when SOF_TIMESTAMPING_TX_HARDWARE and SOF_TIMESTAMPING_TX_SOFTWARE are enabled at the same time. */
SOF_TIMESTAMPING_BIND_PHC = (1 << 15) /* Bind the socket to a specific PTP Hardware Clock. */
)

const (
Expand Down Expand Up @@ -311,6 +313,7 @@ const (
HWTSTAMP_FILTER_NTP_ALL /* NTP, UDP, all versions and packet modes */
)

// TimestampingInformation contains PTP timetstapming information
type TimestampingInformation struct {
Cmd uint32
SoTimestamping uint32 /* SOF_TIMESTAMPING_* bitmask */
Expand Down Expand Up @@ -381,6 +384,7 @@ type Pause struct {
TxPause uint32
}

// Ethtool is a struct that contains the file descriptor for the ethtool
type Ethtool struct {
fd int
}
Expand All @@ -389,7 +393,7 @@ type Ethtool struct {
func goString(s []byte) string {
strEnd := bytes.IndexByte(s, 0)
if strEnd == -1 {
return string(s[:])
return string(s)
}
return string(s[:strEnd])
}
Expand Down Expand Up @@ -729,6 +733,7 @@ func isFeatureBitSet(blocks [MAX_FEATURE_BLOCKS]ethtoolGetFeaturesBlock, index u
return (blocks)[index/32].active&(1<<(index%32)) != 0
}

// FeatureState contains the state of a feature.
type FeatureState struct {
Available bool
Requested bool
Expand Down Expand Up @@ -950,7 +955,7 @@ func (e *Ethtool) UpdatePrivFlags(intf string, config map[string]bool) error {
return e.ioctl(intf, uintptr(unsafe.Pointer(&update)))
}

// Get state of a link.
// LinkState get the state of a link.
func (e *Ethtool) LinkState(intf string) (uint32, error) {
x := ethtoolLink{
cmd: ETHTOOL_GLINK,
Expand Down
9 changes: 4 additions & 5 deletions ethtool_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ import (
"golang.org/x/sys/unix"
)

type EthtoolCmd struct { /* ethtool.c: struct ethtool_cmd */
// EthtoolCmd is the Go version of the Linux kerne ethtool_cmd struct
// see ethtool.c
type EthtoolCmd struct {
Cmd uint32
Supported uint32
Advertising uint32
Expand Down Expand Up @@ -102,10 +104,6 @@ func (f *EthtoolCmd) reflect(retv *map[string]uint64) {
default:
(*retv)[typeField.Name+"_unknown_type"] = 0
}

// tag := typeField.Tag
// fmt.Printf("Field Name: %s,\t Field Value: %v,\t Tag Value: %s\n",
// typeField.Name, valueField.Interface(), tag.Get("tag_name"))
}
}

Expand Down Expand Up @@ -198,6 +196,7 @@ func (e *Ethtool) CmdGetMapped(intf string) (map[string]uint64, error) {
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 {
Expand Down
2 changes: 1 addition & 1 deletion ethtool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestGoString(t *testing.T) {
}

for want, s := range testcases {
got := goString(s[:])
got := goString(s)
if got != want {
t.Errorf("String conversion failed, got: %s, want: %s.", got, want)
}
Expand Down

0 comments on commit 4e3aff4

Please sign in to comment.