.arg2_type = ARG_ANYTHING,
};
-BPF_CALL_3(bpf_redirect_map, struct bpf_map *, map, u32, ifindex, u64, flags)
-{
- struct redirect_info *ri = this_cpu_ptr(&redirect_info);
-
- if (unlikely(flags))
- return XDP_ABORTED;
-
- ri->ifindex = ifindex;
- ri->flags = flags;
- ri->map = map;
-
- return XDP_REDIRECT;
-}
-
-static const struct bpf_func_proto bpf_redirect_map_proto = {
- .func = bpf_redirect_map,
- .gpl_only = false,
- .ret_type = RET_INTEGER,
- .arg1_type = ARG_CONST_MAP_PTR,
- .arg2_type = ARG_ANYTHING,
- .arg3_type = ARG_ANYTHING,
-};
-
BPF_CALL_3(bpf_sk_redirect_map, struct bpf_map *, map, u32, key, u64, flags)
{
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
err = dev->netdev_ops->ndo_xdp_xmit(dev, xdp);
if (err)
return err;
-
if (map)
__dev_map_insert_ctx(map, index);
else
dev->netdev_ops->ndo_xdp_flush(dev);
-
- return err;
+ return 0;
}
void xdp_do_flush_map(void)
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
struct bpf_map *map = ri->map_to_flush;
- ri->map = NULL;
ri->map_to_flush = NULL;
-
if (map)
__dev_map_flush(map);
}
EXPORT_SYMBOL_GPL(xdp_do_flush_map);
-int xdp_do_redirect_map(struct net_device *dev, struct xdp_buff *xdp,
- struct bpf_prog *xdp_prog)
+static int xdp_do_redirect_map(struct net_device *dev, struct xdp_buff *xdp,
+ struct bpf_prog *xdp_prog)
{
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
struct bpf_map *map = ri->map;
err = -EINVAL;
goto out;
}
-
- if (ri->map_to_flush && (ri->map_to_flush != map))
+ if (ri->map_to_flush && ri->map_to_flush != map)
xdp_do_flush_map();
err = __bpf_tx_xdp(fwd, map, xdp, index);
if (likely(!err))
ri->map_to_flush = map;
-
out:
trace_xdp_redirect(dev, fwd, xdp_prog, XDP_REDIRECT, err);
return err;
ri->ifindex = 0;
if (unlikely(!dev)) {
bpf_warn_invalid_xdp_redirect(index);
- goto err;
+ return -EINVAL;
}
if (unlikely(!(dev->flags & IFF_UP)))
- goto err;
-
+ return -ENETDOWN;
len = dev->mtu + dev->hard_header_len + VLAN_HLEN;
if (skb->len > len)
- goto err;
+ return -E2BIG;
skb->dev = dev;
return 0;
-err:
- return -EINVAL;
}
EXPORT_SYMBOL_GPL(xdp_do_generic_redirect);
ri->ifindex = ifindex;
ri->flags = flags;
+
return XDP_REDIRECT;
}
.arg2_type = ARG_ANYTHING,
};
+BPF_CALL_3(bpf_xdp_redirect_map, struct bpf_map *, map, u32, ifindex, u64, flags)
+{
+ struct redirect_info *ri = this_cpu_ptr(&redirect_info);
+
+ if (unlikely(flags))
+ return XDP_ABORTED;
+
+ ri->ifindex = ifindex;
+ ri->flags = flags;
+ ri->map = map;
+
+ return XDP_REDIRECT;
+}
+
+static const struct bpf_func_proto bpf_xdp_redirect_map_proto = {
+ .func = bpf_xdp_redirect_map,
+ .gpl_only = false,
+ .ret_type = RET_INTEGER,
+ .arg1_type = ARG_CONST_MAP_PTR,
+ .arg2_type = ARG_ANYTHING,
+ .arg3_type = ARG_ANYTHING,
+};
+
bool bpf_helper_changes_pkt_data(void *func)
{
if (func == bpf_skb_vlan_push ||
case BPF_FUNC_redirect:
return &bpf_xdp_redirect_proto;
case BPF_FUNC_redirect_map:
- return &bpf_redirect_map_proto;
+ return &bpf_xdp_redirect_map_proto;
default:
return bpf_base_func_proto(func_id);
}