From patchwork Fri Nov 3 06:30:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 833682 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="cUnaqjbw"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ySsl05F8yz9sBd for ; Fri, 3 Nov 2017 17:39:56 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754474AbdKCGju (ORCPT ); Fri, 3 Nov 2017 02:39:50 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:47876 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752105AbdKCGiq (ORCPT ); Fri, 3 Nov 2017 02:38:46 -0400 Received: by mail-pg0-f66.google.com with SMTP id r25so1705982pgn.4 for ; Thu, 02 Nov 2017 23:38:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=591TzVct2YqWdirq1I3OLwk6ip+tmdQuwWYWcKqO988=; b=cUnaqjbw5z/U5Vh1YhDZoFe2dp425AB5T/RKYoIGH1KBS+2EpiNGUukmo/KRohcpF6 kJFljAcZWWlI5IRY+I+mZHfiI/6kRa2DhbqB0SCDfH42dI2m7krtKx5fnD+5oegcJrY1 DypKgAEgdEyFAohRYEFkmgvZBIejBP2o2tND25mRxuRnyAI3CcIOHtksKJFmJB4NmNK6 xCEU5B5ADETSmF6CbyRT4hCYV68izifwprCbUK4tarJ9Rg5SW1dwHVh0719/hhqAowWG UjzbOifxL+8MMEKnGKgBghihC561y8WyHA+WoJeVmw/HOCsmcUnUEBBKoSSOtH6P2UHF W6GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=591TzVct2YqWdirq1I3OLwk6ip+tmdQuwWYWcKqO988=; b=ZOWGI6YpXQ3lCAk1MIaTvmPhjzSG5pgCafBYW8QYQIlUC5H1nIm9ZqG+O7C2ydRioM OuRKA2PumJXFuAQvb2KNStFqr94qZfCbtf1445/zDnSs4ltKDB0picLn8xOsZSHVQDt5 REn0ZMPtKJKvg2VeItlFSPm4qhvlf6e6J7QbKJPVQpGRt0VXHsghNHUpIANhAKRZYcha V60MRzUIDDK9ircYD0MYEsuPYeJ6xjA5zcQi0gI3I0lf6YbE3rTE+3tHRiLhkU0zxAuP e+Vh3N+0SiMMTbV74oENLOniBaHaNrl0l+qOuuidlotX+kmDQCb6MmVFNevuWz5TNLCu ZILA== X-Gm-Message-State: AMCzsaXV6dufDo6PhQyhZ+a/PtpsEJhOUoS9CFUNwf1ZIIwJsupeM7dY ++0/zHejAHxt7By0CeV5GJOsD33f X-Google-Smtp-Source: ABhQp+TmXWqEVhg4wsNkVluElsgRjRvHOP+OSwxOpfA1YOy4fKUzVfboEddxSyYGGK+ObIoZ139WrQ== X-Received: by 10.98.158.211 with SMTP id f80mr6562336pfk.156.1509691126081; Thu, 02 Nov 2017 23:38:46 -0700 (PDT) Received: from jkicinski-Precision-T1700.netronome.com ([75.53.12.129]) by smtp.gmail.com with ESMTPSA id 62sm8456357pfw.129.2017.11.02.23.38.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Nov 2017 23:38:45 -0700 (PDT) From: Jakub Kicinski To: netdev@vger.kernel.org Cc: oss-drivers@netronome.com, alexei.starovoitov@gmail.com, daniel@iogearbox.net, Jakub Kicinski Subject: [PATCH net-next 04/15] bpftool: print program device bound info Date: Thu, 2 Nov 2017 23:30:58 -0700 Message-Id: <20171103063109.9441-5-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171103063109.9441-1-jakub.kicinski@netronome.com> References: <20171103063109.9441-1-jakub.kicinski@netronome.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org If program is bound to a device, print the name of the relevant interface or unknown if the netdev has since been removed. Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Reviewed-by: Quentin Monnet --- tools/bpf/bpftool/prog.c | 31 +++++++++++++++++++++++++++++++ tools/include/uapi/linux/bpf.h | 7 +++++++ 2 files changed, 38 insertions(+) diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index 250f80fd46aa..d3ab808dc882 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -229,6 +230,21 @@ static void print_prog_json(struct bpf_prog_info *info, int fd) info->tag[0], info->tag[1], info->tag[2], info->tag[3], info->tag[4], info->tag[5], info->tag[6], info->tag[7]); + if (info->status & BPF_PROG_STATUS_DEV_BOUND) { + jsonw_name(json_wtr, "dev"); + if (info->ifindex) { + char name[IF_NAMESIZE]; + + if (!if_indextoname(info->ifindex, name)) + jsonw_printf(json_wtr, "\"ifindex:%d\"", + info->ifindex); + else + jsonw_printf(json_wtr, "\"%s\"", name); + } else { + jsonw_printf(json_wtr, "\"unknown\""); + } + } + if (info->load_time) { char buf[32]; @@ -274,6 +290,21 @@ static void print_prog_plain(struct bpf_prog_info *info, int fd) printf("tag "); fprint_hex(stdout, info->tag, BPF_TAG_SIZE, ""); + printf(" "); + + if (info->status & BPF_PROG_STATUS_DEV_BOUND) { + printf("dev "); + if (info->ifindex) { + char name[IF_NAMESIZE]; + + if (!if_indextoname(info->ifindex, name)) + printf("ifindex:%d ", info->ifindex); + else + printf("%s ", name); + } else { + printf("unknown "); + } + } printf("\n"); if (info->load_time) { diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 7cebba491011..e92f62cf933a 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -259,6 +259,7 @@ union bpf_attr { __u32 kern_version; /* checked when prog_type=kprobe */ __u32 prog_flags; char prog_name[BPF_OBJ_NAME_LEN]; + __u32 prog_target_ifindex; /* ifindex of netdev to prep for */ }; struct { /* anonymous struct used by BPF_OBJ_* commands */ @@ -893,6 +894,10 @@ enum sk_action { #define BPF_TAG_SIZE 8 +enum bpf_prog_status { + BPF_PROG_STATUS_DEV_BOUND = (1 << 0), +}; + struct bpf_prog_info { __u32 type; __u32 id; @@ -906,6 +911,8 @@ struct bpf_prog_info { __u32 nr_map_ids; __aligned_u64 map_ids; char name[BPF_OBJ_NAME_LEN]; + __u32 ifindex; + __u32 status; } __attribute__((aligned(8))); struct bpf_map_info {