From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jakub Kicinski Subject: Re: [PATCH] tc, bpf: add option to dump bpf verifier as C program fragment Date: Mon, 18 Jun 2018 13:18:42 -0700 Message-ID: <20180618131842.7b4d259f@cakuba.netronome.com> References: <1529225321-15429-1-git-send-email-ophirmu@mellanox.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: netdev@vger.kernel.org, Stephen Hemminger , David Ahern , Thomas Monjalon , Olga Shern To: Ophir Munk Return-path: Received: from mail-qt0-f196.google.com ([209.85.216.196]:32927 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932665AbeFRUSq (ORCPT ); Mon, 18 Jun 2018 16:18:46 -0400 Received: by mail-qt0-f196.google.com with SMTP id l10-v6so16394285qtj.0 for ; Mon, 18 Jun 2018 13:18:46 -0700 (PDT) In-Reply-To: <1529225321-15429-1-git-send-email-ophirmu@mellanox.com> Sender: netdev-owner@vger.kernel.org List-ID: On Sun, 17 Jun 2018 08:48:41 +0000, Ophir Munk wrote: > Similar to cbpf used within tcpdump utility with a "-d" option to dump > the compiled packet-matching code in a human readable form - tc has the > "verbose" option to dump ebpf verifier output. > Another useful option of cbpf using tcpdump "-dd" option is to dump > packet-matching code a C program fragment. Similar to this - this commit > adds a new tc ebpf option named "code" to dump ebpf verifier as C program > fragment. > > Existing "verbose" option sample output: > > Verifier analysis: > 0: (61) r2 = *(u32 *)(r1 +52) > 1: (18) r3 = 0xdeadbeef > 3: (63) *(u32 *)(r10 -4) = r3 > . > . > 11: (63) *(u32 *)(r1 +52) = r2 > 12: (18) r0 = 0xffffffff > 14: (95) exit > > New "code" option sample output: > > /* struct bpf_insn cls_q_code[] = { */ > {0x61, 2, 1, 52, 0x00000000}, > {0x18, 3, 0, 0, 0xdeadbeef}, > {0x00, 0, 0, 0, 0x00000000}, > . > . > {0x63, 1, 2, 52, 0x00000000}, > {0x18, 0, 0, 0, 0xffffffff}, > {0x00, 0, 0, 0, 0x00000000}, > {0x95, 0, 0, 0, 0x00000000}, > > Signed-off-by: Ophir Munk Hmm... printing C arrays looks like hacky integration with some C code... Would you not be better served by simply using libbpf in whatever is consuming this output?