| 484 | |
| 485 | #ifdef DO_RFC_1812_CHECKS |
| 486 | static inline int |
| 487 | is_valid_ipv4_pkt(struct rte_ipv4_hdr *pkt, uint32_t link_len) |
| 488 | { |
| 489 | /* From http://www.rfc-editor.org/rfc/rfc1812.txt section 5.2.2 */ |
| 490 | /* |
| 491 | * 1. The packet length reported by the Link Layer must be large |
| 492 | * enough to hold the minimum length legal IP datagram (20 bytes). |
| 493 | */ |
| 494 | if (link_len < sizeof(struct rte_ipv4_hdr)) |
| 495 | return -1; |
| 496 | |
| 497 | /* 2. The IP checksum must be correct. */ |
| 498 | /* if this is not checked in H/W, check it. */ |
| 499 | if ((port_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM) == 0) { |
| 500 | uint16_t actual_cksum, expected_cksum; |
| 501 | actual_cksum = pkt->hdr_checksum; |
| 502 | pkt->hdr_checksum = 0; |
| 503 | expected_cksum = rte_ipv4_cksum(pkt); |
| 504 | if (actual_cksum != expected_cksum) |
| 505 | return -2; |
| 506 | } |
| 507 | |
| 508 | /* |
| 509 | * 3. The IP version number must be 4. If the version number is not 4 |
| 510 | * then the packet may be another version of IP, such as IPng or |
| 511 | * ST-II. |
| 512 | */ |
| 513 | if (((pkt->version_ihl) >> 4) != 4) |
| 514 | return -3; |
| 515 | /* |
| 516 | * 4. The IP header length field must be large enough to hold the |
| 517 | * minimum length legal IP datagram (20 bytes = 5 words). |
| 518 | */ |
| 519 | if ((pkt->version_ihl & 0xf) < 5) |
| 520 | return -4; |
| 521 | |
| 522 | /* |
| 523 | * 5. The IP total length field must be large enough to hold the IP |
| 524 | * datagram header, whose length is specified in the IP header length |
| 525 | * field. |
| 526 | */ |
| 527 | if (rte_cpu_to_be_16(pkt->total_length) < sizeof(struct rte_ipv4_hdr)) |
| 528 | return -5; |
| 529 | |
| 530 | return 0; |
| 531 | } |
| 532 | #endif |
| 533 | |
| 534 | #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH) |
no test coverage detected