mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	samples: bpf: get ifindex from ifname
Find the ifindex with if_nametoindex() instead of requiring the numeric ifindex. Signed-off-by: Matteo Croce <mcroce@redhat.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
		
							parent
							
								
									d606ee5c1d
								
							
						
					
					
						commit
						dc378a1ab5
					
				
					 1 changed files with 7 additions and 2 deletions
				
			
		| 
						 | 
					@ -15,6 +15,7 @@
 | 
				
			||||||
#include <unistd.h>
 | 
					#include <unistd.h>
 | 
				
			||||||
#include <libgen.h>
 | 
					#include <libgen.h>
 | 
				
			||||||
#include <sys/resource.h>
 | 
					#include <sys/resource.h>
 | 
				
			||||||
 | 
					#include <net/if.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "bpf_util.h"
 | 
					#include "bpf_util.h"
 | 
				
			||||||
#include "bpf/bpf.h"
 | 
					#include "bpf/bpf.h"
 | 
				
			||||||
| 
						 | 
					@ -59,7 +60,7 @@ static void poll_stats(int map_fd, int interval)
 | 
				
			||||||
static void usage(const char *prog)
 | 
					static void usage(const char *prog)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	fprintf(stderr,
 | 
						fprintf(stderr,
 | 
				
			||||||
		"usage: %s [OPTS] IFINDEX\n\n"
 | 
							"usage: %s [OPTS] IFACE\n\n"
 | 
				
			||||||
		"OPTS:\n"
 | 
							"OPTS:\n"
 | 
				
			||||||
		"    -S    use skb-mode\n"
 | 
							"    -S    use skb-mode\n"
 | 
				
			||||||
		"    -N    enforce native mode\n",
 | 
							"    -N    enforce native mode\n",
 | 
				
			||||||
| 
						 | 
					@ -102,7 +103,11 @@ int main(int argc, char **argv)
 | 
				
			||||||
		return 1;
 | 
							return 1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ifindex = strtoul(argv[optind], NULL, 0);
 | 
						ifindex = if_nametoindex(argv[1]);
 | 
				
			||||||
 | 
						if (!ifindex) {
 | 
				
			||||||
 | 
							perror("if_nametoindex");
 | 
				
			||||||
 | 
							return 1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
 | 
						snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
 | 
				
			||||||
	prog_load_attr.file = filename;
 | 
						prog_load_attr.file = filename;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue