Skip to content

Commit

Permalink
gofumpt code
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Aug 23, 2024
1 parent 65a253d commit 92dcdba
Show file tree
Hide file tree
Showing 69 changed files with 505 additions and 457 deletions.
6 changes: 4 additions & 2 deletions addr_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,15 @@ func addrSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- AddrUpdate, done <-c
continue
}

ch <- AddrUpdate{LinkAddress: *addr.IPNet,
ch <- AddrUpdate{
LinkAddress: *addr.IPNet,
LinkIndex: addr.LinkIndex,
NewAddr: msgType == unix.RTM_NEWADDR,
Flags: addr.Flags,
Scope: addr.Scope,
PreferedLft: addr.PreferedLft,
ValidLft: addr.ValidLft}
ValidLft: addr.ValidLft,
}
}
}
}()
Expand Down
11 changes: 5 additions & 6 deletions addr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}{
Expand Down Expand Up @@ -138,16 +138,15 @@ func DoTestAddr(t *testing.T, FunctionUndertest func(Link, *Addr) error) {
t.Fatal("Address not removed properly")
}
}

}

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

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 {
Expand Down
4 changes: 2 additions & 2 deletions bridge_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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)
Expand Down Expand Up @@ -139,7 +139,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())
}

Expand Down
2 changes: 1 addition & 1 deletion bridge_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion class_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,5 +679,4 @@ func TestClassHfsc(t *testing.T) {
if err := ClassChange(hfscClass); err != nil {
t.Fatal(err)
}

}
28 changes: 15 additions & 13 deletions conntrack_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,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)
Expand All @@ -209,14 +211,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
Expand All @@ -234,7 +238,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
Expand All @@ -258,7 +261,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
}
Expand Down Expand Up @@ -335,7 +338,7 @@ func (s *ConntrackFlow) toNlData() ([]*nl.RtAttr, error) {
// <len, CTA_TIMEOUT>
// <BEuint64>
// <len, NLA_F_NESTED|CTA_PROTOINFO>

// CTA_TUPLE_ORIG
ctTupleOrig := nl.NewRtAttr(unix.NLA_F_NESTED|nl.CTA_TUPLE_ORIG, nil)
forwardFlowAttrs, err := s.Forward.toNlData(s.FamilyType)
Expand Down Expand Up @@ -513,17 +516,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) {
Expand Down Expand Up @@ -637,7 +639,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)
Expand Down
Loading

0 comments on commit 92dcdba

Please sign in to comment.