Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup golangci-lint job #859

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ on:

jobs:

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.17

- uses: golangci/golangci-lint-action@v3
with:
args: --print-resources-usage --verbose

build:
runs-on: ubuntu-latest
steps:
Expand Down
33 changes: 33 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
issues:
exclude-rules:
- linters:
- revive
text: var-naming
max-issues-per-linter: 0
max-same-issues: 0

linters:
enable:
- gci
- gofumpt
- gosimple
- govet
- ineffassign
- nilerr
- revive
- staticcheck
- unconvert
- whitespace
disable:
- errcheck
- unused

linters-settings:
gci:
sections:
- standard
- default
- prefix(github.com/vishvananda)

run:
timeout: 5m
17 changes: 10 additions & 7 deletions addr_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"strings"
"syscall"

"golang.org/x/sys/unix"

"github.com/vishvananda/netlink/nl"
"github.com/vishvananda/netns"
"golang.org/x/sys/unix"
)

// AddrAdd will add an IP address to a link device.
Expand Down Expand Up @@ -153,7 +154,7 @@ func (h *Handle) addrHandle(link Link, addr *Addr, req *nl.NetlinkRequest) error
// value should be "forever". To compensate for that, only add the attributes if at least one of the values is
// non-zero, which means the caller has explicitly set them
if addr.ValidLft > 0 || addr.PreferedLft > 0 {
cachedata := nl.IfaCacheInfo{unix.IfaCacheinfo{
cachedata := nl.IfaCacheInfo{IfaCacheinfo: unix.IfaCacheinfo{
Valid: uint32(addr.ValidLft),
Prefered: uint32(addr.PreferedLft),
}}
Expand Down Expand Up @@ -380,13 +381,13 @@ func addrSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- AddrUpdate, done <-c
continue
}
if m.Header.Type == unix.NLMSG_ERROR {
error := int32(native.Uint32(m.Data[0:4]))
if error == 0 {
errno := int32(native.Uint32(m.Data[0:4]))
if errno == 0 {
continue
}
if cberr != nil {
cberr(fmt.Errorf("error message: %v",
syscall.Errno(-error)))
syscall.Errno(-errno)))
}
continue
}
Expand All @@ -406,13 +407,15 @@ func addrSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- AddrUpdate, done <-c
continue
}

ch <- AddrUpdate{LinkAddress: *addr.IPNet,
ch <- AddrUpdate{
LinkAddress: *addr.IPNet,
LinkIndex: addr.LinkIndex,
NewAddr: msgType == unix.RTM_NEWADDR,
Flags: addr.Flags,
Scope: addr.Scope,
PreferedLft: addr.PreferedLft,
ValidLft: addr.ValidLft}
ValidLft: addr.ValidLft,
}
}
}
}()
Expand Down
15 changes: 7 additions & 8 deletions addr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ func TestAddrReplace(t *testing.T) {
DoTestAddr(t, AddrReplace)
}

func DoTestAddr(t *testing.T, FunctionUndertest func(Link, *Addr) error) {
func DoTestAddr(t *testing.T, functionUndertest func(Link, *Addr) error) {
if os.Getenv("CI") == "true" {
t.Skipf("Fails in CI with: addr_test.go:*: Address flags not set properly, got=128, expected=132")
}
// TODO: IFA_F_PERMANENT does not seem to be set by default on older kernels?
// TODO: IFA_F_OPTIMISTIC failing in CI. should we just skip that one check?
var address = &net.IPNet{IP: net.IPv4(127, 0, 0, 2), Mask: net.CIDRMask(32, 32)}
var peer = &net.IPNet{IP: net.IPv4(127, 0, 0, 3), Mask: net.CIDRMask(24, 32)}
var addrTests = []struct {
address := &net.IPNet{IP: net.IPv4(127, 0, 0, 2), Mask: net.CIDRMask(32, 32)}
peer := &net.IPNet{IP: net.IPv4(127, 0, 0, 3), Mask: net.CIDRMask(24, 32)}
addrTests := []struct {
addr *Addr
expected *Addr
}{
Expand Down Expand Up @@ -67,7 +67,7 @@ func DoTestAddr(t *testing.T, FunctionUndertest func(Link, *Addr) error) {
}

for _, tt := range addrTests {
if err = FunctionUndertest(link, tt.addr); err != nil {
if err = functionUndertest(link, tt.addr); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -138,15 +138,14 @@ func DoTestAddr(t *testing.T, FunctionUndertest func(Link, *Addr) error) {
t.Fatal("Address not removed properly")
}
}

}

func TestAddrAddReplace(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()

var address = &net.IPNet{IP: net.IPv4(127, 0, 0, 2), Mask: net.CIDRMask(24, 32)}
var addr = &Addr{IPNet: address}
address := &net.IPNet{IP: net.IPv4(127, 0, 0, 2), Mask: net.CIDRMask(24, 32)}
addr := &Addr{IPNet: address}

link, err := LinkByName("lo")
if err != nil {
Expand Down
11 changes: 5 additions & 6 deletions bridge_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package netlink
import (
"fmt"

"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"

"github.com/vishvananda/netlink/nl"
)

// BridgeVlanList gets a map of device id to bridge vlan infos.
Expand Down Expand Up @@ -34,16 +35,14 @@ func (h *Handle) BridgeVlanList() (map[int32][]*nl.BridgeVlanInfo, error) {
return nil, err
}
for _, attr := range attrs {
switch attr.Attr.Type {
case unix.IFLA_AF_SPEC:
//nested attr
if attr.Attr.Type == unix.IFLA_AF_SPEC {
// nested attr
nestAttrs, err := nl.ParseRouteAttr(attr.Value)
if err != nil {
return nil, fmt.Errorf("failed to parse nested attr %v", err)
}
for _, nestAttr := range nestAttrs {
switch nestAttr.Attr.Type {
case nl.IFLA_BRIDGE_VLAN_INFO:
if nestAttr.Attr.Type == nl.IFLA_BRIDGE_VLAN_INFO {
vlanInfo := nl.DeserializeBridgeVlanInfo(nestAttr.Value)
ret[msg.Index] = append(ret[msg.Index], vlanInfo)
}
Expand Down
18 changes: 6 additions & 12 deletions bridge_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ func TestBridgeVlan(t *testing.T) {
} else {
if len(vInfo) != 1 {
t.Fatal()
} else {
if !vInfo[0].EngressUntag() || !vInfo[0].PortVID() || vInfo[0].Vid != 1 {
t.Fatalf("bridge vlan show get wrong return %s", vInfo[0].String())
}
} else if !vInfo[0].EngressUntag() || !vInfo[0].PortVID() || vInfo[0].Vid != 1 {
t.Fatalf("bridge vlan show get wrong return %s", vInfo[0].String())
}
}
}
Expand All @@ -61,17 +59,13 @@ func TestBridgeVlan(t *testing.T) {
}
if vInfo, ok := vlanMap[int32(bridge.Index)]; !ok {
t.Fatal("vlanMap should include foo port vlan info")
} else {
if fmt.Sprintf("%v", vInfo) != "[{Flags:6 Vid:1}]" {
t.Fatalf("unexpected result %v", vInfo)
}
} else if fmt.Sprintf("%v", vInfo) != "[{Flags:6 Vid:1}]" {
t.Fatalf("unexpected result %v", vInfo)
}
if vInfo, ok := vlanMap[int32(dummy.Index)]; !ok {
t.Fatal("vlanMap should include dum1 port vlan info")
} else {
if fmt.Sprintf("%v", vInfo) != "[{Flags:4 Vid:1} {Flags:0 Vid:2} {Flags:6 Vid:3}]" {
t.Fatalf("unexpected result %v", vInfo)
}
} else if fmt.Sprintf("%v", vInfo) != "[{Flags:4 Vid:1} {Flags:0 Vid:2} {Flags:6 Vid:3}]" {
t.Fatalf("unexpected result %v", vInfo)
}
}
}
6 changes: 3 additions & 3 deletions chain_linux.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package netlink

import (
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"

"github.com/vishvananda/netlink/nl"
)

// ChainDel will delete a chain from the system.
Expand Down Expand Up @@ -99,8 +100,7 @@ func (h *Handle) ChainList(link Link, parent uint32) ([]Chain, error) {

var chain Chain
for _, attr := range attrs {
switch attr.Attr.Type {
case nl.TCA_CHAIN:
if attr.Attr.Type == nl.TCA_CHAIN {
chain.Chain = native.Uint32(attr.Value)
chain.Parent = parent
}
Expand Down
3 changes: 2 additions & 1 deletion class_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
"fmt"
"syscall"

"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"

"github.com/vishvananda/netlink/nl"
)

// Internal tc_stats representation in Go struct.
Expand Down
1 change: 0 additions & 1 deletion class_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,5 +675,4 @@ func TestClassHfsc(t *testing.T) {
if err := ClassChange(hfscClass); err != nil {
t.Fatal(err)
}

}
3 changes: 2 additions & 1 deletion cmd/ipset-test/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux
// +build linux

package main
Expand Down Expand Up @@ -115,7 +116,7 @@ func cmdList(args []string) {
log.Printf("%+v", result)
}

func cmdListAll(args []string) {
func cmdListAll(_ []string) {
result, err := netlink.IpsetListAll()
check(err)
for _, ipset := range result {
Expand Down
Loading