devmap: Rename ifindex member in bpf_redirect_info
The bpf_redirect_info struct has an 'ifindex' member which was named back when the redirects could only target egress interfaces. Now that we can also redirect to sockets and CPUs, this is a bit misleading, so rename the member to tgt_index. Reorder the struct members so we can have 'tgt_index' and 'tgt_value' next to each other in a subsequent patch. Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:
parent
d5df2830ca
commit
4b55cf290d
@ -578,8 +578,8 @@ struct bpf_skb_data_end {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct bpf_redirect_info {
|
struct bpf_redirect_info {
|
||||||
u32 ifindex;
|
|
||||||
u32 flags;
|
u32 flags;
|
||||||
|
u32 tgt_index;
|
||||||
struct bpf_map *map;
|
struct bpf_map *map;
|
||||||
struct bpf_map *map_to_flush;
|
struct bpf_map *map_to_flush;
|
||||||
u32 kern_flags;
|
u32 kern_flags;
|
||||||
|
@ -2158,8 +2158,8 @@ BPF_CALL_2(bpf_redirect, u32, ifindex, u64, flags)
|
|||||||
if (unlikely(flags & ~(BPF_F_INGRESS)))
|
if (unlikely(flags & ~(BPF_F_INGRESS)))
|
||||||
return TC_ACT_SHOT;
|
return TC_ACT_SHOT;
|
||||||
|
|
||||||
ri->ifindex = ifindex;
|
|
||||||
ri->flags = flags;
|
ri->flags = flags;
|
||||||
|
ri->tgt_index = ifindex;
|
||||||
|
|
||||||
return TC_ACT_REDIRECT;
|
return TC_ACT_REDIRECT;
|
||||||
}
|
}
|
||||||
@ -2169,8 +2169,8 @@ int skb_do_redirect(struct sk_buff *skb)
|
|||||||
struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info);
|
struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info);
|
||||||
struct net_device *dev;
|
struct net_device *dev;
|
||||||
|
|
||||||
dev = dev_get_by_index_rcu(dev_net(skb->dev), ri->ifindex);
|
dev = dev_get_by_index_rcu(dev_net(skb->dev), ri->tgt_index);
|
||||||
ri->ifindex = 0;
|
ri->tgt_index = 0;
|
||||||
if (unlikely(!dev)) {
|
if (unlikely(!dev)) {
|
||||||
kfree_skb(skb);
|
kfree_skb(skb);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -3488,11 +3488,11 @@ xdp_do_redirect_slow(struct net_device *dev, struct xdp_buff *xdp,
|
|||||||
struct bpf_prog *xdp_prog, struct bpf_redirect_info *ri)
|
struct bpf_prog *xdp_prog, struct bpf_redirect_info *ri)
|
||||||
{
|
{
|
||||||
struct net_device *fwd;
|
struct net_device *fwd;
|
||||||
u32 index = ri->ifindex;
|
u32 index = ri->tgt_index;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
fwd = dev_get_by_index_rcu(dev_net(dev), index);
|
fwd = dev_get_by_index_rcu(dev_net(dev), index);
|
||||||
ri->ifindex = 0;
|
ri->tgt_index = 0;
|
||||||
if (unlikely(!fwd)) {
|
if (unlikely(!fwd)) {
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
goto err;
|
goto err;
|
||||||
@ -3604,11 +3604,11 @@ static int xdp_do_redirect_map(struct net_device *dev, struct xdp_buff *xdp,
|
|||||||
struct bpf_prog *xdp_prog, struct bpf_map *map,
|
struct bpf_prog *xdp_prog, struct bpf_map *map,
|
||||||
struct bpf_redirect_info *ri)
|
struct bpf_redirect_info *ri)
|
||||||
{
|
{
|
||||||
u32 index = ri->ifindex;
|
u32 index = ri->tgt_index;
|
||||||
void *fwd = NULL;
|
void *fwd = NULL;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
ri->ifindex = 0;
|
ri->tgt_index = 0;
|
||||||
WRITE_ONCE(ri->map, NULL);
|
WRITE_ONCE(ri->map, NULL);
|
||||||
|
|
||||||
fwd = __xdp_map_lookup_elem(map, index);
|
fwd = __xdp_map_lookup_elem(map, index);
|
||||||
@ -3651,11 +3651,11 @@ static int xdp_do_generic_redirect_map(struct net_device *dev,
|
|||||||
struct bpf_map *map)
|
struct bpf_map *map)
|
||||||
{
|
{
|
||||||
struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info);
|
struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info);
|
||||||
u32 index = ri->ifindex;
|
u32 index = ri->tgt_index;
|
||||||
void *fwd = NULL;
|
void *fwd = NULL;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
ri->ifindex = 0;
|
ri->tgt_index = 0;
|
||||||
WRITE_ONCE(ri->map, NULL);
|
WRITE_ONCE(ri->map, NULL);
|
||||||
|
|
||||||
fwd = __xdp_map_lookup_elem(map, index);
|
fwd = __xdp_map_lookup_elem(map, index);
|
||||||
@ -3695,14 +3695,14 @@ int xdp_do_generic_redirect(struct net_device *dev, struct sk_buff *skb,
|
|||||||
{
|
{
|
||||||
struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info);
|
struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info);
|
||||||
struct bpf_map *map = READ_ONCE(ri->map);
|
struct bpf_map *map = READ_ONCE(ri->map);
|
||||||
u32 index = ri->ifindex;
|
u32 index = ri->tgt_index;
|
||||||
struct net_device *fwd;
|
struct net_device *fwd;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
if (map)
|
if (map)
|
||||||
return xdp_do_generic_redirect_map(dev, skb, xdp, xdp_prog,
|
return xdp_do_generic_redirect_map(dev, skb, xdp, xdp_prog,
|
||||||
map);
|
map);
|
||||||
ri->ifindex = 0;
|
ri->tgt_index = 0;
|
||||||
fwd = dev_get_by_index_rcu(dev_net(dev), index);
|
fwd = dev_get_by_index_rcu(dev_net(dev), index);
|
||||||
if (unlikely(!fwd)) {
|
if (unlikely(!fwd)) {
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
@ -3730,8 +3730,8 @@ BPF_CALL_2(bpf_xdp_redirect, u32, ifindex, u64, flags)
|
|||||||
if (unlikely(flags))
|
if (unlikely(flags))
|
||||||
return XDP_ABORTED;
|
return XDP_ABORTED;
|
||||||
|
|
||||||
ri->ifindex = ifindex;
|
|
||||||
ri->flags = flags;
|
ri->flags = flags;
|
||||||
|
ri->tgt_index = ifindex;
|
||||||
WRITE_ONCE(ri->map, NULL);
|
WRITE_ONCE(ri->map, NULL);
|
||||||
|
|
||||||
return XDP_REDIRECT;
|
return XDP_REDIRECT;
|
||||||
@ -3753,8 +3753,8 @@ BPF_CALL_3(bpf_xdp_redirect_map, struct bpf_map *, map, u32, ifindex,
|
|||||||
if (unlikely(flags))
|
if (unlikely(flags))
|
||||||
return XDP_ABORTED;
|
return XDP_ABORTED;
|
||||||
|
|
||||||
ri->ifindex = ifindex;
|
|
||||||
ri->flags = flags;
|
ri->flags = flags;
|
||||||
|
ri->tgt_index = ifindex;
|
||||||
WRITE_ONCE(ri->map, map);
|
WRITE_ONCE(ri->map, map);
|
||||||
|
|
||||||
return XDP_REDIRECT;
|
return XDP_REDIRECT;
|
||||||
|
Loading…
Reference in New Issue
Block a user