public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: "Maciej Fijałkowski" <maciejromanfijalkowski@gmail.com>
To: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: daniel@iogearbox.net, ast@kernel.org, netdev@vger.kernel.org,
	jakub.kicinski@netronome.com,
	"Toke Høiland-Jørgensen" <toke@toke.dk>
Subject: Re: [PATCH bpf-next v3 5/7] samples/bpf: Add a "force" flag to XDP samples
Date: Fri, 25 Jan 2019 18:52:04 +0100	[thread overview]
Message-ID: <20190125185204.48fb6ef8@maciek-lenovo> (raw)
In-Reply-To: <20190125093822.735c6a27@redhat.com>

On Fri, 25 Jan 2019 09:38:22 +0100
Jesper Dangaard Brouer <brouer@redhat.com> wrote:

> On Thu, 24 Jan 2019 22:47:45 +0100
> Maciej Fijalkowski <maciejromanfijalkowski@gmail.com> 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 <libbpf.h>
> >  #include <bpf/bpf.h>
> >  #include <sys/resource.h>
> > +#include <libgen.h>
> > +#include <linux/if_link.h>
> >  
> >  #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 <ifname>\n", argv[0]);
>                                   ^^^^^^^^
> Old help text says <ifname>
> 
> > +	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;
> 
> 


  reply	other threads:[~2019-01-25 17:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-24 21:47 [PATCH bpf-next v3 0/7] xdp: Avoid unloading xdp prog not attached by sample Maciej Fijalkowski
2019-01-24 21:47 ` [PATCH bpf-next v3 1/7] libbpf: Add a helper for retrieving a map fd for a given name Maciej Fijalkowski
2019-01-24 21:47 ` [PATCH bpf-next v3 2/7] samples/bpf: xdp_redirect_cpu have not need for read_trace_pipe Maciej Fijalkowski
2019-01-24 21:47 ` [PATCH bpf-next v3 3/7] samples/bpf: Convert XDP samples to libbpf usage Maciej Fijalkowski
2019-01-25  8:30   ` Jesper Dangaard Brouer
2019-01-25 17:53     ` Maciej Fijałkowski
2019-01-24 21:47 ` [PATCH bpf-next v3 4/7] samples/bpf: Extend RLIMIT_MEMLOCK for xdp_{sample_pkts, router_ipv4} Maciej Fijalkowski
2019-01-25  8:32   ` Jesper Dangaard Brouer
2019-01-24 21:47 ` [PATCH bpf-next v3 5/7] samples/bpf: Add a "force" flag to XDP samples Maciej Fijalkowski
2019-01-25  8:38   ` Jesper Dangaard Brouer
2019-01-25 17:52     ` Maciej Fijałkowski [this message]
2019-01-24 21:47 ` [PATCH bpf-next v3 6/7] libbpf: Add a support for getting xdp prog id on ifindex Maciej Fijalkowski
2019-01-24 21:47 ` [PATCH bpf-next v3 7/7] samples/bpf: Check the prog id before exiting Maciej Fijalkowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190125185204.48fb6ef8@maciek-lenovo \
    --to=maciejromanfijalkowski@gmail.com \
    --cc=ast@kernel.org \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=jakub.kicinski@netronome.com \
    --cc=netdev@vger.kernel.org \
    --cc=toke@toke.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox