mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-23 01:10:04 +00:00
![John Fastabend](/assets/img/avatar_default.png)
This program binds a program to a cgroup and then matches hard coded IP addresses and adds these to a sockmap. This will receive messages from the backend and send them to the client. client:X <---> frontend:10000 client:X <---> backend:10001 To keep things simple this is only designed for 1:1 connections using hard coded values. A more complete example would allow many backends and clients. To run, # sockmap <cgroup2_dir> Signed-off-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
78 lines
2.3 KiB
Makefile
78 lines
2.3 KiB
Makefile
# kbuild trick to avoid linker error. Can be omitted if a module is built.
|
|
obj- := dummy.o
|
|
|
|
# List of programs to build
|
|
hostprogs-y := sockmap
|
|
|
|
# Libbpf dependencies
|
|
LIBBPF := ../../tools/lib/bpf/bpf.o
|
|
|
|
HOSTCFLAGS += -I$(objtree)/usr/include
|
|
HOSTCFLAGS += -I$(srctree)/tools/lib/
|
|
HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
|
|
HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
|
|
HOSTCFLAGS += -I$(srctree)/tools/perf
|
|
|
|
sockmap-objs := ../bpf/bpf_load.o $(LIBBPF) sockmap_user.o
|
|
|
|
# Tell kbuild to always build the programs
|
|
always := $(hostprogs-y)
|
|
always += sockmap_kern.o
|
|
|
|
HOSTLOADLIBES_sockmap += -lelf -lpthread
|
|
|
|
# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
|
|
# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
|
|
LLC ?= llc
|
|
CLANG ?= clang
|
|
|
|
# Trick to allow make to be run from this directory
|
|
all:
|
|
$(MAKE) -C ../../ $(CURDIR)/
|
|
|
|
clean:
|
|
$(MAKE) -C ../../ M=$(CURDIR) clean
|
|
@rm -f *~
|
|
|
|
$(obj)/syscall_nrs.s: $(src)/syscall_nrs.c
|
|
$(call if_changed_dep,cc_s_c)
|
|
|
|
$(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE
|
|
$(call filechk,offsets,__SYSCALL_NRS_H__)
|
|
|
|
clean-files += syscall_nrs.h
|
|
|
|
FORCE:
|
|
|
|
|
|
# Verify LLVM compiler tools are available and bpf target is supported by llc
|
|
.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
|
|
|
|
verify_cmds: $(CLANG) $(LLC)
|
|
@for TOOL in $^ ; do \
|
|
if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
|
|
echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
|
|
exit 1; \
|
|
else true; fi; \
|
|
done
|
|
|
|
verify_target_bpf: verify_cmds
|
|
@if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
|
|
echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
|
|
echo " NOTICE: LLVM version >= 3.7.1 required" ;\
|
|
exit 2; \
|
|
else true; fi
|
|
|
|
$(src)/*.c: verify_target_bpf
|
|
|
|
# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
|
|
# But, there is no easy way to fix it, so just exclude it since it is
|
|
# useless for BPF samples.
|
|
$(obj)/%.o: $(src)/%.c
|
|
$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
|
|
-D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
|
|
-Wno-compare-distinct-pointer-types \
|
|
-Wno-gnu-variable-sized-type-not-at-end \
|
|
-Wno-address-of-packed-member -Wno-tautological-compare \
|
|
-Wno-unknown-warning-option \
|
|
-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@
|