0

我正在运行 bcc 示例/http_filter/http-parse-simple.c,其中有一条评论说明:

/*
  eBPF program.
  Filter IP and TCP packets, having payload not empty
  and containing "HTTP", "GET", "POST" ... as first bytes of payload
  if the program is loaded as PROG_TYPE_SOCKET_FILTER
  and attached to a socket
  return  0 -> DROP the packet
  return -1 -> KEEP the packet and return it to user space (userspace
      can read it from the socket_fd )
*/

当我运行这个例子时,我看到当我运行一个 UDP 数据包(例如 dig)或 icmp 数据包(ping)时,用户程序员确实没有收到数据包。

但是 ping 或 dig 程序不会丢失。

据我了解,这些非 TCP 数据包应该被丢弃(我希望 ping 或 dig 会失败),但事实并非如此。

那么是什么原因呢?

还有其他方法可以放弃 skb_buff 使用 ebpf/bcc 吗?

4

1 回答 1

2

TL;博士。http-parse-simple 丢弃数据包的副本,而不是原始数据包。


http-parse-simple 的目标是向用户显示在给定接口上发出的所有 HTTP 请求的 URL。为此,它创建了一个原始套接字并将一个 BPF 程序附加到它上面。原始套接字接收接口上所有传入数据包的副本;这与 BPF 无关。然后使用附加的 BPF 程序向用户空间传输感兴趣的数据包(即只有 HTTP 数据包);其他数据包的副本被丢弃。

因此,http-parse-simple 的用户空间进程只接收 HTTP 数据包,并且这样做不会影响您的原始应用程序(例如,Web 浏览器),因为 BPF 程序在数据包副本上工作。

于 2020-01-07T09:37:21.923 回答