BPF:UDP套接字的sock_ops等效功能

huangapple go评论77阅读模式
英文:

BPF: sock_ops equivalent for UDP sockets

问题

BPF_PROG_TYPE_SOCK_OPS是一种BPF程序类型,当对TCP套接字执行一组操作时会调用它。

目前,我正在使用它来标记试图与fwmark建立连接的TCP套接字。

我想对UDP套接字执行相同的操作,但不幸的是,BPF_PROG_TYPE_SOCK_OPS探针在UDP数据包上不会被调用。

是否有等效的方法?

英文:

BPF_PROG_TYPE_SOCK_OPS is a BPF program type which is called when a set of actions is performed on a TCP socket.

Right now, I am using it to mark TCP sockets that are trying to connect with an fwmark.

I want to do the same for UDP sockets, but unfortunately the BPF_PROG_TYPE_SOCK_OPS probe is not called on UDP packets.

Is there an equivalent?

答案1

得分: 0

UDP套接字实际上不会真正连接,因此触发类似事件。最接近的方法将是在套接字创建时使用BPF_PROG_TYPE_CGROUP_SOCK程序触发。

您还可以在这里找到所有BPF套接字的列表。由于您想设置套接字选项,您还可以查看bpf助手的手册页。对于bpf_setsockopt,您将找到此助手可用的附加点列表。但请注意,对于某些BPF探针,您还可以直接编辑套接字标记(例如BPF_CGROUP_INET_SOCK_CREATE),而无需调用助手函数。

英文:

UDP sockets don't really connect, so similar event to trigger on. Closest thing would be to trigger on socket creation with the use of a BPF_PROG_TYPE_CGROUP_SOCK program.

You can also find a list of all BPF sockets here. Since you want to set a socket option, you can also look at the man page of the bpf helpers. For bpf_setsockopt, you will find a list of attach points for which this helper will be available. Note though that for some BPF probes, you can also edit the socket mark directly (e.g. BPF_CGROUP_INET_SOCK_CREATE) without calling the helper function.

huangapple
  • 本文由 发表于 2023年7月20日 17:58:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76728722.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定