Skip to content

Commit 8d3b778

Browse files
netoptimizerdavem330
authored andcommitted
xdp: tracepoint xdp_redirect also need a map argument
To make sense of the map index, the tracepoint user also need to know that map we are talking about. Supply the map pointer but only expose the map->id. The 'to_index' is renamed 'to_ifindex'. In the xdp_redirect_map case, this is the result of the devmap lookup. The map lookup key is exposed as map_index, which is needed to troubleshoot in case the lookup failed. The 'to_ifindex' is placed after 'err' to keep TP_STRUCT as common as possible. This also keeps the TP_STRUCT similar enough, that userspace can write a monitor program, that doesn't need to care about whether bpf_redirect or bpf_redirect_map were used. Signed-off-by: Jesper Dangaard Brouer <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c31e5a4 commit 8d3b778

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

include/trace/events/xdp.h

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,37 +49,59 @@ TRACE_EVENT(xdp_exception,
4949
__entry->ifindex)
5050
);
5151

52-
TRACE_EVENT(xdp_redirect,
52+
DECLARE_EVENT_CLASS(xdp_redirect_template,
5353

5454
TP_PROTO(const struct net_device *dev,
5555
const struct bpf_prog *xdp,
56-
int to_index, int err),
56+
int to_ifindex, int err,
57+
const struct bpf_map *map, u32 map_index),
5758

58-
TP_ARGS(dev, xdp, to_index, err),
59+
TP_ARGS(dev, xdp, to_ifindex, err, map, map_index),
5960

6061
TP_STRUCT__entry(
6162
__array(u8, prog_tag, 8)
6263
__field(u32, act)
6364
__field(int, ifindex)
64-
__field(int, to_index)
6565
__field(int, err)
66+
__field(int, to_ifindex)
67+
__field(u32, map_id)
68+
__field(int, map_index)
6669
),
6770

6871
TP_fast_assign(
6972
BUILD_BUG_ON(sizeof(__entry->prog_tag) != sizeof(xdp->tag));
7073
memcpy(__entry->prog_tag, xdp->tag, sizeof(xdp->tag));
7174
__entry->act = XDP_REDIRECT;
7275
__entry->ifindex = dev->ifindex;
73-
__entry->to_index = to_index;
7476
__entry->err = err;
77+
__entry->to_ifindex = to_ifindex;
78+
__entry->map_id = map ? map->id : 0;
79+
__entry->map_index = map_index;
7580
),
7681

77-
TP_printk("prog=%s action=%s ifindex=%d to_index=%d err=%d",
82+
TP_printk("prog=%s action=%s ifindex=%d to_ifindex=%d err=%d"
83+
" map_id=%d map_index=%d",
7884
__print_hex_str(__entry->prog_tag, 8),
7985
__print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
80-
__entry->ifindex, __entry->to_index,
81-
__entry->err)
86+
__entry->ifindex, __entry->to_ifindex,
87+
__entry->err,
88+
__entry->map_id, __entry->map_index)
8289
);
90+
91+
DEFINE_EVENT(xdp_redirect_template, xdp_redirect,
92+
TP_PROTO(const struct net_device *dev,
93+
const struct bpf_prog *xdp,
94+
int to_ifindex, int err,
95+
const struct bpf_map *map, u32 map_index),
96+
TP_ARGS(dev, xdp, to_ifindex, err, map, map_index)
97+
);
98+
99+
#define _trace_xdp_redirect(dev, xdp, to, err) \
100+
trace_xdp_redirect(dev, xdp, to, err, NULL, 0);
101+
102+
#define trace_xdp_redirect_map(dev, xdp, fwd, err, map, idx) \
103+
trace_xdp_redirect(dev, xdp, fwd ? fwd->ifindex : 0, err, map, idx);
104+
83105
#endif /* _TRACE_XDP_H */
84106

85107
#include <trace/define_trace.h>

net/core/filter.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,7 +2524,7 @@ static int xdp_do_redirect_map(struct net_device *dev, struct xdp_buff *xdp,
25242524
if (likely(!err))
25252525
ri->map_to_flush = map;
25262526
out:
2527-
trace_xdp_redirect(dev, xdp_prog, index, err);
2527+
trace_xdp_redirect_map(dev, xdp_prog, fwd, err, map, index);
25282528
return err;
25292529
}
25302530

@@ -2548,7 +2548,7 @@ int xdp_do_redirect(struct net_device *dev, struct xdp_buff *xdp,
25482548

25492549
err = __bpf_tx_xdp(fwd, NULL, xdp, 0);
25502550
out:
2551-
trace_xdp_redirect(dev, xdp_prog, index, err);
2551+
_trace_xdp_redirect(dev, xdp_prog, index, err);
25522552
return err;
25532553
}
25542554
EXPORT_SYMBOL_GPL(xdp_do_redirect);
@@ -2582,7 +2582,7 @@ int xdp_do_generic_redirect(struct net_device *dev, struct sk_buff *skb,
25822582

25832583
skb->dev = fwd;
25842584
out:
2585-
trace_xdp_redirect(dev, xdp_prog, index, err);
2585+
_trace_xdp_redirect(dev, xdp_prog, index, err);
25862586
return err;
25872587
}
25882588
EXPORT_SYMBOL_GPL(xdp_do_generic_redirect);

0 commit comments

Comments
 (0)