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

fix: caddy cannot accept connections #262

Merged
merged 3 commits into from
Aug 5, 2023
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
1 change: 0 additions & 1 deletion .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ jobs:
mkdir -p ./build/
export CGO_ENABLED=0
export GOFLAGS="-trimpath -modcacherw"
export CFLAGS="-D__REMOVE_BPF_PRINTK"
export OUTPUT=build/dae-$ASSET_NAME
export VERSION=${{ steps.get_version.outputs.VERSION }}
export CLANG=clang-15
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ jobs:
mkdir -p ./build/
export CGO_ENABLED=0
export GOFLAGS="-trimpath -modcacherw"
export CFLAGS="-D__REMOVE_BPF_PRINTK"
export OUTPUT=build/dae-$ASSET_NAME
export VERSION=${{ steps.get_version.outputs.VERSION }}
export CLANG=clang-15
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/seed-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ jobs:
mkdir -p ./build/
export CGO_ENABLED=0
export GOFLAGS="-trimpath -modcacherw"
export CFLAGS="-D__REMOVE_BPF_PRINTK"
export OUTPUT=build/dae-$ASSET_NAME
export VERSION=${{ steps.get_version.outputs.VERSION }}
export CLANG=clang-15
Expand Down
2 changes: 1 addition & 1 deletion control/bpf_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ retryLoadBpf:
if strings.Contains(err.Error(), "no BTF found for kernel version") {
err = fmt.Errorf("%w: you should re-compile linux kernel with BTF configurations; see docs for more information", err)
} else if strings.Contains(err.Error(), "unknown func bpf_trace_printk") {
err = fmt.Errorf(`%w: please try to compile dae without bpf_printk; example of cross-compilation to arm64: make GOARCH=arm64 CGO_ENABLED=0 CFLAGS="-D__REMOVE_BPF_PRINTK"`, err)
err = fmt.Errorf(`%w: please try to compile dae without bpf_printk"`, err)
} else if strings.Contains(err.Error(), "unknown func bpf_probe_read") {
err = fmt.Errorf(`%w: please re-compile linux kernel with CONFIG_BPF_EVENTS=y and CONFIG_KPROBE_EVENTS=y"`, err)
}
Expand Down
11 changes: 6 additions & 5 deletions control/kern/tproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
// #define __DEBUG_ROUTING
// #define __PRINT_ROUTING_RESULT
// #define __PRINT_SETUP_PROCESS_CONNNECTION
// #define __REMOVE_BPF_PRINTK
// #define __DEBUG
// #define __UNROLL_ROUTE_LOOP

#ifndef __DEBUG
#undef bpf_printk
#define bpf_printk(...) (void)0
#endif
// #define likely(x) x
// #define unlikely(x) x
#define likely(x) __builtin_expect((x), 1)
Expand Down Expand Up @@ -1362,10 +1366,6 @@ int tproxy_lan_ingress(struct __sk_buff *skb) {

sk = bpf_skc_lookup_tcp(skb, &tuple, tuple_size, BPF_F_CURRENT_NETNS, 0);
if (sk) {
if (tuples.dport == bpf_ntohs(445)) {
// samba. It is safe because the smb port cannot be customized.
goto sk_accept;
}
if (sk->state != BPF_TCP_LISTEN) {
is_old_conn = true;
goto assign;
Expand Down Expand Up @@ -1487,6 +1487,7 @@ int tproxy_lan_ingress(struct __sk_buff *skb) {
bpf_printk("bpf_sk_assign: %d, perhaps you have other TPROXY programs "
"(such as v2ray) running?",
ret);
return TC_ACT_OK;
} else {
bpf_printk("bpf_sk_assign: %d", ret);
}
Expand Down
12 changes: 1 addition & 11 deletions docs/en/troubleshooting.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
# Troubleshooting

## Unknown bpf_trace_printk

```console
invalid argument: unknown func bpf_trace_printk
```

Solution:

Compile dae with CFLAG `-D__REMOVE_BPF_PRINTK`. See [build-by-yourself](user-guide/build-by-yourself.md).

## No network after `dae suspend`

Do not set dae as the DNS in DHCP setting. For example, you can set `223.5.5.5` as DNS in your DHCP setting.
Expand Down Expand Up @@ -77,4 +67,4 @@ If you use `clang-13` to compile dae, you may encounter this problem.
There are ways to resolve it:

1. Method 1: Use `clang-15` or higher versions to compile dae. Or just download dae from [releases](https://github.com/daeuniverse/dae/releases).
2. Method 2: Add CFLAGS `-D__UNROLL_ROUTE_LOOP` while compiling. However, it will increse memory occupation (or swap space) at the eBPF loading stage (about 180MB). For example, compile dae to ARM64 using `make CGO_ENABLED=0 GOARCH=arm64 CFLAGS="-D__UNROLL_ROUTE_LOOP -D__REMOVE_BPF_PRINTK"`.
2. Method 2: Add CFLAGS `-D__UNROLL_ROUTE_LOOP` while compiling. However, it will increse memory occupation (or swap space) at the eBPF loading stage (about 180MB). For example, compile dae to ARM64 using `make CGO_ENABLED=0 GOARCH=arm64 CFLAGS="-D__UNROLL_ROUTE_LOOP"`.
1 change: 0 additions & 1 deletion docs/en/user-guide/build-by-yourself.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ cd dae
git submodule update --init
## Minimal dependency build
make GOFLAGS="-buildvcs=false" \
CFLAGS="-D__REMOVE_BPF_PRINTK" \
CC=clang

## Normal build
Expand Down