OSDN Git Service

tools: libbpf: recognize offload neutral maps
authorJakub Kicinski <jakub.kicinski@netronome.com>
Tue, 10 Jul 2018 21:43:01 +0000 (14:43 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 11 Jul 2018 20:13:34 +0000 (22:13 +0200)
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>
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf.h

index 42f31ef..3099230 100644 (file)
@@ -2154,6 +2154,11 @@ void *bpf_map__priv(struct bpf_map *map)
        return map ? map->priv : ERR_PTR(-EINVAL);
 }
 
+bool bpf_map__is_offload_neutral(struct bpf_map *map)
+{
+       return map->def.type == BPF_MAP_TYPE_PERF_EVENT_ARRAY;
+}
+
 void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex)
 {
        map->map_ifindex = ifindex;
@@ -2278,7 +2283,8 @@ int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr,
        }
 
        bpf_map__for_each(map, obj) {
-               map->map_ifindex = attr->ifindex;
+               if (!bpf_map__is_offload_neutral(map))
+                       map->map_ifindex = attr->ifindex;
        }
 
        if (!first_prog) {
index d1ce5c8..749acf5 100644 (file)
@@ -255,6 +255,7 @@ typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *);
 int bpf_map__set_priv(struct bpf_map *map, void *priv,
                      bpf_map_clear_priv_t clear_priv);
 void *bpf_map__priv(struct bpf_map *map);
+bool bpf_map__is_offload_neutral(struct bpf_map *map);
 void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex);
 int bpf_map__pin(struct bpf_map *map, const char *path);