2004-04-22 00:10:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1982, 1986, 1988, 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
Remove the advertising clause from the slirp license
According to the FSF, the 4-clause BSD license, which slirp is covered under,
is not compatible with the GPL or LGPL[1].
[1] http://www.fsf.org/licensing/licenses/index_html#GPLIncompatibleLicenses
There are three declared copyright holders in slirp that use the 4-clause
BSD license, the Regents of UC Berkley, Danny Gasparovski, and Kelly Price.
Below are the appropriate permissions to remove the advertise clause from slirp
from each party.
Special thanks go to Richard Fontana from Red Hat for contacting all of the
necessary authors to resolve this issue!
Regents of UC Berkley:
From ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
July 22, 1999
To All Licensees, Distributors of Any Version of BSD:
As you know, certain of the Berkeley Software Distribution ("BSD") source
code files require that further distributions of products containing all or
portions of the software, acknowledge within their advertising materials
that such products contain software developed by UC Berkeley and its
contributors.
Specifically, the provision reads:
" * 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors."
Effective immediately, licensees and distributors are no longer required to
include the acknowledgement within advertising materials. Accordingly, the
foregoing paragraph of those BSD Unix files containing it is hereby deleted
in its entirety.
William Hoskins
Director, Office of Technology Licensing
University of California, Berkeley
Danny Gasparovski:
Subject: RE: Slirp license
Date: Thu, 8 Jan 2009 10:51:00 +1100
From: "Gasparovski, Daniel" <Daniel.Gasparovski@ato.gov.au>
To: "Richard Fontana" <rfontana@redhat.com>
Hi Richard,
I have no objection to having Slirp code in QEMU be licensed under the
3-clause BSD license.
Thanks for taking the effort to consult me about this.
Dan ...
Kelly Price:
Date: Thu, 8 Jan 2009 19:38:56 -0500
From: "Kelly Price" <strredwolf@gmail.com>
To: "Richard Fontana" <rfontana@redhat.com>
Subject: Re: Slirp license
Thanks for contacting me, Richard. I'm glad you were able to find
Dan, as I've been "keeping the light on" for Slirp. I have no use for
it now, and I have little time for it (now holding onto Keenspot's
Comic Genesis and having a regular US state government position). If
Dan would like to return to the project, I'd love to give it back to
him.
As for copyright, I don't own all of it. Dan does, so I will defer to
him. Any of my patches I will gladly license to the 3-part BSD
license. My interest in re-licensing was because we didn't have ready
info to contact Dan. If Dan would like to port Slirp back out of
QEMU, a lot of us 64-bit users would be grateful.
Feel free to share this email address with Dan. I will be glad to
effect a transfer of the project to him and Mr. Bellard of the QEMU
project.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6451 c046a42c-6fe2-441c-8c8c-71466251a162
2009-01-26 19:37:41 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2004-04-22 00:10:48 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)udp_usrreq.c 8.4 (Berkeley) 1/21/94
|
|
|
|
* udp_usrreq.c,v 1.4 1994/10/02 17:48:45 phk Exp
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Changes and additions relating to SLiRP
|
|
|
|
* Copyright (c) 1995 Danny Gasparovski.
|
2007-09-16 21:08:06 +00:00
|
|
|
*
|
|
|
|
* Please read the file COPYRIGHT for the
|
2004-04-22 00:10:48 +00:00
|
|
|
* terms and conditions of the copyright.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <slirp.h>
|
|
|
|
#include "ip_icmp.h"
|
|
|
|
|
2010-07-22 20:15:23 +00:00
|
|
|
static uint8_t udp_tos(struct socket *so);
|
2007-10-26 19:01:16 +00:00
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
void
|
2009-06-24 12:42:31 +00:00
|
|
|
udp_init(Slirp *slirp)
|
2004-04-22 00:10:48 +00:00
|
|
|
{
|
2009-06-24 12:42:31 +00:00
|
|
|
slirp->udb.so_next = slirp->udb.so_prev = &slirp->udb;
|
|
|
|
slirp->udp_last_so = &slirp->udb;
|
2004-04-22 00:10:48 +00:00
|
|
|
}
|
2012-02-29 18:14:23 +00:00
|
|
|
|
|
|
|
void udp_cleanup(Slirp *slirp)
|
|
|
|
{
|
|
|
|
while (slirp->udb.so_next != &slirp->udb) {
|
|
|
|
udp_detach(slirp->udb.so_next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 21:08:06 +00:00
|
|
|
/* m->m_data points at ip packet header
|
|
|
|
* m->m_len length ip packet
|
2004-04-22 00:10:48 +00:00
|
|
|
* ip->ip_len length data (IPDU)
|
|
|
|
*/
|
|
|
|
void
|
2009-04-18 07:32:41 +00:00
|
|
|
udp_input(register struct mbuf *m, int iphlen)
|
2004-04-22 00:10:48 +00:00
|
|
|
{
|
2009-06-24 12:42:31 +00:00
|
|
|
Slirp *slirp = m->slirp;
|
2004-04-22 00:10:48 +00:00
|
|
|
register struct ip *ip;
|
|
|
|
register struct udphdr *uh;
|
|
|
|
int len;
|
2007-09-16 21:08:06 +00:00
|
|
|
struct ip save_ip;
|
2004-04-22 00:10:48 +00:00
|
|
|
struct socket *so;
|
2007-09-16 21:08:06 +00:00
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
DEBUG_CALL("udp_input");
|
|
|
|
DEBUG_ARG("m = %lx", (long)m);
|
|
|
|
DEBUG_ARG("iphlen = %d", iphlen);
|
2007-09-16 21:08:06 +00:00
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
if(iphlen > sizeof(struct ip)) {
|
|
|
|
ip_stripoptions(m, (struct mbuf *)0);
|
|
|
|
iphlen = sizeof(struct ip);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get IP and UDP header together in first mbuf.
|
|
|
|
*/
|
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
uh = (struct udphdr *)((caddr_t)ip + iphlen);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make mbuf data length reflect UDP length.
|
|
|
|
* If not enough data to reflect UDP length, drop.
|
|
|
|
*/
|
2010-07-22 20:15:23 +00:00
|
|
|
len = ntohs((uint16_t)uh->uh_ulen);
|
2004-04-22 00:10:48 +00:00
|
|
|
|
|
|
|
if (ip->ip_len != len) {
|
|
|
|
if (len > ip->ip_len) {
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
m_adj(m, len - ip->ip_len);
|
|
|
|
ip->ip_len = len;
|
|
|
|
}
|
2007-09-16 21:08:06 +00:00
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
/*
|
|
|
|
* Save a copy of the IP header in case we want restore it
|
|
|
|
* for sending an ICMP error message in response.
|
|
|
|
*/
|
2007-09-16 21:08:06 +00:00
|
|
|
save_ip = *ip;
|
2004-04-22 00:10:48 +00:00
|
|
|
save_ip.ip_len+= iphlen; /* tcp_input subtracts this */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Checksum extended UDP header and data.
|
|
|
|
*/
|
2009-06-24 12:42:29 +00:00
|
|
|
if (uh->uh_sum) {
|
2009-01-13 19:48:42 +00:00
|
|
|
memset(&((struct ipovly *)ip)->ih_mbuf, 0, sizeof(struct mbuf_ptr));
|
2004-04-22 00:10:48 +00:00
|
|
|
((struct ipovly *)ip)->ih_x1 = 0;
|
|
|
|
((struct ipovly *)ip)->ih_len = uh->uh_ulen;
|
|
|
|
if(cksum(m, len + sizeof(struct ip))) {
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handle DHCP/BOOTP
|
|
|
|
*/
|
2011-07-20 10:20:15 +00:00
|
|
|
if (ntohs(uh->uh_dport) == BOOTP_SERVER &&
|
|
|
|
(ip->ip_dst.s_addr == slirp->vhost_addr.s_addr ||
|
|
|
|
ip->ip_dst.s_addr == 0xffffffff)) {
|
|
|
|
bootp_input(m);
|
|
|
|
goto bad;
|
|
|
|
}
|
2004-04-22 00:10:48 +00:00
|
|
|
|
2004-08-24 21:57:12 +00:00
|
|
|
/*
|
|
|
|
* handle TFTP
|
|
|
|
*/
|
2011-07-20 10:20:15 +00:00
|
|
|
if (ntohs(uh->uh_dport) == TFTP_SERVER &&
|
|
|
|
ip->ip_dst.s_addr == slirp->vhost_addr.s_addr) {
|
2004-08-24 21:57:12 +00:00
|
|
|
tftp_input(m);
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2011-07-20 10:20:13 +00:00
|
|
|
if (slirp->restricted) {
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
/*
|
|
|
|
* Locate pcb for datagram.
|
|
|
|
*/
|
2009-06-24 12:42:31 +00:00
|
|
|
so = slirp->udp_last_so;
|
2004-04-22 00:10:48 +00:00
|
|
|
if (so->so_lport != uh->uh_sport ||
|
|
|
|
so->so_laddr.s_addr != ip->ip_src.s_addr) {
|
|
|
|
struct socket *tmp;
|
2007-09-17 08:09:54 +00:00
|
|
|
|
2009-06-24 12:42:31 +00:00
|
|
|
for (tmp = slirp->udb.so_next; tmp != &slirp->udb;
|
|
|
|
tmp = tmp->so_next) {
|
2004-04-22 00:10:48 +00:00
|
|
|
if (tmp->so_lport == uh->uh_sport &&
|
|
|
|
tmp->so_laddr.s_addr == ip->ip_src.s_addr) {
|
|
|
|
so = tmp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-06-24 12:42:31 +00:00
|
|
|
if (tmp == &slirp->udb) {
|
2004-04-22 00:10:48 +00:00
|
|
|
so = NULL;
|
|
|
|
} else {
|
2009-06-24 12:42:31 +00:00
|
|
|
slirp->udp_last_so = so;
|
2004-04-22 00:10:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 21:08:06 +00:00
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
if (so == NULL) {
|
|
|
|
/*
|
|
|
|
* If there's no socket for this packet,
|
|
|
|
* create one
|
|
|
|
*/
|
2009-06-24 12:42:31 +00:00
|
|
|
so = socreate(slirp);
|
|
|
|
if (!so) {
|
|
|
|
goto bad;
|
|
|
|
}
|
2004-04-22 00:10:48 +00:00
|
|
|
if(udp_attach(so) == -1) {
|
2007-09-16 21:08:06 +00:00
|
|
|
DEBUG_MISC((dfd," udp_attach errno = %d-%s\n",
|
2004-04-22 00:10:48 +00:00
|
|
|
errno,strerror(errno)));
|
|
|
|
sofree(so);
|
|
|
|
goto bad;
|
|
|
|
}
|
2007-09-17 08:09:54 +00:00
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
/*
|
|
|
|
* Setup fields
|
|
|
|
*/
|
|
|
|
so->so_laddr = ip->ip_src;
|
|
|
|
so->so_lport = uh->uh_sport;
|
2007-09-17 08:09:54 +00:00
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
if ((so->so_iptos = udp_tos(so)) == 0)
|
|
|
|
so->so_iptos = ip->ip_tos;
|
2007-09-17 08:09:54 +00:00
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
/*
|
|
|
|
* XXXXX Here, check if it's in udpexec_list,
|
|
|
|
* and if it is, do the fork_exec() etc.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2007-01-17 22:47:40 +00:00
|
|
|
so->so_faddr = ip->ip_dst; /* XXX */
|
|
|
|
so->so_fport = uh->uh_dport; /* XXX */
|
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
iphlen += sizeof(struct udphdr);
|
|
|
|
m->m_len -= iphlen;
|
|
|
|
m->m_data += iphlen;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now we sendto() the packet.
|
|
|
|
*/
|
|
|
|
if(sosendto(so,m) == -1) {
|
|
|
|
m->m_len += iphlen;
|
|
|
|
m->m_data -= iphlen;
|
|
|
|
*ip=save_ip;
|
|
|
|
DEBUG_MISC((dfd,"udp tx errno = %d-%s\n",errno,strerror(errno)));
|
2007-09-17 08:09:54 +00:00
|
|
|
icmp_error(m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno));
|
2004-04-22 00:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_free(so->so_m); /* used for ICMP if error on sorecvfrom */
|
|
|
|
|
|
|
|
/* restore the orig mbuf packet */
|
|
|
|
m->m_len += iphlen;
|
|
|
|
m->m_data -= iphlen;
|
|
|
|
*ip=save_ip;
|
|
|
|
so->so_m=m; /* ICMP backup */
|
|
|
|
|
|
|
|
return;
|
|
|
|
bad:
|
2011-07-20 10:20:16 +00:00
|
|
|
m_free(m);
|
2004-04-22 00:10:48 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 21:08:06 +00:00
|
|
|
int udp_output2(struct socket *so, struct mbuf *m,
|
2004-04-22 00:10:48 +00:00
|
|
|
struct sockaddr_in *saddr, struct sockaddr_in *daddr,
|
|
|
|
int iptos)
|
|
|
|
{
|
|
|
|
register struct udpiphdr *ui;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
DEBUG_CALL("udp_output");
|
|
|
|
DEBUG_ARG("so = %lx", (long)so);
|
|
|
|
DEBUG_ARG("m = %lx", (long)m);
|
|
|
|
DEBUG_ARG("saddr = %lx", (long)saddr->sin_addr.s_addr);
|
|
|
|
DEBUG_ARG("daddr = %lx", (long)daddr->sin_addr.s_addr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjust for header
|
|
|
|
*/
|
|
|
|
m->m_data -= sizeof(struct udpiphdr);
|
|
|
|
m->m_len += sizeof(struct udpiphdr);
|
2007-09-16 21:08:06 +00:00
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
/*
|
|
|
|
* Fill in mbuf with extended UDP header
|
|
|
|
* and addresses and length put into network format.
|
|
|
|
*/
|
|
|
|
ui = mtod(m, struct udpiphdr *);
|
2009-01-13 19:48:42 +00:00
|
|
|
memset(&ui->ui_i.ih_mbuf, 0 , sizeof(struct mbuf_ptr));
|
2004-04-22 00:10:48 +00:00
|
|
|
ui->ui_x1 = 0;
|
|
|
|
ui->ui_pr = IPPROTO_UDP;
|
2009-06-24 12:42:29 +00:00
|
|
|
ui->ui_len = htons(m->m_len - sizeof(struct ip));
|
2004-04-22 00:10:48 +00:00
|
|
|
/* XXXXX Check for from-one-location sockets, or from-any-location sockets */
|
|
|
|
ui->ui_src = saddr->sin_addr;
|
|
|
|
ui->ui_dst = daddr->sin_addr;
|
|
|
|
ui->ui_sport = saddr->sin_port;
|
|
|
|
ui->ui_dport = daddr->sin_port;
|
|
|
|
ui->ui_ulen = ui->ui_len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stuff checksum and output datagram.
|
|
|
|
*/
|
|
|
|
ui->ui_sum = 0;
|
2009-06-24 12:42:29 +00:00
|
|
|
if ((ui->ui_sum = cksum(m, m->m_len)) == 0)
|
2004-04-22 00:10:48 +00:00
|
|
|
ui->ui_sum = 0xffff;
|
|
|
|
((struct ip *)ui)->ip_len = m->m_len;
|
|
|
|
|
2007-10-26 19:01:16 +00:00
|
|
|
((struct ip *)ui)->ip_ttl = IPDEFTTL;
|
2004-04-22 00:10:48 +00:00
|
|
|
((struct ip *)ui)->ip_tos = iptos;
|
2007-09-16 21:08:06 +00:00
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
error = ip_output(so, m);
|
2007-09-16 21:08:06 +00:00
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2007-09-16 21:08:06 +00:00
|
|
|
int udp_output(struct socket *so, struct mbuf *m,
|
2004-04-22 00:10:48 +00:00
|
|
|
struct sockaddr_in *addr)
|
|
|
|
|
|
|
|
{
|
2009-06-24 12:42:31 +00:00
|
|
|
Slirp *slirp = so->slirp;
|
2004-04-22 00:10:48 +00:00
|
|
|
struct sockaddr_in saddr, daddr;
|
|
|
|
|
|
|
|
saddr = *addr;
|
2009-06-24 12:42:31 +00:00
|
|
|
if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) ==
|
|
|
|
slirp->vnetwork_addr.s_addr) {
|
|
|
|
uint32_t inv_mask = ~slirp->vnetwork_mask.s_addr;
|
|
|
|
|
|
|
|
if ((so->so_faddr.s_addr & inv_mask) == inv_mask) {
|
|
|
|
saddr.sin_addr = slirp->vhost_addr;
|
2009-06-24 12:42:28 +00:00
|
|
|
} else if (addr->sin_addr.s_addr == loopback_addr.s_addr ||
|
2009-06-24 12:42:31 +00:00
|
|
|
so->so_faddr.s_addr != slirp->vhost_addr.s_addr) {
|
2009-06-24 12:42:28 +00:00
|
|
|
saddr.sin_addr = so->so_faddr;
|
|
|
|
}
|
2006-05-03 20:53:46 +00:00
|
|
|
}
|
2004-04-22 00:10:48 +00:00
|
|
|
daddr.sin_addr = so->so_laddr;
|
|
|
|
daddr.sin_port = so->so_lport;
|
2007-09-17 08:09:54 +00:00
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
return udp_output2(so, m, &saddr, &daddr, so->so_iptos);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-04-18 07:32:41 +00:00
|
|
|
udp_attach(struct socket *so)
|
2004-04-22 00:10:48 +00:00
|
|
|
{
|
2009-12-02 11:24:42 +00:00
|
|
|
if((so->s = qemu_socket(AF_INET,SOCK_DGRAM,0)) != -1) {
|
2009-07-23 00:53:15 +00:00
|
|
|
so->so_expire = curtime + SO_EXPIRE;
|
|
|
|
insque(so, &so->slirp->udb);
|
2004-04-22 00:10:48 +00:00
|
|
|
}
|
|
|
|
return(so->s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-04-18 07:32:41 +00:00
|
|
|
udp_detach(struct socket *so)
|
2004-04-22 00:10:48 +00:00
|
|
|
{
|
2004-07-12 22:33:07 +00:00
|
|
|
closesocket(so->s);
|
2004-04-22 00:10:48 +00:00
|
|
|
sofree(so);
|
|
|
|
}
|
|
|
|
|
2007-10-26 19:01:16 +00:00
|
|
|
static const struct tos_t udptos[] = {
|
2004-04-22 00:10:48 +00:00
|
|
|
{0, 53, IPTOS_LOWDELAY, 0}, /* DNS */
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2010-07-22 20:15:23 +00:00
|
|
|
static uint8_t
|
2007-10-26 19:01:16 +00:00
|
|
|
udp_tos(struct socket *so)
|
2004-04-22 00:10:48 +00:00
|
|
|
{
|
|
|
|
int i = 0;
|
2007-09-16 21:08:06 +00:00
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
while(udptos[i].tos) {
|
|
|
|
if ((udptos[i].fport && ntohs(so->so_fport) == udptos[i].fport) ||
|
|
|
|
(udptos[i].lport && ntohs(so->so_lport) == udptos[i].lport)) {
|
|
|
|
so->so_emu = udptos[i].emu;
|
|
|
|
return udptos[i].tos;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2007-09-16 21:08:06 +00:00
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct socket *
|
2010-07-22 20:15:23 +00:00
|
|
|
udp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr,
|
2009-06-24 12:42:31 +00:00
|
|
|
u_int lport, int flags)
|
2004-04-22 00:10:48 +00:00
|
|
|
{
|
|
|
|
struct sockaddr_in addr;
|
|
|
|
struct socket *so;
|
2008-05-10 01:49:53 +00:00
|
|
|
socklen_t addrlen = sizeof(struct sockaddr_in), opt = 1;
|
2007-09-16 21:08:06 +00:00
|
|
|
|
2009-06-24 12:42:31 +00:00
|
|
|
so = socreate(slirp);
|
|
|
|
if (!so) {
|
|
|
|
return NULL;
|
2004-04-22 00:10:48 +00:00
|
|
|
}
|
2009-12-02 11:24:42 +00:00
|
|
|
so->s = qemu_socket(AF_INET,SOCK_DGRAM,0);
|
2004-04-22 00:10:48 +00:00
|
|
|
so->so_expire = curtime + SO_EXPIRE;
|
2009-06-24 12:42:31 +00:00
|
|
|
insque(so, &slirp->udb);
|
2004-04-22 00:10:48 +00:00
|
|
|
|
|
|
|
addr.sin_family = AF_INET;
|
2009-06-24 12:42:28 +00:00
|
|
|
addr.sin_addr.s_addr = haddr;
|
|
|
|
addr.sin_port = hport;
|
2004-04-22 00:10:48 +00:00
|
|
|
|
|
|
|
if (bind(so->s,(struct sockaddr *)&addr, addrlen) < 0) {
|
|
|
|
udp_detach(so);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
|
2007-09-16 21:08:06 +00:00
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
getsockname(so->s,(struct sockaddr *)&addr,&addrlen);
|
|
|
|
so->so_fport = addr.sin_port;
|
2009-06-24 12:42:28 +00:00
|
|
|
if (addr.sin_addr.s_addr == 0 ||
|
|
|
|
addr.sin_addr.s_addr == loopback_addr.s_addr) {
|
2009-06-24 12:42:31 +00:00
|
|
|
so->so_faddr = slirp->vhost_addr;
|
2009-06-24 12:42:28 +00:00
|
|
|
} else {
|
2004-04-22 00:10:48 +00:00
|
|
|
so->so_faddr = addr.sin_addr;
|
2009-06-24 12:42:28 +00:00
|
|
|
}
|
2004-04-22 00:10:48 +00:00
|
|
|
so->so_lport = lport;
|
|
|
|
so->so_laddr.s_addr = laddr;
|
|
|
|
if (flags != SS_FACCEPTONCE)
|
|
|
|
so->so_expire = 0;
|
2007-09-16 21:08:06 +00:00
|
|
|
|
2009-06-24 12:42:29 +00:00
|
|
|
so->so_state &= SS_PERSISTENT_MASK;
|
2009-06-24 12:42:29 +00:00
|
|
|
so->so_state |= SS_ISFCONNECTED | flags;
|
2007-09-16 21:08:06 +00:00
|
|
|
|
2004-04-22 00:10:48 +00:00
|
|
|
return so;
|
|
|
|
}
|