Changeset 11170 in vbox for trunk/src/VBox/Devices/Network
- Timestamp:
- Aug 6, 2008 1:45:50 AM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 34164
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DrvNAT.cpp
r11157 r11170 28 28 #define __STDC_LIMIT_MACROS 29 29 #define __STDC_CONSTANT_MACROS 30 #ifndef VBOX_NAT_SOURCES 30 31 #include "Network/slirp/libslirp.h" 32 #else 33 #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 #include "Network/nat/nat.h" 47 #endif 31 48 #include <VBox/pdmdrv.h> 32 49 #include <iprt/assert.h> … … 60 77 PDMNETWORKLINKSTATE enmLinkState; 61 78 /** NAT state for this instance. */ 79 #ifndef VBOX_NAT_SOURCES 62 80 PNATState pNATState; 81 #endif 63 82 /** TFTP directory prefix. */ 64 83 char *pszTFTPPrefix; … … 82 101 83 102 103 /******************************************************************************* 104 * Internal Functions * 105 *******************************************************************************/ 106 107 108 #ifdef VBOX_NAT_SOURCES 109 /* 110 * Sends data to guest called from NAT glue code 111 */ 112 static DECLCALLBACK(void) drvNATOutput(const void * data, const uint8_t *msg, size_t size) 113 { 114 PDRVNAT pData = (PDRVNAT)(void *)data; 115 LogFlow(("output: pvBuf=%p cb=%#x\n", msg, size)); 116 int rc = pData->pPort->pfnWaitReceiveAvail(pData->pPort, 0); 117 if (RT_SUCCESS(rc)) 118 pData->pPort->pfnReceive(pData->pPort, msg, size); 119 LogFlow(("output: exit\n")); 120 } 121 122 #endif 123 84 124 /** 85 125 * Send data to the network. … … 104 144 105 145 Assert(pData->enmLinkState == PDMNETWORKLINKSTATE_UP); 106 if (pData->enmLinkState == PDMNETWORKLINKSTATE_UP) 146 if (pData->enmLinkState == PDMNETWORKLINKSTATE_UP) { 147 #ifndef VBOX_NAT_SOURCES 107 148 slirp_input(pData->pNATState, (uint8_t *)pvBuf, cb); 149 #else 150 ether_chk(pData, pvBuf, cb); 151 #endif 152 } 108 153 RTCritSectLeave(&pData->CritSect); 109 154 LogFlow(("drvNATSend: end\n")); … … 150 195 case PDMNETWORKLINKSTATE_UP: 151 196 LogRel(("NAT: link up\n")); 197 #ifndef VBOX_NAT_SOURCES 152 198 slirp_link_up(pData->pNATState); 199 #endif 153 200 break; 154 201 … … 156 203 case PDMNETWORKLINKSTATE_DOWN_RESUME: 157 204 LogRel(("NAT: link down\n")); 205 #ifndef VBOX_NAT_SOURCES 158 206 slirp_link_down(pData->pNATState); 207 #endif 159 208 break; 160 209 … … 183 232 AssertReleaseRC(rc); 184 233 234 #ifndef VBOX_NAT_SOURCES 185 235 slirp_select_fill(pData->pNATState, &cFDs, &ReadFDs, &WriteFDs, &XcptFDs); 236 #else 237 nat_select_fill(NULL, &cFDs, &ReadFDs, &WriteFDs, &XcptFDs); 238 #endif 186 239 187 240 struct timeval tv = {0, 0}; /* no wait */ 188 241 int cReadFDs = select(cFDs + 1, &ReadFDs, &WriteFDs, &XcptFDs, &tv); 242 #ifndef VBOX_NAT_SOURCES 189 243 if (cReadFDs >= 0) 190 244 slirp_select_poll(pData->pNATState, &ReadFDs, &WriteFDs, &XcptFDs); 245 #else 246 if (cReadFDs >= 0) { 247 nat_select_poll(pData, &ReadFDs, &WriteFDs, &XcptFDs); 248 } 249 #endif 191 250 192 251 RTCritSectLeave(&pData->CritSect); 193 252 } 194 253 195 254 #ifndef VBOX_NAT_SOURCES 196 255 /** 197 256 * Function called by slirp to check if it's possible to feed incoming data to the network port. … … 237 296 LogFlow(("slirp_output END %x %d\n", pu8Buf, cb)); 238 297 } 298 #endif 239 299 240 300 /** … … 279 339 int rc = RTCritSectEnter(&pData->CritSect); 280 340 AssertReleaseRC(rc); 341 #ifndef VBOX_NAT_SOURCES 281 342 slirp_term(pData->pNATState); 282 343 pData->pNATState = NULL; 344 #endif 283 345 RTCritSectLeave(&pData->CritSect); 284 346 … … 295 357 static int drvNATConstructRedir(unsigned iInstance, PDRVNAT pData, PCFGMNODE pCfgHandle, RTIPV4ADDR Network) 296 358 { 359 #ifndef VBOX_NAT_SOURCES 297 360 /* 298 361 * Enumerate redirections. … … 361 424 return PDMDrvHlpVMSetError(pData->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); 362 425 } /* for each redir rule */ 426 #endif 363 427 364 428 return VINF_SUCCESS; … … 370 434 static void drvNATSetMac(PDRVNAT pData) 371 435 { 436 #ifndef VBOX_NAT_SOURCES 372 437 if (pData->pConfig) 373 438 { … … 376 441 slirp_set_ethaddr(pData->pNATState, Mac.au8); 377 442 } 443 #endif 378 444 } 379 445 … … 429 495 */ 430 496 pData->pDrvIns = pDrvIns; 497 #ifndef VBOX_NAT_SOURCES 431 498 pData->pNATState = NULL; 499 #endif 432 500 pData->pszTFTPPrefix = NULL; 433 501 pData->pszBootFile = NULL; … … 502 570 { 503 571 #endif 572 #ifndef VBOX_NAT_SOURCES 504 573 /* 505 574 * Initialize slirp. … … 539 608 AssertMsgFailed(("Add error message for rc=%d (%Vrc)\n", rc, rc)); 540 609 } 610 #else 611 pDrvIns->pDrvHlp->pfnPDMPollerRegister(pDrvIns, drvNATPoller); 612 pData->enmLinkState = PDMNETWORKLINKSTATE_UP; 613 mbuf_init(NULL); 614 struct nat_output_callbacks cb; 615 cb.noc_guest_out = drvNATOutput; 616 #if 0 617 cb.noc_host_udp_out = host_udp_out; 618 cb.noc_host_udp_in = host_udp_in; 619 #endif 620 nat_init(&cb); 621 ipfw_nat_init(); 622 #endif 541 623 #if 0 542 624 g_fThreadTerm = true; … … 548 630 } 549 631 #endif 632 #ifndef VBOX_NAT_SOURCES 550 633 RTCritSectDelete(&pData->CritSect); 634 #endif 551 635 return rc; 552 636 }
Note:
See TracChangeset
for help on using the changeset viewer.