* Handler for incoming packets directly from the network adapter * Identifies the packet type (IP or ARP) and passes it along to one of the * helper functions debugnet_handle_ip or debugnet_handle_arp. * * It needs to partially replicate the behaviour of ether_input() and * ether_demux(). * * Parameters: * ifp the interface the packet came from * m an mbuf containing the packet received
| 515 | * m an mbuf containing the packet received |
| 516 | */ |
| 517 | static void |
| 518 | debugnet_pkt_in(struct ifnet *ifp, struct mbuf *m) |
| 519 | { |
| 520 | struct ifreq ifr; |
| 521 | struct ether_header *eh; |
| 522 | u_short etype; |
| 523 | |
| 524 | /* Ethernet processing. */ |
| 525 | if ((m->m_flags & M_PKTHDR) == 0) { |
| 526 | DNETDEBUG_IF(ifp, "discard frame without packet header\n"); |
| 527 | goto done; |
| 528 | } |
| 529 | if (m->m_len < ETHER_HDR_LEN) { |
| 530 | DNETDEBUG_IF(ifp, |
| 531 | "discard frame without leading eth header (len %u pktlen %u)\n", |
| 532 | m->m_len, m->m_pkthdr.len); |
| 533 | goto done; |
| 534 | } |
| 535 | if ((m->m_flags & M_HASFCS) != 0) { |
| 536 | m_adj(m, -ETHER_CRC_LEN); |
| 537 | m->m_flags &= ~M_HASFCS; |
| 538 | } |
| 539 | eh = mtod(m, struct ether_header *); |
| 540 | etype = ntohs(eh->ether_type); |
| 541 | if ((m->m_flags & M_VLANTAG) != 0 || etype == ETHERTYPE_VLAN) { |
| 542 | DNETDEBUG_IF(ifp, "ignoring vlan packets\n"); |
| 543 | goto done; |
| 544 | } |
| 545 | if (if_gethwaddr(ifp, &ifr) != 0) { |
| 546 | DNETDEBUG_IF(ifp, "failed to get hw addr for interface\n"); |
| 547 | goto done; |
| 548 | } |
| 549 | if (memcmp(ifr.ifr_addr.sa_data, eh->ether_dhost, |
| 550 | ETHER_ADDR_LEN) != 0 && |
| 551 | (etype != ETHERTYPE_ARP || !ETHER_IS_BROADCAST(eh->ether_dhost))) { |
| 552 | DNETDEBUG_IF(ifp, |
| 553 | "discard frame with incorrect destination addr\n"); |
| 554 | goto done; |
| 555 | } |
| 556 | |
| 557 | MPASS(g_debugnet_pcb_inuse); |
| 558 | |
| 559 | /* Done ethernet processing. Strip off the ethernet header. */ |
| 560 | m_adj(m, ETHER_HDR_LEN); |
| 561 | switch (etype) { |
| 562 | case ETHERTYPE_ARP: |
| 563 | debugnet_handle_arp(&g_dnet_pcb, &m); |
| 564 | break; |
| 565 | case ETHERTYPE_IP: |
| 566 | debugnet_handle_ip(&g_dnet_pcb, &m); |
| 567 | break; |
| 568 | default: |
| 569 | DNETDEBUG_IF(ifp, "dropping unknown ethertype %hu\n", etype); |
| 570 | break; |
| 571 | } |
| 572 | done: |
| 573 | if (m != NULL) |
| 574 | m_freem(m); |
nothing calls this directly
no test coverage detected