【问题标题】:How to drop skb_buff use ebpf/bcc?如何删除 skb_buff 使用 ebpf/bcc?
【发布时间】:2020-04-24 13:42:31
【问题描述】:

我正在运行密件抄送示例/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 吗?

【问题讨论】:

  • 您的问题中的某些内容我不清楚。 1)数据包是否被丢弃(你说 UDP/ICMP 数据包被丢弃)或没有(你添加你希望 ping/dig 失败但它毕竟工作,所以大概数据包没有被丢弃?) 2)你的意思是“是无论如何还有其他方法可以删除 skb_buff 使用 ebpf/bcc”,请您改写一下吗?

标签: python linux-kernel bpf ebpf bcc-bpf


【解决方案1】:

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


http-parse-simple 的目标是向用户显示在给定接口上发出的所有 HTTP 请求的 URL。为此,它creates a raw socket and attaches a BPF program to it。原始套接字接收接口上所有传入数据包的副本;这与 BPF 无关。然后使用附加的 BPF 程序仅向用户空间传输感兴趣的数据包(即,仅 HTTP 数据包);其他数据包的副本被丢弃。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-20
    • 2012-09-01
    • 1970-01-01
    • 2014-01-01
    • 2022-11-13
    • 2020-01-02
    • 1970-01-01
    相关资源
    最近更新 更多