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

patch: rewrite bpf spec before loading to avoid bpf map lookup during runtime #376

Merged
merged 2 commits into from
Jan 1, 2024

Conversation

jschwinger233
Copy link
Member

@jschwinger233 jschwinger233 commented Dec 21, 2023

Previously we call bpf_map_lookup constantly to fetch tproxy_pid and tproxy_port, which can be done in a more efficient way by rewriting bpf spec. This PR improves this part without any functional change.

@jschwinger233
Copy link
Member Author

Tested locally, CI should be green too.

@jschwinger233 jschwinger233 marked this pull request as ready for review December 21, 2023 03:47
@jschwinger233 jschwinger233 requested a review from a team as a code owner December 21, 2023 03:47
@jschwinger233
Copy link
Member Author

go test ./... broke but I don't think I'm the culprit.

dae $ go test -timeout 30s ./...
# github.com/daeuniverse/dae/component/outbound [github.com/daeuniverse/dae/component/outbound.test]
component/outbound/dialer_group_test.go:41:3: multiple-value dialer.NewDirectDialer(option, true) (value of type (netproxy.Dialer, *dialer.Property)) in single-value context
component/outbound/dialer_group_test.go:42:3: multiple-value dialer.NewDirectDialer(option, false) (value of type (netproxy.Dialer, *dialer.Property)) in single-value context
component/outbound/dialer_group_test.go:48:5: not enough arguments in call to NewDialerGroup
        have (*dialer.GlobalOption, string, []*dialer.Dialer, DialerSelectionPolicy, func(alive bool, networkType *dialer.NetworkType, isInit bool))
        want (*dialer.GlobalOption, string, []*dialer.Dialer, []*dialer.Annotation, DialerSelectionPolicy, func(alive bool, networkType *dialer.NetworkType, isInit bool))
component/outbound/dialer_group_test.go:81:3: multiple-value dialer.NewDirectDialer(option, false) (value of type (netproxy.Dialer, *dialer.Property)) in single-value context
component/outbound/dialer_group_test.go:82:3: multiple-value dialer.NewDirectDialer(option, false) (value of type (netproxy.Dialer, *dialer.Property)) in single-value context
component/outbound/dialer_group_test.go:83:3: multiple-value dialer.NewDirectDialer(option, false) (value of type (netproxy.Dialer, *dialer.Property)) in single-value context
component/outbound/dialer_group_test.go:84:3: multiple-value dialer.NewDirectDialer(option, false) (value of type (netproxy.Dialer, *dialer.Property)) in single-value context
component/outbound/dialer_group_test.go:85:3: multiple-value dialer.NewDirectDialer(option, false) (value of type (netproxy.Dialer, *dialer.Property)) in single-value context
component/outbound/dialer_group_test.go:86:3: multiple-value dialer.NewDirectDialer(option, false) (value of type (netproxy.Dialer, *dialer.Property)) in single-value context
component/outbound/dialer_group_test.go:87:3: multiple-value dialer.NewDirectDialer(option, false) (value of type (netproxy.Dialer, *dialer.Property)) in single-value context
component/outbound/dialer_group_test.go:87:3: too many errors
?       github.com/daeuniverse/dae      [no test files]
?       github.com/daeuniverse/dae/cmd  [no test files]
?       github.com/daeuniverse/dae/cmd/internal [no test files]
?       github.com/daeuniverse/dae/common       [no test files]
?       github.com/daeuniverse/dae/common/assets        [no test files]
?       github.com/daeuniverse/dae/common/consts        [no test files]
?       github.com/daeuniverse/dae/common/json  [no test files]
?       github.com/daeuniverse/dae/common/subscription  [no test files]
?       github.com/daeuniverse/dae/component/dns        [no test files]
?       github.com/daeuniverse/dae/component/outbound/dialer    [no test files]
?       github.com/daeuniverse/dae/component/outbound/dialer/http       [no test files]
?       github.com/daeuniverse/dae/component/outbound/dialer/juicity    [no test files]
?       github.com/daeuniverse/dae/component/outbound/dialer/shadowsocks        [no test files]
?       github.com/daeuniverse/dae/component/outbound/dialer/shadowsocksr       [no test files]
--- FAIL: TestBitList6 (0.00s)
    bitlist_test.go:29: failed to tighten 6
--- FAIL: TestBitList19 (0.00s)
    bitlist_test.go:63: failed to tighten 17
FAIL
FAIL    github.com/daeuniverse/dae/common/bitlist       0.002s
?       github.com/daeuniverse/dae/component/outbound/dialer/trojan     [no test files]
?       github.com/daeuniverse/dae/component/outbound/dialer/tuic       [no test files]
?       github.com/daeuniverse/dae/component/outbound/dialer/v2ray      [no test files]
?       github.com/daeuniverse/dae/component/outbound/transport/simpleobfs      [no test files]
?       github.com/daeuniverse/dae/component/outbound/transport/tls     [no test files]
?       github.com/daeuniverse/dae/component/outbound/transport/ws      [no test files]
?       github.com/daeuniverse/dae/component/routing    [no test files]
ok      github.com/daeuniverse/dae/common/netutils      0.033s
FAIL    github.com/daeuniverse/dae/component/outbound [build failed]
?       github.com/daeuniverse/dae/pkg/anybuffer        [no test files]
?       github.com/daeuniverse/dae/pkg/ebpf_internal    [no test files]
?       github.com/daeuniverse/dae/pkg/ebpf_internal/internal/unix      [no test files]
?       github.com/daeuniverse/dae/pkg/geodata  [no test files]
?       github.com/daeuniverse/dae/pkg/geodata/protoext [no test files]
?       github.com/daeuniverse/dae/pkg/logger   [no test files]
--- FAIL: TestSocks5 (5.00s)
    socks_test.go:53: context deadline exceeded
FAIL
FAIL    github.com/daeuniverse/dae/component/outbound/dialer/socks      5.008s
ok      github.com/daeuniverse/dae/component/routing/domain_matcher     4.269s
ok      github.com/daeuniverse/dae/component/sniffing   0.003s
ok      github.com/daeuniverse/dae/component/sniffing/internal/quicutils        0.002s
--- FAIL: TestMarshal (0.00s)
    marshal_test.go:23: permissions 0664 for '/home/gray/src/github.com/daeuniverse/dae/example.dae' are too open; requires the file is NOT writable by the same group and NOT accessible by others; suggest 0640 or
0600
FAIL
FAIL    github.com/daeuniverse/dae/config       0.003s
--- FAIL: TestPacketSniffer_Mismatched (0.00s)
    packet_sniffer_pool_test.go:56: unexpected found i.ytimg.com
FAIL
FAIL    github.com/daeuniverse/dae/control      0.005s
ok      github.com/daeuniverse/dae/pkg/config_parser    0.004s
ok      github.com/daeuniverse/dae/pkg/trie     0.002s
FAIL

Breakage can also be seen on main.

@mzz2017
Copy link
Contributor

mzz2017 commented Dec 21, 2023

I'm in Shenzhen these days. I'll take a review on weekends as long as I'm free. Thank you!

@piyoki piyoki added the triage/accepted Issues which should be fixed (post-triage) label Dec 21, 2023
@piyoki
Copy link
Contributor

piyoki commented Dec 21, 2023

Link to #375

@jschwinger233
Copy link
Member Author

@mzz2017 这个 PR 比较简单, 也不涉及功能性修改, 应该比较好 review :pitiful:

@mzz2017
Copy link
Contributor

mzz2017 commented Jan 1, 2024

I'll take a look right now.

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.

@mzz2017
Copy link
Contributor

mzz2017 commented Jan 1, 2024

Will this approach occupy registers for a long time? According to my previous experience, using map will reduce register usage.

@jschwinger233 jschwinger233 merged commit e7c4473 into daeuniverse:main Jan 1, 2024
27 checks passed
@sumire88 sumire88 changed the title Rewrite bpf spec before loading to avoid bpf map lookup during runtime patch: rewrite bpf spec before loading to avoid bpf map lookup during runtime Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage/accepted Issues which should be fixed (post-triage)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants