-
Notifications
You must be signed in to change notification settings - Fork 0
Add ping command
#110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AlexandreYang
wants to merge
22
commits into
main
Choose a base branch
from
alex/ping
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,105
−27
Open
Add ping command
#110
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
dc30e2d
empty
AlexandreYang d9d0ef7
Merge branch 'main' into alex/ping
AlexandreYang 0abfa86
Implement ping builtin using datadog-traceroute ICMP E2E probe
AlexandreYang 371cf65
fix: use lowercase protocol string for datadog-traceroute ICMP matching
AlexandreYang 34cf0f9
[iter 1] Add MaxInterval bound, clarify allowlist comments
AlexandreYang 2f6522b
[iter 1] Fix packet loss percentage, document interval limitation, ad…
AlexandreYang e33a60f
[iter 1] Add missing LICENSE-3rdparty.csv entries for datadog-tracero…
AlexandreYang a935536
[iter 2] Skip failed E2E probes, fix NaN interval, harden fuzz test
AlexandreYang 04ec64a
[iter 2] Fix Fuzz (ping) CI timeout by enforcing context cancellation
AlexandreYang 6b71c70
[iter 3] Add result package to allowedsymbols, fix fuzz exit code, ad…
AlexandreYang b392924
[iter 3] Fix FuzzPingFlags: filter pipe/compound shell constructs fro…
AlexandreYang 155a2ed
[iter 8] Use RSHELL_PING_TEST env var for ping integration tests
AlexandreYang 27759bc
Add RSHELL_PING_TEST env guard and CI job for ping integration tests
AlexandreYang c6a9a1e
[iter 9] Fix CI: ping integration sudo PATH, macOS ICMP privileges, l…
AlexandreYang 818ed1a
[iter 9] Skip multi-ping integration test on Windows
AlexandreYang 0ed122e
[iter 1] Address review comments: exact reply count assertion, docume…
AlexandreYang 90666eb
[iter 1] Skip ping integration test entirely on Windows
AlexandreYang e24a3fa
[iter 2] Fix float promotion in packet loss display and add Windows i…
AlexandreYang 0943be7
[iter 2] Fix Windows ping integration test: accept exit code 0 or 1
AlexandreYang 9dfefe3
[iter 4] Expand ping CI test filter and tolerate Windows ICMP failures
AlexandreYang 94f6acc
[iter 6] Enforce ping-count assertions in Windows integration path
AlexandreYang f807fec
[iter 7] Fix Windows ping integration test: tolerate partial packet loss
AlexandreYang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,53 @@ | ||
| Component,Origin,License,Copyright | ||
| github.com/stretchr/testify,https://github.com/stretchr/testify,MIT,"Copyright (c) 2012-2020 Mat Ryer, Tyler Bunnell and contributors" | ||
| gopkg.in/yaml.v3,https://github.com/go-yaml/yaml,MIT AND Apache-2.0,"Copyright (c) 2006-2011 Kirill Simonov, 2011-2019 Canonical Ltd" | ||
| mvdan.cc/sh/v3,https://github.com/mvdan/sh,BSD-3-Clause,"Copyright (c) 2016, Daniel Marti" | ||
| github.com/DataDog/datadog-traceroute,https://github.com/DataDog/datadog-traceroute,Apache-2.0,Copyright 2024-present Datadog Inc. | ||
| github.com/DataDog/datadog-agent/comp/core/telemetry,https://github.com/DataDog/datadog-agent,Apache-2.0,Copyright 2016-present Datadog Inc. | ||
| github.com/DataDog/datadog-agent/comp/def,https://github.com/DataDog/datadog-agent,Apache-2.0,Copyright 2016-present Datadog Inc. | ||
| github.com/DataDog/datadog-agent/pkg/network/driver,https://github.com/DataDog/datadog-agent,Apache-2.0,Copyright 2016-present Datadog Inc. | ||
| github.com/DataDog/datadog-agent/pkg/telemetry,https://github.com/DataDog/datadog-agent,Apache-2.0,Copyright 2016-present Datadog Inc. | ||
| github.com/DataDog/datadog-agent/pkg/util/fxutil,https://github.com/DataDog/datadog-agent,Apache-2.0,Copyright 2016-present Datadog Inc. | ||
| github.com/DataDog/datadog-agent/pkg/util/log,https://github.com/DataDog/datadog-agent,Apache-2.0,Copyright 2016-present Datadog Inc. | ||
| github.com/DataDog/datadog-agent/pkg/util/optional,https://github.com/DataDog/datadog-agent,Apache-2.0,Copyright 2016-present Datadog Inc. | ||
| github.com/DataDog/datadog-agent/pkg/util/scrubber,https://github.com/DataDog/datadog-agent,Apache-2.0,Copyright 2016-present Datadog Inc. | ||
| github.com/DataDog/datadog-agent/pkg/util/winutil,https://github.com/DataDog/datadog-agent,Apache-2.0,Copyright 2016-present Datadog Inc. | ||
| github.com/DataDog/datadog-agent/pkg/version,https://github.com/DataDog/datadog-agent,Apache-2.0,Copyright 2016-present Datadog Inc. | ||
| github.com/beorn7/perks,https://github.com/beorn7/perks,MIT,Copyright (C) 2013 Blake Mizerany | ||
| github.com/cenkalti/backoff/v5,https://github.com/cenkalti/backoff,MIT,Copyright (c) 2014 Cenk Alti | ||
| github.com/cespare/xxhash/v2,https://github.com/cespare/xxhash,MIT,Copyright (c) 2016 Caleb Spare | ||
| github.com/cihub/seelog,https://github.com/cihub/seelog,BSD-3-Clause,"Copyright (c) 2012, Cloud Instruments Co. Ltd." | ||
| github.com/davecgh/go-spew,https://github.com/davecgh/go-spew,ISC,Copyright (c) 2012-2016 Dave Collins | ||
| github.com/go-logr/logr,https://github.com/go-logr/logr,Apache-2.0,Copyright 2019 The logr Authors | ||
| github.com/go-logr/stdr,https://github.com/go-logr/stdr,Apache-2.0,Copyright 2021 The logr Authors | ||
| github.com/golang/mock,https://github.com/golang/mock,Apache-2.0,Copyright 2010 Google Inc. | ||
| github.com/google/gopacket,https://github.com/google/gopacket,BSD-3-Clause,Copyright (c) 2012 Google Inc. All rights reserved. | ||
| github.com/google/uuid,https://github.com/google/uuid,BSD-3-Clause,"Copyright (c) 2009, 2014 Google Inc. All rights reserved." | ||
| github.com/inconshreveable/mousetrap,https://github.com/inconshreveable/mousetrap,Apache-2.0,Copyright 2014 Alan Shreve | ||
| github.com/munnerz/goautoneg,https://github.com/munnerz/goautoneg,BSD-3-Clause,"Copyright (c) 2011, Open Knowledge Foundation Ltd." | ||
| github.com/patrickmn/go-cache,https://github.com/patrickmn/go-cache,MIT,Copyright (c) 2012-2017 Patrick Mylund Nielsen and the go-cache contributors | ||
| github.com/pkg/errors,https://github.com/pkg/errors,BSD-2-Clause,Copyright (c) 2015 Dave Cheney | ||
| github.com/pmezard/go-difflib,https://github.com/pmezard/go-difflib,BSD-3-Clause,"Copyright (c) 2013, Patrick Mezard" | ||
| github.com/prometheus/client_golang,https://github.com/prometheus/client_golang,Apache-2.0,Copyright 2012-2015 The Prometheus Authors | ||
| github.com/prometheus/client_model,https://github.com/prometheus/client_model,Apache-2.0,Copyright 2012-2015 The Prometheus Authors | ||
| github.com/prometheus/common,https://github.com/prometheus/common,Apache-2.0,Copyright 2015 The Prometheus Authors | ||
| github.com/prometheus/procfs,https://github.com/prometheus/procfs,Apache-2.0,Copyright 2014-2015 The Prometheus Authors | ||
| github.com/spf13/cobra,https://github.com/spf13/cobra,Apache-2.0,Copyright 2013-2023 The Cobra Authors | ||
| github.com/spf13/pflag,https://github.com/spf13/pflag,BSD-3-Clause,"Copyright (c) 2012 Alex Ogier, The Go Authors" | ||
| github.com/stretchr/testify,https://github.com/stretchr/testify,MIT,"Copyright (c) 2012-2020 Mat Ryer, Tyler Bunnell and contributors" | ||
| go.opentelemetry.io/auto/sdk,https://github.com/open-telemetry/opentelemetry-go,Apache-2.0,Copyright The OpenTelemetry Authors | ||
| go.opentelemetry.io/otel,https://github.com/open-telemetry/opentelemetry-go,Apache-2.0,Copyright The OpenTelemetry Authors | ||
| go.opentelemetry.io/otel/exporters/prometheus,https://github.com/open-telemetry/opentelemetry-go,Apache-2.0,Copyright The OpenTelemetry Authors | ||
| go.opentelemetry.io/otel/metric,https://github.com/open-telemetry/opentelemetry-go,Apache-2.0,Copyright The OpenTelemetry Authors | ||
| go.opentelemetry.io/otel/sdk,https://github.com/open-telemetry/opentelemetry-go,Apache-2.0,Copyright The OpenTelemetry Authors | ||
| go.opentelemetry.io/otel/sdk/metric,https://github.com/open-telemetry/opentelemetry-go,Apache-2.0,Copyright The OpenTelemetry Authors | ||
| go.opentelemetry.io/otel/trace,https://github.com/open-telemetry/opentelemetry-go,Apache-2.0,Copyright The OpenTelemetry Authors | ||
| go.uber.org/atomic,https://github.com/uber-go/atomic,MIT,Copyright (c) 2016 Uber Technologies Inc. | ||
| go.uber.org/dig,https://github.com/uber-go/dig,MIT,"Copyright (c) 2017-2018 Uber Technologies, Inc." | ||
| go.uber.org/fx,https://github.com/uber-go/fx,MIT,"Copyright (c) 2016-2018 Uber Technologies, Inc." | ||
| go.uber.org/multierr,https://github.com/uber-go/multierr,MIT,"Copyright (c) 2017-2021 Uber Technologies, Inc." | ||
| go.uber.org/zap,https://github.com/uber-go/zap,MIT,"Copyright (c) 2016-2017 Uber Technologies, Inc." | ||
| go.yaml.in/yaml/v2,https://github.com/go-yaml/yaml,Apache-2.0,Copyright 2011-2016 Canonical Ltd. | ||
| golang.org/x/net,https://github.com/golang/net,BSD-3-Clause,Copyright 2009 The Go Authors | ||
| golang.org/x/sync,https://github.com/golang/sync,BSD-3-Clause,Copyright 2009 The Go Authors | ||
| golang.org/x/sys,https://github.com/golang/sys,BSD-3-Clause,Copyright 2009 The Go Authors | ||
| google.golang.org/protobuf,https://github.com/protocolbuffers/protobuf-go,BSD-3-Clause,Copyright (c) 2018 The Go Authors. All rights reserved. | ||
| gopkg.in/yaml.v3,https://github.com/go-yaml/yaml,MIT AND Apache-2.0,"Copyright (c) 2006-2011 Kirill Simonov, 2011-2019 Canonical Ltd" | ||
| mvdan.cc/sh/v3,https://github.com/mvdan/sh,BSD-3-Clause,"Copyright (c) 2016, Daniel Marti" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| // Unless explicitly stated otherwise all files in this repository are licensed | ||
| // under the Apache License Version 2.0. | ||
| // This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| // Copyright 2026-present Datadog, Inc. | ||
|
|
||
| package ping_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| // --- Integer edge cases for -c (count) — validation only, no network --- | ||
|
|
||
| func TestPingPentestCountOverflow(t *testing.T) { | ||
| dir := t.TempDir() | ||
| // Value exceeding int64 range: pflag returns a parse error. | ||
| _, stderr, code := cmdRun(t, "ping -c 99999999999999999999 localhost", dir) | ||
| assert.Equal(t, 1, code) | ||
| assert.Contains(t, stderr, "ping:") | ||
| } | ||
|
|
||
| func TestPingPentestCountEmpty(t *testing.T) { | ||
| dir := t.TempDir() | ||
| // -c with no value: pflag error. | ||
| _, stderr, code := cmdRun(t, "ping -c", dir) | ||
| assert.Equal(t, 1, code) | ||
| assert.Contains(t, stderr, "ping:") | ||
| } | ||
|
|
||
| // --- Integer edge cases for -W (timeout) — validation only --- | ||
|
|
||
| func TestPingPentestTimeoutOverflow(t *testing.T) { | ||
| dir := t.TempDir() | ||
| _, stderr, code := cmdRun(t, "ping -c 1 -W 99999999999999999999 localhost", dir) | ||
| assert.Equal(t, 1, code) | ||
| assert.Contains(t, stderr, "ping:") | ||
| } | ||
|
|
||
| // --- Flag and argument injection --- | ||
|
|
||
| func TestPingPentestDoubleDash(t *testing.T) { | ||
| if os.Getenv("RSHELL_PING_TEST") == "" { | ||
| t.Skip("skipping ping integration test; set RSHELL_PING_TEST=1 and run with sudo on Linux") | ||
| } | ||
| dir := t.TempDir() | ||
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer cancel() | ||
| // -- separates flags from positional args. | ||
| // "ping -- --follow" should treat "--follow" as the hostname, not a flag. | ||
| _, stderr, _ := runScriptCtx(ctx, t, "ping -c 1 -- --follow", dir) | ||
| assert.NotContains(t, stderr, "unknown flag") | ||
| } | ||
|
|
||
| func TestPingPentestFlagViaExpansion(t *testing.T) { | ||
| dir := t.TempDir() | ||
| // Flag-like value via variable expansion. | ||
| _, stderr, code := cmdRun(t, `flag="-f"; ping $flag localhost`, dir) | ||
| assert.Equal(t, 1, code) | ||
| assert.Contains(t, stderr, "unknown shorthand flag") | ||
| } | ||
|
|
||
| func TestPingPentestMultipleUnknownFlags(t *testing.T) { | ||
| dir := t.TempDir() | ||
| _, stderr, code := cmdRun(t, "ping -f -F --exec localhost", dir) | ||
| assert.Equal(t, 1, code) | ||
| assert.Contains(t, stderr, "ping:") | ||
| } | ||
|
|
||
| // --- Hostname edge cases (these hit the network, need short-mode guard) --- | ||
|
|
||
| func TestPingPentestEmptyHostname(t *testing.T) { | ||
| if os.Getenv("RSHELL_PING_TEST") == "" { | ||
| t.Skip("skipping ping integration test; set RSHELL_PING_TEST=1 and run with sudo on Linux") | ||
| } | ||
| dir := t.TempDir() | ||
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer cancel() | ||
| _, _, code := runScriptCtx(ctx, t, `ping -c 1 ""`, dir) | ||
| assert.Equal(t, 1, code) | ||
| } | ||
|
|
||
| func TestPingPentestHostnameWithSpaces(t *testing.T) { | ||
| if os.Getenv("RSHELL_PING_TEST") == "" { | ||
| t.Skip("skipping ping integration test; set RSHELL_PING_TEST=1 and run with sudo on Linux") | ||
| } | ||
| dir := t.TempDir() | ||
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer cancel() | ||
| _, _, code := runScriptCtx(ctx, t, `ping -c 1 "host with spaces"`, dir) | ||
| assert.Equal(t, 1, code) | ||
| } | ||
|
|
||
| func TestPingPentestHostnameInjection(t *testing.T) { | ||
| if os.Getenv("RSHELL_PING_TEST") == "" { | ||
| t.Skip("skipping ping integration test; set RSHELL_PING_TEST=1 and run with sudo on Linux") | ||
| } | ||
| dir := t.TempDir() | ||
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer cancel() | ||
| // Hostname with shell metacharacters in quotes — passed as literal hostname. | ||
| // Should fail on DNS, not execute injected commands. | ||
| _, _, code := runScriptCtx(ctx, t, `ping -c 1 '; echo pwned'`, dir) | ||
| assert.Equal(t, 1, code) | ||
| } | ||
|
|
||
| // --- Count clamping (needs network) --- | ||
|
|
||
| func TestPingPentestCountMaxIntClamped(t *testing.T) { | ||
| if os.Getenv("RSHELL_PING_TEST") == "" { | ||
| t.Skip("skipping ping integration test; set RSHELL_PING_TEST=1 and run with sudo on Linux") | ||
| } | ||
| dir := t.TempDir() | ||
| // Large count gets clamped to MaxCount (1000). With a 5s timeout context, | ||
| // the traceroute will be interrupted before completing all probes. | ||
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer cancel() | ||
| _, stderr, _ := runScriptCtx(ctx, t, "ping -c 2147483647 127.0.0.1", dir) | ||
| // Should NOT get "invalid count" — it was clamped, not rejected. | ||
| assert.NotContains(t, stderr, "invalid count") | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.