From patchwork Wed Oct 18 23:01:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manu Bretelle X-Patchwork-Id: 13428073 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72D5239861 for ; Wed, 18 Oct 2023 23:02:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WhHQxBLv" Received: from mail-oo1-xc34.google.com (mail-oo1-xc34.google.com [IPv6:2607:f8b0:4864:20::c34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61CF9113 for ; Wed, 18 Oct 2023 16:02:07 -0700 (PDT) Received: by mail-oo1-xc34.google.com with SMTP id 006d021491bc7-57b74782be6so3899069eaf.2 for ; Wed, 18 Oct 2023 16:02:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697670126; x=1698274926; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=c/s64ybxh3SIykvx36VJBDmDk6npodPlCgr5zaGbo0g=; b=WhHQxBLvian6Zn2PUNyC5hbkSpqyu6FnJIfWsSveppoZWYaw08Moq4AUiRw2tFlMK8 s8FPR9npcze7FsSpqgJR1lZ2vWof+um27L6WQFuE/xK7RZGfXpxSPWdJV1wQoI6/Ny15 5+VArp6sFPEMzcBYPFx8QpxeA0afgLchQFsjhF6mhH7Al5OL+G0Sfqbv+FICSLXY/ipu BMRknUOY01iRS1Ttz8vM+gX8RJRVDGEM712MYjNHNPxZREEhzLLFhy7JN6V9cK97wWLS q3yfzW1ajERYYHZUrZHBYgLDslaKztwaxfi1a2EOO5MBDGoLLMOJSUwNNTpwAGPJVUor HjUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697670126; x=1698274926; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c/s64ybxh3SIykvx36VJBDmDk6npodPlCgr5zaGbo0g=; b=REeznvWr8gT2Ks+62UTzHXNrDnvpuYR8132JdL3MepZCcj7XPuOgXs3OcbSzagTXcq JGabaa66B9qqKzcySbTR6OMDK3ykb5eEez14KzcFvsmdSYi0zhsPJtdyjdCq2VgPbaxv CnZixszOHDSMCs8sEUq5MHpHZR28m9JxlAfsW5HG28UGjFciD5VZcIg3F4wZmRClt7hf xt/kLHvT5t0A7cA/jyQUyucrS8nBlS+bZKTTqn3cI0/ePTGrkT24BcteilhVGzDwsyW3 S/mm7e0yF1Tcr/6X8xfiYwR/bf4QWPJ9fD3OgzouCOEayrMu7hm9zQQnX/a2R/oAafzt 1ubg== X-Gm-Message-State: AOJu0YzUqzpkp+S1FnxSnoDs9D6CV+fhELNSnkQszI/xI5KdHM3YxwJM w7ojGpMeKpnETT489ElDJnhQboB/PENKrzNe X-Google-Smtp-Source: AGHT+IFffo4xaahXNRhq6L1tpevC5hzW/bZW8uZVNPm5OZDVQ8xkf2QFjLgLdlLfi2y2Lgl+NWR2Kg== X-Received: by 2002:a05:6870:3c8b:b0:1e9:efa9:1199 with SMTP id gl11-20020a0568703c8b00b001e9efa91199mr989305oab.4.1697670126129; Wed, 18 Oct 2023 16:02:06 -0700 (PDT) Received: from localhost (fwdproxy-vll-118.fbsv.net. [2a03:2880:12ff:76::face:b00c]) by smtp.gmail.com with ESMTPSA id y28-20020a9d715c000000b006c4e3d1fdf4sm834227otj.14.2023.10.18.16.02.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:02:05 -0700 (PDT) From: Manu Bretelle To: bpf@vger.kernel.org, quentin@isovalent.com, andrii@kernel.org, daniel@iogearbox.net, ast@kernel.org, martin.lau@linux.dev, song@kernel.org, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org Subject: [PATCH bpf-next 1/2] bpftool: fix printing of pointer value Date: Wed, 18 Oct 2023 16:01:32 -0700 Message-Id: <20231018230133.1593152-2-chantr4@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231018230133.1593152-1-chantr4@gmail.com> References: <20231018230133.1593152-1-chantr4@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net When printing a pointer value, "%p" will either print the hexadecimal value of the pointer (e.g `0x1234`), or `(nil)` when NULL. Both of those are invalid json "integer" values and need to be wrapped in quotes. Before: ``` $ sudo bpftool struct_ops dump name ned_dummy_cca | grep next "next": (nil), $ sudo bpftool struct_ops dump name ned_dummy_cca | \ jq '.[1].bpf_struct_ops_tcp_congestion_ops.data.list.next' parse error: Invalid numeric literal at line 29, column 34 ``` After: ``` $ sudo ./bpftool struct_ops dump name ned_dummy_cca | grep next "next": "(nil)", $ sudo ./bpftool struct_ops dump name ned_dummy_cca | \ jq '.[1].bpf_struct_ops_tcp_congestion_ops.data.list.next' "(nil)" ``` Signed-off-by: Manu Bretelle --- tools/bpf/bpftool/btf_dumper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c index 1b7f69714604..527fe867a8fb 100644 --- a/tools/bpf/bpftool/btf_dumper.c +++ b/tools/bpf/bpftool/btf_dumper.c @@ -127,7 +127,7 @@ static void btf_dumper_ptr(const struct btf_dumper *d, print_ptr_value: if (d->is_plain_text) - jsonw_printf(d->jw, "%p", (void *)value); + jsonw_printf(d->jw, "\"%p\"", (void *)value); else jsonw_printf(d->jw, "%lu", value); } From patchwork Wed Oct 18 23:01:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manu Bretelle X-Patchwork-Id: 13428074 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7841B39861 for ; Wed, 18 Oct 2023 23:02:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GC1uHnPX" Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CC7F113 for ; Wed, 18 Oct 2023 16:02:10 -0700 (PDT) Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-6c64c2c0f97so4509865a34.3 for ; Wed, 18 Oct 2023 16:02:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697670129; x=1698274929; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Jh91EGxU7WVmN/7t+t76eeQKqYP9BYC/Vn2WsbI9rZU=; b=GC1uHnPXS7oJfTul5jm4wgY7d41gvRLepP5lcZYwJncBQQli8OYOlsmXK3uhSXdMJC MEfPkYC66pyJh7sKgMw10jK4ZPr3G1ue5sOvNE8jfE/eeNWNPMNvySFBdoaRe6yDZPui ZV43/Yu7My3/kvGemn470Y3t3Z6t3c+cHyKcQpBBhdR60T1Vsi7R2WwPM6/SaIszbCuG WTgmzEEOlxLK/+fxb3ma6Qj59G7OjaRaejhd0SrZ4LpP+Qm/rVxI2eTTf5C6Kdl/OK5B BDTxijm0obm/ZV9efUdu7inTMUo1PcbWkFY+POKXu44VIKoMZsNe7rqU5oZLEiQ8aT0q MUkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697670129; x=1698274929; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jh91EGxU7WVmN/7t+t76eeQKqYP9BYC/Vn2WsbI9rZU=; b=B3yQcu/Hzpr3ipEUOAANefwoddSwGxiKUOIua73oowHl8zu4icUe56ZodFEk1W6wBs HqxjreTyuS8s5AFf+w7iZJ7JaatjxuL6nmeEQnrcqiu2K0vamfZ4vA1lOYoT7j9B5ROt OH98DYeUCBPb0LEIa7f3zx9/vTYLQARcGPfDdqk6tz7qn8trPLeZP5sGRT9/EB7PCFw5 OSiKAgP6R/Bb+pKVYXYxWjU75cchpQjs+kb/lB2TCZzBRVT2X9aqL6G/USdVbXNvJv9C +rnmRLqBI8mi7EbLr7xozF57xVK4acKVqnGUg8lyaL6DQ7x4TaQqogP9o+ZPe0SUljmp 5fmw== X-Gm-Message-State: AOJu0YwWoZOulojpeU+V4ufP7fHSTzN5DnNSFrNzuoobOv5MuMewf4iW D1rDIb6xD4UuVwaDOYyG7nFyxcgDpNyQxF6y X-Google-Smtp-Source: AGHT+IEhVB0xD3X91ywn0KuzVdC2SNR4GxDV7ECdx/ABle4DOb5sWD4E5IYhkOf/wQBdJ7YG07keLQ== X-Received: by 2002:a05:6870:4988:b0:1e9:b29b:b145 with SMTP id ho8-20020a056870498800b001e9b29bb145mr981544oab.7.1697670129153; Wed, 18 Oct 2023 16:02:09 -0700 (PDT) Received: from localhost (fwdproxy-vll-009.fbsv.net. [2a03:2880:12ff:9::face:b00c]) by smtp.gmail.com with ESMTPSA id n1-20020a9d7101000000b006b9734b9fafsm835677otj.13.2023.10.18.16.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:02:08 -0700 (PDT) From: Manu Bretelle To: bpf@vger.kernel.org, quentin@isovalent.com, andrii@kernel.org, daniel@iogearbox.net, ast@kernel.org, martin.lau@linux.dev, song@kernel.org, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org Subject: [PATCH bpf-next 2/2] bpftool: wrap struct_ops dump in an array Date: Wed, 18 Oct 2023 16:01:33 -0700 Message-Id: <20231018230133.1593152-3-chantr4@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231018230133.1593152-1-chantr4@gmail.com> References: <20231018230133.1593152-1-chantr4@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net When dumping a struct_ops, 2 dictionaries are emitted. When using `name`, they were already wrapped in an array, but not when using `id`. Causing `jq` to fail at parsing the payload as it reached the comma following the first dict. This change wraps those dictionaries in an array so valid json is emitted. Before, jq fails to parse the output: ``` $ sudo bpftool struct_ops dump id 1523612 | jq . > /dev/null parse error: Expected value before ',' at line 19, column 2 ``` After, no error parsing the output: ``` sudo ./bpftool struct_ops dump id 1523612 | jq . > /dev/null ``` Signed-off-by: Manu Bretelle --- tools/bpf/bpftool/struct_ops.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/bpf/bpftool/struct_ops.c b/tools/bpf/bpftool/struct_ops.c index 3ebc9fe91e0e..d573f2640d8e 100644 --- a/tools/bpf/bpftool/struct_ops.c +++ b/tools/bpf/bpftool/struct_ops.c @@ -276,6 +276,9 @@ static struct res do_one_id(const char *id_str, work_func func, void *data, res.nr_maps++; + if (wtr) + jsonw_start_array(wtr); + if (func(fd, info, data, wtr)) res.nr_errs++; else if (!wtr && json_output) @@ -288,6 +291,9 @@ static struct res do_one_id(const char *id_str, work_func func, void *data, */ jsonw_null(json_wtr); + if (wtr) + jsonw_end_array(wtr); + done: free(info); close(fd);