Skip to content
Merged
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
27 changes: 27 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Docker Image CI

on:
push:
branches: ["main", "ghostbaby"]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build the Docker image
run: make image
12 changes: 12 additions & 0 deletions .gitignore copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.idea
e2e
e2e.tar
bpfnfs
nfstrace_x86_bpfel.go
nfstrace_x86_bpfel.o
nfstrace_arm64_bpfel.go
nfstrace_arm64_bpfel.o

bpfnfs-linux-arm64
bpfnfs-linux-amd64
.vscode
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.associations": {
"bpf_utils.h": "c",
"validate_protocol.h": "c"
}
}
62 changes: 62 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 使用 Ubuntu 24.04 作为基础镜像
FROM --platform=$BUILDPLATFORM ubuntu:24.04 AS builder

# 避免交互式前端
ENV DEBIAN_FRONTEND=noninteractive

# 更新包列表并安装必要的工具
RUN apt-get update && apt-get install -y \
golang-1.22 \
git \
make \
gcc \
clang \
gcc-aarch64-linux-gnu \
llvm \
libcapstone-dev \
&& rm -rf /var/lib/apt/lists/*

# 设置 Go 环境变量
ENV PATH="/usr/lib/go-1.22/bin:${PATH}"
ENV GOPATH="/go"
ENV PATH="${GOPATH}/bin:${PATH}"

# 设置工作目录
WORKDIR /app

# 复制 go mod 和 sum 文件
COPY go.mod go.sum ./

# 设置构建参数
ARG TARGETARCH
ARG TARGETOS

# 下载依赖
RUN go mod download

# 复制源代码
COPY . .

RUN mkdir -p /app/internal/binary/

# 编译应用
RUN make build GOARCH=$TARGETARCH GOOS=$TARGETOS

# 使用 Ubuntu 24.04 作为最终镜像
FROM ubuntu:24.04

# 安装必要的运行时依赖
RUN apt-get update && apt-get install -y \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /root/

# 从 builder 阶段复制编译好的二进制文件
COPY --from=builder /app/cmd/bpfnfs .

# 暴露应用端口(如果需要的话)
# EXPOSE 8080

# 运行应用
CMD ["./cmd/bpfnfs"]
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
GO := go
GO_BUILD = CGO_ENABLED=1 $(GO) build
GO_GENERATE = $(GO) generate
GO_TAGS ?=
TARGET_GOARCH ?= amd64,arm64
GOARCH ?= amd64
GOOS ?= linux
VERSION=$(shell git describe --tags --always)
FILTER_STRUCT ?= kiocb
# For compiling libpcap and CGO
CC ?= gcc


build: elf
cd ./cmd;CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -gcflags "all=-N -l" -o bpfnfs

dlv: build
# dlv --headless --listen=:2345 --api-version=2 exec ./cmd/bpfnfs -- --filter-struct=$(FILTER_STRUCT) --filter-func="^nfs.*" --all-kmods=true
dlv --headless --listen=:2345 --api-version=2 exec ./cmd/bpfnfs -- --config-path=./cmd/config.yaml

run: build
#./cmd/bpfnfs --filter-struct=$(FILTER_STRUCT) --filter-func="^(vfs_|nfs_).*" --all-kmods=true --enable-nfs-metrics=true --enable-dns=true --enable-bpfnfsr=true
./cmd/bpfnfs --config-path=./cmd/config.yaml
skip: build
./cmd/bpfnfs --filter-struct=$(FILTER_STRUCT) --skip-attach=true --all-kmods=true --filter-func="^nfs.*"

funcs: build
./cmd/bpfnfs --filter-struct=kiocb --all-kmods=true --filter-func="^(vfs_|nfs_).*" --add-funcs="nfs_file_direct_read:1,nfs_file_direct_write:1,nfs_swap_rw:1,nfs_file_read:1,nfs_file_write:1"

elf:
TARGET_GOARCH=$(TARGET_GOARCH) FILTER_STRUCT=$(FILTER_STRUCT) $(GO_GENERATE)
CC=$(CC) GOARCH=$(TARGET_GOARCH) $(GO_BUILD) $(if $(GO_TAGS),-tags $(GO_TAGS)) \
-ldflags "-w -s "

image:
docker buildx create --use
docker buildx build --platform linux/amd64 -t ghostbaby/bpfnfs:v0.0.1-amd64 --push .
docker buildx build --platform linux/arm64 -t ghostbaby/bpfnfs:v0.0.1-arm64 --push .
23 changes: 23 additions & 0 deletions bpf/LICENSE.BSD-2-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright Authors of Cilium. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Loading
Loading