of: MSI: Simplify irqdomain lookup
[linux/fpc-iii.git] / samples / bpf / tracex1_kern.c
blob3f450a8fa1f3487b2cf2d9b261f63dc3d25f6599
1 /* Copyright (c) 2013-2015 PLUMgrid, http://plumgrid.com
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
6 */
7 #include <linux/skbuff.h>
8 #include <linux/netdevice.h>
9 #include <uapi/linux/bpf.h>
10 #include <linux/version.h>
11 #include "bpf_helpers.h"
13 #define _(P) ({typeof(P) val = 0; bpf_probe_read(&val, sizeof(val), &P); val;})
15 /* kprobe is NOT a stable ABI
16 * kernel functions can be removed, renamed or completely change semantics.
17 * Number of arguments and their positions can change, etc.
18 * In such case this bpf+kprobe example will no longer be meaningful
20 SEC("kprobe/__netif_receive_skb_core")
21 int bpf_prog1(struct pt_regs *ctx)
23 /* attaches to kprobe netif_receive_skb,
24 * looks for packets on loobpack device and prints them
26 char devname[IFNAMSIZ] = {};
27 struct net_device *dev;
28 struct sk_buff *skb;
29 int len;
31 /* non-portable! works for the given kernel only */
32 skb = (struct sk_buff *) PT_REGS_PARM1(ctx);
34 dev = _(skb->dev);
36 len = _(skb->len);
38 bpf_probe_read(devname, sizeof(devname), dev->name);
40 if (devname[0] == 'l' && devname[1] == 'o') {
41 char fmt[] = "skb %p len %d\n";
42 /* using bpf_trace_printk() for DEBUG ONLY */
43 bpf_trace_printk(fmt, sizeof(fmt), skb, len);
46 return 0;
49 char _license[] SEC("license") = "GPL";
50 u32 _version SEC("version") = LINUX_VERSION_CODE;