Skip to content

Commit

Permalink
Use progname instead of progsec throughout
Browse files Browse the repository at this point in the history
Signed-off-by: Donald Hunter <[email protected]>
  • Loading branch information
donaldh committed Mar 3, 2023
1 parent 3485c1e commit 3d9579b
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 45 deletions.
12 changes: 6 additions & 6 deletions advanced03-AF_XDP/af_xdp_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ static const struct option_wrapper long_options[] = {
{{"filename", required_argument, NULL, 1 },
"Load program from <file>", "<file>"},

{{"progsec", required_argument, NULL, 2 },
"Load program in <section> of the ELF file", "<section>"},
{{"progname", required_argument, NULL, 2 },
"Load program from function <name> in the ELF file", "<name>"},

{{0, 0, NULL, 0 }, NULL, false}
};
Expand Down Expand Up @@ -529,7 +529,7 @@ int main(int argc, char **argv)
/* Global shutdown handler */
signal(SIGINT, exit_application);

/* Cmdline options can change progsec */
/* Cmdline options can change progname */
parse_cmdline_args(argc, argv, long_options, &cfg, __doc__);

/* Required option */
Expand All @@ -545,12 +545,12 @@ int main(int argc, char **argv)

custom_xsk = true;
xdp_opts.open_filename = cfg.filename;
xdp_opts.prog_name = cfg.progsec;
xdp_opts.prog_name = cfg.progname;
xdp_opts.opts = &opts;

if (cfg.progsec[0] != 0) {
if (cfg.progname[0] != 0) {
xdp_opts.open_filename = cfg.filename;
xdp_opts.prog_name = cfg.progsec;
xdp_opts.prog_name = cfg.progname;
xdp_opts.opts = &opts;

prog = xdp_program__create(&xdp_opts);
Expand Down
10 changes: 5 additions & 5 deletions basic-solutions/xdp_loader.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
static const char *__doc__ = "XDP loader\n"
" - Allows selecting BPF section --progsec name to XDP-attach to --dev\n";
" - Allows selecting BPF section --progname name to XDP-attach to --dev\n";

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -57,8 +57,8 @@ static const struct option_wrapper long_options[] = {
{{"filename", required_argument, NULL, 1 },
"Load program from <file>", "<file>"},

{{"progsec", required_argument, NULL, 2 },
"Load program in <section> of the ELF file", "<section>"},
{{"progname", required_argument, NULL, 2 },
"Load program from function <name> in the ELF file", "<name>"},

{{0, 0, NULL, 0 }, NULL, false}
};
Expand Down Expand Up @@ -119,7 +119,7 @@ int main(int argc, char **argv)
};
/* Set default BPF-ELF object file and BPF program name */
strncpy(cfg.filename, default_filename, sizeof(cfg.filename));
/* Cmdline options can change progsec */
/* Cmdline options can change progname */
parse_cmdline_args(argc, argv, long_options, &cfg, __doc__);

/* Required option */
Expand Down Expand Up @@ -148,7 +148,7 @@ int main(int argc, char **argv)

if (verbose) {
printf("Success: Loaded BPF-object(%s) and used section(%s)\n",
cfg.filename, cfg.progsec);
cfg.filename, cfg.progname);
printf(" - XDP prog attached on device:%s(ifindex:%d)\n",
cfg.ifname, cfg.ifindex);
}
Expand Down
2 changes: 1 addition & 1 deletion basic-solutions/xdp_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ int main(int argc, char **argv)
.do_unload = false,
};

/* Cmdline options can change progsec */
/* Cmdline options can change progname */
parse_cmdline_args(argc, argv, long_options, &cfg, __doc__);

/* Required option */
Expand Down
12 changes: 6 additions & 6 deletions basic02-prog-by-name/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,24 @@ IPv6 address =fc00:dead:cafe:1::2= (as seen in the script output).
The *assignment* is to manually load the compiled xdp program in the ELF OBJ
file =xdp_prog_kern.o=, using the =xdp_loader= program in this directory.
Observe the available options you can give the xdp_loader via =--help=. Try
to select the program section named =xdp_drop= via =--progsec=, and observe
to select the program section named =xdp_drop= via =--progname=, and observe
via ping that packets gets dropped.

Here are some example commands:
#+begin_example sh
sudo ./xdp_loader --help
sudo ./xdp_loader --dev veth-basic02
sudo ./xdp_loader --dev veth-basic02 --force --progsec xdp_drop
sudo ./xdp_loader --dev veth-basic02 --force --progsec xdp_pass
sudo ./xdp_loader --dev veth-basic02 --force --progname xdp_drop
sudo ./xdp_loader --dev veth-basic02 --force --progname xdp_pass
#+end_example

The testenv script also has a helper command for "load" which will use the
=xdp_loader= program in the current directory:
#+begin_example
sudo ../testenv/testenv.sh load --name veth-basic02
sudo ../testenv/testenv.sh load --name veth-basic02 -- --force
sudo ../testenv/testenv.sh load --name veth-basic02 -- --force --progsec xdp_drop
sudo ../testenv/testenv.sh load --name veth-basic02 -- --force --progsec xdp_pass
sudo ../testenv/testenv.sh load --name veth-basic02 -- --force --progname xdp_drop
sudo ../testenv/testenv.sh load --name veth-basic02 -- --force --progname xdp_pass
#+end_example

*** A note about: The test environment and veth packets directions
Expand Down Expand Up @@ -177,7 +177,7 @@ Add a new program section "xdp_abort" in [[file:xdp_prog_kern.c]] that uses
new program, e.g. similar to above:

#+begin_example sh
sudo ./xdp_loader --dev veth-basic02 --force --progsec xdp_abort
sudo ./xdp_loader --dev veth-basic02 --force --progname xdp_abort
#+end_example

*Lesson*: XDP_ABORTED is different from XDP_DROP, because it triggers the
Expand Down
16 changes: 9 additions & 7 deletions basic02-prog-by-name/xdp_loader.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 */
static const char *__doc__ = "XDP loader\n"
" - Specify BPF-object --filename to load \n"
" - and select BPF section --progsec name to XDP-attach to --dev\n";
" - and select BPF section --progname name to XDP-attach to --dev\n";

#include <stdio.h>
#include <stdlib.h>
Expand All @@ -19,7 +19,7 @@ static const char *__doc__ = "XDP loader\n"
#include "../common/common_params.h"

static const char *default_filename = "xdp_prog_kern.o";
static const char *default_progsec = "xdp_pass_func";
static const char *default_progname = "xdp_pass_func";

static const struct option_wrapper long_options[] = {
{{"help", no_argument, NULL, 'h' },
Expand Down Expand Up @@ -52,8 +52,8 @@ static const struct option_wrapper long_options[] = {
{{"filename", required_argument, NULL, 1 },
"Load program from <file>", "<file>"},

{{"progsec", required_argument, NULL, 2 },
"Load program in <section> of the ELF file", "<section>"},
{{"progname", required_argument, NULL, 2 },
"Load program from function <name> in the ELF file", "<name>"},

{{0, 0, NULL, 0 }, NULL, false}
};
Expand All @@ -75,7 +75,7 @@ struct xdp_program *__load_bpf_and_xdp_attach(struct config *cfg)
DECLARE_LIBXDP_OPTS(xdp_program_opts, xdp_opts, 0);

xdp_opts.open_filename = cfg->filename;
xdp_opts.prog_name = cfg->progsec;
xdp_opts.prog_name = cfg->progname;
xdp_opts.opts = &opts;

/* If flags indicate hardware offload, supply ifindex */
Expand Down Expand Up @@ -122,6 +122,8 @@ static void list_avail_progs(struct bpf_object *obj)
bpf_object__name(obj));

bpf_object__for_each_program(pos, obj) {
printf("*** %s\n", bpf_program__name(pos));
printf("*** %d\n", bpf_program__type(pos));
if (bpf_program__type(pos) == BPF_PROG_TYPE_XDP)
printf(" %s\n", bpf_program__name(pos));
}
Expand All @@ -136,7 +138,7 @@ int main(int argc, char **argv)
};
/* Set default BPF-ELF object file and BPF program name */
strncpy(cfg.filename, default_filename, sizeof(cfg.filename));
strncpy(cfg.progsec, default_progsec, sizeof(cfg.progsec));
strncpy(cfg.progname, default_progname, sizeof(cfg.progname));
/* Cmdline options can change these */
parse_cmdline_args(argc, argv, long_options, &cfg, __doc__);

Expand All @@ -158,7 +160,7 @@ int main(int argc, char **argv)

if (verbose) {
printf("Success: Loaded BPF-object(%s) and used section(%s)\n",
cfg.filename, cfg.progsec);
cfg.filename, cfg.progname);
printf(" - XDP prog attached on device:%s(ifindex:%d)\n",
cfg.ifname, cfg.ifindex);
}
Expand Down
10 changes: 5 additions & 5 deletions basic03-map-counter/xdp_load_and_stats.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
static const char *__doc__ = "XDP loader and stats program\n"
" - Allows selecting BPF section --progsec name to XDP-attach to --dev\n";
" - Allows selecting BPF section --progname name to XDP-attach to --dev\n";

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -54,8 +54,8 @@ static const struct option_wrapper long_options[] = {
{{"filename", required_argument, NULL, 1 },
"Load program from <file>", "<file>"},

{{"progsec", required_argument, NULL, 2 },
"Load program in <section> of the ELF file", "<section>"},
{{"progname", required_argument, NULL, 2 },
"Load program from function <name> in the ELF file", "<name>"},

{{0, 0, NULL, 0 }}
};
Expand Down Expand Up @@ -283,7 +283,7 @@ int main(int argc, char **argv)
};
/* Set default BPF-ELF object file and BPF program name */
strncpy(cfg.filename, default_filename, sizeof(cfg.filename));
strncpy(cfg.progsec, default_progname, sizeof(cfg.progsec));
strncpy(cfg.progname, default_progname, sizeof(cfg.progname));
/* Cmdline options can change progname */
parse_cmdline_args(argc, argv, long_options, &cfg, __doc__);

Expand All @@ -302,7 +302,7 @@ int main(int argc, char **argv)

if (verbose) {
printf("Success: Loaded BPF-object(%s) and used section(%s)\n",
cfg.filename, cfg.progsec);
cfg.filename, cfg.progname);
printf(" - XDP prog attached on device:%s(ifindex:%d)\n",
cfg.ifname, cfg.ifindex);
}
Expand Down
10 changes: 5 additions & 5 deletions basic04-pinning-maps/xdp_loader.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
static const char *__doc__ = "XDP loader\n"
" - Allows selecting BPF section --progsec name to XDP-attach to --dev\n";
" - Allows selecting BPF section --progname name to XDP-attach to --dev\n";

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -55,8 +55,8 @@ static const struct option_wrapper long_options[] = {
{{"filename", required_argument, NULL, 1 },
"Load program from <file>", "<file>"},

{{"progsec", required_argument, NULL, 2 },
"Load program in <section> of the ELF file", "<section>"},
{{"progname", required_argument, NULL, 2 },
"Load program from function <name> in the ELF file", "<name>"},

{{0, 0, NULL, 0 }, NULL, false}
};
Expand Down Expand Up @@ -124,7 +124,7 @@ int main(int argc, char **argv)
};
/* Set default BPF-ELF object file and BPF program name */
strncpy(cfg.filename, default_filename, sizeof(cfg.filename));
/* Cmdline options can change progsec */
/* Cmdline options can change progname */
parse_cmdline_args(argc, argv, long_options, &cfg, __doc__);

/* Required option */
Expand All @@ -144,7 +144,7 @@ int main(int argc, char **argv)

if (verbose) {
printf("Success: Loaded BPF-object(%s) and used section(%s)\n",
cfg.filename, cfg.progsec);
cfg.filename, cfg.progname);
printf(" - XDP prog attached on device:%s(ifindex:%d)\n",
cfg.ifname, cfg.ifindex);
}
Expand Down
2 changes: 1 addition & 1 deletion basic04-pinning-maps/xdp_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ int main(int argc, char **argv)
.do_unload = false,
};

/* Cmdline options can change progsec */
/* Cmdline options can change progname */
parse_cmdline_args(argc, argv, long_options, &cfg, __doc__);

/* Required option */
Expand Down
2 changes: 1 addition & 1 deletion common/common_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct config {
bool reuse_maps;
char pin_dir[512];
char filename[512];
char progsec[32];
char progname[32];
char src_mac[18];
char dest_mac[18];
__u16 xsk_bind_flags;
Expand Down
6 changes: 3 additions & 3 deletions common/common_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ void parse_cmdline_args(int argc, char **argv,
dest = (char *)&cfg->filename;
strncpy(dest, optarg, sizeof(cfg->filename));
break;
case 2: /* --progsec */
dest = (char *)&cfg->progsec;
strncpy(dest, optarg, sizeof(cfg->progsec));
case 2: /* --progname */
dest = (char *)&cfg->progname;
strncpy(dest, optarg, sizeof(cfg->progname));
break;
case 'L': /* --src-mac */
dest = (char *)&cfg->src_mac;
Expand Down
2 changes: 1 addition & 1 deletion common/common_user_bpf_xdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct xdp_program *load_bpf_and_xdp_attach(struct config *cfg)
DECLARE_LIBXDP_OPTS(xdp_program_opts, xdp_opts, 0);

xdp_opts.open_filename = cfg->filename;
xdp_opts.prog_name = cfg->progsec;
xdp_opts.prog_name = cfg->progname;
xdp_opts.opts = &opts;

/* If flags indicate hardware offload, supply ifindex */
Expand Down
2 changes: 1 addition & 1 deletion packet-solutions/xdp_prog_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ int main(int argc, char **argv)
.redirect_ifindex = -1,
};

/* Cmdline options can change progsec */
/* Cmdline options can change progname */
parse_cmdline_args(argc, argv, long_options, &cfg, __doc__);

redirect_map = (cfg.ifindex > 0) && (cfg.redirect_ifindex > 0);
Expand Down
4 changes: 2 additions & 2 deletions tracing01-xdp-simple/trace_load_and_stats.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
static const char *__doc__ = "XDP loader and stats program\n"
" - Allows selecting BPF section --progsec name to XDP-attach to --dev\n";
" - Allows selecting BPF section --progname name to XDP-attach to --dev\n";

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -238,7 +238,7 @@ int main(int argc, char **argv)
/* Set default BPF-ELF object file and BPF program name */
strncpy(cfg.filename, default_filename, sizeof(cfg.filename));

/* Cmdline options can change progsec */
/* Cmdline options can change progname */
parse_cmdline_args(argc, argv, long_options, &cfg, __doc__);

bpf_obj = load_bpf_and_trace_attach(&cfg);
Expand Down
2 changes: 1 addition & 1 deletion tracing02-xdp-monitor/trace_load_and_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ int main(int argc, char **argv)
/* Set default BPF-ELF object file and BPF program name */
strncpy(cfg.filename, default_filename, sizeof(cfg.filename));

/* Cmdline options can change progsec */
/* Cmdline options can change progname */
parse_cmdline_args(argc, argv, long_options, &cfg, __doc__);

bpf_obj = load_bpf_and_trace_attach(&cfg);
Expand Down

0 comments on commit 3d9579b

Please sign in to comment.