Skip to content

Commit

Permalink
[NPM-3110] Fix revive lint warnings for the networks team (#28937)
Browse files Browse the repository at this point in the history
  • Loading branch information
pimlu authored Sep 3, 2024
1 parent aec1824 commit 0cce24d
Show file tree
Hide file tree
Showing 42 changed files with 55 additions and 144 deletions.
2 changes: 1 addition & 1 deletion pkg/network/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(NET) Fix revive linter
// Package network contains logic and types for network tracing
package network

// ConnectionBuffer encapsulates a resizing buffer for ConnectionStat objects
Expand Down
2 changes: 1 addition & 1 deletion pkg/network/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(NET) Fix revive linter
// Package config implements network tracing configuration
package config

import (
Expand Down
4 changes: 1 addition & 3 deletions pkg/network/config/replace_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"fmt"
"regexp"

"github.com/DataDog/datadog-agent/pkg/config"
//nolint:revive // TODO(NET) Fix revive linter
ddconfig "github.com/DataDog/datadog-agent/pkg/config"
)

Expand All @@ -28,7 +26,7 @@ type ReplaceRule struct {
}

func parseReplaceRules(cfg ddconfig.Config, key string) ([]*ReplaceRule, error) {
if !config.SystemProbe().IsSet(key) {
if !ddconfig.SystemProbe().IsSet(key) {
return nil, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/network/config/sysctl/sysctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

//go:build linux

//nolint:revive // TODO(NET) Fix revive linter
// Package sysctl implements reading of system parameters such as system limits
package sysctl

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/network/config/sysctl/sysctl_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

//go:build darwin

//nolint:revive // TODO(NET) Fix revive linter
// Package sysctl implements reading of system parameters such as system limits
package sysctl

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/network/dns/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(NET) Fix revive linter
// Package dns traces DNS activity and caches DNS lookups for reverse DNS capability
package dns

import (
Expand Down
3 changes: 0 additions & 3 deletions pkg/network/ebpf/bpf_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
var prebuiltModulesInUse = map[string]struct{}{}
var telemetrymu sync.Mutex

//nolint:revive // TODO(NET) Fix revive linter
func ModuleFileName(moduleName string, debug bool) string {
if debug {
return fmt.Sprintf("%s-debug.o", moduleName)
Expand Down Expand Up @@ -67,7 +66,6 @@ func ReadOffsetBPFModule(bpfDir string, debug bool) (bytecode.AssetReader, error
return readModule(bpfDir, "offset-guess", debug)
}

//nolint:revive // TODO(NET) Fix revive linter
func ReadFentryTracerModule(bpfDir string, debug bool) (bytecode.AssetReader, error) {
return readModule(bpfDir, "tracer-fentry", debug)
}
Expand All @@ -77,7 +75,6 @@ func ReadConntrackBPFModule(bpfDir string, debug bool) (bytecode.AssetReader, er
return readModule(bpfDir, "conntrack", debug)
}

//nolint:revive // TODO(NET) Fix revive linter
func GetModulesInUse() []string {
telemetrymu.Lock()
defer telemetrymu.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion pkg/network/ebpf/conntrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

//go:build linux

//nolint:revive // TODO(NET) Fix revive linter
// Package ebpf implements tracing network events with eBPF
package ebpf

import (
Expand Down
1 change: 0 additions & 1 deletion pkg/network/encoding/marshal/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(NET) Fix revive linter
package marshal

import (
Expand Down
4 changes: 3 additions & 1 deletion pkg/network/event_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ func (s StatCounters) IsZero() bool {
return s == StatCounters{}
}

//nolint:revive // TODO(NET) Fix revive linter
// StatCookie A 64-bit hash designed to uniquely identify a connection.
// In eBPF this is 32 bits but it gets re-hashed to 64 bits in userspace to
// reduce collisions; see PR #17197 for more info.
type StatCookie = uint64

// ConnectionStats stores statistics for a single connection. Field order in the struct should be 8-byte aligned
Expand Down
2 changes: 1 addition & 1 deletion pkg/network/events/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func Initialized() bool {
return theMonitor.Load() != nil
}

//nolint:revive // TODO(NET) Fix revive linter
// ProcessEventHandler represents a handler function triggered for process events
type ProcessEventHandler interface {
HandleProcessEvent(*Process)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/network/events/network_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
// NetworkConsumer describes a process monitoring object
type NetworkConsumer struct{}

//nolint:revive // TODO(NET) Fix revive linter
// Start starts the event consumer (noop)
func (n *NetworkConsumer) Start() error {
return nil
}

//nolint:revive // TODO(NET) Fix revive linter
// Stop stops the event consumer (noop)
func (n *NetworkConsumer) Stop() {
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/network/events/network_consumer_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (
// NetworkConsumer describes a process monitoring object
type NetworkConsumer struct{}

//nolint:revive // TODO(NET) Fix revive linter
// Start starts the event consumer (noop)
func (n *NetworkConsumer) Start() error {
return fmt.Errorf("network consumer is only supported on linux")
}

//nolint:revive // TODO(NET) Fix revive linter
// Stop stops the event consumer (noop)
func (n *NetworkConsumer) Stop() {}

// ID returns id for process monitor
Expand Down
2 changes: 1 addition & 1 deletion pkg/network/netlink/circuit_breaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(NET) Fix revive linter
// Package netlink implements network connection tracking.
package netlink

import (
Expand Down
4 changes: 1 addition & 3 deletions pkg/network/netlink/conntracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ func TestTooManyEntries(t *testing.T) {
// Run this test with -memprofile to get an insight of how much memory is
// allocated/used by Conntracker to store maxStateSize entries.
// Example: go test -run TestConntrackerMemoryAllocation -memprofile mem.prof .
//
//nolint:revive // TODO(NET) Fix revive linter
func TestConntrackerMemoryAllocation(t *testing.T) {
func TestConntrackerMemoryAllocation(_t *testing.T) {
rt := newConntracker(10000)
ipGen := randomIPGen()

Expand Down
1 change: 0 additions & 1 deletion pkg/network/netlink/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func TestConsumerKeepsRunningAfterCircuitBreakerTrip(t *testing.T) {

go func() {
defer close(exited)
//nolint:revive // TODO(NET) Fix revive linter
for range ev {
}
}()
Expand Down
19 changes: 5 additions & 14 deletions pkg/network/netlink/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,26 @@ func NewNoOpConntracker() Conntracker {
// GetType returns a string describing whether the conntracker is "ebpf" or "netlink"
func (*noOpConntracker) GetType() string { return "" }

//nolint:revive // TODO(NET) Fix revive linter
func (*noOpConntracker) GetTranslationForConn(c *network.ConnectionStats) *network.IPTranslation {
func (*noOpConntracker) GetTranslationForConn(_c *network.ConnectionStats) *network.IPTranslation {
return nil
}

//nolint:revive // TODO(NET) Fix revive linter
func (*noOpConntracker) DeleteTranslation(c *network.ConnectionStats) {
func (*noOpConntracker) DeleteTranslation(_c *network.ConnectionStats) {

}

//nolint:revive // TODO(NET) Fix revive linter
func (*noOpConntracker) IsSampling() bool {
return false
}

//nolint:revive // TODO(NET) Fix revive linter
func (*noOpConntracker) Close() {}

//nolint:revive // TODO(NET) Fix revive linter
func (c *noOpConntracker) DumpCachedTable(ctx context.Context) (map[uint32][]DebugConntrackEntry, error) {
func (*noOpConntracker) DumpCachedTable(_ctx context.Context) (map[uint32][]DebugConntrackEntry, error) {
return nil, nil
}

// Describe returns all descriptions of the collector
//
//nolint:revive // TODO(NET) Fix revive linter
func (*noOpConntracker) Describe(ch chan<- *prometheus.Desc) {}
func (*noOpConntracker) Describe(_ch chan<- *prometheus.Desc) {}

// Collect returns the current state of all metrics of the collector
//
//nolint:revive // TODO(NET) Fix revive linter
func (*noOpConntracker) Collect(ch chan<- prometheus.Metric) {}
func (*noOpConntracker) Collect(_ch chan<- prometheus.Metric) {}
34 changes: 4 additions & 30 deletions pkg/network/netlink/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,21 @@ func NewSocket(netNS netns.NsHandle) (*Socket, error) {
}

// fixMsg updates the fields of m using the logic specified in Send.
func (c *Socket) fixMsg(m *netlink.Message, ml int) {
func (s *Socket) fixMsg(m *netlink.Message, ml int) {
if m.Header.Length == 0 {
m.Header.Length = uint32(nlmsgAlign(ml))
}

if m.Header.Sequence == 0 {
m.Header.Sequence = c.seq.Add(1)
m.Header.Sequence = s.seq.Add(1)
}

if m.Header.PID == 0 {
m.Header.PID = c.pid
m.Header.PID = s.pid
}
}

// Send a netlink.Message
//
//nolint:revive // TODO(NET) Fix revive linter
func (s *Socket) Send(m netlink.Message) error {
s.fixMsg(&m, nlmsgLength(len(m.Data)))
b, err := m.MarshalBinary()
Expand All @@ -151,16 +149,12 @@ func (s *Socket) Send(m netlink.Message) error {
}

// Receive is not implemented. See ReceiveInto
//
//nolint:revive // TODO(NET) Fix revive linter
func (s *Socket) Receive() ([]netlink.Message, error) {
return nil, errNotImplemented
}

// ReceiveAndDiscard reads netlink messages off the socket & discards them.
// If the NLMSG_DONE flag is found in one of the messages, returns true.
//
//nolint:revive // TODO(NET) Fix revive linter
func (s *Socket) ReceiveAndDiscard() (bool, uint32, error) {
for {
n, _, err := s.recvmsg()
Expand Down Expand Up @@ -205,8 +199,6 @@ func (s *Socket) ReceiveAndDiscard() (bool, uint32, error) {
}

// ReceiveInto reads one or more netlink.Messages off the socket
//
//nolint:revive // TODO(NET) Fix revive linter
func (s *Socket) ReceiveInto(b []byte) ([]netlink.Message, uint32, error) {
var netns uint32
n, oobn, err := s.recvmsg()
Expand Down Expand Up @@ -282,29 +274,21 @@ func parseNetNS(scms []unix.SocketControlMessage) uint32 {
}

// File descriptor of the socket
//
//nolint:revive // TODO(NET) Fix revive linter
func (s *Socket) File() *os.File {
return s.fd
}

// Close the socket
//
//nolint:revive // TODO(NET) Fix revive linter
func (s *Socket) Close() error {
return s.fd.Close()
}

// SendMessages isn't implemented in our case
//
//nolint:revive // TODO(NET) Fix revive linter
func (s *Socket) SendMessages(m []netlink.Message) error {
func (s *Socket) SendMessages(_m []netlink.Message) error {
return errNotImplemented
}

// JoinGroup creates a new group membership
//
//nolint:revive // TODO(NET) Fix revive linter
func (s *Socket) JoinGroup(group uint32) error {
return os.NewSyscallError("setsockopt", s.SetSockoptInt(
unix.SOL_NETLINK,
Expand All @@ -314,8 +298,6 @@ func (s *Socket) JoinGroup(group uint32) error {
}

// LeaveGroup deletes a group membership
//
//nolint:revive // TODO(NET) Fix revive linter
func (s *Socket) LeaveGroup(group uint32) error {
return os.NewSyscallError("setsockopt", s.SetSockoptInt(
unix.SOL_NETLINK,
Expand All @@ -325,8 +307,6 @@ func (s *Socket) LeaveGroup(group uint32) error {
}

// SetSockoptInt sets a socket option
//
//nolint:revive // TODO(NET) Fix revive linter
func (s *Socket) SetSockoptInt(level, opt, value int) error {
// Value must be in range of a C integer.
if value < math.MinInt32 || value > math.MaxInt32 {
Expand All @@ -346,8 +326,6 @@ func (s *Socket) SetSockoptInt(level, opt, value int) error {
}

// GetSockoptInt gets a socket option
//
//nolint:revive // TODO(NET) Fix revive linter
func (s *Socket) GetSockoptInt(level, opt int) (int, error) {
var err error
var v int
Expand All @@ -363,8 +341,6 @@ func (s *Socket) GetSockoptInt(level, opt int) (int, error) {
}

// SetBPF attaches an assembled BPF program to the socket
//
//nolint:revive // TODO(NET) Fix revive linter
func (s *Socket) SetBPF(filter []bpf.RawInstruction) error {
prog := unix.SockFprog{
Len: uint16(len(filter)),
Expand All @@ -382,7 +358,6 @@ func (s *Socket) SetBPF(filter []bpf.RawInstruction) error {
return err
}

//nolint:revive // TODO(NET) Fix revive linter
func (s *Socket) recvmsg() (int, int, error) {
ctrlErr := s.conn.Read(s.rawread)
if ctrlErr != nil {
Expand All @@ -391,7 +366,6 @@ func (s *Socket) recvmsg() (int, int, error) {
return s.n, s.oobn, s.readErr
}

//nolint:revive // TODO(NET) Fix revive linter
func (s *Socket) rawread(fd uintptr) bool {
s.n, s.oobn, _, s.readErr = noallocRecvmsg(int(fd), s.recvbuf, s.oobbuf, unix.MSG_DONTWAIT)
return ready(s.readErr)
Expand Down
9 changes: 4 additions & 5 deletions pkg/network/netlink/testutil/conntrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

//go:build linux

//nolint:revive // TODO(NET) Fix revive linter
// Package testutil contains helper functions used for testing conntrack
package testutil

import (
Expand Down Expand Up @@ -98,7 +98,7 @@ func SetupDNAT6(t *testing.T) {
teardownDNAT6(t, ifName, linkName)
})

nettestutil.Ip6tablesSave(t)
nettestutil.IP6tablesSave(t)
cmds := []string{
fmt.Sprintf("ip link add %s type dummy", linkName),
fmt.Sprintf("ip address add fd00::1 dev %s", linkName),
Expand Down Expand Up @@ -177,8 +177,7 @@ func SetupVeth6Pair(t *testing.T) (ns string) {
return
}

//nolint:revive // TODO(NET) Fix revive linter
func teardownVeth6Pair(t *testing.T, ns string) {
func teardownVeth6Pair(t *testing.T, _ns string) {
cmds := []string{
"ip link del veth1",
}
Expand Down Expand Up @@ -236,7 +235,7 @@ func SetupCrossNsDNAT6(t *testing.T) (ns string) {
})
ns = SetupVeth6Pair(t)

nettestutil.Ip6tablesSave(t)
nettestutil.IP6tablesSave(t)
cmds := []string{
"ip6tables -I INPUT 1 -m conntrack --ctstate NEW,RELATED,ESTABLISHED -j ACCEPT",
fmt.Sprintf("ip netns exec %s ip6tables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-port 8080", ns),
Expand Down
Loading

0 comments on commit 0cce24d

Please sign in to comment.