In kernel based UDP server, we do bind to a address/port. For ebpf as I understand it I can just do filter the port in ebpf program rather than call bind. However some of the existing udp clients are using bind
call which failed because ebpf socket is not bound/listen to any port.
So the question is can ebpf server call bind
on fd returned by the call xsk_socket__fd
(I can't find xsl_socket__bind
) so not too sure how to make udp client bind call not failing.
There might be some confusion here due to naming. An XDP socket is just a construct for setting up the infrastructure to be able to forward packets from XDP to userspace.
however some of the existing udp clients are using
bind
call which failed because ebpf socket is not bound/listen to any port.
Reading from and writing to these sockets happens via ring buffers instead of standard syscalls and typically require a library such as libxdp to handle all of this. You have to write special purpose programs to make use of XDP sockets, you cannot use them in place of a normal UDP/TCP socket.
See https://github.com/xdp-project/bpf-examples/blob/main/AF_XDP-example/xdpsock.c for an example on how to use XDP sockets from userspace.
So the question is can ebpf server call
bind
on fd returned by the callxsk_socket__fd
(I can't findxsl_socket__bind
) so not too sure how to make udp client bind call not failing.
"binding" a socket is telling the kernel network stack to match traffic to a specific address and/or port, so that traffic with that address/port as destination is sent to the right socket.
You cannot bind an XDP socket because the network stack will never send traffic to it as part of the normal socket selection.
It is the XDP program that has to decide to forward a packet to the XDP socket or to let it pass to the kernel.