Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
74fc097
Documentation
LICENSES
arch
block
certs
crypto
drivers
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
accounting
arch
bootconfig
bpf
bpftool
Documentation
bash-completion
skeleton
.gitignore
Makefile
btf.c
btf_dumper.c
cfg.c
cfg.h
cgroup.c
common.c
feature.c
gen.c
iter.c
jit_disasm.c
json_writer.c
json_writer.h
link.c
main.c
main.h
map.c
map_perf_ring.c
net.c
netlink_dumper.c
netlink_dumper.h
perf.c
pids.c
prog.c
struct_ops.c
tracelog.c
xlated_dumper.c
xlated_dumper.h
resolve_btfids
runqslower
.gitignore
Makefile
Makefile.helpers
bpf_asm.c
bpf_dbg.c
bpf_exp.l
bpf_exp.y
bpf_jit_disasm.c
build
cgroup
debugging
edid
firewire
firmware
gpio
hv
iio
include
io_uring
kvm
laptop
leds
lib
memory-model
nfsd
objtool
pci
pcmcia
perf
power
scripts
spi
testing
thermal
time
usb
virtio
vm
wmi
Makefile
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
tools
/
bpf
/
bpftool
/
iter.c
Blame
Blame
Latest commit
History
History
116 lines (96 loc) · 2.18 KB
Breadcrumbs
linux
/
tools
/
bpf
/
bpftool
/
iter.c
Top
File metadata and controls
Code
Blame
116 lines (96 loc) · 2.18 KB
Raw
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) // Copyright (C) 2020 Facebook #define _GNU_SOURCE #include <unistd.h> #include <linux/err.h> #include <bpf/libbpf.h> #include "main.h" static int do_pin(int argc, char **argv) { DECLARE_LIBBPF_OPTS(bpf_iter_attach_opts, iter_opts); union bpf_iter_link_info linfo; const char *objfile, *path; struct bpf_program *prog; struct bpf_object *obj; struct bpf_link *link; int err = -1, map_fd = -1; if (!REQ_ARGS(2)) usage(); objfile = GET_ARG(); path = GET_ARG(); /* optional arguments */ if (argc) { if (is_prefix(*argv, "map")) { NEXT_ARG(); if (!REQ_ARGS(2)) { p_err("incorrect map spec"); return -1; } map_fd = map_parse_fd(&argc, &argv); if (map_fd < 0) return -1; memset(&linfo, 0, sizeof(linfo)); linfo.map.map_fd = map_fd; iter_opts.link_info = &linfo; iter_opts.link_info_len = sizeof(linfo); } } obj = bpf_object__open(objfile); if (IS_ERR(obj)) { p_err("can't open objfile %s", objfile); goto close_map_fd; } err = bpf_object__load(obj); if (err) { p_err("can't load objfile %s", objfile); goto close_obj; } prog = bpf_program__next(NULL, obj); if (!prog) { p_err("can't find bpf program in objfile %s", objfile); goto close_obj; } link = bpf_program__attach_iter(prog, &iter_opts); if (IS_ERR(link)) { err = PTR_ERR(link); p_err("attach_iter failed for program %s", bpf_program__name(prog)); goto close_obj; } err = mount_bpffs_for_pin(path); if (err) goto close_link; err = bpf_link__pin(link, path); if (err) { p_err("pin_iter failed for program %s to path %s", bpf_program__name(prog), path); goto close_link; } close_link: bpf_link__destroy(link); close_obj: bpf_object__close(obj); close_map_fd: if (map_fd >= 0) close(map_fd); return err; } static int do_help(int argc, char **argv) { fprintf(stderr, "Usage: %1$s %2$s pin OBJ PATH [map MAP]\n" " %1$s %2$s help\n" " " HELP_SPEC_MAP "\n" "", bin_name, "iter"); return 0; } static const struct cmd cmds[] = { { "help", do_help }, { "pin", do_pin }, { 0 } }; int do_iter(int argc, char **argv) { return cmd_select(cmds, argc, argv, do_help); }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
You can’t perform that action at this time.