Skip to content

Commit 9aba361

Browse files
Jakub Kicinskiborkmann
authored andcommitted
tools: libbpf: allow setting ifindex for programs and maps
Users of bpf_object__open()/bpf_object__load() APIs may want to load the programs and maps onto a device for offload. Allow setting ifindex on those sub-objects. 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>
1 parent d9b683d commit 9aba361

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,11 @@ void *bpf_program__priv(struct bpf_program *prog)
18961896
return prog ? prog->priv : ERR_PTR(-EINVAL);
18971897
}
18981898

1899+
void bpf_program__set_ifindex(struct bpf_program *prog, __u32 ifindex)
1900+
{
1901+
prog->prog_ifindex = ifindex;
1902+
}
1903+
18991904
const char *bpf_program__title(struct bpf_program *prog, bool needs_copy)
19001905
{
19011906
const char *title;
@@ -2122,6 +2127,11 @@ void *bpf_map__priv(struct bpf_map *map)
21222127
return map ? map->priv : ERR_PTR(-EINVAL);
21232128
}
21242129

2130+
void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex)
2131+
{
2132+
map->map_ifindex = ifindex;
2133+
}
2134+
21252135
struct bpf_map *
21262136
bpf_map__next(struct bpf_map *prev, struct bpf_object *obj)
21272137
{

tools/lib/bpf/libbpf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ int bpf_program__set_priv(struct bpf_program *prog, void *priv,
109109
bpf_program_clear_priv_t clear_priv);
110110

111111
void *bpf_program__priv(struct bpf_program *prog);
112+
void bpf_program__set_ifindex(struct bpf_program *prog, __u32 ifindex);
112113

113114
const char *bpf_program__title(struct bpf_program *prog, bool needs_copy);
114115

@@ -251,6 +252,7 @@ typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *);
251252
int bpf_map__set_priv(struct bpf_map *map, void *priv,
252253
bpf_map_clear_priv_t clear_priv);
253254
void *bpf_map__priv(struct bpf_map *map);
255+
void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex);
254256
int bpf_map__pin(struct bpf_map *map, const char *path);
255257

256258
long libbpf_get_error(const void *ptr);

0 commit comments

Comments
 (0)