Changeset 13967 in vbox
- Timestamp:
- Nov 7, 2008 3:16:56 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DrvNAT.cpp
r13951 r13967 28 28 #define __STDC_LIMIT_MACROS 29 29 #define __STDC_CONSTANT_MACROS 30 #ifndef VBOX_NAT_SOURCES31 30 #include "Network/slirp/libslirp.h" 32 #else33 #include <sys/types.h>34 #include <sys/socket.h>35 36 #include <netinet/in.h>37 38 #include <errno.h>39 40 #include <unistd.h>41 42 #include <fcntl.h>43 44 #include <string.h>45 46 #endif47 31 #include <VBox/pdmdrv.h> 48 32 #include <iprt/assert.h> … … 53 37 54 38 #include "Builtins.h" 55 56 #ifdef VBOX_NAT_SOURCES57 #include "Network/nat/nat.h"58 #endif59 39 60 40 #ifdef VBOX_WITH_SYNC_SLIRP … … 86 66 PDMNETWORKLINKSTATE enmLinkState; 87 67 /** NAT state for this instance. */ 88 #ifndef VBOX_NAT_SOURCES89 68 PNATState pNATState; 90 #endif91 69 /** TFTP directory prefix. */ 92 70 char *pszTFTPPrefix; … … 97 75 PPDMTHREAD pThread; 98 76 /*used for wakep of poling thread*/ 99 RTSEMEVENT 100 PTMTIMER 101 PTMTIMER 77 RTSEMEVENT semIOmutex; 78 PTMTIMER pNATFastTimer; 79 PTMTIMER pNATSlowTimer; 102 80 /** The write end of the control pipe. */ 103 81 RTFILE PipeWrite; … … 127 105 128 106 129 #ifdef VBOX_NAT_SOURCES130 /*131 * Sends data to guest called from NAT glue code132 */133 static DECLCALLBACK(void) drvNATOutput(const void * data, const uint8_t *msg, int size)134 {135 PDRVNAT pThis = (PDRVNAT)(void *)data;136 LogFlow(("output: pvBuf=%p cb=%#x\n", msg, size));137 int rc = pThis->pPort->pfnWaitReceiveAvail(pThis->pPort, 0);138 if (RT_SUCCESS(rc))139 pThis->pPort->pfnReceive(pThis->pPort, msg, size);140 LogFlow(("output: exit\n"));141 }142 143 #endif144 145 107 /** 146 108 * Send data to the network. … … 168 130 Assert(pThis->enmLinkState == PDMNETWORKLINKSTATE_UP); 169 131 if (pThis->enmLinkState == PDMNETWORKLINKSTATE_UP) { 170 #ifndef VBOX_NAT_SOURCES171 132 slirp_input(pThis->pNATState, (uint8_t *)pvBuf, cb); 172 #else173 ether_chk(pThis, pvBuf, cb);174 #endif175 133 } 176 134 #ifndef VBOX_WITH_SYNC_SLIRP … … 232 190 case PDMNETWORKLINKSTATE_UP: 233 191 LogRel(("NAT: link up\n")); 234 #ifndef VBOX_NAT_SOURCES235 192 slirp_link_up(pThis->pNATState); 236 #endif237 193 break; 238 194 … … 240 196 case PDMNETWORKLINKSTATE_DOWN_RESUME: 241 197 LogRel(("NAT: link down\n")); 242 #ifndef VBOX_NAT_SOURCES243 198 slirp_link_down(pThis->pNATState); 244 #endif245 199 break; 246 200 … … 272 226 AssertReleaseRC(rc); 273 227 274 #ifndef VBOX_NAT_SOURCES275 228 slirp_select_fill(pThis->pNATState, &cFDs, &ReadFDs, &WriteFDs, &XcptFDs); 276 #else277 nat_select_fill(NULL, &cFDs, &ReadFDs, &WriteFDs, &XcptFDs);278 #endif279 229 280 230 struct timeval tv = {0, 0}; /* no wait */ 281 231 int cReadFDs = select(cFDs + 1, &ReadFDs, &WriteFDs, &XcptFDs, &tv); 282 #ifndef VBOX_NAT_SOURCES283 232 if (cReadFDs >= 0) 284 233 slirp_select_poll(pThis->pNATState, &ReadFDs, &WriteFDs, &XcptFDs); 285 #else286 if (cReadFDs >= 0) {287 nat_select_poll(pThis, &ReadFDs, &WriteFDs, &XcptFDs);288 }289 #endif290 234 291 235 RTCritSectLeave(&pThis->CritSect); … … 308 252 TMTimerSetMicro(pTimer, 500); 309 253 } 254 310 255 static DECLCALLBACK(int) drvNATAsyncIoThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread) 311 256 { … … 318 263 319 264 LogFlow(("drvNATAsyncIoThread: pThis=%p\n", pThis)); 320 321 265 322 266 if (pThread->enmState == PDMTHREADSTATE_INITIALIZING) … … 386 330 #endif 387 331 388 #ifndef VBOX_NAT_SOURCES389 332 /** 390 333 * Function called by slirp to check if it's possible to feed incoming data to the network port. … … 434 377 LogFlow(("slirp_output END %x %d\n", pu8Buf, cb)); 435 378 } 436 #endif437 379 438 380 /** … … 477 419 int rc = RTCritSectEnter(&pThis->CritSect); 478 420 AssertReleaseRC(rc); 479 #ifndef VBOX_NAT_SOURCES480 421 slirp_term(pThis->pNATState); 481 422 pThis->pNATState = NULL; 482 #endif483 423 RTCritSectLeave(&pThis->CritSect); 484 424 … … 495 435 static int drvNATConstructRedir(unsigned iInstance, PDRVNAT pThis, PCFGMNODE pCfgHandle, RTIPV4ADDR Network) 496 436 { 497 #ifndef VBOX_NAT_SOURCES498 437 /* 499 438 * Enumerate redirections. … … 562 501 return PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_NAT_REDIR_SETUP, RT_SRC_POS, N_("NAT#%d: configuration error: failed to set up redirection of %d to %s:%d. Probably a conflict with existing services or other rules"), iInstance, iHostPort, szGuestIP, iGuestPort); 563 502 } /* for each redir rule */ 564 #endif565 503 566 504 return VINF_SUCCESS; … … 572 510 static void drvNATSetMac(PDRVNAT pThis) 573 511 { 574 #ifndef VBOX_NAT_SOURCES575 512 if (pThis->pConfig) 576 513 { … … 579 516 slirp_set_ethaddr(pThis->pNATState, Mac.au8); 580 517 } 581 #endif582 518 } 583 519 … … 633 569 */ 634 570 pThis->pDrvIns = pDrvIns; 635 #ifndef VBOX_NAT_SOURCES636 571 pThis->pNATState = NULL; 637 #endif638 572 pThis->pszTFTPPrefix = NULL; 639 573 pThis->pszBootFile = NULL; … … 708 642 { 709 643 #endif 710 #ifndef VBOX_NAT_SOURCES711 644 /* 712 645 * Initialize slirp. … … 774 707 AssertMsgFailed(("Add error message for rc=%d (%Rrc)\n", rc, rc)); 775 708 } 776 #else777 pDrvIns->pDrvHlp->pfnPDMPollerRegister(pDrvIns, drvNATPoller);778 pThis->enmLinkState = PDMNETWORKLINKSTATE_UP;779 struct nat_output_callbacks cb;780 cb.noc_guest_out = drvNATOutput;781 nat_init(&cb, pDrvIns);782 #endif783 709 #if 0 784 710 g_fThreadTerm = true; … … 790 716 } 791 717 #endif 792 #ifndef VBOX_NAT_SOURCES793 718 RTCritSectDelete(&pThis->CritSect); 794 #endif795 719 return rc; 796 720 }
Note:
See TracChangeset
for help on using the changeset viewer.