1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright Leon Hwang */
5 #include <bpf/bpf_helpers.h>
14 __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
17 } xdp_errmsg_pb SEC(".maps");
19 struct xdp_attach_error_ctx {
23 * bpf does not support tracepoint __data_loc directly.
25 * Actually, this field is a 32 bit integer whose value encodes
26 * information on where to find the actual data. The first 2 bytes is
27 * the size of the data. The last 2 bytes is the offset from the start
28 * of the tracepoint struct where the data begins.
29 * -- https://github.com/iovisor/bpftrace/pull/1542
31 __u32 msg; // __data_loc char[] msg;
35 * Catch the error message at the tracepoint.
38 SEC("tp/xdp/bpf_xdp_link_attach_failed")
39 int tp__xdp__bpf_xdp_link_attach_failed(struct xdp_attach_error_ctx *ctx)
41 char *msg = (void *)(__u64) ((void *) ctx + (__u16) ctx->msg);
42 struct xdp_errmsg errmsg = {};
44 bpf_probe_read_kernel_str(&errmsg.msg, ERRMSG_LEN, msg);
45 bpf_perf_event_output(ctx, &xdp_errmsg_pb, BPF_F_CURRENT_CPU, &errmsg,
51 * Reuse the XDP program in xdp_dummy.c.
54 char LICENSE[] SEC("license") = "GPL";