Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a8e8c0ec authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'bpftool-add-a-version-command-and-fix-several-items'



Jakub Kicinski says:

====================
tools: bpftool: add a "version" command, and fix several items

Quentin says:

The first seven patches of this series bring several minor fixes to
bpftool. Please see individual commit logs for details.

Last patch adds a "version" commands to bpftool, which is in fact the
version of the kernel from which it was compiled.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents f3ae608e 821cfbb0
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -11,8 +11,8 @@ SYNOPSIS
========

|	**bpftool** prog show [*PROG*]
|	**bpftool** prog dump xlated *PROG* [file *FILE*] [opcodes]
|	**bpftool** prog dump jited  *PROG* [file *FILE*] [opcodes]
|	**bpftool** prog dump xlated *PROG* [{file *FILE* | opcodes }]
|	**bpftool** prog dump jited  *PROG* [{file *FILE* | opcodes }]
|	**bpftool** prog pin *PROG* *FILE*
|	**bpftool** prog help
|
@@ -28,14 +28,14 @@ DESCRIPTION
		  Output will start with program ID followed by program type and
		  zero or more named attributes (depending on kernel version).

	**bpftool prog dump xlated** *PROG* [**file** *FILE*] [**opcodes**]
	**bpftool prog dump xlated** *PROG* [{ **file** *FILE* | **opcodes** }]
		  Dump eBPF instructions of the program from the kernel.
		  If *FILE* is specified image will be written to a file,
		  otherwise it will be disassembled and printed to stdout.

		  **opcodes** controls if raw opcodes will be printed.

	**bpftool prog dump jited**  *PROG* [**file** *FILE*] [**opcodes**]
	**bpftool prog dump jited**  *PROG* [{ **file** *FILE* | **opcodes** }]
		  Dump jited image (host machine code) of the program.
		  If *FILE* is specified image will be written to a file,
		  otherwise it will be disassembled and printed to stdout.
+2 −0
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@ SYNOPSIS

	**bpftool** batch file *FILE*

	**bpftool** version

	*OBJECT* := { **map** | **program** }

	*MAP-COMMANDS* :=
+17 −5
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
#include <ctype.h>
#include <errno.h>
#include <linux/bpf.h>
#include <linux/version.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -62,13 +63,23 @@ static int do_help(int argc, char **argv)
	fprintf(stderr,
		"Usage: %s OBJECT { COMMAND | help }\n"
		"       %s batch file FILE\n"
		"       %s version\n"
		"\n"
		"       OBJECT := { prog | map }\n",
		bin_name, bin_name);
		bin_name, bin_name, bin_name);

	return 0;
}

static int do_version(int argc, char **argv)
{
	printf("%s v%d.%d.%d\n", bin_name,
	       LINUX_VERSION_CODE >> 16,
	       LINUX_VERSION_CODE >> 8 & 0xf,
	       LINUX_VERSION_CODE & 0xf);
	return 0;
}

int cmd_select(const struct cmd *cmds, int argc, char **argv,
	       int (*help)(int argc, char **argv))
{
@@ -100,7 +111,7 @@ bool is_prefix(const char *pfx, const char *str)
	return !memcmp(str, pfx, strlen(pfx));
}

void print_hex(void *arg, unsigned int n, const char *sep)
void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep)
{
	unsigned char *data = arg;
	unsigned int i;
@@ -111,13 +122,13 @@ void print_hex(void *arg, unsigned int n, const char *sep)
		if (!i)
			/* nothing */;
		else if (!(i % 16))
			printf("\n");
			fprintf(f, "\n");
		else if (!(i % 8))
			printf("  ");
			fprintf(f, "  ");
		else
			pfx = sep;

		printf("%s%02hhx", i ? pfx : "", data[i]);
		fprintf(f, "%s%02hhx", i ? pfx : "", data[i]);
	}
}

@@ -128,6 +139,7 @@ static const struct cmd cmds[] = {
	{ "batch",	do_batch },
	{ "prog",	do_prog },
	{ "map",	do_map },
	{ "version",	do_version },
	{ 0 }
};

+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ enum bpf_obj_type {
extern const char *bin_name;

bool is_prefix(const char *pfx, const char *str);
void print_hex(void *arg, unsigned int n, const char *sep);
void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep);
void usage(void) __attribute__((noreturn));

struct cmd {
+11 −11
Original line number Diff line number Diff line
@@ -216,12 +216,12 @@ static void print_entry(struct bpf_map_info *info, unsigned char *key,
			!break_names;

		printf("key:%c", break_names ? '\n' : ' ');
		print_hex(key, info->key_size, " ");
		fprint_hex(stdout, key, info->key_size, " ");

		printf(single_line ? "  " : "\n");

		printf("value:%c", break_names ? '\n' : ' ');
		print_hex(value, info->value_size, " ");
		fprint_hex(stdout, value, info->value_size, " ");

		printf("\n");
	} else {
@@ -230,12 +230,12 @@ static void print_entry(struct bpf_map_info *info, unsigned char *key,
		n = get_possible_cpus();

		printf("key:\n");
		print_hex(key, info->key_size, " ");
		fprint_hex(stdout, key, info->key_size, " ");
		printf("\n");
		for (i = 0; i < n; i++) {
			printf("value (CPU %02d):%c",
			       i, info->value_size > 16 ? '\n' : ' ');
			print_hex(value + i * info->value_size,
			fprint_hex(stdout, value + i * info->value_size,
				   info->value_size, " ");
			printf("\n");
		}
@@ -252,7 +252,7 @@ static char **parse_bytes(char **argv, const char *name, unsigned char *val,
		val[i] = strtoul(argv[i], &endptr, 0);
		if (*endptr) {
			err("error parsing byte: %s\n", argv[i]);
			break;
			return NULL;
		}
		i++;
	}
@@ -492,8 +492,8 @@ static int do_dump(int argc, char **argv)
			print_entry(&info, key, value);
		} else {
			info("can't lookup element with key: ");
			print_hex(key, info.key_size, " ");
			printf("\n");
			fprint_hex(stderr, key, info.key_size, " ");
			fprintf(stderr, "\n");
		}

		prev_key = key;
@@ -587,7 +587,7 @@ static int do_lookup(int argc, char **argv)
		print_entry(&info, key, value);
	} else if (errno == ENOENT) {
		printf("key:\n");
		print_hex(key, info.key_size, " ");
		fprint_hex(stdout, key, info.key_size, " ");
		printf("\n\nNot found\n");
	} else {
		err("lookup failed: %s\n", strerror(errno));
@@ -642,14 +642,14 @@ static int do_getnext(int argc, char **argv)

	if (key) {
		printf("key:\n");
		print_hex(key, info.key_size, " ");
		fprint_hex(stdout, key, info.key_size, " ");
		printf("\n");
	} else {
		printf("key: None\n");
	}

	printf("next key:\n");
	print_hex(nextkey, info.key_size, " ");
	fprint_hex(stdout, nextkey, info.key_size, " ");
	printf("\n");

exit_free:
Loading