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=-1.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_PASS,UNWANTED_LANGUAGE_BODY 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 0DA81C282C0 for ; Fri, 25 Jan 2019 08:38:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DAC612084A for ; Fri, 25 Jan 2019 08:38:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727967AbfAYIia (ORCPT ); Fri, 25 Jan 2019 03:38:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53508 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726200AbfAYIi3 (ORCPT ); Fri, 25 Jan 2019 03:38:29 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68A3030EF81; Fri, 25 Jan 2019 08:38:29 +0000 (UTC) Received: from localhost (ovpn-200-36.brq.redhat.com [10.40.200.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AAE018221; Fri, 25 Jan 2019 08:38:24 +0000 (UTC) Date: Fri, 25 Jan 2019 09:38:22 +0100 From: Jesper Dangaard Brouer To: Maciej Fijalkowski Cc: daniel@iogearbox.net, ast@kernel.org, netdev@vger.kernel.org, jakub.kicinski@netronome.com, brouer@redhat.com, Toke =?UTF-8?B?SMO4aWxh?= =?UTF-8?B?bmQtSsO4cmdlbnNlbg==?= Subject: Re: [PATCH bpf-next v3 5/7] samples/bpf: Add a "force" flag to XDP samples Message-ID: <20190125093822.735c6a27@redhat.com> In-Reply-To: <20190124214747.6986-6-maciejromanfijalkowski@gmail.com> References: <20190124214747.6986-1-maciejromanfijalkowski@gmail.com> <20190124214747.6986-6-maciejromanfijalkowski@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 25 Jan 2019 08:38:29 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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. > + "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; -- Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer