BCC and passing packet from XDP to user-mode app #bcc


Yonghong Song
 

On Thu, Mar 18, 2021 at 4:49 AM Federico Parola
<federico.parola@...> wrote:

Hi,
the virtual function you are looking for is perf_submit_skb():

https://github.com/iovisor/bcc/blob/c8de00e1746e242cdcd68b4673a083bb467cd35e/src/cc/export/helpers.h#L193

Strangely it is not documented in the reference guide.
Thanks, Federico and others. Maybe one of you can add it to the
reference_guide.md? We
do have events.perf_submit there. Thanks!


Best regards,
Federico Parola

On 18/03/21 10:29, v.a.bonert@... wrote:
Hi!
Is it possible to pass full ethernet packet from XDP to user-mode app
using BCC?
I wrote C code like this:
BPF_PERF_OUTPUT(captured_data);
capture(struct xdp_md *ctx)
{
events.perf_submit(ctx, ...);
}
But there is no flags argument in perf_submit function (but
bpf_perf_event_output has such argument).
Without BCC I can write such code to pass full packet to user-mode:
struct packet_info
{
uint32_t packet_len;
uint32_t iface_id;
};
struct bpf_map_def SEC("maps") captured_data =
{
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
.key_size = sizeof(u32),
.value_size = sizeof(u32),
.max_entries = MAX_CPUS
};
SEC("xdp")
int capture_kern(struct xdp_md *ctx)
{
u32 len = ctx->data_end - ctx->data;
u64 flags = BPF_F_CURRENT_CPU;
flags |= (u64)len << 32;
struct packet_info info = {len, ctx->ingress_ifindex};
bpf_perf_event_output(ctx, &captured_data, flags, &info, sizeof(info));
return XDP_PASS;
}
How can I do the same when using BCC?




Federico Parola
 

Hi,
the virtual function you are looking for is perf_submit_skb():

https://github.com/iovisor/bcc/blob/c8de00e1746e242cdcd68b4673a083bb467cd35e/src/cc/export/helpers.h#L193

Strangely it is not documented in the reference guide.

Best regards,
Federico Parola

On 18/03/21 10:29, v.a.bonert@... wrote:
Hi!
Is it possible to pass full ethernet packet from XDP to user-mode app using BCC?
I wrote C code like this:
BPF_PERF_OUTPUT(captured_data);
capture(struct xdp_md *ctx)
{
    events.perf_submit(ctx, ...);
}
But there is no flags argument in perf_submit function (but bpf_perf_event_output has such argument).
Without BCC I can write such code to pass full packet to user-mode:
struct packet_info
{
    uint32_t packet_len;
    uint32_t iface_id;
};
struct bpf_map_def SEC("maps") captured_data =
{
    .type        = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
    .key_size    = sizeof(u32),
    .value_size  = sizeof(u32),
    .max_entries = MAX_CPUS
};
SEC("xdp")
int capture_kern(struct xdp_md *ctx)
{
    u32 len = ctx->data_end - ctx->data;
    u64 flags = BPF_F_CURRENT_CPU;
    flags |= (u64)len << 32;
    struct packet_info info = {len, ctx->ingress_ifindex};
    bpf_perf_event_output(ctx, &captured_data, flags, &info, sizeof(info));
    return XDP_PASS;
}
How can I do the same when using BCC?


v.a.bonert@...
 
Edited

Hi!
 
Is it possible to pass full ethernet packet from XDP to user-mode app using BCC?
I wrote C code like this:
 
BPF_PERF_OUTPUT(captured_data);
int capture(struct xdp_md *ctx)
{
    captured_data.perf_submit(ctx, ...);
    return XDP_PASS;
}
 
But there is no flags argument in perf_submit function (but bpf_perf_event_output has such argument).
 
Without BCC I can write such code to pass full packet to user-mode:
 
struct packet_info
{
    uint32_t packet_len;
    uint32_t iface_id;
};
 
struct bpf_map_def SEC("maps") captured_data =
{
    .type        = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
    .key_size    = sizeof(u32),
    .value_size  = sizeof(u32),
    .max_entries = MAX_CPUS
};
 
SEC("xdp")
int capture_kern(struct xdp_md *ctx)
{
    u32 len = ctx->data_end - ctx->data;
    u64 flags = BPF_F_CURRENT_CPU;
    flags |= (u64)len << 32;
    struct packet_info info = {len, ctx->ingress_ifindex};
    bpf_perf_event_output(ctx, &captured_data, flags, &info, sizeof(info));
 
    return XDP_PASS;
}
 
How can I do the same when using BCC?