diff --git a/addr_linux.go b/addr_linux.go index 9b49baf9..b512add6 100644 --- a/addr_linux.go +++ b/addr_linux.go @@ -338,7 +338,8 @@ func AddrSubscribeWithOptions(ch chan<- AddrUpdate, done <-chan struct{}, option } func addrSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- AddrUpdate, done <-chan struct{}, cberr func(error), listExisting bool, - rcvbuf int, rcvTimeout *unix.Timeval, rcvBufForce bool) error { + rcvbuf int, rcvTimeout *unix.Timeval, rcvBufForce bool, +) error { s, err := nl.SubscribeAt(newNs, curNs, unix.NETLINK_ROUTE, unix.RTNLGRP_IPV4_IFADDR, unix.RTNLGRP_IPV6_IFADDR) if err != nil { return err @@ -417,13 +418,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, + } } } }() diff --git a/addr_test.go b/addr_test.go index d45a9894..7d021287 100644 --- a/addr_test.go +++ b/addr_test.go @@ -26,9 +26,9 @@ func DoTestAddr(t *testing.T, FunctionUndertest func(Link, *Addr) error) { } // 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 }{ @@ -138,7 +138,6 @@ func DoTestAddr(t *testing.T, FunctionUndertest func(Link, *Addr) error) { t.Fatal("Address not removed properly") } } - } func TestAddrAddReplace(t *testing.T) { @@ -146,8 +145,8 @@ func TestAddrAddReplace(t *testing.T) { defer tearDown() for _, nilLink := range []bool{false, true} { - 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 { diff --git a/bridge_linux.go b/bridge_linux.go index fa5766b8..2025a358 100644 --- a/bridge_linux.go +++ b/bridge_linux.go @@ -43,7 +43,7 @@ func (h *Handle) BridgeVlanList() (map[int32][]*nl.BridgeVlanInfo, error) { for _, attr := range attrs { switch attr.Attr.Type { case unix.IFLA_AF_SPEC: - //nested attr + // nested attr nestAttrs, err := nl.ParseRouteAttr(attr.Value) if err != nil { return nil, fmt.Errorf("failed to parse nested attr %v", err) @@ -146,7 +146,7 @@ func (h *Handle) bridgeVlanModify(cmd int, link Link, vid, vidEnd uint16, pvid, vlanEndInfo.Flags |= nl.BRIDGE_VLAN_INFO_RANGE_END br.AddRtAttr(nl.IFLA_BRIDGE_VLAN_INFO, vlanEndInfo.Serialize()) - } else { + } else { br.AddRtAttr(nl.IFLA_BRIDGE_VLAN_INFO, vlanInfo.Serialize()) } diff --git a/bridge_linux_test.go b/bridge_linux_test.go index 710a01b7..13ea7c8d 100644 --- a/bridge_linux_test.go +++ b/bridge_linux_test.go @@ -80,7 +80,7 @@ func TestBridgeVlan(t *testing.T) { } func TestBridgeGroupFwdMask(t *testing.T) { - minKernelRequired(t, 4, 15) //minimal release for per-port group_fwd_mask + minKernelRequired(t, 4, 15) // minimal release for per-port group_fwd_mask tearDown := setUpNetlinkTest(t) defer tearDown() if err := remountSysfs(); err != nil { diff --git a/class_test.go b/class_test.go index 9f0bf5d2..6b332350 100644 --- a/class_test.go +++ b/class_test.go @@ -679,5 +679,4 @@ func TestClassHfsc(t *testing.T) { if err := ClassChange(hfscClass); err != nil { t.Fatal(err) } - } diff --git a/conntrack_linux.go b/conntrack_linux.go index 69c5eca0..82d75781 100644 --- a/conntrack_linux.go +++ b/conntrack_linux.go @@ -218,10 +218,12 @@ type ProtoInfo interface { type ProtoInfoTCP struct { State uint8 } + // Protocol returns "tcp". -func (*ProtoInfoTCP) Protocol() string {return "tcp"} +func (*ProtoInfoTCP) Protocol() string { return "tcp" } + func (p *ProtoInfoTCP) toNlData() ([]*nl.RtAttr, error) { - ctProtoInfo := nl.NewRtAttr(unix.NLA_F_NESTED | nl.CTA_PROTOINFO, []byte{}) + ctProtoInfo := nl.NewRtAttr(unix.NLA_F_NESTED|nl.CTA_PROTOINFO, []byte{}) ctProtoInfoTCP := nl.NewRtAttr(unix.NLA_F_NESTED|nl.CTA_PROTOINFO_TCP, []byte{}) ctProtoInfoTCPState := nl.NewRtAttr(nl.CTA_PROTOINFO_TCP_STATE, nl.Uint8Attr(p.State)) ctProtoInfoTCP.AddChild(ctProtoInfoTCPState) @@ -231,14 +233,16 @@ func (p *ProtoInfoTCP) toNlData() ([]*nl.RtAttr, error) { } // ProtoInfoSCTP only supports the protocol name. -type ProtoInfoSCTP struct {} +type ProtoInfoSCTP struct{} + // Protocol returns "sctp". -func (*ProtoInfoSCTP) Protocol() string {return "sctp"} +func (*ProtoInfoSCTP) Protocol() string { return "sctp" } // ProtoInfoDCCP only supports the protocol name. -type ProtoInfoDCCP struct {} +type ProtoInfoDCCP struct{} + // Protocol returns "dccp". -func (*ProtoInfoDCCP) Protocol() string {return "dccp"} +func (*ProtoInfoDCCP) Protocol() string { return "dccp" } // The full conntrack flow structure is very complicated and can be found in the file: // http://git.netfilter.org/libnetfilter_conntrack/tree/include/internal/object.h @@ -256,7 +260,6 @@ type IPTuple struct { // toNlData generates the inner fields of a nested tuple netlink datastructure // does not generate the "nested"-flagged outer message. func (t *IPTuple) toNlData(family uint8) ([]*nl.RtAttr, error) { - var srcIPsFlag, dstIPsFlag int if family == nl.FAMILY_V4 { srcIPsFlag = nl.CTA_IP_V4_SRC @@ -280,7 +283,7 @@ func (t *IPTuple) toNlData(family uint8) ([]*nl.RtAttr, error) { ctTupleProtoSrcPort := nl.NewRtAttr(nl.CTA_PROTO_SRC_PORT, nl.BEUint16Attr(t.SrcPort)) ctTupleProto.AddChild(ctTupleProtoSrcPort) ctTupleProtoDstPort := nl.NewRtAttr(nl.CTA_PROTO_DST_PORT, nl.BEUint16Attr(t.DstPort)) - ctTupleProto.AddChild(ctTupleProtoDstPort, ) + ctTupleProto.AddChild(ctTupleProtoDstPort) return []*nl.RtAttr{ctTupleIP, ctTupleProto}, nil } @@ -357,7 +360,7 @@ func (s *ConntrackFlow) toNlData() ([]*nl.RtAttr, error) { // // // - + // CTA_TUPLE_ORIG ctTupleOrig := nl.NewRtAttr(unix.NLA_F_NESTED|nl.CTA_TUPLE_ORIG, nil) forwardFlowAttrs, err := s.Forward.toNlData(s.FamilyType) @@ -535,17 +538,16 @@ func parseTimeStamp(r *bytes.Reader, readSize uint16) (tstart, tstop uint64) { } } return - } func parseProtoInfoTCPState(r *bytes.Reader) (s uint8) { binary.Read(r, binary.BigEndian, &s) - r.Seek(nl.SizeofNfattr - 1, seekCurrent) + r.Seek(nl.SizeofNfattr-1, seekCurrent) return s } // parseProtoInfoTCP reads the entire nested protoinfo structure, but only parses the state attr. -func parseProtoInfoTCP(r *bytes.Reader, attrLen uint16) (*ProtoInfoTCP) { +func parseProtoInfoTCP(r *bytes.Reader, attrLen uint16) *ProtoInfoTCP { p := new(ProtoInfoTCP) bytesRead := 0 for bytesRead < int(attrLen) { @@ -659,7 +661,7 @@ func parseRawData(data []byte) *ConntrackFlow { switch t { case nl.CTA_MARK: s.Mark = parseConnectionMark(reader) - case nl.CTA_LABELS: + case nl.CTA_LABELS: s.Labels = parseConnectionLabels(reader) case nl.CTA_TIMEOUT: s.TimeOut = parseTimeOut(reader) diff --git a/conntrack_test.go b/conntrack_test.go index 6850f3c5..74421dde 100644 --- a/conntrack_test.go +++ b/conntrack_test.go @@ -22,6 +22,7 @@ func CheckErrorFail(t *testing.T, err error) { t.Fatalf("Fatal Error: %s", err) } } + func CheckError(t *testing.T, err error) { if err != nil { t.Errorf("Error: %s", err) @@ -350,22 +351,22 @@ func TestConntrackTableDelete(t *testing.T) { func TestConntrackFilter(t *testing.T) { var flowList []ConntrackFlow flowList = append(flowList, ConntrackFlow{ - FamilyType: unix.AF_INET, - Forward: IPTuple{ - SrcIP: net.ParseIP("10.0.0.1"), - DstIP: net.ParseIP("20.0.0.1"), - SrcPort: 1000, - DstPort: 2000, - Protocol: 17, - }, - Reverse: IPTuple{ - SrcIP: net.ParseIP("20.0.0.1"), - DstIP: net.ParseIP("192.168.1.1"), - SrcPort: 2000, - DstPort: 1000, - Protocol: 17, - }, + FamilyType: unix.AF_INET, + Forward: IPTuple{ + SrcIP: net.ParseIP("10.0.0.1"), + DstIP: net.ParseIP("20.0.0.1"), + SrcPort: 1000, + DstPort: 2000, + Protocol: 17, + }, + Reverse: IPTuple{ + SrcIP: net.ParseIP("20.0.0.1"), + DstIP: net.ParseIP("192.168.1.1"), + SrcPort: 2000, + DstPort: 1000, + Protocol: 17, }, + }, ConntrackFlow{ FamilyType: unix.AF_INET, Forward: IPTuple{ @@ -866,7 +867,8 @@ func TestParseRawData(t *testing.T) { 22, 134, 80, 142, 230, 127, 74, 166, /* >> CTA_LABELS */ 20, 0, 22, 0, - 0, 0, 0, 0, 5, 0, 18, 172, 66, 2, 1, 0, 0, 0, 0, 0}, + 0, 0, 0, 0, 5, 0, 18, 172, 66, 2, 1, 0, 0, 0, 0, 0, + }, expConntrackFlow: "udp\t17 src=192.168.0.10 dst=192.168.0.3 sport=48385 dport=53 packets=1 bytes=55\t" + "src=192.168.0.3 dst=192.168.0.10 sport=53 dport=48385 packets=1 bytes=71 mark=0x5 labels=0x00000000050012ac4202010000000000 " + "start=2021-06-07 13:41:30.39632247 +0000 UTC stop=1970-01-01 00:00:00 +0000 UTC timeout=32(sec)", @@ -964,7 +966,8 @@ func TestParseRawData(t *testing.T) { 16, 0, 20, 128, /* >>>> CTA_TIMESTAMP_START */ 12, 0, 1, 0, - 22, 134, 80, 175, 134, 10, 182, 221}, + 22, 134, 80, 175, 134, 10, 182, 221, + }, expConntrackFlow: "tcp\t6 src=192.168.0.10 dst=192.168.77.73 sport=42625 dport=3333 packets=11 bytes=1914\t" + "src=192.168.77.73 dst=192.168.0.10 sport=3333 dport=42625 packets=10 bytes=1858 mark=0x5 zone=100 " + "start=2021-06-07 13:43:50.511990493 +0000 UTC stop=1970-01-01 00:00:00 +0000 UTC timeout=152(sec)", @@ -1015,23 +1018,23 @@ func TestConntrackUpdateV4(t *testing.T) { flow := ConntrackFlow{ FamilyType: FAMILY_V4, Forward: IPTuple{ - SrcIP: net.IP{234,234,234,234}, - DstIP: net.IP{123,123,123,123}, - SrcPort: 48385, - DstPort: 53, + SrcIP: net.IP{234, 234, 234, 234}, + DstIP: net.IP{123, 123, 123, 123}, + SrcPort: 48385, + DstPort: 53, Protocol: unix.IPPROTO_TCP, }, Reverse: IPTuple{ - SrcIP: net.IP{123,123,123,123}, - DstIP: net.IP{234,234,234,234}, - SrcPort: 53, - DstPort: 48385, + SrcIP: net.IP{123, 123, 123, 123}, + DstIP: net.IP{234, 234, 234, 234}, + SrcPort: 53, + DstPort: 48385, Protocol: unix.IPPROTO_TCP, }, // No point checking equivalence of timeout, but value must // be reasonable to allow for a potentially slow subsequent read. - TimeOut: 100, - Mark: 12, + TimeOut: 100, + Mark: 12, ProtoInfo: &ProtoInfoTCP{ State: nl.TCP_CONNTRACK_SYN_SENT2, }, @@ -1054,8 +1057,8 @@ func TestConntrackUpdateV4(t *testing.T) { filter := ConntrackFilter{ ipNetFilter: map[ConntrackFilterType]*net.IPNet{ - ConntrackOrigSrcIP: NewIPNet(flow.Forward.SrcIP), - ConntrackOrigDstIP: NewIPNet(flow.Forward.DstIP), + ConntrackOrigSrcIP: NewIPNet(flow.Forward.SrcIP), + ConntrackOrigDstIP: NewIPNet(flow.Forward.DstIP), ConntrackReplySrcIP: NewIPNet(flow.Reverse.SrcIP), ConntrackReplyDstIP: NewIPNet(flow.Reverse.DstIP), }, @@ -1063,7 +1066,7 @@ func TestConntrackUpdateV4(t *testing.T) { ConntrackOrigSrcPort: flow.Forward.SrcPort, ConntrackOrigDstPort: flow.Forward.DstPort, }, - protoFilter:unix.IPPROTO_TCP, + protoFilter: unix.IPPROTO_TCP, } var match *ConntrackFlow @@ -1148,23 +1151,23 @@ func TestConntrackUpdateV6(t *testing.T) { flow := ConntrackFlow{ FamilyType: FAMILY_V6, Forward: IPTuple{ - SrcIP: net.ParseIP("2001:db8::68"), - DstIP: net.ParseIP("2001:db9::32"), - SrcPort: 48385, - DstPort: 53, + SrcIP: net.ParseIP("2001:db8::68"), + DstIP: net.ParseIP("2001:db9::32"), + SrcPort: 48385, + DstPort: 53, Protocol: unix.IPPROTO_TCP, }, Reverse: IPTuple{ - SrcIP: net.ParseIP("2001:db9::32"), - DstIP: net.ParseIP("2001:db8::68"), - SrcPort: 53, - DstPort: 48385, + SrcIP: net.ParseIP("2001:db9::32"), + DstIP: net.ParseIP("2001:db8::68"), + SrcPort: 53, + DstPort: 48385, Protocol: unix.IPPROTO_TCP, }, // No point checking equivalence of timeout, but value must // be reasonable to allow for a potentially slow subsequent read. - TimeOut: 100, - Mark: 12, + TimeOut: 100, + Mark: 12, ProtoInfo: &ProtoInfoTCP{ State: nl.TCP_CONNTRACK_SYN_SENT2, }, @@ -1187,8 +1190,8 @@ func TestConntrackUpdateV6(t *testing.T) { filter := ConntrackFilter{ ipNetFilter: map[ConntrackFilterType]*net.IPNet{ - ConntrackOrigSrcIP: NewIPNet(flow.Forward.SrcIP), - ConntrackOrigDstIP: NewIPNet(flow.Forward.DstIP), + ConntrackOrigSrcIP: NewIPNet(flow.Forward.SrcIP), + ConntrackOrigDstIP: NewIPNet(flow.Forward.DstIP), ConntrackReplySrcIP: NewIPNet(flow.Reverse.SrcIP), ConntrackReplyDstIP: NewIPNet(flow.Reverse.DstIP), }, @@ -1196,7 +1199,7 @@ func TestConntrackUpdateV6(t *testing.T) { ConntrackOrigSrcPort: flow.Forward.SrcPort, ConntrackOrigDstPort: flow.Forward.DstPort, }, - protoFilter:unix.IPPROTO_TCP, + protoFilter: unix.IPPROTO_TCP, } var match *ConntrackFlow @@ -1279,23 +1282,23 @@ func TestConntrackCreateV4(t *testing.T) { flow := ConntrackFlow{ FamilyType: FAMILY_V4, Forward: IPTuple{ - SrcIP: net.IP{234,234,234,234}, - DstIP: net.IP{123,123,123,123}, - SrcPort: 48385, - DstPort: 53, + SrcIP: net.IP{234, 234, 234, 234}, + DstIP: net.IP{123, 123, 123, 123}, + SrcPort: 48385, + DstPort: 53, Protocol: unix.IPPROTO_TCP, }, Reverse: IPTuple{ - SrcIP: net.IP{123,123,123,123}, - DstIP: net.IP{234,234,234,234}, - SrcPort: 53, - DstPort: 48385, + SrcIP: net.IP{123, 123, 123, 123}, + DstIP: net.IP{234, 234, 234, 234}, + SrcPort: 53, + DstPort: 48385, Protocol: unix.IPPROTO_TCP, }, // No point checking equivalence of timeout, but value must // be reasonable to allow for a potentially slow subsequent read. - TimeOut: 100, - Mark: 12, + TimeOut: 100, + Mark: 12, ProtoInfo: &ProtoInfoTCP{ State: nl.TCP_CONNTRACK_ESTABLISHED, }, @@ -1313,8 +1316,8 @@ func TestConntrackCreateV4(t *testing.T) { filter := ConntrackFilter{ ipNetFilter: map[ConntrackFilterType]*net.IPNet{ - ConntrackOrigSrcIP: NewIPNet(flow.Forward.SrcIP), - ConntrackOrigDstIP: NewIPNet(flow.Forward.DstIP), + ConntrackOrigSrcIP: NewIPNet(flow.Forward.SrcIP), + ConntrackOrigDstIP: NewIPNet(flow.Forward.DstIP), ConntrackReplySrcIP: NewIPNet(flow.Reverse.SrcIP), ConntrackReplyDstIP: NewIPNet(flow.Reverse.DstIP), }, @@ -1322,7 +1325,7 @@ func TestConntrackCreateV4(t *testing.T) { ConntrackOrigSrcPort: flow.Forward.SrcPort, ConntrackOrigDstPort: flow.Forward.DstPort, }, - protoFilter:unix.IPPROTO_TCP, + protoFilter: unix.IPPROTO_TCP, } var match *ConntrackFlow @@ -1374,23 +1377,23 @@ func TestConntrackCreateV6(t *testing.T) { flow := ConntrackFlow{ FamilyType: FAMILY_V6, Forward: IPTuple{ - SrcIP: net.ParseIP("2001:db8::68"), - DstIP: net.ParseIP("2001:db9::32"), - SrcPort: 48385, - DstPort: 53, + SrcIP: net.ParseIP("2001:db8::68"), + DstIP: net.ParseIP("2001:db9::32"), + SrcPort: 48385, + DstPort: 53, Protocol: unix.IPPROTO_TCP, }, Reverse: IPTuple{ - SrcIP: net.ParseIP("2001:db9::32"), - DstIP: net.ParseIP("2001:db8::68"), - SrcPort: 53, - DstPort: 48385, + SrcIP: net.ParseIP("2001:db9::32"), + DstIP: net.ParseIP("2001:db8::68"), + SrcPort: 53, + DstPort: 48385, Protocol: unix.IPPROTO_TCP, }, // No point checking equivalence of timeout, but value must // be reasonable to allow for a potentially slow subsequent read. - TimeOut: 100, - Mark: 12, + TimeOut: 100, + Mark: 12, ProtoInfo: &ProtoInfoTCP{ State: nl.TCP_CONNTRACK_ESTABLISHED, }, @@ -1408,8 +1411,8 @@ func TestConntrackCreateV6(t *testing.T) { filter := ConntrackFilter{ ipNetFilter: map[ConntrackFilterType]*net.IPNet{ - ConntrackOrigSrcIP: NewIPNet(flow.Forward.SrcIP), - ConntrackOrigDstIP: NewIPNet(flow.Forward.DstIP), + ConntrackOrigSrcIP: NewIPNet(flow.Forward.SrcIP), + ConntrackOrigDstIP: NewIPNet(flow.Forward.DstIP), ConntrackReplySrcIP: NewIPNet(flow.Reverse.SrcIP), ConntrackReplyDstIP: NewIPNet(flow.Reverse.DstIP), }, @@ -1417,7 +1420,7 @@ func TestConntrackCreateV6(t *testing.T) { ConntrackOrigSrcPort: flow.Forward.SrcPort, ConntrackOrigDstPort: flow.Forward.DstPort, }, - protoFilter:unix.IPPROTO_TCP, + protoFilter: unix.IPPROTO_TCP, } var match *ConntrackFlow @@ -1448,43 +1451,43 @@ func TestConntrackFlowToNlData(t *testing.T) { flowV4 := ConntrackFlow{ FamilyType: FAMILY_V4, Forward: IPTuple{ - SrcIP: net.IP{234,234,234,234}, - DstIP: net.IP{123,123,123,123}, - SrcPort: 48385, - DstPort: 53, + SrcIP: net.IP{234, 234, 234, 234}, + DstIP: net.IP{123, 123, 123, 123}, + SrcPort: 48385, + DstPort: 53, Protocol: unix.IPPROTO_TCP, }, Reverse: IPTuple{ - SrcIP: net.IP{123,123,123,123}, - DstIP: net.IP{234,234,234,234}, - SrcPort: 53, - DstPort: 48385, + SrcIP: net.IP{123, 123, 123, 123}, + DstIP: net.IP{234, 234, 234, 234}, + SrcPort: 53, + DstPort: 48385, Protocol: unix.IPPROTO_TCP, }, - Mark: 5, - TimeOut: 10, + Mark: 5, + TimeOut: 10, ProtoInfo: &ProtoInfoTCP{ State: nl.TCP_CONNTRACK_ESTABLISHED, }, } - flowV6 := ConntrackFlow { + flowV6 := ConntrackFlow{ FamilyType: FAMILY_V6, Forward: IPTuple{ - SrcIP: net.ParseIP("2001:db8::68"), - DstIP: net.ParseIP("2001:db9::32"), - SrcPort: 48385, - DstPort: 53, - Protocol: unix.IPPROTO_TCP, + SrcIP: net.ParseIP("2001:db8::68"), + DstIP: net.ParseIP("2001:db9::32"), + SrcPort: 48385, + DstPort: 53, + Protocol: unix.IPPROTO_TCP, }, Reverse: IPTuple{ - SrcIP: net.ParseIP("2001:db9::32"), - DstIP: net.ParseIP("2001:db8::68"), - SrcPort: 53, - DstPort: 48385, + SrcIP: net.ParseIP("2001:db9::32"), + DstIP: net.ParseIP("2001:db8::68"), + SrcPort: 53, + DstPort: 48385, Protocol: unix.IPPROTO_TCP, }, - Mark: 5, - TimeOut: 10, + Mark: 5, + TimeOut: 10, ProtoInfo: &ProtoInfoTCP{ State: nl.TCP_CONNTRACK_ESTABLISHED, }, @@ -1497,7 +1500,7 @@ func TestConntrackFlowToNlData(t *testing.T) { t.Fatalf("Error converting ConntrackFlow to netlink messages: %s", err) } // Mock nfgenmsg header - bytesV4 = append(bytesV4, flowV4.FamilyType,0,0,0) + bytesV4 = append(bytesV4, flowV4.FamilyType, 0, 0, 0) for _, a := range attrsV4 { bytesV4 = append(bytesV4, a.Serialize()...) } @@ -1507,7 +1510,7 @@ func TestConntrackFlowToNlData(t *testing.T) { t.Fatalf("Error converting ConntrackFlow to netlink messages: %s", err) } // Mock nfgenmsg header - bytesV6 = append(bytesV6, flowV6.FamilyType,0,0,0) + bytesV6 = append(bytesV6, flowV6.FamilyType, 0, 0, 0) for _, a := range attrsV6 { bytesV6 = append(bytesV6, a.Serialize()...) } diff --git a/conntrack_unspecified.go b/conntrack_unspecified.go index 0049048d..c995d6a6 100644 --- a/conntrack_unspecified.go +++ b/conntrack_unspecified.go @@ -1,3 +1,4 @@ +//go:build !linux // +build !linux package netlink diff --git a/devlink_linux.go b/devlink_linux.go index 45d8ee4b..0a03ce26 100644 --- a/devlink_linux.go +++ b/devlink_linux.go @@ -376,7 +376,7 @@ func eswitchStringToMode(modeName string) (uint16, error) { } func parseEswitchMode(mode uint16) string { - var eswitchMode = map[uint16]string{ + eswitchMode := map[uint16]string{ nl.DEVLINK_ESWITCH_MODE_LEGACY: "legacy", nl.DEVLINK_ESWITCH_MODE_SWITCHDEV: "switchdev", } @@ -388,7 +388,7 @@ func parseEswitchMode(mode uint16) string { } func parseEswitchInlineMode(inlinemode uint8) string { - var eswitchInlineMode = map[uint8]string{ + eswitchInlineMode := map[uint8]string{ nl.DEVLINK_ESWITCH_INLINE_MODE_NONE: "none", nl.DEVLINK_ESWITCH_INLINE_MODE_LINK: "link", nl.DEVLINK_ESWITCH_INLINE_MODE_NETWORK: "network", @@ -402,7 +402,7 @@ func parseEswitchInlineMode(inlinemode uint8) string { } func parseEswitchEncapMode(encapmode uint8) string { - var eswitchEncapMode = map[uint8]string{ + eswitchEncapMode := map[uint8]string{ nl.DEVLINK_ESWITCH_ENCAP_MODE_NONE: "disable", nl.DEVLINK_ESWITCH_ENCAP_MODE_BASIC: "enable", } @@ -701,7 +701,6 @@ func parseDevlinkPortMsg(msgs [][]byte) (*DevlinkPort, error) { // DevLinkGetPortByIndexprovides a pointer to devlink device and nil error, // otherwise returns an error code. func (h *Handle) DevLinkGetPortByIndex(Bus string, Device string, PortIndex uint32) (*DevlinkPort, error) { - _, req, err := h.createCmdReq(nl.DEVLINK_CMD_PORT_GET, Bus, Device) if err != nil { return nil, err @@ -1062,7 +1061,6 @@ func parseInfoMsg(msg []byte) (map[string]string, error) { info := make(map[string]string) err := collectInfoData(msg[nl.SizeofGenlmsg:], info) - if err != nil { return nil, err } diff --git a/devlink_test.go b/devlink_test.go index cf6961c7..abc83ca8 100644 --- a/devlink_test.go +++ b/devlink_test.go @@ -147,9 +147,11 @@ func TestDevLinkSfPortFnSet(t *testing.T) { } } -var bus string -var device string -var sfnum uint +var ( + bus string + device string + sfnum uint +) func init() { flag.StringVar(&bus, "bus", "", "devlink device bus name") @@ -204,7 +206,8 @@ func mockDevlinkInfoGetterEmpty(bus, device string) ([]byte, error) { } func devlinkInfo() []byte { - return []byte{51, 1, 0, 0, 8, 0, 1, 0, 112, 99, 105, 0, 17, 0, 2, 0, 48, + return []byte{ + 51, 1, 0, 0, 8, 0, 1, 0, 112, 99, 105, 0, 17, 0, 2, 0, 48, 48, 48, 48, 58, 56, 52, 58, 48, 48, 46, 48, 0, 0, 0, 0, 8, 0, 98, 0, 105, 99, 101, 0, 28, 0, 99, 0, 51, 48, 45, 56, 57, 45, 97, 51, 45, 102, 102, 45, 102, 102, 45, 99, 97, 45, 48, 53, 45, 54, 56, 0, 36, @@ -234,7 +237,8 @@ func devlinkInfo() []byte { 52, 48, 46, 50, 48, 48, 48, 45, 51, 46, 49, 54, 46, 48, 0, 0, 0, 0, 44, 0, 101, 0, 21, 0, 103, 0, 102, 119, 46, 110, 101, 116, 108, 105, 115, 116, 46, 98, 117, 105, 108, 100, 0, 0, 0, 0, 15, 0, 104, 0, 48, - 120, 54, 55, 54, 97, 52, 56, 57, 100, 0, 0} + 120, 54, 55, 54, 97, 52, 56, 57, 100, 0, 0, + } } func devlinkTestInfoParesd() map[string]string { @@ -275,7 +279,7 @@ func TestDevlinkGetDeviceResources(t *testing.T) { defer tearDown() if bus == "" || device == "" { - //TODO: setup netdevsim device instead of getting device from flags + // TODO: setup netdevsim device instead of getting device from flags t.Log("devlink bus and device are empty, skipping test") t.SkipNow() } diff --git a/filter_linux.go b/filter_linux.go index 19306612..058d4d3f 100644 --- a/filter_linux.go +++ b/filter_linux.go @@ -546,7 +546,8 @@ func toTimeStamp(tcf *nl.Tcf) *ActionTimestamp { Installed: tcf.Install, LastUsed: tcf.LastUse, Expires: tcf.Expires, - FirstUsed: tcf.FirstUse} + FirstUsed: tcf.FirstUse, + } } func encodePolice(attr *nl.RtAttr, action *PoliceAction) error { diff --git a/filter_test.go b/filter_test.go index 3a49f1b8..f3da32c6 100644 --- a/filter_test.go +++ b/filter_test.go @@ -1223,7 +1223,6 @@ func TestFilterMatchAllAddDel(t *testing.T) { if len(filters) != 0 { t.Fatal("Failed to remove filter") } - } func TestFilterU32TunnelKeyAddDel(t *testing.T) { diff --git a/genetlink_unspecified.go b/genetlink_unspecified.go index 0192b991..18f8e629 100644 --- a/genetlink_unspecified.go +++ b/genetlink_unspecified.go @@ -1,3 +1,4 @@ +//go:build !linux // +build !linux package netlink diff --git a/gtp_test.go b/gtp_test.go index 4b94b6bd..2b51713b 100644 --- a/gtp_test.go +++ b/gtp_test.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package netlink diff --git a/handle_test.go b/handle_test.go index c7feb22d..90070e6a 100644 --- a/handle_test.go +++ b/handle_test.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package netlink @@ -209,6 +210,7 @@ func getXfrmPolicy(thread int) *XfrmPolicy { }, } } + func initParallel() { ns1, initError = netns.New() if initError != nil { diff --git a/handle_unspecified.go b/handle_unspecified.go index 3fe03642..cd14ab04 100644 --- a/handle_unspecified.go +++ b/handle_unspecified.go @@ -1,3 +1,4 @@ +//go:build !linux // +build !linux package netlink diff --git a/ipset_linux.go b/ipset_linux.go index f4c05229..4d9e2df0 100644 --- a/ipset_linux.go +++ b/ipset_linux.go @@ -129,7 +129,6 @@ func IpsetTest(setname string, entry *IPSetEntry) (bool, error) { func (h *Handle) IpsetProtocol() (protocol uint8, minVersion uint8, err error) { req := h.newIpsetRequest(nl.IPSET_CMD_PROTOCOL) msgs, err := req.Execute(unix.NETLINK_NETFILTER, 0) - if err != nil { return 0, 0, err } @@ -408,7 +407,6 @@ func getIpsetDefaultWithTypeName(typename string) uint8 { func ipsetExecute(req *nl.NetlinkRequest) (msgs [][]byte, err error) { msgs, err = req.Execute(unix.NETLINK_NETFILTER, 0) - if err != nil { if errno := int(err.(syscall.Errno)); errno >= nl.IPSET_ERR_PRIVATE { err = nl.IPSetError(uintptr(errno)) diff --git a/ipset_linux_test.go b/ipset_linux_test.go index 298c3a3a..c70f8112 100644 --- a/ipset_linux_test.go +++ b/ipset_linux_test.go @@ -114,7 +114,6 @@ func TestIpsetCreateListAddDelDestroy(t *testing.T) { } results, err := IpsetListAll() - if err != nil { t.Fatal(err) } @@ -159,7 +158,6 @@ func TestIpsetCreateListAddDelDestroy(t *testing.T) { IP: ip, Replace: false, }) - if err != nil { t.Fatal(err) } @@ -175,7 +173,6 @@ func TestIpsetCreateListAddDelDestroy(t *testing.T) { } result, err := IpsetList("my-test-ipset-1") - if err != nil { t.Fatal(err) } @@ -470,7 +467,6 @@ func TestIpsetCreateListAddDelDestroyWithTestCases(t *testing.T) { } err = IpsetAdd(tC.setname, tC.entry) - if err != nil { t.Error(result.Protocol, result.Family) t.Fatal(err) @@ -485,7 +481,6 @@ func TestIpsetCreateListAddDelDestroyWithTestCases(t *testing.T) { } result, err = IpsetList(tC.setname) - if err != nil { t.Fatal(err) } @@ -637,7 +632,6 @@ func TestIpsetBitmapCreateListWithTestCases(t *testing.T) { t.Fatalf("expected ip range %v-%v, got %v-%v", tC.options.IPFrom, tC.options.IPTo, result.IPFrom, result.IPTo) } } - }) } } diff --git a/link.go b/link.go index f820cdb6..4930ff53 100644 --- a/link.go +++ b/link.go @@ -340,8 +340,10 @@ func (macvtap Macvtap) Type() string { return "macvtap" } -type TuntapMode uint16 -type TuntapFlag uint16 +type ( + TuntapMode uint16 + TuntapFlag uint16 +) // Tuntap links created via /dev/tun/tap, but can be destroyed via netlink type Tuntap struct { @@ -603,6 +605,7 @@ var bondModeToString = map[BondMode]string{ BOND_MODE_BALANCE_TLB: "balance-tlb", BOND_MODE_BALANCE_ALB: "balance-alb", } + var StringToBondModeMap = map[string]BondMode{ "balance-rr": BOND_MODE_BALANCE_RR, "active-backup": BOND_MODE_ACTIVE_BACKUP, @@ -630,6 +633,7 @@ var bondArpValidateToString = map[BondArpValidate]string{ BOND_ARP_VALIDATE_BACKUP: "backup", BOND_ARP_VALIDATE_ALL: "none", } + var StringToBondArpValidateMap = map[string]BondArpValidate{ "none": BOND_ARP_VALIDATE_NONE, "active": BOND_ARP_VALIDATE_ACTIVE, @@ -660,6 +664,7 @@ var bondPrimaryReselectToString = map[BondPrimaryReselect]string{ BOND_PRIMARY_RESELECT_BETTER: "better", BOND_PRIMARY_RESELECT_FAILURE: "failure", } + var StringToBondPrimaryReselectMap = map[string]BondPrimaryReselect{ "always": BOND_PRIMARY_RESELECT_ALWAYS, "better": BOND_PRIMARY_RESELECT_BETTER, @@ -687,6 +692,7 @@ var bondArpAllTargetsToString = map[BondArpAllTargets]string{ BOND_ARP_ALL_TARGETS_ANY: "any", BOND_ARP_ALL_TARGETS_ALL: "all", } + var StringToBondArpAllTargetsMap = map[string]BondArpAllTargets{ "any": BOND_ARP_ALL_TARGETS_ANY, "all": BOND_ARP_ALL_TARGETS_ALL, @@ -715,6 +721,7 @@ var bondFailOverMacToString = map[BondFailOverMac]string{ BOND_FAIL_OVER_MAC_ACTIVE: "active", BOND_FAIL_OVER_MAC_FOLLOW: "follow", } + var StringToBondFailOverMacMap = map[string]BondFailOverMac{ "none": BOND_FAIL_OVER_MAC_NONE, "active": BOND_FAIL_OVER_MAC_ACTIVE, @@ -761,19 +768,20 @@ const ( ) var bondXmitHashPolicyToString = map[BondXmitHashPolicy]string{ - BOND_XMIT_HASH_POLICY_LAYER2: "layer2", - BOND_XMIT_HASH_POLICY_LAYER3_4: "layer3+4", - BOND_XMIT_HASH_POLICY_LAYER2_3: "layer2+3", - BOND_XMIT_HASH_POLICY_ENCAP2_3: "encap2+3", - BOND_XMIT_HASH_POLICY_ENCAP3_4: "encap3+4", + BOND_XMIT_HASH_POLICY_LAYER2: "layer2", + BOND_XMIT_HASH_POLICY_LAYER3_4: "layer3+4", + BOND_XMIT_HASH_POLICY_LAYER2_3: "layer2+3", + BOND_XMIT_HASH_POLICY_ENCAP2_3: "encap2+3", + BOND_XMIT_HASH_POLICY_ENCAP3_4: "encap3+4", BOND_XMIT_HASH_POLICY_VLAN_SRCMAC: "vlan+srcmac", } + var StringToBondXmitHashPolicyMap = map[string]BondXmitHashPolicy{ - "layer2": BOND_XMIT_HASH_POLICY_LAYER2, - "layer3+4": BOND_XMIT_HASH_POLICY_LAYER3_4, - "layer2+3": BOND_XMIT_HASH_POLICY_LAYER2_3, - "encap2+3": BOND_XMIT_HASH_POLICY_ENCAP2_3, - "encap3+4": BOND_XMIT_HASH_POLICY_ENCAP3_4, + "layer2": BOND_XMIT_HASH_POLICY_LAYER2, + "layer3+4": BOND_XMIT_HASH_POLICY_LAYER3_4, + "layer2+3": BOND_XMIT_HASH_POLICY_LAYER2_3, + "encap2+3": BOND_XMIT_HASH_POLICY_ENCAP2_3, + "encap3+4": BOND_XMIT_HASH_POLICY_ENCAP3_4, "vlan+srcmac": BOND_XMIT_HASH_POLICY_VLAN_SRCMAC, } @@ -808,6 +816,7 @@ var bondLacpRateToString = map[BondLacpRate]string{ BOND_LACP_RATE_SLOW: "slow", BOND_LACP_RATE_FAST: "fast", } + var StringToBondLacpRateMap = map[string]BondLacpRate{ "slow": BOND_LACP_RATE_SLOW, "fast": BOND_LACP_RATE_FAST, @@ -828,6 +837,7 @@ var bondAdSelectToString = map[BondAdSelect]string{ BOND_AD_SELECT_BANDWIDTH: "bandwidth", BOND_AD_SELECT_COUNT: "count", } + var StringToBondAdSelectMap = map[string]BondAdSelect{ "stable": BOND_AD_SELECT_STABLE, "bandwidth": BOND_AD_SELECT_BANDWIDTH, @@ -956,9 +966,9 @@ func (bond *Bond) Type() string { type BondSlaveState uint8 const ( - //BondStateActive Link is active. + // BondStateActive Link is active. BondStateActive BondSlaveState = iota - //BondStateBackup Link is backup. + // BondStateBackup Link is backup. BondStateBackup ) @@ -978,13 +988,13 @@ func (s BondSlaveState) String() string { type BondSlaveMiiStatus uint8 const ( - //BondLinkUp link is up and running. + // BondLinkUp link is up and running. BondLinkUp BondSlaveMiiStatus = iota - //BondLinkFail link has just gone down. + // BondLinkFail link has just gone down. BondLinkFail - //BondLinkDown link has been down for too long time. + // BondLinkDown link has been down for too long time. BondLinkDown - //BondLinkBack link is going back. + // BondLinkBack link is going back. BondLinkBack ) diff --git a/link_linux.go b/link_linux.go index dca26162..89fe3eb7 100644 --- a/link_linux.go +++ b/link_linux.go @@ -1413,7 +1413,7 @@ func (h *Handle) linkModify(link Link, flags int) error { req.Flags = uint16(tuntap.Flags) - if queues == 0 { //Legacy compatibility + if queues == 0 { // Legacy compatibility queues = 1 if tuntap.Flags == 0 { req.Flags = uint16(TUNTAP_DEFAULTS) @@ -2415,7 +2415,8 @@ func LinkSubscribeWithOptions(ch chan<- LinkUpdate, done <-chan struct{}, option } func linkSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- LinkUpdate, done <-chan struct{}, cberr func(error), listExisting bool, - rcvbuf int, rcvTimeout *unix.Timeval, rcvbufForce bool) error { + rcvbuf int, rcvTimeout *unix.Timeval, rcvbufForce bool, +) error { s, err := nl.SubscribeAt(newNs, curNs, unix.NETLINK_ROUTE, unix.RTNLGRP_LINK) if err != nil { return err @@ -2606,6 +2607,7 @@ func (h *Handle) setProtinfoAttrRawVal(link Link, val []byte, attr int) error { } return nil } + func (h *Handle) setProtinfoAttr(link Link, mode bool, attr int) error { return h.setProtinfoAttrRawVal(link, boolToByte(mode), attr) } @@ -3833,7 +3835,7 @@ type vethEthtoolStats struct { } func vethStatsDeserialize(b []byte) (vethEthtoolStats, error) { - var stats = vethEthtoolStats{} + stats := vethEthtoolStats{} err := binary.Read(bytes.NewReader(b), nl.NativeEndian(), &stats) return stats, err } @@ -3912,7 +3914,6 @@ func parseIPoIBData(link Link, data []syscall.NetlinkRouteAttr) { func parseCanData(link Link, data []syscall.NetlinkRouteAttr) { can := link.(*Can) for _, datum := range data { - switch datum.Attr.Type { case nl.IFLA_CAN_BITTIMING: can.BitRate = native.Uint32(datum.Value) diff --git a/link_test.go b/link_test.go index eb7bd228..bfa17c37 100644 --- a/link_test.go +++ b/link_test.go @@ -104,7 +104,6 @@ func testLinkAddDel(t *testing.T, link Link) { } } } - } if veth, ok := result.(*Veth); ok { @@ -540,7 +539,6 @@ func compareGretun(t *testing.T, expected, actual *Gretun) { } func compareVxlan(t *testing.T, expected, actual *Vxlan) { - if actual.VxlanId != expected.VxlanId { t.Fatal("Vxlan.VxlanId doesn't match") } @@ -725,12 +723,14 @@ func TestLinkAddDelGeneve(t *testing.T) { testLinkAddDel(t, &Geneve{ LinkAttrs: LinkAttrs{Name: "foo4", EncapType: "geneve"}, ID: 0x1000, - Remote: net.IPv4(127, 0, 0, 1)}) + Remote: net.IPv4(127, 0, 0, 1), + }) testLinkAddDel(t, &Geneve{ LinkAttrs: LinkAttrs{Name: "foo6", EncapType: "geneve"}, ID: 0x1000, - Remote: net.ParseIP("2001:db8:ef33::2")}) + Remote: net.ParseIP("2001:db8:ef33::2"), + }) } func TestLinkAddDelGeneveFlowBased(t *testing.T) { @@ -740,7 +740,8 @@ func TestLinkAddDelGeneveFlowBased(t *testing.T) { testLinkAddDel(t, &Geneve{ LinkAttrs: LinkAttrs{Name: "foo"}, Dport: 1234, - FlowBased: true}) + FlowBased: true, + }) } func TestGeneveCompareToIP(t *testing.T) { @@ -792,14 +793,16 @@ func TestLinkAddDelGretap(t *testing.T) { OKey: 0x101, PMtuDisc: 1, Local: net.IPv4(127, 0, 0, 1), - Remote: net.IPv4(127, 0, 0, 1)}) + Remote: net.IPv4(127, 0, 0, 1), + }) testLinkAddDel(t, &Gretap{ LinkAttrs: LinkAttrs{Name: "foo6"}, IKey: 0x101, OKey: 0x101, Local: net.ParseIP("2001:db8:abcd::1"), - Remote: net.ParseIP("2001:db8:ef33::2")}) + Remote: net.ParseIP("2001:db8:ef33::2"), + }) } func TestLinkAddDelGretun(t *testing.T) { @@ -809,12 +812,14 @@ func TestLinkAddDelGretun(t *testing.T) { testLinkAddDel(t, &Gretun{ LinkAttrs: LinkAttrs{Name: "foo4"}, Local: net.IPv4(127, 0, 0, 1), - Remote: net.IPv4(127, 0, 0, 1)}) + Remote: net.IPv4(127, 0, 0, 1), + }) testLinkAddDel(t, &Gretun{ LinkAttrs: LinkAttrs{Name: "foo6"}, Local: net.ParseIP("2001:db8:abcd::1"), - Remote: net.ParseIP("2001:db8:ef33::2")}) + Remote: net.ParseIP("2001:db8:ef33::2"), + }) } func TestLinkAddDelGretunPointToMultiPoint(t *testing.T) { @@ -825,13 +830,15 @@ func TestLinkAddDelGretunPointToMultiPoint(t *testing.T) { LinkAttrs: LinkAttrs{Name: "foo"}, Local: net.IPv4(127, 0, 0, 1), IKey: 1234, - OKey: 1234}) + OKey: 1234, + }) testLinkAddDel(t, &Gretun{ LinkAttrs: LinkAttrs{Name: "foo6"}, Local: net.ParseIP("2001:db8:1234::4"), IKey: 5678, - OKey: 7890}) + OKey: 7890, + }) } func TestLinkAddDelGretunFlowBased(t *testing.T) { @@ -842,7 +849,8 @@ func TestLinkAddDelGretunFlowBased(t *testing.T) { testLinkAddDel(t, &Gretun{ LinkAttrs: LinkAttrs{Name: "foo"}, - FlowBased: true}) + FlowBased: true, + }) } func TestLinkAddDelGretapFlowBased(t *testing.T) { @@ -853,7 +861,8 @@ func TestLinkAddDelGretapFlowBased(t *testing.T) { testLinkAddDel(t, &Gretap{ LinkAttrs: LinkAttrs{Name: "foo"}, - FlowBased: true}) + FlowBased: true, + }) } func TestLinkAddDelVlan(t *testing.T) { @@ -1434,7 +1443,6 @@ func TestLinkSetNs(t *testing.T) { if err == nil { t.Fatal("Other half of veth pair not deleted") } - } func TestLinkAddDelWireguard(t *testing.T) { @@ -2003,7 +2011,6 @@ func TestLinkAltName(t *testing.T) { t.Fatalf("Expected %s AltNames, got %s", altNamesStr, linkAltNamesStr) } } - } func TestLinkSetARP(t *testing.T) { @@ -2208,7 +2215,8 @@ func TestLinkSubscribeListExisting(t *testing.T) { defer close(done) if err := LinkSubscribeWithOptions(ch, done, LinkSubscribeOptions{ Namespace: &newNs, - ListExisting: true}, + ListExisting: true, + }, ); err != nil { t.Fatal(err) } @@ -2321,7 +2329,8 @@ func TestLinkAddDelIptun(t *testing.T) { LinkAttrs: LinkAttrs{Name: "iptunfoo"}, PMtuDisc: 1, Local: net.IPv4(127, 0, 0, 1), - Remote: net.IPv4(127, 0, 0, 1)}) + Remote: net.IPv4(127, 0, 0, 1), + }) } func TestLinkAddDelIptunFlowBased(t *testing.T) { @@ -2364,7 +2373,8 @@ func TestLinkAddDelSittun(t *testing.T) { LinkAttrs: LinkAttrs{Name: "sittunfoo"}, PMtuDisc: 1, Local: net.IPv4(127, 0, 0, 1), - Remote: net.IPv4(127, 0, 0, 1)}) + Remote: net.IPv4(127, 0, 0, 1), + }) } func TestLinkAddDelVti(t *testing.T) { @@ -2376,14 +2386,16 @@ func TestLinkAddDelVti(t *testing.T) { IKey: 0x101, OKey: 0x101, Local: net.IPv4(127, 0, 0, 1), - Remote: net.IPv4(127, 0, 0, 1)}) + Remote: net.IPv4(127, 0, 0, 1), + }) testLinkAddDel(t, &Vti{ LinkAttrs: LinkAttrs{Name: "vtibar"}, IKey: 0x101, OKey: 0x101, Local: net.IPv6loopback, - Remote: net.IPv6loopback}) + Remote: net.IPv6loopback, + }) } func TestLinkSetGSOMaxSize(t *testing.T) { @@ -2943,7 +2955,8 @@ func TestLinkAddDelXfrmi(t *testing.T) { testLinkAddDel(t, &Xfrmi{ LinkAttrs: LinkAttrs{Name: "xfrm123", ParentIndex: lo.Attrs().Index}, - Ifid: 123}) + Ifid: 123, + }) } func TestLinkAddDelXfrmiNoId(t *testing.T) { @@ -2953,11 +2966,11 @@ func TestLinkAddDelXfrmiNoId(t *testing.T) { lo, _ := LinkByName("lo") err := LinkAdd(&Xfrmi{ - LinkAttrs: LinkAttrs{Name: "xfrm0", ParentIndex: lo.Attrs().Index}}) + LinkAttrs: LinkAttrs{Name: "xfrm0", ParentIndex: lo.Attrs().Index}, + }) if !errors.Is(err, unix.EINVAL) { t.Errorf("Error returned expected to be EINVAL") } - } func TestLinkByNameWhenLinkIsNotFound(t *testing.T) { @@ -3002,7 +3015,8 @@ func TestLinkAddDelTuntap(t *testing.T) { testLinkAddDel(t, &Tuntap{ LinkAttrs: LinkAttrs{Name: "foo"}, - Mode: TUNTAP_MODE_TAP}) + Mode: TUNTAP_MODE_TAP, + }) } func TestLinkAddDelTuntapMq(t *testing.T) { @@ -3022,13 +3036,15 @@ func TestLinkAddDelTuntapMq(t *testing.T) { testLinkAddDel(t, &Tuntap{ LinkAttrs: LinkAttrs{Name: "foo"}, Mode: TUNTAP_MODE_TAP, - Queues: 4}) + Queues: 4, + }) testLinkAddDel(t, &Tuntap{ LinkAttrs: LinkAttrs{Name: "foo"}, Mode: TUNTAP_MODE_TAP, Queues: 4, - Flags: TUNTAP_MULTI_QUEUE_DEFAULTS | TUNTAP_VNET_HDR}) + Flags: TUNTAP_MULTI_QUEUE_DEFAULTS | TUNTAP_VNET_HDR, + }) } func TestLinkAddDelTuntapOwnerGroup(t *testing.T) { diff --git a/neigh.go b/neigh.go index 32d722e8..66d1ee8b 100644 --- a/neigh.go +++ b/neigh.go @@ -15,7 +15,7 @@ type Neigh struct { FlagsExt int IP net.IP HardwareAddr net.HardwareAddr - LLIPAddr net.IP //Used in the case of NHRP + LLIPAddr net.IP // Used in the case of NHRP Vlan int VNI int MasterIndex int diff --git a/neigh_linux.go b/neigh_linux.go index 1c6f2958..ca228df4 100644 --- a/neigh_linux.go +++ b/neigh_linux.go @@ -397,7 +397,8 @@ func NeighSubscribeWithOptions(ch chan<- NeighUpdate, done <-chan struct{}, opti } func neighSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- NeighUpdate, done <-chan struct{}, cberr func(error), listExisting bool, - rcvbuf int, rcvTimeout *unix.Timeval, rcvbufForce bool) error { + rcvbuf int, rcvTimeout *unix.Timeval, rcvbufForce bool, +) error { s, err := nl.SubscribeAt(newNs, curNs, unix.NETLINK_ROUTE, unix.RTNLGRP_NEIGH) makeRequest := func(family int) error { req := pkgHandle.newNetlinkRequest(unix.RTM_GETNEIGH, unix.NLM_F_DUMP) diff --git a/neigh_test.go b/neigh_test.go index bf52cd80..7591b387 100644 --- a/neigh_test.go +++ b/neigh_test.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package netlink @@ -76,7 +77,8 @@ func TestNeighAddDelLLIPAddr(t *testing.T) { LinkAttrs: LinkAttrs{Name: "neigh0"}, Local: net.IPv4(127, 0, 0, 1), IKey: 1234, - OKey: 1234} + OKey: 1234, + } if err := LinkAdd(&dummy); err != nil { t.Errorf("Failed to create link: %v", err) } @@ -142,7 +144,6 @@ func TestNeighAddDel(t *testing.T) { IP: entry.ip, HardwareAddr: entry.mac, }) - if err != nil { t.Errorf("Failed to NeighAdd: %v", err) } @@ -167,7 +168,6 @@ func TestNeighAddDel(t *testing.T) { IP: entry.ip, HardwareAddr: entry.mac, }) - if err != nil { t.Errorf("Failed to NeighDel: %v", err) } @@ -217,7 +217,6 @@ func TestNeighAddDelProxy(t *testing.T) { Flags: NTF_PROXY, IP: entry.ip, }) - if err != nil { t.Errorf("Failed to NeighAdd: %v", err) } @@ -242,7 +241,6 @@ func TestNeighAddDelProxy(t *testing.T) { Flags: NTF_PROXY, IP: entry.ip, }) - if err != nil { t.Errorf("Failed to NeighDel: %v", err) } @@ -324,7 +322,7 @@ func TestNeighSubscribe(t *testing.T) { if err := NeighAdd(entry); err != nil { t.Errorf("Failed to NeighAdd: %v", err) } - if !expectNeighUpdate(ch, []NeighUpdate{NeighUpdate{ + if !expectNeighUpdate(ch, []NeighUpdate{{ Type: unix.RTM_NEWNEIGH, Neigh: *entry, }}) { @@ -333,11 +331,12 @@ func TestNeighSubscribe(t *testing.T) { if err := NeighDel(entry); err != nil { t.Fatal(err) } - if !expectNeighUpdate(ch, []NeighUpdate{NeighUpdate{ + if !expectNeighUpdate(ch, []NeighUpdate{{ Type: unix.RTM_NEWNEIGH, Neigh: Neigh{ State: NUD_FAILED, - IP: entry.IP}, + IP: entry.IP, + }, }}) { t.Fatalf("Del update not received as expected") } @@ -386,7 +385,7 @@ func TestNeighSubscribeWithOptions(t *testing.T) { if err != nil { t.Errorf("Failed to NeighAdd: %v", err) } - if !expectNeighUpdate(ch, []NeighUpdate{NeighUpdate{ + if !expectNeighUpdate(ch, []NeighUpdate{{ Type: unix.RTM_NEWNEIGH, Neigh: *entry, }}) { @@ -440,7 +439,7 @@ func TestNeighSubscribeAt(t *testing.T) { if err != nil { t.Errorf("Failed to NeighAdd: %v", err) } - if !expectNeighUpdate(ch, []NeighUpdate{NeighUpdate{ + if !expectNeighUpdate(ch, []NeighUpdate{{ Type: unix.RTM_NEWNEIGH, Neigh: *entry, }}) { @@ -517,17 +516,18 @@ func TestNeighSubscribeListExisting(t *testing.T) { defer close(done) if err := NeighSubscribeWithOptions(ch, done, NeighSubscribeOptions{ Namespace: &newNs, - ListExisting: true}, + ListExisting: true, + }, ); err != nil { t.Fatal(err) } if !expectNeighUpdate(ch, []NeighUpdate{ - NeighUpdate{ + { Type: unix.RTM_NEWNEIGH, Neigh: *entry1, }, - NeighUpdate{ + { Type: unix.RTM_NEWNEIGH, Neigh: *entryBr, }, @@ -547,7 +547,7 @@ func TestNeighSubscribeListExisting(t *testing.T) { t.Errorf("Failed to NeighAdd: %v", err) } - if !expectNeighUpdate(ch, []NeighUpdate{NeighUpdate{ + if !expectNeighUpdate(ch, []NeighUpdate{{ Type: unix.RTM_NEWNEIGH, Neigh: *entry2, }}) { @@ -588,7 +588,6 @@ func TestNeighListExecuteStateFilter(t *testing.T) { IP: entry.ip, HardwareAddr: entry.mac, }) - if err != nil { t.Errorf("Failed to NeighAdd: %v", err) } @@ -601,7 +600,6 @@ func TestNeighListExecuteStateFilter(t *testing.T) { IP: entry.ip, HardwareAddr: entry.mac, }) - if err != nil { t.Errorf("Failed to NeighAdd: %v", err) } @@ -634,7 +632,6 @@ func TestNeighListExecuteStateFilter(t *testing.T) { IP: entry.ip, HardwareAddr: entry.mac, }) - if err != nil { t.Errorf("Failed to NeighDel: %v", err) } diff --git a/netlink.go b/netlink.go index 9cb685dc..d7660109 100644 --- a/netlink.go +++ b/netlink.go @@ -13,10 +13,8 @@ import ( "net" ) -var ( - // ErrNotImplemented is returned when a requested feature is not implemented. - ErrNotImplemented = errors.New("not implemented") -) +// ErrNotImplemented is returned when a requested feature is not implemented. +var ErrNotImplemented = errors.New("not implemented") // ParseIPNet parses a string in ip/net format and returns a net.IPNet. // This is valuable because addresses in netlink are often IPNets and diff --git a/netlink_test.go b/netlink_test.go index ed0059ae..f247338a 100644 --- a/netlink_test.go +++ b/netlink_test.go @@ -195,6 +195,7 @@ func setUpNetlinkTestWithKModule(t *testing.T, moduleNames ...string) tearDownNe skipUnlessKModuleLoaded(t, moduleNames...) return setUpNetlinkTest(t) } + func setUpNamedNetlinkTestWithKModule(t *testing.T, moduleNames ...string) (string, tearDownNetlinkTest) { file, err := ioutil.ReadFile("/proc/modules") if err != nil { diff --git a/netlink_unspecified.go b/netlink_unspecified.go index da12c42a..f9587076 100644 --- a/netlink_unspecified.go +++ b/netlink_unspecified.go @@ -1,3 +1,4 @@ +//go:build !linux // +build !linux package netlink diff --git a/netns_linux.go b/netns_linux.go index 2eb29c7c..6fa05747 100644 --- a/netns_linux.go +++ b/netns_linux.go @@ -93,7 +93,6 @@ func (h *Handle) getNetNsId(attrType int, val uint32) (int, error) { req.AddData(attr) msgs, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWNSID) - if err != nil { return 0, err } diff --git a/netns_test.go b/netns_test.go index e18169ae..ec97ee48 100644 --- a/netns_test.go +++ b/netns_test.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package netlink @@ -71,7 +72,7 @@ func TestNetNsIdByPid(t *testing.T) { err = h.SetNetNsIdByPid(syscall.Gettid(), wantID) CheckErrorFail(t, err) - //Get the ID and see if it worked + // Get the ID and see if it worked haveID, _ := h.GetNetNsIdByPid(syscall.Gettid()) if haveID != wantID { t.Errorf("GetNetNsIdByPid returned %d, want %d", haveID, wantID) diff --git a/netns_unspecified.go b/netns_unspecified.go index 5c5899e3..a187cf8c 100644 --- a/netns_unspecified.go +++ b/netns_unspecified.go @@ -1,3 +1,4 @@ +//go:build !linux // +build !linux package netlink diff --git a/nl/addr_linux_test.go b/nl/addr_linux_test.go index b2cbb443..28894c8f 100644 --- a/nl/addr_linux_test.go +++ b/nl/addr_linux_test.go @@ -26,13 +26,13 @@ func (msg *IfAddrmsg) serializeSafe() []byte { } func deserializeIfAddrmsgSafe(b []byte) *IfAddrmsg { - var msg = IfAddrmsg{} + msg := IfAddrmsg{} binary.Read(bytes.NewReader(b[0:unix.SizeofIfAddrmsg]), NativeEndian(), &msg) return &msg } func TestIfAddrmsgDeserializeSerialize(t *testing.T) { - var orig = make([]byte, unix.SizeofIfAddrmsg) + orig := make([]byte, unix.SizeofIfAddrmsg) rand.Read(orig) safemsg := deserializeIfAddrmsgSafe(orig) msg := DeserializeIfAddrmsg(orig) @@ -55,13 +55,13 @@ func (msg *IfaCacheInfo) serializeSafe() []byte { } func deserializeIfaCacheInfoSafe(b []byte) *IfaCacheInfo { - var msg = IfaCacheInfo{} + msg := IfaCacheInfo{} binary.Read(bytes.NewReader(b[0:unix.SizeofIfaCacheinfo]), NativeEndian(), &msg) return &msg } func TestIfaCacheInfoDeserializeSerialize(t *testing.T) { - var orig = make([]byte, unix.SizeofIfaCacheinfo) + orig := make([]byte, unix.SizeofIfaCacheinfo) rand.Read(orig) safemsg := deserializeIfaCacheInfoSafe(orig) msg := DeserializeIfaCacheInfo(orig) diff --git a/nl/bridge_linux_test.go b/nl/bridge_linux_test.go index 8f952fcd..16d19f81 100644 --- a/nl/bridge_linux_test.go +++ b/nl/bridge_linux_test.go @@ -21,13 +21,13 @@ func (msg *BridgeVlanInfo) serializeSafe() []byte { } func deserializeBridgeVlanInfoSafe(b []byte) *BridgeVlanInfo { - var msg = BridgeVlanInfo{} + msg := BridgeVlanInfo{} binary.Read(bytes.NewReader(b[0:SizeofBridgeVlanInfo]), NativeEndian(), &msg) return &msg } func TestBridgeVlanInfoDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofBridgeVlanInfo) + orig := make([]byte, SizeofBridgeVlanInfo) rand.Read(orig) safemsg := deserializeBridgeVlanInfoSafe(orig) msg := DeserializeBridgeVlanInfo(orig) diff --git a/nl/conntrack_linux.go b/nl/conntrack_linux.go index 6989d1ed..9ecc8c30 100644 --- a/nl/conntrack_linux.go +++ b/nl/conntrack_linux.go @@ -16,6 +16,7 @@ var L4ProtoMap = map[uint8]string{ } // From https://git.netfilter.org/libnetfilter_conntrack/tree/include/libnetfilter_conntrack/libnetfilter_conntrack_tcp.h +// // enum tcp_state { // TCP_CONNTRACK_NONE, // TCP_CONNTRACK_SYN_SENT, @@ -32,38 +33,38 @@ var L4ProtoMap = map[uint8]string{ // TCP_CONNTRACK_IGNORE // }; const ( - TCP_CONNTRACK_NONE = 0 - TCP_CONNTRACK_SYN_SENT = 1 - TCP_CONNTRACK_SYN_RECV = 2 - TCP_CONNTRACK_ESTABLISHED = 3 - TCP_CONNTRACK_FIN_WAIT = 4 - TCP_CONNTRACK_CLOSE_WAIT = 5 - TCP_CONNTRACK_LAST_ACK = 6 - TCP_CONNTRACK_TIME_WAIT = 7 - TCP_CONNTRACK_CLOSE = 8 - TCP_CONNTRACK_LISTEN = 9 - TCP_CONNTRACK_SYN_SENT2 = 9 - TCP_CONNTRACK_MAX = 10 - TCP_CONNTRACK_IGNORE = 11 + TCP_CONNTRACK_NONE = 0 + TCP_CONNTRACK_SYN_SENT = 1 + TCP_CONNTRACK_SYN_RECV = 2 + TCP_CONNTRACK_ESTABLISHED = 3 + TCP_CONNTRACK_FIN_WAIT = 4 + TCP_CONNTRACK_CLOSE_WAIT = 5 + TCP_CONNTRACK_LAST_ACK = 6 + TCP_CONNTRACK_TIME_WAIT = 7 + TCP_CONNTRACK_CLOSE = 8 + TCP_CONNTRACK_LISTEN = 9 + TCP_CONNTRACK_SYN_SENT2 = 9 + TCP_CONNTRACK_MAX = 10 + TCP_CONNTRACK_IGNORE = 11 ) // All the following constants are coming from: // https://github.com/torvalds/linux/blob/master/include/uapi/linux/netfilter/nfnetlink_conntrack.h -// enum cntl_msg_types { -// IPCTNL_MSG_CT_NEW, -// IPCTNL_MSG_CT_GET, -// IPCTNL_MSG_CT_DELETE, -// IPCTNL_MSG_CT_GET_CTRZERO, -// IPCTNL_MSG_CT_GET_STATS_CPU, -// IPCTNL_MSG_CT_GET_STATS, -// IPCTNL_MSG_CT_GET_DYING, -// IPCTNL_MSG_CT_GET_UNCONFIRMED, +// enum cntl_msg_types { +// IPCTNL_MSG_CT_NEW, +// IPCTNL_MSG_CT_GET, +// IPCTNL_MSG_CT_DELETE, +// IPCTNL_MSG_CT_GET_CTRZERO, +// IPCTNL_MSG_CT_GET_STATS_CPU, +// IPCTNL_MSG_CT_GET_STATS, +// IPCTNL_MSG_CT_GET_DYING, +// IPCTNL_MSG_CT_GET_UNCONFIRMED, // -// IPCTNL_MSG_MAX -// }; +// IPCTNL_MSG_MAX +// }; const ( - IPCTNL_MSG_CT_NEW = 0 + IPCTNL_MSG_CT_NEW = 0 IPCTNL_MSG_CT_GET = 1 IPCTNL_MSG_CT_DELETE = 2 ) @@ -80,36 +81,38 @@ const ( NLA_ALIGNTO uint16 = 4 // #define NLA_ALIGNTO 4 ) -// enum ctattr_type { -// CTA_UNSPEC, -// CTA_TUPLE_ORIG, -// CTA_TUPLE_REPLY, -// CTA_STATUS, -// CTA_PROTOINFO, -// CTA_HELP, -// CTA_NAT_SRC, +// enum ctattr_type { +// CTA_UNSPEC, +// CTA_TUPLE_ORIG, +// CTA_TUPLE_REPLY, +// CTA_STATUS, +// CTA_PROTOINFO, +// CTA_HELP, +// CTA_NAT_SRC, +// // #define CTA_NAT CTA_NAT_SRC /* backwards compatibility */ -// CTA_TIMEOUT, -// CTA_MARK, -// CTA_COUNTERS_ORIG, -// CTA_COUNTERS_REPLY, -// CTA_USE, -// CTA_ID, -// CTA_NAT_DST, -// CTA_TUPLE_MASTER, -// CTA_SEQ_ADJ_ORIG, -// CTA_NAT_SEQ_ADJ_ORIG = CTA_SEQ_ADJ_ORIG, -// CTA_SEQ_ADJ_REPLY, -// CTA_NAT_SEQ_ADJ_REPLY = CTA_SEQ_ADJ_REPLY, -// CTA_SECMARK, /* obsolete */ -// CTA_ZONE, -// CTA_SECCTX, -// CTA_TIMESTAMP, -// CTA_MARK_MASK, -// CTA_LABELS, -// CTA_LABELS_MASK, -// __CTA_MAX -// }; +// +// CTA_TIMEOUT, +// CTA_MARK, +// CTA_COUNTERS_ORIG, +// CTA_COUNTERS_REPLY, +// CTA_USE, +// CTA_ID, +// CTA_NAT_DST, +// CTA_TUPLE_MASTER, +// CTA_SEQ_ADJ_ORIG, +// CTA_NAT_SEQ_ADJ_ORIG = CTA_SEQ_ADJ_ORIG, +// CTA_SEQ_ADJ_REPLY, +// CTA_NAT_SEQ_ADJ_REPLY = CTA_SEQ_ADJ_REPLY, +// CTA_SECMARK, /* obsolete */ +// CTA_ZONE, +// CTA_SECCTX, +// CTA_TIMESTAMP, +// CTA_MARK_MASK, +// CTA_LABELS, +// CTA_LABELS_MASK, +// __CTA_MAX +// }; const ( CTA_TUPLE_ORIG = 1 CTA_TUPLE_REPLY = 2 @@ -127,27 +130,29 @@ const ( CTA_LABELS_MASK = 23 ) -// enum ctattr_tuple { -// CTA_TUPLE_UNSPEC, -// CTA_TUPLE_IP, -// CTA_TUPLE_PROTO, -// CTA_TUPLE_ZONE, -// __CTA_TUPLE_MAX -// }; +// enum ctattr_tuple { +// CTA_TUPLE_UNSPEC, +// CTA_TUPLE_IP, +// CTA_TUPLE_PROTO, +// CTA_TUPLE_ZONE, +// __CTA_TUPLE_MAX +// }; +// // #define CTA_TUPLE_MAX (__CTA_TUPLE_MAX - 1) const ( CTA_TUPLE_IP = 1 CTA_TUPLE_PROTO = 2 ) -// enum ctattr_ip { -// CTA_IP_UNSPEC, -// CTA_IP_V4_SRC, -// CTA_IP_V4_DST, -// CTA_IP_V6_SRC, -// CTA_IP_V6_DST, -// __CTA_IP_MAX -// }; +// enum ctattr_ip { +// CTA_IP_UNSPEC, +// CTA_IP_V4_SRC, +// CTA_IP_V4_DST, +// CTA_IP_V6_SRC, +// CTA_IP_V6_DST, +// __CTA_IP_MAX +// }; +// // #define CTA_IP_MAX (__CTA_IP_MAX - 1) const ( CTA_IP_V4_SRC = 1 @@ -156,19 +161,20 @@ const ( CTA_IP_V6_DST = 4 ) -// enum ctattr_l4proto { -// CTA_PROTO_UNSPEC, -// CTA_PROTO_NUM, -// CTA_PROTO_SRC_PORT, -// CTA_PROTO_DST_PORT, -// CTA_PROTO_ICMP_ID, -// CTA_PROTO_ICMP_TYPE, -// CTA_PROTO_ICMP_CODE, -// CTA_PROTO_ICMPV6_ID, -// CTA_PROTO_ICMPV6_TYPE, -// CTA_PROTO_ICMPV6_CODE, -// __CTA_PROTO_MAX -// }; +// enum ctattr_l4proto { +// CTA_PROTO_UNSPEC, +// CTA_PROTO_NUM, +// CTA_PROTO_SRC_PORT, +// CTA_PROTO_DST_PORT, +// CTA_PROTO_ICMP_ID, +// CTA_PROTO_ICMP_TYPE, +// CTA_PROTO_ICMP_CODE, +// CTA_PROTO_ICMPV6_ID, +// CTA_PROTO_ICMPV6_TYPE, +// CTA_PROTO_ICMPV6_CODE, +// __CTA_PROTO_MAX +// }; +// // #define CTA_PROTO_MAX (__CTA_PROTO_MAX - 1) const ( CTA_PROTO_NUM = 1 @@ -176,30 +182,32 @@ const ( CTA_PROTO_DST_PORT = 3 ) -// enum ctattr_protoinfo { -// CTA_PROTOINFO_UNSPEC, -// CTA_PROTOINFO_TCP, -// CTA_PROTOINFO_DCCP, -// CTA_PROTOINFO_SCTP, -// __CTA_PROTOINFO_MAX -// }; +// enum ctattr_protoinfo { +// CTA_PROTOINFO_UNSPEC, +// CTA_PROTOINFO_TCP, +// CTA_PROTOINFO_DCCP, +// CTA_PROTOINFO_SCTP, +// __CTA_PROTOINFO_MAX +// }; +// // #define CTA_PROTOINFO_MAX (__CTA_PROTOINFO_MAX - 1) const ( CTA_PROTOINFO_UNSPEC = 0 - CTA_PROTOINFO_TCP = 1 - CTA_PROTOINFO_DCCP = 2 - CTA_PROTOINFO_SCTP = 3 + CTA_PROTOINFO_TCP = 1 + CTA_PROTOINFO_DCCP = 2 + CTA_PROTOINFO_SCTP = 3 ) -// enum ctattr_protoinfo_tcp { -// CTA_PROTOINFO_TCP_UNSPEC, -// CTA_PROTOINFO_TCP_STATE, -// CTA_PROTOINFO_TCP_WSCALE_ORIGINAL, -// CTA_PROTOINFO_TCP_WSCALE_REPLY, -// CTA_PROTOINFO_TCP_FLAGS_ORIGINAL, -// CTA_PROTOINFO_TCP_FLAGS_REPLY, -// __CTA_PROTOINFO_TCP_MAX -// }; +// enum ctattr_protoinfo_tcp { +// CTA_PROTOINFO_TCP_UNSPEC, +// CTA_PROTOINFO_TCP_STATE, +// CTA_PROTOINFO_TCP_WSCALE_ORIGINAL, +// CTA_PROTOINFO_TCP_WSCALE_REPLY, +// CTA_PROTOINFO_TCP_FLAGS_ORIGINAL, +// CTA_PROTOINFO_TCP_FLAGS_REPLY, +// __CTA_PROTOINFO_TCP_MAX +// }; +// // #define CTA_PROTOINFO_TCP_MAX (__CTA_PROTOINFO_TCP_MAX - 1) const ( CTA_PROTOINFO_TCP_STATE = 1 @@ -209,15 +217,16 @@ const ( CTA_PROTOINFO_TCP_FLAGS_REPLY = 5 ) -// enum ctattr_counters { -// CTA_COUNTERS_UNSPEC, -// CTA_COUNTERS_PACKETS, /* 64bit counters */ -// CTA_COUNTERS_BYTES, /* 64bit counters */ -// CTA_COUNTERS32_PACKETS, /* old 32bit counters, unused */ -// CTA_COUNTERS32_BYTES, /* old 32bit counters, unused */ -// CTA_COUNTERS_PAD, -// __CTA_COUNTERS_M -// }; +// enum ctattr_counters { +// CTA_COUNTERS_UNSPEC, +// CTA_COUNTERS_PACKETS, /* 64bit counters */ +// CTA_COUNTERS_BYTES, /* 64bit counters */ +// CTA_COUNTERS32_PACKETS, /* old 32bit counters, unused */ +// CTA_COUNTERS32_BYTES, /* old 32bit counters, unused */ +// CTA_COUNTERS_PAD, +// __CTA_COUNTERS_M +// }; +// // #define CTA_COUNTERS_MAX (__CTA_COUNTERS_MAX - 1) const ( CTA_COUNTERS_PACKETS = 1 @@ -232,13 +241,14 @@ const ( CTA_TIMESTAMP_STOP = 2 ) -// /* General form of address family dependent message. -// */ -// struct nfgenmsg { -// __u8 nfgen_family; /* AF_xxx */ -// __u8 version; /* nfnetlink version */ -// __be16 res_id; /* resource id */ -// }; +// General form of address family dependent message. +// +// struct nfgenmsg { +// __u8 nfgen_family; /* AF_xxx */ +// __u8 version; /* nfnetlink version */ +// __be16 res_id; /* resource id */ +// }; + type Nfgenmsg struct { NfgenFamily uint8 Version uint8 diff --git a/nl/ip6tnl_linux.go b/nl/ip6tnl_linux.go index d5dd69e0..aaef8905 100644 --- a/nl/ip6tnl_linux.go +++ b/nl/ip6tnl_linux.go @@ -11,11 +11,7 @@ const ( LWTUNNEL_IP6_HOPLIMIT LWTUNNEL_IP6_TC LWTUNNEL_IP6_FLAGS - LWTUNNEL_IP6_PAD // not implemented + LWTUNNEL_IP6_PAD // not implemented LWTUNNEL_IP6_OPTS // not implemented __LWTUNNEL_IP6_MAX ) - - - - diff --git a/nl/ipset_linux.go b/nl/ipset_linux.go index 89dd009d..76c18efd 100644 --- a/nl/ipset_linux.go +++ b/nl/ipset_linux.go @@ -211,11 +211,9 @@ func GetIpsetFlags(cmd int) int { IPSET_CMD_SWAP, IPSET_CMD_TEST: return unix.NLM_F_REQUEST | unix.NLM_F_ACK - case IPSET_CMD_LIST, - IPSET_CMD_SAVE: + case IPSET_CMD_LIST, IPSET_CMD_SAVE: return unix.NLM_F_REQUEST | unix.NLM_F_ACK | unix.NLM_F_ROOT | unix.NLM_F_MATCH | unix.NLM_F_DUMP - case IPSET_CMD_ADD, - IPSET_CMD_DEL: + case IPSET_CMD_ADD, IPSET_CMD_DEL: return unix.NLM_F_REQUEST | unix.NLM_F_ACK case IPSET_CMD_HEADER, IPSET_CMD_TYPE, diff --git a/nl/link_linux_test.go b/nl/link_linux_test.go index ec8dff0c..91bf7ca8 100644 --- a/nl/link_linux_test.go +++ b/nl/link_linux_test.go @@ -21,13 +21,13 @@ func (msg *VfMac) serializeSafe() []byte { } func deserializeVfMacSafe(b []byte) *VfMac { - var msg = VfMac{} + msg := VfMac{} binary.Read(bytes.NewReader(b[0:SizeofVfMac]), NativeEndian(), &msg) return &msg } func TestVfMacDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofVfMac) + orig := make([]byte, SizeofVfMac) rand.Read(orig) safemsg := deserializeVfMacSafe(orig) msg := DeserializeVfMac(orig) @@ -49,13 +49,13 @@ func (msg *VfVlan) serializeSafe() []byte { } func deserializeVfVlanSafe(b []byte) *VfVlan { - var msg = VfVlan{} + msg := VfVlan{} binary.Read(bytes.NewReader(b[0:SizeofVfVlan]), NativeEndian(), &msg) return &msg } func TestVfVlanDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofVfVlan) + orig := make([]byte, SizeofVfVlan) rand.Read(orig) safemsg := deserializeVfVlanSafe(orig) msg := DeserializeVfVlan(orig) @@ -76,13 +76,13 @@ func (msg *VfTxRate) serializeSafe() []byte { } func deserializeVfTxRateSafe(b []byte) *VfTxRate { - var msg = VfTxRate{} + msg := VfTxRate{} binary.Read(bytes.NewReader(b[0:SizeofVfTxRate]), NativeEndian(), &msg) return &msg } func TestVfTxRateDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofVfTxRate) + orig := make([]byte, SizeofVfTxRate) rand.Read(orig) safemsg := deserializeVfTxRateSafe(orig) msg := DeserializeVfTxRate(orig) @@ -104,13 +104,13 @@ func (msg *VfRate) serializeSafe() []byte { } func deserializeVfRateSafe(b []byte) *VfRate { - var msg = VfRate{} + msg := VfRate{} binary.Read(bytes.NewReader(b[0:SizeofVfRate]), NativeEndian(), &msg) return &msg } func TestVfRateDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofVfRate) + orig := make([]byte, SizeofVfRate) rand.Read(orig) safemsg := deserializeVfRateSafe(orig) msg := DeserializeVfRate(orig) @@ -131,13 +131,13 @@ func (msg *VfSpoofchk) serializeSafe() []byte { } func deserializeVfSpoofchkSafe(b []byte) *VfSpoofchk { - var msg = VfSpoofchk{} + msg := VfSpoofchk{} binary.Read(bytes.NewReader(b[0:SizeofVfSpoofchk]), NativeEndian(), &msg) return &msg } func TestVfSpoofchkDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofVfSpoofchk) + orig := make([]byte, SizeofVfSpoofchk) rand.Read(orig) safemsg := deserializeVfSpoofchkSafe(orig) msg := DeserializeVfSpoofchk(orig) @@ -158,13 +158,13 @@ func (msg *VfLinkState) serializeSafe() []byte { } func deserializeVfLinkStateSafe(b []byte) *VfLinkState { - var msg = VfLinkState{} + msg := VfLinkState{} binary.Read(bytes.NewReader(b[0:SizeofVfLinkState]), NativeEndian(), &msg) return &msg } func TestVfLinkStateDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofVfLinkState) + orig := make([]byte, SizeofVfLinkState) rand.Read(orig) safemsg := deserializeVfLinkStateSafe(orig) msg := DeserializeVfLinkState(orig) @@ -185,13 +185,13 @@ func (msg *VfRssQueryEn) serializeSafe() []byte { } func deserializeVfRssQueryEnSafe(b []byte) *VfRssQueryEn { - var msg = VfRssQueryEn{} + msg := VfRssQueryEn{} binary.Read(bytes.NewReader(b[0:SizeofVfRssQueryEn]), NativeEndian(), &msg) return &msg } func TestVfRssQueryEnDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofVfRssQueryEn) + orig := make([]byte, SizeofVfRssQueryEn) rand.Read(orig) safemsg := deserializeVfRssQueryEnSafe(orig) msg := DeserializeVfRssQueryEn(orig) diff --git a/nl/nl_linux_test.go b/nl/nl_linux_test.go index 117a48a8..41094ef0 100644 --- a/nl/nl_linux_test.go +++ b/nl/nl_linux_test.go @@ -48,13 +48,13 @@ func (msg *IfInfomsg) serializeSafe() []byte { } func deserializeIfInfomsgSafe(b []byte) *IfInfomsg { - var msg = IfInfomsg{} + msg := IfInfomsg{} binary.Read(bytes.NewReader(b[0:unix.SizeofIfInfomsg]), NativeEndian(), &msg) return &msg } func TestIfInfomsgDeserializeSerialize(t *testing.T) { - var orig = make([]byte, unix.SizeofIfInfomsg) + orig := make([]byte, unix.SizeofIfInfomsg) rand.Read(orig) // zero out the pad byte orig[1] = 0 @@ -179,13 +179,13 @@ func (msg *CnMsgOp) serializeSafe() []byte { } func deserializeCnMsgOpSafe(b []byte) *CnMsgOp { - var msg = CnMsgOp{} + msg := CnMsgOp{} binary.Read(bytes.NewReader(b[0:SizeofCnMsgOp]), NativeEndian(), &msg) return &msg } func TestCnMsgOpDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofCnMsgOp) + orig := make([]byte, SizeofCnMsgOp) rand.Read(orig) safemsg := deserializeCnMsgOpSafe(orig) msg := DeserializeCnMsgOp(orig) diff --git a/nl/nl_unspecified.go b/nl/nl_unspecified.go index dfc0be66..818b93c4 100644 --- a/nl/nl_unspecified.go +++ b/nl/nl_unspecified.go @@ -1,3 +1,4 @@ +//go:build !linux // +build !linux package nl diff --git a/nl/route_linux_test.go b/nl/route_linux_test.go index 58bc569a..020b07b0 100644 --- a/nl/route_linux_test.go +++ b/nl/route_linux_test.go @@ -30,13 +30,13 @@ func (msg *RtMsg) serializeSafe() []byte { } func deserializeRtMsgSafe(b []byte) *RtMsg { - var msg = RtMsg{} + msg := RtMsg{} binary.Read(bytes.NewReader(b[0:unix.SizeofRtMsg]), NativeEndian(), &msg) return &msg } func TestRtMsgDeserializeSerialize(t *testing.T) { - var orig = make([]byte, unix.SizeofRtMsg) + orig := make([]byte, unix.SizeofRtMsg) rand.Read(orig) safemsg := deserializeRtMsgSafe(orig) msg := DeserializeRtMsg(orig) diff --git a/nl/seg6_linux.go b/nl/seg6_linux.go index fe88285f..cb86f952 100644 --- a/nl/seg6_linux.go +++ b/nl/seg6_linux.go @@ -49,6 +49,7 @@ const ( SEG6_IPTUNNEL_SRH __SEG6_IPTUNNEL_MAX ) + const ( SEG6_IPTUNNEL_MAX = __SEG6_IPTUNNEL_MAX - 1 ) @@ -121,6 +122,7 @@ func DecodeSEG6Srh(buf []byte) ([]net.IP, error) { } return srh.Segments, nil } + func EncodeSEG6Srh(segments []net.IP) ([]byte, error) { nsegs := len(segments) // nsegs: number of segments if nsegs == 0 { diff --git a/nl/seg6local_linux.go b/nl/seg6local_linux.go index 8172b847..9006f072 100644 --- a/nl/seg6local_linux.go +++ b/nl/seg6local_linux.go @@ -1,7 +1,5 @@ package nl -import () - // seg6local parameters const ( SEG6_LOCAL_UNSPEC = iota @@ -15,6 +13,7 @@ const ( SEG6_LOCAL_BPF __SEG6_LOCAL_MAX ) + const ( SEG6_LOCAL_MAX = __SEG6_LOCAL_MAX ) @@ -38,6 +37,7 @@ const ( SEG6_LOCAL_ACTION_END_BPF // 15 __SEG6_LOCAL_ACTION_MAX ) + const ( SEG6_LOCAL_ACTION_MAX = __SEG6_LOCAL_ACTION_MAX - 1 ) diff --git a/nl/syscall.go b/nl/syscall.go index b5ba039a..b46f9fe2 100644 --- a/nl/syscall.go +++ b/nl/syscall.go @@ -45,8 +45,8 @@ const ( // socket diags related const ( - SOCK_DIAG_BY_FAMILY = 20 /* linux.sock_diag.h */ - SOCK_DESTROY = 21 + SOCK_DIAG_BY_FAMILY = 20 /* linux.sock_diag.h */ + SOCK_DESTROY = 21 TCPDIAG_NOCOOKIE = 0xFFFFFFFF /* TCPDIAG_NOCOOKIE in net/ipv4/tcp_diag.h*/ ) diff --git a/nl/tc_linux.go b/nl/tc_linux.go index 0720729a..21190dbb 100644 --- a/nl/tc_linux.go +++ b/nl/tc_linux.go @@ -1079,8 +1079,10 @@ const ( __TCA_FLOWER_MAX ) -const TCA_CLS_FLAGS_SKIP_HW = 1 << 0 /* don't offload filter to HW */ -const TCA_CLS_FLAGS_SKIP_SW = 1 << 1 /* don't use filter in SW */ +const ( + TCA_CLS_FLAGS_SKIP_HW = 1 << 0 // don't offload filter to HW + TCA_CLS_FLAGS_SKIP_SW = 1 << 1 // don't use filter in SW +) // struct tc_sfq_qopt { // unsigned quantum; /* Bytes per round allocated to flow */ @@ -1238,12 +1240,11 @@ const ( TCA_PEDIT_KEY_EX ) -// /* TCA_PEDIT_KEY_EX_HDR_TYPE_NETWROK is a special case for legacy users. It -// * means no specific header type - offset is relative to the network layer -// */ type PeditHeaderType uint16 const ( + // TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK is a special case for legacy users. It + // means no specific header type - offset is relative to the network layer TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK = iota TCA_PEDIT_KEY_EX_HDR_TYPE_ETH TCA_PEDIT_KEY_EX_HDR_TYPE_IP4 diff --git a/nl/tc_linux_test.go b/nl/tc_linux_test.go index 148b2b02..6a2a3ae8 100644 --- a/nl/tc_linux_test.go +++ b/nl/tc_linux_test.go @@ -26,13 +26,13 @@ func (msg *TcMsg) serializeSafe() []byte { } func deserializeTcMsgSafe(b []byte) *TcMsg { - var msg = TcMsg{} + msg := TcMsg{} binary.Read(bytes.NewReader(b[0:SizeofTcMsg]), NativeEndian(), &msg) return &msg } func TestTcMsgDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofTcMsg) + orig := make([]byte, SizeofTcMsg) rand.Read(orig) safemsg := deserializeTcMsgSafe(orig) msg := DeserializeTcMsg(orig) @@ -53,13 +53,13 @@ func (msg *TcActionMsg) serializeSafe() []byte { } func deserializeTcActionMsgSafe(b []byte) *TcActionMsg { - var msg = TcActionMsg{} + msg := TcActionMsg{} binary.Read(bytes.NewReader(b[0:SizeofTcActionMsg]), NativeEndian(), &msg) return &msg } func TestTcActionMsgDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofTcActionMsg) + orig := make([]byte, SizeofTcActionMsg) rand.Read(orig) safemsg := deserializeTcActionMsgSafe(orig) msg := DeserializeTcActionMsg(orig) @@ -85,13 +85,13 @@ func (msg *TcRateSpec) serializeSafe() []byte { } func deserializeTcRateSpecSafe(b []byte) *TcRateSpec { - var msg = TcRateSpec{} + msg := TcRateSpec{} binary.Read(bytes.NewReader(b[0:SizeofTcRateSpec]), NativeEndian(), &msg) return &msg } func TestTcRateSpecDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofTcRateSpec) + orig := make([]byte, SizeofTcRateSpec) rand.Read(orig) safemsg := deserializeTcRateSpecSafe(orig) msg := DeserializeTcRateSpec(orig) @@ -120,13 +120,13 @@ func (msg *TcTbfQopt) serializeSafe() []byte { } func deserializeTcTbfQoptSafe(b []byte) *TcTbfQopt { - var msg = TcTbfQopt{} + msg := TcTbfQopt{} binary.Read(bytes.NewReader(b[0:SizeofTcTbfQopt]), NativeEndian(), &msg) return &msg } func TestTcTbfQoptDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofTcTbfQopt) + orig := make([]byte, SizeofTcTbfQopt) rand.Read(orig) safemsg := deserializeTcTbfQoptSafe(orig) msg := DeserializeTcTbfQopt(orig) @@ -159,13 +159,13 @@ func (msg *TcHtbCopt) serializeSafe() []byte { } func deserializeTcHtbCoptSafe(b []byte) *TcHtbCopt { - var msg = TcHtbCopt{} + msg := TcHtbCopt{} binary.Read(bytes.NewReader(b[0:SizeofTcHtbCopt]), NativeEndian(), &msg) return &msg } func TestTcHtbCoptDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofTcHtbCopt) + orig := make([]byte, SizeofTcHtbCopt) rand.Read(orig) safemsg := deserializeTcHtbCoptSafe(orig) msg := DeserializeTcHtbCopt(orig) diff --git a/nl/xfrm_linux.go b/nl/xfrm_linux.go index cdb318ba..0f62bcf5 100644 --- a/nl/xfrm_linux.go +++ b/nl/xfrm_linux.go @@ -119,7 +119,7 @@ const ( type XfrmAddress [SizeofXfrmAddress]byte func (x *XfrmAddress) ToIP() net.IP { - var empty = [12]byte{} + empty := [12]byte{} ip := make(net.IP, net.IPv6len) if bytes.Equal(x[4:16], empty[:]) { ip[10] = 0xff @@ -148,7 +148,7 @@ func (x *XfrmAddress) ToIPNet(prefixlen uint8, family uint16) *net.IPNet { } func (x *XfrmAddress) FromIP(ip net.IP) { - var empty = [16]byte{} + empty := [16]byte{} if len(ip) < net.IPv4len { copy(x[4:16], empty[:]) } else if GetIPFamily(ip) == FAMILY_V4 { diff --git a/nl/xfrm_linux_test.go b/nl/xfrm_linux_test.go index 04404d75..0a2d0a12 100644 --- a/nl/xfrm_linux_test.go +++ b/nl/xfrm_linux_test.go @@ -18,13 +18,13 @@ func (msg *XfrmAddress) serializeSafe() []byte { } func deserializeXfrmAddressSafe(b []byte) *XfrmAddress { - var msg = XfrmAddress{} + msg := XfrmAddress{} binary.Read(bytes.NewReader(b[0:SizeofXfrmAddress]), NativeEndian(), &msg) return &msg } func TestXfrmAddressDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofXfrmAddress) + orig := make([]byte, SizeofXfrmAddress) rand.Read(orig) safemsg := deserializeXfrmAddressSafe(orig) msg := DeserializeXfrmAddress(orig) @@ -57,13 +57,13 @@ func (msg *XfrmSelector) serializeSafe() []byte { } func deserializeXfrmSelectorSafe(b []byte) *XfrmSelector { - var msg = XfrmSelector{} + msg := XfrmSelector{} binary.Read(bytes.NewReader(b[0:SizeofXfrmSelector]), NativeEndian(), &msg) return &msg } func TestXfrmSelectorDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofXfrmSelector) + orig := make([]byte, SizeofXfrmSelector) rand.Read(orig) safemsg := deserializeXfrmSelectorSafe(orig) msg := DeserializeXfrmSelector(orig) @@ -90,13 +90,13 @@ func (msg *XfrmLifetimeCfg) serializeSafe() []byte { } func deserializeXfrmLifetimeCfgSafe(b []byte) *XfrmLifetimeCfg { - var msg = XfrmLifetimeCfg{} + msg := XfrmLifetimeCfg{} binary.Read(bytes.NewReader(b[0:SizeofXfrmLifetimeCfg]), NativeEndian(), &msg) return &msg } func TestXfrmLifetimeCfgDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofXfrmLifetimeCfg) + orig := make([]byte, SizeofXfrmLifetimeCfg) rand.Read(orig) safemsg := deserializeXfrmLifetimeCfgSafe(orig) msg := DeserializeXfrmLifetimeCfg(orig) @@ -119,13 +119,13 @@ func (msg *XfrmLifetimeCur) serializeSafe() []byte { } func deserializeXfrmLifetimeCurSafe(b []byte) *XfrmLifetimeCur { - var msg = XfrmLifetimeCur{} + msg := XfrmLifetimeCur{} binary.Read(bytes.NewReader(b[0:SizeofXfrmLifetimeCur]), NativeEndian(), &msg) return &msg } func TestXfrmLifetimeCurDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofXfrmLifetimeCur) + orig := make([]byte, SizeofXfrmLifetimeCur) rand.Read(orig) safemsg := deserializeXfrmLifetimeCurSafe(orig) msg := DeserializeXfrmLifetimeCur(orig) @@ -147,13 +147,13 @@ func (msg *XfrmId) serializeSafe() []byte { } func deserializeXfrmIdSafe(b []byte) *XfrmId { - var msg = XfrmId{} + msg := XfrmId{} binary.Read(bytes.NewReader(b[0:SizeofXfrmId]), NativeEndian(), &msg) return &msg } func TestXfrmIdDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofXfrmId) + orig := make([]byte, SizeofXfrmId) rand.Read(orig) safemsg := deserializeXfrmIdSafe(orig) msg := DeserializeXfrmId(orig) diff --git a/nl/xfrm_monitor_linux_test.go b/nl/xfrm_monitor_linux_test.go index 3602caf7..be6768ee 100644 --- a/nl/xfrm_monitor_linux_test.go +++ b/nl/xfrm_monitor_linux_test.go @@ -20,13 +20,13 @@ func (msg *XfrmUserExpire) serializeSafe() []byte { } func deserializeXfrmUserExpireSafe(b []byte) *XfrmUserExpire { - var msg = XfrmUserExpire{} + msg := XfrmUserExpire{} binary.Read(bytes.NewReader(b[0:SizeofXfrmUserExpire]), NativeEndian(), &msg) return &msg } func TestXfrmUserExpireDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofXfrmUserExpire) + orig := make([]byte, SizeofXfrmUserExpire) rand.Read(orig) safemsg := deserializeXfrmUserExpireSafe(orig) msg := DeserializeXfrmUserExpire(orig) diff --git a/nl/xfrm_policy_linux_test.go b/nl/xfrm_policy_linux_test.go index 08a604b9..13cef1f6 100644 --- a/nl/xfrm_policy_linux_test.go +++ b/nl/xfrm_policy_linux_test.go @@ -22,13 +22,13 @@ func (msg *XfrmUserpolicyId) serializeSafe() []byte { } func deserializeXfrmUserpolicyIdSafe(b []byte) *XfrmUserpolicyId { - var msg = XfrmUserpolicyId{} + msg := XfrmUserpolicyId{} binary.Read(bytes.NewReader(b[0:SizeofXfrmUserpolicyId]), NativeEndian(), &msg) return &msg } func TestXfrmUserpolicyIdDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofXfrmUserpolicyId) + orig := make([]byte, SizeofXfrmUserpolicyId) rand.Read(orig) safemsg := deserializeXfrmUserpolicyIdSafe(orig) msg := DeserializeXfrmUserpolicyId(orig) @@ -58,13 +58,13 @@ func (msg *XfrmUserpolicyInfo) serializeSafe() []byte { } func deserializeXfrmUserpolicyInfoSafe(b []byte) *XfrmUserpolicyInfo { - var msg = XfrmUserpolicyInfo{} + msg := XfrmUserpolicyInfo{} binary.Read(bytes.NewReader(b[0:SizeofXfrmUserpolicyInfo]), NativeEndian(), &msg) return &msg } func TestXfrmUserpolicyInfoDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofXfrmUserpolicyInfo) + orig := make([]byte, SizeofXfrmUserpolicyInfo) rand.Read(orig) safemsg := deserializeXfrmUserpolicyInfoSafe(orig) msg := DeserializeXfrmUserpolicyInfo(orig) @@ -95,13 +95,13 @@ func (msg *XfrmUserTmpl) serializeSafe() []byte { } func deserializeXfrmUserTmplSafe(b []byte) *XfrmUserTmpl { - var msg = XfrmUserTmpl{} + msg := XfrmUserTmpl{} binary.Read(bytes.NewReader(b[0:SizeofXfrmUserTmpl]), NativeEndian(), &msg) return &msg } func TestXfrmUserTmplDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofXfrmUserTmpl) + orig := make([]byte, SizeofXfrmUserTmpl) rand.Read(orig) safemsg := deserializeXfrmUserTmplSafe(orig) msg := DeserializeXfrmUserTmpl(orig) diff --git a/nl/xfrm_state_linux_test.go b/nl/xfrm_state_linux_test.go index 5ede308c..bc139a4e 100644 --- a/nl/xfrm_state_linux_test.go +++ b/nl/xfrm_state_linux_test.go @@ -23,13 +23,13 @@ func (msg *XfrmUsersaId) serializeSafe() []byte { } func deserializeXfrmUsersaIdSafe(b []byte) *XfrmUsersaId { - var msg = XfrmUsersaId{} + msg := XfrmUsersaId{} binary.Read(bytes.NewReader(b[0:SizeofXfrmUsersaId]), NativeEndian(), &msg) return &msg } func TestXfrmUsersaIdDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofXfrmUsersaId) + orig := make([]byte, SizeofXfrmUsersaId) rand.Read(orig) safemsg := deserializeXfrmUsersaIdSafe(orig) msg := DeserializeXfrmUsersaId(orig) @@ -50,13 +50,13 @@ func (msg *XfrmStats) serializeSafe() []byte { } func deserializeXfrmStatsSafe(b []byte) *XfrmStats { - var msg = XfrmStats{} + msg := XfrmStats{} binary.Read(bytes.NewReader(b[0:SizeofXfrmStats]), NativeEndian(), &msg) return &msg } func TestXfrmStatsDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofXfrmStats) + orig := make([]byte, SizeofXfrmStats) rand.Read(orig) safemsg := deserializeXfrmStatsSafe(orig) msg := DeserializeXfrmStats(orig) @@ -92,13 +92,13 @@ func (msg *XfrmUsersaInfo) serializeSafe() []byte { } func deserializeXfrmUsersaInfoSafe(b []byte) *XfrmUsersaInfo { - var msg = XfrmUsersaInfo{} + msg := XfrmUsersaInfo{} binary.Read(bytes.NewReader(b[0:SizeofXfrmUsersaInfo]), NativeEndian(), &msg) return &msg } func TestXfrmUsersaInfoDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofXfrmUsersaInfo) + orig := make([]byte, SizeofXfrmUsersaInfo) rand.Read(orig) safemsg := deserializeXfrmUsersaInfoSafe(orig) msg := DeserializeXfrmUsersaInfo(orig) @@ -132,13 +132,13 @@ func (msg *XfrmUserSpiInfo) serializeSafe() []byte { } func deserializeXfrmUserSpiInfoSafe(b []byte) *XfrmUserSpiInfo { - var msg = XfrmUserSpiInfo{} + msg := XfrmUserSpiInfo{} binary.Read(bytes.NewReader(b[0:SizeofXfrmUserSpiInfo]), NativeEndian(), &msg) return &msg } func TestXfrmUserSpiInfoDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofXfrmUserSpiInfo) + orig := make([]byte, SizeofXfrmUserSpiInfo) rand.Read(orig) safemsg := deserializeXfrmUserSpiInfoSafe(orig) msg := DeserializeXfrmUserSpiInfo(orig) @@ -146,7 +146,7 @@ func TestXfrmUserSpiInfoDeserializeSerialize(t *testing.T) { } func deserializeXfrmAlgoSafe(b []byte) *XfrmAlgo { - var msg = XfrmAlgo{} + msg := XfrmAlgo{} copy(msg.AlgName[:], b[0:64]) binary.Read(bytes.NewReader(b[64:68]), NativeEndian(), &msg.AlgKeyLen) msg.AlgKey = b[68:msg.Len()] @@ -156,7 +156,7 @@ func deserializeXfrmAlgoSafe(b []byte) *XfrmAlgo { func TestXfrmAlgoDeserializeSerialize(t *testing.T) { native := NativeEndian() // use a 32 byte key len - var orig = make([]byte, SizeofXfrmAlgo+32) + orig := make([]byte, SizeofXfrmAlgo+32) rand.Read(orig) // set the key len to 256 bits var KeyLen uint32 = 0x00000100 @@ -186,7 +186,7 @@ func (msg *XfrmAlgoAuth) serializeSafe() []byte { } func deserializeXfrmAlgoAuthSafe(b []byte) *XfrmAlgoAuth { - var msg = XfrmAlgoAuth{} + msg := XfrmAlgoAuth{} copy(msg.AlgName[:], b[0:64]) binary.Read(bytes.NewReader(b[64:68]), NativeEndian(), &msg.AlgKeyLen) binary.Read(bytes.NewReader(b[68:72]), NativeEndian(), &msg.AlgTruncLen) @@ -197,7 +197,7 @@ func deserializeXfrmAlgoAuthSafe(b []byte) *XfrmAlgoAuth { func TestXfrmAlgoAuthDeserializeSerialize(t *testing.T) { native := NativeEndian() // use a 32 byte key len - var orig = make([]byte, SizeofXfrmAlgoAuth+32) + orig := make([]byte, SizeofXfrmAlgoAuth+32) rand.Read(orig) // set the key len to 256 bits var KeyLen uint32 = 0x00000100 @@ -228,13 +228,13 @@ func (msg *XfrmEncapTmpl) serializeSafe() []byte { } func deserializeXfrmEncapTmplSafe(b []byte) *XfrmEncapTmpl { - var msg = XfrmEncapTmpl{} + msg := XfrmEncapTmpl{} binary.Read(bytes.NewReader(b[0:SizeofXfrmEncapTmpl]), NativeEndian(), &msg) return &msg } func TestXfrmEncapTmplDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofXfrmEncapTmpl) + orig := make([]byte, SizeofXfrmEncapTmpl) rand.Read(orig) safemsg := deserializeXfrmEncapTmplSafe(orig) msg := DeserializeXfrmEncapTmpl(orig) @@ -254,13 +254,13 @@ func (msg *XfrmMark) serializeSafe() []byte { } func deserializeXfrmMarkSafe(b []byte) *XfrmMark { - var msg = XfrmMark{} + msg := XfrmMark{} binary.Read(bytes.NewReader(b[0:SizeofXfrmMark]), NativeEndian(), &msg) return &msg } func TestXfrmMarkDeserializeSerialize(t *testing.T) { - var orig = make([]byte, SizeofXfrmMark) + orig := make([]byte, SizeofXfrmMark) rand.Read(orig) safemsg := deserializeXfrmMarkSafe(orig) msg := DeserializeXfrmMark(orig) @@ -282,7 +282,7 @@ func (msg *XfrmAlgoAEAD) serializeSafe() []byte { } func deserializeXfrmAlgoAEADSafe(b []byte) *XfrmAlgoAEAD { - var msg = XfrmAlgoAEAD{} + msg := XfrmAlgoAEAD{} copy(msg.AlgName[:], b[0:64]) binary.Read(bytes.NewReader(b[64:68]), NativeEndian(), &msg.AlgKeyLen) binary.Read(bytes.NewReader(b[68:72]), NativeEndian(), &msg.AlgICVLen) @@ -293,7 +293,7 @@ func deserializeXfrmAlgoAEADSafe(b []byte) *XfrmAlgoAEAD { func TestXfrmXfrmAlgoAeadDeserializeSerialize(t *testing.T) { native := NativeEndian() // use a 32 byte key len - var orig = make([]byte, SizeofXfrmAlgoAEAD+36) + orig := make([]byte, SizeofXfrmAlgoAEAD+36) rand.Read(orig) // set the key len to (256 + 32) bits var KeyLen uint32 = 0x00000120 diff --git a/proc_event_test.go b/proc_event_test.go index 6455be8c..18af8d5d 100644 --- a/proc_event_test.go +++ b/proc_event_test.go @@ -1,13 +1,15 @@ +//go:build linux // +build linux package netlink import ( - "github.com/vishvananda/netns" "os" "os/exec" "runtime" "testing" + + "github.com/vishvananda/netns" ) func TestSubscribeProcEvent(t *testing.T) { diff --git a/qdisc.go b/qdisc.go index 067743d3..79098d15 100644 --- a/qdisc.go +++ b/qdisc.go @@ -12,6 +12,7 @@ const ( HANDLE_ROOT = 0xFFFFFFFF PRIORITY_MAP_LEN = 16 ) + const ( HANDLE_MIN_INGRESS = 0xFFFFFFF2 HANDLE_MIN_EGRESS = 0xFFFFFFF3 diff --git a/qdisc_linux.go b/qdisc_linux.go index 22cf0e58..62d7ba3c 100644 --- a/qdisc_linux.go +++ b/qdisc_linux.go @@ -162,7 +162,6 @@ func (h *Handle) qdiscModify(cmd, flags int, qdisc Qdisc) error { } func qdiscPayload(req *nl.NetlinkRequest, qdisc Qdisc) error { - req.AddData(nl.NewRtAttr(nl.TCA_KIND, nl.ZeroTerminated(qdisc.Type()))) if qdisc.Attrs().IngressBlock != nil { req.AddData(nl.NewRtAttr(nl.TCA_INGRESS_BLOCK, nl.Uint32Attr(*qdisc.Attrs().IngressBlock))) @@ -545,7 +544,6 @@ func parseHtbData(qdisc Qdisc, data []syscall.NetlinkRouteAttr) error { func parseFqCodelData(qdisc Qdisc, data []syscall.NetlinkRouteAttr) error { fqCodel := qdisc.(*FqCodel) for _, datum := range data { - switch datum.Attr.Type { case nl.TCA_FQ_CODEL_TARGET: fqCodel.Target = native.Uint32(datum.Value) diff --git a/rdma_link_linux.go b/rdma_link_linux.go index 9bb75073..4f2fea43 100644 --- a/rdma_link_linux.go +++ b/rdma_link_linux.go @@ -30,19 +30,18 @@ func getProtoField(clientType int, op int) int { } func uint64ToGuidString(guid uint64) string { - //Convert to byte array + // Convert to byte array sysGuidBytes := new(bytes.Buffer) binary.Write(sysGuidBytes, binary.LittleEndian, guid) - //Convert to HardwareAddr + // Convert to HardwareAddr sysGuidNet := net.HardwareAddr(sysGuidBytes.Bytes()) - //Get the String + // Get the String return sysGuidNet.String() } func executeOneGetRdmaLink(data []byte) (*RdmaLink, error) { - link := RdmaLink{} reader := bytes.NewReader(data) @@ -79,7 +78,6 @@ func executeOneGetRdmaLink(data []byte) (*RdmaLink, error) { } func execRdmaSetLink(req *nl.NetlinkRequest) error { - _, err := req.Execute(unix.NETLINK_RDMA, 0) return err } @@ -217,7 +215,6 @@ func RdmaSystemGetNetnsMode() (string, error) { // otherwise. // Equivalent to: `rdma system show netns' func (h *Handle) RdmaSystemGetNetnsMode() (string, error) { - proto := getProtoField(nl.RDMA_NL_NLDEV, nl.RDMA_NLDEV_CMD_SYS_GET) req := h.newNetlinkRequest(proto, unix.NLM_F_ACK) diff --git a/rdma_link_test.go b/rdma_link_test.go index 241b89e8..391514ef 100644 --- a/rdma_link_test.go +++ b/rdma_link_test.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package netlink @@ -147,7 +148,7 @@ func TestRdmaLinkSetNsFd(t *testing.T) { } newns.Close() - //Set the old mode back at start of the test + // Set the old mode back at start of the test err = RdmaSystemSetNetnsMode(mode) if err != nil { t.Fatal(err) diff --git a/route.go b/route.go index 1b4555d5..cb85d1c3 100644 --- a/route.go +++ b/route.go @@ -45,7 +45,7 @@ type Encap interface { Equal(Encap) bool } -//Protocol describe what was the originator of the route +// Protocol describe what was the originator of the route type RouteProtocol int // Route represents a netlink route. diff --git a/route_linux.go b/route_linux.go index 28a132a2..d6e5f6a4 100644 --- a/route_linux.go +++ b/route_linux.go @@ -201,6 +201,7 @@ type SEG6Encap struct { func (e *SEG6Encap) Type() int { return nl.LWTUNNEL_ENCAP_SEG6 } + func (e *SEG6Encap) Decode(buf []byte) error { if len(buf) < 4 { return fmt.Errorf("lack of bytes") @@ -222,6 +223,7 @@ func (e *SEG6Encap) Decode(buf []byte) error { return err } + func (e *SEG6Encap) Encode() ([]byte, error) { s, err := nl.EncodeSEG6Encap(e.Mode, e.Segments) hdr := make([]byte, 4) @@ -229,6 +231,7 @@ func (e *SEG6Encap) Encode() ([]byte, error) { native.PutUint16(hdr[2:], nl.SEG6_IPTUNNEL_SRH) return append(hdr, s...), err } + 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. @@ -239,6 +242,7 @@ func (e *SEG6Encap) String() string { len(e.Segments), strings.Join(segs, " ")) return str } + func (e *SEG6Encap) Equal(x Encap) bool { o, ok := x.(*SEG6Encap) if !ok { @@ -289,6 +293,7 @@ func (e *SEG6LocalEncap) SetProg(progFd int, progName string) error { func (e *SEG6LocalEncap) Type() int { return nl.LWTUNNEL_ENCAP_SEG6_LOCAL } + func (e *SEG6LocalEncap) Decode(buf []byte) error { attrs, err := nl.ParseRouteAttr(buf) if err != nil { @@ -337,6 +342,7 @@ func (e *SEG6LocalEncap) Decode(buf []byte) error { } return err } + func (e *SEG6LocalEncap) Encode() ([]byte, error) { var err error res := make([]byte, 8) @@ -406,6 +412,7 @@ func (e *SEG6LocalEncap) Encode() ([]byte, error) { } return res, err } + func (e *SEG6LocalEncap) String() string { strs := make([]string, 0, nl.SEG6_LOCAL_MAX) strs = append(strs, fmt.Sprintf("action %s", nl.SEG6LocalActionString(e.Action))) @@ -448,6 +455,7 @@ func (e *SEG6LocalEncap) String() string { } return strings.Join(strs, " ") } + func (e *SEG6LocalEncap) Equal(x Encap) bool { o, ok := x.(*SEG6LocalEncap) if !ok { @@ -521,6 +529,7 @@ func (e *BpfEncap) SetXmitHeadroom(headroom int) error { func (e *BpfEncap) Type() int { return nl.LWTUNNEL_ENCAP_BPF } + func (e *BpfEncap) Decode(buf []byte) error { if len(buf) < 4 { return fmt.Errorf("lwt bpf decode: lack of bytes") @@ -674,7 +683,6 @@ func (e *IP6tnlEncap) Decode(buf []byte) error { } func (e *IP6tnlEncap) Encode() ([]byte, error) { - final := []byte{} resID := make([]byte, 12) @@ -1713,7 +1721,8 @@ func RouteSubscribeWithOptions(ch chan<- RouteUpdate, done <-chan struct{}, opti } func routeSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- RouteUpdate, done <-chan struct{}, cberr func(error), listExisting bool, - rcvbuf int, rcvTimeout *unix.Timeval, rcvbufForce bool) error { + rcvbuf int, rcvTimeout *unix.Timeval, rcvbufForce bool, +) error { s, err := nl.SubscribeAt(newNs, curNs, unix.NETLINK_ROUTE, unix.RTNLGRP_IPV4_ROUTE, unix.RTNLGRP_IPV6_ROUTE) if err != nil { return err diff --git a/route_test.go b/route_test.go index 7e5e6b0e..12e4284f 100644 --- a/route_test.go +++ b/route_test.go @@ -758,7 +758,8 @@ func TestRouteSubscribeListExisting(t *testing.T) { defer close(done) if err := RouteSubscribeWithOptions(ch, done, RouteSubscribeOptions{ Namespace: &newNs, - ListExisting: true}, + ListExisting: true, + }, ); err != nil { t.Fatal(err) } @@ -1418,8 +1419,10 @@ func TestRouteOifOption(t *testing.T) { } gw1 := net.IPv4(192, 168, 1, 254) gw2 := net.IPv4(192, 168, 2, 254) - route := Route{Dst: dst, MultiPath: []*NexthopInfo{{LinkIndex: link1.Attrs().Index, - Gw: gw1}, {LinkIndex: link2.Attrs().Index, Gw: gw2}}} + route := Route{Dst: dst, MultiPath: []*NexthopInfo{{ + LinkIndex: link1.Attrs().Index, + Gw: gw1, + }, {LinkIndex: link2.Attrs().Index, Gw: gw2}}} if err := RouteAdd(&route); err != nil { t.Fatal(err) } @@ -1445,7 +1448,6 @@ func TestRouteOifOption(t *testing.T) { !routes[0].Gw.Equal(gw2) { t.Fatal("Get route from unmatched interface") } - } func TestFilterDefaultRoute(t *testing.T) { @@ -1498,7 +1500,7 @@ func TestFilterDefaultRoute(t *testing.T) { if err := RouteAdd(&extraRoute); err != nil { t.Fatal(err) } - var filterTests = []struct { + filterTests := []struct { filter *Route mask uint64 expected net.IP @@ -1527,7 +1529,6 @@ func TestFilterDefaultRoute(t *testing.T) { t.Fatal("Unexpected Gateway") } } - } func TestMPLSRouteAddDel(t *testing.T) { @@ -1574,7 +1575,6 @@ func TestMPLSRouteAddDel(t *testing.T) { if len(routes) != 0 { t.Fatal("Route not removed properly") } - } func TestIP6tnlRouteAddDel(t *testing.T) { @@ -1634,7 +1634,6 @@ func TestIP6tnlRouteAddDel(t *testing.T) { if len(routes) != 0 { t.Fatal("Route not removed properly") } - } func TestRouteEqual(t *testing.T) { @@ -1989,6 +1988,7 @@ func TestSEG6LocalEqual(t *testing.T) { } } } + func TestSEG6RouteAddDel(t *testing.T) { if os.Getenv("CI") == "true" { t.Skipf("Fails in CI with: route_test.go:*: Invalid Type. SEG6_IPTUN_MODE_INLINE routes not added properly") diff --git a/route_unspecified.go b/route_unspecified.go index db737268..380d50b2 100644 --- a/route_unspecified.go +++ b/route_unspecified.go @@ -1,3 +1,4 @@ +//go:build !linux // +build !linux package netlink diff --git a/rule_linux.go b/rule_linux.go index dba99147..056f6bdb 100644 --- a/rule_linux.go +++ b/rule_linux.go @@ -225,7 +225,7 @@ func (h *Handle) RuleListFiltered(family int, filter *Rule, filterMask uint64) ( return nil, executeErr } - var res = make([]Rule, 0) + res := make([]Rule, 0) for i := range msgs { msg := nl.DeserializeRtMsg(msgs[i]) attrs, err := nl.ParseRouteAttr(msgs[i][msg.Len():]) diff --git a/vdpa_linux.go b/vdpa_linux.go index c14877a2..adf591f6 100644 --- a/vdpa_linux.go +++ b/vdpa_linux.go @@ -398,7 +398,8 @@ func (h *Handle) VDPANewDev(name, mgmtBus, mgmtName string, params VDPANewDevPar // Equivalent to: `vdpa dev del ` func (h *Handle) VDPADelDev(name string) error { _, err := h.vdpaRequest(nl.VDPA_CMD_DEV_DEL, 0, []*nl.RtAttr{ - nl.NewRtAttr(nl.VDPA_ATTR_DEV_NAME, nl.ZeroTerminated(name))}) + nl.NewRtAttr(nl.VDPA_ATTR_DEV_NAME, nl.ZeroTerminated(name)), + }) return err } diff --git a/vdpa_linux_test.go b/vdpa_linux_test.go index 91a488e4..897fbb52 100644 --- a/vdpa_linux_test.go +++ b/vdpa_linux_test.go @@ -16,9 +16,7 @@ const ( vdpaTestDeviceName = "__nl_test_dev" ) -var ( - vdapTestReqModules = []string{"vdpa", "vdpa_sim", "vdpa_sim_net"} -) +var vdapTestReqModules = []string{"vdpa", "vdpa_sim", "vdpa_sim_net"} func setupVDPATest(t *testing.T, reqCommands ...int) func() { t.Helper() diff --git a/xfrm_monitor_linux.go b/xfrm_monitor_linux.go index 985d3a91..9292d8e4 100644 --- a/xfrm_monitor_linux.go +++ b/xfrm_monitor_linux.go @@ -31,9 +31,7 @@ func parseXfrmMsgExpire(b []byte) *XfrmMsgExpire { return &e } -func XfrmMonitor(ch chan<- XfrmMsg, done <-chan struct{}, errorChan chan<- error, - types ...nl.XfrmMsgType) error { - +func XfrmMonitor(ch chan<- XfrmMsg, done <-chan struct{}, errorChan chan<- error, types ...nl.XfrmMsgType) error { groups, err := xfrmMcastGroups(types) if err != nil { return nil @@ -48,7 +46,6 @@ func XfrmMonitor(ch chan<- XfrmMsg, done <-chan struct{}, errorChan chan<- error <-done s.Close() }() - } go func() { diff --git a/xfrm_policy_linux_test.go b/xfrm_policy_linux_test.go index fff14e36..b7cf9bbf 100644 --- a/xfrm_policy_linux_test.go +++ b/xfrm_policy_linux_test.go @@ -136,7 +136,6 @@ func TestXfrmPolicyFlush(t *testing.T) { if len(policies) != 0 { t.Fatalf("unexpected number of policies: %d", len(policies)) } - } func TestXfrmPolicyBlockWithIfindex(t *testing.T) { diff --git a/xfrm_state_linux.go b/xfrm_state_linux.go index 2f461465..dc52d81d 100644 --- a/xfrm_state_linux.go +++ b/xfrm_state_linux.go @@ -129,6 +129,7 @@ func (sa XfrmState) String() string { return fmt.Sprintf("Dst: %v, Src: %v, Proto: %s, Mode: %s, SPI: 0x%x, ReqID: 0x%x, ReplayWindow: %d, Mark: %v, OutputMark: %v, Ifid: %d, Auth: %v, Crypt: %v, Aead: %v, Encap: %v, ESN: %t, DontEncapDSCP: %t, OSeqMayWrap: %t, Replay: %v", sa.Dst, sa.Src, sa.Proto, sa.Mode, sa.Spi, sa.Reqid, sa.ReplayWindow, sa.Mark, sa.OutputMark, sa.Ifid, sa.Auth, sa.Crypt, sa.Aead, sa.Encap, sa.ESN, sa.DontEncapDSCP, sa.OSeqMayWrap, sa.Replay) } + func (sa XfrmState) Print(stats bool) string { if !stats { return sa.String() @@ -151,6 +152,7 @@ func printLimit(lmt uint64) string { } return fmt.Sprintf("%d", lmt) } + func writeStateAlgo(a *XfrmStateAlgo) []byte { algo := nl.XfrmAlgo{ AlgKeyLen: uint32(len(a.Key) * 8), @@ -259,7 +261,6 @@ func (h *Handle) XfrmStateUpdate(state *XfrmState) error { } 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") diff --git a/xfrm_state_linux_test.go b/xfrm_state_linux_test.go index 22031e39..25479af9 100644 --- a/xfrm_state_linux_test.go +++ b/xfrm_state_linux_test.go @@ -133,7 +133,6 @@ func TestXfrmStateFlush(t *testing.T) { if len(states) != 0 { t.Fatal("State not flushed properly") } - } func TestXfrmStateUpdateLimits(t *testing.T) { @@ -271,6 +270,7 @@ func TestXfrmStateWithOutputMarkAndMask(t *testing.T) { t.Fatal(err) } } + func genStateSelectorForV6Payload() *XfrmPolicy { _, wildcardV6Net, _ := net.ParseCIDR("::/0") return &XfrmPolicy{ @@ -375,6 +375,7 @@ func getAeadState() *XfrmState { }, } } + func compareSelector(a, b *XfrmPolicy) bool { return a.Src.String() == b.Src.String() && a.Dst.String() == b.Dst.String() && @@ -405,7 +406,6 @@ func compareStates(a, b *XfrmState) bool { compareAlgo(a.Aead, b.Aead) && compareMarks(a.Mark, b.Mark) && compareMarks(a.OutputMark, b.OutputMark) - } func compareLimits(a, b *XfrmState) bool { diff --git a/xfrm_unspecified.go b/xfrm_unspecified.go index 12fdd26d..385292d5 100644 --- a/xfrm_unspecified.go +++ b/xfrm_unspecified.go @@ -3,5 +3,7 @@ package netlink -type XfrmPolicy struct{} -type XfrmState struct{} +type ( + XfrmPolicy struct{} + XfrmState struct{} +)