slirp.c revision b08ef9b004264c5334b65bfe8e1af14da731db92
#include "slirp.h"
#ifdef RT_OS_OS2
# include <paths.h>
#endif
#ifdef VBOX_WITH_SYNC_SLIRP
#include <iprt/semaphore.h>
#endif
0x52, 0x54, 0x00, 0x12, 0x35, 0x00
};
#ifdef _WIN32
const char **ppszDomain)
{
int rc = 0;
BufLen = sizeof(FIXED_INFO);
/** @todo: this API returns all DNS servers, no matter whether the
* corresponding network adapter is disabled or not. Maybe replace
if (FixedInfo) {
}
}
if (FixedInfo) {
}
rc = -1;
goto get_dns_prefix;
}
Log(("nat: DNS Servers:\n"));
while ( pIPAddr )
{
if (fVerbose)
}
if (FixedInfo) {
}
if (ppszDomain)
{
char szDnsDomain[256];
*ppszDomain = NULL;
GetVersionEx(&ver);
{
/* GetComputerNameEx exists in Windows versions starting with 2000. */
{
if (szDnsDomain[0])
{
/* Just non-empty strings are valid. */
if (pData->fPassDomain)
{
if (fVerbose)
}
else
}
}
else
}
}
return rc;
}
#else
const char **ppszDomain)
{
char buff[512];
char buff2[256];
FILE *f;
int found = 0;
#ifdef RT_OS_OS2
/* Try various locations. */
f = NULL;
if (etc)
{
}
if (!f) {
}
if (!f) {
}
#else
#endif
if (!f)
return -1;
if (ppszDomain)
*ppszDomain = NULL;
Log(("nat: DNS Servers:\n"));
continue;
/* If it's the first one, set it to dns_addr */
if (!found)
{
}
else
{
if (fVerbose)
}
found++;
}
if ( ppszDomain
{
if (*ppszDomain == NULL)
{
char *tok;
char *saveptr;
if (tok)
{
if (pData->fPassDomain)
{
if (fVerbose)
}
else
}
}
}
}
fclose(f);
if (!found)
return -1;
return 0;
}
#endif
{
}
bool fPassDomain, const char *pszTFTPPrefix,
const char *pszBootFile, void *pvUser)
{
int fNATfailed = 0;
#ifdef VBOX_WITH_SYNC_SLIRP
int rc = 0;
#endif
if (!pData)
return VERR_NO_MEMORY;
if (u32Netmask & 0x1f)
/* CTL is x.x.x.15, bootp passes up to 16 IPs (15..31) */
return VERR_INVALID_PARAMETER;
#if ARCH_BITS == 64
#endif
#ifdef _WIN32
{
}
#endif
#ifdef VBOX_WITH_SYNC_SLIRP
#endif
link_up = 1;
/* Initialise mbufs *after* setting the MTU */
/* set default addresses */
fNATfailed = 1;
}
/**
* Marks the link as up, making it possible to establish new connections.
*/
{
link_up = 1;
}
/**
* Marks the link as down and cleans up the current connections.
*/
{
{
else
}
link_up = 0;
}
/**
* Terminates the slirp component.
*/
{
#if ARCH_BITS == 64
LogRel(("NAT: cpvHashUsed=%RU32 cpvHashCollisions=%RU32 cpvHashInserts=%RU64 cpvHashDone=%RU64\n",
#endif
#ifdef WIN32
WSACleanup();
#endif
#ifdef LOG_ENABLED
Log(("\n"
"NAT statistics\n"
"--------------\n"
"\n"));
Log(("\n"
"\n"
"\n"));
#endif
}
#define CONN_CANFSEND(so) (((so)->so_state & (SS_FCANTSENDMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED)
/*
* curtime kept to an accuracy of 1ms
*/
#ifdef _WIN32
{
}
#else
{
gettimeofday(&tt, 0);
curtime++;
}
#endif
{
int nfds;
int tmp_time;
/*
* First, TCP sockets
*/
do_slowtimo = 0;
if (link_up) {
/*
* *_slowtimo needs calling if there are IP fragments
* in the fragment queue, or there are TCP connections active
*/
#ifndef VBOX_WITH_SYNC_SLIRP
#else
while (1) {
break;
}
#endif
/*
* See if we need a tcp_fasttimo
*/
/*
* NOFDREF can include still connecting to local-host,
* newly socreated() sockets etc. Don't want to select these.
*/
#ifndef VBOX_WITH_SYNC_SLIRP
continue;
#else
goto before_loop_ends;
#endif
/*
* Set for reading sockets which are accepting
*/
#ifndef VBOX_WITH_SYNC_SLIRP
continue;
#else
goto before_loop_ends;
#endif
}
/*
* Set for writing sockets which are connecting
*/
#ifndef VBOX_WITH_SYNC_SLIRP
continue;
#else
goto before_loop_ends;
#endif
}
/*
* Set for writing if we are connected, can send more, and
* we have something to send
*/
}
/*
* Set for reading (and urgent data) if we are connected, can
* receive more, and we have room for it XXX /2 ?
*/
}
#ifdef VBOX_WITH_SYNC_SLIRP
/*Release of global tcb mutex happens in the head of loop*/
#endif
}
/*
* UDP sockets
*/
#ifndef VBOX_WITH_SYNC_SLIRP
#else
while(1) {
break;
}
#endif
/*
* See if it's timed out
*/
#ifndef VBOX_WITH_SYNC_SLIRP
continue;
#else
goto before_udp_loop_end;
#endif
} else
}
/*
* When UDP packets are received from over the
* link, they're sendto()'d straight away, so
* no need for setting for writing
* Limit the number of packets queued by this session
* to 4. Note that even though we try and limit this
* to 4 packets, the session could have more queued
* if the packets needed to be fragmented
* (XXX <= 4 ?)
*/
}
#ifdef VBOX_WITH_SYNC_SLIRP
#endif
}
}
/*
* Setup timeout to use minimum CPU usage, especially when idle
*/
/*
* First, see the timeout needed by *timo
*/
/*
* If a slowtimo is needed, set timeout to 500ms from the last
* slow timeout. If a fast timeout is needed, set timeout within
* 200ms of when it was requested.
*/
if (do_slowtimo) {
/* XXX + 10000 because some select()'s aren't that accurate */
/* Can only fasttimo if we also slowtimo */
if (time_fasttimo) {
if (tmp_time < 0)
tmp_time = 0;
/* Choose the smallest of the 2 */
}
}
}
{
int ret;
/* Update time */
/*
* See if anything has timed out
*/
if (link_up) {
time_fasttimo = 0;
}
}
}
/*
* Check sockets
*/
if (link_up) {
/*
* Check TCP sockets
*/
#ifndef VBOX_WITH_SYNC_SLIRP
#else
while (1) {
break;
}
#endif
/*
* FD_ISSET is meaningless on these sockets
* (and they can crash the program)
*/
#ifndef VBOX_WITH_SYNC_SLIRP
continue;
#else
goto before_loop_ends;
#endif
/*
* Check for URG data
* This will soread as well, so no need to
* test for readfds below if this succeeds
*/
/*
* Check sockets for reading
*/
/*
* Check for incoming connections
*/
#ifndef VBOX_WITH_SYNC_SLIRP
continue;
#else
goto before_loop_ends;
#endif
} /* else */
/* Output it if we read something */
if (ret > 0)
}
/*
* Check sockets for writing
*/
/*
* Check for non-blocking, still-connecting sockets
*/
/* Connected */
/*
* This should be probably guarded by PROBE_CONN too. Anyway,
* we disable it on OS/2 because the below send call returns
* EFAULT which causes the opened TCP socket to close right
* after it has been opened and connected.
*/
#ifndef RT_OS_OS2
if (ret < 0) {
/* XXXXX Must fix, zero bytes is a NOP */
#ifndef VBOX_WITH_SYNC_SLIRP
continue;
#else
goto before_loop_ends;
#endif
/* else failed */
}
/* else so->so_state &= ~SS_ISFCONNECTING; */
#endif
/*
* Continue tcp_input
*/
/* continue; */
} else
/*
* XXXXX If we wrote something (a lot), there
* could be a need for a window update.
* In the worst case, the remote will send
* a window probe to get things going again
*/
}
/*
* Probe a still-connecting, non-blocking socket
* to check if it's still alive
*/
#ifdef PROBE_CONN
if (ret < 0) {
/* XXX */
#ifndef VBOX_WITH_SYNC_SLIRP
continue;/* Still connecting, continue */
#else
goto before_loop_ends;
#endif
/* else failed */
/* tcp_input will take care of it */
} else {
if (ret < 0) {
/* XXX */
#ifndef VBOX_WITH_SYNC_SLIRP
continue;
#else
goto before_loop_ends;
#endif
/* else failed */
} else
}
} /* SS_ISFCONNECTING */
#endif
#ifdef VBOX_WITH_SYNC_SLIRP
#endif
}
/*
* Now UDP sockets.
* Incoming packets are sent straight away, they're not buffered.
* Incoming UDP data isn't buffered either.
*/
#ifndef VBOX_WITH_SYNC_SLIRP
#else
while(1) {
break;
}
#endif
}
#ifdef VBOX_WITH_SYNC_SLIRP
#endif
}
}
/*
* See if we can start outputting
*/
#ifndef VBOX_WITH_SYNC_SLIRP
#else
#if 0
if (link_up) {
if (if_queued > 0){
}
else {
}
}
#endif
#endif
}
#define ETH_ALEN 6
#define ETH_HLEN 14
struct ethhdr
{
unsigned short h_proto; /* packet type ID field */
};
struct arphdr
{
unsigned short ar_hrd; /* format of hardware address */
unsigned short ar_pro; /* format of protocol address */
unsigned char ar_hln; /* length of hardware address */
unsigned char ar_pln; /* length of protocol address */
unsigned short ar_op; /* ARP opcode (command) */
/*
* Ethernet looks like this : This bit is variable sized however...
*/
};
static
{
int ar_op;
switch(ar_op) {
case ARPOP_REQUEST:
goto arp_ok;
goto arp_ok;
}
return;
/* XXX: make an ARP request to have the client address */
}
break;
default:
break;
}
}
{
struct mbuf *m;
int proto;
#ifdef VBOX_WITH_SYNC_SLIRP
int rc;
#endif
return;
switch(proto) {
case ETH_P_ARP:
break;
case ETH_P_IP:
/* Update time. Important if the network is very quiet, as otherwise
* the first outgoing connection gets an incorrect timestamp. */
#ifdef VBOX_WITH_SYNC_SLIRP
if (m != NULL) {
}
#endif
if (!m)
return;
/* Note: we add to align the IP header */
}
#ifdef VBOX_WITH_SYNC_SLIRP
#endif
break;
default:
break;
}
}
/* output the IP packet to the ethernet device */
{
return;
/* XXX: not correct */
}
{
if (is_udp) {
htons(guest_port), 0))
return -1;
} else {
htons(guest_port), 0))
return -1;
}
return 0;
}
int guest_port)
{
}
{
}