* Handler for IP packets: checks their sanity and then processes any debugnet * ACK packets it finds. * * It needs to partially replicate the behaviour of ip_input() and udp_input(). * * Parameters: * pcb a pointer to the live debugnet PCB * mb a pointer to an mbuf * containing the packet received * Updates *mb if m_pullup et al change the pointer * Assumes the calling function will tak
| 80 | * Assumes the calling function will take care of freeing the mbuf |
| 81 | */ |
| 82 | void |
| 83 | debugnet_handle_ip(struct debugnet_pcb *pcb, struct mbuf **mb) |
| 84 | { |
| 85 | struct ip *ip; |
| 86 | struct mbuf *m; |
| 87 | unsigned short hlen; |
| 88 | |
| 89 | /* IP processing. */ |
| 90 | m = *mb; |
| 91 | if (m->m_pkthdr.len < sizeof(struct ip)) { |
| 92 | DNETDEBUG("dropping packet too small for IP header\n"); |
| 93 | return; |
| 94 | } |
| 95 | if (m->m_len < sizeof(struct ip)) { |
| 96 | m = m_pullup(m, sizeof(struct ip)); |
| 97 | *mb = m; |
| 98 | if (m == NULL) { |
| 99 | DNETDEBUG("m_pullup failed\n"); |
| 100 | return; |
| 101 | } |
| 102 | } |
| 103 | ip = mtod(m, struct ip *); |
| 104 | |
| 105 | /* IP version. */ |
| 106 | if (ip->ip_v != IPVERSION) { |
| 107 | DNETDEBUG("bad IP version %d\n", ip->ip_v); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | /* Header length. */ |
| 112 | hlen = ip->ip_hl << 2; |
| 113 | if (hlen < sizeof(struct ip)) { |
| 114 | DNETDEBUG("bad IP header length (%hu)\n", hlen); |
| 115 | return; |
| 116 | } |
| 117 | if (hlen > m->m_len) { |
| 118 | m = m_pullup(m, hlen); |
| 119 | *mb = m; |
| 120 | if (m == NULL) { |
| 121 | DNETDEBUG("m_pullup failed\n"); |
| 122 | return; |
| 123 | } |
| 124 | ip = mtod(m, struct ip *); |
| 125 | } |
| 126 | /* Ignore packets with IP options. */ |
| 127 | if (hlen > sizeof(struct ip)) { |
| 128 | DNETDEBUG("drop packet with IP options\n"); |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | #ifdef INVARIANTS |
| 133 | if ((IN_LOOPBACK(ntohl(ip->ip_dst.s_addr)) || |
| 134 | IN_LOOPBACK(ntohl(ip->ip_src.s_addr))) && |
| 135 | (m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK) == 0) { |
| 136 | DNETDEBUG("Bad IP header (RFC1122)\n"); |
| 137 | return; |
| 138 | } |
| 139 | #endif |
no test coverage detected