Skip to content

Commit

Permalink
xdp: adjust xdp redirect tracepoint to include return error code
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jesper Dangaard Brouer authored and David S. Miller committed Aug 18, 2017
1 parent d2cee2e commit 4c03bdd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
11 changes: 7 additions & 4 deletions include/trace/events/xdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ TRACE_EVENT(xdp_redirect,

TP_PROTO(const struct net_device *from,
const struct net_device *to,
const struct bpf_prog *xdp, u32 act),
const struct bpf_prog *xdp, u32 act, int err),

TP_ARGS(from, to, xdp, act),
TP_ARGS(from, to, xdp, act, err),

TP_STRUCT__entry(
__string(name_from, from->name)
__string(name_to, to->name)
__array(u8, prog_tag, 8)
__field(u32, act)
__field(int, err)
),

TP_fast_assign(
Expand All @@ -70,12 +71,14 @@ TRACE_EVENT(xdp_redirect,
__assign_str(name_from, from->name);
__assign_str(name_to, to->name);
__entry->act = act;
__entry->err = err;
),

TP_printk("prog=%s from=%s to=%s action=%s",
TP_printk("prog=%s from=%s to=%s action=%s err=%d",
__print_hex_str(__entry->prog_tag, 8),
__get_str(name_from), __get_str(name_to),
__print_symbolic(__entry->act, __XDP_ACT_SYM_TAB))
__print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
__entry->err)
);
#endif /* _TRACE_XDP_H */

Expand Down
19 changes: 12 additions & 7 deletions net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2535,14 +2535,16 @@ int xdp_do_redirect_map(struct net_device *dev, struct xdp_buff *xdp,
struct bpf_map *map = ri->map;
u32 index = ri->ifindex;
struct net_device *fwd;
int err = -EINVAL;
int err;

ri->ifindex = 0;
ri->map = NULL;

fwd = __dev_map_lookup_elem(map, index);
if (!fwd)
if (!fwd) {
err = -EINVAL;
goto out;
}

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

out:
trace_xdp_redirect(dev, fwd, xdp_prog, XDP_REDIRECT);
trace_xdp_redirect(dev, fwd, xdp_prog, XDP_REDIRECT, err);
return err;
}

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

if (ri->map)
return xdp_do_redirect_map(dev, xdp, xdp_prog);
Expand All @@ -2570,12 +2573,14 @@ int xdp_do_redirect(struct net_device *dev, struct xdp_buff *xdp,
ri->ifindex = 0;
if (unlikely(!fwd)) {
bpf_warn_invalid_xdp_redirect(index);
return -EINVAL;
err = -EINVAL;
goto out;
}

trace_xdp_redirect(dev, fwd, xdp_prog, XDP_REDIRECT);

return __bpf_tx_xdp(fwd, NULL, xdp, 0);
err = __bpf_tx_xdp(fwd, NULL, xdp, 0);
out:
trace_xdp_redirect(dev, fwd, xdp_prog, XDP_REDIRECT, err);
return err;
}
EXPORT_SYMBOL_GPL(xdp_do_redirect);

Expand Down

0 comments on commit 4c03bdd

Please sign in to comment.