VirtualBox

Changeset 1033 in vbox


Ignore:
Timestamp:
Feb 23, 2007 2:22:00 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
18906
Message:

Big change to make slirp fully instantiatable (replace all global
variables with local ones, passing a reference to the state/config
structure to all places which are interested). You can now have as many
cards in the guest configured for NAT networking as you want.

Location:
trunk/src/VBox/Devices/Network
Files:
35 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/DrvNAT.cpp

    r792 r1033  
    5959    /** Link state */
    6060    PDMNETWORKLINKSTATE     enmLinkState;
     61    /** NAT state for this instance. */
     62    PNATState               pNATState;
    6163} DRVNAT, *PDRVNAT;
    6264
    6365/** Converts a pointer to NAT::INetworkConnector to a PRDVNAT. */
    6466#define PDMINETWORKCONNECTOR_2_DRVNAT(pInterface)   ( (PDRVNAT)((uintptr_t)pInterface - RT_OFFSETOF(DRVNAT, INetworkConnector)) )
    65 
    6667
    6768/*******************************************************************************
    6869*   Global Variables                                                           *
    6970*******************************************************************************/
    70 /** @todo change this into a MAC -> PDRVNAT translation list. */
    71 /** Pointer to the driver instance.
    72  * This is required by slirp. */
    73 static PDRVNAT          g_pDrv = NULL;
    7471#if 0
    7572/** If set the thread should terminate. */
     
    103100    Assert(pData->enmLinkState == PDMNETWORKLINKSTATE_UP);
    104101    if (pData->enmLinkState == PDMNETWORKLINKSTATE_UP)
    105         slirp_input((uint8_t *)pvBuf, cb);
     102        slirp_input(pData->pNATState, (uint8_t *)pvBuf, cb);
    106103    RTCritSectLeave(&pData->CritSect);
    107104    LogFlow(("drvNATSend: end\n"));
     
    148145        case PDMNETWORKLINKSTATE_UP:
    149146            LogRel(("NAT: link up\n"));
    150             slirp_link_up();
     147            slirp_link_up(pData->pNATState);
    151148            break;
    152149
     
    154151        case PDMNETWORKLINKSTATE_DOWN_RESUME:
    155152            LogRel(("NAT: link down\n"));
    156             slirp_link_down();
     153            slirp_link_down(pData->pNATState);
    157154            break;
    158155
     
    196193    AssertReleaseRC(rc);
    197194
    198     slirp_select_fill(&cFDs, &ReadFDs, &WriteFDs, &XcptFDs);
     195    slirp_select_fill(pData->pNATState, &cFDs, &ReadFDs, &WriteFDs, &XcptFDs);
    199196
    200197    struct timeval tv = {0, 0}; /* no wait */
    201198    int cReadFDs = select(cFDs + 1, &ReadFDs, &WriteFDs, &XcptFDs, &tv);
    202199    if (cReadFDs >= 0)
    203         slirp_select_poll(&ReadFDs, &WriteFDs, &XcptFDs);
     200        slirp_select_poll(pData->pNATState, &ReadFDs, &WriteFDs, &XcptFDs);
    204201
    205202    RTCritSectLeave(&pData->CritSect);
     
    212209 * @returns 0 if not possible.
    213210 */
    214 int slirp_can_output(void)
    215 {
     211int slirp_can_output(void *pvUser)
     212{
     213    PDRVNAT pData = (PDRVNAT)pvUser;
     214
     215    Assert(pData);
     216
    216217    /** Happens during termination */
    217     if (!RTCritSectIsOwner(&g_pDrv->CritSect))
     218    if (!RTCritSectIsOwner(&pData->CritSect))
    218219        return 0;
    219220
    220     if (g_pDrv)
    221         return g_pDrv->pPort->pfnCanReceive(g_pDrv->pPort);
     221    return pData->pPort->pfnCanReceive(pData->pPort);
    222222
    223223    return 0;
     
    228228 * Function called by slirp to feed incoming data to the network port.
    229229 */
    230 void slirp_output(const uint8_t *pu8Buf, int cb)
    231 {
     230void slirp_output(void *pvUser, const uint8_t *pu8Buf, int cb)
     231{
     232    PDRVNAT pData = (PDRVNAT)pvUser;
     233
    232234    LogFlow(("slirp_output BEGING %x %d\n", pu8Buf, cb));
    233     Log2(("slirp_output: pu8Buf=%p cb=%#x (g_pDrv=%p)\n"
     235    Log2(("slirp_output: pu8Buf=%p cb=%#x (pData=%p)\n"
    234236          "%.*Vhxd\n",
    235           pu8Buf, cb, g_pDrv,
     237          pu8Buf, cb, pData,
    236238          cb, pu8Buf));
    237     if (g_pDrv)
    238     {
    239         /** Happens during termination */
    240         if (!RTCritSectIsOwner(&g_pDrv->CritSect))
    241             return;
    242 
    243         int rc = g_pDrv->pPort->pfnReceive(g_pDrv->pPort, pu8Buf, cb);
    244         AssertRC(rc);
    245     }
     239
     240    Assert(pData);
     241
     242    /** Happens during termination */
     243    if (!RTCritSectIsOwner(&pData->CritSect))
     244        return;
     245
     246    int rc = pData->pPort->pfnReceive(pData->pPort, pu8Buf, cb);
     247    AssertRC(rc);
    246248    LogFlow(("slirp_output END %x %d\n", pu8Buf, cb));
    247249}
     
    289291    LogRel(("NAT: g_cpvHashUsed=%RU32 g_cpvHashCollisions=%RU32 g_cpvHashInserts=%RU64 g_cpvHashDone=%RU64\n",
    290292            g_cpvHashUsed, g_cpvHashCollisions, g_cpvHashInserts, g_cpvHashDone));
    291 #endif 
     293#endif
    292294    int rc = RTCritSectEnter(&pData->CritSect);
    293295    AssertReleaseRC(rc);
    294     slirp_term();
    295     g_pDrv = NULL;
     296    slirp_term(pData->pNATState);
     297    pData->pNATState = NULL;
    296298    RTCritSectLeave(&pData->CritSect);
    297299
     
    306308 * @param   pCfgHandle      The drivers configuration handle.
    307309 */
    308 static int drvNATConstructRedir(PCFGMNODE pCfgHandle)
     310static int drvNATConstructRedir(PDRVNAT pData, PCFGMNODE pCfgHandle)
    309311{
    310312    /*
     
    363365         */
    364366        Log(("drvNATConstruct: Redir %d -> %s:%d\n", iHostPort, szGuestIP, iGuestPort));
    365         if (slirp_redir(fUDP, iHostPort, GuestIP, iGuestPort) < 0)
     367        if (slirp_redir(pData->pNATState, fUDP, iHostPort, GuestIP, iGuestPort) < 0)
    366368        {
    367369            AssertMsgFailed(("Configuration error: failed to setup redirection of %d to %s:%d. Probably a conflict with existing services or other rules.\n",
     
    388390{
    389391    PDRVNAT pData = PDMINS2DATA(pDrvIns, PDRVNAT);
     392    char szNetAddr[16];
    390393    LogFlow(("drvNATConstruct:\n"));
    391394
     
    407410    pData->INetworkConnector.pfnNotifyLinkChanged  = drvNATNotifyLinkChanged;
    408411    pData->INetworkConnector.pfnNotifyCanReceive   = drvNATNotifyCanReceive;
     412   
     413    pData->pNATState                    = NULL;
    409414
    410415    /*
     
    415420        return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_MISSING_INTERFACE_ABOVE,
    416421                                N_("Configuration error: the above device/driver didn't export the network port interface!\n"));
     422
     423    /* Generate a network address for this network card. */
     424    RTStrPrintf(szNetAddr, sizeof(szNetAddr), "10.0.%d.0", pDrvIns->iInstance + 2);
    417425
    418426    /*
     
    437445             * Initialize slirp.
    438446             */
    439             rc = slirp_init();
     447            rc = slirp_init(&pData->pNATState, &szNetAddr[0], pData);
    440448            if (VBOX_SUCCESS(rc))
    441449            {
    442                 rc = drvNATConstructRedir(pCfgHandle);
     450                rc = drvNATConstructRedir(pData, pCfgHandle);
    443451                if (VBOX_SUCCESS(rc))
    444452                {
    445453                    pDrvIns->pDrvHlp->pfnPDMPollerRegister(pDrvIns, drvNATPoller);
    446                     g_pDrv = pData;
    447454
    448455                    pData->enmLinkState = PDMNETWORKLINKSTATE_UP;
     
    454461                }
    455462                /* failure path */
    456                 slirp_term();
     463                slirp_term(pData->pNATState);
     464                pData->pNATState = NULL;
    457465            }
    458466            else
     
    500508    PDM_DRVREG_CLASS_NETWORK,
    501509    /* cMaxInstances */
    502     1,
     510    16,
    503511    /* cbInstance */
    504512    sizeof(DRVNAT),
  • trunk/src/VBox/Devices/Network/slirp/bootp.c

    r1023 r1033  
    11/*
    22 * QEMU BOOTP/DHCP server
    3  * 
     3 *
    44 * Copyright (c) 2004 Fabrice Bellard
    5  * 
     5 *
    66 * Permission is hereby granted, free of charge, to any person obtaining a copy
    77 * of this software and associated documentation files (the "Software"), to deal
     
    2626/* XXX: only DHCP is supported */
    2727
     28#ifndef VBOX
    2829#define NB_ADDR 16
    2930
     
    4041
    4142const char *bootp_filename;
     43#endif /* !VBOX */
    4244
    4345static const uint8_t rfc1533_cookie[] = { RFC1533_COOKIE };
     
    5860    Log(("dhcp: %N", pszFormat, &args));
    5961    va_end(args);
    60 #endif
    61 }
    62 #endif /* VBOX */
    63 
     62#endif
     63}
     64#endif /* VBOX */
     65
     66#ifdef VBOX
     67static BOOTPClient *get_new_addr(PNATState pData, struct in_addr *paddr)
     68#else /* !VBOX */
    6469static BOOTPClient *get_new_addr(struct in_addr *paddr)
     70#endif /* !VBOX */
    6571{
    6672    BOOTPClient *bc;
     
    8086
    8187#ifdef VBOX
    82 static void release_addr(struct in_addr *paddr)
     88static void release_addr(PNATState pData, struct in_addr *paddr)
    8389{
    8490    int i;
     
    9298#endif /* VBOX */
    9399
     100#ifdef VBOX
     101static BOOTPClient *find_addr(PNATState pData, struct in_addr *paddr, const uint8_t *macaddr)
     102#else /* !VBOX */
    94103static BOOTPClient *find_addr(struct in_addr *paddr, const uint8_t *macaddr)
     104#endif /* !VBOX */
    95105{
    96106    BOOTPClient *bc;
     
    115125    int len, tag;
    116126
    117     *pmsg_type = 0;   
     127    *pmsg_type = 0;
    118128
    119129    p = buf;
     
    127137        tag = p[0];
    128138        if (tag == RFC1533_PAD) {
    129             p++; 
     139            p++;
    130140        } else if (tag == RFC1533_END) {
    131141            break;
     
    150160}
    151161
     162#ifdef VBOX
     163static void bootp_reply(PNATState pData, struct bootp_t *bp)
     164#else /* !VBOX */
    152165static void bootp_reply(struct bootp_t *bp)
     166#endif /* !VBOX */
    153167{
    154168    BOOTPClient *bc;
     
    156170    struct bootp_t *rbp;
    157171    struct sockaddr_in saddr, daddr;
     172#ifdef VBOX
     173    struct in_addr dns_addr_dhcp;
     174#else /* !VBOX */
    158175    struct in_addr dns_addr;
     176#endif /* !VBOX */
    159177    int dhcp_msg_type, val;
    160178    uint8_t *q;
     
    163181    dhcp_decode(bp->bp_vend, DHCP_OPT_LEN, &dhcp_msg_type);
    164182    dprintf("bootp packet op=%d msgtype=%d\n", bp->bp_op, dhcp_msg_type);
    165    
     183
    166184    if (dhcp_msg_type == 0)
    167185        dhcp_msg_type = DHCPREQUEST; /* Force reply for old BOOTP clients */
    168        
     186
    169187#ifdef VBOX
    170188    if (dhcp_msg_type == DHCPRELEASE) {
    171189        uint32_t addr = ntohl(bp->bp_ciaddr.s_addr);
    172         release_addr(&bp->bp_ciaddr);
     190        release_addr(pData, &bp->bp_ciaddr);
    173191        LogRel(("NAT: DHCP released IP address %u.%u.%u.%u\n",
    174192                addr >> 24, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff));
     
    178196    }
    179197#endif /* VBOX */
    180     if (dhcp_msg_type != DHCPDISCOVER && 
     198    if (dhcp_msg_type != DHCPDISCOVER &&
    181199        dhcp_msg_type != DHCPREQUEST)
    182200        return;
    183201    /* XXX: this is a hack to get the client mac address */
    184202    memcpy(client_ethaddr, bp->bp_hwaddr, 6);
    185    
     203
     204#ifdef VBOX
     205    if ((m = m_get(pData)) == NULL)
     206#else /* !VBOX */
    186207    if ((m = m_get()) == NULL)
     208#endif /* !VBOX */
    187209        return;
    188210    m->m_data += if_maxlinkhdr;
     
    194216#ifdef VBOX
    195217        /* Do not allocate a new lease for clients that forgot that they had a lease. */
    196         bc = find_addr(&daddr.sin_addr, bp->bp_hwaddr);
     218        bc = find_addr(pData, &daddr.sin_addr, bp->bp_hwaddr);
    197219        if (bc)
    198220            goto reuse_lease;
    199221#endif /* VBOX */
    200222    new_addr:
     223#ifdef VBOX
     224        bc = get_new_addr(pData, &daddr.sin_addr);
     225#else /* !VBOX */
    201226        bc = get_new_addr(&daddr.sin_addr);
     227#endif /* !VBOX */
    202228        if (!bc) {
    203229#ifdef VBOX
     
    212238#endif /* VBOX */
    213239    } else {
     240#ifdef VBOX
     241        bc = find_addr(pData, &daddr.sin_addr, bp->bp_hwaddr);
     242#else /* !VBOX */
    214243        bc = find_addr(&daddr.sin_addr, bp->bp_hwaddr);
     244#endif /* !VBOX */
    215245        if (!bc) {
    216246            /* if never assigned, behaves as if it was already
     
    230260    {
    231261        uint32_t addr = ntohl(daddr.sin_addr.s_addr);
    232         LogRel(("NAT: DHCP offered IP address %u.%u.%u.%u\n", 
     262        LogRel(("NAT: DHCP offered IP address %u.%u.%u.%u\n",
    233263                addr >> 24, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff));
    234264    }
     
    263293        *q++ = DHCPACK;
    264294    }
    265        
     295
    266296    if (dhcp_msg_type == DHCPDISCOVER ||
    267297        dhcp_msg_type == DHCPREQUEST) {
     
    277307        *q++ = 0xff;
    278308        *q++ = 0x00;
    279        
     309
    280310        *q++ = RFC1533_GATEWAY;
    281311        *q++ = 4;
    282312        memcpy(q, &saddr.sin_addr, 4);
    283313        q += 4;
    284        
     314
    285315        *q++ = RFC1533_DNS;
    286316        *q++ = 4;
     317#ifdef VBOX
     318        dns_addr_dhcp.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_DNS);
     319        memcpy(q, &dns_addr_dhcp, 4);
     320#else /* !VBOX */
    287321        dns_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_DNS);
    288322        memcpy(q, &dns_addr, 4);
     323#endif /* !VBOX */
    289324        q += 4;
    290325
     
    304339    }
    305340    *q++ = RFC1533_END;
    306    
    307     m->m_len = sizeof(struct bootp_t) - 
     341
     342    m->m_len = sizeof(struct bootp_t) -
    308343        sizeof(struct ip) - sizeof(struct udphdr);
    309344#ifdef VBOX
    310345    /* Reply to the broadcast address, as some clients perform paranoid checks. */
    311346    daddr.sin_addr.s_addr = INADDR_BROADCAST;
    312 #endif /* VBOX */
     347    udp_output2(pData, NULL, m, &saddr, &daddr, IPTOS_LOWDELAY);
     348#else /* !VBOX */
    313349    udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY);
    314 }
    315 
     350#endif /* !VBOX */
     351}
     352
     353#ifdef VBOX
     354void bootp_input(PNATState pData, struct mbuf *m)
     355#else /* !VBOX */
    316356void bootp_input(struct mbuf *m)
     357#endif /* !VBOX */
    317358{
    318359    struct bootp_t *bp = mtod(m, struct bootp_t *);
    319360
    320361    if (bp->bp_op == BOOTP_REQUEST) {
     362#ifdef VBOX
     363        bootp_reply(pData, bp);
     364#else /* !VBOX */
    321365        bootp_reply(bp);
    322     }
    323 }
     366#endif /* !VBOX */
     367    }
     368}
  • trunk/src/VBox/Devices/Network/slirp/bootp.h

    r1 r1033  
    114114};
    115115
     116#ifdef VBOX
     117void bootp_input(PNATState, struct mbuf *m);
     118#else /* !VBOX */
    116119void bootp_input(struct mbuf *m);
     120#endif /* !VBOX */
  • trunk/src/VBox/Devices/Network/slirp/debug.c

    r1 r1033  
    22 * Copyright (c) 1995 Danny Gasparovski.
    33 * Portions copyright (c) 2000 Kelly Price.
    4  * 
    5  * Please read the file COPYRIGHT for the 
     4 *
     5 * Please read the file COPYRIGHT for the
    66 * terms and conditions of the copyright.
    77 */
     
    99#include <slirp.h>
    1010
     11#ifndef VBOX
    1112FILE *dfd = NULL;
    1213#ifdef DEBUG
     
    1617#endif
    1718int slirp_debug = 0;
     19#endif /* !VBOX */
    1820
    1921#ifndef VBOX
    2022extern char *strerror _P((int));
    21 #endif 
    22 
    23 /* Carry over one item from main.c so that the tty's restored. 
     23#endif
     24
     25/* Carry over one item from main.c so that the tty's restored.
    2426 * Only done when the tty being used is /dev/tty --RedWolf */
    2527extern struct termios slirp_tty_settings;
     
    3638        if (dfd)
    3739           fclose(dfd);
    38        
     40
    3941        dfd = fopen(file,"w");
    4042        if (dfd != NULL) {
     
    6567        u_char *pptr = (u_char *)dat;
    6668        int j,k;
    67        
     69
    6870        n /= 16;
    6971        n++;
     
    8587/*
    8688 * Statistic routines
    87  * 
     89 *
    8890 * These will print statistics to the screen, the debug file (dfd), or
    8991 * a buffer, depending on "type", so that the stats can be sent over
     
    9799        struct slirp_ifstats *is = &ttyp->ifstats;
    98100        char buff[512];
    99        
     101
    100102        lprint(" \r\n");
    101        
     103
    102104        if (if_comp & IF_COMPRESS)
    103105           strcpy(buff, "on");
     
    134136{
    135137        struct ttys *ttyp;
    136        
     138
    137139        for (ttyp = ttys; ttyp; ttyp = ttyp->next)
    138140           ttystats(ttyp);
     
    141143
    142144void
     145#ifdef VBOX
     146ipstats(PNATState pData)
     147#else /* !VBOX */
    143148ipstats()
    144 {
    145         lprint(" \r\n");       
     149#endif /* !VBOX */
     150{
     151        lprint(" \r\n");
    146152
    147153        lprint("IP stats:\r\n");
     
    169175{
    170176        lprint(" \r\n");
    171        
     177
    172178        lprint("VJ compression stats:\r\n");
    173        
     179
    174180        lprint("  %6d outbound packets (%d compressed)\r\n",
    175181               comp_s.sls_packets, comp_s.sls_compressed);
     
    184190
    185191void
     192#ifdef VBOX
     193tcpstats(PNATState pData)
     194#else /* !VBOX */
    186195tcpstats()
     196#endif /* !VBOX */
    187197{
    188198        lprint(" \r\n");
    189199
    190200        lprint("TCP stats:\r\n");
    191        
     201
    192202        lprint("  %6d packets sent\r\n", tcpstat.tcps_sndtotal);
    193203        lprint("          %6d data packets (%d bytes)\r\n",
     
    202212        lprint("          %6d control (SYN/FIN/RST) packets\r\n", tcpstat.tcps_sndctrl);
    203213        lprint("          %6d times tcp_output did nothing\r\n", tcpstat.tcps_didnuttin);
    204        
    205         lprint("  %6d packets received\r\n", tcpstat.tcps_rcvtotal);       
     214
     215        lprint("  %6d packets received\r\n", tcpstat.tcps_rcvtotal);
    206216        lprint("          %6d acks (for %d bytes)\r\n",
    207217                        tcpstat.tcps_rcvackpack, tcpstat.tcps_rcvackbyte);
     
    212222        lprint("          %6d completely duplicate packets (%d bytes)\r\n",
    213223                        tcpstat.tcps_rcvduppack, tcpstat.tcps_rcvdupbyte);
    214        
     224
    215225        lprint("          %6d packets with some duplicate data (%d bytes duped)\r\n",
    216226                        tcpstat.tcps_rcvpartduppack, tcpstat.tcps_rcvpartdupbyte);
     
    225235        lprint("          %6d discarded for bad header offset fields\r\n",
    226236                        tcpstat.tcps_rcvbadoff);
    227        
     237
    228238        lprint("  %6d connection requests\r\n", tcpstat.tcps_connattempt);
    229239        lprint("  %6d connection accepts\r\n", tcpstat.tcps_accepts);
     
    244254        lprint("  %6d correct data packet header predictions\n", tcpstat.tcps_preddat);
    245255        lprint("  %6d TCP cache misses\r\n", tcpstat.tcps_socachemiss);
    246        
    247        
     256
     257
    248258/*      lprint("    Packets received too short:         %d\r\n", tcpstat.tcps_rcvshort); */
    249259/*      lprint("    Segments dropped due to PAWS:       %d\r\n", tcpstat.tcps_pawsdrop); */
     
    252262
    253263void
     264#ifdef VBOX
     265udpstats(PNATState pData)
     266#else /* !VBOX */
    254267udpstats()
     268#endif /* !VBOX */
    255269{
    256270        lprint(" \r\n");
     
    266280
    267281void
     282#ifdef VBOX
     283icmpstats(PNATState pData)
     284#else /* !VBOX */
    268285icmpstats()
     286#endif /* !VBOX */
    269287{
    270288        lprint(" \r\n");
     
    279297
    280298void
     299#ifdef VBOX
     300mbufstats(PNATState pData)
     301#else /* !VBOX */
    281302mbufstats()
     303#endif /* !VBOX */
    282304{
    283305        struct mbuf *m;
    284306        int i;
    285        
     307
    286308        lprint(" \r\n");
    287        
     309
    288310        lprint("Mbuf stats:\r\n");
    289311
    290312        lprint("  %6d mbufs allocated (%d max)\r\n", mbuf_alloced, mbuf_max);
    291        
     313
    292314        i = 0;
    293315        for (m = m_freelist.m_next; m != &m_freelist; m = m->m_next)
    294316                i++;
    295317        lprint("  %6d mbufs on free list\r\n",  i);
    296        
     318
    297319        i = 0;
    298320        for (m = m_usedlist.m_next; m != &m_usedlist; m = m->m_next)
     
    303325
    304326void
     327#ifdef VBOX
     328sockstats(PNATState pData)
     329#else /* !VBOX */
    305330sockstats()
     331#endif /* !VBOX */
    306332{
    307333        char buff[256];
     
    310336
    311337        lprint(" \r\n");
    312        
     338
    313339        lprint(
    314340           "Proto[state]     Sock     Local Address, Port  Remote Address, Port RecvQ SendQ\r\n");
    315                        
     341
    316342        for (so = tcb.so_next; so != &tcb; so = so->so_next) {
    317                
     343
    318344                n = sprintf(buff, "tcp[%s]", so->so_tcpcb?tcpstates[so->so_tcpcb->t_state]:"NONE");
    319345                while (n < 17)
     
    327353                                so->so_rcv.sb_cc, so->so_snd.sb_cc);
    328354        }
    329                    
     355
    330356        for (so = udb.so_next; so != &udb; so = so->so_next) {
    331                
     357
    332358                n = sprintf(buff, "udp[%d sec]", (so->so_expire - curtime) / 1000);
    333359                while (n < 17)
     
    349375{
    350376        struct ttys *ttyp;
    351        
     377
    352378        DEBUG_CALL("slirp_exit");
    353379        DEBUG_ARG("exit_status = %d", exit_status);
     
    358384                   debug_init("slirp_stats", 0xf);
    359385                lprint_arg = (char **)&dfd;
    360                
     386
    361387                ipstats();
    362388                tcpstats();
     
    368394                vjstats();
    369395        }
    370        
     396
    371397        for (ttyp = ttys; ttyp; ttyp = ttyp->next)
    372398           tty_detached(ttyp, 1);
    373        
     399
    374400        if (slirp_forked) {
    375401                /* Menendez time */
     
    378404                            (long) getppid());
    379405        }
    380        
     406
    381407        /* Restore the terminal if we gotta */
    382408        if(slirp_tty_restore)
  • trunk/src/VBox/Devices/Network/slirp/debug.h

    r1 r1033  
    11/*
    22 * Copyright (c) 1995 Danny Gasparovski.
    3  * 
    4  * Please read the file COPYRIGHT for the 
     3 *
     4 * Please read the file COPYRIGHT for the
    55 * terms and conditions of the copyright.
    66 */
     
    99#define PRN_SPRINTF     2
    1010
     11#ifdef VBOX
     12/* Unused anyway, using VBox Log facility. */
     13#define dfd NULL
     14#else /* !VBOX */
    1115extern FILE *dfd;
    1216extern FILE *lfd;
     17#endif /* !VBOX */
    1318extern int dostats;
    1419extern int slirp_debug;
     
    8792/*void ttystats _P((struct ttys *)); */
    8893void allttystats _P((void));
     94#ifdef VBOX
     95void ipstats _P((PNATState));
     96void tcpstats _P((PNATState));
     97void udpstats _P((PNATState));
     98void icmpstats _P((PNATState));
     99void mbufstats _P((PNATState));
     100void sockstats _P((PNATState));
     101#else /* !VBOX */
    89102void ipstats _P((void));
    90 #ifndef VBOX
    91103void vjstats _P((void));
    92 #endif /* VBOX */
    93104void tcpstats _P((void));
    94105void udpstats _P((void));
     
    96107void mbufstats _P((void));
    97108void sockstats _P((void));
     109#endif /* VBOX */
    98110#ifndef VBOX
    99111void slirp_exit _P((int));
  • trunk/src/VBox/Devices/Network/slirp/icmp_var.h

    r1 r1033  
    4242 * of the internet control message protocol.
    4343 */
     44#ifdef VBOX
     45struct icmpstat_t {
     46#else /* !VBOX */
    4447struct icmpstat {
     48#endif /* !VBOX */
    4549/* statistics related to input messages processed */
    4650        u_long  icps_received;          /* #ICMP packets received */
     
    6569}
    6670
     71#ifndef VBOX
    6772extern struct icmpstat icmpstat;
     73#endif /* !VBOX */
    6874
    6975#endif
  • trunk/src/VBox/Devices/Network/slirp/if.c

    r1 r1033  
    88#include <slirp.h>
    99
     10#ifndef VBOX
    1011int if_mtu, if_mru;
    1112int if_comp;
     
    1819struct  mbuf if_batchq;                 /* queue for non-interactive data */
    1920struct  mbuf *next_m;                   /* Pointer to next mbuf to output */
     21#endif /* !VBOX */
    2022
    2123#define ifs_init(ifm) ((ifm)->ifs_next = (ifm)->ifs_prev = (ifm))
     
    4850
    4951void
     52#ifdef VBOX
     53if_init(PNATState pData)
     54#else /* !VBOX */
    5055if_init()
     56#endif /* !VBOX */
    5157{
    5258#if 0
     
    6470        if_maxlinkhdr = 2 + 14 + 40;
    6571#endif
     72#ifdef VBOX
     73        if_queued = 0;
     74        if_thresh = 10;
     75#endif /* VBOX */
    6676        if_mtu = 1500;
    6777        if_mru = 1500;
     
    8696        int ret;
    8797        int total;
    88        
     98
    8999        /* This should succeed most of the time */
    90100        ret = send(fd, bptr, n,0);
    91101        if (ret == n || ret <= 0)
    92102           return ret;
    93        
     103
    94104        /* Didn't write everything, go into the loop */
    95105        total = ret;
     
    106116 * if_input - read() the tty, do "top level" processing (ie: check for any escapes),
    107117 * and pass onto (*ttyp->if_input)
    108  * 
     118 *
    109119 * XXXXX Any zeros arriving by themselves are NOT placed into the arriving packet.
    110120 */
     
    116126        u_char if_inbuff[INBUFF_SIZE];
    117127        int if_n;
    118        
     128
    119129        DEBUG_CALL("if_input");
    120130        DEBUG_ARG("ttyp = %lx", (long)ttyp);
    121        
     131
    122132        if_n = recv(ttyp->fd, (char *)if_inbuff, INBUFF_SIZE,0);
    123        
     133
    124134        DEBUG_MISC((dfd, " read %d bytes\n", if_n));
    125        
     135
    126136        if (if_n <= 0) {
    127137                if (if_n == 0 || (errno != EINTR && errno != EAGAIN)) {
     
    147157        }
    148158        ttyp->ones = ttyp->zeros = 0;
    149        
     159
    150160        (*ttyp->if_input)(ttyp, if_inbuff, if_n);
    151161}
    152 #endif 
    153        
     162#endif
     163
    154164/*
    155165 * if_output: Queue packet into an output queue.
    156  * There are 2 output queue's, if_fastq and if_batchq. 
     166 * There are 2 output queue's, if_fastq and if_batchq.
    157167 * Each output queue is a doubly linked list of double linked lists
    158168 * of mbufs, each list belonging to one "session" (socket).  This
    159169 * way, we can output packets fairly by sending one packet from each
    160170 * session, instead of all the packets from one session, then all packets
    161  * from the next session, etc.  Packets on the if_fastq get absolute 
     171 * from the next session, etc.  Packets on the if_fastq get absolute
    162172 * priority, but if one session hogs the link, it gets "downgraded"
    163173 * to the batchq until it runs out of packets, then it'll return
     
    166176 */
    167177void
     178#ifdef VBOX
     179if_output(PNATState pData, struct socket *so, struct mbuf *ifm)
     180#else /* !VBOX */
    168181if_output(so, ifm)
    169182        struct socket *so;
    170183        struct mbuf *ifm;
     184#endif /* !VBOX */
    171185{
    172186        struct mbuf *ifq;
    173187        int on_fastq = 1;
    174        
     188
    175189        DEBUG_CALL("if_output");
    176190        DEBUG_ARG("so = %lx", (long)so);
    177191        DEBUG_ARG("ifm = %lx", (long)ifm);
    178        
     192
    179193        /*
    180194         * First remove the mbuf from m_usedlist,
     
    186200                ifm->m_flags &= ~M_USEDLIST;
    187201        }
    188        
    189         /*
    190          * See if there's already a batchq list for this session. 
     202
     203        /*
     204         * See if there's already a batchq list for this session.
    191205         * This can include an interactive session, which should go on fastq,
    192206         * but gets too greedy... hence it'll be downgraded from fastq to batchq.
     
    202216                }
    203217        }
    204        
     218
    205219        /* No match, check which queue to put it on */
    206220        if (so && (so->so_iptos & IPTOS_LOWDELAY)) {
     
    218232        } else
    219233                ifq = if_batchq.ifq_prev;
    220        
     234
    221235        /* Create a new doubly linked list for this session */
    222236        ifm->ifq_so = so;
    223237        ifs_init(ifm);
    224238        insque(ifm, ifq);
    225        
     239
    226240diddit:
    227241        ++if_queued;
    228        
     242
    229243        if (so) {
    230244                /* Update *_queued */
     
    238252                 * (XXX These are arbitrary numbers, probably not optimal..)
    239253                 */
    240                 if (on_fastq && ((so->so_nqueued >= 6) && 
     254                if (on_fastq && ((so->so_nqueued >= 6) &&
    241255                                 (so->so_nqueued - so->so_queued) >= 3)) {
    242                        
     256
    243257                        /* Remove from current queue... */
    244258                        remque(ifm->ifs_next);
    245                        
     259
    246260                        /* ...And insert in the new.  That'll teach ya! */
    247261                        insque(ifm->ifs_next, &if_batchq);
     
    255269        if (link_up) {
    256270                /* if_start will check towrite */
     271#ifdef VBOX
     272                if_start(pData);
     273#else /* !VBOX */
    257274                if_start();
     275#endif /* !VBOX */
    258276        }
    259277#endif
     
    273291 */
    274292void
     293#ifdef VBOX
     294if_start(PNATState pData)
     295#else /* !VBOX */
    275296if_start(void)
     297#endif /* !VBOX */
    276298{
    277299        struct mbuf *ifm, *ifqt;
    278        
     300
    279301        DEBUG_CALL("if_start");
    280        
     302
    281303        if (if_queued == 0)
    282304           return; /* Nothing to do */
    283        
     305
    284306 again:
    285307        /* check if we can really output */
     308#ifdef VBOX
     309        if (!slirp_can_output(pData->pvUser))
     310#else /* !VBOX */
    286311        if (!slirp_can_output())
     312#endif /* !VBOX */
    287313            return;
    288314
     
    299325                else
    300326                   ifm = if_batchq.ifq_next;
    301                
     327
    302328                /* Set which packet to send on next iteration */
    303329                next_m = ifm->ifq_next;
     
    307333        remque(ifm);
    308334        --if_queued;
    309        
     335
    310336        /* If there are more packets for this session, re-queue them */
    311337        if (ifm->ifs_next != /* ifm->ifs_prev != */ ifm) {
     
    313339                ifs_remque(ifm);
    314340        }
    315        
     341
    316342        /* Update so_queued */
    317343        if (ifm->ifq_so) {
     
    320346                   ifm->ifq_so->so_nqueued = 0;
    321347        }
    322        
     348
    323349        /* Encapsulate the packet for sending */
    324350#ifndef VBOX
    325351        if_encap(ifm->m_data, ifm->m_len);
    326352#else /* VBOX */
    327         if_encap((const uint8_t *)ifm->m_data, ifm->m_len);
     353        if_encap(pData, (const uint8_t *)ifm->m_data, ifm->m_len);
    328354#endif /* VBOX */
    329355
     356#ifdef VBOX
     357        m_free(pData, ifm);
     358#else /* !VBOX */
    330359        m_free(ifm);
     360#endif /* !VBOX */
    331361
    332362        if (if_queued)
  • trunk/src/VBox/Devices/Network/slirp/ip.h

    r1 r1033  
    213213
    214214#if SIZEOF_CHAR_P == 4
    215 typedef struct ipq *ipqp_32;
     215typedef struct ipq_t *ipqp_32;
    216216typedef struct ipasfrag *ipasfragp_32;
    217217#else
     
    239239 * size 28 bytes
    240240 */
    241 struct ipq {
     241struct ipq_t {
    242242        ipqp_32 next,prev;      /* to other reass headers */
    243243        u_int8_t        ipq_ttl;                /* time for reass q to live */
     
    300300 */
    301301
     302#ifdef VBOX
     303struct  ipstat_t {
     304#else /* !VBOX */
    302305struct  ipstat {
     306#endif /* !VBOX */
    303307        u_long  ips_total;              /* total packets received */
    304308        u_long  ips_badsum;             /* checksum bad */
     
    328332};
    329333
     334#ifndef VBOX
    330335extern struct   ipstat  ipstat;
    331336extern struct   ipq     ipq;                    /* ip reass. queue */
    332337extern u_int16_t        ip_id;                          /* ip packet ctr, for ids */
    333338extern int      ip_defttl;                      /* default IP ttl */
    334 
    335 #endif
     339#endif /* !VBOX */
     340
     341#endif
  • trunk/src/VBox/Devices/Network/slirp/ip_icmp.c

    r1 r1033  
    3838#include "ip_icmp.h"
    3939
     40#ifndef VBOX
    4041struct icmpstat icmpstat;
     42#endif /* !VBOX */
    4143
    4244/* The message sent when emulating PING */
    4345/* Be nice and tell them it's just a psuedo-ping packet */
     46#ifdef VBOX
     47static const char icmp_ping_msg[] = "This is a psuedo-PING packet used by Slirp to emulate ICMP ECHO-REQUEST packets.\n";
     48#else /* !VBOX */
    4449char icmp_ping_msg[] = "This is a psuedo-PING packet used by Slirp to emulate ICMP ECHO-REQUEST packets.\n";
     50#endif /* !VBOX */
    4551
    4652/* list of actions for icmp_error() on RX of an icmp message */
     53#ifdef VBOX
     54static const int icmp_flush[19] = {
     55#else /* !VBOX */
    4756static int icmp_flush[19] = {
     57#endif /* !VBOX */
    4858/*  ECHO REPLY (0)  */   0,
    4959                         1,
     
    6474/* INFO REPLY (16) */    0,
    6575/* ADDR MASK (17) */     0,
    66 /* ADDR MASK REPLY (18) */ 0 
     76/* ADDR MASK REPLY (18) */ 0
    6777};
    6878
     
    7181 */
    7282void
     83#ifdef VBOX
     84icmp_input(PNATState pData, struct mbuf *m, int hlen)
     85#else /* !VBOX */
    7386icmp_input(m, hlen)
    7487     struct mbuf *m;
    7588     int hlen;
     89#endif /* !VBOX */
    7690{
    7791  register struct icmp *icp;
     
    7993  int icmplen=ip->ip_len;
    8094  /* int code; */
    81        
     95
    8296  DEBUG_CALL("icmp_input");
    8397  DEBUG_ARG("m = %lx", (long )m);
     
    8599
    86100  icmpstat.icps_received++;
    87        
     101
    88102  /*
    89103   * Locate icmp structure in mbuf, and check
     
    93107    icmpstat.icps_tooshort++;
    94108  freeit:
     109#ifdef VBOX
     110    m_freem(pData, m);
     111#else /* !VBOX */
    95112    m_freem(m);
     113#endif /* !VBOX */
    96114    goto end_error;
    97115  }
     
    106124  m->m_len += hlen;
    107125  m->m_data -= hlen;
    108  
     126
    109127  /*    icmpstat.icps_inhist[icp->icmp_type]++; */
    110128  /* code = icp->icmp_code; */
     
    116134    ip->ip_len += hlen;              /* since ip_input subtracts this */
    117135    if (ip->ip_dst.s_addr == alias_addr.s_addr) {
     136#ifdef VBOX
     137      icmp_reflect(pData, m);
     138#else /* !VBOX */
    118139      icmp_reflect(m);
     140#endif /* !VBOX */
    119141    } else {
    120142      struct socket *so;
    121143      struct sockaddr_in addr;
    122144      if ((so = socreate()) == NULL) goto freeit;
     145#ifdef VBOX
     146      if(udp_attach(pData, so) == -1) {
     147#else /* !VBOX */
    123148      if(udp_attach(so) == -1) {
    124         DEBUG_MISC((dfd,"icmp_input udp_attach errno = %d-%s\n",
     149#endif /* !VBOX */
     150        DEBUG_MISC((dfd,"icmp_input udp_attach errno = %d-%s\n",
    125151                    errno,strerror(errno)));
     152#ifdef VBOX
     153        sofree(pData, so);
     154        m_free(pData, m);
     155#else /* !VBOX */
    126156        sofree(so);
    127157        m_free(m);
     158#endif /* !VBOX */
    128159        goto end_error;
    129160      }
     
    136167      so->so_type = IPPROTO_ICMP;
    137168      so->so_state = SS_ISFCONNECTED;
    138      
     169
    139170      /* Send the packet */
    140171      addr.sin_family = AF_INET;
     
    158189        DEBUG_MISC((dfd,"icmp_input udp sendto tx errno = %d-%s\n",
    159190                    errno,strerror(errno)));
    160         icmp_error(m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno));
     191#ifdef VBOX
     192        icmp_error(pData, m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno));
     193        udp_detach(pData, so);
     194#else /* !VBOX */
     195        icmp_error(m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno));
    161196        udp_detach(so);
     197#endif /* !VBOX */
    162198      }
    163199    } /* if ip->ip_dst.s_addr == alias_addr.s_addr */
     
    172208  case ICMP_REDIRECT:
    173209    icmpstat.icps_notsupp++;
     210#ifdef VBOX
     211    m_freem(pData, m);
     212#else /* !VBOX */
    174213    m_freem(m);
     214#endif /* !VBOX */
    175215    break;
    176    
     216
    177217  default:
    178218    icmpstat.icps_badtype++;
     219#ifdef VBOX
     220    m_freem(pData, m);
     221#else /* !VBOX */
    179222    m_freem(m);
     223#endif /* !VBOX */
    180224  } /* swith */
    181225
     
    200244 * It is reported as the bad ip packet.  The header should
    201245 * be fully correct and in host byte order.
    202  * ICMP fragmentation is illegal.  All machines must accept 576 bytes in one 
     246 * ICMP fragmentation is illegal.  All machines must accept 576 bytes in one
    203247 * packet.  The maximum payload is 576-20(ip hdr)-8(icmp hdr)=548
    204248 */
     
    214258     char *message;
    215259#else /* VBOX */
    216 void icmp_error(struct mbuf *msrc, u_char type, u_char code, int minsize, char *message)
     260void icmp_error(PNATState pData, struct mbuf *msrc, u_char type, u_char code, int minsize, char *message)
    217261#endif /* VBOX */
    218262{
     
    231275  if(!msrc) goto end_error;
    232276  ip = mtod(msrc, struct ip *);
    233 #if DEBUG 
     277#if DEBUG
    234278  { char bufa[20], bufb[20];
    235279    strcpy(bufa, inet_ntoa(ip->ip_src));
     
    252296
    253297  /* make a copy */
     298#ifdef VBOX
     299  if(!(m=m_get(pData))) goto end_error;               /* get mbuf */
     300#else /* !VBOX */
    254301  if(!(m=m_get())) goto end_error;               /* get mbuf */
     302#endif /* !VBOX */
    255303  { int new_m_size;
    256304    new_m_size=sizeof(struct ip )+ICMP_MINLEN+msrc->m_len+ICMP_MAXDATALEN;
     
    263311  ip  = mtod(m, struct ip *);
    264312  hlen= sizeof(struct ip );     /* no options in reply */
    265  
     313
    266314  /* fill in icmp */
    267   m->m_data += hlen;                 
     315  m->m_data += hlen;
    268316  m->m_len -= hlen;
    269317
     
    274322    s_ip_len=ICMP_MAXDATALEN;
    275323
    276   m->m_len=ICMP_MINLEN+s_ip_len;        /* 8 bytes ICMP header */ 
     324  m->m_len=ICMP_MINLEN+s_ip_len;        /* 8 bytes ICMP header */
    277325
    278326  /* min. size = 8+sizeof(struct ip)+8 */
     
    309357  ip->ip_hl = hlen >> 2;
    310358  ip->ip_len = m->m_len;
    311  
     359
    312360  ip->ip_tos=((ip->ip_tos & 0x1E) | 0xC0);  /* high priority for errors */
    313361
     
    317365  ip->ip_src = alias_addr;
    318366
     367#ifdef VBOX
     368  (void ) ip_output(pData, (struct socket *)NULL, m);
     369#else /* !VBOX */
    319370  (void ) ip_output((struct socket *)NULL, m);
    320  
     371#endif /* !VBOX */
     372
    321373  icmpstat.icps_reflect++;
    322374
     
    330382 */
    331383void
     384#ifdef VBOX
     385icmp_reflect(PNATState pData, struct mbuf *m)
     386#else /* !VBOX */
    332387icmp_reflect(m)
    333388     struct mbuf *m;
     389#endif /* !VBOX */
    334390{
    335391  register struct ip *ip = mtod(m, struct ip *);
     
    374430  }
    375431
     432#ifdef VBOX
     433  (void ) ip_output(pData, (struct socket *)NULL, m);
     434#else /* !VBOX */
    376435  (void ) ip_output((struct socket *)NULL, m);
     436#endif /* !VBOX */
    377437
    378438  icmpstat.icps_reflect++;
  • trunk/src/VBox/Devices/Network/slirp/ip_icmp.h

    r1 r1033  
    158158        (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
    159159
     160#ifdef VBOX
     161void icmp_input _P((PNATState, struct mbuf *, int));
     162void icmp_error _P((PNATState, struct mbuf *, u_char, u_char, int, char *));
     163void icmp_reflect _P((PNATState, struct mbuf *));
     164#else /* !VBOX */
    160165void icmp_input _P((struct mbuf *, int));
    161166void icmp_error _P((struct mbuf *, u_char, u_char, int, char *));
    162167void icmp_reflect _P((struct mbuf *));
     168#endif /* !VBOX */
    163169
    164170#endif
  • trunk/src/VBox/Devices/Network/slirp/ip_input.c

    r530 r1033  
    3838 * Changes and additions relating to SLiRP are
    3939 * Copyright (c) 1995 Danny Gasparovski.
    40  * 
     40 *
    4141 * Please read the file COPYRIGHT for the
    4242 * terms and conditions of the copyright.
     
    4646#include "ip_icmp.h"
    4747
     48#ifndef VBOX
    4849int ip_defttl;
    4950struct ipstat ipstat;
    5051struct ipq ipq;
     52#endif /* !VBOX */
    5153
    5254/*
     
    5557 */
    5658void
     59#ifdef VBOX
     60ip_init(PNATState pData)
     61#else /* !VBOX */
    5762ip_init()
     63#endif /* !VBOX */
    5864{
    5965        ipq.next = ipq.prev = ptr_to_u32(&ipq);
     66#ifdef VBOX
     67        ip_currid = tt.tv_sec & 0xffff;
     68        udp_init(pData);
     69        tcp_init(pData);
     70#else /* !VBOX */
    6071        ip_id = tt.tv_sec & 0xffff;
    6172        udp_init();
    6273        tcp_init();
     74#endif /* !VBOX */
     75#ifndef VBOX
    6376        ip_defttl = IPDEFTTL;
     77#endif /* !VBOX */
    6478}
    6579
     
    6983 */
    7084void
     85#ifdef VBOX
     86ip_input(PNATState pData, struct mbuf *m)
     87#else /* !VBOX */
    7188ip_input(m)
    7289        struct mbuf *m;
     90#endif /* !VBOX */
    7391{
    7492        register struct ip *ip;
    7593        int hlen;
    76        
     94
    7795        DEBUG_CALL("ip_input");
    7896        DEBUG_ARG("m = %lx", (long)m);
     
    8098
    8199        ipstat.ips_total++;
    82        
     100
    83101        if (m->m_len < sizeof (struct ip)) {
    84102                ipstat.ips_toosmall++;
    85103                return;
    86104        }
    87        
     105
    88106        ip = mtod(m, struct ip *);
    89        
     107
    90108        if (ip->ip_v != IPVERSION) {
    91109                ipstat.ips_badvers++;
     
    100118
    101119        /* keep ip header intact for ICMP reply
    102          * ip->ip_sum = cksum(m, hlen); 
    103          * if (ip->ip_sum) { 
     120         * ip->ip_sum = cksum(m, hlen);
     121         * if (ip->ip_sum) {
    104122         */
    105123        if(cksum(m,hlen)) {
     
    135153        /* check ip_ttl for a correct ICMP reply */
    136154        if(ip->ip_ttl==0 || ip->ip_ttl==1) {
     155#ifdef VBOX
     156          icmp_error(pData, m, ICMP_TIMXCEED,ICMP_TIMXCEED_INTRANS, 0,"ttl");
     157#else /* !VBOX */
    137158          icmp_error(m, ICMP_TIMXCEED,ICMP_TIMXCEED_INTRANS, 0,"ttl");
     159#endif /* !VBOX */
    138160          goto bad;
    139161        }
     
    155177         * if the packet was previously fragmented,
    156178         * but it's not worth the time; just let them time out.)
    157          * 
     179         *
    158180         * XXX This should fail, don't fragment yet
    159181         */
    160182        if (ip->ip_off &~ IP_DF) {
    161           register struct ipq *fp;
     183          register struct ipq_t *fp;
    162184                /*
    163185                 * Look for queue of fragments
    164186                 * of this datagram.
    165187                 */
    166                 for (fp = u32_to_ptr(ipq.next, struct ipq *); fp != &ipq;
    167                      fp = u32_to_ptr(fp->next, struct ipq *))
     188                for (fp = u32_to_ptr(ipq.next, struct ipq_t *); fp != &ipq;
     189                     fp = u32_to_ptr(fp->next, struct ipq_t *))
    168190                  if (ip->ip_id == fp->ipq_id &&
    169191                      ip->ip_src.s_addr == fp->ipq_src.s_addr &&
     
    182204                if (ip->ip_off & IP_MF)
    183205                  ((struct ipasfrag *)ip)->ipf_mff |= 1;
    184                 else 
     206                else
    185207                  ((struct ipasfrag *)ip)->ipf_mff &= ~1;
    186208
     
    194216                if (((struct ipasfrag *)ip)->ipf_mff & 1 || ip->ip_off) {
    195217                        ipstat.ips_fragments++;
     218#ifdef VBOX
     219                        ip = ip_reass(pData, (struct ipasfrag *)ip, fp);
     220#else /* !VBOX */
    196221                        ip = ip_reass((struct ipasfrag *)ip, fp);
     222#endif /* !VBOX */
    197223                        if (ip == 0)
    198224                                return;
    199225                        ipstat.ips_reassembled++;
     226#ifdef VBOX
     227                        m = dtom(pData, ip);
     228#else /* !VBOX */
    200229                        m = dtom(ip);
     230#endif /* !VBOX */
    201231                } else
    202232                        if (fp)
     233#ifdef VBOX
     234                           ip_freef(pData, fp);
     235#else /* !VBOX */
    203236                           ip_freef(fp);
     237#endif /* !VBOX */
    204238
    205239        } else
     
    212246        switch (ip->ip_p) {
    213247         case IPPROTO_TCP:
     248#ifdef VBOX
     249                tcp_input(pData, m, hlen, (struct socket *)NULL);
     250#else /* !VBOX */
    214251                tcp_input(m, hlen, (struct socket *)NULL);
     252#endif /* !VBOX */
    215253                break;
    216254         case IPPROTO_UDP:
     255#ifdef VBOX
     256                udp_input(pData, m, hlen);
     257#else /* !VBOX */
    217258                udp_input(m, hlen);
     259#endif /* !VBOX */
    218260                break;
    219261         case IPPROTO_ICMP:
     262#ifdef VBOX
     263                icmp_input(pData, m, hlen);
     264#else /* !VBOX */
    220265                icmp_input(m, hlen);
     266#endif /* !VBOX */
    221267                break;
    222268         default:
    223269                ipstat.ips_noproto++;
     270#ifdef VBOX
     271                m_free(pData, m);
     272#else /* !VBOX */
    224273                m_free(m);
     274#endif /* !VBOX */
    225275        }
    226276        return;
    227277bad:
     278#ifdef VBOX
     279        m_freem(pData, m);
     280#else /* !VBOX */
    228281        m_freem(m);
     282#endif /* !VBOX */
    229283        return;
    230284}
     
    237291 */
    238292struct ip *
     293#ifdef VBOX
     294ip_reass(PNATState pData, register struct ipasfrag *ip, register struct ipq_t *fp)
     295#else /* !VBOX */
    239296ip_reass(ip, fp)
    240297        register struct ipasfrag *ip;
    241         register struct ipq *fp;
     298        register struct ipq_t *fp;
     299#endif /* !VBOX */
    242300{
     301#ifdef VBOX
     302        register struct mbuf *m = dtom(pData, ip);
     303#else /* !VBOX */
    243304        register struct mbuf *m = dtom(ip);
     305#endif /* !VBOX */
    244306        register struct ipasfrag *q;
    245307        int hlen = ip->ip_hl << 2;
    246308        int i, next;
    247        
     309
    248310        DEBUG_CALL("ip_reass");
    249311        DEBUG_ARG("ip = %lx", (long)ip);
     
    264326        if (fp == 0) {
    265327          struct mbuf *t;
     328#ifdef VBOX
     329          if ((t = m_get(pData)) == NULL) goto dropfrag;
     330#else /* !VBOX */
    266331          if ((t = m_get()) == NULL) goto dropfrag;
    267           fp = mtod(t, struct ipq *);
     332#endif /* !VBOX */
     333          fp = mtod(t, struct ipq_t *);
    268334          insque_32(fp, &ipq);
    269335          fp->ipq_ttl = IPFRAGTTL;
     
    276342          goto insert;
    277343        }
    278        
     344
    279345        /*
    280346         * Find a segment which begins after this one does.
     
    290356         * segment.  If it provides all of our data, drop us.
    291357         */
    292         if (u32_to_ptr(q->ipf_prev, struct ipq *) != fp) {
     358        if (u32_to_ptr(q->ipf_prev, struct ipq_t *) != fp) {
    293359                i = (u32_to_ptr(q->ipf_prev, struct ipasfrag *))->ip_off +
    294360                  (u32_to_ptr(q->ipf_prev, struct ipasfrag *))->ip_len - ip->ip_off;
     
    296362                        if (i >= ip->ip_len)
    297363                                goto dropfrag;
     364#ifdef VBOX
     365                        m_adj(dtom(pData, ip), i);
     366#else /* !VBOX */
    298367                        m_adj(dtom(ip), i);
     368#endif /* !VBOX */
    299369                        ip->ip_off += i;
    300370                        ip->ip_len -= i;
     
    311381                        q->ip_len -= i;
    312382                        q->ip_off += i;
     383#ifdef VBOX
     384                        m_adj(dtom(pData, q), i);
     385#else /* !VBOX */
    313386                        m_adj(dtom(q), i);
     387#endif /* !VBOX */
    314388                        break;
    315389                }
    316390                q = u32_to_ptr(q->ipf_next, struct ipasfrag *);
    317                 m_freem(dtom(u32_to_ptr(q->ipf_prev, struct ipasfrag *)));
     391                m_freem(pData, dtom(pData, u32_to_ptr(q->ipf_prev, struct ipasfrag *)));
    318392                ip_deq(u32_to_ptr(q->ipf_prev, struct ipasfrag *));
    319393        }
     
    339413         */
    340414        q = u32_to_ptr(fp->ipq_next, struct ipasfrag *);
     415#ifdef VBOX
     416        m = dtom(pData, q);
     417#else /* !VBOX */
    341418        m = dtom(q);
     419#endif /* !VBOX */
    342420
    343421        q = u32_to_ptr(q->ipf_next, struct ipasfrag *);
    344422        while (q != (struct ipasfrag *)fp) {
    345423          struct mbuf *t;
     424#ifdef VBOX
     425          t = dtom(pData, q);
     426#else /* !VBOX */
    346427          t = dtom(q);
     428#endif /* !VBOX */
    347429          q = u32_to_ptr(q->ipf_next, struct ipasfrag *);
     430#ifdef VBOX
     431          m_cat(pData, m, t);
     432#else /* !VBOX */
    348433          m_cat(m, t);
     434#endif /* !VBOX */
    349435        }
    350436
     
    370456        }
    371457
    372         /* DEBUG_ARG("ip = %lx", (long)ip); 
     458        /* DEBUG_ARG("ip = %lx", (long)ip);
    373459         * ip=(struct ipasfrag *)m->m_data; */
    374460
     
    378464        ((struct ip *)ip)->ip_dst = fp->ipq_dst;
    379465        remque_32(fp);
     466#ifdef VBOX
     467        (void) m_free(pData, dtom(pData, fp));
     468        m = dtom(pData, ip);
     469#else /* !VBOX */
    380470        (void) m_free(dtom(fp));
    381471        m = dtom(ip);
     472#endif /* !VBOX */
    382473        m->m_len += (ip->ip_hl << 2);
    383474        m->m_data -= (ip->ip_hl << 2);
     
    387478dropfrag:
    388479        ipstat.ips_fragdropped++;
     480#ifdef VBOX
     481        m_freem(pData, m);
     482#else /* !VBOX */
    389483        m_freem(m);
     484#endif /* !VBOX */
    390485        return (0);
    391486}
     
    396491 */
    397492void
     493#ifdef VBOX
     494ip_freef(PNATState pData, struct ipq_t *fp)
     495#else /* !VBOX */
    398496ip_freef(fp)
    399         struct ipq *fp;
     497        struct ipq_t *fp;
     498#endif /* !VBOX */
    400499{
    401500        register struct ipasfrag *q, *p;
     
    405504                p = u32_to_ptr(q->ipf_next, struct ipasfrag *);
    406505                ip_deq(q);
     506#ifdef VBOX
     507                m_freem(pData, dtom(pData, q));
     508#else /* !VBOX */
    407509                m_freem(dtom(q));
     510#endif /* !VBOX */
    408511        }
    409512        remque_32(fp);
     513#ifdef VBOX
     514        (void) m_free(pData, dtom(pData, fp));
     515#else /* !VBOX */
    410516        (void) m_free(dtom(fp));
     517#endif /* !VBOX */
    411518}
    412519
     
    447554 */
    448555void
     556#ifdef VBOX
     557ip_slowtimo(PNATState pData)
     558#else /* !VBOX */
    449559ip_slowtimo()
     560#endif /* !VBOX */
    450561{
    451         register struct ipq *fp;
    452        
     562        register struct ipq_t *fp;
     563
    453564        DEBUG_CALL("ip_slowtimo");
    454        
    455         fp = u32_to_ptr(ipq.next, struct ipq *);
     565
     566        fp = u32_to_ptr(ipq.next, struct ipq_t *);
    456567        if (fp == 0)
    457568           return;
     
    459570        while (fp != &ipq) {
    460571                --fp->ipq_ttl;
    461                 fp = u32_to_ptr(fp->next, struct ipq *);
    462                 if (u32_to_ptr(fp->prev, struct ipq *)->ipq_ttl == 0) {
     572                fp = u32_to_ptr(fp->next, struct ipq_t *);
     573                if (u32_to_ptr(fp->prev, struct ipq_t *)->ipq_ttl == 0) {
    463574                        ipstat.ips_fragtimeout++;
    464                         ip_freef(u32_to_ptr(fp->prev, struct ipq *));
     575                        ip_freef(pData, u32_to_ptr(fp->prev, struct ipq_t *));
    465576                }
    466577        }
     
    696807        memcpy(opts, opts  + olen, (unsigned)i);
    697808        m->m_len -= olen;
    698        
     809
    699810        ip->ip_hl = sizeof(struct ip) >> 2;
    700811}
  • trunk/src/VBox/Devices/Network/slirp/ip_output.c

    r1 r1033  
    4545#include <slirp.h>
    4646
     47#ifndef VBOX
    4748u_int16_t ip_id;
     49#endif /* !VBOX */
    4850
    4951/*
     
    5456 */
    5557int
     58#ifdef VBOX
     59ip_output(PNATState pData, struct socket *so, struct mbuf *m0)
     60#else /* !VBOX */
    5661ip_output(so, m0)
    5762        struct socket *so;
    5863        struct mbuf *m0;
     64#endif /* !VBOX */
    5965{
    6066        register struct ip *ip;
     
    6672        DEBUG_ARG("so = %lx", (long)so);
    6773        DEBUG_ARG("m0 = %lx", (long)m0);
    68        
     74
    6975        /* We do no options */
    7076/*      if (opt) {
     
    7985        ip->ip_v = IPVERSION;
    8086        ip->ip_off &= IP_DF;
     87#ifdef VBOX
     88        ip->ip_id = htons(ip_currid++);
     89#else /* !VBOX */
    8190        ip->ip_id = htons(ip_id++);
     91#endif /* !VBOX */
    8292        ip->ip_hl = hlen >> 2;
    8393        ipstat.ips_localout++;
     
    93103 *      }
    94104 */
    95        
     105
    96106        /*
    97107         * If small enough for interface, can just send directly.
     
    103113                ip->ip_sum = cksum(m, hlen);
    104114
     115#ifdef VBOX
     116                if_output(pData, so, m);
     117#else /* !VBOX */
    105118                if_output(so, m);
     119#endif /* !VBOX */
    106120                goto done;
    107121        }
     
    116130                goto bad;
    117131        }
    118        
     132
    119133        len = (if_mtu - hlen) &~ 7;       /* ip databytes per packet */
    120134        if (len < 8) {
     
    135149        for (off = hlen + len; off < (u_int16_t)ip->ip_len; off += len) {
    136150          register struct ip *mhip;
     151#ifdef VBOX
     152          m = m_get(pData);
     153#else /* !VBOX */
    137154          m = m_get();
     155#endif /* !VBOX */
    138156          if (m == 0) {
    139157            error = -1;
     
    144162          mhip = mtod(m, struct ip *);
    145163          *mhip = *ip;
    146                
     164
    147165                /* No options */
    148166/*              if (hlen > sizeof (struct ip)) {
     
    157175          if (off + len >= (u_int16_t)ip->ip_len)
    158176            len = (u_int16_t)ip->ip_len - off;
    159           else 
     177          else
    160178            mhip->ip_off |= IP_MF;
    161179          mhip->ip_len = htons((u_int16_t)(len + mhlen));
    162          
     180
    163181          if (m_copy(m, m0, off, len) < 0) {
    164182            error = -1;
    165183            goto sendorfree;
    166184          }
    167          
     185
    168186          mhip->ip_off = htons((u_int16_t)mhip->ip_off);
    169187          mhip->ip_sum = 0;
     
    188206                m->m_nextpkt = 0;
    189207                if (error == 0)
     208#ifdef VBOX
     209                        if_output(pData, so, m);
     210#else /* !VBOX */
    190211                        if_output(so, m);
     212#endif /* !VBOX */
    191213                else
     214#ifdef VBOX
     215                        m_freem(pData, m);
     216#else /* !VBOX */
    192217                        m_freem(m);
     218#endif /* !VBOX */
    193219        }
    194220
     
    201227
    202228bad:
     229#ifdef VBOX
     230        m_freem(pData, m0);
     231#else /* !VBOX */
    203232        m_freem(m0);
     233#endif /* !VBOX */
    204234        goto done;
    205235}
  • trunk/src/VBox/Devices/Network/slirp/libslirp.h

    r530 r1033  
    2121#ifdef VBOX
    2222#include <VBox/types.h>
     23
     24typedef struct NATState *PNATState;
    2325#endif /* VBOX */
    2426
     
    3032void slirp_init(void);
    3133#else /* VBOX */
    32 int slirp_init(void);
    33 void slirp_term(void);
    34 void slirp_link_up(void);
    35 void slirp_link_down(void);
     34int slirp_init(PNATState *, const char *, void *);
     35void slirp_term(PNATState);
     36void slirp_link_up(PNATState);
     37void slirp_link_down(PNATState);
    3638# if ARCH_BITS == 64
     39error fix the last remaining global variables.....
    3740extern uint32_t g_cpvHashUsed;
    3841extern uint32_t g_cpvHashCollisions;
    3942extern uint64_t g_cpvHashInserts;
    4043extern uint64_t g_cpvHashDone;
    41 # endif 
     44# endif
    4245#endif /* VBOX */
    4346
     47#ifdef VBOX
     48void slirp_select_fill(PNATState pData, int *pnfds,
     49                       fd_set *readfds, fd_set *writefds, fd_set *xfds);
     50
     51void slirp_select_poll(PNATState pData, fd_set *readfds, fd_set *writefds, fd_set *xfds);
     52
     53void slirp_input(PNATState pData, const uint8_t *pkt, int pkt_len);
     54#else /* !VBOX */
    4455void slirp_select_fill(int *pnfds,
    4556                       fd_set *readfds, fd_set *writefds, fd_set *xfds);
     
    4859
    4960void slirp_input(const uint8_t *pkt, int pkt_len);
     61#endif /* !VBOX */
    5062
     63#ifdef VBOX
     64/* you must provide the following functions: */
     65int slirp_can_output(void * pvUser);
     66void slirp_output(void * pvUser, const uint8_t *pkt, int pkt_len);
     67
     68int slirp_redir(PNATState pData, int is_udp, int host_port,
     69                struct in_addr guest_addr, int guest_port);
     70int slirp_add_exec(PNATState pData, int do_pty, const char *args, int addr_low_byte,
     71                   int guest_port);
     72#else /* !VBOX */
    5173/* you must provide the following functions: */
    5274int slirp_can_output(void);
     
    5779int slirp_add_exec(int do_pty, const char *args, int addr_low_byte,
    5880                   int guest_port);
     81#endif /* !VBOX */
    5982
     83#ifndef VBOX
    6084extern const char *tftp_prefix;
    6185extern char slirp_hostname[33];
     86#endif /* !VBOX */
    6287
    6388#ifdef __cplusplus
  • trunk/src/VBox/Devices/Network/slirp/main.h

    r1 r1033  
    11/*
    22 * Copyright (c) 1995 Danny Gasparovski.
    3  * 
    4  * Please read the file COPYRIGHT for the 
     3 *
     4 * Please read the file COPYRIGHT for the
    55 * terms and conditions of the copyright.
    66 */
     
    1212#define TOWRITEMAX 512
    1313
     14#ifndef VBOX
    1415extern struct timeval tt;
    1516extern int link_up;
     
    2021extern char *slirp_socket_passwd;
    2122extern int ctty_closed;
     23#endif /* !VBOX */
    2224
    2325/*
     
    2931#define TIME_DIFF(x,y) (x)-(y) < 0 ? ~0-(y)+(x) : (x)-(y)
    3032
     33#ifndef VBOX
    3134extern char *slirp_tty;
    3235extern char *exec_shell;
     
    4649extern int tcp_keepintvl;
    4750extern uint8_t client_ethaddr[6];
     51#endif /* !VBOX */
    4852
    4953#define PROTO_SLIP 0x1
     
    5256#endif
    5357
     58#ifdef VBOX
     59void if_encap(PNATState pData, const uint8_t *ip_data, int ip_data_len);
     60#else /* !VBOX */
    5461void if_encap(const uint8_t *ip_data, int ip_data_len);
     62#endif /* !VBOX */
  • trunk/src/VBox/Devices/Network/slirp/mbuf.c

    r531 r1033  
    1818#include <slirp.h>
    1919
     20#ifndef VBOX
    2021struct  mbuf *mbutl;
    2122char    *mclrefcnt;
     
    2526int mbuf_max = 0;
    2627int msize;
    27 
    28 void
     28#endif /* !VBOX */
     29
     30void
     31#ifdef VBOX
     32m_init(PNATState pData)
     33#else /* !VBOX */
    2934m_init()
     35#endif /* !VBOX */
    3036{
    3137        m_freelist.m_next = m_freelist.m_prev = &m_freelist;
    3238        m_usedlist.m_next = m_usedlist.m_prev = &m_usedlist;
     39#ifdef VBOX
     40        mbuf_alloced = 0;
     41        msize_init(pData);
     42#else /* !VBOX */
    3343        msize_init();
    34 }
    35 
    36 void
     44#endif /* !VBOX */
     45}
     46
     47void
     48#ifdef VBOX
     49msize_init(PNATState pData)
     50#else /* !VBOX */
    3751msize_init()
     52#endif /* !VBOX */
    3853{
    3954        /*
     
    4156         * XXX if_maxlinkhdr already in mtu
    4257         */
    43         msize = (if_mtu>if_mru?if_mtu:if_mru) + 
     58        msize = (if_mtu>if_mru?if_mtu:if_mru) +
    4459                        if_maxlinkhdr + sizeof(struct m_hdr ) + 6;
    4560}
     
    4863 * Get an mbuf from the free list, if there are none
    4964 * malloc one
    50  * 
     65 *
    5166 * Because fragmentation can occur if we alloc new mbufs and
    5267 * free old mbufs, we mark all mbufs above mbuf_thresh as M_DOFREE,
     
    5469 */
    5570struct mbuf *
     71#ifdef VBOX
     72m_get(PNATState pData)
     73#else /* !VBOX */
    5674m_get()
     75#endif /* !VBOX */
    5776{
    5877        register struct mbuf *m;
    5978        int flags = 0;
    60        
     79
    6180        DEBUG_CALL("m_get");
    62        
     81
    6382        if (m_freelist.m_next == &m_freelist) {
    6483                m = (struct mbuf *)malloc(msize);
     
    7392                remque(m);
    7493        }
    75        
     94
    7695        /* Insert it in the used list */
    7796        insque(m,&m_usedlist);
    7897        m->m_flags = (flags | M_USEDLIST);
    79        
     98
    8099        /* Initialise it */
    81100        m->m_size = msize - sizeof(struct m_hdr);
     
    90109
    91110void
     111#ifdef VBOX
     112m_free(PNATState pData, struct mbuf *m)
     113#else /* !VBOX */
    92114m_free(m)
    93115        struct mbuf *m;
    94 {
    95        
     116#endif /* !VBOX */
     117{
     118
    96119  DEBUG_CALL("m_free");
    97120  DEBUG_ARG("m = %lx", (long )m);
    98        
     121
    99122  if(m) {
    100123        /* Remove from m_usedlist */
    101124        if (m->m_flags & M_USEDLIST)
    102125           remque(m);
    103        
     126
    104127        /* If it's M_EXT, free() it */
    105128        if (m->m_flags & M_EXT)
     
    126149 */
    127150void
     151#ifdef VBOX
     152m_cat(PNATState pData, register struct mbuf *m, register struct mbuf *n)
     153#else /* !VBOX */
    128154m_cat(m, n)
    129155        register struct mbuf *m, *n;
     156#endif /* !VBOX */
    130157{
    131158        /*
     
    134161        if (M_FREEROOM(m) < n->m_len)
    135162                m_inc(m,m->m_size+MINCSIZE);
    136        
     163
    137164        memcpy(m->m_data+m->m_len, n->m_data, n->m_len);
    138165        m->m_len += n->m_len;
    139166
     167#ifdef VBOX
     168        m_free(pData, n);
     169#else /* !VBOX */
    140170        m_free(n);
     171#endif /* !VBOX */
    141172}
    142173
     
    158189/*              if (m->m_ext == NULL)
    159190 *                      return (struct mbuf *)NULL;
    160  */             
     191 */
    161192          m->m_data = m->m_ext + datasize;
    162193        } else {
     
    168199 */
    169200          memcpy(dat, m->m_dat, m->m_size);
    170          
     201
    171202          m->m_ext = dat;
    172203          m->m_data = m->m_ext + datasize;
    173204          m->m_flags |= M_EXT;
    174205        }
    175  
     206
    176207        m->m_size = size;
    177208
     
    222253 */
    223254struct mbuf *
     255#ifdef VBOX
     256dtom(PNATState pData, void *dat)
     257#else /* !VBOX */
    224258dtom(dat)
    225259        void *dat;
     260#endif /* !VBOX */
    226261{
    227262        struct mbuf *m;
    228        
     263
    229264        DEBUG_CALL("dtom");
    230265        DEBUG_ARG("dat = %lx", (long )dat);
     
    240275          }
    241276        }
    242        
     277
    243278        DEBUG_ERROR((dfd, "dtom failed"));
    244        
     279
    245280        return (struct mbuf *)0;
    246281}
  • trunk/src/VBox/Devices/Network/slirp/mbuf.h

    r1 r1033  
    7070        int     mh_size;                /* Size of data */
    7171        struct  socket *mh_so;
    72        
     72
    7373        caddr_t mh_data;                /* Location of data */
    7474        int     mh_len;                 /* Amount of data in this mbuf */
    7575};
    7676
    77 /* 
     77/*
    7878 * How much room is in the mbuf, from m_data to the end of the mbuf
    7979 */
     
    127127struct mbstat {
    128128        int mbs_alloced;                /* Number of mbufs allocated */
    129        
     129
    130130};
    131131
     
    135135extern int mbuf_max;
    136136
     137#ifdef VBOX
     138void m_init _P((PNATState));
     139void msize_init _P((PNATState));
     140struct mbuf * m_get _P((PNATState));
     141void m_free _P((PNATState, struct mbuf *));
     142void m_cat _P((PNATState, register struct mbuf *, register struct mbuf *));
     143#else /* !VBOX */
    137144void m_init _P((void));
    138145void msize_init _P((void));
     
    140147void m_free _P((struct mbuf *));
    141148void m_cat _P((register struct mbuf *, register struct mbuf *));
     149#endif /* !VBOX */
    142150void m_inc _P((struct mbuf *, int));
    143151void m_adj _P((struct mbuf *, int));
    144152int m_copy _P((struct mbuf *, struct mbuf *, int, int));
     153#ifdef VBOX
     154struct mbuf * dtom _P((PNATState, void *));
     155#else /* !VBOX */
    145156struct mbuf * dtom _P((void *));
     157#endif /* !VBOX */
    146158
    147159#endif
  • trunk/src/VBox/Devices/Network/slirp/misc.c

    r674 r1033  
    11/*
    22 * Copyright (c) 1995 Danny Gasparovski.
    3  * 
     3 *
    44 * Please read the file COPYRIGHT for the
    55 * terms and conditions of the copyright.
     
    99#include <slirp.h>
    1010
     11#ifndef VBOX
    1112u_int curtime, time_fasttimo, last_slowtimo, detach_time;
    1213u_int detach_wait = 600000;     /* 10 minutes */
     14#endif /* !VBOX */
    1315
    1416#if 0
     
    3234                   lprint("X Redir: Redirecting to display %d\r\n", x_display);
    3335        }
    34        
     36
    3537        return CFG_OK;
    3638}
     
    4850{
    4951        int i;
    50        
     52
    5153        if (x_port >= 0) {
    5254                lprint("X Redir: X already being redirected.\r\n");
     
    8688 */
    8789void
     90#ifdef VBOX
     91getouraddr(PNATState pData)
     92#else /* !VBOX */
    8893getouraddr()
     94#endif /* !VBOX */
    8995{
    9096        char buff[256];
    9197        struct hostent *he = NULL;
    92        
     98
    9399        if (gethostname(buff,256) == 0)
    94100            he = gethostbyname(buff);
     
    125131
    126132#ifndef _MSC_VER
    127 inline 
     133inline
    128134#endif
    129135void
     
    192198{
    193199        struct ex_list *tmp_ptr;
    194        
     200
    195201        /* First, check if the port is "bound" */
    196202        for (tmp_ptr = *ex_ptr; tmp_ptr; tmp_ptr = tmp_ptr->ex_next) {
     
    198204                   return -1;
    199205        }
    200        
     206
    201207        tmp_ptr = *ex_ptr;
    202208        *ex_ptr = (struct ex_list *)malloc(sizeof(struct ex_list));
     
    245251#else
    246252
     253#ifndef VBOX
    247254int
    248255slirp_openpty(amaster, aslave)
     
    253260#ifdef HAVE_GRANTPT
    254261        char *ptr;
    255        
     262
    256263        if ((master = open("/dev/ptmx", O_RDWR)) < 0 ||
    257264            grantpt(master) < 0 ||
     
    261268                return -1;
    262269        }
    263        
     270
    264271        if ((slave = open(ptr, O_RDWR)) < 0 ||
    265272            ioctl(slave, I_PUSH, "ptem") < 0 ||
     
    270277                return -1;
    271278        }
    272        
     279
    273280        *amaster = master;
    274281        *aslave = slave;
    275282        return 0;
    276        
    277 #else
    278        
     283
     284#else
     285
    279286        static char line[] = "/dev/ptyXX";
    280287        register const char *cp1, *cp2;
    281        
     288
    282289        for (cp1 = "pqrsPQRS"; *cp1; cp1++) {
    283290                line[8] = *cp1;
     
    309316#endif
    310317}
     318#endif /* !VBOX */
    311319
    312320/*
     
    316324 * exec the wanted program.  If something (strange) happens,
    317325 * the accept() call could block us forever.
    318  * 
     326 *
    319327 * do_pty = 0   Fork/exec inetd style
    320328 * do_pty = 1   Fork/exec using slirp.telnetd
     
    322330 */
    323331int
     332#ifdef VBOX
     333fork_exec(PNATState pData, struct socket *so, char *ex, int do_pty)
     334#else /* !VBOX */
    324335fork_exec(so, ex, do_pty)
    325336        struct socket *so;
    326337        char *ex;
    327338        int do_pty;
     339#endif /* !VBOX */
    328340{
    329341        int s;
     
    344356        char *curarg;
    345357        int c, i, ret;
    346        
     358
    347359        DEBUG_CALL("fork_exec");
    348360        DEBUG_ARG("so = %lx", (long)so);
    349361        DEBUG_ARG("ex = %lx", (long)ex);
    350362        DEBUG_ARG("do_pty = %lx", (long)do_pty);
    351        
     363
    352364        if (do_pty == 2) {
     365#ifdef VBOX
     366                AssertRelease(do_pty != 2);
     367#else /* !VBOX */
    353368                if (slirp_openpty(&master, &s) == -1) {
    354369                        lprint("Error: openpty failed: %s\n", strerror(errno));
    355370                        return 0;
    356371                }
     372#endif /* !VBOX */
    357373        } else {
    358374                addr.sin_family = AF_INET;
    359375                addr.sin_port = 0;
    360376                addr.sin_addr.s_addr = INADDR_ANY;
    361                
     377
    362378                if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0 ||
    363379                    bind(s, (struct sockaddr *)&addr, addrlen) < 0 ||
     
    365381                        lprint("Error: inet socket: %s\n", strerror(errno));
    366382                        closesocket(s);
    367                        
     383
    368384                        return 0;
    369385                }
    370386        }
    371        
     387
    372388        switch(fork()) {
    373389         case -1:
     
    377393                   close(master);
    378394                return 0;
    379                
     395
    380396         case 0:
    381397                /* Set the DISPLAY */
     
    399415                        } while (ret < 0 && errno == EINTR);
    400416                }
    401                
     417
    402418#if 0
    403419                if (x_port >= 0) {
     
    410426#endif
    411427                }
    412 #endif 
     428#endif
    413429                dup2(s, 0);
    414430                dup2(s, 1);
     
    416432                for (s = 3; s <= 255; s++)
    417433                   close(s);
    418                
     434
    419435                i = 0;
    420436                bptr = strdup(ex); /* No need to free() this */
     
    434450                        argv[i++] = strdup(curarg);
    435451                   } while (c);
    436                
     452
    437453                argv[i] = 0;
    438454                execvp(argv[0], argv);
    439                
     455
    440456                /* Ooops, failed, let's tell the user why */
    441457                  {
    442458                          char buff[256];
    443                          
    444                           sprintf(buff, "Error: execvp of %s failed: %s\n", 
     459
     460                          sprintf(buff, "Error: execvp of %s failed: %s\n",
    445461                                  argv[0], strerror(errno));
    446462                          write(2, buff, strlen(buff)+1);
     
    448464                close(0); close(1); close(2); /* XXX */
    449465                exit(1);
    450                
     466
    451467         default:
    452468                if (do_pty == 2) {
     
    471487                }
    472488                fd_nonblock(so->s);
    473                
     489
    474490                /* Append the telnet options now */
    475491                if (so->so_m != 0 && do_pty == 1)  {
     492#ifdef VBOX
     493                        sbappend(pData, so, so->so_m);
     494#else /* !VBOX */
    476495                        sbappend(so, so->so_m);
     496#endif /* !VBOX */
    477497                        so->so_m = 0;
    478498                }
    479                
     499
    480500                return 1;
    481501        }
     
    489509{
    490510        char *bptr;
    491        
     511
    492512        bptr = (char *)malloc(strlen(str)+1);
    493513        strcpy(bptr, str);
    494        
     514
    495515        return bptr;
    496516}
     
    508528        struct sockaddr_in sock_in;
    509529        char buff[256];
    510        
     530
    511531        ret = -1;
    512532        if (slirp_socket_passwd) {
     
    538558        slirp_exit(0);
    539559}
    540        
    541        
     560
     561
    542562void
    543563snooze()
     
    545565        sigset_t s;
    546566        int i;
    547        
     567
    548568        /* Don't need our data anymore */
    549569        /* XXX This makes SunOS barf */
    550570/*      brk(0); */
    551        
     571
    552572        /* Close all fd's */
    553573        for (i = 255; i >= 0; i--)
    554574           close(i);
    555        
     575
    556576        signal(SIGQUIT, slirp_exit);
    557577        signal(SIGHUP, snooze_hup);
    558578        sigemptyset(&s);
    559        
     579
    560580        /* Wait for any signal */
    561581        sigsuspend(&s);
    562        
     582
    563583        /* Just in case ... */
    564584        exit(255);
     
    573593        fd_set readfds;
    574594        struct ttys *ttyp;
    575        
     595
    576596        /* Don't need our data anymore */
    577597        /* XXX This makes SunOS barf */
    578598/*      brk(0); */
    579        
     599
    580600        signal(SIGQUIT, slirp_exit);
    581601        signal(SIGHUP, slirp_exit);
    582602        signal(SIGINT, slirp_exit);
    583603        signal(SIGTERM, slirp_exit);
    584        
     604
    585605        /* Fudge to get term_raw and term_restore to work */
    586606        if (NULL == (ttyp = tty_attach (0, slirp_tty))) {
     
    591611        ttyp->flags |= TTY_CTTY;
    592612        term_raw(ttyp);
    593        
     613
    594614        while (1) {
    595615                FD_ZERO(&readfds);
    596                
     616
    597617                FD_SET(0, &readfds);
    598618                FD_SET(s, &readfds);
    599                
     619
    600620                n = select(s+1, &readfds, (fd_set *)0, (fd_set *)0, (struct timeval *)0);
    601                
     621
    602622                if (n <= 0)
    603623                   slirp_exit(0);
    604                
     624
    605625                if (FD_ISSET(0, &readfds)) {
    606626                        n = read(0, buf, 8192);
     
    611631                           slirp_exit(0);
    612632                }
    613                
     633
    614634                if (FD_ISSET(s, &readfds)) {
    615635                        n = read(s, buf, 8192);
     
    621641                }
    622642        }
    623        
     643
    624644        /* Just in case.... */
    625645        exit(1);
     
    639659{
    640660        va_list args;
    641        
     661
    642662#ifdef __STDC__
    643663        va_start(args, format);
     
    656676                        int deltar = lprint_sb->sb_rptr - lprint_sb->sb_data;
    657677                        int deltap = lprint_ptr -         lprint_sb->sb_data;
    658                                                
     678
    659679                        lprint_sb->sb_data = (char *)realloc(lprint_sb->sb_data,
    660680                                                             lprint_sb->sb_datalen + TCP_SNDSPACE);
    661                        
     681
    662682                        /* Adjust all values */
    663683                        lprint_sb->sb_wptr = lprint_sb->sb_data + deltaw;
    664684                        lprint_sb->sb_rptr = lprint_sb->sb_data + deltar;
    665685                        lprint_ptr =         lprint_sb->sb_data + deltap;
    666                        
     686
    667687                        lprint_sb->sb_datalen += TCP_SNDSPACE;
    668688                }
    669689        }
    670 #endif 
     690#endif
    671691        if (lprint_print)
    672692           lprint_ptr += (*lprint_print)(*lprint_arg, format, args);
    673        
     693
    674694        /* Check if they want output to be logged to file as well */
    675695        if (lfd) {
    676                 /* 
     696                /*
    677697                 * Remove \r's
    678698                 * otherwise you'll get ^M all over the file
     
    680700                int len = strlen(format);
    681701                char *bptr1, *bptr2;
    682                
     702
    683703                bptr1 = bptr2 = strdup(format);
    684                
     704
    685705                while (len--) {
    686706                        if (*bptr1 == '\r')
     
    705725        struct emu_t *emup;
    706726        struct socket *so;
    707        
     727
    708728        if (sscanf(buff, "%256s %256s", buff2, buff1) != 2) {
    709729                lprint("Error: Bad arguments\r\n");
    710730                return;
    711731        }
    712        
     732
    713733        if (sscanf(buff1, "%d:%d", &lport, &fport) != 2) {
    714734                lport = 0;
     
    718738                }
    719739        }
    720        
     740
    721741        if (sscanf(buff2, "%128[^:]:%128s", buff1, buff3) != 2) {
    722742                buff3 = 0;
     
    726746                }
    727747        }
    728        
     748
    729749        if (buff3) {
    730750                if (strcmp(buff3, "lowdelay") == 0)
     
    737757                }
    738758        }
    739        
     759
    740760        if (strcmp(buff1, "ftp") == 0)
    741761           emu = EMU_FTP;
     
    748768                return;
    749769        }
    750        
     770
    751771        /* First, check that it isn't already emulated */
    752772        for (emup = tcpemu; emup; emup = emup->next) {
     
    756776                }
    757777        }
    758        
     778
    759779        /* link it */
    760780        emup = (struct emu_t *)malloc(sizeof (struct emu_t));
     
    765785        emup->next = tcpemu;
    766786        tcpemu = emup;
    767        
     787
    768788        /* And finally, mark all current sessions, if any, as being emulated */
    769789        for (so = tcb.so_next; so != &tcb; so = so->so_next) {
     
    776796                }
    777797        }
    778        
     798
    779799        lprint("Adding emulation for %s to port %d/%d\r\n", buff1, emup->lport, emup->fport);
    780800}
     
    829849        struct timeval t;
    830850        fd_set fdset;
    831        
     851
    832852        FD_ZERO(&fdset);
    833        
     853
    834854        t.tv_sec = 0;
    835855        t.tv_usec = usec * 1000;
    836        
     856
    837857        select(0, &fdset, &fdset, &fdset, &t);
    838858}
     
    848868#ifdef FIONBIO
    849869        int opt = 1;
    850        
     870
    851871        ioctlsocket(fd, FIONBIO, &opt);
    852872#else
    853873        int opt;
    854        
     874
    855875        opt = fcntl(fd, F_GETFL, 0);
    856876        opt |= O_NONBLOCK;
     
    865885#ifdef FIONBIO
    866886        int opt = 0;
    867        
     887
    868888        ioctlsocket(fd, FIONBIO, &opt);
    869889#else
    870890        int opt;
    871        
     891
    872892        opt = fcntl(fd, F_GETFL, 0);
    873893        opt &= ~O_NONBLOCK;
     
    893913        int s;
    894914        char buff[256];
    895        
     915
    896916        DEBUG_CALL("rsh_exec");
    897917        DEBUG_ARG("so = %lx", (long)so);
    898        
     918
    899919        if (pipe(fd)<0) {
    900920          lprint("Error: pipe failed: %s\n", strerror(errno));
     
    917937        }
    918938#endif
    919        
     939
    920940        switch(fork()) {
    921941         case -1:
     
    926946           close(fd0[1]);
    927947           return 0;
    928            
     948
    929949         case 0:
    930950           close(fd[0]);
    931951           close(fd0[0]);
    932            
     952
    933953                /* Set the DISPLAY */
    934954           if (x_port >= 0) {
     
    941961#endif
    942962           }
    943            
     963
    944964           dup2(fd0[1], 0);
    945965           dup2(fd0[1], 1);
     
    947967           for (s = 3; s <= 255; s++)
    948968             close(s);
    949            
     969
    950970           execlp("rsh","rsh","-l", user, host, args, NULL);
    951            
     971
    952972           /* Ooops, failed, let's tell the user why */
    953            
    954            sprintf(buff, "Error: execlp of %s failed: %s\n", 
     973
     974           sprintf(buff, "Error: execlp of %s failed: %s\n",
    955975                   "rsh", strerror(errno));
    956976           write(2, buff, strlen(buff)+1);
    957977           close(0); close(1); close(2); /* XXX */
    958978           exit(1);
    959            
     979
    960980        default:
    961981          close(fd[1]);
     
    963983          ns->s=fd[0];
    964984          so->s=fd0[0];
    965          
     985
    966986          return 1;
    967987        }
  • trunk/src/VBox/Devices/Network/slirp/misc.h

    r1 r1033  
    11/*
    22 * Copyright (c) 1995 Danny Gasparovski.
    3  * 
    4  * Please read the file COPYRIGHT for the 
     3 *
     4 * Please read the file COPYRIGHT for the
    55 * terms and conditions of the copyright.
    66 */
     
    1818
    1919extern struct ex_list *exec_list;
     20#ifndef VBOX
    2021extern u_int curtime, time_fasttimo, last_slowtimo, detach_time, detach_wait;
     22#endif /* !VBOX */
    2123
    2224#ifndef VBOX
     
    7274int show_x _P((char *, struct socket *));
    7375void redir_x _P((u_int32_t, int, int, int));
     76#ifdef VBOX
     77void getouraddr _P((PNATState));
     78#else /* !VBOX */
    7479void getouraddr _P((void));
     80#endif /* !VBOX */
    7581inline  void slirp_insque  _P((void *, void *));
    7682inline  void slirp_remque  _P((void *));
    7783int add_exec _P((struct ex_list **, int, char *, int, int));
    7884int slirp_openpty _P((int *, int *));
     85#ifdef VBOX
     86int fork_exec _P((PNATState, struct socket *, char *, int));
     87#else /* !VBOX */
    7988int fork_exec _P((struct socket *, char *, int));
     89#endif /* !VBOX */
    8090void snooze_hup _P((int));
    8191void snooze _P((void));
  • trunk/src/VBox/Devices/Network/slirp/sbuf.c

    r1 r1033  
    11/*
    22 * Copyright (c) 1995 Danny Gasparovski.
    3  * 
    4  * Please read the file COPYRIGHT for the 
     3 *
     4 * Please read the file COPYRIGHT for the
    55 * terms and conditions of the copyright.
    66 */
     
    1010/* Done as a macro in socket.h */
    1111/* int
    12  * sbspace(struct sockbuff *sb) 
     12 * sbspace(struct sockbuff *sb)
    1313 * {
    1414 *      return SB_DATALEN - sb->sb_cc;
     
    2626sbdrop(sb, num)
    2727        struct sbuf *sb;
    28         int num; 
    29 {
    30         /* 
     28        int num;
     29{
     30        /*
    3131         * We can only drop how much we have
    32          * This should never succeed 
     32         * This should never succeed
    3333         */
    3434        if(num > sb->sb_cc)
     
    3838        if(sb->sb_rptr >= sb->sb_data + sb->sb_datalen)
    3939                sb->sb_rptr -= sb->sb_datalen;
    40    
     40
    4141}
    4242
     
    7373 */
    7474void
     75#ifdef VBOX
     76sbappend(PNATState pData, struct socket *so, struct mbuf *m)
     77#else /* !VBOX */
    7578sbappend(so, m)
    7679        struct socket *so;
    7780        struct mbuf *m;
     81#endif /* !VBOX */
    7882{
    7983        int ret = 0;
    80        
     84
    8185        DEBUG_CALL("sbappend");
    8286        DEBUG_ARG("so = %lx", (long)so);
    8387        DEBUG_ARG("m = %lx", (long)m);
    8488        DEBUG_ARG("m->m_len = %d", m->m_len);
    85        
     89
    8690        /* Shouldn't happen, but...  e.g. foreign host closes connection */
    8791        if (m->m_len <= 0) {
     92#ifdef VBOX
     93                m_free(pData, m);
     94#else /* !VBOX */
    8895                m_free(m);
     96#endif /* !VBOX */
    8997                return;
    9098        }
    91        
     99
    92100        /*
    93101         * If there is urgent data, call sosendoob
     
    97105        if (so->so_urgc) {
    98106                sbappendsb(&so->so_rcv, m);
     107#ifdef VBOX
     108                m_free(pData, m);
     109#else /* !VBOX */
    99110                m_free(m);
     111#endif /* !VBOX */
    100112                sosendoob(so);
    101113                return;
    102114        }
    103        
     115
    104116        /*
    105117         * We only write if there's nothing in the buffer,
     
    108120        if (!so->so_rcv.sb_cc)
    109121           ret = send(so->s, m->m_data, m->m_len, 0);
    110        
     122
    111123        if (ret <= 0) {
    112                 /* 
     124                /*
    113125                 * Nothing was written
    114126                 * It's possible that the socket has closed, but
     
    127139        } /* else */
    128140        /* Whatever happened, we free the mbuf */
     141#ifdef VBOX
     142        m_free(pData, m);
     143#else /* !VBOX */
    129144        m_free(m);
     145#endif /* !VBOX */
    130146}
    131147
     
    140156{
    141157        int len, n,  nn;
    142        
     158
    143159        len = m->m_len;
    144160
     
    181197{
    182198        char *from;
    183        
     199
    184200        from = sb->sb_rptr + off;
    185201        if (from >= sb->sb_data + sb->sb_datalen)
     
    199215        }
    200216}
    201                
     217
  • trunk/src/VBox/Devices/Network/slirp/sbuf.h

    r1 r1033  
    11/*
    22 * Copyright (c) 1995 Danny Gasparovski.
    3  * 
    4  * Please read the file COPYRIGHT for the 
     3 *
     4 * Please read the file COPYRIGHT for the
    55 * terms and conditions of the copyright.
    66 */
     
    2525void sbdrop _P((struct sbuf *, int));
    2626void sbreserve _P((struct sbuf *, int));
     27#ifdef VBOX
     28void sbappend _P((PNATState, struct socket *, struct mbuf *));
     29#else /* !VBOX */
    2730void sbappend _P((struct socket *, struct mbuf *));
     31#endif /* !VBOX */
    2832void sbappendsb _P((struct sbuf *, struct mbuf *));
    2933void sbcopy _P((struct sbuf *, int, int, char *));
  • trunk/src/VBox/Devices/Network/slirp/slirp.c

    r926 r1033  
    88#endif
    99
     10#ifndef VBOX
    1011/* host address */
    1112struct in_addr our_addr;
     
    1920/* virtual address alias for host */
    2021struct in_addr alias_addr;
    21 
     22#endif /* !VBOX */
     23
     24#ifdef VBOX
     25static const uint8_t special_ethaddr[6] = {
     26#else /* !VBOX */
    2227const uint8_t special_ethaddr[6] = {
     28#endif /* !VBOX */
    2329    0x52, 0x54, 0x00, 0x12, 0x35, 0x00
    2430};
    2531
     32#ifndef VBOX
    2633uint8_t client_ethaddr[6];
    2734
     
    3138FILE *lfd;
    3239struct ex_list *exec_list;
     40#endif /* !VBOX */
    3341
    3442#ifndef VBOX
    3543/* XXX: suppress those select globals */
    3644fd_set *global_readfds, *global_writefds, *global_xfds;
    37 #endif /* !VBOX */
    3845
    3946char slirp_hostname[33];
     47#endif /* !VBOX */
    4048
    4149#ifdef _WIN32
     
    106114#else
    107115
     116#ifdef VBOX
     117static int get_dns_addr(PNATState pData, struct in_addr *pdns_addr)
     118#else /* !VBOX */
    108119static int get_dns_addr(struct in_addr *pdns_addr)
     120#endif /* !VBOX */
    109121{
    110122    char buff[512];
     
    193205#else /* VBOX */
    194206/** Number of slirp users. Used for making sure init and term are only executed once. */
    195 static int g_cUsers = 0;
    196 int slirp_init(void)
    197 {
    198     if (g_cUsers != 0) {
    199         g_cUsers++;
    200         return VINF_SUCCESS;
    201     }
     207int slirp_init(PNATState *ppData, const char *pszNetAddr, void *pvUser)
     208{
     209    PNATState pData = malloc(sizeof(NATState));
     210    *ppData = pData;
     211    if (!pData)
     212        return VERR_NO_MEMORY;
     213    memset(pData, '\0', sizeof(NATState));
     214    pData->pvUser = pvUser;
    202215#endif /* VBOX */
    203216
     
    217230    link_up = 1;
    218231
     232#ifdef VBOX
     233    if_init(pData);
     234    ip_init(pData);
     235#else /* !VBOX */
    219236    if_init();
    220237    ip_init();
     238#endif /* !VBOX */
    221239
    222240    /* Initialise mbufs *after* setting the MTU */
     241#ifdef VBOX
     242    m_init(pData);
     243#else /* !VBOX */
    223244    m_init();
     245#endif /* !VBOX */
    224246
    225247    /* set default addresses */
    226248    inet_aton("127.0.0.1", &loopback_addr);
    227249
     250#ifdef VBOX
     251    if (get_dns_addr(pData, &dns_addr) < 0) {
     252#else /* !VBOX */
    228253    if (get_dns_addr(&dns_addr) < 0) {
     254#endif /* !VBOX */
    229255#ifndef VBOX
    230256        dns_addr = loopback_addr;
     
    235261    }
    236262
     263#ifdef VBOX
     264    inet_aton(pszNetAddr, &special_addr);
     265#else /* !VBOX */
    237266    inet_aton(CTL_SPECIAL, &special_addr);
     267#endif /* !VBOX */
    238268    alias_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS);
     269#ifdef VBOX
     270    getouraddr(pData);
     271    return VINF_SUCCESS;
     272#else /* !VBOX */
    239273    getouraddr();
    240 #ifdef VBOX
    241     g_cUsers++;
    242     return VINF_SUCCESS;
    243 #endif
     274#endif /* !VBOX */
    244275}
    245276
     
    248279 * Marks the link as up, making it possible to establish new connections.
    249280 */
    250 void slirp_link_up(void)
     281void slirp_link_up(PNATState pData)
    251282{
    252283    link_up = 1;
     
    256287 * Marks the link as down and cleans up the current connections.
    257288 */
    258 void slirp_link_down(void)
     289void slirp_link_down(PNATState pData)
    259290{
    260291    struct socket *so;
     
    263294    {
    264295        if (so->so_state & SS_NOFDREF || so->s == -1)
    265             sofree(so);
     296            sofree(pData, so);
    266297        else
    267             tcp_drop(sototcpcb(so), 0);
     298            tcp_drop(pData, sototcpcb(so), 0);
    268299    }
    269300
    270301    while ((so = udb.so_next) != &udb)
    271         udp_detach(so);
     302        udp_detach(pData, so);
    272303
    273304    link_up = 0;
     
    277308 * Terminates the slirp component.
    278309 */
    279 void slirp_term(void)
    280 {
    281     if (--g_cUsers > 0)
    282         return;
    283     slirp_link_down();
     310void slirp_term(PNATState pData)
     311{
     312    slirp_link_down(pData);
    284313#ifdef WIN32
    285314    WSACleanup();
     
    290319         "--------------\n"
    291320         "\n"));
    292     ipstats();
    293     tcpstats();
    294     udpstats();
    295     icmpstats();
    296     mbufstats();
    297     sockstats();
     321    ipstats(pData);
     322    tcpstats(pData);
     323    udpstats(pData);
     324    icmpstats(pData);
     325    mbufstats(pData);
     326    sockstats(pData);
    298327    Log(("\n"
    299328         "\n"
    300329         "\n"));
    301330#endif
     331    free(pData);
    302332}
    303333#endif /* VBOX */
     
    312342 */
    313343#ifdef _WIN32
     344#ifdef VBOX
     345static void updtime(PNATState pData)
     346#else /* !VBOX */
    314347static void updtime(void)
     348#endif /* !VBOX */
    315349{
    316350    struct _timeb tb;
     
    321355}
    322356#else
     357#ifdef VBOX
     358static void updtime(PNATState pData)
     359#else /* !VBOX */
    323360static void updtime(void)
     361#endif /* !VBOX */
    324362{
    325363        gettimeofday(&tt, 0);
     
    333371#endif
    334372
     373#ifdef VBOX
     374void slirp_select_fill(PNATState pData, int *pnfds,
     375                       fd_set *readfds, fd_set *writefds, fd_set *xfds)
     376#else /* !VBOX */
    335377void slirp_select_fill(int *pnfds,
    336378                       fd_set *readfds, fd_set *writefds, fd_set *xfds)
     379#endif /* !VBOX */
    337380{
    338381    struct socket *so, *so_next;
     
    426469                        if (so->so_expire) {
    427470                                if (so->so_expire <= curtime) {
     471#ifdef VBOX
     472                                        udp_detach(pData, so);
     473#else /* !VBOX */
    428474                                        udp_detach(so);
     475#endif /* !VBOX */
    429476                                        continue;
    430477                                } else
     
    485532}
    486533
     534#ifdef VBOX
     535void slirp_select_poll(PNATState pData, fd_set *readfds, fd_set *writefds, fd_set *xfds)
     536#else /* !VBOX */
    487537void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)
     538#endif /* !VBOX */
    488539{
    489540    struct socket *so, *so_next;
     
    497548
    498549        /* Update time */
     550#ifdef VBOX
     551        updtime(pData);
     552#else /* !VBOX */
    499553        updtime();
     554#endif /* !VBOX */
    500555
    501556        /*
     
    504559        if (link_up) {
    505560                if (time_fasttimo && ((curtime - time_fasttimo) >= 2)) {
     561#ifdef VBOX
     562                        tcp_fasttimo(pData);
     563#else /* !VBOX */
    506564                        tcp_fasttimo();
     565#endif /* !VBOX */
    507566                        time_fasttimo = 0;
    508567                }
    509568                if (do_slowtimo && ((curtime - last_slowtimo) >= 499)) {
     569#ifdef VBOX
     570                        ip_slowtimo(pData);
     571                        tcp_slowtimo(pData);
     572#else /* !VBOX */
    510573                        ip_slowtimo();
    511574                        tcp_slowtimo();
     575#endif /* !VBOX */
    512576                        last_slowtimo = curtime;
    513577                }
     
    537601                         */
    538602                        if (FD_ISSET(so->s, xfds))
     603#ifdef VBOX
     604                           sorecvoob(pData, so);
     605#else /* !VBOX */
    539606                           sorecvoob(so);
     607#endif /* !VBOX */
    540608                        /*
    541609                         * Check sockets for reading
     
    546614                                 */
    547615                                if (so->so_state & SS_FACCEPTCONN) {
     616#ifdef VBOX
     617                                        tcp_connect(pData, so);
     618#else /* !VBOX */
    548619                                        tcp_connect(so);
     620#endif /* !VBOX */
    549621                                        continue;
    550622                                } /* else */
     623#ifdef VBOX
     624                                ret = soread(pData, so);
     625#else /* !VBOX */
    551626                                ret = soread(so);
     627#endif /* !VBOX */
    552628
    553629                                /* Output it if we read something */
    554630                                if (ret > 0)
     631#ifdef VBOX
     632                                   tcp_output(pData, sototcpcb(so));
     633#else /* !VBOX */
    555634                                   tcp_output(sototcpcb(so));
     635#endif /* !VBOX */
    556636                        }
    557637
     
    582662                             * Continue tcp_input
    583663                             */
     664#ifdef VBOX
     665                            tcp_input(pData, (struct mbuf *)NULL, sizeof(struct ip), so);
     666#else /* !VBOX */
    584667                            tcp_input((struct mbuf *)NULL, sizeof(struct ip), so);
     668#endif /* !VBOX */
    585669                            /* continue; */
    586670                          } else
     671#ifdef VBOX
     672                            ret = sowrite(pData, so);
     673#else /* !VBOX */
    587674                            ret = sowrite(so);
     675#endif /* !VBOX */
    588676                          /*
    589677                           * XXXXX If we wrote something (a lot), there
     
    639727
    640728                        if (so->s != -1 && FD_ISSET(so->s, readfds)) {
     729#ifdef VBOX
     730                            sorecvfrom(pData, so);
     731#else /* !VBOX */
    641732                            sorecvfrom(so);
     733#endif /* !VBOX */
    642734                        }
    643735                }
     
    648740         */
    649741        if (if_queued && link_up)
     742#ifdef VBOX
     743           if_start(pData);
     744#else /* !VBOX */
    650745           if_start();
     746#endif /* !VBOX */
    651747
    652748#ifndef VBOX
     
    697793#ifdef VBOX
    698794static
    699 #endif
     795void arp_input(PNATState pData, const uint8_t *pkt, int pkt_len)
     796#else /* !VBOX */
    700797void arp_input(const uint8_t *pkt, int pkt_len)
     798#endif /* !VBOX */
    701799{
    702800    struct ethhdr *eh = (struct ethhdr *)pkt;
     
    738836            memcpy(rah->ar_tha, ah->ar_sha, ETH_ALEN);
    739837            memcpy(rah->ar_tip, ah->ar_sip, 4);
     838#ifdef VBOX
     839            slirp_output(pData->pvUser, arp_reply, sizeof(arp_reply));
     840#else /* !VBOX */
    740841            slirp_output(arp_reply, sizeof(arp_reply));
     842#endif /* !VBOX */
    741843        }
    742844        break;
     
    746848}
    747849
     850#ifdef VBOX
     851void slirp_input(PNATState pData, const uint8_t *pkt, int pkt_len)
     852#else /* !VBOX */
    748853void slirp_input(const uint8_t *pkt, int pkt_len)
     854#endif /* !VBOX */
    749855{
    750856    struct mbuf *m;
     
    757863    switch(proto) {
    758864    case ETH_P_ARP:
     865#ifdef VBOX
     866        arp_input(pData, pkt, pkt_len);
     867#else /* !VBOX */
    759868        arp_input(pkt, pkt_len);
     869#endif /* !VBOX */
    760870        break;
    761871    case ETH_P_IP:
     872#ifdef VBOX
     873        m = m_get(pData);
     874#else /* !VBOX */
    762875        m = m_get();
     876#endif /* !VBOX */
    763877        if (!m)
    764878            return;
     
    770884        m->m_len -= 2 + ETH_HLEN;
    771885
     886#ifdef VBOX
     887        ip_input(pData, m);
     888#else /* !VBOX */
    772889        ip_input(m);
     890#endif /* !VBOX */
    773891        break;
    774892    default:
     
    778896
    779897/* output the IP packet to the ethernet device */
     898#ifdef VBOX
     899void if_encap(PNATState pData, const uint8_t *ip_data, int ip_data_len)
     900#else /* !VBOX */
    780901void if_encap(const uint8_t *ip_data, int ip_data_len)
     902#endif /* !VBOX */
    781903{
    782904    uint8_t buf[1600];
     
    792914    eh->h_proto = htons(ETH_P_IP);
    793915    memcpy(buf + sizeof(struct ethhdr), ip_data, ip_data_len);
     916#ifdef VBOX
     917    slirp_output(pData->pvUser, buf, ip_data_len + ETH_HLEN);
     918#else /* !VBOX */
    794919    slirp_output(buf, ip_data_len + ETH_HLEN);
    795 }
    796 
    797 int slirp_redir(int is_udp, int host_port,
     920#endif /* !VBOX */
     921}
     922
     923int slirp_redir(PNATState pData, int is_udp, int host_port,
    798924                struct in_addr guest_addr, int guest_port)
    799925{
    800926    if (is_udp) {
     927#ifdef VBOX
     928        if (!udp_listen(pData, htons(host_port), guest_addr.s_addr,
     929                        htons(guest_port), 0))
     930#else /* !VBOX */
    801931        if (!udp_listen(htons(host_port), guest_addr.s_addr,
    802932                        htons(guest_port), 0))
     933#endif /* !VBOX */
    803934            return -1;
    804935    } else {
     936#ifdef VBOX
     937        if (!solisten(pData, htons(host_port), guest_addr.s_addr,
     938                      htons(guest_port), 0))
     939#else /* !VBOX */
    805940        if (!solisten(htons(host_port), guest_addr.s_addr,
    806941                      htons(guest_port), 0))
     942#endif /* !VBOX */
    807943            return -1;
    808944    }
     
    810946}
    811947
     948#ifdef VBOX
     949int slirp_add_exec(PNATState pData, int do_pty, const char *args, int addr_low_byte,
     950                  int guest_port)
     951#else /* !VBOX */
    812952int slirp_add_exec(int do_pty, const char *args, int addr_low_byte,
    813953                  int guest_port)
     954#endif /* !VBOX */
    814955{
    815956    return add_exec(&exec_list, do_pty, (char *)args,
  • trunk/src/VBox/Devices/Network/slirp/slirp.h

    r1023 r1033  
    3737#  include <io.h>
    3838# endif
     39# include <iprt/assert.h>
    3940# include <iprt/string.h>
    4041# include <VBox/types.h>
     
    236237#include <sys/stropts.h>
    237238#endif
     239
     240#ifdef VBOX
     241#include "libslirp.h"
     242#endif /* !VBOX */
    238243
    239244#include "debug.h"
     
    260265#include "bootp.h"
    261266#include "tftp.h"
     267#ifndef VBOX
    262268#include "libslirp.h"
    263 
     269#endif /* !VBOX */
     270
     271#ifdef VBOX
     272#include "slirp_state.h"
     273#endif /* VBOX */
     274
     275#ifndef VBOX
    264276extern struct ttys *ttys_unit[MAX_INTERFACES];
     277#endif /* !VBOX */
    265278
    266279#ifndef NULL
     
    268281#endif
    269282
     283#ifdef VBOX
     284void if_start _P((PNATState));
     285#else /* !VBOX */
    270286#ifndef FULL_BOLT
    271287void if_start _P((void));
     
    273289void if_start _P((struct ttys *));
    274290#endif
     291#endif /* !VBOX */
    275292
    276293#ifdef BAD_SPRINTF
     
    330347 inline void insque_32 _P((void *, void *));
    331348 inline void remque_32 _P((void *));
    332 # endif 
     349# endif
    333350#endif
    334351
     
    343360
    344361/* if.c */
     362#ifdef VBOX
     363void if_init _P((PNATState));
     364void if_output _P((PNATState, struct socket *, struct mbuf *));
     365#else /* VBOX */
    345366void if_init _P((void));
    346367void if_output _P((struct socket *, struct mbuf *));
     368#endif /* VBOX */
    347369
    348370/* ip_input.c */
     371#ifdef VBOX
     372void ip_init _P((PNATState));
     373void ip_input _P((PNATState, struct mbuf *));
     374struct ip * ip_reass _P((PNATState, register struct ipasfrag *, register struct ipq_t *));
     375void ip_freef _P((PNATState, struct ipq_t *));
     376#else /* !VBOX */
    349377void ip_init _P((void));
    350378void ip_input _P((struct mbuf *));
    351379struct ip * ip_reass _P((register struct ipasfrag *, register struct ipq *));
    352380void ip_freef _P((struct ipq *));
     381#endif /* !VBOX */
    353382void ip_enq _P((register struct ipasfrag *, register struct ipasfrag *));
    354383void ip_deq _P((register struct ipasfrag *));
     384#ifdef VBOX
     385void ip_slowtimo _P((PNATState));
     386#else /* !VBOX */
    355387void ip_slowtimo _P((void));
     388#endif /* !VBOX */
    356389void ip_stripoptions _P((register struct mbuf *, struct mbuf *));
    357390
    358391/* ip_output.c */
     392#ifdef VBOX
     393int ip_output _P((PNATState, struct socket *, struct mbuf *));
     394#else /* !VBOX */
    359395int ip_output _P((struct socket *, struct mbuf *));
     396#endif /* !VBOX */
    360397
    361398/* tcp_input.c */
     399#ifdef VBOX
     400int tcp_reass _P((PNATState, register struct tcpcb *, register struct tcpiphdr *, struct mbuf *));
     401void tcp_input _P((PNATState, register struct mbuf *, int, struct socket *));
     402void tcp_dooptions _P((PNATState, struct tcpcb *, u_char *, int, struct tcpiphdr *));
     403void tcp_xmit_timer _P((PNATState, register struct tcpcb *, int));
     404int tcp_mss _P((PNATState, register struct tcpcb *, u_int));
     405#else /* !VBOX */
    362406int tcp_reass _P((register struct tcpcb *, register struct tcpiphdr *, struct mbuf *));
    363407void tcp_input _P((register struct mbuf *, int, struct socket *));
     
    365409void tcp_xmit_timer _P((register struct tcpcb *, int));
    366410int tcp_mss _P((register struct tcpcb *, u_int));
     411#endif /* !VBOX */
    367412
    368413/* tcp_output.c */
     414#ifdef VBOX
     415int tcp_output _P((PNATState, register struct tcpcb *));
     416#else /* !VBOX */
    369417int tcp_output _P((register struct tcpcb *));
     418#endif /* !VBOX */
    370419void tcp_setpersist _P((register struct tcpcb *));
    371420
    372421/* tcp_subr.c */
     422#ifdef VBOX
     423void tcp_init _P((PNATState));
     424#else /* !VBOX */
    373425void tcp_init _P((void));
     426#endif /* !VBOX */
    374427void tcp_template _P((struct tcpcb *));
     428#ifdef VBOX
     429void tcp_respond _P((PNATState, struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int));
     430#else /* !VBOX */
    375431void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int));
     432#endif /* !VBOX */
    376433struct tcpcb * tcp_newtcpcb _P((struct socket *));
     434#ifdef VBOX
     435struct tcpcb * tcp_close _P((PNATState, register struct tcpcb *));
     436#else /* !VBOX */
    377437struct tcpcb * tcp_close _P((register struct tcpcb *));
     438#endif /* !VBOX */
    378439void tcp_drain _P((void));
     440#ifdef VBOX
     441void tcp_sockclosed _P((PNATState, struct tcpcb *));
     442int tcp_fconnect _P((PNATState, struct socket *));
     443void tcp_connect _P((PNATState, struct socket *));
     444int tcp_attach _P((PNATState, struct socket *));
     445#else /* !VBOX */
    379446void tcp_sockclosed _P((struct tcpcb *));
    380447int tcp_fconnect _P((struct socket *));
    381448void tcp_connect _P((struct socket *));
    382449int tcp_attach _P((struct socket *));
     450#endif /* !VBOX */
    383451u_int8_t tcp_tos _P((struct socket *));
     452#ifdef VBOX
     453int tcp_emu _P((PNATState, struct socket *, struct mbuf *));
     454int tcp_ctl _P((PNATState, struct socket *));
     455struct tcpcb *tcp_drop(PNATState, struct tcpcb *tp, int err);
     456#else /* !VBOX */
    384457int tcp_emu _P((struct socket *, struct mbuf *));
    385458int tcp_ctl _P((struct socket *));
    386459struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
     460#endif /* !VBOX */
    387461
    388462#ifdef USE_PPP
  • trunk/src/VBox/Devices/Network/slirp/socket.c

    r926 r1033  
    6868 */
    6969void
     70#ifdef VBOX
     71sofree(PNATState pData, struct socket *so)
     72#else /* !VBOX */
    7073sofree(so)
    7174        struct socket *so;
     75#endif /* !VBOX */
    7276{
    7377  if (so->so_emu==EMU_RSH && so->extra) {
     78#ifdef VBOX
     79        sofree(pData, so->extra);
     80#else /* !VBOX */
    7481        sofree(so->extra);
     82#endif /* !VBOX */
    7583        so->extra=NULL;
    7684  }
     
    8088    udp_last_so = &udb;
    8189
     90#ifdef VBOX
     91  m_free(pData, so->so_m);
     92#else /* !VBOX */
    8293  m_free(so->so_m);
     94#endif /* !VBOX */
    8395
    8496  if(so->so_next && so->so_prev)
     
    94106 */
    95107int
     108#ifdef VBOX
     109soread(PNATState pData, struct socket *so)
     110#else /* !VBOX */
    96111soread(so)
    97112        struct socket *so;
     113#endif /* !VBOX */
    98114{
    99115        int n, nn, lss, total;
     
    164180                        DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno)));
    165181                        sofcantrcvmore(so);
     182#ifdef VBOX
     183                        tcp_sockclosed(pData, sototcpcb(so));
     184#else /* !VBOX */
    166185                        tcp_sockclosed(sototcpcb(so));
     186#endif /* !VBOX */
    167187                        return -1;
    168188                }
     
    205225 */
    206226void
     227#ifdef VBOX
     228sorecvoob(PNATState pData, struct socket *so)
     229#else /* !VBOX */
    207230sorecvoob(so)
    208231        struct socket *so;
     232#endif /* !VBOX */
    209233{
    210234        struct tcpcb *tp = sototcpcb(so);
     
    221245         * urgent data.
    222246         */
     247#ifdef VBOX
     248        soread(pData, so);
     249#else /* !VBOX */
    223250        soread(so);
     251#endif /* !VBOX */
    224252        tp->snd_up = tp->snd_una + so->so_snd.sb_cc;
    225253        tp->t_force = 1;
     254#ifdef VBOX
     255        tcp_output(pData, tp);
     256#else /* !VBOX */
    226257        tcp_output(tp);
     258#endif /* !VBOX */
    227259        tp->t_force = 0;
    228260}
     
    292324 */
    293325int
     326#ifdef VBOX
     327sowrite(PNATState pData, struct socket *so)
     328#else /* !VBOX */
    294329sowrite(so)
    295330        struct socket *so;
     331#endif /* !VBOX */
    296332{
    297333        int  n,nn;
     
    351387                        so->so_state, errno));
    352388                sofcantsendmore(so);
     389#ifdef VBOX
     390                tcp_sockclosed(pData, sototcpcb(so));
     391#else /* !VBOX */
    353392                tcp_sockclosed(sototcpcb(so));
     393#endif /* !VBOX */
    354394                return -1;
    355395        }
     
    385425 */
    386426void
     427#ifdef VBOX
     428sorecvfrom(PNATState pData, struct socket *so)
     429#else /* !VBOX */
    387430sorecvfrom(so)
    388431        struct socket *so;
     432#endif /* !VBOX */
    389433{
    390434        struct sockaddr_in addr;
     
    414458            DEBUG_MISC((dfd," udp icmp rx errno = %d-%s\n",
    415459                        errno,strerror(errno)));
     460#ifdef VBOX
     461            icmp_error(pData, so->so_m, ICMP_UNREACH,code, 0,strerror(errno));
     462#else /* !VBOX */
    416463            icmp_error(so->so_m, ICMP_UNREACH,code, 0,strerror(errno));
     464#endif /* !VBOX */
    417465          } else {
     466#ifdef VBOX
     467            icmp_reflect(pData, so->so_m);
     468#else /* !VBOX */
    418469            icmp_reflect(so->so_m);
     470#endif /* !VBOX */
    419471            so->so_m = 0; /* Don't m_free() it again! */
    420472          }
    421473          /* No need for this socket anymore, udp_detach it */
     474#ifdef VBOX
     475          udp_detach(pData, so);
     476#else /* !VBOX */
    422477          udp_detach(so);
     478#endif /* !VBOX */
    423479        } else {                                /* A "normal" UDP packet */
    424480          struct mbuf *m;
    425481          int len, n;
    426482
     483#ifdef VBOX
     484          if (!(m = m_get(pData))) return;
     485#else /* !VBOX */
    427486          if (!(m = m_get())) return;
     487#endif /* !VBOX */
    428488          m->m_data += if_maxlinkhdr;
    429489
     
    454514
    455515            DEBUG_MISC((dfd," rx error, tx icmp ICMP_UNREACH:%i\n", code));
     516#ifdef VBOX
     517            icmp_error(pData, so->so_m, ICMP_UNREACH,code, 0,strerror(errno));
     518            m_free(pData, m);
     519#else /* !VBOX */
    456520            icmp_error(so->so_m, ICMP_UNREACH,code, 0,strerror(errno));
    457521            m_free(m);
     522#endif /* !VBOX */
    458523          } else {
    459524          /*
     
    480545             * make it look like that's where it came from, done by udp_output
    481546             */
     547#ifdef VBOX
     548            udp_output(pData, so, m, &addr);
     549#else /* !VBOX */
    482550            udp_output(so, m, &addr);
     551#endif /* !VBOX */
    483552          } /* rx error */
    484553        } /* if ping packet */
     
    489558 */
    490559int
     560#ifdef VBOX
     561sosendto(PNATState pData, struct socket *so, struct mbuf *m)
     562#else /* !VBOX */
    491563sosendto(so, m)
    492564        struct socket *so;
    493565        struct mbuf *m;
     566#endif /* !VBOX */
    494567{
    495568        int ret;
     
    538611 */
    539612struct socket *
     613#ifdef VBOX
     614solisten(PNATState pData, u_int port, u_int32_t laddr, u_int lport, int flags)
     615#else /* !VBOX */
    540616solisten(port, laddr, lport, flags)
    541617        u_int port;
     
    543619        u_int lport;
    544620        int flags;
     621#endif /* !VBOX */
    545622{
    546623        struct sockaddr_in addr;
     
    604681                int tmperrno = WSAGetLastError(); /* Don't clobber the real reason we failed */
    605682                closesocket(s);
    606                 sofree(so);
     683                sofree(pData, so);
    607684                /* Restore the real errno */
    608685                WSASetLastError(tmperrno);
     
    610687                int tmperrno = errno; /* Don't clobber the real reason we failed */
    611688                close(s);
    612                 sofree(so);
     689                sofree(pData, so);
    613690                /* Restore the real errno */
    614691                errno = tmperrno;
  • trunk/src/VBox/Devices/Network/slirp/socket.h

    r1 r1033  
    11/*
    22 * Copyright (c) 1995 Danny Gasparovski.
    3  * 
    4  * Please read the file COPYRIGHT for the 
     3 *
     4 * Please read the file COPYRIGHT for the
    55 * terms and conditions of the copyright.
    66 */
     
    3434  u_int16_t so_fport;              /* foreign port */
    3535  u_int16_t so_lport;              /* local port */
    36  
     36
    3737  u_int8_t      so_iptos;       /* Type of service */
    3838  u_int8_t      so_emu;         /* Is the socket emulated? */
    39  
     39
    4040  u_char        so_type;                /* Type of socket, UDP or TCP */
    4141  int   so_state;               /* internal state flags SS_*, below */
    42  
     42
    4343  struct        tcpcb *so_tcpcb;        /* pointer to TCP protocol control block */
    4444  u_int so_expire;              /* When the socket will expire */
    45  
     45
    4646  int   so_queued;              /* Number of packets queued from this socket */
    4747  int   so_nqueued;             /* Number of packets queued in a row
    4848                                 * Used to determine when to "downgrade" a session
    4949                                         * from fastq to batchq */
    50        
     50
    5151  struct sbuf so_rcv;           /* Receive buffer */
    5252  struct sbuf so_snd;           /* Send buffer */
     
    8585struct socket * solookup _P((struct socket *, struct in_addr, u_int, struct in_addr, u_int));
    8686struct socket * socreate _P((void));
     87#ifdef VBOX
     88void sofree _P((PNATState, struct socket *));
     89int soread _P((PNATState, struct socket *));
     90void sorecvoob _P((PNATState, struct socket *));
     91#else /* !VBOX */
    8792void sofree _P((struct socket *));
    8893int soread _P((struct socket *));
    8994void sorecvoob _P((struct socket *));
     95#endif /* !VBOX */
    9096int sosendoob _P((struct socket *));
     97#ifdef VBOX
     98int sowrite _P((PNATState, struct socket *));
     99void sorecvfrom _P((PNATState, struct socket *));
     100int sosendto _P((PNATState, struct socket *, struct mbuf *));
     101struct socket * solisten _P((PNATState, u_int, u_int32_t, u_int, int));
     102#else /* !VBOX */
    91103int sowrite _P((struct socket *));
    92104void sorecvfrom _P((struct socket *));
    93105int sosendto _P((struct socket *, struct mbuf *));
    94106struct socket * solisten _P((u_int, u_int32_t, u_int, int));
     107#endif /* !VBOX */
    95108void sorwakeup _P((struct socket *));
    96109void sowwakeup _P((struct socket *));
  • trunk/src/VBox/Devices/Network/slirp/tcp.h

    r478 r1033  
    180180#define TCP_ISSINCR     (125*1024)      /* increment for tcp_iss each second */
    181181
     182#ifndef VBOX
    182183extern tcp_seq tcp_iss;                /* tcp initial send seq # */
     184#endif /* !VBOX */
    183185
     186#ifdef VBOX
     187extern const char * const tcpstates[];
     188#else /* !VBOX */
    184189extern char *tcpstates[];
     190#endif /* !VBOX */
    185191
    186192#endif
  • trunk/src/VBox/Devices/Network/slirp/tcp_input.c

    r530 r1033  
    3838 * Changes and additions relating to SLiRP
    3939 * Copyright (c) 1995 Danny Gasparovski.
    40  * 
    41  * Please read the file COPYRIGHT for the 
     40 *
     41 * Please read the file COPYRIGHT for the
    4242 * terms and conditions of the copyright.
    4343 */
     
    4646#include "ip_icmp.h"
    4747
     48#ifndef VBOX
    4849struct socket tcb;
    4950
     
    5253
    5354tcp_seq tcp_iss;                /* tcp initial send seq # */
     55#endif /* !VBOX */
    5456
    5557#define TCP_PAWS_IDLE   (24 * 24 * 60 * 60 * PR_SLOWHZ)
     
    6971 * when segments are out of order (so fast retransmit can work).
    7072 */
     73#ifdef VBOX
     74#ifdef TCP_ACK_HACK
     75#define TCP_REASS(pData, tp, ti, m, so, flags) {\
     76       if ((ti)->ti_seq == (tp)->rcv_nxt && \
     77           u32_to_ptr((tp)->seg_next, struct tcpcb *) == (tp) && \
     78           (tp)->t_state == TCPS_ESTABLISHED) {\
     79               if (ti->ti_flags & TH_PUSH) \
     80                       tp->t_flags |= TF_ACKNOW; \
     81               else \
     82                       tp->t_flags |= TF_DELACK; \
     83               (tp)->rcv_nxt += (ti)->ti_len; \
     84               flags = (ti)->ti_flags & TH_FIN; \
     85               tcpstat.tcps_rcvpack++;\
     86               tcpstat.tcps_rcvbyte += (ti)->ti_len;\
     87               if (so->so_emu) { \
     88                       if (tcp_emu((pData), (so),(m))) sbappend((pData), (so), (m)); \
     89               } else \
     90                       sbappend((pData), (so), (m)); \
     91/*               sorwakeup(so); */ \
     92        } else {\
     93               (flags) = tcp_reass((pData), (tp), (ti), (m)); \
     94               tp->t_flags |= TF_ACKNOW; \
     95       } \
     96}
     97#else
     98#define TCP_REASS(pData, tp, ti, m, so, flags) { \
     99        if ((ti)->ti_seq == (tp)->rcv_nxt && \
     100            u32_to_ptr((tp)->seg_next, struct tcpcb *) == (tp) && \
     101            (tp)->t_state == TCPS_ESTABLISHED) { \
     102                tp->t_flags |= TF_DELACK; \
     103                (tp)->rcv_nxt += (ti)->ti_len; \
     104                flags = (ti)->ti_flags & TH_FIN; \
     105                tcpstat.tcps_rcvpack++;\
     106                tcpstat.tcps_rcvbyte += (ti)->ti_len;\
     107                if (so->so_emu) { \
     108                        if (tcp_emu((pData), (so),(m))) sbappend((pData), (so), (m)); \
     109                } else \
     110                        sbappend((pData), (so), (m)); \
     111/*              sorwakeup(so); */ \
     112        } else { \
     113                (flags) = tcp_reass((pData), (tp), (ti), (m)); \
     114                tp->t_flags |= TF_ACKNOW; \
     115        } \
     116}
     117#endif
     118#else /* !VBOX */
    71119#ifdef TCP_ACK_HACK
    72120#define TCP_REASS(tp, ti, m, so, flags) {\
     
    113161}
    114162#endif
     163#endif /* !VBOX */
    115164
    116165int
     166#ifdef VBOX
     167tcp_reass(PNATState pData, register struct tcpcb *tp, register struct tcpiphdr *ti, struct mbuf *m)
     168#else /* !VBOX */
    117169tcp_reass(tp, ti, m)
    118170        register struct tcpcb *tp;
    119171        register struct tcpiphdr *ti;
    120172        struct mbuf *m;
     173#endif /* !VBOX */
    121174{
    122175        register struct tcpiphdr *q;
    123176        struct socket *so = tp->t_socket;
    124177        int flags;
    125        
     178
    126179        /*
    127180         * Call with ti==0 after become established to
     
    153206                                tcpstat.tcps_rcvduppack++;
    154207                                tcpstat.tcps_rcvdupbyte += ti->ti_len;
     208#ifdef VBOX
     209                                m_freem(pData, m);
     210#else /* !VBOX */
    155211                                m_freem(m);
     212#endif /* !VBOX */
    156213                                /*
    157214                                 * Try to present any queued data
     
    189246                m = REASS_MBUF_GET(u32_to_ptr(q->ti_prev, struct tcpiphdr *));
    190247                remque_32(u32_to_ptr(q->ti_prev, struct tcpiphdr *));
     248#ifdef VBOX
     249                m_freem(pData, m);
     250#else /* !VBOX */
    191251                m_freem(m);
     252#endif /* !VBOX */
    192253        }
    193254
     
    217278/*              if (so->so_state & SS_FCANTRCVMORE) */
    218279                if (so->so_state & SS_FCANTSENDMORE)
     280#ifdef VBOX
     281                        m_freem(pData, m);
     282#else /* !VBOX */
    219283                        m_freem(m);
     284#endif /* !VBOX */
    220285                else {
    221286                        if (so->so_emu) {
     287#ifdef VBOX
     288                                if (tcp_emu(pData, so,m)) sbappend(pData, so, m);
     289#else /* !VBOX */
    222290                                if (tcp_emu(so,m)) sbappend(so, m);
     291#endif /* !VBOX */
    223292                        } else
     293#ifdef VBOX
     294                                sbappend(pData, so, m);
     295#else /* !VBOX */
    224296                                sbappend(so, m);
     297#endif /* !VBOX */
    225298                }
    226299        } while (ti != (struct tcpiphdr *)tp && ti->ti_seq == tp->rcv_nxt);
     
    234307 */
    235308void
     309#ifdef VBOX
     310tcp_input(PNATState pData, register struct mbuf *m, int iphlen, struct socket *inso)
     311#else /* !VBOX */
    236312tcp_input(m, iphlen, inso)
    237313        register struct mbuf *m;
    238314        int iphlen;
    239315        struct socket *inso;
     316#endif /* !VBOX */
    240317{
    241318        struct ip save_ip, *ip;
     
    255332
    256333        DEBUG_CALL("tcp_input");
    257         DEBUG_ARGS((dfd," m = %8lx  iphlen = %2d  inso = %lx\n", 
     334        DEBUG_ARGS((dfd," m = %8lx  iphlen = %2d  inso = %lx\n",
    258335                    (long )m, iphlen, (long )inso ));
    259        
     336
    260337        /*
    261338         * If called with m == 0, then we're continuing the connect
     
    263340        if (m == NULL) {
    264341                so = inso;
    265                
     342
    266343                /* Re-set a few variables */
    267344                tp = sototcpcb(so);
     
    271348                tiwin = ti->ti_win;
    272349                tiflags = ti->ti_flags;
    273                
     350
    274351                goto cont_conn;
    275352        }
    276        
    277        
     353
     354
    278355        tcpstat.tcps_rcvtotal++;
    279356        /*
     
    287364        }
    288365        /* XXX Check if too short */
    289        
     366
    290367
    291368        /*
     
    294371         */
    295372        ip=mtod(m, struct ip *);
    296         save_ip = *ip; 
     373        save_ip = *ip;
    297374        save_ip.ip_len+= iphlen;
    298375
     
    306383        len = sizeof(struct ip ) + tlen;
    307384        /* keep checksum for ICMP reply
    308          * ti->ti_sum = cksum(m, len); 
     385         * ti->ti_sum = cksum(m, len);
    309386         * if (ti->ti_sum) { */
    310387        if(cksum(m, len)) {
     
    328405          optp = mtod(m, caddr_t) + sizeof (struct tcpiphdr);
    329406
    330                 /* 
     407                /*
    331408                 * Do quick retrieval of timestamp options ("options
    332409                 * prediction?").  If timestamp is the only option and it's
     
    348425        }
    349426        tiflags = ti->ti_flags;
    350        
     427
    351428        /*
    352429         * Convert TCP protocol specific fields to host format.
     
    362439        m->m_data += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
    363440        m->m_len  -= sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
    364        
     441
    365442        /*
    366443         * Locate pcb for segment.
     
    386463         *
    387464         * state == CLOSED means we've done socreate() but haven't
    388          * attached it to a protocol yet... 
    389          * 
     465         * attached it to a protocol yet...
     466         *
    390467         * XXX If a TCB does not exist, and the TH_SYN flag is
    391468         * the only flag set, then create a session, mark it
     
    395472          if ((tiflags & (TH_SYN|TH_FIN|TH_RST|TH_URG|TH_ACK)) != TH_SYN)
    396473            goto dropwithreset;
    397                
     474
    398475          if ((so = socreate()) == NULL)
    399476            goto dropwithreset;
     477#ifdef VBOX
     478          if (tcp_attach(pData, so) < 0) {
     479#else /* !VBOX */
    400480          if (tcp_attach(so) < 0) {
     481#endif /* !VBOX */
    401482            free(so); /* Not sofree (if it failed, it's not insqued) */
    402483            goto dropwithreset;
    403484          }
    404                
     485
    405486          sbreserve(&so->so_snd, tcp_sndspace);
    406487          sbreserve(&so->so_rcv, tcp_rcvspace);
    407          
     488
    408489          /*            tcp_last_so = so; */  /* XXX ? */
    409490          /*            tp = sototcpcb(so);    */
    410                
     491
    411492          so->so_laddr = ti->ti_src;
    412493          so->so_lport = ti->ti_sport;
    413494          so->so_faddr = ti->ti_dst;
    414495          so->so_fport = ti->ti_dport;
    415                
     496
    416497          if ((so->so_iptos = tcp_tos(so)) == 0)
    417498            so->so_iptos = ((struct ip *)ti)->ip_tos;
    418                
     499
    419500          tp = sototcpcb(so);
    420501          tp->t_state = TCPS_LISTEN;
    421502        }
    422            
     503
    423504        /*
    424505         * If this is a still-connecting socket, this probably
     
    430511
    431512        tp = sototcpcb(so);
    432        
     513
    433514        /* XXX Should never fail */
    434515        if (tp == 0)
     
    436517        if (tp->t_state == TCPS_CLOSED)
    437518                goto drop;
    438        
     519
    439520        /* Unscale the window into a 32-bit value. */
    440521/*      if ((tiflags & TH_SYN) == 0)
     
    459540         */
    460541        if (optp && tp->t_state != TCPS_LISTEN)
    461                 tcp_dooptions(tp, (u_char *)optp, optlen, ti);
     542#ifdef VBOX
     543                tcp_dooptions(pData, tp, (u_char *)optp, optlen, ti);
     544#else /* !VBOX */
     545                tcp_dooptions(tp, (u_char *)optp, optlen, ti);
     546#endif /* !VBOX */
    462547/* , */
    463548/*                      &ts_present, &ts_val, &ts_ecr); */
    464549
    465         /* 
     550        /*
    466551         * Header prediction: check for the two common cases
    467552         * of a uni-directional data xfer.  If the packet has
     
    487572            tiwin && tiwin == tp->snd_wnd &&
    488573            tp->snd_nxt == tp->snd_max) {
    489                 /* 
     574                /*
    490575                 * If last ACK falls within this segment's sequence numbers,
    491576                 *  record the timestamp.
     
    507592/*                              if (ts_present)
    508593 *                                      tcp_xmit_timer(tp, tcp_now-ts_ecr+1);
    509  *                              else 
     594 *                              else
    510595 */                                  if (tp->t_rtt &&
    511596                                            SEQ_GT(ti->ti_ack, tp->t_rtseq))
     597#ifdef VBOX
     598                                        tcp_xmit_timer(pData, tp, tp->t_rtt);
     599#else /* !VBOX */
    512600                                        tcp_xmit_timer(tp, tp->t_rtt);
     601#endif /* !VBOX */
    513602                                acked = ti->ti_ack - tp->snd_una;
    514603                                tcpstat.tcps_rcvackpack++;
     
    516605                                sbdrop(&so->so_snd, acked);
    517606                                tp->snd_una = ti->ti_ack;
     607#ifdef VBOX
     608                                m_freem(pData, m);
     609#else /* !VBOX */
    518610                                m_freem(m);
     611#endif /* !VBOX */
    519612
    520613                                /*
     
    532625                                        tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
    533626
    534                                 /* 
     627                                /*
    535628                                 * There's room in so_snd, sowwakup will read()
    536629                                 * from the socket if we can
     
    539632 *                                      sowwakeup(so);
    540633 */
    541                                 /* 
     634                                /*
    542635                                 * This is called because sowwakeup might have
    543636                                 * put data into so_snd.  Since we don't so sowwakeup,
     
    545638                                 */
    546639                                if (so->so_snd.sb_cc)
     640#ifdef VBOX
     641                                        (void) tcp_output(pData, tp);
     642#else /* !VBOX */
    547643                                        (void) tcp_output(tp);
     644#endif /* !VBOX */
    548645
    549646                                return;
     
    565662                         */
    566663                        if (so->so_emu) {
     664#ifdef VBOX
     665                                if (tcp_emu(pData, so,m)) sbappend(pData, so, m);
     666#else /* !VBOX */
    567667                                if (tcp_emu(so,m)) sbappend(so, m);
     668#endif /* !VBOX */
    568669                        } else
     670#ifdef VBOX
     671                                sbappend(pData, so, m);
     672#else /* !VBOX */
    569673                                sbappend(so, m);
    570                        
    571                         /*
     674#endif /* !VBOX */
     675
     676                        /*
    572677                         * XXX This is called when data arrives.  Later, check
    573678                         * if we can actually write() to the socket
     
    575680                         */
    576681/*                      sorwakeup(so); */
    577                        
     682
    578683                        /*
    579684                         * If this is a short packet, then ACK now - with Nagel
    580685                         *      congestion avoidance sender won't send more until
    581686                         *      he gets an ACK.
    582                          * 
     687                         *
    583688                         * It is better to not delay acks at all to maximize
    584689                         * TCP throughput.  See RFC 2581.
    585                          */ 
     690                         */
    586691                        tp->t_flags |= TF_ACKNOW;
     692#ifdef VBOX
     693                        tcp_output(pData, tp);
     694#else /* !VBOX */
    587695                        tcp_output(tp);
     696#endif /* !VBOX */
    588697                        return;
    589698                }
     
    625734          if ((tiflags & TH_SYN) == 0)
    626735            goto drop;
    627                
     736
    628737          /*
    629738           * This has way too many gotos...
    630739           * But a bit of spaghetti code never hurt anybody :)
    631740           */
    632          
     741
    633742          /*
    634743           * If this is destined for the control address, then flag to
     
    642751                /* Command or exec adress */
    643752                so->so_state |= SS_CTL;
    644               } else 
     753              } else
    645754#endif
    646755              {
     
    648757                struct ex_list *ex_ptr;
    649758                for(ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) {
    650                   if(ex_ptr->ex_fport == so->so_fport && 
     759                  if(ex_ptr->ex_fport == so->so_fport &&
    651760                     lastbyte == ex_ptr->ex_addr) {
    652761                    so->so_state |= SS_CTL;
     
    659768            /* CTL_ALIAS: Do nothing, tcp_fconnect will be called on it */
    660769          }
    661          
     770
    662771          if (so->so_emu & EMU_NOCONNECT) {
    663772            so->so_emu &= ~EMU_NOCONNECT;
    664773            goto cont_input;
    665774          }
    666          
     775
     776#ifdef VBOX
     777          if((tcp_fconnect(pData, so) == -1) && (errno != EINPROGRESS) && (errno != EWOULDBLOCK)) {
     778#else /* !VBOX */
    667779          if((tcp_fconnect(so) == -1) && (errno != EINPROGRESS) && (errno != EWOULDBLOCK)) {
     780#endif /* !VBOX */
    668781            u_char code=ICMP_UNREACH_NET;
    669782            DEBUG_MISC((dfd," tcp fconnect errno = %d-%s\n",
     
    671784            if(errno == ECONNREFUSED) {
    672785              /* ACK the SYN, send RST to refuse the connection */
     786#ifdef VBOX
     787              tcp_respond(pData, tp, ti, m, ti->ti_seq+1, (tcp_seq)0,
     788                          TH_RST|TH_ACK);
     789#else /* !VBOX */
    673790              tcp_respond(tp, ti, m, ti->ti_seq+1, (tcp_seq)0,
    674                           TH_RST|TH_ACK);
     791                          TH_RST|TH_ACK);
     792#endif /* !VBOX */
    675793            } else {
    676794              if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST;
     
    682800              m->m_len  += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
    683801              *ip=save_ip;
     802#ifdef VBOX
     803              icmp_error(pData, m, ICMP_UNREACH,code, 0,strerror(errno));
     804#else /* !VBOX */
    684805              icmp_error(m, ICMP_UNREACH,code, 0,strerror(errno));
     806#endif /* !VBOX */
    685807            }
     808#ifdef VBOX
     809            tp = tcp_close(pData, tp);
     810            m_free(pData, m);
     811#else /* !VBOX */
    686812            tp = tcp_close(tp);
    687813            m_free(m);
     814#endif /* !VBOX */
    688815          } else {
    689816            /*
     
    700827          return;
    701828
    702         cont_conn:     
    703           /* m==NULL 
     829        cont_conn:
     830          /* m==NULL
    704831           * Check if the connect succeeded
    705832           */
    706833          if (so->so_state & SS_NOFDREF) {
     834#ifdef VBOX
     835            tp = tcp_close(pData, tp);
     836#else /* !VBOX */
    707837            tp = tcp_close(tp);
     838#endif /* !VBOX */
    708839            goto dropwithreset;
    709840          }
    710         cont_input:             
     841        cont_input:
    711842          tcp_template(tp);
    712          
     843
    713844          if (optp)
     845#ifdef VBOX
     846            tcp_dooptions(pData, tp, (u_char *)optp, optlen, ti);
     847#else /* !VBOX */
    714848            tcp_dooptions(tp, (u_char *)optp, optlen, ti);
     849#endif /* !VBOX */
    715850          /* , */
    716851          /*                            &ts_present, &ts_val, &ts_ecr); */
    717          
     852
    718853          if (iss)
    719854            tp->iss = iss;
    720           else 
     855          else
    721856            tp->iss = tcp_iss;
    722857          tcp_iss += TCP_ISSINCR/2;
     
    730865          goto trimthenstep6;
    731866        } /* case TCPS_LISTEN */
    732        
     867
    733868        /*
    734869         * If the state is SYN_SENT:
     
    751886                if (tiflags & TH_RST) {
    752887                        if (tiflags & TH_ACK)
     888#ifdef VBOX
     889                                tp = tcp_drop(pData, tp,0); /* XXX Check t_softerror! */
     890#else /* !VBOX */
    753891                                tp = tcp_drop(tp,0); /* XXX Check t_softerror! */
     892#endif /* !VBOX */
    754893                        goto drop;
    755894                }
     
    771910                        soisfconnected(so);
    772911                        tp->t_state = TCPS_ESTABLISHED;
    773                        
     912
    774913                        /* Do window scaling on this connection? */
    775914/*                      if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
     
    779918 *                      }
    780919 */
     920#ifdef VBOX
     921                        (void) tcp_reass(pData, tp, (struct tcpiphdr *)0,
     922                                (struct mbuf *)0);
     923#else /* !VBOX */
    781924                        (void) tcp_reass(tp, (struct tcpiphdr *)0,
    782925                                (struct mbuf *)0);
     926#endif /* !VBOX */
    783927                        /*
    784928                         * if we didn't have to retransmit the SYN,
     
    786930                         */
    787931                        if (tp->t_rtt)
     932#ifdef VBOX
     933                                tcp_xmit_timer(pData, tp, tp->t_rtt);
     934#else /* !VBOX */
    788935                                tcp_xmit_timer(tp, tp->t_rtt);
     936#endif /* !VBOX */
    789937                } else
    790938                        tp->t_state = TCPS_SYN_RECEIVED;
     
    812960         * States other than LISTEN or SYN_SENT.
    813961         * First check timestamp, if present.
    814          * Then check that at least some bytes of segment are within 
     962         * Then check that at least some bytes of segment are within
    815963         * receive window.  If segment begins before rcv_nxt,
    816964         * drop leading data (and SYN); if nothing left, just ack.
    817          * 
     965         *
    818966         * RFC 1323 PAWS: If we have a timestamp reply on this segment
    819967         * and it's less than ts_recent, drop it.
     
    850998                        tiflags &= ~TH_SYN;
    851999                        ti->ti_seq++;
    852                         if (ti->ti_urp > 1) 
     1000                        if (ti->ti_urp > 1)
    8531001                                ti->ti_urp--;
    8541002                        else
     
    8671015                         */
    8681016                        tiflags &= ~TH_FIN;
    869                        
     1017
    8701018                        /*
    8711019                         * Send an ACK to resynchronize and drop any data.
     
    8961044        if ((so->so_state & SS_NOFDREF) &&
    8971045            tp->t_state > TCPS_CLOSE_WAIT && ti->ti_len) {
     1046#ifdef VBOX
     1047                tp = tcp_close(pData, tp);
     1048#else /* !VBOX */
    8981049                tp = tcp_close(tp);
     1050#endif /* !VBOX */
    8991051                tcpstat.tcps_rcvafterclose++;
    9001052                goto dropwithreset;
     
    9201072                            SEQ_GT(ti->ti_seq, tp->rcv_nxt)) {
    9211073                                iss = tp->rcv_nxt + TCP_ISSINCR;
     1074#ifdef VBOX
     1075                                tp = tcp_close(pData, tp);
     1076#else /* !VBOX */
    9221077                                tp = tcp_close(tp);
     1078#endif /* !VBOX */
    9231079                                goto findso;
    9241080                        }
     
    9781134                tp->t_state = TCPS_CLOSED;
    9791135                tcpstat.tcps_drops++;
     1136#ifdef VBOX
     1137                tp = tcp_close(pData, tp);
     1138#else /* !VBOX */
    9801139                tp = tcp_close(tp);
     1140#endif /* !VBOX */
    9811141                goto drop;
    9821142
     
    9841144        case TCPS_LAST_ACK:
    9851145        case TCPS_TIME_WAIT:
     1146#ifdef VBOX
     1147                tp = tcp_close(pData, tp);
     1148#else /* !VBOX */
    9861149                tp = tcp_close(tp);
     1150#endif /* !VBOX */
    9871151                goto drop;
    9881152        }
     
    9931157         */
    9941158        if (tiflags & TH_SYN) {
     1159#ifdef VBOX
     1160                tp = tcp_drop(pData, tp,0);
     1161#else /* !VBOX */
    9951162                tp = tcp_drop(tp,0);
     1163#endif /* !VBOX */
    9961164                goto dropwithreset;
    9971165        }
     
    10181186                tcpstat.tcps_connects++;
    10191187                tp->t_state = TCPS_ESTABLISHED;
    1020                 /* 
    1021                  * The sent SYN is ack'ed with our sequence number +1 
    1022                  * The first data byte already in the buffer will get 
     1188                /*
     1189                 * The sent SYN is ack'ed with our sequence number +1
     1190                 * The first data byte already in the buffer will get
    10231191                 * lost if no correction is made.  This is only needed for
    10241192                 * SS_CTL since the buffer is empty otherwise.
    1025                  * tp->snd_una++; or:     
     1193                 * tp->snd_una++; or:
    10261194                 */
    10271195                tp->snd_una=ti->ti_ack;
    10281196                if (so->so_state & SS_CTL) {
    10291197                  /* So tcp_ctl reports the right state */
     1198#ifdef VBOX
     1199                  ret = tcp_ctl(pData, so);
     1200#else /* !VBOX */
    10301201                  ret = tcp_ctl(so);
     1202#endif /* !VBOX */
    10311203                  if (ret == 1) {
    10321204                    soisfconnected(so);
     
    10411213                  soisfconnected(so);
    10421214                }
    1043                
     1215
    10441216                /* Do window scaling? */
    10451217/*              if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
     
    10491221 *              }
    10501222 */
     1223#ifdef VBOX
     1224                (void) tcp_reass(pData, tp, (struct tcpiphdr *)0, (struct mbuf *)0);
     1225#else /* !VBOX */
    10511226                (void) tcp_reass(tp, (struct tcpiphdr *)0, (struct mbuf *)0);
     1227#endif /* !VBOX */
    10521228                tp->snd_wl1 = ti->ti_seq - 1;
    10531229                /* Avoid ack processing; snd_una==ti_ack  =>  dup ack */
     
    10951271                                 *
    10961272                                 * Dup acks mean that packets have left the
    1097                                  * network (they're now cached at the receiver) 
     1273                                 * network (they're now cached at the receiver)
    10981274                                 * so bump cwnd by the amount in the receiver
    10991275                                 * to keep a constant cwnd packets in the
     
    11161292                                        tp->snd_nxt = ti->ti_ack;
    11171293                                        tp->snd_cwnd = tp->t_maxseg;
     1294#ifdef VBOX
     1295                                        (void) tcp_output(pData, tp);
     1296#else /* !VBOX */
    11181297                                        (void) tcp_output(tp);
     1298#endif /* !VBOX */
    11191299                                        tp->snd_cwnd = tp->snd_ssthresh +
    11201300                                               tp->t_maxseg * tp->t_dupacks;
     
    11241304                                } else if (tp->t_dupacks > tcprexmtthresh) {
    11251305                                        tp->snd_cwnd += tp->t_maxseg;
     1306#ifdef VBOX
     1307                                        (void) tcp_output(pData, tp);
     1308#else /* !VBOX */
    11261309                                        (void) tcp_output(tp);
     1310#endif /* !VBOX */
    11271311                                        goto drop;
    11281312                                }
     
    11601344 *                      tcp_xmit_timer(tp, tcp_now-ts_ecr+1);
    11611345 *              else
    1162  */                 
     1346 */
    11631347                     if (tp->t_rtt && SEQ_GT(ti->ti_ack, tp->t_rtseq))
     1348#ifdef VBOX
     1349                        tcp_xmit_timer(pData, tp,tp->t_rtt);
     1350#else /* !VBOX */
    11641351                        tcp_xmit_timer(tp,tp->t_rtt);
     1352#endif /* !VBOX */
    11651353
    11661354                /*
     
    12011389                /*
    12021390                 * XXX sowwakup is called when data is acked and there's room for
    1203                  * for more data... it should read() the socket 
     1391                 * for more data... it should read() the socket
    12041392                 */
    12051393/*              if (so->so_snd.sb_flags & SB_NOTIFY)
     
    12571445                case TCPS_LAST_ACK:
    12581446                        if (ourfinisacked) {
     1447#ifdef VBOX
     1448                                tp = tcp_close(pData, tp);
     1449#else /* !VBOX */
    12591450                                tp = tcp_close(tp);
     1451#endif /* !VBOX */
    12601452                                goto drop;
    12611453                        }
     
    12791471         */
    12801472        if ((tiflags & TH_ACK) &&
    1281             (SEQ_LT(tp->snd_wl1, ti->ti_seq) || 
     1473            (SEQ_LT(tp->snd_wl1, ti->ti_seq) ||
    12821474            (tp->snd_wl1 == ti->ti_seq && (SEQ_LT(tp->snd_wl2, ti->ti_ack) ||
    12831475            (tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd))))) {
     
    13141506                 * then mark the data stream.  This should not happen
    13151507                 * in CLOSE_WAIT, CLOSING, LAST_ACK or TIME_WAIT STATES since
    1316                  * a FIN has been received from the remote side. 
     1508                 * a FIN has been received from the remote side.
    13171509                 * In these states we ignore the URG.
    13181510                 *
     
    13211513                 * of urgent data.  We continue, however,
    13221514                 * to consider it to indicate the first octet
    1323                  * of data past the urgent section as the original 
     1515                 * of data past the urgent section as the original
    13241516                 * spec states (in one of two places).
    13251517                 */
     
    13291521                                (tp->rcv_up - tp->rcv_nxt); /* -1; */
    13301522                        tp->rcv_up = ti->ti_seq + ti->ti_urp;
    1331          
     1523
    13321524                }
    13331525        } else
     
    13511543        if ((ti->ti_len || (tiflags&TH_FIN)) &&
    13521544            TCPS_HAVERCVDFIN(tp->t_state) == 0) {
     1545#ifdef VBOX
     1546                TCP_REASS(pData, tp, ti, m, so, tiflags);
     1547#else /* !VBOX */
    13531548                TCP_REASS(tp, ti, m, so, tiflags);
     1549#endif /* !VBOX */
    13541550                /*
    13551551                 * Note the amount of data that peer has sent into
     
    13591555                len = so->so_rcv.sb_datalen - (tp->rcv_adv - tp->rcv_nxt);
    13601556        } else {
     1557#ifdef VBOX
     1558                m_free(pData, m);
     1559#else /* !VBOX */
    13611560                m_free(m);
     1561#endif /* !VBOX */
    13621562                tiflags &= ~TH_FIN;
    13631563        }
     
    13801580/*                      sofcantrcvmore(so); */
    13811581                        sofwdrain(so);
    1382                        
     1582
    13831583                        tp->t_flags |= TF_ACKNOW;
    13841584                        tp->rcv_nxt++;
     
    13941594                  if(so->so_emu == EMU_CTL)        /* no shutdown on socket */
    13951595                    tp->t_state = TCPS_LAST_ACK;
    1396                   else 
     1596                  else
    13971597                    tp->t_state = TCPS_CLOSE_WAIT;
    13981598                  break;
     
    14081608                /*
    14091609                 * In FIN_WAIT_2 state enter the TIME_WAIT state,
    1410                  * starting the time-wait timer, turning off the other 
     1610                 * starting the time-wait timer, turning off the other
    14111611                 * standard timers.
    14121612                 */
     
    14311631         *      congestion avoidance sender won't send more until
    14321632         *      he gets an ACK.
    1433          * 
     1633         *
    14341634         * See above.
    14351635         */
     
    14501650         */
    14511651        if (needoutput || (tp->t_flags & TF_ACKNOW)) {
     1652#ifdef VBOX
     1653                (void) tcp_output(pData, tp);
     1654#else /* !VBOX */
    14521655                (void) tcp_output(tp);
     1656#endif /* !VBOX */
    14531657        }
    14541658        return;
     
    14611665        if (tiflags & TH_RST)
    14621666                goto drop;
     1667#ifdef VBOX
     1668        m_freem(pData, m);
     1669#else /* !VBOX */
    14631670        m_freem(m);
     1671#endif /* !VBOX */
    14641672        tp->t_flags |= TF_ACKNOW;
     1673#ifdef VBOX
     1674        (void) tcp_output(pData, tp);
     1675#else /* !VBOX */
    14651676        (void) tcp_output(tp);
     1677#endif /* !VBOX */
    14661678        return;
    14671679
     
    14691681        /* reuses m if m!=NULL, m_free() unnecessary */
    14701682        if (tiflags & TH_ACK)
     1683#ifdef VBOX
     1684                tcp_respond(pData, tp, ti, m, (tcp_seq)0, ti->ti_ack, TH_RST);
     1685#else /* !VBOX */
    14711686                tcp_respond(tp, ti, m, (tcp_seq)0, ti->ti_ack, TH_RST);
     1687#endif /* !VBOX */
    14721688        else {
    14731689                if (tiflags & TH_SYN) ti->ti_len++;
     1690#ifdef VBOX
     1691                tcp_respond(pData, tp, ti, m, ti->ti_seq+ti->ti_len, (tcp_seq)0,
     1692                    TH_RST|TH_ACK);
     1693#else /* !VBOX */
    14741694                tcp_respond(tp, ti, m, ti->ti_seq+ti->ti_len, (tcp_seq)0,
    14751695                    TH_RST|TH_ACK);
     1696#endif /* !VBOX */
    14761697        }
    14771698
     
    14821703         * Drop space held by incoming segment and return.
    14831704         */
     1705#ifdef VBOX
     1706        m_free(pData, m);
     1707#else /* !VBOX */
    14841708        m_free(m);
     1709#endif /* !VBOX */
    14851710
    14861711        return;
     
    14921717 */
    14931718void
     1719#ifdef VBOX
     1720tcp_dooptions(PNATState pData, struct tcpcb *tp, u_char *cp, int cnt, struct tcpiphdr *ti)
     1721#else /* !VBOX */
    14941722tcp_dooptions(tp, cp, cnt, ti)
    14951723        struct tcpcb *tp;
     
    14971725        int cnt;
    14981726        struct tcpiphdr *ti;
     1727#endif /* !VBOX */
    14991728{
    15001729        u_int16_t mss;
     
    15271756                        memcpy((char *) &mss, (char *) cp + 2, sizeof(mss));
    15281757                        NTOHS(mss);
     1758#ifdef VBOX
     1759                        (void) tcp_mss(pData, tp, mss); /* sets t_maxseg */
     1760#else /* !VBOX */
    15291761                        (void) tcp_mss(tp, mss);        /* sets t_maxseg */
     1762#endif /* !VBOX */
    15301763                        break;
    15311764
     
    15481781 *                      NTOHL(*ts_ecr);
    15491782 *
    1550  */                     /* 
     1783 */                     /*
    15511784 *                       * A timestamp received in a SYN makes
    15521785 *                       * it ok to send timestamp requests and replies.
     
    15791812{
    15801813        int cnt = ti->ti_urp - 1;
    1581        
     1814
    15821815        while (cnt >= 0) {
    15831816                if (m->m_len > cnt) {
     
    16071840
    16081841void
     1842#ifdef VBOX
     1843tcp_xmit_timer(PNATState pData, register struct tcpcb *tp, int rtt)
     1844#else /* !VBOX */
    16091845tcp_xmit_timer(tp, rtt)
    16101846        register struct tcpcb *tp;
    16111847        int rtt;
     1848#endif /* !VBOX */
    16121849{
    16131850        register short delta;
     
    16161853        DEBUG_ARG("tp = %lx", (long)tp);
    16171854        DEBUG_ARG("rtt = %d", rtt);
    1618        
     1855
    16191856        tcpstat.tcps_rttupdated++;
    16201857        if (tp->t_srtt != 0) {
     
    16451882                        tp->t_rttvar = 1;
    16461883        } else {
    1647                 /* 
     1884                /*
    16481885                 * No rtt measurement yet - use the unsmoothed rtt.
    16491886                 * Set the variance to half the rtt (so our first
     
    16691906        TCPT_RANGESET(tp->t_rxtcur, TCP_REXMTVAL(tp),
    16701907            (short)tp->t_rttmin, TCPTV_REXMTMAX); /* XXX */
    1671        
     1908
    16721909        /*
    16731910         * We received an ack for a packet that wasn't retransmitted;
     
    16971934
    16981935int
     1936#ifdef VBOX
     1937tcp_mss(PNATState pData, register struct tcpcb *tp, u_int offer)
     1938#else /* !VBOX */
    16991939tcp_mss(tp, offer)
    17001940        register struct tcpcb *tp;
    17011941        u_int offer;
     1942#endif /* !VBOX */
    17021943{
    17031944        struct socket *so = tp->t_socket;
    17041945        int mss;
    1705        
     1946
    17061947        DEBUG_CALL("tcp_mss");
    17071948        DEBUG_ARG("tp = %lx", (long)tp);
    17081949        DEBUG_ARG("offer = %d", offer);
    1709        
     1950
    17101951        mss = min(if_mtu, if_mru) - sizeof(struct tcpiphdr);
    17111952        if (offer)
     
    17141955        if (mss < tp->t_maxseg || offer != 0)
    17151956           tp->t_maxseg = mss;
    1716        
     1957
    17171958        tp->snd_cwnd = mss;
    1718        
     1959
    17191960        sbreserve(&so->so_snd, tcp_sndspace+((tcp_sndspace%mss)?(mss-(tcp_sndspace%mss)):0));
    17201961        sbreserve(&so->so_rcv, tcp_rcvspace+((tcp_rcvspace%mss)?(mss-(tcp_rcvspace%mss)):0));
    1721        
     1962
    17221963        DEBUG_MISC((dfd, " returning mss = %d\n", mss));
    1723        
     1964
    17241965        return mss;
    17251966}
  • trunk/src/VBox/Devices/Network/slirp/tcp_output.c

    r1 r1033  
    3838 * Changes and additions relating to SLiRP
    3939 * Copyright (c) 1995 Danny Gasparovski.
    40  * 
    41  * Please read the file COPYRIGHT for the 
     40 *
     41 * Please read the file COPYRIGHT for the
    4242 * terms and conditions of the copyright.
    4343 */
     
    4949 * names instead of the REAL names
    5050 */
     51#ifdef VBOX
     52const char * const tcpstates[] = {
     53#else /* !VBOX */
    5154char *tcpstates[] = {
     55#endif /* !VBOX */
    5256/*      "CLOSED",       "LISTEN",       "SYN_SENT",     "SYN_RCVD", */
    5357        "REDIRECT",     "LISTEN",       "SYN_SENT",     "SYN_RCVD",
     
    5660};
    5761
     62#ifdef VBOX
     63static const u_char  tcp_outflags[TCP_NSTATES] = {
     64#else /* !VBOX */
    5865u_char  tcp_outflags[TCP_NSTATES] = {
     66#endif /* !VBOX */
    5967        TH_RST|TH_ACK, 0,      TH_SYN,        TH_SYN|TH_ACK,
    60         TH_ACK,        TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK, 
     68        TH_ACK,        TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK,
    6169        TH_FIN|TH_ACK, TH_ACK, TH_ACK,
    6270};
     
    6977 */
    7078int
     79#ifdef VBOX
     80tcp_output(PNATState pData, register struct tcpcb *tp)
     81#else /* !VBOX */
    7182tcp_output(tp)
    7283        register struct tcpcb *tp;
     84#endif /* !VBOX */
    7385{
    7486        register struct socket *so = tp->t_socket;
     
    8092        unsigned optlen, hdrlen;
    8193        int idle, sendalot;
    82        
     94
    8395        DEBUG_CALL("tcp_output");
    8496        DEBUG_ARG("tp = %lx", (long )tp);
    85        
     97
    8698        /*
    8799         * Determine length of data that should be transmitted,
     
    104116
    105117        flags = tcp_outflags[tp->t_state];
    106        
     118
    107119        DEBUG_MISC((dfd, " --- tcp_output flags = 0x%x\n",flags));
    108        
     120
    109121        /*
    110122         * If in persist timeout with window of 0, send 1 byte.
     
    159171                }
    160172        }
    161        
     173
    162174        if (len > tp->t_maxseg) {
    163175                len = tp->t_maxseg;
     
    201213         */
    202214        if (win > 0) {
    203                 /* 
     215                /*
    204216                 * "adv" is the amount we can increase the window,
    205217                 * taking into account that we are limited by
     
    265277         */
    266278        tcpstat.tcps_didnuttin++;
    267        
     279
    268280        return (0);
    269281
     
    286298                        opt[0] = TCPOPT_MAXSEG;
    287299                        opt[1] = 4;
     300#ifdef VBOX
     301                        mss = htons((u_int16_t) tcp_mss(pData, tp, 0));
     302#else /* !VBOX */
    288303                        mss = htons((u_int16_t) tcp_mss(tp, 0));
     304#endif /* !VBOX */
    289305                        memcpy((caddr_t)(opt + 2), (caddr_t)&mss, sizeof(mss));
    290306                        optlen = 4;
     
    303319                }
    304320        }
    305  
     321
    306322        /*
    307          * Send a timestamp and echo-reply if this is a SYN and our side 
     323         * Send a timestamp and echo-reply if this is a SYN and our side
    308324         * wants to use timestamps (TF_REQ_TSTMP is set) or both our side
    309325         * and our peer have sent timestamps in our SYN's.
     
    323339 */
    324340        hdrlen += optlen;
    325  
     341
    326342        /*
    327343         * Adjust data length if insertion of options will
     
    349365                }
    350366
     367#ifdef VBOX
     368                m = m_get(pData);
     369#else /* !VBOX */
    351370                m = m_get();
     371#endif /* !VBOX */
    352372                if (m == NULL) {
    353373/*                      error = ENOBUFS; */
     
    357377                m->m_data += if_maxlinkhdr;
    358378                m->m_len = hdrlen;
    359                
    360                 /* 
     379
     380                /*
    361381                 * This will always succeed, since we make sure our mbufs
    362382                 * are big enough to hold one MSS packet + header + ... etc.
     
    391411                        tcpstat.tcps_sndwinup++;
    392412
     413#ifdef VBOX
     414                m = m_get(pData);
     415#else /* !VBOX */
    393416                m = m_get();
     417#endif /* !VBOX */
    394418                if (m == NULL) {
    395419/*                      error = ENOBUFS; */
     
    402426
    403427        ti = mtod(m, struct tcpiphdr *);
    404        
     428
    405429        memcpy((caddr_t)ti, &tp->t_template, sizeof (struct tcpiphdr));
    406430
     
    410434         * If resending a FIN, be sure not to use a new sequence number.
    411435         */
    412         if (flags & TH_FIN && tp->t_flags & TF_SENTFIN && 
     436        if (flags & TH_FIN && tp->t_flags & TF_SENTFIN &&
    413437            tp->snd_nxt == tp->snd_max)
    414438                tp->snd_nxt--;
     
    447471                win = (long)(tp->rcv_adv - tp->rcv_nxt);
    448472        ti->ti_win = htons((u_int16_t) (win>>tp->rcv_scale));
    449        
     473
    450474        if (SEQ_GT(tp->snd_up, tp->snd_una)) {
    451475                ti->ti_urp = htons((u_int16_t)(tp->snd_up - ntohl(ti->ti_seq)));
    452 #ifdef notdef           
     476#ifdef notdef
    453477        if (SEQ_GT(tp->snd_up, tp->snd_nxt)) {
    454478                ti->ti_urp = htons((u_int16_t)(tp->snd_up - tp->snd_nxt));
     
    532556         */
    533557        m->m_len = hdrlen + len; /* XXX Needed? m_len should be correct */
    534        
     558
    535559    {
    536            
     560
    537561        ((struct ip *)ti)->ip_len = m->m_len;
    538562
    539563        ((struct ip *)ti)->ip_ttl = ip_defttl;
    540564        ((struct ip *)ti)->ip_tos = so->so_iptos;
    541            
     565
    542566/* #if BSD >= 43 */
    543567        /* Don't do IP options... */
     
    545569 *          so->so_options & SO_DONTROUTE, 0);
    546570 */
     571#ifdef VBOX
     572        error = ip_output(pData, so, m);
     573#else /* !VBOX */
    547574        error = ip_output(so, m);
     575#endif /* !VBOX */
    548576
    549577/* #else
    550  *      error = ip_output(m, (struct mbuf *)0, &tp->t_inpcb->inp_route, 
     578 *      error = ip_output(m, (struct mbuf *)0, &tp->t_inpcb->inp_route,
    551579 *          so->so_options & SO_DONTROUTE);
    552580 * #endif
  • trunk/src/VBox/Devices/Network/slirp/tcp_subr.c

    r532 r1033  
    3838 * Changes and additions relating to SLiRP
    3939 * Copyright (c) 1995 Danny Gasparovski.
    40  * 
    41  * Please read the file COPYRIGHT for the 
     40 *
     41 * Please read the file COPYRIGHT for the
    4242 * terms and conditions of the copyright.
    4343 */
     
    4646#include <slirp.h>
    4747
     48#ifndef VBOX
    4849/* patchable/settable parameters for tcp */
    4950int     tcp_mssdflt = TCP_MSS;
     
    5253int     tcp_rcvspace;   /* You may want to change this */
    5354int     tcp_sndspace;   /* Keep small if you have an error prone link */
     55#endif /* !VBOX */
    5456
    5557/*
     
    5759 */
    5860void
     61#ifdef VBOX
     62tcp_init(PNATState pData)
     63#else /* !VBOX */
    5964tcp_init()
     65#endif /* !VBOX */
    6066{
    6167        tcp_iss = 1;            /* wrong */
    6268        tcb.so_next = tcb.so_prev = &tcb;
    63        
     69#ifdef VBOX
     70        tcp_last_so = &tcb;
     71#endif /* VBOX */
     72
     73#ifndef VBOX
    6474        /* tcp_rcvspace = our Window we advertise to the remote */
    6575        tcp_rcvspace = TCP_RCVSPACE;
    6676        tcp_sndspace = TCP_SNDSPACE;
    67        
     77
    6878        /* Make sure tcp_sndspace is at least 2*MSS */
    6979        if (tcp_sndspace < 2*(min(if_mtu, if_mru) - sizeof(struct tcpiphdr)))
    7080                tcp_sndspace = 2*(min(if_mtu, if_mru) - sizeof(struct tcpiphdr));
     81#endif /* !VBOX */
    7182}
    7283
     
    93104        n->ti_sport = so->so_fport;
    94105        n->ti_dport = so->so_lport;
    95        
     106
    96107        n->ti_seq = 0;
    97108        n->ti_ack = 0;
     
    118129 */
    119130void
     131#ifdef VBOX
     132tcp_respond(PNATState pData, struct tcpcb *tp, struct tcpiphdr *ti, struct mbuf *m, tcp_seq ack, tcp_seq seq, int flags)
     133#else /* !VBOX */
    120134tcp_respond(tp, ti, m, ack, seq, flags)
    121135        struct tcpcb *tp;
     
    124138        tcp_seq ack, seq;
    125139        int flags;
     140#endif /* !VBOX */
    126141{
    127142        register int tlen;
     
    135150        DEBUG_ARG("seq = %u", seq);
    136151        DEBUG_ARG("flags = %x", flags);
    137        
     152
    138153        if (tp)
    139154                win = sbspace(&tp->t_socket->so_rcv);
    140155        if (m == 0) {
     156#ifdef VBOX
     157                if ((m = m_get(pData)) == NULL)
     158#else /* !VBOX */
    141159                if ((m = m_get()) == NULL)
     160#endif /* !VBOX */
    142161                        return;
    143162#ifdef TCP_COMPAT_42
     
    151170                flags = TH_ACK;
    152171        } else {
    153                 /* 
     172                /*
    154173                 * ti points into m so the next line is just making
    155174                 * the mbuf point to ti
    156175                 */
    157176                m->m_data = (caddr_t)ti;
    158                
     177
    159178                m->m_len = sizeof (struct tcpiphdr);
    160179                tlen = 0;
     
    184203        ((struct ip *)ti)->ip_len = tlen;
    185204
    186         if(flags & TH_RST) 
     205        if(flags & TH_RST)
    187206          ((struct ip *)ti)->ip_ttl = MAXTTL;
    188         else 
     207        else
    189208          ((struct ip *)ti)->ip_ttl = ip_defttl;
    190        
     209
     210#ifdef VBOX
     211        (void) ip_output(pData, (struct socket *)0, m);
     212#else /* !VBOX */
    191213        (void) ip_output((struct socket *)0, m);
     214#endif /* !VBOX */
    192215}
    193216
     
    202225{
    203226        register struct tcpcb *tp;
    204        
     227
    205228        tp = (struct tcpcb *)malloc(sizeof(*tp));
    206229        if (tp == NULL)
    207230                return ((struct tcpcb *)0);
    208        
     231
    209232        memset((char *) tp, 0, sizeof(struct tcpcb));
    210233        tp->seg_next = tp->seg_prev = ptr_to_u32((struct tcpiphdr *)tp);
    211234        tp->t_maxseg = tcp_mssdflt;
    212        
     235
    213236        tp->t_flags = tcp_do_rfc1323 ? (TF_REQ_SCALE|TF_REQ_TSTMP) : 0;
    214237        tp->t_socket = so;
    215        
     238
    216239        /*
    217240         * Init srtt to TCPTV_SRTTBASE (0), so we can tell that we have no
     
    223246        tp->t_rttmin = TCPTV_MIN;
    224247
    225         TCPT_RANGESET(tp->t_rxtcur, 
     248        TCPT_RANGESET(tp->t_rxtcur,
    226249            ((TCPTV_SRTTBASE >> 2) + (TCPTV_SRTTDFLT << 2)) >> 1,
    227250            TCPTV_MIN, TCPTV_REXMTMAX);
     
    230253        tp->snd_ssthresh = TCP_MAXWIN << TCP_MAX_WINSHIFT;
    231254        tp->t_state = TCPS_CLOSED;
    232        
     255
    233256        so->so_tcpcb = tp;
    234257
     
    241264 * then send a RST to peer.
    242265 */
    243 struct tcpcb *tcp_drop(struct tcpcb *tp, int err)
     266#ifdef VBOX
     267struct tcpcb *tcp_drop(PNATState pData, struct tcpcb *tp, int err)
     268#else /* !VBOX */
     269struct tcpcb *tcp_drop(struct tcpcb *tp, int err)
     270#endif /* !VBOX */
    244271{
    245272/* tcp_drop(tp, errno)
     
    252279        DEBUG_ARG("tp = %lx", (long)tp);
    253280        DEBUG_ARG("errno = %d", errno);
    254        
     281
    255282        if (TCPS_HAVERCVDSYN(tp->t_state)) {
    256283                tp->t_state = TCPS_CLOSED;
     284#ifdef VBOX
     285                (void) tcp_output(pData, tp);
     286#else /* !VBOX */
    257287                (void) tcp_output(tp);
     288#endif /* !VBOX */
    258289                tcpstat.tcps_drops++;
    259290        } else
     
    263294 */
    264295/*      so->so_error = errno; */
     296#ifdef VBOX
     297        return (tcp_close(pData, tp));
     298#else /* !VBOX */
    265299        return (tcp_close(tp));
     300#endif /* !VBOX */
    266301}
    267302
     
    273308 */
    274309struct tcpcb *
     310#ifdef VBOX
     311tcp_close(PNATState pData, register struct tcpcb *tp)
     312#else /* !VBOX */
    275313tcp_close(tp)
    276314        register struct tcpcb *tp;
     315#endif /* !VBOX */
    277316{
    278317        register struct tcpiphdr *t;
     
    282321        DEBUG_CALL("tcp_close");
    283322        DEBUG_ARG("tp = %lx", (long )tp);
    284        
     323
    285324        /* free the reassembly queue, if any */
    286325        t = u32_to_ptr(tp->seg_next, struct tcpiphdr *);
     
    289328                m = REASS_MBUF_GET(u32_to_ptr(t->ti_prev, struct tcpiphdr *));
    290329                remque_32(u32_to_ptr(t->ti_prev, struct tcpiphdr *));
     330#ifdef VBOX
     331                m_freem(pData, m);
     332#else /* !VBOX */
    291333                m_freem(m);
     334#endif /* !VBOX */
    292335        }
    293336        /* It's static */
     
    306349        sbfree(&so->so_rcv);
    307350        sbfree(&so->so_snd);
     351#ifdef VBOX
     352        sofree(pData, so);
     353#else /* !VBOX */
    308354        sofree(so);
     355#endif /* !VBOX */
    309356        tcpstat.tcps_closed++;
    310357        return ((struct tcpcb *)0);
     
    352399 */
    353400void
     401#ifdef VBOX
     402tcp_sockclosed(PNATState pData, struct tcpcb *tp)
     403#else /* !VBOX */
    354404tcp_sockclosed(tp)
    355405        struct tcpcb *tp;
     406#endif /* !VBOX */
    356407{
    357408
    358409        DEBUG_CALL("tcp_sockclosed");
    359410        DEBUG_ARG("tp = %lx", (long)tp);
    360        
     411
    361412        switch (tp->t_state) {
    362413
     
    365416        case TCPS_SYN_SENT:
    366417                tp->t_state = TCPS_CLOSED;
     418#ifdef VBOX
     419                tp = tcp_close(pData, tp);
     420#else /* !VBOX */
    367421                tp = tcp_close(tp);
     422#endif /* !VBOX */
    368423                break;
    369424
     
    381436                soisfdisconnected(tp->t_socket);
    382437        if (tp)
     438#ifdef VBOX
     439                tcp_output(pData, tp);
     440#else /* !VBOX */
    383441                tcp_output(tp);
     442#endif /* !VBOX */
    384443}
    385444
    386 /* 
     445/*
    387446 * Connect to a host on the Internet
    388447 * Called by tcp_input
     
    391450 * else return -1 means we're still connecting
    392451 * The return value is almost always -1 since the socket is
    393  * nonblocking.  Connect returns after the SYN is sent, and does 
     452 * nonblocking.  Connect returns after the SYN is sent, and does
    394453 * not wait for ACK+SYN.
    395454 */
     455#ifdef VBOX
     456int tcp_fconnect(PNATState pData, struct socket *so)
     457#else /* !VBOX */
    396458int tcp_fconnect(so)
    397459     struct socket *so;
     460#endif /* !VBOX */
    398461{
    399462  int ret=0;
    400  
     463
    401464  DEBUG_CALL("tcp_fconnect");
    402465  DEBUG_ARG("so = %lx", (long )so);
     
    411474    opt = 1;
    412475    setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(opt ));
    413    
     476
    414477    addr.sin_family = AF_INET;
    415478    if ((so->so_faddr.s_addr & htonl(0xffffff00)) == special_addr.s_addr) {
     
    427490      addr.sin_addr = so->so_faddr;
    428491    addr.sin_port = so->so_fport;
    429    
     492
    430493    DEBUG_MISC((dfd, " connect()ing, addr.sin_port=%d, "
    431                 "addr.sin_addr.s_addr=%.16s\n", 
     494                "addr.sin_addr.s_addr=%.16s\n",
    432495                ntohs(addr.sin_port), inet_ntoa(addr.sin_addr)));
    433496    /* We don't care what port we get */
    434497    ret = connect(s,(struct sockaddr *)&addr,sizeof (addr));
    435    
     498
    436499    /*
    437500     * If it's not in progress, it failed, so we just return 0,
     
    446509/*
    447510 * Accept the socket and connect to the local-host
    448  * 
     511 *
    449512 * We have a problem. The correct thing to do would be
    450513 * to first connect to the local-host, and only if the
    451514 * connection is accepted, then do an accept() here.
    452  * But, a) we need to know who's trying to connect 
     515 * But, a) we need to know who's trying to connect
    453516 * to the socket to be able to SYN the local-host, and
    454517 * b) we are already connected to the foreign host by
    455518 * the time it gets to accept(), so... We simply accept
    456519 * here and SYN the local-host.
    457  */ 
     520 */
    458521void
     522#ifdef VBOX
     523tcp_connect(PNATState pData, struct socket *inso)
     524#else /* !VBOX */
    459525tcp_connect(inso)
    460526        struct socket *inso;
     527#endif /* !VBOX */
    461528{
    462529        struct socket *so;
     
    472539        DEBUG_CALL("tcp_connect");
    473540        DEBUG_ARG("inso = %lx", (long)inso);
    474        
     541
    475542        /*
    476543         * If it's an SS_ACCEPTONCE socket, no need to socreate()
     
    486553                        return;
    487554                }
     555#ifdef VBOX
     556                if (tcp_attach(pData, so) < 0) {
     557#else /* !VBOX */
    488558                if (tcp_attach(so) < 0) {
     559#endif /* !VBOX */
    489560                        free(so); /* NOT sofree */
    490561                        return;
     
    493564                so->so_lport = inso->so_lport;
    494565        }
    495        
     566
     567#ifdef VBOX
     568        (void) tcp_mss(pData, sototcpcb(so), 0);
     569#else /* !VBOX */
    496570        (void) tcp_mss(sototcpcb(so), 0);
     571#endif /* !VBOX */
    497572
    498573        if ((s = accept(inso->s,(struct sockaddr *)&addr,&addrlen)) < 0) {
     574#ifdef VBOX
     575                tcp_close(pData, sototcpcb(so)); /* This will sofree() as well */
     576#else /* !VBOX */
    499577                tcp_close(sototcpcb(so)); /* This will sofree() as well */
     578#endif /* !VBOX */
    500579                return;
    501580        }
     
    513592        if (so->so_faddr.s_addr == 0 || so->so_faddr.s_addr == loopback_addr.s_addr)
    514593           so->so_faddr = alias_addr;
    515        
     594
    516595        /* Close the accept() socket, set right state */
    517596        if (inso->so_state & SS_FACCEPTONCE) {
     
    521600        }
    522601        so->s = s;
    523        
     602
    524603        so->so_iptos = tcp_tos(so);
    525604        tp = sototcpcb(so);
    526605
    527606        tcp_template(tp);
    528        
     607
    529608        /* Compute window scaling to request.  */
    530609/*      while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
     
    535614/*      soisconnecting(so); */ /* NOFDREF used instead */
    536615        tcpstat.tcps_connattempt++;
    537        
     616
    538617        tp->t_state = TCPS_SYN_SENT;
    539618        tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
    540         tp->iss = tcp_iss; 
     619        tp->iss = tcp_iss;
    541620        tcp_iss += TCP_ISSINCR/2;
    542621        tcp_sendseqinit(tp);
     622#ifdef VBOX
     623        tcp_output(pData, tp);
     624#else /* !VBOX */
    543625        tcp_output(tp);
     626#endif /* !VBOX */
    544627}
    545628
     
    548631 */
    549632int
     633#ifdef VBOX
     634tcp_attach(PNATState pData, struct socket *so)
     635#else /* !VBOX */
    550636tcp_attach(so)
    551637        struct socket *so;
     638#endif /* !VBOX */
    552639{
    553640        if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL)
    554641           return -1;
    555        
     642
    556643        insque(so, &tcb);
    557644
     
    562649 * Set the socket's type of service field
    563650 */
     651#ifdef VBOX
     652static const struct tos_t tcptos[] = {
     653#else /* !VBOX */
    564654struct tos_t tcptos[] = {
     655#endif /* !VBOX */
    565656          {0, 20, IPTOS_THROUGHPUT, 0}, /* ftp data */
    566657          {21, 21, IPTOS_LOWDELAY,  EMU_FTP},   /* ftp control */
     
    578669};
    579670
     671#ifndef VBOX
    580672struct emu_t *tcpemu = 0;
    581                
     673#endif /* !VBOX */
     674
    582675/*
    583676 * Return TOS according to the above table
     
    588681{
    589682        int i = 0;
     683#ifndef VBOX
    590684        struct emu_t *emup;
    591        
     685#endif /* !VBOX */
     686
    592687        while(tcptos[i].tos) {
    593688                if ((tcptos[i].fport && (ntohs(so->so_fport) == tcptos[i].fport)) ||
     
    598693                i++;
    599694        }
    600        
     695
     696#ifdef VBOX
     697        /* No user-added emulators supported. */
     698#else /* !VBOX */
    601699        /* Nope, lets see if there's a user-added one */
    602700        for (emup = tcpemu; emup; emup = emup->next) {
     
    607705                }
    608706        }
    609        
     707#endif /* !VBOX */
     708
    610709        return 0;
    611710}
    612711
     712#ifndef VBOX
    613713int do_echo = -1;
     714#endif /* !VBOX */
    614715
    615716/*
     
    618719 * initiated by the server) and IRC (DCC CHAT and
    619720 * DCC SEND) for now
    620  * 
     721 *
    621722 * NOTE: It's possible to crash SLiRP by sending it
    622723 * unstandard strings to emulate... if this is a problem,
     
    624725 *
    625726 * XXX Assumes the whole command came in one packet
    626  *                                         
     727 *
    627728 * XXX Some ftp clients will have their TOS set to
    628729 * LOWDELAY and so Nagel will kick in.  Because of this,
     
    631732 * DCC doesn't have this problem because there's other stuff
    632733 * in the packet before the DCC command.
    633  * 
    634  * Return 1 if the mbuf m is still valid and should be 
     734 *
     735 * Return 1 if the mbuf m is still valid and should be
    635736 * sbappend()ed
    636  * 
     737 *
    637738 * NOTE: if you return 0 you MUST m_free() the mbuf!
    638739 */
    639740int
     741#ifdef VBOX
     742tcp_emu(PNATState pData, struct socket *so, struct mbuf *m)
     743#else /* !VBOX */
    640744tcp_emu(so, m)
    641745        struct socket *so;
    642746        struct mbuf *m;
     747#endif /* !VBOX */
    643748{
    644749        u_int n1, n2, n3, n4, n5, n6;
     
    647752        u_int lport;
    648753        char *bptr;
    649        
     754
    650755        DEBUG_CALL("tcp_emu");
    651756        DEBUG_ARG("so = %lx", (long)so);
    652757        DEBUG_ARG("m = %lx", (long)m);
    653        
     758
    654759        switch(so->so_emu) {
    655760                int x, i;
    656                
     761
    657762         case EMU_IDENT:
    658763                /*
    659764                 * Identification protocol as per rfc-1413
    660765                 */
    661                
     766
    662767                {
    663768                        struct socket *tmpso;
     
    669774#endif /* VBOX */
    670775                        struct sbuf *so_rcv = &so->so_rcv;
    671                        
     776
    672777                        memcpy(so_rcv->sb_wptr, m->m_data, m->m_len);
    673778                        so_rcv->sb_wptr += m->m_len;
     
    699804                                so_rcv->sb_wptr = so_rcv->sb_data + so_rcv->sb_cc;
    700805                        }
     806#ifdef VBOX
     807                        m_free(pData, m);
     808#else /* !VBOX */
    701809                        m_free(m);
     810#endif /* !VBOX */
    702811                        return 0;
    703812                }
    704                
     813
    705814#if 0
    706815         case EMU_RLOGIN:
     
    717826                        struct sbuf *so_snd = &so->so_snd;
    718827                        struct sbuf *so_rcv = &so->so_rcv;
    719                        
     828
    720829                        /* First check if they have a priveladged port, or too much data has arrived */
    721830                        if (ntohs(so->so_lport) > 1023 || ntohs(so->so_lport) < 512 ||
     
    728837                                return 0;
    729838                        }
    730                        
     839
    731840                        /* Append the current data */
    732841                        memcpy(so_rcv->sb_wptr, m->m_data, m->m_len);
     
    734843                        so_rcv->sb_rptr += m->m_len;
    735844                        m_free(m);
    736                        
     845
    737846                        /*
    738847                         * Check if we have all the initial options,
     
    766875                                }
    767876                        }
    768                        
     877
    769878                        if (n != 4)
    770879                           return 0;
    771                        
     880
    772881                        /* We have it, set our term variable and fork_exec() */
    773882#ifdef HAVE_SETENV
     
    779888                        term[0] = 0;
    780889                        so->so_emu = 0;
    781                        
     890
    782891                        /* And finally, send the client a 0 character */
    783892                        so_snd->sb_wptr[0] = 0;
    784893                        so_snd->sb_wptr++;
    785894                        so_snd->sb_cc++;
    786                        
     895
    787896                        return 0;
    788897                }
    789                
     898
    790899         case EMU_RSH:
    791900                /*
     
    801910                        struct sbuf *so_snd = &so->so_snd;
    802911                        struct sbuf *so_rcv = &so->so_rcv;
    803                        
     912
    804913                        /* First check if they have a priveladged port, or too much data has arrived */
    805914                        if (ntohs(so->so_lport) > 1023 || ntohs(so->so_lport) < 512 ||
     
    812921                                return 0;
    813922                        }
    814                        
     923
    815924                        /* Append the current data */
    816925                        memcpy(so_rcv->sb_wptr, m->m_data, m->m_len);
     
    818927                        so_rcv->sb_rptr += m->m_len;
    819928                        m_free(m);
    820                        
     929
    821930                        /*
    822931                         * Check if we have all the initial options,
     
    854963                                ns->so_fport=htons(IPPORT_RESERVED-1); /* Use a fake port. */
    855964
    856                                 if (ns->so_faddr.s_addr == 0 || 
     965                                if (ns->so_faddr.s_addr == 0 ||
    857966                                        ns->so_faddr.s_addr == loopback_addr.s_addr)
    858967                  ns->so_faddr = alias_addr;
     
    860969                                ns->so_iptos = tcp_tos(ns);
    861970                                tp = sototcpcb(ns);
    862                
     971
    863972                                tcp_template(tp);
    864                
     973
    865974                                /* Compute window scaling to request.  */
    866975                                /*      while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
     
    872981
    873982                                tcpstat.tcps_connattempt++;
    874                                        
     983
    875984                                tp->t_state = TCPS_SYN_SENT;
    876985                                tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
    877                                 tp->iss = tcp_iss; 
     986                                tp->iss = tcp_iss;
    878987                                tcp_iss += TCP_ISSINCR/2;
    879988                                tcp_sendseqinit(tp);
     
    8911000              }
    8921001                        }
    893                        
     1002
    8941003                        if (n != 4)
    8951004              return 0;
    896                        
     1005
    8971006                        rsh_exec(so,so->extra, user, inet_ntoa(so->so_faddr), args);
    8981007                        so->so_emu = 0;
    8991008                        so->extra=NULL;
    900                        
     1009
    9011010                        /* And finally, send the client a 0 character */
    9021011                        so_snd->sb_wptr[0] = 0;
    9031012                        so_snd->sb_wptr++;
    9041013                        so_snd->sb_cc++;
    905                        
     1014
    9061015                        return 0;
    9071016                }
     
    9121021                        struct sbuf *so_snd = &so->so_snd;
    9131022                        struct sbuf *so_rcv = &so->so_rcv;
    914                        
     1023
    9151024                        /*
    9161025                         * If there is binary data here, we save it in so->so_m
     
    9271036                          }
    9281037                        } /* if(so->so_m==NULL) */
    929                        
     1038
    9301039                        /*
    9311040                         * Append the line
    9321041                         */
    9331042                        sbappendsb(so_rcv, m);
    934                        
     1043
    9351044                        /* To avoid going over the edge of the buffer, we reset it */
    9361045                        if (so_snd->sb_cc == 0)
    9371046                           so_snd->sb_wptr = so_snd->sb_rptr = so_snd->sb_data;
    938                        
     1047
    9391048                        /*
    9401049                         * A bit of a hack:
     
    9551064                        } else
    9561065                          m_free(m);
    957                        
     1066
    9581067                        num = 0;
    9591068                        while (num < so->so_rcv.sb_cc) {
     
    9611070                                    *(so->so_rcv.sb_rptr + num) == '\r') {
    9621071                                        int n;
    963                                        
     1072
    9641073                                        *(so_rcv->sb_rptr + num) = 0;
    9651074                                        if (ctl_password && !ctl_password_ok) {
     
    9981107                        return 0;
    9991108                }
    1000 #endif         
     1109#endif
    10011110        case EMU_FTP: /* ftp */
    10021111                *(m->m_data+m->m_len) = 0; /* NULL terminate for strstr */
     
    10041113                        /*
    10051114                         * Need to emulate the PORT command
    1006                          */                     
    1007 #ifdef VBOX
    1008                         x = sscanf(bptr, "ORT %u,%u,%u,%u,%u,%u\r\n%256[^\177]", 
     1115                         */
     1116#ifdef VBOX
     1117                        x = sscanf(bptr, "ORT %u,%u,%u,%u,%u,%u\r\n%256[^\177]",
    10091118                                   &n1, &n2, &n3, &n4, &n5, &n6, buff);
    10101119#else
    1011                         x = sscanf(bptr, "ORT %d,%d,%d,%d,%d,%d\r\n%256[^\177]", 
     1120                        x = sscanf(bptr, "ORT %d,%d,%d,%d,%d,%d\r\n%256[^\177]",
    10121121                                   &n1, &n2, &n3, &n4, &n5, &n6, buff);
    10131122#endif
    10141123                        if (x < 6)
    10151124                           return 1;
    1016                        
     1125
    10171126                        laddr = htonl((n1 << 24) | (n2 << 16) | (n3 << 8) | (n4));
    10181127                        lport = htons((n5 << 8) | (n6));
    1019                        
     1128
     1129#ifdef VBOX
     1130                        if ((so = solisten(pData, 0, laddr, lport, SS_FACCEPTONCE)) == NULL)
     1131#else /* !VBOX */
    10201132                        if ((so = solisten(0, laddr, lport, SS_FACCEPTONCE)) == NULL)
     1133#endif /* !VBOX */
    10211134                           return 1;
    1022                        
     1135
    10231136                        n6 = ntohs(so->so_fport);
    1024                        
     1137
    10251138                        n5 = (n6 >> 8) & 0xff;
    10261139                        n6 &= 0xff;
    1027                        
     1140
    10281141                        laddr = ntohl(so->so_faddr.s_addr);
    1029                        
     1142
    10301143                        n1 = ((laddr >> 24) & 0xff);
    10311144                        n2 = ((laddr >> 16) & 0xff);
    10321145                        n3 = ((laddr >> 8)  & 0xff);
    10331146                        n4 =  (laddr & 0xff);
    1034                        
     1147
    10351148                        m->m_len = bptr - m->m_data; /* Adjust length */
    1036                         m->m_len += sprintf(bptr,"ORT %d,%d,%d,%d,%d,%d\r\n%s", 
     1149                        m->m_len += sprintf(bptr,"ORT %d,%d,%d,%d,%d,%d\r\n%s",
    10371150                                            n1, n2, n3, n4, n5, n6, x==7?buff:"");
    10381151                        return 1;
     
    10501163                        if (x < 6)
    10511164                           return 1;
    1052                        
     1165
    10531166                        laddr = htonl((n1 << 24) | (n2 << 16) | (n3 << 8) | (n4));
    10541167                        lport = htons((n5 << 8) | (n6));
    1055                        
     1168
     1169#ifdef VBOX
     1170                        if ((so = solisten(pData, 0, laddr, lport, SS_FACCEPTONCE)) == NULL)
     1171#else /* !VBOX */
    10561172                        if ((so = solisten(0, laddr, lport, SS_FACCEPTONCE)) == NULL)
     1173#endif /* !VBOX */
    10571174                           return 1;
    1058                        
     1175
    10591176                        n6 = ntohs(so->so_fport);
    1060                        
     1177
    10611178                        n5 = (n6 >> 8) & 0xff;
    10621179                        n6 &= 0xff;
    1063                        
     1180
    10641181                        laddr = ntohl(so->so_faddr.s_addr);
    1065                        
     1182
    10661183                        n1 = ((laddr >> 24) & 0xff);
    10671184                        n2 = ((laddr >> 16) & 0xff);
    10681185                        n3 = ((laddr >> 8)  & 0xff);
    10691186                        n4 =  (laddr & 0xff);
    1070                        
     1187
    10711188                        m->m_len = bptr - m->m_data; /* Adjust length */
    10721189                        m->m_len += sprintf(bptr,"27 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n%s",
    10731190                                            n1, n2, n3, n4, n5, n6, x==7?buff:"");
    1074                        
     1191
    10751192                        return 1;
    10761193                }
    1077                
     1194
    10781195                return 1;
    1079                                    
     1196
    10801197         case EMU_KSH:
    10811198                /*
     
    10931210                }
    10941211                if (m->m_data[m->m_len-1] == '\0' && lport != 0 &&
     1212#ifdef VBOX
     1213                    (so = solisten(pData, 0, so->so_laddr.s_addr, htons(lport), SS_FACCEPTONCE)) != NULL)
     1214#else /* !VBOX */
    10951215                    (so = solisten(0, so->so_laddr.s_addr, htons(lport), SS_FACCEPTONCE)) != NULL)
     1216#endif /* !VBOX */
    10961217                        m->m_len = sprintf(m->m_data, "%d", ntohs(so->so_fport))+1;
    10971218                return 1;
    1098                
     1219
    10991220         case EMU_IRC:
    11001221                /*
     
    11041225                if ((bptr = (char *)strstr(m->m_data, "DCC")) == NULL)
    11051226                         return 1;
    1106                
     1227
    11071228                /* The %256s is for the broken mIRC */
    11081229                if (sscanf(bptr, "DCC CHAT %256s %u %u", buff, &laddr, &lport) == 3) {
     1230#ifdef VBOX
     1231                        if ((so = solisten(pData, 0, htonl(laddr), htons(lport), SS_FACCEPTONCE)) == NULL)
     1232#else /* !VBOX */
    11091233                        if ((so = solisten(0, htonl(laddr), htons(lport), SS_FACCEPTONCE)) == NULL)
     1234#endif /* !VBOX */
    11101235                                return 1;
    1111                        
     1236
    11121237                        m->m_len = bptr - m->m_data; /* Adjust length */
    11131238                        m->m_len += sprintf(bptr, "DCC CHAT chat %lu %u%c\n",
     
    11151240                             ntohs(so->so_fport), 1);
    11161241                } else if (sscanf(bptr, "DCC SEND %256s %u %u %u", buff, &laddr, &lport, &n1) == 4) {
     1242#ifdef VBOX
     1243                        if ((so = solisten(pData, 0, htonl(laddr), htons(lport), SS_FACCEPTONCE)) == NULL)
     1244#else /* !VBOX */
    11171245                        if ((so = solisten(0, htonl(laddr), htons(lport), SS_FACCEPTONCE)) == NULL)
     1246#endif /* !VBOX */
    11181247                                return 1;
    1119                        
     1248
    11201249                        m->m_len = bptr - m->m_data; /* Adjust length */
    1121                         m->m_len += sprintf(bptr, "DCC SEND %s %lu %u %u%c\n", 
     1250                        m->m_len += sprintf(bptr, "DCC SEND %s %lu %u %u%c\n",
    11221251                              buff, (unsigned long)ntohl(so->so_faddr.s_addr),
    11231252                              ntohs(so->so_fport), n1, 1);
    11241253                } else if (sscanf(bptr, "DCC MOVE %256s %u %u %u", buff, &laddr, &lport, &n1) == 4) {
     1254#ifdef VBOX
     1255                        if ((so = solisten(pData, 0, htonl(laddr), htons(lport), SS_FACCEPTONCE)) == NULL)
     1256#else /* !VBOX */
    11251257                        if ((so = solisten(0, htonl(laddr), htons(lport), SS_FACCEPTONCE)) == NULL)
     1258#endif /* !VBOX */
    11261259                                return 1;
    1127                        
     1260
    11281261                        m->m_len = bptr - m->m_data; /* Adjust length */
    11291262                        m->m_len += sprintf(bptr, "DCC MOVE %s %lu %u %u%c\n",
     
    11331266                return 1;
    11341267
     1268#ifdef VBOX
     1269         /** @todo Disabled EMU_REALAUDIO, because it uses a static variable.
     1270          * This is not legal when more than one slirp instance is active. */
     1271#else /* !VBOX */
    11351272         case EMU_REALAUDIO:
    1136                 /* 
     1273                /*
    11371274                 * RealAudio emulation - JP. We must try to parse the incoming
    11381275                 * data and try to find the two characters that contain the
     
    11421279                 * The 1.0 beta versions of the player are not supported
    11431280                 * any more.
    1144                  * 
     1281                 *
    11451282                 * A typical packet for player version 1.0 (release version):
    1146                  *       
    1147                  * 0000:50 4E 41 00 05 
     1283                 *
     1284                 * 0000:50 4E 41 00 05
    11481285                 * 0000:00 01 00 02 1B D7 00 00 67 E6 6C DC 63 00 12 50 .....×..gælÜc..P
    11491286                 * 0010:4E 43 4C 49 45 4E 54 20 31 30 31 20 41 4C 50 48 NCLIENT 101 ALPH
    11501287                 * 0020:41 6C 00 00 52 00 17 72 61 66 69 6C 65 73 2F 76 Al..R..rafiles/v
    11511288                 * 0030:6F 61 2F 65 6E 67 6C 69 73 68 5F 2E 72 61 79 42 oa/english_.rayB
    1152                  *         
     1289                 *
    11531290                 * Now the port number 0x1BD7 is found at offset 0x04 of the
    11541291                 * Now the port number 0x1BD7 is found at offset 0x04 of the
     
    11571294                 *
    11581295                 * A typical packet for player version 2.0 (beta):
    1159                  *       
     1296                 *
    11601297                 * 0000:50 4E 41 00 06 00 02 00 00 00 01 00 02 1B C1 00 PNA...........Á.
    11611298                 * 0010:00 67 75 78 F5 63 00 0A 57 69 6E 32 2E 30 2E 30 .guxõc..Win2.0.0
     
    11631300                 * 0030:77 65 62 73 69 74 65 2F 32 30 72 65 6C 65 61 73 website/20releas
    11641301                 * 0040:65 2E 72 61 79 53 00 00 06 36 42                e.rayS...6B
    1165                  *       
     1302                 *
    11661303                 * Port number 0x1BC1 is found at offset 0x0d.
    1167                  *     
     1304                 *
    11681305                 * This is just a horrible switch statement. Variable ra tells
    11691306                 * us where we're going.
    11701307                 */
    1171                
     1308
    11721309                bptr = m->m_data;
    11731310                while (bptr < m->m_data + m->m_len) {
    11741311                        u_short p;
    11751312                        static int ra = 0;
    1176                         char ra_tbl[4]; 
    1177                        
     1313                        char ra_tbl[4];
     1314
    11781315                        ra_tbl[0] = 0x50;
    11791316                        ra_tbl[1] = 0x4e;
    11801317                        ra_tbl[2] = 0x41;
    11811318                        ra_tbl[3] = 0;
    1182                        
     1319
    11831320                        switch (ra) {
    11841321                         case 0:
     
    11901327                                }
    11911328                                break;
    1192                                
     1329
    11931330                         case 1:
    11941331                                /*
     
    12041341                                }
    12051342                                break;
    1206                                
    1207                          case 4: 
    1208                                 /* 
     1343
     1344                         case 4:
     1345                                /*
    12091346                                 * skip version number
    12101347                                 */
    12111348                                bptr++;
    12121349                                break;
    1213                                
    1214                          case 5: 
     1350
     1351                         case 5:
    12151352                                /*
    12161353                                 * The difference between versions 1.0 and
     
    12221359                                else
    12231360                                   bptr += 4;
    1224                                 break;                         
    1225                                
     1361                                break;
     1362
    12261363                         case 6:
    12271364                                /* This is the field containing the port
    12281365                                 * number that RA-player is listening to.
    12291366                                 */
    1230                                 lport = (((u_char*)bptr)[0] << 8) 
     1367                                lport = (((u_char*)bptr)[0] << 8)
    12311368                                + ((u_char *)bptr)[1];
    1232                                 if (lport < 6970)     
     1369                                if (lport < 6970)
    12331370                                   lport += 256;   /* don't know why */
    12341371                                if (lport < 6970 || lport > 7170)
    12351372                                   return 1;       /* failed */
    1236                                
     1373
    12371374                                /* try to get udp port between 6970 - 7170 */
    12381375                                for (p = 6970; p < 7071; p++) {
     
    12481385                                *(u_char *)bptr++ = (p >> 8) & 0xff;
    12491386                                *(u_char *)bptr++ = p & 0xff;
    1250                                 ra = 0; 
     1387                                ra = 0;
    12511388                                return 1;   /* port redirected, we're done */
    1252                                 break; 
    1253                                
     1389                                break;
     1390
    12541391                         default:
    1255                                 ra = 0;                         
     1392                                ra = 0;
    12561393                        }
    12571394                        ra++;
    12581395                }
    1259                 return 1;                               
    1260                
     1396                return 1;
     1397#endif /* !VBOX */
     1398
    12611399         default:
    12621400                /* Ooops, not emulated, won't call tcp_emu again */
     
    12721410 */
    12731411int
     1412#ifdef VBOX
     1413tcp_ctl(PNATState pData, struct socket *so)
     1414#else /* !VBOX */
    12741415tcp_ctl(so)
    12751416        struct socket *so;
     1417#endif /* !VBOX */
    12761418{
    12771419        struct sbuf *sb = &so->so_snd;
     
    12801422        int do_pty;
    12811423        /*      struct socket *tmpso; */
    1282        
     1424
    12831425        DEBUG_CALL("tcp_ctl");
    12841426        DEBUG_ARG("so = %lx", (long )so);
    1285        
     1427
    12861428#if 0
    12871429        /*
     
    12931435                return 0;
    12941436        }
    1295 #endif 
     1437#endif
    12961438        command = (ntohl(so->so_faddr.s_addr) & 0xff);
    1297        
     1439
    12981440        switch(command) {
    12991441        default: /* Check for exec's */
    1300                
     1442
    13011443                /*
    13021444                 * Check if it's pty_exec
     
    13091451                        }
    13101452                }
    1311                
     1453
    13121454                /*
    13131455                 * Nothing bound..
    13141456                 */
    13151457                /* tcp_fconnect(so); */
    1316                
     1458
    13171459                /* FALLTHROUGH */
    13181460        case CTL_ALIAS:
     
    13241466        do_exec:
    13251467                DEBUG_MISC((dfd, " executing %s \n",ex_ptr->ex_exec));
     1468#ifdef VBOX
     1469                return(fork_exec(pData, so, ex_ptr->ex_exec, do_pty));
     1470#else /* !VBOX */
    13261471                return(fork_exec(so, ex_ptr->ex_exec, do_pty));
    1327                
     1472#endif /* !VBOX */
     1473
    13281474#if 0
    13291475        case CTL_CMD:
    13301476           for (tmpso = tcb.so_next; tmpso != &tcb; tmpso = tmpso->so_next) {
    1331              if (tmpso->so_emu == EMU_CTL && 
    1332                  !(tmpso->so_tcpcb? 
     1477             if (tmpso->so_emu == EMU_CTL &&
     1478                 !(tmpso->so_tcpcb?
    13331479                   (tmpso->so_tcpcb->t_state & (TCPS_TIME_WAIT|TCPS_LAST_ACK))
    13341480                   :0)) {
     
    13501496
    13511497#if defined(VBOX) && SIZEOF_CHAR_P != 4
    1352 /** Hash table used for translating pointers to unique uint32_t entries. 
     1498/** Hash table used for translating pointers to unique uint32_t entries.
    13531499* The 0 entry is reserved for NULL pointers. */
    13541500void       *g_apvHash[16384];
     
    13771523        else
    13781524        {
    1379             /* 
    1380              * Try up to 10 times then assume it's an insertion. 
    1381              * If we didn't find a free entry by then, try another 100 times. 
     1525            /*
     1526             * Try up to 10 times then assume it's an insertion.
     1527             * If we didn't find a free entry by then, try another 100 times.
    13821528             * If that fails, give up.
    13831529             */
     
    13911537            {
    13921538                /* check if we should give in.*/
    1393                 if (--cTries > 0) 
     1539                if (--cTries > 0)
    13941540                {
    13951541                    if (i1stFree != 0)
     
    14051551                    if (!cTries2)
    14061552                    {
    1407                         AssertReleaseMsgFailed(("NAT pointer hash error. pv=%p g_cpvHashUsed=%d g_cpvHashCollisions=%u\n", 
     1553                        AssertReleaseMsgFailed(("NAT pointer hash error. pv=%p g_cpvHashUsed=%d g_cpvHashCollisions=%u\n",
    14081554                                                pv, g_cpvHashUsed, g_cpvHashCollisions));
    14091555                        i = 0;
     
    14521598    if (RT_UNLIKELY(g_apvHash[iHint] != pv))
    14531599    {
    1454         /* 
     1600        /*
    14551601         * Try up to 120 times then assert.
    14561602         */
     
    14691615            if (--cTries > 0)
    14701616            {
    1471                 AssertReleaseMsgFailed(("NAT pointer hash error. pv=%p g_cpvHashUsed=%u g_cpvHashCollisions=%u\n", 
     1617                AssertReleaseMsgFailed(("NAT pointer hash error. pv=%p g_cpvHashUsed=%u g_cpvHashCollisions=%u\n",
    14721618                                        pv, g_cpvHashUsed, g_cpvHashCollisions));
    14731619                return;
     
    14811627}
    14821628
    1483 #endif 
     1629#endif
  • trunk/src/VBox/Devices/Network/slirp/tcp_timer.c

    r1 r1033  
    3737#include <slirp.h>
    3838
     39#ifndef VBOX
    3940int     tcp_keepidle = TCPTV_KEEP_IDLE;
    4041int     tcp_keepintvl = TCPTV_KEEPINTVL;
     
    4445struct   tcpstat tcpstat;        /* tcp statistics */
    4546u_int32_t        tcp_now;                /* for RFC 1323 timestamps */
     47#endif /* !VBOX */
    4648
    4749/*
     
    4951 */
    5052void
     53#ifdef VBOX
     54tcp_fasttimo(PNATState pData)
     55#else /* !VBOX */
    5156tcp_fasttimo()
     57#endif /* !VBOX */
    5258{
    5359        register struct socket *so;
     
    5561
    5662        DEBUG_CALL("tcp_fasttimo");
    57        
     63
    5864        so = tcb.so_next;
    5965        if (so)
     
    6470                        tp->t_flags |= TF_ACKNOW;
    6571                        tcpstat.tcps_delack++;
     72#ifdef VBOX
     73                        (void) tcp_output(pData, tp);
     74#else /*! VBOX */
    6675                        (void) tcp_output(tp);
     76#endif /* !VBOX */
    6777                }
    6878}
     
    7484 */
    7585void
     86#ifdef VBOX
     87tcp_slowtimo(PNATState pData)
     88#else /* !VBOX */
    7689tcp_slowtimo()
     90#endif /* !VBOX */
    7791{
    7892        register struct socket *ip, *ipnxt;
     
    8195
    8296        DEBUG_CALL("tcp_slowtimo");
    83        
     97
     98#ifndef VBOX
    8499        tcp_maxidle = TCPTV_KEEPCNT * tcp_keepintvl;
     100#endif /* !VBOX */
    85101        /*
    86102         * Search through tcb's and update active timers.
     
    96112                for (i = 0; i < TCPT_NTIMERS; i++) {
    97113                        if (tp->t_timer[i] && --tp->t_timer[i] == 0) {
     114#ifdef VBOX
     115                                tcp_timers(pData, tp,i);
     116#else /* !VBOX */
    98117                                tcp_timers(tp,i);
     118#endif /* !VBOX */
    99119                                if (ipnxt->so_prev != ip)
    100120                                        goto tpgone;
     
    128148}
    129149
     150#ifdef VBOX
     151const int       tcp_backoff[TCP_MAXRXTSHIFT + 1] =
     152#else /* !VBOX */
    130153int     tcp_backoff[TCP_MAXRXTSHIFT + 1] =
     154#endif /* !VBOX */
    131155   { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
    132156
     
    135159 */
    136160struct tcpcb *
     161#ifdef VBOX
     162tcp_timers(PNATState pData, register struct tcpcb *tp, int timer)
     163#else /* !VBOX */
    137164tcp_timers(tp, timer)
    138165        register struct tcpcb *tp;
    139166        int timer;
     167#endif /* !VBOX */
    140168{
    141169        register int rexmt;
    142        
     170
    143171        DEBUG_CALL("tcp_timers");
    144        
     172
    145173        switch (timer) {
    146174
     
    156184                        tp->t_timer[TCPT_2MSL] = tcp_keepintvl;
    157185                else
     186#ifdef VBOX
     187                        tp = tcp_close(pData, tp);
     188#else /* !VBOX */
    158189                        tp = tcp_close(tp);
     190#endif /* !VBOX */
    159191                break;
    160192
     
    165197         */
    166198        case TCPT_REXMT:
    167                
     199
    168200                /*
    169201                 * XXXXX If a packet has timed out, then remove all the queued
    170202                 * packets for that session.
    171203                 */
    172                
     204
    173205                if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) {
    174206                        /*
     
    179211                         * retransmitting, and eventually the connection dies...
    180212                         * (this only happens on incoming data)
    181                          * 
     213                         *
    182214                         * So, if we were gonna drop the connection from too many retransmits,
    183215                         * don't... instead halve the t_maxseg, which might break up the NULLs and
    184216                         * let them through
    185                          * 
     217                         *
    186218                         * *sigh*
    187219                         */
    188                        
     220
    189221                        tp->t_maxseg >>= 1;
    190222                        if (tp->t_maxseg < 32) {
     
    194226                                tp->t_rxtshift = TCP_MAXRXTSHIFT;
    195227                                tcpstat.tcps_timeoutdrop++;
     228#ifdef VBOX
     229                                tp = tcp_drop(pData, tp, tp->t_softerror);
     230#else /* !VBOX */
    196231                                tp = tcp_drop(tp, tp->t_softerror);
     232#endif /* !VBOX */
    197233                                /* tp->t_softerror : ETIMEDOUT); */ /* XXX */
    198234                                return (tp); /* XXX */
    199235                        }
    200                        
     236
    201237                        /*
    202238                         * Set rxtshift to 6, which is still at the maximum
     
    241277                 * window is larger than the path can handle, this
    242278                 * exponential growth results in dropped packet(s)
    243                  * almost immediately.  To get more time between 
     279                 * almost immediately.  To get more time between
    244280                 * drops but still "push" the network to take advantage
    245281                 * of improving conditions, we switch from exponential
     
    260296                tp->t_dupacks = 0;
    261297                }
     298#ifdef VBOX
     299                (void) tcp_output(pData, tp);
     300#else /* !VBOX */
    262301                (void) tcp_output(tp);
     302#endif /* !VBOX */
    263303                break;
    264304
     
    271311                tcp_setpersist(tp);
    272312                tp->t_force = 1;
     313#ifdef VBOX
     314                (void) tcp_output(pData, tp);
     315#else /* !VBOX */
    273316                (void) tcp_output(tp);
     317#endif /* !VBOX */
    274318                tp->t_force = 0;
    275319                break;
     
    309353                            tp->rcv_nxt - 1, tp->snd_una - 1, 0);
    310354#else
     355#ifdef VBOX
     356                        tcp_respond(pData, tp, &tp->t_template, (struct mbuf *)NULL,
     357                            tp->rcv_nxt, tp->snd_una - 1, 0);
     358#else /* !VBOX */
    311359                        tcp_respond(tp, &tp->t_template, (struct mbuf *)NULL,
    312360                            tp->rcv_nxt, tp->snd_una - 1, 0);
     361#endif /* !VBOX */
    313362#endif
    314363                        tp->t_timer[TCPT_KEEP] = tcp_keepintvl;
     
    319368        dropit:
    320369                tcpstat.tcps_keepdrops++;
     370#ifdef VBOX
     371                tp = tcp_drop(pData, tp, 0); /* ETIMEDOUT); */
     372#else /* !VBOX */
    321373                tp = tcp_drop(tp, 0); /* ETIMEDOUT); */
     374#endif /* !VBOX */
    322375                break;
    323376        }
  • trunk/src/VBox/Devices/Network/slirp/tcp_timer.h

    r1 r1033  
    127127}
    128128
     129#ifndef VBOX
    129130extern int tcp_keepidle;                /* time before keepalive probes begin */
    130131extern int tcp_keepintvl;               /* time between keepalive probes */
    131132extern int tcp_maxidle;                 /* time to drop after starting probes */
     133#endif /* !VBOX */
    132134extern int tcp_ttl;                     /* time to live for TCP segs */
     135#ifdef VBOX
     136extern const int tcp_backoff[];
     137#else /* !VBOX */
    133138extern int tcp_backoff[];
     139#endif /* !VBOX */
    134140
    135141struct tcpcb;
    136142
     143#ifdef VBOX
     144void tcp_fasttimo _P((PNATState));
     145void tcp_slowtimo _P((PNATState));
     146#else /* !VBOX */
    137147void tcp_fasttimo _P((void));
    138148void tcp_slowtimo _P((void));
     149#endif /* !VBOX */
    139150void tcp_canceltimers _P((struct tcpcb *));
     151#ifdef VBOX
     152struct tcpcb * tcp_timers _P((PNATState, register struct tcpcb *, int));
     153#else /* !VBOX */
    140154struct tcpcb * tcp_timers _P((register struct tcpcb *, int));
     155#endif /* !VBOX */
    141156
    142157#endif
  • trunk/src/VBox/Devices/Network/slirp/tcp_var.h

    r530 r1033  
    5050 typedef u_int32_t tcpiphdrp_32;
    5151# ifdef VBOX
    52 #  include <iprt/types.h> 
     52#  include <iprt/types.h>
    5353#  include <iprt/assert.h>
    5454
    5555   /* VBox change that's to much bother to #ifdef. */
    56 #  define u32ptr_done(u32, ptr) VBoxU32PtrDone((ptr), (u32))   
     56#  define u32ptr_done(u32, ptr) VBoxU32PtrDone((ptr), (u32))
    5757#  define ptr_to_u32(ptr)       VBoxU32PtrHash((ptr))
    5858#  define u32_to_ptr(u32, type) ((type)VBoxU32PtrLookup(u32))
     
    6262    extern void     VBoxU32PtrDone(void *pv, uint32_t iHint);
    6363    extern uint32_t VBoxU32PtrHashSlow(void *pv);
    64    
     64
    6565    /** Hash the pointer, inserting it if need be. */
    6666    DECLINLINE(uint32_t) VBoxU32PtrHash(void *pv)
     
    7777        Assert(i < RT_ELEMENTS(g_apvHash));
    7878        pv = g_apvHash[i];
    79         Assert(pv || !i); 
     79        Assert(pv || !i);
    8080        return pv;
    8181    }
     
    238238 * but that's inconvenient at the moment.
    239239 */
     240#ifdef VBOX
     241struct tcpstat_t {
     242#else /* !VBOX */
    240243struct tcpstat {
     244#endif /* !VBOX */
    241245        u_long  tcps_connattempt;       /* connections initiated */
    242246        u_long  tcps_accepts;           /* connections accepted */
     
    294298};
    295299
     300#ifndef VBOX
    296301extern struct   tcpstat tcpstat;        /* tcp statistics */
    297302extern u_int32_t        tcp_now;                /* for RFC 1323 timestamps */
     303#endif /* !VBOX */
    298304
    299305#endif
  • trunk/src/VBox/Devices/Network/slirp/tftp.c

    r1023 r1033  
    11/*
    22 * tftp.c - a simple, read-only tftp server for qemu
    3  * 
     3 *
    44 * Copyright (c) 2004 Magnus Damm <[email protected]>
    5  * 
     5 *
    66 * Permission is hereby granted, free of charge, to any person obtaining a copy
    77 * of this software and associated documentation files (the "Software"), to deal
     
    2525#include <slirp.h>
    2626
     27#ifndef VBOX
    2728struct tftp_session {
    2829    int in_use;
    2930    unsigned char filename[TFTP_FILENAME_MAX];
    30    
     31
    3132    struct in_addr client_ip;
    3233    u_int16_t client_port;
    33    
     34
    3435    int timestamp;
    3536};
     
    3839
    3940const char *tftp_prefix;
    40 
     41#endif /* !VBOX */
     42
     43#ifdef VBOX
     44static void tftp_session_update(PNATState pData, struct tftp_session *spt)
     45#else /* !VBOX */
    4146static void tftp_session_update(struct tftp_session *spt)
     47#endif /* !VBOX */
    4248{
    4349    spt->timestamp = curtime;
     
    5056}
    5157
     58#ifdef VBOX
     59static int tftp_session_allocate(PNATState pData, struct tftp_t *tp)
     60#else /* !VBOX */
    5261static int tftp_session_allocate(struct tftp_t *tp)
     62#endif /* !VBOX */
    5363{
    5464  struct tftp_session *spt;
     
    7383  spt->client_port = tp->udp.uh_sport;
    7484
     85#ifdef VBOX
     86  tftp_session_update(pData, spt);
     87#else /* !VBOX */
    7588  tftp_session_update(spt);
     89#endif /* !VBOX */
    7690
    7791  return k;
    7892}
    7993
     94#ifdef VBOX
     95static int tftp_session_find(PNATState pData, struct tftp_t *tp)
     96#else /* !VBOX */
    8097static int tftp_session_find(struct tftp_t *tp)
     98#endif /* !VBOX */
    8199{
    82100  struct tftp_session *spt;
     
    98116}
    99117
     118#ifdef VBOX
     119static int tftp_read_data(PNATState pData, struct tftp_session *spt, u_int16_t block_nr,
     120                          u_int8_t *buf, int len)
     121#else /* !VBOX */
    100122static int tftp_read_data(struct tftp_session *spt, u_int16_t block_nr,
    101123                          u_int8_t *buf, int len)
     124#endif /* !VBOX */
    102125{
    103126  int fd;
     
    133156}
    134157
    135 static int tftp_send_oack(struct tftp_session *spt,
     158#ifdef VBOX
     159static int tftp_send_oack(PNATState pData,
     160                          struct tftp_session *spt,
    136161                          const char *key, uint32_t value,
    137162                          struct tftp_t *recv_tp)
     163#else /* !VBOX */
     164static int tftp_send_oack(struct tftp_session *spt,
     165                          const char *key, uint32_t value,
     166                          struct tftp_t *recv_tp)
     167#endif /* !VBOX */
    138168{
    139169    struct sockaddr_in saddr, daddr;
     
    142172    int n = 0;
    143173
     174#ifdef VBOX
     175    m = m_get(pData);
     176#else /* !VBOX */
    144177    m = m_get();
     178#endif /* !VBOX */
    145179
    146180    if (!m)
     
    152186    tp = (void *)m->m_data;
    153187    m->m_data += sizeof(struct udpiphdr);
    154    
     188
    155189    tp->tp_op = htons(TFTP_OACK);
     190#ifdef VBOX
     191    n += sprintf((char *)tp->x.tp_buf + n, "%s", key) + 1;
     192    n += sprintf((char *)tp->x.tp_buf + n, "%u", value) + 1;
     193#else /* !VBOX */
    156194    n += sprintf(tp->x.tp_buf + n, "%s", key) + 1;
    157195    n += sprintf(tp->x.tp_buf + n, "%u", value) + 1;
     196#endif /* !VBOX */
    158197
    159198    saddr.sin_addr = recv_tp->ip.ip_dst;
    160199    saddr.sin_port = recv_tp->udp.uh_dport;
    161    
     200
    162201    daddr.sin_addr = spt->client_ip;
    163202    daddr.sin_port = spt->client_port;
    164203
    165     m->m_len = sizeof(struct tftp_t) - 514 + n - 
     204    m->m_len = sizeof(struct tftp_t) - 514 + n -
    166205        sizeof(struct ip) - sizeof(struct udphdr);
     206#ifdef VBOX
     207    udp_output2(pData, NULL, m, &saddr, &daddr, IPTOS_LOWDELAY);
     208#else /* !VBOX */
    167209    udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY);
     210#endif /* !VBOX */
    168211
    169212    return 0;
     
    172215
    173216
    174 static int tftp_send_error(struct tftp_session *spt,
     217#ifdef VBOX
     218static int tftp_send_error(PNATState pData,
     219                           struct tftp_session *spt,
    175220                           u_int16_t errorcode, const char *msg,
    176221                           struct tftp_t *recv_tp)
     222#else /* !VBOX */
     223static int tftp_send_error(struct tftp_session *spt,
     224                           u_int16_t errorcode, const char *msg,
     225                           struct tftp_t *recv_tp)
     226#endif /* !VBOX */
    177227{
    178228  struct sockaddr_in saddr, daddr;
     
    181231  int nobytes;
    182232
     233#ifdef VBOX
     234  m = m_get(pData);
     235#else /* !VBOX */
    183236  m = m_get();
     237#endif /* !VBOX */
    184238
    185239  if (!m) {
     
    192246  tp = (void *)m->m_data;
    193247  m->m_data += sizeof(struct udpiphdr);
    194  
     248
    195249  tp->tp_op = htons(TFTP_ERROR);
    196250  tp->x.tp_error.tp_error_code = htons(errorcode);
     
    209263  nobytes = 2;
    210264
    211   m->m_len = sizeof(struct tftp_t) - 514 + 3 + strlen(msg) - 
     265  m->m_len = sizeof(struct tftp_t) - 514 + 3 + strlen(msg) -
    212266        sizeof(struct ip) - sizeof(struct udphdr);
    213267
     268#ifdef VBOX
     269  udp_output2(pData, NULL, m, &saddr, &daddr, IPTOS_LOWDELAY);
     270#else /* !VBOX */
    214271  udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY);
     272#endif /* !VBOX */
    215273
    216274  tftp_session_terminate(spt);
     
    219277}
    220278
    221 static int tftp_send_data(struct tftp_session *spt,
     279#ifdef VBOX
     280static int tftp_send_data(PNATState pData,
     281                          struct tftp_session *spt,
    222282                          u_int16_t block_nr,
    223283                          struct tftp_t *recv_tp)
     284#else /* !VBOX */
     285static int tftp_send_data(struct tftp_session *spt,
     286                          u_int16_t block_nr,
     287                          struct tftp_t *recv_tp)
     288#endif /* !VBOX */
    224289{
    225290  struct sockaddr_in saddr, daddr;
     
    232297  }
    233298
     299#ifdef VBOX
     300  m = m_get(pData);
     301#else /* !VBOX */
    234302  m = m_get();
     303#endif /* !VBOX */
    235304
    236305  if (!m) {
     
    243312  tp = (void *)m->m_data;
    244313  m->m_data += sizeof(struct udpiphdr);
    245  
     314
    246315  tp->tp_op = htons(TFTP_DATA);
    247316  tp->x.tp_data.tp_block_nr = htons(block_nr);
     
    253322  daddr.sin_port = spt->client_port;
    254323
     324#ifdef VBOX
     325  nobytes = tftp_read_data(pData, spt, block_nr - 1, tp->x.tp_data.tp_buf, 512);
     326#else /* !VBOX */
    255327  nobytes = tftp_read_data(spt, block_nr - 1, tp->x.tp_data.tp_buf, 512);
     328#endif /* !VBOX */
    256329
    257330  if (nobytes < 0) {
     331#ifdef VBOX
     332    m_free(pData, m);
     333#else /* !VBOX */
    258334    m_free(m);
     335#endif /* !VBOX */
    259336
    260337    /* send "file not found" error back */
    261338
     339#ifdef VBOX
     340    tftp_send_error(pData, spt, 1, "File not found", tp);
     341#else /* !VBOX */
    262342    tftp_send_error(spt, 1, "File not found", tp);
     343#endif /* !VBOX */
    263344
    264345    return -1;
    265346  }
    266347
    267   m->m_len = sizeof(struct tftp_t) - (512 - nobytes) - 
     348  m->m_len = sizeof(struct tftp_t) - (512 - nobytes) -
    268349        sizeof(struct ip) - sizeof(struct udphdr);
    269350
     351#ifdef VBOX
     352  udp_output2(pData, NULL, m, &saddr, &daddr, IPTOS_LOWDELAY);
     353#else /* !VBOX */
    270354  udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY);
     355#endif /* !VBOX */
    271356
    272357  if (nobytes == 512) {
     358#ifdef VBOX
     359    tftp_session_update(pData, spt);
     360#else /* !VBOX */
    273361    tftp_session_update(spt);
     362#endif /* !VBOX */
    274363  }
    275364  else {
     
    280369}
    281370
     371#ifdef VBOX
     372static void tftp_handle_rrq(PNATState pData, struct tftp_t *tp, int pktlen)
     373#else /* !VBOX */
    282374static void tftp_handle_rrq(struct tftp_t *tp, int pktlen)
     375#endif /* !VBOX */
    283376{
    284377  struct tftp_session *spt;
     
    286379  u_int8_t *src, *dst;
    287380
     381#ifdef VBOX
     382  s = tftp_session_allocate(pData, tp);
     383#else /* !VBOX */
    288384  s = tftp_session_allocate(tp);
     385#endif /* !VBOX */
    289386
    290387  if (s < 0) {
     
    307404      return;
    308405    }
    309    
     406
    310407    if (src[k] == '\0') {
    311408      break;
    312409    }
    313410  }
    314      
     411
    315412  if (k >= n) {
    316413    return;
    317414  }
    318  
     415
    319416  k++;
    320  
     417
    321418  /* check mode */
    322419  if ((n - k) < 6) {
    323420    return;
    324421  }
    325  
     422
    326423  if (memcmp(&src[k], "octet\0", 6) != 0) {
     424#ifdef VBOX
     425      tftp_send_error(pData, spt, 4, "Unsupported transfer mode", tp);
     426#else /* !VBOX */
    327427      tftp_send_error(spt, 4, "Unsupported transfer mode", tp);
     428#endif /* !VBOX */
    328429      return;
    329430  }
     
    337438      || (spt->filename[strlen(spt->filename) - 1] == '/')
    338439      ||  strstr(spt->filename, "/../")) {
     440      tftp_send_error(spt, 2, "Access violation", tp);
    339441#else /* VBOX */
    340442  if ((spt->filename[0] != '/')
    341443      || (spt->filename[strlen((const char *)spt->filename) - 1] == '/')
    342444      ||  strstr((char *)spt->filename, "/../")) {
     445      tftp_send_error(pData, spt, 2, "Access violation", tp);
    343446#endif /* VBOX */
     447      return;
     448  }
     449
     450  /* only allow exported prefixes */
     451
     452  if (!tftp_prefix) {
     453#ifdef VBOX
     454      tftp_send_error(pData, spt, 2, "Access violation", tp);
     455#else /* !VBOX */
    344456      tftp_send_error(spt, 2, "Access violation", tp);
     457#endif /* !VBOX */
    345458      return;
    346459  }
    347460
    348   /* only allow exported prefixes */
    349 
    350   if (!tftp_prefix) {
    351       tftp_send_error(spt, 2, "Access violation", tp);
    352       return;
    353   }
    354 
    355461  /* check if the file exists */
    356  
     462
     463#ifdef VBOX
     464  if (tftp_read_data(pData, spt, 0, spt->filename, 0) < 0) {
     465      tftp_send_error(pData, spt, 1, "File not found", tp);
     466#else /* !VBOX */
    357467  if (tftp_read_data(spt, 0, spt->filename, 0) < 0) {
    358468      tftp_send_error(spt, 1, "File not found", tp);
     469#endif /* !VBOX */
    359470      return;
    360471  }
    361472
    362473  if (src[n - 1] != 0) {
     474#ifdef VBOX
     475      tftp_send_error(pData, spt, 2, "Access violation", tp);
     476#else /* !VBOX */
    363477      tftp_send_error(spt, 2, "Access violation", tp);
     478#endif /* !VBOX */
    364479      return;
    365480  }
     
    368483      const char *key, *value;
    369484
     485#ifdef VBOX
     486      key = (const char *)src + k;
     487#else /* !VBOX */
    370488      key = src + k;
     489#endif /* !VBOX */
    371490      k += strlen(key) + 1;
    372491
    373492      if (k >= n) {
     493#ifdef VBOX
     494          tftp_send_error(pData, spt, 2, "Access violation", tp);
     495#else /* !VBOX */
    374496          tftp_send_error(spt, 2, "Access violation", tp);
     497#endif /* !VBOX */
    375498          return;
    376499      }
    377500
     501#ifdef VBOX
     502      value = (const char *)src + k;
     503#else /* !VBOX */
    378504      value = src + k;
     505#endif /* !VBOX */
    379506      k += strlen(value) + 1;
    380507
     
    398525                  tsize = stat_p.st_size;
    399526              else {
     527#ifdef VBOX
     528                  tftp_send_error(pData, spt, 1, "File not found", tp);
     529#else /* !VBOX */
    400530                  tftp_send_error(spt, 1, "File not found", tp);
     531#endif /* !VBOX */
    401532                  return;
    402533              }
    403534          }
    404535
     536#ifdef VBOX
     537          tftp_send_oack(pData, spt, "tsize", tsize, tp);
     538#else /* !VBOX */
    405539          tftp_send_oack(spt, "tsize", tsize, tp);
     540#endif /* !VBOX */
    406541      }
    407542  }
    408543
     544#ifdef VBOX
     545  tftp_send_data(pData, spt, 1, tp);
     546#else /* !VBOX */
    409547  tftp_send_data(spt, 1, tp);
    410 }
    411 
     548#endif /* !VBOX */
     549}
     550
     551#ifdef VBOX
     552static void tftp_handle_ack(PNATState pData, struct tftp_t *tp, int pktlen)
     553#else /* !VBOX */
    412554static void tftp_handle_ack(struct tftp_t *tp, int pktlen)
     555#endif /* !VBOX */
    413556{
    414557  int s;
    415558
     559#ifdef VBOX
     560  s = tftp_session_find(pData, tp);
     561#else /* !VBOX */
    416562  s = tftp_session_find(tp);
     563#endif /* !VBOX */
    417564
    418565  if (s < 0) {
     
    420567  }
    421568
    422   if (tftp_send_data(&tftp_sessions[s],
    423                      ntohs(tp->x.tp_data.tp_block_nr) + 1,
     569#ifdef VBOX
     570  if (tftp_send_data(pData, &tftp_sessions[s],
     571                     ntohs(tp->x.tp_data.tp_block_nr) + 1,
    424572                     tp) < 0) {
     573#else /* !VBOX */
     574  if (tftp_send_data(&tftp_sessions[s],
     575                     ntohs(tp->x.tp_data.tp_block_nr) + 1,
     576                     tp) < 0) {
     577#endif /* !VBOX */
    425578    return;
    426579  }
    427580}
    428581
     582#ifdef VBOX
     583void tftp_input(PNATState pData, struct mbuf *m)
     584#else /* !VBOX */
    429585void tftp_input(struct mbuf *m)
     586#endif /* !VBOX */
    430587{
    431588  struct tftp_t *tp = (struct tftp_t *)m->m_data;
     
    433590  switch(ntohs(tp->tp_op)) {
    434591  case TFTP_RRQ:
     592#ifdef VBOX
     593    tftp_handle_rrq(pData, tp, m->m_len);
     594#else /* !VBOX */
    435595    tftp_handle_rrq(tp, m->m_len);
     596#endif /* !VBOX */
    436597    break;
    437598
    438599  case TFTP_ACK:
     600#ifdef VBOX
     601    tftp_handle_ack(pData, tp, m->m_len);
     602#else /* !VBOX */
    439603    tftp_handle_ack(tp, m->m_len);
     604#endif /* !VBOX */
    440605    break;
    441606  }
  • trunk/src/VBox/Devices/Network/slirp/tftp.h

    r1016 r1033  
    1919  u_int16_t tp_op;
    2020  union {
    21     struct { 
     21    struct {
    2222      u_int16_t tp_block_nr;
    2323      u_int8_t tp_buf[512];
    2424    } tp_data;
    25     struct { 
     25    struct {
    2626      u_int16_t tp_error_code;
    2727      u_int8_t tp_msg[512];
     
    3131};
    3232
     33#ifdef VBOX
     34void tftp_input(PNATState pData, struct mbuf *m);
     35#else /* !VBOX */
    3336void tftp_input(struct mbuf *m);
     37#endif /* !VBOX */
  • trunk/src/VBox/Devices/Network/slirp/udp.c

    r1022 r1033  
    4646#include "ip_icmp.h"
    4747
     48#ifndef VBOX
    4849struct udpstat udpstat;
    4950
    5051struct socket udb;
     52#endif /* !VBOX */
    5153
    5254/*
     
    5456 * Per RFC 768, August, 1980.
    5557 */
     58#ifdef VBOX
     59#define udpcksum 1
     60#else /* !VBOX */
    5661#ifndef COMPAT_42
    5762int     udpcksum = 1;
     
    5964int     udpcksum = 0;           /* XXX */
    6065#endif
    61 
     66#endif /* !VBOX */
     67
     68#ifndef VBOX
    6269struct  socket *udp_last_so = &udb;
     70#endif /* !VBOX */
    6371
    6472void
     73#ifdef VBOX
     74udp_init(PNATState pData)
     75#else /* !VBOX */
    6576udp_init()
    66 {
     77#endif /* !VBOX */
     78{
     79#ifdef VBOX
     80        udp_last_so = &udb;
     81#endif /* VBOX */
    6782        udb.so_next = udb.so_prev = &udb;
    6883}
     
    7287 */
    7388void
     89#ifdef VBOX
     90udp_input(PNATState pData, register struct mbuf *m, int iphlen)
     91#else /* !VBOX */
    7492udp_input(m, iphlen)
    7593        register struct mbuf *m;
    7694        int iphlen;
     95#endif /* !VBOX */
    7796{
    7897        register struct ip *ip;
     
    150169         */
    151170        if (ntohs(uh->uh_dport) == BOOTP_SERVER) {
     171#ifdef VBOX
     172            bootp_input(pData, m);
     173#else /* !VBOX */
    152174            bootp_input(m);
     175#endif /* !VBOX */
    153176            goto bad;
    154177        }
     
    158181         */
    159182        if (ntohs(uh->uh_dport) == TFTP_SERVER) {
     183#ifdef VBOX
     184            tftp_input(pData, m);
     185#else /* !VBOX */
    160186            tftp_input(m);
     187#endif /* !VBOX */
    161188            goto bad;
    162189        }
     
    195222           */
    196223          if ((so = socreate()) == NULL) goto bad;
     224#ifdef VBOX
     225          if(udp_attach(pData, so) == -1) {
     226#else /* !VBOX */
    197227          if(udp_attach(so) == -1) {
     228#endif /* !VBOX */
    198229            DEBUG_MISC((dfd," udp_attach errno = %d-%s\n",
    199230                        errno,strerror(errno)));
     231#ifdef VBOX
     232            sofree(pData, so);
     233#else /* !VBOX */
    200234            sofree(so);
     235#endif /* !VBOX */
    201236            goto bad;
    202237          }
     
    229264         */
    230265        if (so->so_emu)
     266#ifdef VBOX
     267           udp_emu(pData, so, m);
     268#else /* !VBOX */
    231269           udp_emu(so, m);
    232 
     270#endif /* !VBOX */
     271
     272#ifdef VBOX
     273        if(sosendto(pData, so,m) == -1) {
     274#else /* !VBOX */
    233275        if(sosendto(so,m) == -1) {
     276#endif /* !VBOX */
    234277          m->m_len += iphlen;
    235278          m->m_data -= iphlen;
    236279          *ip=save_ip;
    237280          DEBUG_MISC((dfd,"udp tx errno = %d-%s\n",errno,strerror(errno)));
     281#ifdef VBOX
     282          icmp_error(pData, m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno));
     283#else /* !VBOX */
    238284          icmp_error(m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno));
    239         }
    240 
     285#endif /* !VBOX */
     286        }
     287
     288#ifdef VBOX
     289        m_free(pData, so->so_m);   /* used for ICMP if error on sorecvfrom */
     290#else /* !VBOX */
    241291        m_free(so->so_m);   /* used for ICMP if error on sorecvfrom */
     292#endif /* !VBOX */
    242293
    243294        /* restore the orig mbuf packet */
     
    249300        return;
    250301bad:
     302#ifdef VBOX
     303        m_freem(pData, m);
     304#else /* !VBOX */
    251305        m_freem(m);
     306#endif /* !VBOX */
    252307        /* if (opts) m_freem(opts); */
    253308        return;
    254309}
    255310
     311#ifdef VBOX
     312int udp_output2(PNATState pData, struct socket *so, struct mbuf *m,
     313                struct sockaddr_in *saddr, struct sockaddr_in *daddr,
     314                int iptos)
     315#else /* !VBOX */
    256316int udp_output2(struct socket *so, struct mbuf *m,
    257317                struct sockaddr_in *saddr, struct sockaddr_in *daddr,
    258318                int iptos)
     319#endif /* !VBOX */
    259320{
    260321        register struct udpiphdr *ui;
     
    304365        udpstat.udps_opackets++;
    305366
     367#ifdef VBOX
     368        error = ip_output(pData, so, m);
     369#else /* !VBOX */
    306370        error = ip_output(so, m);
     371#endif /* !VBOX */
    307372
    308373        return (error);
    309374}
    310375
     376#ifdef VBOX
     377int udp_output(PNATState pData, struct socket *so, struct mbuf *m,
     378               struct sockaddr_in *addr)
     379#else /* !VBOX */
    311380int udp_output(struct socket *so, struct mbuf *m,
    312381               struct sockaddr_in *addr)
    313 
     382#endif /* !VBOX */
    314383{
    315384    struct sockaddr_in saddr, daddr;
     
    324393    daddr.sin_port = so->so_lport;
    325394
     395#ifdef VBOX
     396    return udp_output2(pData, so, m, &saddr, &daddr, so->so_iptos);
     397#else /* !VBOX */
    326398    return udp_output2(so, m, &saddr, &daddr, so->so_iptos);
     399#endif /* !VBOX */
    327400}
    328401
    329402int
     403#ifdef VBOX
     404udp_attach(PNATState pData, struct socket *so)
     405#else /* !VBOX */
    330406udp_attach(so)
    331407     struct socket *so;
     408#endif /* !VBPX */
    332409{
    333410  struct sockaddr_in addr;
     
    354431      /* success, insert in queue */
    355432      so->so_expire = curtime + SO_EXPIRE;
     433      so->so_expire = curtime + SO_EXPIRE;
    356434      insque(so,&udb);
    357435    }
     
    361439
    362440void
     441#ifdef VBOX
     442udp_detach(PNATState pData, struct socket *so)
     443#else /* !VBOX */
    363444udp_detach(so)
    364445        struct socket *so;
     446#endif /* !VBOX */
    365447{
    366448#ifdef VBOX
     
    371453        /* if (so->so_m) m_free(so->so_m);    done by sofree */
    372454
     455#ifdef VBOX
     456        sofree(pData, so);
     457#else /* !VBOX */
    373458        sofree(so);
    374 }
    375 
     459#endif /* !VBOX */
     460}
     461
     462#ifdef VBOX
     463static const struct tos_t udptos[] = {
     464#else /* !VBOX */
    376465struct tos_t udptos[] = {
     466#endif /* !VBOX */
    377467        {0, 53, IPTOS_LOWDELAY, 0},                     /* DNS */
    378468        {517, 517, IPTOS_LOWDELAY, EMU_TALK},   /* talk */
     
    408498 */
    409499void
     500#ifdef VBOX
     501udp_emu(PNATState pData, struct socket *so, struct mbuf *m)
     502#else /* !VBOX */
    410503udp_emu(so, m)
    411504        struct socket *so;
    412505        struct mbuf *m;
     506#endif /* !VBOX */
    413507{
    414508        struct sockaddr_in addr;
     
    640734
    641735struct socket *
     736#ifdef VBOX
     737udp_listen(PNATState pData, u_int port, u_int32_t laddr, u_int lport, int flags)
     738#else /* !VBOX */
    642739udp_listen(port, laddr, lport, flags)
    643740        u_int port;
     
    645742        u_int lport;
    646743        int flags;
     744#endif /* !VBOX */
    647745{
    648746        struct sockaddr_in addr;
     
    668766
    669767        if (bind(so->s,(struct sockaddr *)&addr, addrlen) < 0) {
     768#ifdef VBOX
     769                udp_detach(pData, so);
     770#else /* !VBOX */
    670771                udp_detach(so);
     772#endif /* !VBOX */
    671773                return NULL;
    672774        }
  • trunk/src/VBox/Devices/Network/slirp/udp.h

    r1 r1033  
    7373#define ui_sum          ui_u.uh_sum
    7474
     75#ifdef VBOX
     76struct udpstat_t {
     77#else /* !VBOX */
    7578struct udpstat {
     79#endif /* !VBOX */
    7680                                        /* input statistics: */
    7781                u_long  udps_ipackets;          /* total input packets */
     
    97101struct mbuf;
    98102
     103#ifdef VBOX
     104void udp_init _P((PNATState));
     105void udp_input _P((PNATState, register struct mbuf *, int));
     106int udp_output _P((PNATState, struct socket *, struct mbuf *, struct sockaddr_in *));
     107int udp_attach _P((PNATState, struct socket *));
     108void udp_detach _P((PNATState, struct socket *));
     109#else /* !VBOX */
    99110void udp_init _P((void));
    100111void udp_input _P((register struct mbuf *, int));
     
    102113int udp_attach _P((struct socket *));
    103114void udp_detach _P((struct socket *));
     115#endif /* !VBOX */
    104116u_int8_t udp_tos _P((struct socket *));
     117#ifdef VBOX
     118#else /* !VBOX */
     119#endif /* !VBOX */
     120#ifdef VBOX
     121void udp_emu _P((PNATState, struct socket *, struct mbuf *));
     122struct socket * udp_listen _P((PNATState, u_int, u_int32_t, u_int, int));
     123int udp_output2(PNATState pData, struct socket *so, struct mbuf *m,
     124                struct sockaddr_in *saddr, struct sockaddr_in *daddr,
     125                int iptos);
     126#else /* !VBOX */
    105127void udp_emu _P((struct socket *, struct mbuf *));
    106128struct socket * udp_listen _P((u_int, u_int32_t, u_int, int));
    107 int udp_output2(struct socket *so, struct mbuf *m, 
     129int udp_output2(struct socket *so, struct mbuf *m,
    108130                struct sockaddr_in *saddr, struct sockaddr_in *daddr,
    109131                int iptos);
     132#endif /* !VBOX */
     133
    110134#endif
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette