Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
tcp_cong_tuner: various fixes found for Ubuntu issues
module load was failing as we need CAP_SYS_MODULE, and as a
result the tcp_bbr module wasnt loading
also needed to search in /lib/module/`uname -r`
needed to add capabilities around attach and fix error handling
when link was not attached

Signed-off-by: Alan Maguire <[email protected]>
  • Loading branch information
alan-maguire committed Jul 6, 2023
commit d56799332e3df53a086d5f68efc6dad5f5cf136a
3 changes: 2 additions & 1 deletion src/libbpftune.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ static const cap_value_t cap_vector[] = {
CAP_SYS_ADMIN,
CAP_NET_ADMIN,
CAP_SYS_CHROOT,
CAP_SYS_MODULE,
CAP_SYSLOG
};

Expand Down Expand Up @@ -1446,7 +1447,7 @@ static int bpftune_module_path(const char *name, char *modpath, size_t pathsz)
bpftune_log(LOG_DEBUG, "uname failed: %s\n", strerror(ret));
return ret;
}
snprintf(modpath, pathsz, "/usr/lib/modules/%s/kernel/%s",
snprintf(modpath, pathsz, "/lib/modules/%s/kernel/%s",
utsname.release, name);
return 0;
}
Expand Down
21 changes: 15 additions & 6 deletions src/tcp_cong_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,40 @@ int init(struct bpftuner *tuner)

bpftuner_bpf_init(tcp_cong, tuner, NULL);

err = bpftune_cap_add();
if (err) {
bpftune_log(LOG_ERR, "cannot add caps: %s\n", strerror(-err));
return 1;
}

if (tuner->bpf_legacy) {

/* attach to root cgroup */
if (bpftuner_cgroup_attach(tuner, "cong_tuner_sockops", BPF_CGROUP_SOCK_OPS))
return 1;
goto error;
} else {
struct bpf_link *link;

skel = tuner->skel;
link = bpf_program__attach_iter(skel->progs.bpftune_cong_iter, NULL);
if (!link) {
if (libbpf_get_error(link)) {
bpftune_log(LOG_ERR, "cannot attach iter : %s\n",
strerror(errno));
return 1;
strerror(libbpf_get_error(link)));
goto error;
}
tcp_iter_fd = bpf_iter_create(bpf_link__fd(link));
if (tcp_iter_fd < 0) {
bpftune_log(LOG_ERR, "cannot create iter fd: %s\n",
strerror(errno));
return 1;
goto error;
}
}

return bpftuner_tunables_init(tuner, ARRAY_SIZE(descs), descs,
ARRAY_SIZE(scenarios), scenarios);
error:
bpftune_cap_drop();
return 1;
}

void fini(struct bpftuner *tuner)
Expand Down Expand Up @@ -110,7 +119,7 @@ void event_handler(struct bpftuner *tuner, struct bpftune_event *event,
if (!tuner->bpf_legacy) {
if (!bpftune_cap_add()) {
/* kick existing connections by running iter over them... */
while (read(tcp_iter_fd, &iterbuf, sizeof(iterbuf)) == -1 && errno == EAGAIN) {}
while (read(tcp_iter_fd, &iterbuf, sizeof(iterbuf)) > 0 || errno == EAGAIN) {}

bpftune_cap_drop();
}
Expand Down