Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2025 Huawei Technologies Co., Ltd 3 : : */ 4 : : 5 : : #include "internal.h" 6 : : 7 : : #include <stdio.h> 8 : : #include <stdlib.h> 9 : : 10 : : #include <rte_bpf.h> 11 : : #include <rte_debug.h> 12 : : #include <rte_eal.h> 13 : : #include <rte_errno.h> 14 : : 15 : 0 : RTE_LOG_REGISTER(validate_bpf_logtype, validate-bpf, NOTICE); 16 : : 17 : : static int 18 : 0 : test_bpf_load(struct rte_bpf_prm_ex *prm) 19 : : { 20 : 0 : struct rte_bpf * const bpf = rte_bpf_load_ex(prm); 21 : : 22 : 0 : const int rc = -rte_errno; 23 : : 24 : 0 : rte_bpf_destroy(bpf); 25 : : 26 : 0 : return bpf == NULL ? rc : 0; 27 : : } 28 : : 29 : : /* Re-starts validation of asked from interactive debugger. */ 30 : : static int 31 : 0 : test_bpf_load_with_restarts(struct rte_bpf_prm_ex *prm) 32 : : { 33 : 0 : for (;;) { 34 : 0 : const int rc = test_bpf_load(prm); 35 : : 36 : 0 : if (rc == -ECANCELED && debug_validate_again()) 37 : : continue; 38 : : 39 : 0 : if (rc != 0) 40 : 0 : fprintf(stderr, "Error %d loading BPF: %s\n", 41 : : -rc, strerror(-rc)); 42 : : else 43 : 0 : fprintf(stderr, "Validation succeeded.\n"); 44 : : 45 : 0 : return rc; 46 : : } 47 : : } 48 : : 49 : : int 50 : 0 : main(int argc, char *argv[]) 51 : : { 52 : : int rc; 53 : : 54 : 0 : struct args * const args = args_parse(argc, argv); 55 : 0 : if (args == NULL || args->show_help 56 : 0 : || args->bpf_prm.elf_file.path == NULL) { 57 : 0 : args_destroy(args); 58 : 0 : print_usage(argv[0]); 59 : 0 : if (args == NULL) 60 : : /* Could not parse arguments. */ 61 : : return 2; 62 : 0 : print_supported_types(); 63 : 0 : print_defaults(); 64 : 0 : return 0; 65 : : } 66 : : 67 : 0 : const int eal_init_argc = get_eal_init_argc(); 68 : 0 : char ** const eal_init_argv = get_eal_init_argv(argv[0]); 69 : 0 : rc = rte_eal_init(eal_init_argc, eal_init_argv); 70 : 0 : if (rc < 0) { 71 : 0 : fprintf(stderr, "Error %d initializing EAL: %s\n", 72 : : rte_errno, strerror(rte_errno)); 73 : 0 : args_destroy(args); 74 : 0 : return EXIT_FAILURE; 75 : : } 76 : 0 : RTE_VERIFY(rc == eal_init_argc - 1); 77 : : 78 : 0 : const int ret = test_bpf_load_with_restarts(&args->bpf_prm); 79 : : 80 : 0 : args_destroy(args); 81 : : 82 : 0 : rc = rte_eal_cleanup(); 83 : 0 : if (rc < 0) { 84 : 0 : fprintf(stderr, "Error %d cleaning up EAL: %s\n", 85 : : rte_errno, strerror(rte_errno)); 86 : 0 : return EXIT_FAILURE; 87 : : } 88 : : 89 : 0 : return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS; 90 : : }