~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/test_xdp_attach_fail.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /* Copyright Leon Hwang */
  3 
  4 #include <linux/bpf.h>
  5 #include <bpf/bpf_helpers.h>
  6 
  7 #define ERRMSG_LEN 64
  8 
  9 struct xdp_errmsg {
 10         char msg[ERRMSG_LEN];
 11 };
 12 
 13 struct {
 14         __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
 15         __type(key, int);
 16         __type(value, int);
 17 } xdp_errmsg_pb SEC(".maps");
 18 
 19 struct xdp_attach_error_ctx {
 20         unsigned long unused;
 21 
 22         /*
 23          * bpf does not support tracepoint __data_loc directly.
 24          *
 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
 30          */
 31         __u32 msg; // __data_loc char[] msg;
 32 };
 33 
 34 /*
 35  * Catch the error message at the tracepoint.
 36  */
 37 
 38 SEC("tp/xdp/bpf_xdp_link_attach_failed")
 39 int tp__xdp__bpf_xdp_link_attach_failed(struct xdp_attach_error_ctx *ctx)
 40 {
 41         char *msg = (void *)(__u64) ((void *) ctx + (__u16) ctx->msg);
 42         struct xdp_errmsg errmsg = {};
 43 
 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,
 46                               ERRMSG_LEN);
 47         return 0;
 48 }
 49 
 50 /*
 51  * Reuse the XDP program in xdp_dummy.c.
 52  */
 53 
 54 char LICENSE[] SEC("license") = "GPL";
 55 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php