Example #1
0
File: main.c Project: avagin/linux
static int do_version(int argc, char **argv)
{
	if (json_output) {
		jsonw_start_object(json_wtr);
		jsonw_name(json_wtr, "version");
		jsonw_printf(json_wtr, "\"%s\"", BPFTOOL_VERSION);
		jsonw_end_object(json_wtr);
	} else {
		printf("%s v%s\n", bin_name, BPFTOOL_VERSION);
	}
	return 0;
}
Example #2
0
static void _bridge_print_timer(FILE *f,
				const char *attr,
				struct rtattr *timer)
{
	struct timeval tv;

	__jiffies_to_tv(&tv, rta_getattr_u64(timer));
	if (is_json_context()) {
		json_writer_t *jw = get_json_writer();

		jsonw_name(jw, attr);
		jsonw_printf(jw, "%i.%.2i",
			     (int)tv.tv_sec,
			     (int)tv.tv_usec / 10000);
	} else {
		fprintf(f, "%s %4i.%.2i ", attr, (int)tv.tv_sec,
			(int)tv.tv_usec / 10000);
	}
}
Example #3
0
void dump_xlated_json(struct dump_data *dd, void *buf, unsigned int len,
		      bool opcodes, bool linum)
{
	const struct bpf_prog_linfo *prog_linfo = dd->prog_linfo;
	const struct bpf_insn_cbs cbs = {
		.cb_print	= print_insn_json,
		.cb_call	= print_call,
		.cb_imm		= print_imm,
		.private_data	= dd,
	};
	struct bpf_func_info *record;
	struct bpf_insn *insn = buf;
	struct btf *btf = dd->btf;
	bool double_insn = false;
	unsigned int nr_skip = 0;
	char func_sig[1024];
	unsigned int i;

	jsonw_start_array(json_wtr);
	record = dd->func_info;
	for (i = 0; i < len / sizeof(*insn); i++) {
		if (double_insn) {
			double_insn = false;
			continue;
		}
		double_insn = insn[i].code == (BPF_LD | BPF_IMM | BPF_DW);

		jsonw_start_object(json_wtr);

		if (btf && record) {
			if (record->insn_off == i) {
				btf_dumper_type_only(btf, record->type_id,
						     func_sig,
						     sizeof(func_sig));
				if (func_sig[0] != '\0') {
					jsonw_name(json_wtr, "proto");
					jsonw_string(json_wtr, func_sig);
				}
				record = (void *)record + dd->finfo_rec_size;
			}
		}

		if (prog_linfo) {
			const struct bpf_line_info *linfo;

			linfo = bpf_prog_linfo__lfind(prog_linfo, i, nr_skip);
			if (linfo) {
				btf_dump_linfo_json(btf, linfo, linum);
				nr_skip++;
			}
		}

		jsonw_name(json_wtr, "disasm");
		print_bpf_insn(&cbs, insn + i, true);

		if (opcodes) {
			jsonw_name(json_wtr, "opcodes");
			jsonw_start_object(json_wtr);

			jsonw_name(json_wtr, "code");
			jsonw_printf(json_wtr, "\"0x%02hhx\"", insn[i].code);

			jsonw_name(json_wtr, "src_reg");
			jsonw_printf(json_wtr, "\"0x%hhx\"", insn[i].src_reg);

			jsonw_name(json_wtr, "dst_reg");
			jsonw_printf(json_wtr, "\"0x%hhx\"", insn[i].dst_reg);

			jsonw_name(json_wtr, "off");
			print_hex_data_json((uint8_t *)(&insn[i].off), 2);

			jsonw_name(json_wtr, "imm");
			if (double_insn && i < len - 1)
				print_hex_data_json((uint8_t *)(&insn[i].imm),
						    12);
			else
				print_hex_data_json((uint8_t *)(&insn[i].imm),
						    4);
			jsonw_end_object(json_wtr);
		}
		jsonw_end_object(json_wtr);
	}
	jsonw_end_array(json_wtr);
}
Example #4
0
void jsonw_s64(json_writer_t *self, int64_t num)
{
	jsonw_printf(self, "%"PRId64, num);
}
Example #5
0
void jsonw_int(json_writer_t *self, int num)
{
	jsonw_printf(self, "%d", num);
}
Example #6
0
void jsonw_lluint(json_writer_t *self, unsigned long long num)
{
	jsonw_printf(self, "%llu", num);
}
Example #7
0
void jsonw_xint(json_writer_t *self, uint64_t num)
{
	jsonw_printf(self, "%"PRIx64, num);
}
Example #8
0
void jsonw_u64(json_writer_t *self, uint64_t num)
{
	jsonw_printf(self, "%"PRIu64, num);
}
Example #9
0
void jsonw_uint(json_writer_t *self, unsigned int num)
{
	jsonw_printf(self, "%u", num);
}
Example #10
0
void jsonw_hu(json_writer_t *self, unsigned short num)
{
	jsonw_printf(self, "%hu", num);
}
Example #11
0
void jsonw_hhu(json_writer_t *self, unsigned char num)
{
	jsonw_printf(self, "%hhu", num);
}
Example #12
0
void jsonw_float(json_writer_t *self, double num)
{
	jsonw_printf(self, "%g", num);
}
Example #13
0
void jsonw_null(json_writer_t *self)
{
	jsonw_printf(self, "null");
}
Example #14
0
void jsonw_bool(json_writer_t *self, bool val)
{
	jsonw_printf(self, "%s", val ? "true" : "false");
}
Example #15
0
void jsonw_float_fmt(json_writer_t *self, const char *fmt, double num)
{
	jsonw_printf(self, fmt, num);
}