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

optimize(bpf): Alternative way to avoid parsing packet at dae0 #600

Merged
merged 3 commits into from
Aug 24, 2024

Conversation

jschwinger233
Copy link
Member

@jschwinger233 jschwinger233 commented Aug 7, 2024

Background

#562 caused more issues than benefits, such as #586. Unfortunately I failed to reproduce issues after several attempts. This PR reverts the changes, but introduced an alternative solution to avoid parsing packet at dae0_ingress.

The key idea is skbs at dae0_ingress are bound to be built from a local process (control plane process, dae), so we should be confident in using skb->sk->{local_ip4,dst_ip4,local_ip6,dst_ip6} to get tuples, instead of calling parse_transport() followed by get_tuples(). This doesn't work because udp listener socket always has zero value as sk->dst_ip4.

The key idea is to parse L3 by manually calling bpf_skb_load_bytes for twice only. The instruction number can be greatly reduced from 913 to 333 (jitted x64, kernel 6.5.0-1027-oem), -63% comparing to current main (using direct access). Before #562 the insn number can be as many as 1715, then it's -80%.

The subtle part is this PR deletes l4proto from redirect_tuple. This looks harmless as a TCP connection and a UDP "connection" with same src/dst ip should have same source, therefore they can safely share one redirect_entry.

One followup on me: review and fix ci kernel-test.

Checklist

Full Changelogs

  • [Implement ...]

Issue Reference

Closes #586

Test Result

@jschwinger233 jschwinger233 marked this pull request as ready for review August 7, 2024 16:48
@jschwinger233 jschwinger233 requested a review from a team as a code owner August 7, 2024 16:48
mzz2017
mzz2017 previously approved these changes Aug 7, 2024
Copy link
Contributor

@mzz2017 mzz2017 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@umlka
Copy link

umlka commented Aug 8, 2024

用了这个PR Build国内外(dae本机和局域网客户端)都上不了网了,通过抓包发现只有DNS请求,但收不到DNS应答,dae那边是劫持到了DNS请求了的

环境

debian@Copy-of-VM-debian:~$ uname -a
Linux Copy-of-VM-debian 6.1.0-23-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.99-1 (2024-07-15) x86_64 GNU/Linux
debian@Copy-of-VM-debian:~$ dae -v
dae version unstable-20240807.pr-600.r2.307338
go runtime go1.22.5 linux/amd64
Copyright (c) 2022-2024 @daeuniverse
License GNU AGPLv3 <https://github.com/daeuniverse/dae/blob/main/LICENSE>

测试

debian@Copy-of-VM-debian:~$ curl -v one.one.one.one
* Could not resolve host: one.one.one.one
* Closing connection 0
curl: (6) Could not resolve host: one.one.one.one
debian@Copy-of-VM-debian:~$ curl -v 1.1.1.1
*   Trying 1.1.1.1:80...
* Connected to 1.1.1.1 (1.1.1.1) port 80 (#0)
> GET / HTTP/1.1
> Host: 1.1.1.1
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Server: cloudflare
< Date: Thu, 08 Aug 2024 08:15:30 GMT
< Content-Type: text/html
< Content-Length: 167
< Connection: keep-alive
< Location: https://1.1.1.1/
< CF-RAY: 8afe0f17edaf2f7a-LAX
<
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>cloudflare</center>
</body>
</html>
* Connection #0 to host 1.1.1.1 left intact

Now we can load l3 addr free from heavy duty of parse_transport and
get_tuples.
@umlka
Copy link

umlka commented Aug 8, 2024

现在正常了

@douglarek
Copy link
Contributor

douglarek commented Aug 18, 2024

Is there something preventing this PR from being merged? The latest main branch cannot run on the OpenWrt 6.6 kernel without this PR. @jschwinger233 @mzz2017

I have tested this PR on OpenWrt, and it works well. Is there anything else that needs testing?

Copy link
Contributor

@dae-prow dae-prow bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 Since the PR has been fully tested, please consider merging it.

@mzz2017 mzz2017 merged commit 00d569f into daeuniverse:main Aug 24, 2024
27 checks passed
@jschwinger233 jschwinger233 mentioned this pull request Sep 8, 2024
3 tasks
@dae-prow dae-prow bot mentioned this pull request Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug Report] v0.8.0rc1进程消失
4 participants