Lines Matching full:ip
51 #include <netinet/ip.h>
69 * Handler for IP packets: checks their sanity and then processes any debugnet
83 struct ip *ip; in debugnet_handle_ip() local
90 /* IP processing. */ in debugnet_handle_ip()
92 if (m->m_pkthdr.len < sizeof(struct ip)) { in debugnet_handle_ip()
93 DNETDEBUG("dropping packet too small for IP header\n"); in debugnet_handle_ip()
96 if (m->m_len < sizeof(struct ip)) { in debugnet_handle_ip()
97 m = m_pullup(m, sizeof(struct ip)); in debugnet_handle_ip()
104 ip = mtod(m, struct ip *); in debugnet_handle_ip()
106 /* IP version. */ in debugnet_handle_ip()
107 if (ip->ip_v != IPVERSION) { in debugnet_handle_ip()
108 DNETDEBUG("bad IP version %d\n", ip->ip_v); in debugnet_handle_ip()
113 hlen = ip->ip_hl << 2; in debugnet_handle_ip()
114 if (hlen < sizeof(struct ip)) { in debugnet_handle_ip()
115 DNETDEBUG("bad IP header length (%hu)\n", hlen); in debugnet_handle_ip()
125 ip = mtod(m, struct ip *); in debugnet_handle_ip()
127 /* Ignore packets with IP options. */ in debugnet_handle_ip()
128 if (hlen > sizeof(struct ip)) { in debugnet_handle_ip()
129 DNETDEBUG("drop packet with IP options\n"); in debugnet_handle_ip()
134 if ((IN_LOOPBACK(ntohl(ip->ip_dst.s_addr)) || in debugnet_handle_ip()
135 IN_LOOPBACK(ntohl(ip->ip_src.s_addr))) && in debugnet_handle_ip()
137 DNETDEBUG("Bad IP header (RFC1122)\n"); in debugnet_handle_ip()
145 DNETDEBUG("bad IP checksum\n"); in debugnet_handle_ip()
153 ip->ip_len = ntohs(ip->ip_len); in debugnet_handle_ip()
154 if (ip->ip_len < hlen) { in debugnet_handle_ip()
155 DNETDEBUG("IP packet smaller (%hu) than header (%hu)\n", in debugnet_handle_ip()
156 ip->ip_len, hlen); in debugnet_handle_ip()
159 if (m->m_pkthdr.len < ip->ip_len) { in debugnet_handle_ip()
160 DNETDEBUG("IP packet bigger (%hu) than ethernet packet (%d)\n", in debugnet_handle_ip()
161 ip->ip_len, m->m_pkthdr.len); in debugnet_handle_ip()
164 if (m->m_pkthdr.len > ip->ip_len) { in debugnet_handle_ip()
165 /* Truncate the packet to the IP length. */ in debugnet_handle_ip()
167 m->m_len = ip->ip_len; in debugnet_handle_ip()
168 m->m_pkthdr.len = ip->ip_len; in debugnet_handle_ip()
170 m_adj(m, ip->ip_len - m->m_pkthdr.len); in debugnet_handle_ip()
173 ip->ip_off = ntohs(ip->ip_off); in debugnet_handle_ip()
175 /* Check that the source is the server's IP. */ in debugnet_handle_ip()
176 if (ip->ip_src.s_addr != pcb->dp_server) { in debugnet_handle_ip()
178 ip->ip_src.s_addr); in debugnet_handle_ip()
182 /* Check if the destination IP is ours. */ in debugnet_handle_ip()
183 if (ip->ip_dst.s_addr != pcb->dp_client) { in debugnet_handle_ip()
184 DNETDEBUGV("drop packet not to our IP\n"); in debugnet_handle_ip()
188 if (ip->ip_p != IPPROTO_UDP) { in debugnet_handle_ip()
194 if ((ip->ip_off & (IP_MF | IP_OFFMASK)) != 0) { in debugnet_handle_ip()
208 /* UDP custom is to have packet length not include IP header. */ in debugnet_handle_ip()
209 ip->ip_len -= hlen; in debugnet_handle_ip()
211 /* Checked above before decoding IP header. */ in debugnet_handle_ip()
264 * 1. If the ARP is a request for our IP, respond with our MAC address
332 printf("%s: %*D is using my IP address %s!\n", __func__, in debugnet_handle_arp()
374 DNETDEBUG("ignoring ARP not to our IP\n"); in debugnet_handle_arp()
442 * ifp->if_mtu after adding the UDP/IP headers
456 struct ip *ip; in debugnet_ip_output() local
462 M_PREPEND(m, sizeof(*ip), M_NOWAIT); in debugnet_ip_output()
475 ip = mtod(m, void *); in debugnet_ip_output()
476 udp = (void *)(ip + 1); in debugnet_ip_output()
478 memset(ip, 0, offsetof(struct ip, ip_p)); in debugnet_ip_output()
479 ip->ip_p = IPPROTO_UDP; in debugnet_ip_output()
480 ip->ip_sum = udp->uh_ulen; in debugnet_ip_output()
481 ip->ip_src = (struct in_addr) { pcb->dp_client }; in debugnet_ip_output()
482 ip->ip_dst = (struct in_addr) { pcb->dp_server }; in debugnet_ip_output()
489 ip->ip_v = IPVERSION; in debugnet_ip_output()
490 ip->ip_hl = sizeof(*ip) >> 2; in debugnet_ip_output()
491 ip->ip_tos = 0; in debugnet_ip_output()
492 ip->ip_len = htons(m->m_pkthdr.len); in debugnet_ip_output()
493 ip->ip_id = 0; in debugnet_ip_output()
494 ip->ip_off = htons(IP_DF); in debugnet_ip_output()
495 ip->ip_ttl = 255; in debugnet_ip_output()
496 ip->ip_sum = 0; in debugnet_ip_output()
497 ip->ip_sum = in_cksum(m, sizeof(struct ip)); in debugnet_ip_output()