Skip to content

Commit 4c03bdd

Browse files
netoptimizerdavem330
authored andcommitted
xdp: adjust xdp redirect tracepoint to include return error code
The return error code need to be included in the tracepoint xdp:xdp_redirect, else its not possible to distinguish successful or failed XDP_REDIRECT transmits. XDP have no queuing mechanism. Thus, it is fairly easily to overrun a NIC transmit queue. The eBPF program invoking helpers (bpf_redirect or bpf_redirect_map) to redirect a packet doesn't get any feedback whether the packet was actually transmitted. Info on failed transmits in the tracepoint xdp:xdp_redirect, is interesting as this opens for providing a feedback-loop to the receiving XDP program. Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d2cee2e commit 4c03bdd

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

include/trace/events/xdp.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ TRACE_EVENT(xdp_redirect,
5353

5454
TP_PROTO(const struct net_device *from,
5555
const struct net_device *to,
56-
const struct bpf_prog *xdp, u32 act),
56+
const struct bpf_prog *xdp, u32 act, int err),
5757

58-
TP_ARGS(from, to, xdp, act),
58+
TP_ARGS(from, to, xdp, act, err),
5959

6060
TP_STRUCT__entry(
6161
__string(name_from, from->name)
6262
__string(name_to, to->name)
6363
__array(u8, prog_tag, 8)
6464
__field(u32, act)
65+
__field(int, err)
6566
),
6667

6768
TP_fast_assign(
@@ -70,12 +71,14 @@ TRACE_EVENT(xdp_redirect,
7071
__assign_str(name_from, from->name);
7172
__assign_str(name_to, to->name);
7273
__entry->act = act;
74+
__entry->err = err;
7375
),
7476

75-
TP_printk("prog=%s from=%s to=%s action=%s",
77+
TP_printk("prog=%s from=%s to=%s action=%s err=%d",
7678
__print_hex_str(__entry->prog_tag, 8),
7779
__get_str(name_from), __get_str(name_to),
78-
__print_symbolic(__entry->act, __XDP_ACT_SYM_TAB))
80+
__print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
81+
__entry->err)
7982
);
8083
#endif /* _TRACE_XDP_H */
8184

net/core/filter.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,14 +2535,16 @@ int xdp_do_redirect_map(struct net_device *dev, struct xdp_buff *xdp,
25352535
struct bpf_map *map = ri->map;
25362536
u32 index = ri->ifindex;
25372537
struct net_device *fwd;
2538-
int err = -EINVAL;
2538+
int err;
25392539

25402540
ri->ifindex = 0;
25412541
ri->map = NULL;
25422542

25432543
fwd = __dev_map_lookup_elem(map, index);
2544-
if (!fwd)
2544+
if (!fwd) {
2545+
err = -EINVAL;
25452546
goto out;
2547+
}
25462548

25472549
if (ri->map_to_flush && (ri->map_to_flush != map))
25482550
xdp_do_flush_map();
@@ -2552,7 +2554,7 @@ int xdp_do_redirect_map(struct net_device *dev, struct xdp_buff *xdp,
25522554
ri->map_to_flush = map;
25532555

25542556
out:
2555-
trace_xdp_redirect(dev, fwd, xdp_prog, XDP_REDIRECT);
2557+
trace_xdp_redirect(dev, fwd, xdp_prog, XDP_REDIRECT, err);
25562558
return err;
25572559
}
25582560

@@ -2562,6 +2564,7 @@ int xdp_do_redirect(struct net_device *dev, struct xdp_buff *xdp,
25622564
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
25632565
struct net_device *fwd;
25642566
u32 index = ri->ifindex;
2567+
int err;
25652568

25662569
if (ri->map)
25672570
return xdp_do_redirect_map(dev, xdp, xdp_prog);
@@ -2570,12 +2573,14 @@ int xdp_do_redirect(struct net_device *dev, struct xdp_buff *xdp,
25702573
ri->ifindex = 0;
25712574
if (unlikely(!fwd)) {
25722575
bpf_warn_invalid_xdp_redirect(index);
2573-
return -EINVAL;
2576+
err = -EINVAL;
2577+
goto out;
25742578
}
25752579

2576-
trace_xdp_redirect(dev, fwd, xdp_prog, XDP_REDIRECT);
2577-
2578-
return __bpf_tx_xdp(fwd, NULL, xdp, 0);
2580+
err = __bpf_tx_xdp(fwd, NULL, xdp, 0);
2581+
out:
2582+
trace_xdp_redirect(dev, fwd, xdp_prog, XDP_REDIRECT, err);
2583+
return err;
25792584
}
25802585
EXPORT_SYMBOL_GPL(xdp_do_redirect);
25812586

0 commit comments

Comments
 (0)