diff --git a/bridge_linux_test.go b/bridge_linux_test.go index 04023a2..82704e7 100644 --- a/bridge_linux_test.go +++ b/bridge_linux_test.go @@ -62,14 +62,14 @@ func TestBridgeVlan(t *testing.T) { if vInfo, ok := vlanMap[int32(bridge.Index)]; !ok { t.Fatal("vlanMap should include foo port vlan info") } else { - if "[{Flags:6 Vid:1}]" != fmt.Sprintf("%v", vInfo) { + 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 "[{Flags:4 Vid:1} {Flags:0 Vid:2} {Flags:6 Vid:3}]" != fmt.Sprintf("%v", vInfo) { + if fmt.Sprintf("%v", vInfo) != "[{Flags:4 Vid:1} {Flags:0 Vid:2} {Flags:6 Vid:3}]" { t.Fatalf("unexpected result %v", vInfo) } } diff --git a/class_linux.go b/class_linux.go index fe8963f..6f542ba 100644 --- a/class_linux.go +++ b/class_linux.go @@ -191,9 +191,9 @@ func classPayload(req *nl.NetlinkRequest, class Class) error { opt.Fsc.Set(fm1/8, fd, fm2/8) um1, ud, um2 := hfsc.Usc.Attrs() opt.Usc.Set(um1/8, ud, um2/8) - nl.NewRtAttrChild(options, nl.TCA_HFSC_RSC, nl.SerializeHfscCurve(&opt.Rsc)) - nl.NewRtAttrChild(options, nl.TCA_HFSC_FSC, nl.SerializeHfscCurve(&opt.Fsc)) - nl.NewRtAttrChild(options, nl.TCA_HFSC_USC, nl.SerializeHfscCurve(&opt.Usc)) + options.AddRtAttr(nl.TCA_HFSC_RSC, nl.SerializeHfscCurve(&opt.Rsc)) + options.AddRtAttr(nl.TCA_HFSC_FSC, nl.SerializeHfscCurve(&opt.Fsc)) + options.AddRtAttr(nl.TCA_HFSC_USC, nl.SerializeHfscCurve(&opt.Usc)) } req.AddData(options) return nil diff --git a/class_test.go b/class_test.go index a8b66fe..e456b76 100644 --- a/class_test.go +++ b/class_test.go @@ -617,7 +617,7 @@ func TestClassHfsc(t *testing.T) { } // Check the amount of qdiscs - qdiscs, err = SafeQdiscList(link) + qdiscs, _ = SafeQdiscList(link) if len(qdiscs) != 3 { t.Fatal("Failed to add qdisc") } @@ -641,7 +641,7 @@ func TestClassHfsc(t *testing.T) { t.Fatal("Failed to delete classes") } // Check qdisc - qdiscs, err = SafeQdiscList(link) + qdiscs, _ = SafeQdiscList(link) if len(qdiscs) != 2 { t.Fatal("Failed to delete qdisc") } diff --git a/devlink_linux.go b/devlink_linux.go index 8f48947..c7eceaa 100644 --- a/devlink_linux.go +++ b/devlink_linux.go @@ -493,11 +493,11 @@ func (h *Handle) DevlinkPortFnSet(Bus string, Device string, PortIndex uint32, F fnAttr := nl.NewRtAttr(nl.DEVLINK_ATTR_PORT_FUNCTION|unix.NLA_F_NESTED, nil) - if FnAttrs.HwAddrValid == true { + if FnAttrs.HwAddrValid { fnAttr.AddRtAttr(nl.DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR, []byte(FnAttrs.FnAttrs.HwAddr)) } - if FnAttrs.StateValid == true { + if FnAttrs.StateValid { fnAttr.AddRtAttr(nl.DEVLINK_PORT_FN_ATTR_STATE, nl.Uint8Attr(FnAttrs.FnAttrs.State)) } req.AddData(fnAttr) diff --git a/handle_test.go b/handle_test.go index b046488..ac627ba 100644 --- a/handle_test.go +++ b/handle_test.go @@ -328,7 +328,7 @@ func runParallelTests(t *testing.T, thread int) { if err != nil { t.Fatal(err) } - l, err = handle1.LinkByName(ifName) + _, err = handle1.LinkByName(ifName) if err != nil { t.Fatal(err) } diff --git a/link_linux.go b/link_linux.go index 6c4434b..dd78d6c 100644 --- a/link_linux.go +++ b/link_linux.go @@ -55,8 +55,6 @@ const ( VF_LINK_STATE_DISABLE uint32 = 2 ) -var lookupByDump = false - var macvlanModes = [...]uint32{ 0, nl.MACVLAN_MODE_PRIVATE, @@ -591,13 +589,13 @@ func (h *Handle) LinkSetVfVlanQos(link Link, vf, vlan, qos int) error { req.AddData(msg) data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil) - info := nl.NewRtAttrChild(data, nl.IFLA_VF_INFO, nil) + info := data.AddRtAttr(nl.IFLA_VF_INFO, nil) vfmsg := nl.VfVlan{ Vf: uint32(vf), Vlan: uint32(vlan), Qos: uint32(qos), } - nl.NewRtAttrChild(info, nl.IFLA_VF_VLAN, vfmsg.Serialize()) + info.AddRtAttr(nl.IFLA_VF_VLAN, vfmsg.Serialize()) req.AddData(data) _, err := req.Execute(unix.NETLINK_ROUTE, 0) diff --git a/link_test.go b/link_test.go index 61cf5a7..1ecf21e 100644 --- a/link_test.go +++ b/link_test.go @@ -25,7 +25,7 @@ const ( ) func testLinkAddDel(t *testing.T, link Link) { - links, err := LinkList() + _, err := LinkList() if err != nil { t.Fatal(err) } @@ -215,7 +215,7 @@ func testLinkAddDel(t *testing.T, link Link) { if bond.AdUserPortKey != other.AdUserPortKey { t.Fatalf("Got unexpected AdUserPortKey: %d, expected: %d", other.AdUserPortKey, bond.AdUserPortKey) } - if bytes.Compare(bond.AdActorSystem, other.AdActorSystem) != 0 { + if !bytes.Equal(bond.AdActorSystem, other.AdActorSystem) { t.Fatalf("Got unexpected AdActorSystem: %d, expected: %d", other.AdActorSystem, bond.AdActorSystem) } case "balance-tlb": @@ -299,7 +299,7 @@ func testLinkAddDel(t *testing.T, link Link) { t.Fatal(err) } - links, err = LinkList() + links, err := LinkList() if err != nil { t.Fatal(err) } diff --git a/netlink_test.go b/netlink_test.go index aed1167..43a061c 100644 --- a/netlink_test.go +++ b/netlink_test.go @@ -107,10 +107,10 @@ func setUpNetlinkTestWithLoopback(t *testing.T) tearDownNetlinkTest { func setUpF(t *testing.T, path, value string) { file, err := os.Create(path) - defer file.Close() if err != nil { t.Fatalf("Failed to open %s: %s", path, err) } + defer file.Close() file.WriteString(value) } diff --git a/netns_linux.go b/netns_linux.go index 77cf6f4..2eb29c7 100644 --- a/netns_linux.go +++ b/netns_linux.go @@ -87,7 +87,7 @@ func (h *Handle) getNetNsId(attrType int, val uint32) (int, error) { rtgen := nl.NewRtGenMsg() req.AddData(rtgen) - b := make([]byte, 4, 4) + b := make([]byte, 4) native.PutUint32(b, val) attr := nl.NewRtAttr(attrType, b) req.AddData(attr) @@ -126,12 +126,12 @@ func (h *Handle) setNetNsId(attrType int, val uint32, newnsid uint32) error { rtgen := nl.NewRtGenMsg() req.AddData(rtgen) - b := make([]byte, 4, 4) + b := make([]byte, 4) native.PutUint32(b, val) attr := nl.NewRtAttr(attrType, b) req.AddData(attr) - b1 := make([]byte, 4, 4) + b1 := make([]byte, 4) native.PutUint32(b1, newnsid) attr1 := nl.NewRtAttr(NETNSA_NSID, b1) req.AddData(attr1) diff --git a/netns_test.go b/netns_test.go index 39b6c93..e18169a 100644 --- a/netns_test.go +++ b/netns_test.go @@ -33,7 +33,7 @@ func TestNetNsIdByFd(t *testing.T) { CheckErrorFail(t, err) // Get the ID back, make sure it matches - haveID, err := h.GetNetNsIdByFd(int(ns)) + haveID, _ := h.GetNetNsIdByFd(int(ns)) if haveID != wantID { t.Errorf("GetNetNsIdByFd returned %d, want %d", haveID, wantID) } @@ -72,7 +72,7 @@ func TestNetNsIdByPid(t *testing.T) { CheckErrorFail(t, err) //Get the ID and see if it worked - haveID, err := h.GetNetNsIdByPid(syscall.Gettid()) + haveID, _ := h.GetNetNsIdByPid(syscall.Gettid()) if haveID != wantID { t.Errorf("GetNetNsIdByPid returned %d, want %d", haveID, wantID) } diff --git a/nl/seg6_linux.go b/nl/seg6_linux.go index 5774cbb..fe88285 100644 --- a/nl/seg6_linux.go +++ b/nl/seg6_linux.go @@ -23,7 +23,7 @@ func (s1 *IPv6SrHdr) Equal(s2 IPv6SrHdr) bool { return false } for i := range s1.Segments { - if s1.Segments[i].Equal(s2.Segments[i]) != true { + if !s1.Segments[i].Equal(s2.Segments[i]) { return false } } @@ -89,7 +89,7 @@ func DecodeSEG6Encap(buf []byte) (int, []net.IP, error) { } buf = buf[12:] if len(buf)%16 != 0 { - err := fmt.Errorf("DecodeSEG6Encap: error parsing Segment List (buf len: %d)\n", len(buf)) + err := fmt.Errorf("DecodeSEG6Encap: error parsing Segment List (buf len: %d)", len(buf)) return mode, nil, err } for len(buf) > 0 { diff --git a/nl/syscall.go b/nl/syscall.go index 4a01e6e..bdf6ba6 100644 --- a/nl/syscall.go +++ b/nl/syscall.go @@ -1,6 +1,6 @@ package nl -// syscall package lack of rule atributes type. +// syscall package lack of rule attributes type. // Thus there are defined below const ( FRA_UNSPEC = iota diff --git a/rdma_link_test.go b/rdma_link_test.go index e8f86fd..241b89e 100644 --- a/rdma_link_test.go +++ b/rdma_link_test.go @@ -85,9 +85,9 @@ func TestRdmaSystemSetNetnsMode(t *testing.T) { } // Flip the mode from current mode if mode == "exclusive" { - err = RdmaSystemSetNetnsMode("shared") + RdmaSystemSetNetnsMode("shared") } else { - err = RdmaSystemSetNetnsMode("exclusive") + RdmaSystemSetNetnsMode("exclusive") } newMode, err = RdmaSystemGetNetnsMode() if err != nil { diff --git a/route_linux.go b/route_linux.go index fcfb782..2cdf406 100644 --- a/route_linux.go +++ b/route_linux.go @@ -250,7 +250,7 @@ func (e *SEG6Encap) String() string { segs := make([]string, 0, len(e.Segments)) // append segment backwards (from n to 0) since seg#0 is the last segment. for i := len(e.Segments); i > 0; i-- { - segs = append(segs, fmt.Sprintf("%s", e.Segments[i-1])) + segs = append(segs, e.Segments[i-1].String()) } str := fmt.Sprintf("mode %s segs %d [ %s ]", nl.SEG6EncapModeString(e.Mode), len(e.Segments), strings.Join(segs, " ")) @@ -420,7 +420,7 @@ func (e *SEG6LocalEncap) String() string { segs := make([]string, 0, len(e.Segments)) //append segment backwards (from n to 0) since seg#0 is the last segment. for i := len(e.Segments); i > 0; i-- { - segs = append(segs, fmt.Sprintf("%s", e.Segments[i-1])) + segs = append(segs, e.Segments[i-1].String()) } strs = append(strs, fmt.Sprintf("segs %d [ %s ]", len(e.Segments), strings.Join(segs, " "))) } @@ -530,7 +530,7 @@ func (e *BpfEncap) Decode(buf []byte) error { case nl.LWT_BPF_PROG_FD: bpfO.progFd = int(native.Uint32(parsedAttr.Value)) case nl.LWT_BPF_PROG_NAME: - bpfO.progName = fmt.Sprintf("%s", parsedAttr.Value) + bpfO.progName = string(parsedAttr.Value) default: return fmt.Errorf("lwt bpf decode: received unknown attribute: type: %d, len: %d", parsedAttr.Attr.Type, parsedAttr.Attr.Len) } @@ -599,7 +599,7 @@ func (e *BpfEncap) Equal(x Encap) bool { if e.headroom != o.headroom { return false } - for i, _ := range o.progs { + for i := range o.progs { if o.progs[i] != e.progs[i] { return false } diff --git a/route_test.go b/route_test.go index 36f6a43..babc049 100644 --- a/route_test.go +++ b/route_test.go @@ -1368,8 +1368,7 @@ func TestSEG6LocalRoute6AddDel(t *testing.T) { t.Fatal(err) } // Confirm route is deleted. - routesFound, err = RouteGet(dst1.IP) - if err == nil { + if _, err = RouteGet(dst1.IP); err == nil { t.Fatal("SEG6Local route still exists.") } diff --git a/xfrm_state_linux.go b/xfrm_state_linux.go index 5b1b6c3..3b37b87 100644 --- a/xfrm_state_linux.go +++ b/xfrm_state_linux.go @@ -111,7 +111,7 @@ func (h *Handle) xfrmStateAddOrUpdate(state *XfrmState, nlProto int) error { // A state with spi 0 can't be deleted so don't allow it to be set if state.Spi == 0 { - return fmt.Errorf("Spi must be set when adding xfrm state.") + return fmt.Errorf("Spi must be set when adding xfrm state") } req := h.newNetlinkRequest(nlProto, unix.NLM_F_CREATE|unix.NLM_F_EXCL|unix.NLM_F_ACK)