bpf: sockmap, add sample option to test apply_bytes helper
This adds an option to test the apply_bytes helper. This option lets the user specify an int on the command line specifying how much data each verdict should apply to. When this is set a map entry is set with the bytes input by the user and then the specified program --txmsg or --txmsg_redir will use the value and set the applied data. If no other option is set then a default --txmsg_apply program is run. This program will drop pkts if an error is detected on the bytes map lookup. Useful to verify the map lookup and apply helper are working and causing a hard error if it is not. Signed-off-by: John Fastabend <john.fastabend@gmail.com> Acked-by: David S. Miller <davem@davemloft.net> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:

committed by
Daniel Borkmann

parent
6bce9d2ca6
commit
1c16c3126a
@@ -59,6 +59,7 @@ int txmsg_pass;
|
||||
int txmsg_noisy;
|
||||
int txmsg_redir;
|
||||
int txmsg_redir_noisy;
|
||||
int txmsg_apply;
|
||||
|
||||
static const struct option long_options[] = {
|
||||
{"help", no_argument, NULL, 'h' },
|
||||
@@ -73,6 +74,7 @@ static const struct option long_options[] = {
|
||||
{"txmsg_noisy", no_argument, &txmsg_noisy, 1 },
|
||||
{"txmsg_redir", no_argument, &txmsg_redir, 1 },
|
||||
{"txmsg_redir_noisy", no_argument, &txmsg_redir_noisy, 1},
|
||||
{"txmsg_apply", required_argument, NULL, 'a'},
|
||||
{0, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
@@ -546,7 +548,9 @@ int main(int argc, char **argv)
|
||||
while ((opt = getopt_long(argc, argv, ":dhvc:r:i:l:t:",
|
||||
long_options, &longindex)) != -1) {
|
||||
switch (opt) {
|
||||
/* Cgroup configuration */
|
||||
case 'a':
|
||||
txmsg_apply = atoi(optarg);
|
||||
break;
|
||||
case 'c':
|
||||
cg_fd = open(optarg, O_DIRECTORY, O_RDONLY);
|
||||
if (cg_fd < 0) {
|
||||
@@ -665,6 +669,8 @@ run:
|
||||
tx_prog_fd = prog_fd[5];
|
||||
else if (txmsg_redir_noisy)
|
||||
tx_prog_fd = prog_fd[6];
|
||||
else if (txmsg_apply)
|
||||
tx_prog_fd = prog_fd[7];
|
||||
else
|
||||
tx_prog_fd = 0;
|
||||
|
||||
@@ -699,6 +705,17 @@ run:
|
||||
err, strerror(errno));
|
||||
return err;
|
||||
}
|
||||
|
||||
if (txmsg_apply) {
|
||||
err = bpf_map_update_elem(map_fd[3],
|
||||
&i, &txmsg_apply, BPF_ANY);
|
||||
if (err) {
|
||||
fprintf(stderr,
|
||||
"ERROR: bpf_map_update_elem (apply_bytes): %d (%s\n",
|
||||
err, strerror(errno));
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (test == PING_PONG)
|
||||
err = forever_ping_pong(rate, &options);
|
||||
|
Reference in New Issue
Block a user