tcpaccept.bt(8)

πŸ“¦
version 0.27.0 Β· 3 versions
  • 0.27.0 Β· alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.14.0 Β· ubuntu jammy
  • 0.20.2 Β· ubuntu noble
, in alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸŽ€ tcpaccept.bt πŸŽ€

✨ NAME ✨

okay so the manual name is tcpaccept.bt (section 8) and it's giving trace TCP passive connections (accept()) πŸ’… it uses bpftrace/eBPF under the hood, obsessed πŸ”₯

tcpaccept.bt

πŸ‘‘ SYNOPSIS πŸ‘‘

Just type the name, that's the whole spell ✨

tcpaccept.bt

πŸ’– DESCRIPTION πŸ’–

okay bestie, this tool traces passive TCP connections (like the ones from an accept() syscall). connect() calls are the active ones, so they're not the vibe here πŸ™ˆ It's super useful for general troubleshooting when you wanna see what new connections your local server is accepting, iconic πŸ¦‹

It works by dynamic tracing of the kernel inet_csk_accept() socket function (the one from tcp_prot.accept). ⚠️ Heads up, it'll need to be modified to match kernel changes, so don't be shocked if it needs a glow-up later 🧚

Also, this tool only catches successful TCP accept()s. Connection attempts to closed ports won't show up, so if you need those, you gotta trace them with other functions πŸ’€

And because it uses BPF, only the root user can run it. No sneaking in πŸ”’


🌸 REQUIREMENTS 🌸

You need CONFIG_BPF and bpftrace. Non-negotiable, periodt πŸ’…


πŸŽ€ EXAMPLES πŸŽ€

Trace all passive TCP connections (accept()s):

# tcpaccept.bt

πŸ¦‹ FIELDS πŸ¦‹

Here's what the output columns mean, no cap:

  • TIME(s) β€” Time of the call, in HH:MM:SS format.
  • PID β€” Process ID.
  • COMM β€” Process name.
  • RADDR β€” Remote IP address.
  • RPORT β€” Remote port.
  • LADDR β€” Local IP address.
  • LPORT β€” Local port
  • BL β€” Current accept backlog vs maximum backlog

🧚 OVERHEAD 🧚

This one traces the kernel inet_csk_accept function and prints output for every single event. How much it costs you depends on your server app, bestie. If it's a web or proxy server accepting many tens of thousands of connections per second, the overhead might be measurable (though honestly still way better than tracing every packet 😭). If it's less than a thousand a second, the overhead is expected to be negligible ✨ Test it and understand the overhead before you use it, fr fr 🫢


🌈 SOURCE 🌈

This one's from bpftrace, go check it out πŸ’œ

https://github.com/bpftrace/bpftrace

Also peek in the bpftrace distribution for a companion _examples.txt file with example usage, output, and commentary for this tool. It's giving extra credit πŸ“š

It's a bpftrace version of the bcc tool of the same name. The bcc tool might have more options and customizations, so if you're craving more, go there πŸ“

https://github.com/iovisor/bcc

πŸ’… OS πŸ’…

Linux, obviously 🐧


πŸ™ˆ STABILITY πŸ™ˆ

Unstable - in development. It's still cooking, so be gentle 🍳


πŸ”₯ AUTHOR πŸ”₯

Brendan Gregg, adapted for bpftrace by Dale Hamel. Iconic duo, literally ⭐


⭐ SEE ALSO ⭐

Check out tcpconnect.bt(8), funccount(8), and tcpdump(8) for more tea β˜•


🫢 Okay bestie, that's the whole page! Bye bye, from the USER COMMANDS section, dated 2018-10-24, all about tcpaccept.bt(8) πŸ’–βœ¨