Skip to content

Commit

Permalink
new: introduce flag to explicitly do not detach/destroy TC hook and p…
Browse files Browse the repository at this point in the history
…rogram at the exit

Signed-off-by: Leonardo Di Donato <[email protected]>
  • Loading branch information
leodido committed Jun 1, 2022
1 parent f4e70fd commit 7d8ab75
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions traffico.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ const char OPT_IFNAME_ARG[] = "IFNAME";
const char OPT_ATTACH_LONG[] = "at";
#define OPT_ATTACH_KEY 0x80
const char OPT_ATTACH_ARG[] = "INGRESS|EGRESS";
#define OPT_NO_CLEANUP_KEY 0x81
const char OPT_NO_CLEANUP_LONG[] = "no-cleanup";

const struct argp_option argp_opts[] = {

{"OPTIONS", 0, 0, OPTION_DOC, 0, 0},
{OPT_VERBOSE_LONG, OPT_VERBOSE_KEY, NULL, 0, "Verbose debug output", -1},
{OPT_IFNAME_LONG, OPT_IFNAME_KEY, OPT_IFNAME_ARG, 0, "Interface to which to attach the filter\n(defaults to the default gateway interface)", 1},
{OPT_ATTACH_LONG, OPT_ATTACH_KEY, OPT_ATTACH_ARG, 0, "Where to attach the filter (defaults to egress)", 1},
{OPT_NO_CLEANUP_LONG, OPT_NO_CLEANUP_KEY, NULL, 0, "Do not detach the TC hook and filter at the exit", 1},
{"", 0, 0, OPTION_DOC, 0, 0},
{0} // .

Expand Down Expand Up @@ -89,6 +92,9 @@ static error_t parse_cli(int key, char *arg, struct argp_state *state)
argp_error(state, "option '--%s' requires one of the following values: %s", OPT_ATTACH_LONG, OPT_ATTACH_ARG);
}
break;
case OPT_NO_CLEANUP_KEY:
g_config.cleanup_on_exit = false;
break;

// Arguments
case ARGP_KEY_ARG:
Expand Down Expand Up @@ -205,22 +211,7 @@ int await(struct bpf_tc_hook hook, struct bpf_tc_opts opts)
}
fprintf(stdout, "\n");

// Detach the TC hook
int err;
char buf[100];
buf[sizeof(buf) - 1] = '\0';

opts.prog_fd = opts.prog_id = 0;
opts.flags = 0;
err = bpf_tc_detach(&hook, &opts);
if (err)
{
libbpf_strerror(err, buf, sizeof(buf));
log_erro("fail: detaching the TC eBPF program: %s\n", buf);
}
log_info("done: detaching the TC eBPF program\n");

return err < 0 ? -err : err;
return 0;
}

int main(int argc, char **argv)
Expand Down

0 comments on commit 7d8ab75

Please sign in to comment.