Re: [PATCH bpf-next 2/3] bpftool: match programs by name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Dec 10, 2019 at 01:04:13PM -0800, Jakub Kicinski wrote:
> On Tue, 10 Dec 2019 17:06:42 +0100, Paul Chaignon wrote:
> > When working with frequently modified BPF programs, both the ID and the
> > tag may change.  bpftool currently doesn't provide a "stable" way to match
> > such programs.
> > 
> > This patch implements lookup by name for programs.  The show and dump
> > commands will return all programs with the given name, whereas other
> > commands will error out if several programs have the same name.
> > 
> > Signed-off-by: Paul Chaignon <paul.chaignon@xxxxxxxxxx>
> 
> > @@ -164,7 +165,7 @@ prog_parse_fds(int *argc, char ***argv, int *fds)
> >  		}
> >  		return 1;
> >  	} else if (is_prefix(**argv, "tag")) {
> > -		unsigned char tag[BPF_TAG_SIZE];
> > +		char tag[BPF_TAG_SIZE];
> 
> Perhaps better to change the argument to prog_fd_by_nametag() to void *?
> 
> >  
> >  		NEXT_ARGP();
> >  
> > @@ -176,7 +177,20 @@ prog_parse_fds(int *argc, char ***argv, int *fds)
> >  		}
> >  		NEXT_ARGP();
> >  
> > -		return prog_fd_by_tag(tag, fds);
> > +		return prog_fd_by_nametag(tag, fds, true);
> > +	} else if (is_prefix(**argv, "name")) {
> > +		char *name;
> > +
> > +		NEXT_ARGP();
> > +
> > +		name = **argv;
> > +		if (strlen(name) > BPF_OBJ_NAME_LEN - 1) {
> 
> Is this needed? strncmp will simply never match, is it preferred to
> hard error?

I tried to follow the fail-early pattern of lookups by tag above.  I do
like that there's a different error message for a longer than expected
name.  Since libbpf silently truncates names, typing a longer name is
not uncommon.

[...]

Paul



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux