| 3289 | } |
| 3290 | |
| 3291 | static int |
| 3292 | test_bpf_match(pcap_t *pcap, const char *str, |
| 3293 | struct rte_mbuf *mb) |
| 3294 | { |
| 3295 | struct bpf_program fcode; |
| 3296 | struct rte_bpf_prm *prm = NULL; |
| 3297 | struct rte_bpf *bpf = NULL; |
| 3298 | int ret = -1; |
| 3299 | uint64_t rc; |
| 3300 | |
| 3301 | if (pcap_compile(pcap, &fcode, str, 1, PCAP_NETMASK_UNKNOWN)) { |
| 3302 | printf("%s@%d: pcap_compile(\"%s\") failed: %s;\n", |
| 3303 | __func__, __LINE__, str, pcap_geterr(pcap)); |
| 3304 | return -1; |
| 3305 | } |
| 3306 | |
| 3307 | prm = rte_bpf_convert(&fcode); |
| 3308 | if (prm == NULL) { |
| 3309 | printf("%s@%d: bpf_convert('%s') failed,, error=%d(%s);\n", |
| 3310 | __func__, __LINE__, str, rte_errno, strerror(rte_errno)); |
| 3311 | goto error; |
| 3312 | } |
| 3313 | |
| 3314 | bpf = rte_bpf_load(prm); |
| 3315 | if (bpf == NULL) { |
| 3316 | printf("%s@%d: failed to load bpf code, error=%d(%s);\n", |
| 3317 | __func__, __LINE__, rte_errno, strerror(rte_errno)); |
| 3318 | goto error; |
| 3319 | } |
| 3320 | |
| 3321 | rc = rte_bpf_exec(bpf, mb); |
| 3322 | /* The return code from bpf capture filter is non-zero if matched */ |
| 3323 | ret = (rc == 0); |
| 3324 | error: |
| 3325 | if (bpf) |
| 3326 | rte_bpf_destroy(bpf); |
| 3327 | rte_free(prm); |
| 3328 | pcap_freecode(&fcode); |
| 3329 | return ret; |
| 3330 | } |
| 3331 | |
| 3332 | /* Basic sanity test can we match a IP packet */ |
| 3333 | static int |
no test coverage detected