udp.c revision 8c2d9d7577b4de8ac96614f700b1ec83e0745336
2N/A * Copyright (c) 1982, 1986, 1988, 1990, 1993 2N/A * The Regents of the University of California. All rights reserved. 2N/A * Redistribution and use in source and binary forms, with or without 2N/A * modification, are permitted provided that the following conditions 2N/A * 1. Redistributions of source code must retain the above copyright 2N/A * notice, this list of conditions and the following disclaimer. 2N/A * 2. Redistributions in binary form must reproduce the above copyright 2N/A * notice, this list of conditions and the following disclaimer in the 2N/A * documentation and/or other materials provided with the distribution. 2N/A * 3. All advertising materials mentioning features or use of this software 2N/A * must display the following acknowledgement: 2N/A * This product includes software developed by the University of 2N/A * California, Berkeley and its contributors. 2N/A * 4. Neither the name of the University nor the names of its contributors 2N/A * may be used to endorse or promote products derived from this software 2N/A * without specific prior written permission. 2N/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2N/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2N/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2N/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2N/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2N/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2N/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * Changes and additions relating to SLiRP * Copyright (c) 1995 Danny Gasparovski. * Please read the file COPYRIGHT for the * terms and conditions of the copyright. * UDP protocol implementation. * Per RFC 768, August, 1980. /* m->m_data points at ip packet header * m->m_len length ip packet * ip->ip_len length data (IPDU) * Strip IP options, if any; should skip this, * make available to user, and use on returned packets, * but we don't yet have a way to check the checksum * with options still present. * Get IP and UDP header together in first mbuf. * Make mbuf data length reflect UDP length. * If not enough data to reflect UDP length, drop. * Save a copy of the IP header in case we want restore it * for sending an ICMP error message in response. * Checksum extended UDP header and data. /* keep uh_sum for ICMP reply */ Log3((
"NAT: IP(id: %hd) has bad (udp) cksum\n",
ip->
ip_id));
/* udp_output2 will do opposite operations on mbuf*/ * Locate pcb for datagram. * If there's no socket for this packet, Log3((
"NAT: IP(id: %hd) failed to create socket\n",
ip->
ip_id));
Log3((
"NAT: IP(id: %hd) udp_attach errno = %d-%s\n",
* XXXXX Here, check if it's in udpexec_list, * and if it is, do the fork_exec() etc. * Now we sendto() the packet. LogRel((
"NAT: Error (%s) occurred while setting TTL(%d) attribute " /* in case we receive ICMP on this socket we'll aware that ICMP has been already sent to host*/ /* restore the orig mbuf packet */ so->
so_m = m;
/* ICMP backup */ Log2((
"NAT: UDP(id: %hd) datagram to %R[IP4] with size(%d) claimed as bad\n",
/* some services like bootp(built-in), dns(buildt-in) and dhcp don't need sockets * and create new m'buffers to send them to guest, so we'll free their incomming * Fill in mbuf with extended UDP header * and addresses and length put into network format. /* XXXXX Check for from-one-location sockets, or from-any-location sockets */ * Stuff checksum and output datagram. /* Any UDP packet to the loopback address must be translated to be from * the forwarding address, i.e. 10.0.2.2. */ * Here, we bind() the socket. Although not really needed * (sendto() on an unbound socket will bind it), it's done * here so that emulation of ytalk etc. don't have to do it /* success, insert in queue */ /* enable broadcast for later use */ LogRel((
"NAT: can't create datagramm socket\n"));
LogRel((
"NAT: can't create datagram socket\n"));
/* setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE,(char *)&opt, sizeof(int)); */ /* The original check was completely broken, as the commented out * if statement was always true (INADDR_ANY=0). */ if (
1 == 0)
/* always use the else part */