Re: [PATCH bpf-next v1] bpf, sockmap: Introduce tracing capability for sockmap

From: Jiayuan Chen
Date: Wed Apr 09 2025 - 21:22:10 EST


April 10, 2025 at 01:04, "Cong Wang" <xiyou.wangcong@xxxxxxxxx> wrote:
>
> On Wed, Apr 09, 2025 at 06:29:33PM +0800, Jiayuan Chen wrote:
>
> >
> > 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
> >
>
> Nice work!
>
> While you are on it, could we also trace skb->_sk_redir bits too? It is
>
> very useful to distinguish, at least, ingress from egress redirection.
>
> Thanks!
>

Thanks for your suggestion!
The skb->_sk_redir contains a lot of important information about
redirection, so it's definitely worth including.