Skip to content
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
49bed8e
initial commit
hmahmood May 16, 2024
4464eac
iterate
hmahmood May 29, 2024
fca1a1e
Fix lint errors
hmahmood Jun 5, 2024
f75cb82
Add kernel.IsEbpfSupported
hmahmood Jun 5, 2024
059cbef
Rename config
hmahmood Jun 5, 2024
2e56ffe
Add IsEbpfSupported
hmahmood Jun 6, 2024
c2a3d78
Override when ebpfless config is enabled
hmahmood Jun 6, 2024
3959fe9
Merge remote-tracking branch 'origin/main' into hasan.mahmood/ebpfles…
hmahmood Jun 6, 2024
39853f1
Update go.mod
hmahmood Jun 6, 2024
90637ce
Remove fargate requirement
hmahmood Jun 6, 2024
753fe21
Fix dns test
hmahmood Jun 6, 2024
6a92446
Fix build
hmahmood Jun 6, 2024
8d5952e
Fix lint
hmahmood Jun 6, 2024
3851ef0
Remove ebpf check
hmahmood Jun 7, 2024
d881f84
Merge remote-tracking branch 'origin/main' into hasan.mahmood/ebpfles…
hmahmood Jun 10, 2024
de0b4a1
update go.sum
hmahmood Jun 10, 2024
41d1606
Don't check for tracefs on ebpfless
hmahmood Jun 10, 2024
856ac78
Check module NeedsEBPF function to skip ebpf checks
hmahmood Jun 11, 2024
7e3ec04
Disable configs for ebpf-less
hmahmood Jun 12, 2024
81d931a
Merge remote-tracking branch 'origin/main' into hasan.mahmood/ebpfles…
hmahmood Jun 26, 2024
42e758f
Fix merge
hmahmood Jun 26, 2024
de3545f
Disable tests for ebpfless
hmahmood Jun 26, 2024
ce374c6
Update gopacket
hmahmood Jun 26, 2024
497aff8
Fix typo
hmahmood Jun 26, 2024
361d783
Fix lint
hmahmood Jun 26, 2024
72ad33a
Fix go.sum
hmahmood Jun 27, 2024
8326634
Fix windows
hmahmood Jun 27, 2024
2cd3aaa
Rename network_config.enable_ebpf_less to network_config.enable_ebpfless
hmahmood Jun 27, 2024
e1258c9
Fix windows
hmahmood Jun 27, 2024
4e502e6
Fix netlink conntracker loading to check for NET_ADMIN permissions
hmahmood Jun 27, 2024
31f27a6
Merge remote-tracking branch 'origin/main' into hasan.mahmood/ebpfles…
hmahmood Jun 27, 2024
08c06aa
Remove old comment
hmahmood Jun 27, 2024
b69ef5a
Remove empty file
hmahmood Jun 27, 2024
d985ac6
Fix lint
hmahmood Jun 27, 2024
64fcc03
Merge remote-tracking branch 'origin/main' into hasan.mahmood/ebpfles…
hmahmood Jul 8, 2024
0e39567
Review comments
hmahmood Jul 9, 2024
7ff5a97
Move check for USM support into IsUSMSupported
hmahmood Jul 15, 2024
93fa333
Fix Dockefile
hmahmood Jul 15, 2024
6dc8d7d
Rename IsUSMSupported to CheckUSMSupported
hmahmood Jul 15, 2024
1f504c4
Lint
hmahmood Jul 15, 2024
61dec8d
Merge remote-tracking branch 'origin/main' into hasan.mahmood/ebpfles…
hmahmood Jul 15, 2024
c014ee7
Update go.sum
hmahmood Jul 15, 2024
bae0798
Move check for tracefs to newEbpfTracer
hmahmood Jul 16, 2024
5a10f17
Review comments
hmahmood Jul 16, 2024
907b44d
Merge remote-tracking branch 'origin/main' into hasan.mahmood/ebpfles…
hmahmood Jul 16, 2024
b4efeb5
Adding reason for disabling configs
hmahmood Jul 16, 2024
8c72538
Update go.sum
hmahmood Jul 16, 2024
398e8d8
Remove http configs from disable code
hmahmood Jul 18, 2024
ba54c03
Fix compile error
hmahmood Jul 18, 2024
7297f4b
Fix lint
hmahmood Jul 23, 2024
cfa736d
Merge remote-tracking branch 'origin/main' into hasan.mahmood/ebpfles…
hmahmood Jul 23, 2024
714bf2d
Update go.sum
hmahmood Jul 23, 2024
a97b0af
Review comments
hmahmood Jul 25, 2024
c466fbb
Merge remote-tracking branch 'origin/main' into hasan.mahmood/ebpfles…
hmahmood Jul 25, 2024
15e587e
Merge remote-tracking branch 'origin/main' into hasan.mahmood/ebpfles…
hmahmood Jul 30, 2024
4819981
Update go.sum
hmahmood Jul 30, 2024
0502fb9
Move linux only test functions
hmahmood Jul 30, 2024
ab537d4
Add PacketInfo for each packet reported
hmahmood Jul 31, 2024
14b6ee9
Fix windows
hmahmood Aug 1, 2024
21e40e3
Review comments
hmahmood Aug 1, 2024
e002855
Return error from SetEbpf on reflect failures
hmahmood Aug 5, 2024
0621be0
Review comments
hmahmood Aug 5, 2024
75bab0b
Merge remote-tracking branch 'origin/main' into hasan.mahmood/ebpfles…
hmahmood Aug 5, 2024
b0030e8
Removed unused code
hmahmood Aug 7, 2024
ac937f7
Review comments
hmahmood Aug 8, 2024
f6e3146
Fix typo
hmahmood Aug 9, 2024
ef365aa
Merge remote-tracking branch 'origin/main' into hasan.mahmood/ebpfles…
hmahmood Aug 9, 2024
bce4868
Remove Layers object
hmahmood Aug 13, 2024
6844568
Merge remote-tracking branch 'origin/main' into hasan.mahmood/ebpfles…
hmahmood Aug 13, 2024
eae3003
Add comments
hmahmood Aug 14, 2024
e533dd0
Fix build
hmahmood Aug 19, 2024
1a216d4
Merge remote-tracking branch 'origin/main' into hasan.mahmood/ebpfles…
hmahmood Aug 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions cmd/system-probe/config/adjust_npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
)

func adjustNetwork(cfg config.Config) {
ebpflessEnabled := cfg.GetBool(netNS("enable_ebpf_less"))
Comment thread
hmahmood marked this conversation as resolved.
Outdated

limitMaxInt(cfg, spNS("max_conns_per_message"), maxConnsMessageBatchSize)

if cfg.GetBool(spNS("disable_tcp")) {
Expand Down Expand Up @@ -90,4 +92,25 @@ func adjustNetwork(cfg config.Config) {
log.Warn("disabling NPM connection rollups since USM connection rollups are not enabled")
cfg.Set(netNS("enable_connection_rollup"), false, model.SourceAgentRuntime)
}

// disable features that are not supported on certain
// configs/platforms
var disableConfigs []string
if ebpflessEnabled {
disableConfigs = append(disableConfigs,
spNS("enable_conntrack_all_namespaces"),
netNS("enable_protocol_classification"),
netNS("enable_http_monitoring"),
netNS("enable_https_monitoring"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove, those are legacy USM values

Copy link
Copy Markdown
Contributor Author

@hmahmood hmahmood Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if they are set by the customer shouldn't they be referenced here? adjustNPM is called before adjustUSM, so in order for the code in adjustUSM to do the right thing, we would have to set them up here correctly right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I'm following the comment

if a customer set them, USM is the one to handle them (we have backward compatibility)
if there is a gap - please let me know so we can fix it correctly

also, USM will be disabled with ebpfless mode, in that case, it does not matter what will be the content of enable_http_monitoring and enable_https_monitoring as USM won't run

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed them

evNS("network_process", "enabled"),
netNS("enable_root_netns"),
)
}

for _, c := range disableConfigs {
if cfg.GetBool(c) {
log.Warnf("disabling %s since it is not supported for this config/platform", c)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth explaining why those are not supported

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cfg.Set(c, false, model.SourceAgentRuntime)
}
}
}
7 changes: 7 additions & 0 deletions cmd/system-probe/config/adjust_usm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ import (
"fmt"

"github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/config/model"
"github.com/DataDog/datadog-agent/pkg/util/log"
)

const (
maxHTTPFrag = 512 // matches hard limit currently imposed in NPM driver
)

func adjustUSM(cfg config.Config) {
if cfg.GetBool(netNS("enable_ebpf_less")) && cfg.GetBool(smNS("enabled")) {
log.Warn("disabling USM since ebpf-less network tracer is enabled")
cfg.Set(smNS("enabled"), false, model.SourceAgentRuntime)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned by the current change
enabling one feature of NPM should not disable USM

I think that if a customer enables USM on fargate, system probe should fail until they fix the configuration
or system-probe should not start if both USM and ebpfless are enabled

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here https://github.com/datadog/datadog-agent/blob/hasan.mahmood/ebpfless-tracer/pkg/network/tracer/tracer.go#L152 we do continue if usm is enabled and not supported and npm is enabled. Isn't this equivalent scenario? I can add the check for npm enabled.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not equivalent as I see it
the example you shared handles the case where USM is not able to run
the current PR does not guarantees we're running on fargate (and then USM is not supported), but instead, on any supported kernel, with the new configuration enabled, we will force shutting down USM.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the idea is there is no ebpf-less implementation of USM yet, so how can we continue with enabling USM? This is just a way to not touch multiple points in code to disable USM later on during the load.

Copy link
Copy Markdown
Contributor

@guyarb guyarb Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are assuming NPM configuration should take precedence over USM configuration
We can even say, If USM is enabled, then force disable ebpfless configuration, and just print a warning log

The bottom line, we cannot assume what the customer meant, or even if the customer is aware ebpfless is not supported by USM

if cfg.GetBool(smNS("enabled")) {
applyDefault(cfg, netNS("enable_http_monitoring"), true)
applyDefault(cfg, netNS("enable_https_monitoring"), true)
Expand Down
5 changes: 2 additions & 3 deletions cmd/system-probe/modules/network_tracer_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ package modules
import (
"github.com/DataDog/datadog-agent/cmd/system-probe/api/module"
"github.com/DataDog/datadog-agent/cmd/system-probe/config"
"github.com/DataDog/datadog-agent/pkg/network/tracer"
)

// NetworkTracer is a factory for NPM's tracer
var NetworkTracer = module.Factory{
Name: config.NetworkTracerModule,
ConfigNamespaces: networkTracerModuleConfigNamespaces,
Fn: createNetworkTracerModule,
NeedsEBPF: func() bool {
return true
},
NeedsEBPF: tracer.NeedsEBPF,
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -1374,3 +1374,5 @@ replace (

// Prevent a false-positive detection by the Google and Ikarus security vendors on VirusTotal
exclude go.opentelemetry.io/proto/otlp v1.1.0

replace github.com/google/gopacket v1.1.19 => github.com/DataDog/gopacket v0.0.0-20240626205202-4ac4cee31f14
Comment thread
guyarb marked this conversation as resolved.
7 changes: 5 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/config/setup/system_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ func InitSystemProbeConfig(cfg pkgconfigmodel.Config) {
// connection aggregation with port rollups
cfg.BindEnvAndSetDefault(join(netNS, "enable_connection_rollup"), false)

cfg.BindEnvAndSetDefault(join(netNS, "enable_ebpf_less"), false)

// windows config
cfg.BindEnvAndSetDefault(join(spNS, "windows.enable_monotonic_count"), false)

Expand Down
19 changes: 19 additions & 0 deletions pkg/ebpf/ebpftest/buildmode.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ var (
RuntimeCompiled BuildMode
CORE BuildMode
Fentry BuildMode
Ebpfless BuildMode
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we should dedicate some time to the build modes. I don't think it's a blocker for this PR considering it's a PoC and the ebpfless mode isn't enabled by default (wdyt @brycekahle?), but we could probably find a way to reconciliate the actual eBPF build modes (prebuild/runtime/CORE) with fentry and ebpfless which are not something we'll want in the rest of test code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ebpfless feels OK because it is mutually exclusive from prebuilt/rc/co-re. fentry is the confusing one, because that could be any of the build modes.


func init() {
Prebuilt = prebuilt{}
RuntimeCompiled = runtimeCompiled{}
CORE = core{}
Fentry = fentry{}
Ebpfless = ebpfless{}
}

// BuildMode is an eBPF build mode
Expand Down Expand Up @@ -95,6 +97,23 @@ func (f fentry) Env() map[string]string {
}
}

type ebpfless struct{}

func (e ebpfless) String() string {
return "eBPFless"
}

func (e ebpfless) Env() map[string]string {
return map[string]string{
"NETWORK_TRACER_FENTRY_TESTS": "false",
"DD_ENABLE_RUNTIME_COMPILER": "false",
"DD_ENABLE_CO_RE": "false",
"DD_ALLOW_RUNTIME_COMPILED_FALLBACK": "false",
"DD_ALLOW_PRECOMPILED_FALLBACK": "false",
"DD_NETWORK_CONFIG_ENABLE_EBPF_LESS": "true",
Comment thread
hmahmood marked this conversation as resolved.
Outdated
}
}

// GetBuildMode returns which build mode the current environment matches, if any
func GetBuildMode() BuildMode {
for _, mode := range []BuildMode{Prebuilt, RuntimeCompiled, CORE, Fentry} {
Expand Down
4 changes: 4 additions & 0 deletions pkg/ebpf/ebpftest/buildmode_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func SupportedBuildModes() []BuildMode {
(runtime.GOARCH == "amd64" && (hostPlatform == "amazon" || hostPlatform == "amzn") && kv.Major() == 5 && kv.Minor() == 10) {
modes = append(modes, Fentry)
}
if os.Getenv("TEST_EBPF_LESS_OVERRIDE") == "true" {
Comment thread
hmahmood marked this conversation as resolved.
Outdated
modes = append(modes, Ebpfless)
}

return modes
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/network/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ type Config struct {
// buffers (>=5.8) will result in forcing the use of Perf Maps instead.
EnableUSMRingBuffers bool

EnableEbpfless bool

// EnableUSMEventStream enables USM to use the event stream instead
// of netlink for receiving process events.
EnableUSMEventStream bool
Expand Down Expand Up @@ -393,6 +395,8 @@ func New() *Config {

EnableNPMConnectionRollup: cfg.GetBool(join(netNS, "enable_connection_rollup")),

EnableEbpfless: cfg.GetBool(join(netNS, "enable_ebpf_less")),

// Service Monitoring
EnableJavaTLSSupport: cfg.GetBool(join(smjtNS, "enabled")),
JavaAgentDebug: cfg.GetBool(join(smjtNS, "debug")),
Expand Down
53 changes: 27 additions & 26 deletions pkg/network/dns/monitor_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"fmt"
"math"

"golang.org/x/net/bpf"

"github.com/vishvananda/netns"

manager "github.com/DataDog/ebpf-manager"
Expand All @@ -33,6 +31,26 @@ type dnsMonitor struct {

// NewReverseDNS starts snooping on DNS traffic to allow IP -> domain reverse resolution
func NewReverseDNS(cfg *config.Config, _ telemetry.Component) (ReverseDNS, error) {
// Create the RAW_SOCKET inside the root network namespace
var (
packetSrc *filterpkg.AFPacketSource
srcErr error
ns netns.NsHandle
)
ns, err := cfg.GetRootNetNs()
if err != nil {
return nil, err
}
defer ns.Close()

err = kernel.WithNS(ns, func() error {
packetSrc, srcErr = filterpkg.NewPacketSource(4)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to a reader that 4 is a MB value. Also, how did you choose 4 megabytes? That seems huge for DNS

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 4 MB comes from here:

afpacket.OptFrameSize(4096),

return srcErr
})
if err != nil {
return nil, err
}

currKernelVersion, err := kernel.HostVersion()
if err != nil {
// if the platform couldn't be determined, treat it as new kernel case
Expand All @@ -42,12 +60,11 @@ func NewReverseDNS(cfg *config.Config, _ telemetry.Component) (ReverseDNS, error
pre410Kernel := currKernelVersion < kernel.VersionCode(4, 1, 0)

var p *ebpfProgram
var filter *manager.Probe
var bpfFilter []bpf.RawInstruction
if pre410Kernel {
bpfFilter, err = generateBPFFilter(cfg)
if err != nil {
if pre410Kernel || cfg.EnableEbpfless {
if bpfFilter, err := generateBPFFilter(cfg); err != nil {
return nil, fmt.Errorf("error creating bpf classic filter: %w", err)
} else if err = packetSrc.SetBPF(bpfFilter); err != nil {
return nil, fmt.Errorf("could not set BPF filter on packet source: %w", err)
}
} else {
p, err = newEBPFProgram(cfg)
Expand All @@ -59,35 +76,19 @@ func NewReverseDNS(cfg *config.Config, _ telemetry.Component) (ReverseDNS, error
return nil, fmt.Errorf("error initializing ebpf programs: %w", err)
}

filter, _ = p.GetProbe(manager.ProbeIdentificationPair{EBPFFuncName: probes.SocketDNSFilter, UID: probeUID})
filter, _ := p.GetProbe(manager.ProbeIdentificationPair{EBPFFuncName: probes.SocketDNSFilter, UID: probeUID})
Comment thread
leeavital marked this conversation as resolved.
if filter == nil {
return nil, fmt.Errorf("error retrieving socket filter")
}
}

// Create the RAW_SOCKET inside the root network namespace
var (
packetSrc *filterpkg.AFPacketSource
srcErr error
ns netns.NsHandle
)
if ns, err = cfg.GetRootNetNs(); err != nil {
return nil, err
}
defer ns.Close()

err = kernel.WithNS(ns, func() error {
packetSrc, srcErr = filterpkg.NewPacketSource(filter, bpfFilter)
return srcErr
})
if err != nil {
return nil, err
packetSrc.SetEbpf(filter)
}

snoop, err := newSocketFilterSnooper(cfg, packetSrc)
if err != nil {
return nil, err
}

return &dnsMonitor{
snoop,
p,
Expand Down
2 changes: 1 addition & 1 deletion pkg/network/dns/packet_source_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func newWindowsPacketSource(telemetrycomp telemetry.Component) (packetSource, er
return &windowsPacketSource{di: di}, nil
}

func (p *windowsPacketSource) VisitPackets(exit <-chan struct{}, visit func([]byte, time.Time) error) error {
func (p *windowsPacketSource) VisitPackets(exit <-chan struct{}, visit func([]byte, _ uint8, time.Time) error) error {
for {
didReadPacket, err := p.di.ReadDNSPacket(visit)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/network/dns/snooper.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type packetSource interface {
// The format of the packet is dependent on the implementation of packetSource -- i.e. it may be an ethernet frame, or a IP frame.
// The data buffer is reused between invocations of VisitPacket and thus should not be pointed to.
// If the cancel channel is closed, VisitPackets will stop reading.
VisitPackets(cancel <-chan struct{}, visitor func(data []byte, timestamp time.Time) error) error
VisitPackets(cancel <-chan struct{}, visitor func(data []byte, _ uint8, timestamp time.Time) error) error

// PacketType returns the type of packet this source reads
PacketType() gopacket.LayerType
Expand Down Expand Up @@ -154,7 +154,7 @@ func (s *socketFilterSnooper) Close() {
// The *translation is recycled and re-used in subsequent calls and it should not be accessed concurrently.
// The second parameter `ts` is the time when the packet was captured off the wire. This is used for latency calculation
// and much more reliable than calling time.Now() at the user layer.
func (s *socketFilterSnooper) processPacket(data []byte, ts time.Time) error {
func (s *socketFilterSnooper) processPacket(data []byte, _ uint8, ts time.Time) error {
t := s.getCachedTranslation()
pktInfo := dnsPacketInfo{}

Expand Down
2 changes: 1 addition & 1 deletion pkg/network/dns/snooper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func TestParsingError(t *testing.T) {

reverseDNS := rdns.(*dnsMonitor)
// Pass a byte array of size 1 which should result in parsing error
err = reverseDNS.processPacket(make([]byte, 1), time.Now())
err = reverseDNS.processPacket(make([]byte, 1), 0, time.Now())
require.NoError(t, err)
assert.True(t, cacheTelemetry.length.Load() == 0)
assert.True(t, snooperTelemetry.decodingErrors.Load() == 1)
Expand Down
12 changes: 12 additions & 0 deletions pkg/network/event_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const (
maxByteCountChange uint64 = 375 << 30
// use typical small MTU size, 1300, to get max packet count
maxPacketCountChange uint64 = maxByteCountChange / 1300

// ConnectionByteKeyMaxLen represents the maximum size in bytes of a connection byte key
ConnectionByteKeyMaxLen = 41
)

// ConnectionType will be either TCP or UDP
Expand Down Expand Up @@ -338,6 +341,15 @@ func (c ConnectionStats) ByteKeyNAT(buf []byte) []byte {
return generateConnectionKey(c, buf, true)
}

// IsValid returns `true` if the connection has a valid source and dest
// ports and IPs
func (c ConnectionStats) IsValid() bool {
return c.Source.IsValid() &&
c.Dest.IsValid() &&
c.SPort > 0 &&
c.DPort > 0
}

const keyFmt = "p:%d|src:%s:%d|dst:%s:%d|f:%d|t:%d"

// BeautifyKey returns a human readable byte key (used for debugging purposes)
Expand Down
Loading