Skip to content

Commit ecc0cac

Browse files
committed
chore(ebpf): update bpf header files
This patch updates the bpf header files, as well as introduce Make commands to help updating these files in the future. Also update the Dockerfile for building the agent and generating Go codes. Signed-off-by: Quang Nguyen <[email protected]>
1 parent cbfce9b commit ecc0cac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+200674
-204549
lines changed

.github/workflows/golangci-lint.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
IS_NOT_MERGE_GROUP: ${{ github.event_name != 'merge_group' }}
2020
GOOS: ${{ matrix.goos }}
2121
GOARCH: ${{ matrix.goarch }}
22+
CGO_ENABLED: 0
2223
steps:
2324
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2425
if: env.IS_NOT_MERGE_GROUP

Makefile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,3 +601,68 @@ update-hubble:
601601
echo " git push origin deps/update-hubble-to-$$latest_version"; \
602602
echo "Then create a pull request on GitHub."; \
603603
fi
604+
605+
.PHONY: update-libbpf
606+
update-libbpf: ## Update libbpf headers and sources from upstream
607+
@echo "Updating libbpf from upstream..."
608+
@TMPDIR=$$(mktemp -d); \
609+
echo "Cloning libbpf repository to $$TMPDIR..."; \
610+
git clone --depth 1 https://github.com/libbpf/libbpf.git $$TMPDIR; \
611+
echo "Copying libbpf source files..."; \
612+
rm -rf $(REPO_ROOT)/pkg/plugin/lib/common/libbpf/_src/*; \
613+
cp $$TMPDIR/src/*.c $(REPO_ROOT)/pkg/plugin/lib/common/libbpf/_src/ 2>/dev/null || true; \
614+
cp $$TMPDIR/src/*.h $(REPO_ROOT)/pkg/plugin/lib/common/libbpf/_src/ 2>/dev/null || true; \
615+
echo "Copying libbpf include files..."; \
616+
rm -rf $(REPO_ROOT)/pkg/plugin/lib/common/libbpf/_include/linux/*; \
617+
rm -rf $(REPO_ROOT)/pkg/plugin/lib/common/libbpf/_include/uapi/*; \
618+
rm -rf $(REPO_ROOT)/pkg/plugin/lib/common/libbpf/_include/asm/*; \
619+
cp -r $$TMPDIR/include/linux/* $(REPO_ROOT)/pkg/plugin/lib/common/libbpf/_include/linux/ 2>/dev/null || true; \
620+
cp -r $$TMPDIR/include/uapi/* $(REPO_ROOT)/pkg/plugin/lib/common/libbpf/_include/uapi/ 2>/dev/null || true; \
621+
cp -r $$TMPDIR/include/asm/* $(REPO_ROOT)/pkg/plugin/lib/common/libbpf/_include/asm/ 2>/dev/null || true; \
622+
echo "Adding placeholder.go files..."; \
623+
find $(REPO_ROOT)/pkg/plugin/lib/common/libbpf/_src -type d -exec sh -c 'echo "package placeholder" > {}/placeholder.go' \;; \
624+
find $(REPO_ROOT)/pkg/plugin/lib/common/libbpf/_include -type d -exec sh -c 'echo "package placeholder" > {}/placeholder.go' \;; \
625+
echo "Cleaning up temporary directory..."; \
626+
rm -rf $$TMPDIR; \
627+
echo ""; \
628+
echo "libbpf files updated successfully!"; \
629+
echo "Note: vmlinux.h files are architecture-specific and should be generated separately."; \
630+
echo "To regenerate vmlinux.h, run: make update-vmlinux"
631+
632+
.PHONY: update-vmlinux
633+
update-vmlinux: ## Update vmlinux.h for all architectures from libbpf/vmlinux.h repo
634+
@echo "Updating vmlinux.h files from https://github.com/libbpf/vmlinux.h..."
635+
@TMPDIR=$$(mktemp -d); \
636+
echo "Cloning vmlinux.h repository to $$TMPDIR..."; \
637+
git clone --depth 1 https://github.com/libbpf/vmlinux.h.git $$TMPDIR; \
638+
echo ""; \
639+
echo "Available vmlinux.h files in repository:"; \
640+
find $$TMPDIR -name "*.h" -type f | head -10; \
641+
echo "..."; \
642+
echo ""; \
643+
echo "Updating x86_64 (amd64) vmlinux.h..."; \
644+
X86_FILE=$$(find $$TMPDIR -path "*/x86/vmlinux*.h" -o -name "vmlinux_x86*.h" | head -1); \
645+
if [ -n "$$X86_FILE" ]; then \
646+
cp "$$X86_FILE" $(REPO_ROOT)/pkg/plugin/lib/_amd64/vmlinux.h; \
647+
echo " ✓ Updated _amd64/vmlinux.h from $$(basename $$X86_FILE)"; \
648+
else \
649+
echo " ✗ Warning: x86_64 vmlinux.h not found"; \
650+
fi; \
651+
echo ""; \
652+
echo "Updating aarch64 (arm64) vmlinux.h..."; \
653+
ARM_FILE=$$(find $$TMPDIR -path "*/arm*/vmlinux*.h" -o -name "vmlinux_arm*.h" | head -1); \
654+
if [ -n "$$ARM_FILE" ]; then \
655+
cp "$$ARM_FILE" $(REPO_ROOT)/pkg/plugin/lib/_arm64/vmlinux.h; \
656+
echo " ✓ Updated _arm64/vmlinux.h from $$(basename $$ARM_FILE)"; \
657+
else \
658+
echo " ✗ Warning: arm64 vmlinux.h not found"; \
659+
fi; \
660+
echo ""; \
661+
echo "Cleaning up temporary directory..."; \
662+
rm -rf $$TMPDIR; \
663+
echo ""; \
664+
echo "✓ vmlinux.h files updated successfully!"; \
665+
echo ""; \
666+
echo "Summary:"; \
667+
echo " - AMD64: $$(wc -l < $(REPO_ROOT)/pkg/plugin/lib/_amd64/vmlinux.h) lines"; \
668+
echo " - ARM64: $$(wc -l < $(REPO_ROOT)/pkg/plugin/lib/_arm64/vmlinux.h) lines"

controller/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ ARG GOOS=linux # default to linux
5252
ARG VERSION
5353
ENV GOARCH=${GOARCH}
5454
ENV GOOS=${GOOS}
55+
ENV CGO_ENABLED=0
5556
RUN --mount=type=cache,target="/root/.cache/go-build" go build -v -o /go/bin/retina/captureworkload -ldflags "-X github.com/microsoft/retina/internal/buildinfo.Version="$VERSION" -X github.com/microsoft/retina/internal/buildinfo.ApplicationInsightsID="$APP_INSIGHTS_ID"" captureworkload/main.go
5657

5758

@@ -63,6 +64,7 @@ ARG GOOS=linux # default to linux
6364
ARG VERSION
6465
ENV GOARCH=${GOARCH}
6566
ENV GOOS=${GOOS}
67+
ENV CGO_ENABLED=0
6668
RUN --mount=type=cache,target="/root/.cache/go-build" go build -x -v -o /go/bin/retina/controller -ldflags "-X github.com/microsoft/retina/internal/buildinfo.Version="$VERSION" -X github.com/microsoft/retina/internal/buildinfo.ApplicationInsightsID="$APP_INSIGHTS_ID"" controller/main.go
6769

6870

@@ -74,6 +76,7 @@ ARG GOOS=linux # default to linux
7476
ARG VERSION
7577
ENV GOARCH=${GOARCH}
7678
ENV GOOS=${GOOS}
79+
ENV CGO_ENABLED=0
7780
RUN --mount=type=cache,target="/root/.cache/go-build" go build -v -o /go/bin/retina/initretina -ldflags "-X github.com/microsoft/retina/internal/buildinfo.Version="$VERSION" -X github.com/microsoft/retina/internal/buildinfo.ApplicationInsightsID="$APP_INSIGHTS_ID"" init/retina/main_linux.go
7881

7982

controller/Dockerfile.gogen

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,8 @@ ENV GOOS=${GOOS}
88
ARG GOARCH=amd64
99
ENV GOARCH=${GOARCH}
1010

11-
RUN apt-get update &&\
12-
apt-get -y install lsb-release wget software-properties-common gnupg file git make
13-
1411
# Install clang and llvm.
15-
RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
16-
RUN add-apt-repository "deb http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-14 main"
17-
RUN apt-get update
18-
19-
RUN apt-get install -y clang-14 lldb-14 lld-14 clangd-14 man-db
20-
RUN apt-get install -y bpftool libbpf-dev
21-
22-
RUN ln -s /usr/bin/clang-14 /usr/bin/clang
12+
RUN tdnf install -y clang lld bpftool libbpf-devel gnupg file git make lsb-release wget
2313

2414
WORKDIR /app
2515

pkg/hubble/common/decoder_linux.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"github.com/cilium/cilium/pkg/labels"
1212
)
1313

14-
//go:generate go run github.com/golang/mock/[email protected] -source decoder.go -destination=mocks/mock_types.go -package=mocks
15-
1614
type EpDecoder interface {
1715
Decode(ip netip.Addr) *flow.Endpoint
1816
IsEndpointOnLocalHost(ip string) bool

pkg/plugin/dropreason/_cprog/drop_reason.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ static void get_packet_from_skb(struct packet *p, struct sk_buff *skb)
228228
#endif
229229
}
230230

231+
#ifdef ADVANCED_METRICS
232+
#if ADVANCED_METRICS == 1
231233
static void get_packet_from_sock(struct packet *p, struct sock *sk)
232234
{
233235
// extract 5 tuple from pid
@@ -256,6 +258,8 @@ static void get_packet_from_sock(struct packet *p, struct sock *sk)
256258
p->dst_port = bpf_ntohs(dport);
257259
p->src_port = bpf_ntohs(sport);
258260
}
261+
#endif
262+
#endif
259263

260264
/*
261265
This function will be saving the PID and length of skb it is working on.
@@ -312,8 +316,7 @@ int BPF_KRETPROBE(nf_hook_slow_ret, int retVal)
312316
}
313317

314318
SEC("fexit/nf_hook_slow")
315-
int BPF_PROG(nf_hook_slow_fexit, struct sk_buff *skb, struct nf_hook_state *state,
316-
const struct nf_hook_entries *e, unsigned int s, int retVal)
319+
int BPF_PROG(nf_hook_slow_fexit, struct sk_buff *skb, struct nf_hook_state *state, int retVal)
317320
{
318321
if (retVal < 0) {
319322
__u32 skb_len = 0;

pkg/plugin/dropreason/mocks/mock_types_linux.go

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/plugin/dropreason/types_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type (
9090
// Interface to https://pkg.go.dev/github.com/cilium/ebpf#Map.
9191
// Added for unit tests.
9292
//
93-
//go:generate go run go.uber.org/mock/[email protected] -source=types_linux.go -destination=mocks/mock_types.go -package=dropreason . IMap IMapIterator IPerfReader
93+
//go:generate go run go.uber.org/mock/[email protected] -source=types_linux.go -destination=mocks/mock_types_linux.go -package=dropreason . IMap IMapIterator IPerfReader
9494
type IMapIterator interface {
9595
Next(keyOut interface{}, valueOut interface{}) bool
9696
Err() error

0 commit comments

Comments
 (0)