MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_bpf_match

Function test_bpf_match

dpdk/app/test/test_bpf.c:3291–3330  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3289}
3290
3291static int
3292test_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);
3324error:
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 */
3333static int

Callers 1

test_bpf_filter_sanityFunction · 0.85

Calls 6

rte_bpf_loadFunction · 0.85
rte_bpf_execFunction · 0.85
rte_bpf_destroyFunction · 0.85
rte_freeFunction · 0.85
printfFunction · 0.50
rte_bpf_convertFunction · 0.50

Tested by

no test coverage detected