| 374 | } |
| 375 | |
| 376 | int rte_mbuf_check(const struct rte_mbuf *m, int is_header, |
| 377 | const char **reason) |
| 378 | { |
| 379 | unsigned int nb_segs, pkt_len; |
| 380 | |
| 381 | if (m == NULL) { |
| 382 | *reason = "mbuf is NULL"; |
| 383 | return -1; |
| 384 | } |
| 385 | |
| 386 | /* generic checks */ |
| 387 | if (m->pool == NULL) { |
| 388 | *reason = "bad mbuf pool"; |
| 389 | return -1; |
| 390 | } |
| 391 | if (RTE_IOVA_IN_MBUF && rte_mbuf_iova_get(m) == 0) { |
| 392 | *reason = "bad IO addr"; |
| 393 | return -1; |
| 394 | } |
| 395 | if (m->buf_addr == NULL) { |
| 396 | *reason = "bad virt addr"; |
| 397 | return -1; |
| 398 | } |
| 399 | |
| 400 | uint16_t cnt = rte_mbuf_refcnt_read(m); |
| 401 | if ((cnt == 0) || (cnt == UINT16_MAX)) { |
| 402 | *reason = "bad ref cnt"; |
| 403 | return -1; |
| 404 | } |
| 405 | |
| 406 | /* nothing to check for sub-segments */ |
| 407 | if (is_header == 0) |
| 408 | return 0; |
| 409 | |
| 410 | /* data_len is supposed to be not more than pkt_len */ |
| 411 | if (m->data_len > m->pkt_len) { |
| 412 | *reason = "bad data_len"; |
| 413 | return -1; |
| 414 | } |
| 415 | |
| 416 | nb_segs = m->nb_segs; |
| 417 | pkt_len = m->pkt_len; |
| 418 | |
| 419 | do { |
| 420 | if (m->data_off > m->buf_len) { |
| 421 | *reason = "data offset too big in mbuf segment"; |
| 422 | return -1; |
| 423 | } |
| 424 | if (m->data_off + m->data_len > m->buf_len) { |
| 425 | *reason = "data length too big in mbuf segment"; |
| 426 | return -1; |
| 427 | } |
| 428 | nb_segs -= 1; |
| 429 | pkt_len -= m->data_len; |
| 430 | } while ((m = m->next) != NULL); |
| 431 | |
| 432 | if (nb_segs) { |
| 433 | *reason = "bad nb_segs"; |