Lines Matching full:ip

51 #include <netinet/ip.h>
70 * Handler for IP packets: checks their sanity and then processes any debugnet
84 struct ip *ip; in debugnet_handle_ip() local
91 /* IP processing. */ in debugnet_handle_ip()
93 if (m->m_pkthdr.len < sizeof(struct ip)) { in debugnet_handle_ip()
94 DNETDEBUG("dropping packet too small for IP header\n"); in debugnet_handle_ip()
97 if (m->m_len < sizeof(struct ip)) { in debugnet_handle_ip()
98 m = m_pullup(m, sizeof(struct ip)); in debugnet_handle_ip()
105 ip = mtod(m, struct ip *); in debugnet_handle_ip()
107 /* IP version. */ in debugnet_handle_ip()
108 if (ip->ip_v != IPVERSION) { in debugnet_handle_ip()
109 DNETDEBUG("bad IP version %d\n", ip->ip_v); in debugnet_handle_ip()
114 hlen = ip->ip_hl << 2; in debugnet_handle_ip()
115 if (hlen < sizeof(struct ip)) { in debugnet_handle_ip()
116 DNETDEBUG("bad IP header length (%hu)\n", hlen); in debugnet_handle_ip()
126 ip = mtod(m, struct ip *); in debugnet_handle_ip()
128 /* Ignore packets with IP options. */ in debugnet_handle_ip()
129 if (hlen > sizeof(struct ip)) { in debugnet_handle_ip()
130 DNETDEBUG("drop packet with IP options\n"); in debugnet_handle_ip()
135 if ((IN_LOOPBACK(ntohl(ip->ip_dst.s_addr)) || in debugnet_handle_ip()
136 IN_LOOPBACK(ntohl(ip->ip_src.s_addr))) && in debugnet_handle_ip()
138 DNETDEBUG("Bad IP header (RFC1122)\n"); in debugnet_handle_ip()
146 DNETDEBUG("bad IP checksum\n"); in debugnet_handle_ip()
154 ip->ip_len = ntohs(ip->ip_len); in debugnet_handle_ip()
155 if (ip->ip_len < hlen) { in debugnet_handle_ip()
156 DNETDEBUG("IP packet smaller (%hu) than header (%hu)\n", in debugnet_handle_ip()
157 ip->ip_len, hlen); in debugnet_handle_ip()
160 if (m->m_pkthdr.len < ip->ip_len) { in debugnet_handle_ip()
161 DNETDEBUG("IP packet bigger (%hu) than ethernet packet (%d)\n", in debugnet_handle_ip()
162 ip->ip_len, m->m_pkthdr.len); in debugnet_handle_ip()
165 if (m->m_pkthdr.len > ip->ip_len) { in debugnet_handle_ip()
166 /* Truncate the packet to the IP length. */ in debugnet_handle_ip()
168 m->m_len = ip->ip_len; in debugnet_handle_ip()
169 m->m_pkthdr.len = ip->ip_len; in debugnet_handle_ip()
171 m_adj(m, ip->ip_len - m->m_pkthdr.len); in debugnet_handle_ip()
174 ip->ip_off = ntohs(ip->ip_off); in debugnet_handle_ip()
176 /* Check that the source is the server's IP. */ in debugnet_handle_ip()
177 if (ip->ip_src.s_addr != pcb->dp_server) { in debugnet_handle_ip()
179 ip->ip_src.s_addr); in debugnet_handle_ip()
183 /* Check if the destination IP is ours. */ in debugnet_handle_ip()
184 if (ip->ip_dst.s_addr != pcb->dp_client) { in debugnet_handle_ip()
185 DNETDEBUGV("drop packet not to our IP\n"); in debugnet_handle_ip()
189 if (ip->ip_p != IPPROTO_UDP) { in debugnet_handle_ip()
195 if ((ip->ip_off & (IP_MF | IP_OFFMASK)) != 0) { in debugnet_handle_ip()
209 /* UDP custom is to have packet length not include IP header. */ in debugnet_handle_ip()
210 ip->ip_len -= hlen; in debugnet_handle_ip()
212 /* Checked above before decoding IP header. */ in debugnet_handle_ip()
265 * 1. If the ARP is a request for our IP, respond with our MAC address
333 printf("%s: %*D is using my IP address %s!\n", __func__, in debugnet_handle_arp()
375 DNETDEBUG("ignoring ARP not to our IP\n"); in debugnet_handle_arp()
443 * ifp->if_mtu after adding the UDP/IP headers
457 struct ip *ip; in debugnet_ip_output() local
463 M_PREPEND(m, sizeof(*ip), M_NOWAIT); in debugnet_ip_output()
476 ip = mtod(m, void *); in debugnet_ip_output()
477 udp = (void *)(ip + 1); in debugnet_ip_output()
479 memset(ip, 0, offsetof(struct ip, ip_p)); in debugnet_ip_output()
480 ip->ip_p = IPPROTO_UDP; in debugnet_ip_output()
481 ip->ip_sum = udp->uh_ulen; in debugnet_ip_output()
482 ip->ip_src = (struct in_addr) { pcb->dp_client }; in debugnet_ip_output()
483 ip->ip_dst = (struct in_addr) { pcb->dp_server }; in debugnet_ip_output()
490 ip->ip_v = IPVERSION; in debugnet_ip_output()
491 ip->ip_hl = sizeof(*ip) >> 2; in debugnet_ip_output()
492 ip->ip_tos = 0; in debugnet_ip_output()
493 ip->ip_len = htons(m->m_pkthdr.len); in debugnet_ip_output()
494 ip->ip_id = 0; in debugnet_ip_output()
495 ip->ip_off = htons(IP_DF); in debugnet_ip_output()
496 ip->ip_ttl = 255; in debugnet_ip_output()
497 ip->ip_sum = 0; in debugnet_ip_output()
498 ip->ip_sum = in_cksum(m, sizeof(struct ip)); in debugnet_ip_output()