From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,FROM_EXCESS_BASE64, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 362BAC282C0 for ; Fri, 25 Jan 2019 17:52:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F3BEF218A2 for ; Fri, 25 Jan 2019 17:52:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="B6bLniwh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729210AbfAYRwL (ORCPT ); Fri, 25 Jan 2019 12:52:11 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:43779 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726361AbfAYRwK (ORCPT ); Fri, 25 Jan 2019 12:52:10 -0500 Received: by mail-lf1-f65.google.com with SMTP id u18so7527318lff.10 for ; Fri, 25 Jan 2019 09:52:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1c6ssJgGKjLTG9+eFR4x7UvVBu2kJ/TTHICmLwWFlIQ=; b=B6bLniwhkFdlEIlqoiJCH4D69dwTe5Dpf+obI5XSi5TPnI9vjaTAkEM7bt2ZnPdeT8 vH3kI4TtGLLs5nb20L45ZOd35MSpB1KI3LOYi7el6ofoynxDtJjkDsAjkPXoplzec4xA YwoLpovBluymGZ/n2qTr2NRnm82Rlri9w1mThOeEwgI/C86S/PTYYrf7iirZCc3/6f3T aeB7m16468v59qvVORMgE3KvGVJWhUBPNAnZNm2VvyfdN9KUiQaho6FIiDnZDJhpAihf QakktOzOnrbJPrK4wsIjvF+XnH1rWQMEJEWcxfxPMPLJNpIc/JlXsv0V6QggMNR6w682 qPaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1c6ssJgGKjLTG9+eFR4x7UvVBu2kJ/TTHICmLwWFlIQ=; b=i0lj2fFtA0paK4HTwo9Llq7UipcfxxaQacsOLIT6m/y9rmTeq9aREwODqvwBOwHGOx W16ajUUT1Vr7F8upJs7/CamD8qBKYuipS5NWOuGqlLMrPYJbTHyMngjMSh9IDuHh80DP 8Dp5qSaI7nbL3Y9z5kUyD6JrZgFE5vjRGV5aAXj2EPYax7g/HRpPP8HrZ4AIKCpbxBUE TDQ38mcPrd9p43upjnsN+AB3QPKGaCR/kSxc6DpQxy5DkCReWh/ZWw3LvcnPQ3fCMNYp KjhbnHzbU4SJphvJL+2IibIghVcfjx3noMKaGq2xq9qjYNQTyiP4/Fcgr4cGfaAbA77g eVKw== X-Gm-Message-State: AJcUukfZTJn34t9IID29M/cyDEaRbJPa9jKS3YP3YKXv8QRLV7pl0ZKI E0fBO+FMXUpjsyq4sHFDhGI= X-Google-Smtp-Source: ALg8bN4X3lnRuUTJkh8/vDJCD2ZNTly/NFT/eEde5wUi8QvXmbZq7j9cP/0AQIfuYBFRNRZs4Eg8cQ== X-Received: by 2002:a19:7919:: with SMTP id u25mr9541086lfc.18.1548438727956; Fri, 25 Jan 2019 09:52:07 -0800 (PST) Received: from maciek-lenovo (host-185-93-94-63.ip-point.pl. [185.93.94.63]) by smtp.gmail.com with ESMTPSA id d24-v6sm1595164ljg.2.2019.01.25.09.52.07 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 25 Jan 2019 09:52:07 -0800 (PST) Date: Fri, 25 Jan 2019 18:52:04 +0100 From: Maciej =?UTF-8?B?RmlqYcWCa293c2tp?= To: Jesper Dangaard Brouer Cc: daniel@iogearbox.net, ast@kernel.org, netdev@vger.kernel.org, jakub.kicinski@netronome.com, Toke =?UTF-8?B?SMO4aWxhbmQtSsO4cmdlbnNlbg==?= Subject: Re: [PATCH bpf-next v3 5/7] samples/bpf: Add a "force" flag to XDP samples Message-ID: <20190125185204.48fb6ef8@maciek-lenovo> In-Reply-To: <20190125093822.735c6a27@redhat.com> References: <20190124214747.6986-1-maciejromanfijalkowski@gmail.com> <20190124214747.6986-6-maciejromanfijalkowski@gmail.com> <20190125093822.735c6a27@redhat.com> X-Mailer: Claws Mail 3.9.3 (GTK+ 2.24.23; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Fri, 25 Jan 2019 09:38:22 +0100 Jesper Dangaard Brouer wrote: > On Thu, 24 Jan 2019 22:47:45 +0100 > Maciej Fijalkowski wrote: > > > diff --git a/samples/bpf/xdp_sample_pkts_user.c > > b/samples/bpf/xdp_sample_pkts_user.c index 5f5828ee0761..362ad35b524d 100644 > > --- a/samples/bpf/xdp_sample_pkts_user.c > > +++ b/samples/bpf/xdp_sample_pkts_user.c > > @@ -13,6 +13,8 @@ > > #include > > #include > > #include > > +#include > > +#include > > > > #include "perf-sys.h" > > #include "trace_helpers.h" > > @@ -21,12 +23,13 @@ > > static int pmu_fds[MAX_CPUS], if_idx; > > static struct perf_event_mmap_page *headers[MAX_CPUS]; > > static char *if_name; > > +static __u32 xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; > > > > static int do_attach(int idx, int fd, const char *name) > > { > > int err; > > > > - err = bpf_set_link_xdp_fd(idx, fd, 0); > > + err = bpf_set_link_xdp_fd(idx, fd, xdp_flags); > > if (err < 0) > > printf("ERROR: failed to attach program to %s\n", name); > > > > @@ -98,21 +101,42 @@ static void sig_handler(int signo) > > exit(0); > > } > > > > +static void usage(const char *prog) > > +{ > > + fprintf(stderr, > > + "%s: %s [OPTS] IFINDEX\n\n" > ^^^^^^^ > The usage help text is wrong, this sample takes the interface name as input. > It can take ifindex as well as ifname actually as you're saying later in this mail - so I'm going to fix this message to "(...) IFNAME/IFINDEX" in v4. Hope that makes sense? > > > + "OPTS:\n" > > + " -F force loading prog\n", > > + __func__, prog); > > +} > > + > > int main(int argc, char **argv) > > { > > struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY}; > > struct bpf_prog_load_attr prog_load_attr = { > > .prog_type = BPF_PROG_TYPE_XDP, > > }; > > + const char *optstr = "F"; > > + int prog_fd, map_fd, opt; > > struct bpf_object *obj; > > struct bpf_map *map; > > - int prog_fd, map_fd; > > char filename[256]; > > int ret, err, i; > > int numcpus; > > > > - if (argc < 2) { > > - printf("Usage: %s \n", argv[0]); > ^^^^^^^^ > Old help text says > > > + while ((opt = getopt(argc, argv, optstr)) != -1) { > > + switch (opt) { > > + case 'F': > > + xdp_flags &= ~XDP_FLAGS_UPDATE_IF_NOEXIST; > > + break; > > + default: > > + usage(basename(argv[0])); > > + return 1; > > + } > > + } > > + > > + if (optind == argc) { > > + usage(basename(argv[0])); > > return 1; > > } > > > > @@ -143,16 +167,16 @@ int main(int argc, char **argv) > > } > > map_fd = bpf_map__fd(map); > > > > - if_idx = if_nametoindex(argv[1]); > > + if_idx = if_nametoindex(argv[optind]); > > The we convert the ifname to ifindex. > > > if (!if_idx) > > - if_idx = strtoul(argv[1], NULL, 0); > > + if_idx = strtoul(argv[optind], NULL, 0); > > > > We do support falling back to using this as an ifindex. > > > > if (!if_idx) { > > fprintf(stderr, "Invalid ifname\n"); > > return 1; > > } > > - if_name = argv[1]; > > - err = do_attach(if_idx, prog_fd, argv[1]); > > + if_name = argv[optind]; > > + err = do_attach(if_idx, prog_fd, if_name); > > if (err) > > return err; > >