Skip to content
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

feat: dae trace #435

Merged
merged 3 commits into from
Jan 27, 2024
Merged

feat: dae trace #435

merged 3 commits into from
Jan 27, 2024

Conversation

jschwinger233
Copy link
Member

@jschwinger233 jschwinger233 commented Jan 20, 2024

Background

This PR adds new subcommand dae trace to observe skb on the system.

dae $ ./dae trace -h
To trace traffic

Usage:
  dae trace [flags]

Flags:
  -h, --help              help for trace
  -4, --ipv4              Capture IPv4 traffic
  -6, --ipv6              Capture IPv6 traffic
  -p, --l4-proto string   Layer 4 protocol (default "tcp")
  -o, --output string     Output file (default "/dev/stdout")
  -P, --port int          Port (default 80)

For example, running dae trace -4 -p tcp -P 233 gives:

dae $ sudo ./dae trace -4 -p tcp -P 80
attaching kprobes: 1704/1704
start tracing
ffff92132a71d8e8 mark=0 netns=4026531840 if=0() proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=65476 ip_local_out
ffff92132a71d8e8 mark=0 netns=4026531840 if=0() proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=65476 __ip_local_out
ffff92132a71d8e8 mark=0 netns=4026531840 if=0() proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 nf_hook_slow
ffff92132a71d8e8 mark=0 netns=4026531840 if=0() proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 ip_output
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 nf_hook_slow
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 apparmor_ip_postroute
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 ip_finish_output
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 __ip_finish_output
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 ip_finish_output2
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 __dev_queue_xmit
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 qdisc_pkt_len_init
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 netdev_core_pick_tx
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 sch_direct_xmit
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 validate_xmit_skb_list
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 validate_xmit_skb
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 netif_skb_features
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 passthru_features_check
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 skb_network_protocol
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 skb_csum_hwoffload_help
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 validate_xmit_xfrm
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 dev_hard_start_xmit
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=141081(curl) 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 skb_clone_tx_timestamp
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=0() 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 dev_kfree_skb_any_reason
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=0() 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 kfree_skb_reason(SKB_CONSUMED)
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=0() 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 skb_release_head_state
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=0() 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 tcp_wfree
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=0() 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 skb_release_data
ffff92132a71d8e8 mark=0 netns=4026531840 if=2(enp0s31f6) proc=0() 10.0.0.6:47812 > 1.1.1.1:80 tcp_flags=S payload_len=0 kfree_skbmem

Notes:

  1. The binary size has increased less than 1M, so I presume it's acceptable.
  2. trace.c has to be compiled with specific arch instead of general bpf, so dae trace only supports some arch:
Supported targets:
	386
	amd64
	arm
	arm64
	arm64be
	armbe
	ppc64
	ppc64le
	riscv64
	s390
	s390x
	sparc
	sparc64

Outstanding issues:

Checklist

Full Changelogs

  • [Implement ...]

Issue Reference

Closes #[issue number]

Test Result

cmd/trace.go Outdated
},
}

traceCmd.PersistentFlags().IntVarP(&IPVersion, "ip-version", "v", 4, "IP version")
Copy link
Contributor

Choose a reason for hiding this comment

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

-v is confusing (verbose/version). Can we use -4 and -6?

@jschwinger233 jschwinger233 force-pushed the gray/tracing branch 3 times, most recently from 3ccd3b0 to cb58b97 Compare January 21, 2024 05:07
@jschwinger233
Copy link
Member Author

Mark "Ready for review" to trigger PR build.

@jschwinger233 jschwinger233 marked this pull request as ready for review January 21, 2024 07:17
@jschwinger233 jschwinger233 requested a review from a team as a code owner January 21, 2024 07:17
@jschwinger233 jschwinger233 requested a review from mzz2017 January 21, 2024 07:26
Copy link
Contributor

@mzz2017 mzz2017 left a comment

Choose a reason for hiding this comment

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

This work is owesome!

@sumire88
Copy link
Contributor

@jschwinger233 thanks for your amazing work. Has this new feature been tested yet?

Copy link
Contributor

@dae-prow dae-prow bot left a comment

Choose a reason for hiding this comment

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

🧪 Since the PR has been fully tested, please consider merging it.

@sumire88
Copy link
Contributor

All good, let's proceed.

@jschwinger233 jschwinger233 merged commit 5f3249b into daeuniverse:main Jan 27, 2024
27 checks passed
@douglarek
Copy link
Contributor

A very interesting feature! Regarding the Go environment variable GOARCH, is that it is not automatically injected for the 'make' command. Would it be better to default to 'go env GOARCH' in 'make' if the user has not set it explicitly?

@dae-prow dae-prow bot mentioned this pull request Jun 11, 2024
oluceps added a commit to oluceps/nixpkgs that referenced this pull request Jun 18, 2024
This will build the `trace` command which dae added
few months ago. See <daeuniverse/dae#435>
for detail.

Co-authored-by: Aleksana <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants