2004-04-22 02:10:48 +02:00
|
|
|
/*
|
|
|
|
* QEMU BOOTP/DHCP server
|
2007-09-16 23:08:06 +02:00
|
|
|
*
|
2004-04-22 02:10:48 +02:00
|
|
|
* Copyright (c) 2004 Fabrice Bellard
|
2007-09-16 23:08:06 +02:00
|
|
|
*
|
2004-04-22 02:10:48 +02:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2016-01-29 18:49:59 +01:00
|
|
|
#include "qemu/osdep.h"
|
2016-06-22 19:11:19 +02:00
|
|
|
#include "slirp.h"
|
2004-04-22 02:10:48 +02:00
|
|
|
|
2015-08-29 09:12:35 +02:00
|
|
|
#if defined(_WIN32)
|
|
|
|
/* Windows ntohl() returns an u_long value.
|
|
|
|
* Add a type cast to match the format strings. */
|
|
|
|
# define ntohl(n) ((uint32_t)ntohl(n))
|
|
|
|
#endif
|
|
|
|
|
2004-04-22 02:10:48 +02:00
|
|
|
/* XXX: only DHCP is supported */
|
|
|
|
|
|
|
|
#define LEASE_TIME (24 * 3600)
|
|
|
|
|
|
|
|
static const uint8_t rfc1533_cookie[] = { RFC1533_COOKIE };
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-02-07 00:03:50 +01:00
|
|
|
#define DPRINTF(fmt, ...) \
|
2009-06-24 14:42:29 +02:00
|
|
|
do if (slirp_debug & DBG_CALL) { fprintf(dfd, fmt, ## __VA_ARGS__); fflush(dfd); } while (0)
|
2004-04-22 02:10:48 +02:00
|
|
|
#else
|
2010-08-31 09:30:37 +02:00
|
|
|
#define DPRINTF(fmt, ...) do{}while(0)
|
2004-04-22 02:10:48 +02:00
|
|
|
#endif
|
|
|
|
|
2009-06-24 14:42:31 +02:00
|
|
|
static BOOTPClient *get_new_addr(Slirp *slirp, struct in_addr *paddr,
|
2009-05-21 22:43:39 +02:00
|
|
|
const uint8_t *macaddr)
|
2004-04-22 02:10:48 +02:00
|
|
|
{
|
|
|
|
BOOTPClient *bc;
|
|
|
|
int i;
|
|
|
|
|
2009-06-24 14:42:31 +02:00
|
|
|
for(i = 0; i < NB_BOOTP_CLIENTS; i++) {
|
|
|
|
bc = &slirp->bootp_clients[i];
|
2009-05-21 22:43:39 +02:00
|
|
|
if (!bc->allocated || !memcmp(macaddr, bc->macaddr, 6))
|
2004-04-22 02:10:48 +02:00
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
found:
|
2009-06-24 14:42:31 +02:00
|
|
|
bc = &slirp->bootp_clients[i];
|
2004-04-22 02:10:48 +02:00
|
|
|
bc->allocated = 1;
|
2009-06-24 14:42:31 +02:00
|
|
|
paddr->s_addr = slirp->vdhcp_startaddr.s_addr + htonl(i);
|
2004-04-22 02:10:48 +02:00
|
|
|
return bc;
|
|
|
|
}
|
|
|
|
|
2009-06-24 14:42:31 +02:00
|
|
|
static BOOTPClient *request_addr(Slirp *slirp, const struct in_addr *paddr,
|
2009-04-21 21:56:20 +02:00
|
|
|
const uint8_t *macaddr)
|
|
|
|
{
|
|
|
|
uint32_t req_addr = ntohl(paddr->s_addr);
|
2009-06-24 14:42:31 +02:00
|
|
|
uint32_t dhcp_addr = ntohl(slirp->vdhcp_startaddr.s_addr);
|
2009-04-21 21:56:20 +02:00
|
|
|
BOOTPClient *bc;
|
|
|
|
|
2009-06-24 14:42:28 +02:00
|
|
|
if (req_addr >= dhcp_addr &&
|
2009-06-24 14:42:31 +02:00
|
|
|
req_addr < (dhcp_addr + NB_BOOTP_CLIENTS)) {
|
|
|
|
bc = &slirp->bootp_clients[req_addr - dhcp_addr];
|
2009-04-21 21:56:20 +02:00
|
|
|
if (!bc->allocated || !memcmp(macaddr, bc->macaddr, 6)) {
|
|
|
|
bc->allocated = 1;
|
|
|
|
return bc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-06-24 14:42:31 +02:00
|
|
|
static BOOTPClient *find_addr(Slirp *slirp, struct in_addr *paddr,
|
|
|
|
const uint8_t *macaddr)
|
2004-05-04 05:14:47 +02:00
|
|
|
{
|
|
|
|
BOOTPClient *bc;
|
|
|
|
int i;
|
|
|
|
|
2009-06-24 14:42:31 +02:00
|
|
|
for(i = 0; i < NB_BOOTP_CLIENTS; i++) {
|
|
|
|
if (!memcmp(macaddr, slirp->bootp_clients[i].macaddr, 6))
|
2004-05-04 05:14:47 +02:00
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
found:
|
2009-06-24 14:42:31 +02:00
|
|
|
bc = &slirp->bootp_clients[i];
|
2004-05-04 05:14:47 +02:00
|
|
|
bc->allocated = 1;
|
2009-06-24 14:42:31 +02:00
|
|
|
paddr->s_addr = slirp->vdhcp_startaddr.s_addr + htonl(i);
|
2004-05-04 05:14:47 +02:00
|
|
|
return bc;
|
|
|
|
}
|
|
|
|
|
2009-04-21 21:56:20 +02:00
|
|
|
static void dhcp_decode(const struct bootp_t *bp, int *pmsg_type,
|
2011-01-06 22:43:13 +01:00
|
|
|
struct in_addr *preq_addr)
|
2004-04-22 02:10:48 +02:00
|
|
|
{
|
|
|
|
const uint8_t *p, *p_end;
|
|
|
|
int len, tag;
|
|
|
|
|
2007-09-17 10:09:54 +02:00
|
|
|
*pmsg_type = 0;
|
2011-01-06 22:43:13 +01:00
|
|
|
preq_addr->s_addr = htonl(0L);
|
2004-04-22 02:10:48 +02:00
|
|
|
|
2009-04-21 21:56:20 +02:00
|
|
|
p = bp->bp_vend;
|
|
|
|
p_end = p + DHCP_OPT_LEN;
|
2004-04-22 02:10:48 +02:00
|
|
|
if (memcmp(p, rfc1533_cookie, 4) != 0)
|
|
|
|
return;
|
|
|
|
p += 4;
|
|
|
|
while (p < p_end) {
|
|
|
|
tag = p[0];
|
|
|
|
if (tag == RFC1533_PAD) {
|
2007-09-16 23:08:06 +02:00
|
|
|
p++;
|
2004-04-22 02:10:48 +02:00
|
|
|
} else if (tag == RFC1533_END) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
p++;
|
|
|
|
if (p >= p_end)
|
|
|
|
break;
|
|
|
|
len = *p++;
|
2017-07-17 14:03:26 +02:00
|
|
|
if (p + len > p_end) {
|
|
|
|
break;
|
|
|
|
}
|
2010-02-07 00:03:50 +01:00
|
|
|
DPRINTF("dhcp: tag=%d len=%d\n", tag, len);
|
2004-04-22 02:10:48 +02:00
|
|
|
|
|
|
|
switch(tag) {
|
|
|
|
case RFC2132_MSG_TYPE:
|
|
|
|
if (len >= 1)
|
|
|
|
*pmsg_type = p[0];
|
|
|
|
break;
|
2009-04-21 21:56:20 +02:00
|
|
|
case RFC2132_REQ_ADDR:
|
2011-01-06 22:43:13 +01:00
|
|
|
if (len >= 4) {
|
|
|
|
memcpy(&(preq_addr->s_addr), p, 4);
|
|
|
|
}
|
2009-04-21 21:56:20 +02:00
|
|
|
break;
|
2004-04-22 02:10:48 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p += len;
|
|
|
|
}
|
|
|
|
}
|
2011-01-06 22:43:13 +01:00
|
|
|
if (*pmsg_type == DHCPREQUEST && preq_addr->s_addr == htonl(0L) &&
|
|
|
|
bp->bp_ciaddr.s_addr) {
|
|
|
|
memcpy(&(preq_addr->s_addr), &bp->bp_ciaddr, 4);
|
2009-04-21 21:56:20 +02:00
|
|
|
}
|
2004-04-22 02:10:48 +02:00
|
|
|
}
|
|
|
|
|
2009-06-24 14:42:31 +02:00
|
|
|
static void bootp_reply(Slirp *slirp, const struct bootp_t *bp)
|
2004-04-22 02:10:48 +02:00
|
|
|
{
|
2009-04-21 21:56:20 +02:00
|
|
|
BOOTPClient *bc = NULL;
|
2004-04-22 02:10:48 +02:00
|
|
|
struct mbuf *m;
|
|
|
|
struct bootp_t *rbp;
|
|
|
|
struct sockaddr_in saddr, daddr;
|
2011-01-06 22:43:13 +01:00
|
|
|
struct in_addr preq_addr;
|
2004-04-22 02:10:48 +02:00
|
|
|
int dhcp_msg_type, val;
|
|
|
|
uint8_t *q;
|
2011-08-03 12:52:54 +02:00
|
|
|
uint8_t client_ethaddr[ETH_ALEN];
|
2004-04-22 02:10:48 +02:00
|
|
|
|
|
|
|
/* extract exact DHCP msg type */
|
2009-04-21 21:56:20 +02:00
|
|
|
dhcp_decode(bp, &dhcp_msg_type, &preq_addr);
|
2010-02-07 00:03:50 +01:00
|
|
|
DPRINTF("bootp packet op=%d msgtype=%d", bp->bp_op, dhcp_msg_type);
|
2011-01-06 22:43:13 +01:00
|
|
|
if (preq_addr.s_addr != htonl(0L))
|
2015-08-29 09:12:35 +02:00
|
|
|
DPRINTF(" req_addr=%08" PRIx32 "\n", ntohl(preq_addr.s_addr));
|
2009-04-21 21:56:20 +02:00
|
|
|
else
|
2010-02-07 00:03:50 +01:00
|
|
|
DPRINTF("\n");
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2004-10-03 13:44:41 +02:00
|
|
|
if (dhcp_msg_type == 0)
|
|
|
|
dhcp_msg_type = DHCPREQUEST; /* Force reply for old BOOTP clients */
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2007-09-16 23:08:06 +02:00
|
|
|
if (dhcp_msg_type != DHCPDISCOVER &&
|
2004-04-22 02:10:48 +02:00
|
|
|
dhcp_msg_type != DHCPREQUEST)
|
|
|
|
return;
|
2011-08-03 12:52:54 +02:00
|
|
|
|
|
|
|
/* Get client's hardware address from bootp request */
|
|
|
|
memcpy(client_ethaddr, bp->bp_hwaddr, ETH_ALEN);
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2009-06-24 14:42:31 +02:00
|
|
|
m = m_get(slirp);
|
|
|
|
if (!m) {
|
2004-04-22 02:10:48 +02:00
|
|
|
return;
|
2009-06-24 14:42:31 +02:00
|
|
|
}
|
2007-10-26 21:01:16 +02:00
|
|
|
m->m_data += IF_MAXLINKHDR;
|
2004-04-22 02:10:48 +02:00
|
|
|
rbp = (struct bootp_t *)m->m_data;
|
|
|
|
m->m_data += sizeof(struct udpiphdr);
|
|
|
|
memset(rbp, 0, sizeof(struct bootp_t));
|
|
|
|
|
2004-05-04 05:14:47 +02:00
|
|
|
if (dhcp_msg_type == DHCPDISCOVER) {
|
2011-01-06 22:43:13 +01:00
|
|
|
if (preq_addr.s_addr != htonl(0L)) {
|
2011-08-03 12:52:54 +02:00
|
|
|
bc = request_addr(slirp, &preq_addr, client_ethaddr);
|
2009-04-21 21:56:20 +02:00
|
|
|
if (bc) {
|
2011-01-06 22:43:13 +01:00
|
|
|
daddr.sin_addr = preq_addr;
|
2009-04-21 21:56:20 +02:00
|
|
|
}
|
|
|
|
}
|
2004-05-04 05:14:47 +02:00
|
|
|
if (!bc) {
|
2009-04-21 21:56:20 +02:00
|
|
|
new_addr:
|
2011-08-03 12:52:54 +02:00
|
|
|
bc = get_new_addr(slirp, &daddr.sin_addr, client_ethaddr);
|
2009-04-21 21:56:20 +02:00
|
|
|
if (!bc) {
|
2010-02-07 00:03:50 +01:00
|
|
|
DPRINTF("no address left\n");
|
2009-04-21 21:56:20 +02:00
|
|
|
return;
|
|
|
|
}
|
2004-05-04 05:14:47 +02:00
|
|
|
}
|
2011-08-03 12:52:54 +02:00
|
|
|
memcpy(bc->macaddr, client_ethaddr, ETH_ALEN);
|
2011-01-06 22:43:13 +01:00
|
|
|
} else if (preq_addr.s_addr != htonl(0L)) {
|
2011-08-03 12:52:54 +02:00
|
|
|
bc = request_addr(slirp, &preq_addr, client_ethaddr);
|
2009-04-21 21:56:20 +02:00
|
|
|
if (bc) {
|
2011-01-06 22:43:13 +01:00
|
|
|
daddr.sin_addr = preq_addr;
|
2011-08-03 12:52:54 +02:00
|
|
|
memcpy(bc->macaddr, client_ethaddr, ETH_ALEN);
|
2009-04-21 21:56:20 +02:00
|
|
|
} else {
|
2012-02-24 01:23:28 +01:00
|
|
|
/* DHCPNAKs should be sent to broadcast */
|
|
|
|
daddr.sin_addr.s_addr = 0xffffffff;
|
2009-04-21 21:56:20 +02:00
|
|
|
}
|
2004-05-04 05:14:47 +02:00
|
|
|
} else {
|
2009-06-24 14:42:31 +02:00
|
|
|
bc = find_addr(slirp, &daddr.sin_addr, bp->bp_hwaddr);
|
2004-05-04 05:14:47 +02:00
|
|
|
if (!bc) {
|
2004-09-30 20:57:28 +02:00
|
|
|
/* if never assigned, behaves as if it was already
|
|
|
|
assigned (windows fix because it remembers its address) */
|
|
|
|
goto new_addr;
|
2004-05-04 05:14:47 +02:00
|
|
|
}
|
2004-04-22 02:10:48 +02:00
|
|
|
}
|
2007-02-20 01:05:08 +01:00
|
|
|
|
2011-08-03 12:52:54 +02:00
|
|
|
/* Update ARP table for this IP address */
|
|
|
|
arp_table_add(slirp, daddr.sin_addr.s_addr, client_ethaddr);
|
|
|
|
|
2009-06-24 14:42:31 +02:00
|
|
|
saddr.sin_addr = slirp->vhost_addr;
|
2004-04-22 02:10:48 +02:00
|
|
|
saddr.sin_port = htons(BOOTP_SERVER);
|
|
|
|
|
|
|
|
daddr.sin_port = htons(BOOTP_CLIENT);
|
|
|
|
|
|
|
|
rbp->bp_op = BOOTP_REPLY;
|
|
|
|
rbp->bp_xid = bp->bp_xid;
|
|
|
|
rbp->bp_htype = 1;
|
|
|
|
rbp->bp_hlen = 6;
|
2011-08-03 12:52:54 +02:00
|
|
|
memcpy(rbp->bp_hwaddr, bp->bp_hwaddr, ETH_ALEN);
|
2004-04-22 02:10:48 +02:00
|
|
|
|
2004-10-01 00:22:08 +02:00
|
|
|
rbp->bp_yiaddr = daddr.sin_addr; /* Client IP address */
|
|
|
|
rbp->bp_siaddr = saddr.sin_addr; /* Server IP address */
|
2004-04-22 02:10:48 +02:00
|
|
|
|
|
|
|
q = rbp->bp_vend;
|
|
|
|
memcpy(q, rfc1533_cookie, 4);
|
|
|
|
q += 4;
|
|
|
|
|
2009-04-21 21:56:20 +02:00
|
|
|
if (bc) {
|
2015-08-29 09:12:35 +02:00
|
|
|
DPRINTF("%s addr=%08" PRIx32 "\n",
|
2009-04-21 21:56:20 +02:00
|
|
|
(dhcp_msg_type == DHCPDISCOVER) ? "offered" : "ack'ed",
|
|
|
|
ntohl(daddr.sin_addr.s_addr));
|
|
|
|
|
|
|
|
if (dhcp_msg_type == DHCPDISCOVER) {
|
|
|
|
*q++ = RFC2132_MSG_TYPE;
|
|
|
|
*q++ = 1;
|
|
|
|
*q++ = DHCPOFFER;
|
|
|
|
} else /* DHCPREQUEST */ {
|
|
|
|
*q++ = RFC2132_MSG_TYPE;
|
|
|
|
*q++ = 1;
|
|
|
|
*q++ = DHCPACK;
|
|
|
|
}
|
|
|
|
|
2009-06-24 14:42:31 +02:00
|
|
|
if (slirp->bootp_filename)
|
2009-04-21 21:56:20 +02:00
|
|
|
snprintf((char *)rbp->bp_file, sizeof(rbp->bp_file), "%s",
|
2009-06-24 14:42:31 +02:00
|
|
|
slirp->bootp_filename);
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2004-04-22 02:10:48 +02:00
|
|
|
*q++ = RFC2132_SRV_ID;
|
|
|
|
*q++ = 4;
|
|
|
|
memcpy(q, &saddr.sin_addr, 4);
|
|
|
|
q += 4;
|
|
|
|
|
|
|
|
*q++ = RFC1533_NETMASK;
|
|
|
|
*q++ = 4;
|
2009-06-24 14:42:31 +02:00
|
|
|
memcpy(q, &slirp->vnetwork_mask, 4);
|
2009-06-24 14:42:28 +02:00
|
|
|
q += 4;
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2009-06-24 14:42:31 +02:00
|
|
|
if (!slirp->restricted) {
|
2009-01-08 20:24:00 +01:00
|
|
|
*q++ = RFC1533_GATEWAY;
|
|
|
|
*q++ = 4;
|
|
|
|
memcpy(q, &saddr.sin_addr, 4);
|
|
|
|
q += 4;
|
|
|
|
|
|
|
|
*q++ = RFC1533_DNS;
|
|
|
|
*q++ = 4;
|
2009-06-24 14:42:31 +02:00
|
|
|
memcpy(q, &slirp->vnameserver_addr, 4);
|
2009-01-08 20:24:00 +01:00
|
|
|
q += 4;
|
|
|
|
}
|
2004-04-22 02:10:48 +02:00
|
|
|
|
|
|
|
*q++ = RFC2132_LEASE_TIME;
|
|
|
|
*q++ = 4;
|
|
|
|
val = htonl(LEASE_TIME);
|
|
|
|
memcpy(q, &val, 4);
|
|
|
|
q += 4;
|
2006-04-16 13:06:58 +02:00
|
|
|
|
2009-06-24 14:42:31 +02:00
|
|
|
if (*slirp->client_hostname) {
|
|
|
|
val = strlen(slirp->client_hostname);
|
2006-04-16 13:06:58 +02:00
|
|
|
*q++ = RFC1533_HOSTNAME;
|
|
|
|
*q++ = val;
|
2009-06-24 14:42:31 +02:00
|
|
|
memcpy(q, slirp->client_hostname, val);
|
2006-04-16 13:06:58 +02:00
|
|
|
q += val;
|
|
|
|
}
|
2012-10-27 19:53:39 +02:00
|
|
|
|
2018-02-27 17:06:01 +01:00
|
|
|
if (slirp->vdomainname) {
|
|
|
|
val = strlen(slirp->vdomainname);
|
|
|
|
*q++ = RFC1533_DOMAINNAME;
|
|
|
|
*q++ = val;
|
|
|
|
memcpy(q, slirp->vdomainname, val);
|
|
|
|
q += val;
|
|
|
|
}
|
|
|
|
|
2012-10-27 19:53:39 +02:00
|
|
|
if (slirp->vdnssearch) {
|
|
|
|
size_t spaceleft = sizeof(rbp->bp_vend) - (q - rbp->bp_vend);
|
|
|
|
val = slirp->vdnssearch_len;
|
|
|
|
if (val + 1 > spaceleft) {
|
|
|
|
g_warning("DHCP packet size exceeded, "
|
|
|
|
"omitting domain-search option.");
|
|
|
|
} else {
|
|
|
|
memcpy(q, slirp->vdnssearch, val);
|
|
|
|
q += val;
|
|
|
|
}
|
|
|
|
}
|
2009-04-21 21:56:20 +02:00
|
|
|
} else {
|
|
|
|
static const char nak_msg[] = "requested address not available";
|
|
|
|
|
2015-08-29 09:12:35 +02:00
|
|
|
DPRINTF("nak'ed addr=%08" PRIx32 "\n", ntohl(preq_addr.s_addr));
|
2009-04-21 21:56:20 +02:00
|
|
|
|
|
|
|
*q++ = RFC2132_MSG_TYPE;
|
|
|
|
*q++ = 1;
|
|
|
|
*q++ = DHCPNAK;
|
|
|
|
|
|
|
|
*q++ = RFC2132_MESSAGE;
|
|
|
|
*q++ = sizeof(nak_msg) - 1;
|
|
|
|
memcpy(q, nak_msg, sizeof(nak_msg) - 1);
|
|
|
|
q += sizeof(nak_msg) - 1;
|
2004-04-22 02:10:48 +02:00
|
|
|
}
|
2010-03-07 14:45:37 +01:00
|
|
|
*q = RFC1533_END;
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2009-04-21 21:56:20 +02:00
|
|
|
daddr.sin_addr.s_addr = 0xffffffffu;
|
|
|
|
|
2007-09-16 23:08:06 +02:00
|
|
|
m->m_len = sizeof(struct bootp_t) -
|
2004-06-04 17:30:48 +02:00
|
|
|
sizeof(struct ip) - sizeof(struct udphdr);
|
slirp: Factorizing address translation
This patch factorizes some duplicate code into a new function,
sotranslate_out(). This function perform the address translation when a
packet is transmitted to the host network. If the packet is destinated
to the host, the loopback address is used, and if the packet is
destinated to the virtual DNS, the real DNS address is used. This code
is just a copy of the existent, but factorized and ready to manage the
IPv6 case.
On the same model, the major part of udp_output() code is moved into a
new sotranslate_in(). This function is directly used in sorecvfrom(),
like sotranslate_out() in sosendto().
udp_output() becoming useless, it is removed and udp_output2() is
renamed into udp_output(). This adds consistency with the udp6_output()
function introduced by further patches.
Lastly, this factorizes some duplicate code into sotranslate_accept(), which
performs the address translation when a connection is established on the host
for port forwarding: if it comes from localhost, the host virtual address is
used instead.
This prepares for IPv6 support.
Signed-off-by: Guillaume Subiron <maethor@subiron.org>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2015-12-19 22:24:59 +01:00
|
|
|
udp_output(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY);
|
2004-04-22 02:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void bootp_input(struct mbuf *m)
|
|
|
|
{
|
2005-06-05 19:11:42 +02:00
|
|
|
struct bootp_t *bp = mtod(m, struct bootp_t *);
|
2004-04-22 02:10:48 +02:00
|
|
|
|
|
|
|
if (bp->bp_op == BOOTP_REQUEST) {
|
2009-06-24 14:42:31 +02:00
|
|
|
bootp_reply(m->slirp, bp);
|
2004-04-22 02:10:48 +02:00
|
|
|
}
|
|
|
|
}
|