aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf
diff options
context:
space:
mode:
authorJakub Kicinski <jakub.kicinski@netronome.com>2018-07-10 17:43:01 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-07-11 16:13:34 -0400
commitf83fb22c6c68fdbc98c76291c9e12a40d1eb7ca5 (patch)
treebdc78c13ca85d09e11c41eea4a8239b219e6f391 /tools/lib/bpf
parent49f2cba3e57a4d71e3e7001cc2934b563ee495f4 (diff)
tools: libbpf: recognize offload neutral maps
Add helper to libbpf for recognizing maps which should not have ifindex set when program is loaded. These maps only contain host metadata and therefore are not marked for offload, e.g. the perf event map. Use this helper in bpf_prog_load_xattr(). Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/lib/bpf')
-rw-r--r--tools/lib/bpf/libbpf.c8
-rw-r--r--tools/lib/bpf/libbpf.h1
2 files changed, 8 insertions, 1 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 42f31eff5f3f..30992305f4c1 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -2154,6 +2154,11 @@ void *bpf_map__priv(struct bpf_map *map)
2154 return map ? map->priv : ERR_PTR(-EINVAL); 2154 return map ? map->priv : ERR_PTR(-EINVAL);
2155} 2155}
2156 2156
2157bool bpf_map__is_offload_neutral(struct bpf_map *map)
2158{
2159 return map->def.type == BPF_MAP_TYPE_PERF_EVENT_ARRAY;
2160}
2161
2157void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex) 2162void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex)
2158{ 2163{
2159 map->map_ifindex = ifindex; 2164 map->map_ifindex = ifindex;
@@ -2278,7 +2283,8 @@ int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr,
2278 } 2283 }
2279 2284
2280 bpf_map__for_each(map, obj) { 2285 bpf_map__for_each(map, obj) {
2281 map->map_ifindex = attr->ifindex; 2286 if (!bpf_map__is_offload_neutral(map))
2287 map->map_ifindex = attr->ifindex;
2282 } 2288 }
2283 2289
2284 if (!first_prog) { 2290 if (!first_prog) {
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index d1ce5c828e2e..749acf58a5da 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -255,6 +255,7 @@ typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *);
255int bpf_map__set_priv(struct bpf_map *map, void *priv, 255int bpf_map__set_priv(struct bpf_map *map, void *priv,
256 bpf_map_clear_priv_t clear_priv); 256 bpf_map_clear_priv_t clear_priv);
257void *bpf_map__priv(struct bpf_map *map); 257void *bpf_map__priv(struct bpf_map *map);
258bool bpf_map__is_offload_neutral(struct bpf_map *map);
258void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex); 259void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex);
259int bpf_map__pin(struct bpf_map *map, const char *path); 260int bpf_map__pin(struct bpf_map *map, const char *path);
260 261