Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BPF] Makefile rework #9490

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 88 additions & 41 deletions felix/bpf-gpl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ all: $(OBJS)
ut-objs: $(UT_OBJS)

libbpf: $(LIBBPF_FILE_CREATED)
$(LIBBPF_FILE_CREATED):
$(LIBBPF_FILE_CREATED):
ifeq ("$(wildcard ./$(LIBBPF_DIR))", "")
$(info "Directory does not exist.")
@echo "Directory does not exist."
Expand All @@ -83,18 +83,6 @@ endif

COMPILE=$(CC) $(CFLAGS) `./calculate-flags $@` -c $< -o $@

conntrack_cleanup_%v4.ll: conntrack_cleanup.c conntrack_cleanup.d calculate-flags
$(COMPILE)
conntrack_cleanup_%v6.ll: conntrack_cleanup.c conntrack_cleanup.d calculate-flags
$(COMPILE)

connect_time_%v4.ll: connect_balancer.c connect_balancer.d calculate-flags
$(COMPILE)
connect_time_%v46.ll: connect_balancer_v46.c connect_balancer_v46.d calculate-flags
$(COMPILE)
connect_time_%v6.ll: connect_balancer_v6.c connect_balancer_v6.d calculate-flags
$(COMPILE) -DIPVER6

UT_CFLAGS=\
-D__BPFTOOL_LOADER__ \
-DCALI_LOG_LEVEL=CALI_LOG_LEVEL_DEBUG \
Expand All @@ -119,27 +107,33 @@ policy_default.ll: policy_default.c policy_default.d

# Production and UT versions of the main binaries.
# Combining the targets into one rule causes make to fail to rebuild the .ll files. Not sure why.
to%_v6.ll: tc.c tc_v6.d calculate-flags
$(COMPILE)
to%.ll: tc.c tc.d calculate-flags
$(COMPILE)
from%.ll: tc.c tc.d calculate-flags
$(COMPILE)
to%_v6.ll: tc.c tc.d calculate-flags
$(COMPILE)
from%_v6.ll: tc.c tc.d calculate-flags
from%_v6.ll: tc.c tc_v6.d calculate-flags
$(COMPILE)
test%.ll: tc.c tc.d calculate-flags
$(COMPILE)
test%_v6.ll: tc.c tc.d calculate-flags
test%_v6.ll: tc.c tc_v6.d calculate-flags
$(COMPILE)
xdp%.ll: xdp.c xdp.d calculate-flags
$(COMPILE)
xdp%_v6.ll: xdp.c xdp.d calculate-flags
xdp%_v6.ll: xdp.c xdp_v6.d calculate-flags
$(COMPILE)
test_xdp%.ll: xdp.c xdp.d calculate-flags
$(COMPILE)
test_xdp%_v6.ll: xdp.c xdp.d calculate-flags
test_xdp%_v6.ll: xdp.c xdp_v6.d calculate-flags
$(COMPILE)

tc_v6.d: tc.c
$(COMPILE_DEPS)
xdp_v6.d: xdp.c
$(COMPILE_DEPS)


LINK=$(LD) -march=bpf -filetype=obj -o $@ $<
bin/tc_preamble.o: tc_preamble.ll | bin
$(LINK)
Expand All @@ -155,45 +149,98 @@ bin/test%.o: test%.ll | bin
$(LINK)
bin/xdp%.o: xdp%.ll | bin
$(LINK)
bin/conntrack_cleanup_%v4.o: conntrack_cleanup_%v4.ll | bin
$(LINK)
bin/conntrack_cleanup_%v6.o: conntrack_cleanup_%v6.ll | bin
$(LINK)
bin/connect_time_%v4.o: connect_time_%v4.ll | bin
$(LINK)
bin/connect_time_%v46.o: connect_time_%v46.ll | bin
$(LINK)
bin/connect_time_%v6.o: connect_time_%v6.ll | bin
$(LINK)
bin/connect_time_%v4_co-re.o: connect_time_%v4.ll | bin
$(LINK)
bin/connect_time_%v46_co-re.o: connect_time_%v46.ll | bin
$(LINK)
bin/connect_time_%v6_co-re.o: connect_time_%v6.ll | bin
$(LINK)

ut/%.o: ut/%.ll
$(LINK)
ut/ip_parse_test_v6.ll: ut/ip_parse_test.c
$(CC) $(UT_CFLAGS) $(CFLAGS) -DIPVER6 -c $< -o $@
ut/ip_parse_test_v6.o: ut/ip_parse_test_v6.ll
$(LINK)

%_v4.ll: %.c %.d calculate-flags
$(COMPILE)
%_no_log_v4.ll: %.c %.d calculate-flags
$(COMPILE)
%_debug_v4.ll: %.c %.d calculate-flags
$(COMPILE)
%_no_log_co-re_v4.ll: %.c %.d calculate-flags
$(COMPILE)
%_debug_co-re_v4.ll: %.c %.d calculate-flags
$(COMPILE)

%_v4.ll: %_v4.c %_v4.d calculate-flags
$(COMPILE)
%_no_log_v4.ll: %_v4.c %_v4.d calculate-flags
$(COMPILE)
%_debug_v4.ll: %_v4.c %_v4.d calculate-flags
$(COMPILE)
%_no_log_co-re_v4.ll: %_v4.c %_v4.d calculate-flags
$(COMPILE)
%_debug_co-re_v4.ll: %_v4.c %_v4.d calculate-flags
$(COMPILE)

%_v46.ll: %_v46.c %_v46.d calculate-flags
$(COMPILE)
%_no_log_v46.ll: %_v46.c %_v46.d calculate-flags
$(COMPILE)
%_debug_v46.ll: %_v46.c %_v46.d calculate-flags
$(COMPILE)
%_no_log_co-re_v46.ll: %_v46.c %_v46.d calculate-flags
$(COMPILE)
%_debug_co-re_v46.ll: %_v46.c %_v46.d calculate-flags
$(COMPILE)

%_v6.ll: %_v6.c %_v6.d calculate-flags
$(COMPILE)
%_no_log_v6.ll: %_v6.c %_v6.d calculate-flags
$(COMPILE)
%_debug_v6.ll: %_v6.c %_v6.d calculate-flags
$(COMPILE)
%_no_log_co-re_v6.ll: %_v6.c %_v6.d calculate-flags
$(COMPILE)
%_debug_co-re_v6.ll: %_v6.c %_v6.d calculate-flags
$(COMPILE)

%_v6.ll: %.c %_v6.d calculate-flags
$(COMPILE)
%_no_log_v6.ll: %.c %_v6.d calculate-flags
$(COMPILE)
%_debug_v6.ll: %.c %_v6.d calculate-flags
$(COMPILE)
%_no_log_co-re_v6.ll: %.c %_v6.d calculate-flags
$(COMPILE)
%_debug_co-re_v6.ll: %.c %_v6.d calculate-flags
$(COMPILE)

bin/%_v4.o: %_v4.ll | bin
$(LINK)
bin/%_v46.o: %_v46.ll | bin
$(LINK)
bin/%_v6.o: %_v6.ll | bin
$(LINK)

bin:
mkdir -p bin

.PRECIOUS: %.d

%.d: %.c
set -e; rm -f $@; \
$(COMPILE_DEPS)
%_v6.d: CFLAGS+=-DIPVER6
%_v6.d: %_v6.c
$(COMPILE_DEPS)
%_v6.d: %.c
$(COMPILE_DEPS)


.PRECIOUS: %.d %_v6.d

COMPILE_DEPS=set -e; rm -f $@; \
$(CC) -M $(CFLAGS) $< > $@.$$$$ || { rm -f $@.$$$$; false; } ; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$

D_FILES=$(C_FILES:.c=.d)

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS), libbpf)
include $(D_FILES)
include $(shell ls *.d)
endif
endif

Expand Down
12 changes: 6 additions & 6 deletions felix/bpf-gpl/list-objs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ emit_filename() {
for log_level in debug no_log; do
echo "bin/conntrack_cleanup_${log_level}_co-re_v4.o"
echo "bin/conntrack_cleanup_${log_level}_co-re_v6.o"
echo "bin/connect_time_${log_level}_v4.o"
echo "bin/connect_time_${log_level}_v6.o"
echo "bin/connect_time_${log_level}_v46.o"
echo "bin/connect_time_${log_level}_v4_co-re.o"
echo "bin/connect_time_${log_level}_v46_co-re.o"
echo "bin/connect_time_${log_level}_v6_co-re.o"
echo "bin/connect_balancer_${log_level}_v4.o"
echo "bin/connect_balancer_${log_level}_v6.o"
echo "bin/connect_balancer_${log_level}_v46.o"
echo "bin/connect_balancer_${log_level}_co-re_v4.o"
echo "bin/connect_balancer_${log_level}_co-re_v46.o"
echo "bin/connect_balancer_${log_level}_co-re_v6.o"
echo "bin/xdp_${log_level}.o"
echo "bin/xdp_${log_level}_co-re_v6.o"

Expand Down
2 changes: 1 addition & 1 deletion felix/bpf/nat/connecttime.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func ProgFileName(logLevel string, ipver string) string {
btf = "_co-re"
}

return fmt.Sprintf("connect_time_%s_v%s%s.o", logLevel, ipver, btf)
return fmt.Sprintf("connect_balancer_%s_v%s%s.o", logLevel, ipver, btf)
}

func ensureCgroupPath(cgroupv2 string) (string, error) {
Expand Down