主要变更内容¶
新增 -q/--quiet 参数¶
新增 -q/--quiet 参数用于精简输出内容:
13:50:35.524360 lo curl.345650 Out IP 127.0.0.1.58694 > 127.0.0.1.8000: tcp 0, ParentProc [bash.345626]
新增 --context 参数¶
新增 --context 参数用于指定输出中包含的上下文信息,可以通过这个参数控制只显示特定的上下文信息。
通过 --context=process 限制只输出进程信息:
# --context=process 09:32:09.718892 vethee2a302f wget.3553008 In IP 10.244.0.2.33426 > 139.178.84.217.80: Flags [S], seq 4113492822, win 64240, length 0 # -v --context=process 13:44:41.529003 eth0 In IP (tos 0x4, ttl 45, id 45428, offset 0, flags [DF], proto TCP (6), length 52) 139.178.84.217.443 > 172.19.0.2.42606: Flags [.], cksum 0x5284, seq 3173118145, ack 1385712707, win 118, options [nop,nop,TS val 134560683 ecr 1627716996], length 0 Process (pid 553587, cmd /usr/bin/wget, args wget kernel.org)
该参数既支持通过英文逗号分割多个值,也支持多次指定参数的方式指定多个值:
# -v --context=process,parentproc # -v --context=process --context=parentproc 13:44:41.529003 eth0 In IP (tos 0x4, ttl 45, id 45428, offset 0, flags [DF], proto TCP (6), length 52) 139.178.84.217.443 > 172.19.0.2.42606: Flags [.], cksum 0x5284, seq 3173118145, ack 1385712707, win 118, options [nop,nop,TS val 134560683 ecr 1627716996], length 0 Process (pid 553587, cmd /usr/bin/wget, args wget kernel.org) ParentProc (pid 553296, cmd /bin/sh, args sh) # -v --context=process,parentproc,container # -v --context=process --context=parentproc --context=container 13:44:41.529003 eth0 In IP (tos 0x4, ttl 45, id 45428, offset 0, flags [DF], proto TCP (6), length 52) 139.178.84.217.443 > 172.19.0.2.42606: Flags [.], cksum 0x5284, seq 3173118145, ack 1385712707, win 118, options [nop,nop,TS val 134560683 ecr 1627716996], length 0 Process (pid 553587, cmd /usr/bin/wget, args wget kernel.org) ParentProc (pid 553296, cmd /bin/sh, args sh) Container (name test, id d9028334568bf75a5a084963a8f98f78c56bba7f45f823b3780a135b71b91e95, image docker.io/library/alpine:3.18, labels {"io.cri-containerd.kind":"container","io.kubernetes.container.name":"test","io.kubernetes.pod.name":"test","io.kubernetes.pod.namespace":"default","io.kubernetes.pod.uid":"9e4bc54b-de48-4b1c-8b9e-54709f67ed0c"})
在高版本内核中使用 fentry, btf raw tracepoint 以及 tcx ebpf 特性¶
当在高版本内核中执行 ptcpdump 程序时,程序将自动使用 fentry 代替 kprobe, 使用 btf raw tracepoint 代替 raw tracepoint, 使用 tcx 代替 tc, 通过使用这些新的 ebpf 特性,优化程序在高版本内核下的性能。
新增 --backend 参数¶
新增 --backend 参数用于指定抓包时使用的技术,默认是使用的 tc/tcx 技术。
支持 --backend=cgroup-skb¶
支持通过 --backend=cgroup-skb 参数指定使用 cgroup-skb ebpf 程序进行抓包。 使用该方式抓取的流量将不包含链路层信息,ptcpdump 输出中的链路层信息将是一个固定的 fake 数据。
支持 OpenWrt 24.10 x86-64 系统¶
根据用户的需求反馈,提升程序兼容性,支持在 OpenWrt 24.10 x86-64 系统中使用 ptcpdump (前提是系统内核在编译时启用 ebpf 和 BTF 相关参数)。
支持在输出中显示线程信息¶
当通过 --backend=cgroup-skb 进行抓包时,新增在输出中显示线程信息:
$ sudo ptcpdump -i any --backend cgroup-skb -v port 80 10:18:26.846884 ens33 Out IP (tos 0x0, ttl 64, id 57734, offset 0, flags [DF], proto TCP (6), length 478) xxx.xxx.xxx.35102 > xxx.xxx.xxx.80: Flags [P.], cksum 0x3381, seq xx:xx, ack xx, win 64240, length 438 Process (pid 113278, cmd /snap/firefox/5437/usr/lib/firefox/firefox, args /snap/firefox/5437/usr/lib/firefox/firefox) Thread (tid 113438, name Socket Thread) ParentProc (pid 49607, cmd /usr/bin/xfce4-panel, args xfce4-panel --display :0.0 --sm-client-id xxxx)
支持在输出中显示 uid 以及按 uid 抓包¶
新增在输出中显示 uid 信息:
12:37:40.051539 ens33 Out IP (tos 0x0, ttl 64, id 48697, offset 0, flags [DF], proto TCP (6), length 60) 10.0.x.x.42906 > 139.x.x.x.443: Flags [S], cksum 0xecc8, seq 940329637, win 64240, options [mss 1460,sackOK,TS val 3421262256 ecr 0,nop,wscale 7], length 0 Process (pid 99722, cmd /usr/bin/curl, args curl https://kernel.org) User (uid 1000) ParentProc (pid 18840, cmd /usr/bin/bash, args -bash)
新增支持指定 uid 进行抓包:
$ sudo ptcpdump -i any --uid 100 -v port 80
如果你对 ptcpdump 有额外的改进或新功能建议,欢迎在评论区或项目 issues 中留言。
Comments