| 442 | } |
| 443 | |
| 444 | void |
| 445 | debugnet_handle_udp(struct debugnet_pcb *pcb, struct mbuf **mb) |
| 446 | { |
| 447 | const struct udphdr *udp; |
| 448 | struct mbuf *m; |
| 449 | uint16_t sport, ulen; |
| 450 | |
| 451 | /* UDP processing. */ |
| 452 | |
| 453 | m = *mb; |
| 454 | if (m->m_pkthdr.len < sizeof(*udp)) { |
| 455 | DNETDEBUG("ignoring small UDP packet\n"); |
| 456 | return; |
| 457 | } |
| 458 | |
| 459 | /* Get UDP headers. */ |
| 460 | if (m->m_len < sizeof(*udp)) { |
| 461 | m = m_pullup(m, sizeof(*udp)); |
| 462 | *mb = m; |
| 463 | if (m == NULL) { |
| 464 | DNETDEBUG("m_pullup failed\n"); |
| 465 | return; |
| 466 | } |
| 467 | } |
| 468 | udp = mtod(m, const void *); |
| 469 | |
| 470 | /* We expect to receive UDP packets on the configured client port. */ |
| 471 | if (ntohs(udp->uh_dport) != pcb->dp_client_port) { |
| 472 | DNETDEBUG("not on the expected port.\n"); |
| 473 | return; |
| 474 | } |
| 475 | |
| 476 | /* Check that ulen does not exceed actual size of data. */ |
| 477 | ulen = ntohs(udp->uh_ulen); |
| 478 | if (m->m_pkthdr.len < ulen) { |
| 479 | DNETDEBUG("ignoring runt UDP packet\n"); |
| 480 | return; |
| 481 | } |
| 482 | |
| 483 | sport = ntohs(udp->uh_sport); |
| 484 | |
| 485 | m_adj(m, sizeof(*udp)); |
| 486 | ulen -= sizeof(*udp); |
| 487 | |
| 488 | if (ulen == sizeof(struct debugnet_ack)) { |
| 489 | debugnet_handle_ack(pcb, mb, sport); |
| 490 | return; |
| 491 | } |
| 492 | |
| 493 | if (pcb->dp_rx_handler == NULL) { |
| 494 | if (ulen < sizeof(struct debugnet_ack)) |
| 495 | DNETDEBUG("ignoring small ACK packet\n"); |
| 496 | else |
| 497 | DNETDEBUG("ignoring unexpected non-ACK packet on " |
| 498 | "half-duplex connection.\n"); |
| 499 | return; |
| 500 | } |
| 501 |
no test coverage detected