Skip to content

bpf, sockmap: Introduce tracing capability for sockmap #12

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

Closed
wants to merge 3 commits into from

Conversation

mrpre
Copy link
Owner

@mrpre mrpre commented Apr 9, 2025

Sockmap has the same high-performance forwarding capability as XDP, but operates at Layer 7.

Introduce tracing capability for sockmap, similar to XDP, to trace the execution results of BPF programs without modifying the programs themselves, similar to the existing trace_xdp_redirect{_map}.

It is crucial for debugging BPF programs, especially in production environments.

Additionally, a header file was added to bpf_trace.h to automatically generate tracepoints.

Test results:
$ echo "1" > /sys/kernel/tracing/events/sockmap/enable

skb:
sockmap_redirect: sk=00000000d3266a8d, type=skb, family=2, protocol=6, \ prog_id=73, length=256, action=PASS

msg:
sockmap_redirect: sk=00000000528c7614, type=msg, family=2, protocol=6, \ prog_id=185, length=5, action=REDIRECT

tls:
sockmap_redirect: sk=00000000d04d2224, type=skb, family=2, protocol=6, \ prog_id=143, length=35, action=PASS

strparser:
sockmap_skb_strp_parse: sk=00000000ecab0b30, family=2, protocol=6, \ prog_id=170, size=5

@mrpre mrpre force-pushed the trace branch 4 times, most recently from c21a98a to 07b1c20 Compare April 14, 2025 15:42
@mrpre mrpre force-pushed the bpf-next_base branch from c7849f3 to 309dda5 Compare May 6, 2025 02:00
mrpre added 2 commits May 6, 2025 10:01
Sockmap has the same high-performance forwarding capability as XDP, but
operates at Layer 7.

Introduce tracing capability for sockmap, to trace the execution results
of BPF programs without modifying the programs themselves, similar to
the existing trace_xdp_redirect{_map}.

It is crucial for debugging sockmap programs, especially in production
environments.

Additionally, the new header file has to be added to bpf_trace.h to
automatically generate tracepoints.

Test results:
$ echo "1" > /sys/kernel/tracing/events/sockmap/enable

msg/skb:
'''
sockmap_redirect: sk=000000000ec02a93, netns=4026531840, inode=318, \
family=2, protocol=6, prog_id=59, len=8192, type=msg, action=REDIRECT, \
redirect_type=ingress

sockmap_redirect: sk=00000000d5d9c931, netns=4026531840, inode=64731, \
family=2, protocol=6, prog_id=91, len=8221, type=skb, action=REDIRECT, \
redirect_type=egress

sockmap_redirect: sk=00000000106fc281, netns=4026531840, inode=64729, \
family=2, protocol=6, prog_id=94, len=8192, type=msg, action=PASS, \
redirect_type=none
'''

strparser:
'''
sockmap_strparser: sk=00000000f15fc1c8, netns=4026531840, inode=52396, \
family=2, protocol=6, prog_id=143, in_len=1000, full_len=10
'''

Reviewed-by: Cong Wang <[email protected]>
Suggested-by: Jakub Sitnicki <[email protected]>
Suggested-by: Cong Wang <[email protected]>
Suggested-by: Steven Rostedt <[email protected]>
Signed-off-by: Jiayuan Chen <[email protected]>
This commit relocates the BPF tracepoint definitions for XDP and sockmap
from the kernel directory to net/bpf.

This ensures that these tracepoints are controlled by the CONFIG_NET,
avoiding unnecessary function definitions when the CONFIG_NET is disabled.
Additionally, it prevents build failures caused by the use of net module
functions when CONFIG_NET is not enabled.

Signed-off-by: Jiayuan Chen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant