aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/devmap.c
diff options
context:
space:
mode:
authorJohn Fastabend <john.fastabend@gmail.com>2017-07-17 12:29:18 -0400
committerDavid S. Miller <davem@davemloft.net>2017-07-17 12:48:06 -0400
commit97f91a7cf04ff605845c20948b8a80e54cbd3376 (patch)
tree0d5c2872667d06e7e2a7f83253505c5170a0258b /kernel/bpf/devmap.c
parent546ac1ffb70d25b56c1126940e5ec639c4dd7413 (diff)
bpf: add bpf_redirect_map helper routine
BPF programs can use the devmap with a bpf_redirect_map() helper routine to forward packets to netdevice in map. Signed-off-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel/bpf/devmap.c')
-rw-r--r--kernel/bpf/devmap.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index 1a878356bd37..36dc13deb2e1 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -159,6 +159,18 @@ static int dev_map_get_next_key(struct bpf_map *map, void *key, void *next_key)
159 return 0; 159 return 0;
160} 160}
161 161
162struct net_device *__dev_map_lookup_elem(struct bpf_map *map, u32 key)
163{
164 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map);
165 struct bpf_dtab_netdev *dev;
166
167 if (key >= map->max_entries)
168 return NULL;
169
170 dev = READ_ONCE(dtab->netdev_map[key]);
171 return dev ? dev->dev : NULL;
172}
173
162/* rcu_read_lock (from syscall and BPF contexts) ensures that if a delete and/or 174/* rcu_read_lock (from syscall and BPF contexts) ensures that if a delete and/or
163 * update happens in parallel here a dev_put wont happen until after reading the 175 * update happens in parallel here a dev_put wont happen until after reading the
164 * ifindex. 176 * ifindex.