跟踪数据包通过内核 (linux)
我有两台机器设置为使用 Ip-Security,机器 A(我们称它们为 A 和 B)有一个套接字,该套接字绑定到本地机器上的特定 UDP 端口,并且它经常轮询它以查看是否收到任何内容在它上面。
当我禁用 IP 安全性时,两台机器之间的数据可以正常传输,并且我可以正常发送和接收数据包。但是,当启用 Ip-Security 时,数据包不会到达由机器 B 发送的机器 A 上的套接字。
我在两台机器上执行 tcpdump
,我可以看到(加密的)数据包正在发送从机器 B 发出并在机器 A 上接收。但此后,数据包进入内核,并且在数据包解密或其他阶段的某个位置,数据包被丢弃。
我希望能够在数据包通过内核时跟踪它并查看它被丢弃的位置。是否有一些 /proc
我可以用于此目的?我能想到的另一种方法是在整个内核中插入调试语句并重新编译它,然后尝试再次发送数据包并进行调试。
感谢并抱歉发了这么长的信息,但这是必要的。
I have two machines which are set up to use Ip-Security and machine A (lets call them A and B) has a socket which is bound to a particular UDP port on the local machine and it polls it frequently to see if anything is received on it.
When I disable Ip-security, the data between the two machines goes through fine and I send and receive the packets fine. But when Ip-Security is enabled, the packet doesn't get to that socket on machine A sent by machine B.
I do a tcpdump
on both the machines and I can see the (encrypted) packet being sent out from machine B and being received on machine A. But after that, the packet goes to the kernel and somewhere either in the decryption of the packet or at some other phase, the packet is dropped.
I want to be able to trace the packet as it goes through the kernel and to see where it is dropped. Is there some /proc
that I can use for this purpose? The other method I can think of is to insert debug statements all over the kernel and recompile it and then try sending the packet again and going through the debug.
Thanks and sorry for the long message but it was necessary.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,正如 Dan 所说,SystemTap 很有用。但我最喜欢的是 ftrace。
供参考:
linux内核中UDP数据包的路径
因此,为了跟踪一般的网络流量,请将以下内容放入 bash shell 中并以 root 身份运行:
等等接收入口路径:
这是:
Netlink 处理:
这就是入口也是:
这是出口(从系统调用“sendmsg()”开始):
希望你喜欢......
Yes, as Dan said, SystemTap is useful. But my favorite is ftrace.
For reference:
Path of UDP packet in linux kernel
So for tracing the network traffic in general, put the following in a bash shell and run it as root:
And so on the receiving ingress path:
and this:
Netlink processing:
and this is the ingress also:
And this is the egress (starting from the syscall "sendmsg()"):
Hope you enjoy....
请参阅名为 SystemTap 的项目。它允许您将用户友好的脚本插入任何内核代码,而无需重新编译内核。例如:
它将为网络层中每个收到的数据包发出内核打印。当然,您需要阅读源代码才能更深入地了解网络堆栈。
SystemTap 非常有能力,并且对可以插入的各种钩子有详细的记录。
Please refer to the project named SystemTap. It allows you to insert user-friendly scripts hooking into any kernel code, without recompiling the kernel. For example:
It will emit a kernel print for every received packet in the network layer. Of course, you would need to read the sources to follow from there deeper into the network stack.
SystemTap is very capable and quite documented about the various hooks that can be inserted.