diff options
author | John Fastabend <john.fastabend@gmail.com> | 2017-07-17 12:29:18 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-07-17 12:48:06 -0400 |
commit | 97f91a7cf04ff605845c20948b8a80e54cbd3376 (patch) | |
tree | 0d5c2872667d06e7e2a7f83253505c5170a0258b /kernel/bpf | |
parent | 546ac1ffb70d25b56c1126940e5ec639c4dd7413 (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')
-rw-r--r-- | kernel/bpf/devmap.c | 12 | ||||
-rw-r--r-- | kernel/bpf/verifier.c | 4 |
2 files changed, 16 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 | ||
162 | struct 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. |
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 4016774d5cca..df05d65f0c87 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c | |||
@@ -1312,6 +1312,10 @@ static int check_map_func_compatibility(struct bpf_map *map, int func_id) | |||
1312 | if (map->map_type != BPF_MAP_TYPE_CGROUP_ARRAY) | 1312 | if (map->map_type != BPF_MAP_TYPE_CGROUP_ARRAY) |
1313 | goto error; | 1313 | goto error; |
1314 | break; | 1314 | break; |
1315 | case BPF_FUNC_redirect_map: | ||
1316 | if (map->map_type != BPF_MAP_TYPE_DEVMAP) | ||
1317 | goto error; | ||
1318 | break; | ||
1315 | default: | 1319 | default: |
1316 | break; | 1320 | break; |
1317 | } | 1321 | } |