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 Jan 21, 2025
1 parent 3642538 commit 08e0bac
Show file tree
Hide file tree
Showing 66 changed files with 495 additions and 448 deletions.
9 changes: 6 additions & 3 deletions addr_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,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
Expand Down Expand Up @@ -420,13 +421,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 @@ -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)
Expand Down Expand Up @@ -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())
}

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 @@ -223,10 +223,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 @@ -236,14 +238,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 @@ -261,7 +265,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 @@ -285,7 +288,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 @@ -362,7 +365,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 @@ -540,17 +543,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 @@ -664,7 +666,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 08e0bac

Please sign in to comment.