Skip to content

Commit 35149b2

Browse files
cristian-dumitrescuborkmann
authored andcommitted
samples/bpf: Add new sample xsk_fwd.c
This sample code illustrates the packet forwarding between multiple AF_XDP sockets in multi-threading environment. All the threads and sockets are sharing a common buffer pool, with each socket having its own private buffer cache. The sockets are created with the xsk_socket__create_shared() function, which allows multiple AF_XDP sockets to share the same UMEM object. Example 1: Single thread handling two sockets. Packets received from socket A (on top of interface IFA, queue QA) are forwarded to socket B (on top of interface IFB, queue QB) and vice-versa. The thread is affinitized to CPU core C: ./xsk_fwd -i IFA -q QA -i IFB -q QB -c C Example 2: Two threads, each handling two sockets. Packets from socket A are sent to socket B (by thread X), packets from socket B are sent to socket A (by thread X); packets from socket C are sent to socket D (by thread Y), packets from socket D are sent to socket C (by thread Y). The two threads are bound to CPU cores CX and CY: ./xdp_fwd -i IFA -q QA -i IFB -q QB -i IFC -q QC -i IFD -q QD -c CX -c CY Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Björn Töpel <bjorn.topel@intel.com> Link: https://lore.kernel.org/bpf/1598603189-32145-15-git-send-email-magnus.karlsson@intel.com
1 parent 2f6324a commit 35149b2

2 files changed

Lines changed: 1088 additions & 0 deletions

File tree

‎samples/bpf/Makefile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ tprogs-y += syscall_tp
4848
tprogs-y += cpustat
4949
tprogs-y += xdp_adjust_tail
5050
tprogs-y += xdpsock
51+
tprogs-y += xsk_fwd
5152
tprogs-y += xdp_fwd
5253
tprogs-y += task_fd_query
5354
tprogs-y += xdp_sample_pkts
@@ -104,6 +105,7 @@ syscall_tp-objs := syscall_tp_user.o
104105
cpustat-objs := cpustat_user.o
105106
xdp_adjust_tail-objs := xdp_adjust_tail_user.o
106107
xdpsock-objs := xdpsock_user.o
108+
xsk_fwd-objs := xsk_fwd.o
107109
xdp_fwd-objs := xdp_fwd_user.o
108110
task_fd_query-objs := bpf_load.o task_fd_query_user.o $(TRACE_HELPERS)
109111
xdp_sample_pkts-objs := xdp_sample_pkts_user.o $(TRACE_HELPERS)
@@ -203,6 +205,7 @@ TPROGLDLIBS_trace_output += -lrt
203205
TPROGLDLIBS_map_perf_test += -lrt
204206
TPROGLDLIBS_test_overhead += -lrt
205207
TPROGLDLIBS_xdpsock += -pthread
208+
TPROGLDLIBS_xsk_fwd += -pthread
206209

207210
# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
208211
# make M=samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang

0 commit comments

Comments
 (0)