Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <stdio.h>
0003 #include <unistd.h>
0004 #include <bpf/libbpf.h>
0005 #include "trace_helpers.h"
0006 
0007 int main(int ac, char **argv)
0008 {
0009     struct bpf_link *link = NULL;
0010     struct bpf_program *prog;
0011     struct bpf_object *obj;
0012     char filename[256];
0013     FILE *f;
0014 
0015     snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
0016     obj = bpf_object__open_file(filename, NULL);
0017     if (libbpf_get_error(obj)) {
0018         fprintf(stderr, "ERROR: opening BPF object file failed\n");
0019         return 0;
0020     }
0021 
0022     prog = bpf_object__find_program_by_name(obj, "bpf_prog1");
0023     if (!prog) {
0024         fprintf(stderr, "ERROR: finding a prog in obj file failed\n");
0025         goto cleanup;
0026     }
0027 
0028     /* load BPF program */
0029     if (bpf_object__load(obj)) {
0030         fprintf(stderr, "ERROR: loading BPF object file failed\n");
0031         goto cleanup;
0032     }
0033 
0034     link = bpf_program__attach(prog);
0035     if (libbpf_get_error(link)) {
0036         fprintf(stderr, "ERROR: bpf_program__attach failed\n");
0037         link = NULL;
0038         goto cleanup;
0039     }
0040 
0041     f = popen("taskset 1 ping -c5 localhost", "r");
0042     (void) f;
0043 
0044     read_trace_pipe();
0045 
0046 cleanup:
0047     bpf_link__destroy(link);
0048     bpf_object__close(obj);
0049     return 0;
0050 }