diff options
author | Julia Kartseva <hex@fb.com> | 2021-02-04 09:02:07 +0100 |
---|---|---|
committer | Julia Kartseva <hex@fb.com> | 2021-04-10 05:28:47 +0200 |
commit | 9984f4933b7d1310c6fd24c8d90878d66a5d19d9 (patch) | |
tree | 30c388cb6d9fefaabe2e19d45ae9af2cf80261c4 /src/shared/bpf-program.c | |
parent | shared: add bpf-program helpers (diff) | |
download | systemd-9984f4933b7d1310c6fd24c8d90878d66a5d19d9.tar.xz systemd-9984f4933b7d1310c6fd24c8d90878d66a5d19d9.zip |
shared: bpf_attach_type {from,to} string
Introduce bpf_cgroup_attach_type_table with accustomed attached type
names also used in bpftool.
Add bpf_cgroup_attach_type_{from|to}_string helpers to convert from|to
string representation of pinned bpf program, e.g.
"egress:/sys/fs/bpf/egress-hook" for
/sys/fs/bpf/egress-hook path and BPF_CGROUP_INET_EGRESS attach type.
Diffstat (limited to 'src/shared/bpf-program.c')
-rw-r--r-- | src/shared/bpf-program.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/shared/bpf-program.c b/src/shared/bpf-program.c index d67ada23b0..a8a34521fd 100644 --- a/src/shared/bpf-program.c +++ b/src/shared/bpf-program.c @@ -11,6 +11,30 @@ #include "memory-util.h" #include "missing_syscall.h" #include "path-util.h" +#include "string-table.h" + +static const char *const bpf_cgroup_attach_type_table[__MAX_BPF_ATTACH_TYPE] = { + [BPF_CGROUP_INET_INGRESS] = "ingress", + [BPF_CGROUP_INET_EGRESS] = "egress", + [BPF_CGROUP_INET_SOCK_CREATE] = "sock_create", + [BPF_CGROUP_SOCK_OPS] = "sock_ops", + [BPF_CGROUP_DEVICE] = "device", + [BPF_CGROUP_INET4_BIND] = "bind4", + [BPF_CGROUP_INET6_BIND] = "bind6", + [BPF_CGROUP_INET4_CONNECT] = "connect4", + [BPF_CGROUP_INET6_CONNECT] = "connect6", + [BPF_CGROUP_INET4_POST_BIND] = "post_bind4", + [BPF_CGROUP_INET6_POST_BIND] = "post_bind6", + [BPF_CGROUP_UDP4_SENDMSG] = "sendmsg4", + [BPF_CGROUP_UDP6_SENDMSG] = "sendmsg6", + [BPF_CGROUP_SYSCTL] = "sysctl", + [BPF_CGROUP_UDP4_RECVMSG] = "recvmsg4", + [BPF_CGROUP_UDP6_RECVMSG] = "recvmsg6", + [BPF_CGROUP_GETSOCKOPT] = "getsockopt", + [BPF_CGROUP_SETSOCKOPT] = "setsockopt", +}; + +DEFINE_STRING_TABLE_LOOKUP(bpf_cgroup_attach_type, int); /* struct bpf_prog_info info must be initialized since its value is both input and output * for BPF_OBJ_GET_INFO_BY_FD syscall. */ |