xref: /openbmc/linux/include/trace/events/xdp.h (revision 7211ec63)
1 #undef TRACE_SYSTEM
2 #define TRACE_SYSTEM xdp
3 
4 #if !defined(_TRACE_XDP_H) || defined(TRACE_HEADER_MULTI_READ)
5 #define _TRACE_XDP_H
6 
7 #include <linux/netdevice.h>
8 #include <linux/filter.h>
9 #include <linux/tracepoint.h>
10 
11 #define __XDP_ACT_MAP(FN)	\
12 	FN(ABORTED)		\
13 	FN(DROP)		\
14 	FN(PASS)		\
15 	FN(TX)			\
16 	FN(REDIRECT)
17 
18 #define __XDP_ACT_TP_FN(x)	\
19 	TRACE_DEFINE_ENUM(XDP_##x);
20 #define __XDP_ACT_SYM_FN(x)	\
21 	{ XDP_##x, #x },
22 #define __XDP_ACT_SYM_TAB	\
23 	__XDP_ACT_MAP(__XDP_ACT_SYM_FN) { -1, 0 }
24 __XDP_ACT_MAP(__XDP_ACT_TP_FN)
25 
26 TRACE_EVENT(xdp_exception,
27 
28 	TP_PROTO(const struct net_device *dev,
29 		 const struct bpf_prog *xdp, u32 act),
30 
31 	TP_ARGS(dev, xdp, act),
32 
33 	TP_STRUCT__entry(
34 		__field(int, prog_id)
35 		__field(u32, act)
36 		__field(int, ifindex)
37 	),
38 
39 	TP_fast_assign(
40 		__entry->prog_id	= xdp->aux->id;
41 		__entry->act		= act;
42 		__entry->ifindex	= dev->ifindex;
43 	),
44 
45 	TP_printk("prog_id=%d action=%s ifindex=%d",
46 		  __entry->prog_id,
47 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
48 		  __entry->ifindex)
49 );
50 
51 DECLARE_EVENT_CLASS(xdp_redirect_template,
52 
53 	TP_PROTO(const struct net_device *dev,
54 		 const struct bpf_prog *xdp,
55 		 int to_ifindex, int err,
56 		 const struct bpf_map *map, u32 map_index),
57 
58 	TP_ARGS(dev, xdp, to_ifindex, err, map, map_index),
59 
60 	TP_STRUCT__entry(
61 		__field(int, prog_id)
62 		__field(u32, act)
63 		__field(int, ifindex)
64 		__field(int, err)
65 		__field(int, to_ifindex)
66 		__field(u32, map_id)
67 		__field(int, map_index)
68 	),
69 
70 	TP_fast_assign(
71 		__entry->prog_id	= xdp->aux->id;
72 		__entry->act		= XDP_REDIRECT;
73 		__entry->ifindex	= dev->ifindex;
74 		__entry->err		= err;
75 		__entry->to_ifindex	= to_ifindex;
76 		__entry->map_id		= map ? map->id : 0;
77 		__entry->map_index	= map_index;
78 	),
79 
80 	TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d",
81 		  __entry->prog_id,
82 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
83 		  __entry->ifindex, __entry->to_ifindex,
84 		  __entry->err)
85 );
86 
87 DEFINE_EVENT(xdp_redirect_template, xdp_redirect,
88 	TP_PROTO(const struct net_device *dev,
89 		 const struct bpf_prog *xdp,
90 		 int to_ifindex, int err,
91 		 const struct bpf_map *map, u32 map_index),
92 	TP_ARGS(dev, xdp, to_ifindex, err, map, map_index)
93 );
94 
95 DEFINE_EVENT(xdp_redirect_template, xdp_redirect_err,
96 	TP_PROTO(const struct net_device *dev,
97 		 const struct bpf_prog *xdp,
98 		 int to_ifindex, int err,
99 		 const struct bpf_map *map, u32 map_index),
100 	TP_ARGS(dev, xdp, to_ifindex, err, map, map_index)
101 );
102 
103 #define _trace_xdp_redirect(dev, xdp, to)		\
104 	 trace_xdp_redirect(dev, xdp, to, 0, NULL, 0);
105 
106 #define _trace_xdp_redirect_err(dev, xdp, to, err)	\
107 	 trace_xdp_redirect_err(dev, xdp, to, err, NULL, 0);
108 
109 DEFINE_EVENT_PRINT(xdp_redirect_template, xdp_redirect_map,
110 	TP_PROTO(const struct net_device *dev,
111 		 const struct bpf_prog *xdp,
112 		 int to_ifindex, int err,
113 		 const struct bpf_map *map, u32 map_index),
114 	TP_ARGS(dev, xdp, to_ifindex, err, map, map_index),
115 	TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d"
116 		  " map_id=%d map_index=%d",
117 		  __entry->prog_id,
118 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
119 		  __entry->ifindex, __entry->to_ifindex,
120 		  __entry->err,
121 		  __entry->map_id, __entry->map_index)
122 );
123 
124 DEFINE_EVENT_PRINT(xdp_redirect_template, xdp_redirect_map_err,
125 	TP_PROTO(const struct net_device *dev,
126 		 const struct bpf_prog *xdp,
127 		 int to_ifindex, int err,
128 		 const struct bpf_map *map, u32 map_index),
129 	TP_ARGS(dev, xdp, to_ifindex, err, map, map_index),
130 	TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d"
131 		  " map_id=%d map_index=%d",
132 		  __entry->prog_id,
133 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
134 		  __entry->ifindex, __entry->to_ifindex,
135 		  __entry->err,
136 		  __entry->map_id, __entry->map_index)
137 );
138 
139 #define _trace_xdp_redirect_map(dev, xdp, fwd, map, idx)		\
140 	 trace_xdp_redirect_map(dev, xdp, fwd ? fwd->ifindex : 0,	\
141 				0, map, idx)
142 
143 #define _trace_xdp_redirect_map_err(dev, xdp, fwd, map, idx, err)	\
144 	 trace_xdp_redirect_map_err(dev, xdp, fwd ? fwd->ifindex : 0,	\
145 				    err, map, idx)
146 
147 #endif /* _TRACE_XDP_H */
148 
149 #include <trace/define_trace.h>
150