Changeset 105064 in vbox for trunk/src/VBox/Devices/Network/DrvNATlibslirp.cpp
- Timestamp:
- Jun 27, 2024 2:46:31 PM (5 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DrvNATlibslirp.cpp
r105025 r105064 185 185 Assert(!pSgBuf->pvUser); 186 186 RTMemFree(pSgBuf->aSegs[0].pvSeg); 187 pSgBuf->pvAllocator = NULL;188 187 } 189 188 else if (pSgBuf->pvUser) … … 202 201 * @param pThis Pointer to the NAT instance. 203 202 * @param pSgBuf The scatter/gather buffer. 204 *205 203 * @thread NAT 206 204 */ 207 205 static DECLCALLBACK(void) drvNATSendWorker(PDRVNAT pThis, PPDMSCATTERGATHER pSgBuf) 208 206 { 207 LogFlowFunc(("pThis=%p pSgBuf=%p\n", pThis, pSgBuf)); 208 209 209 if (pThis->enmLinkState == PDMNETWORKLINKSTATE_UP) 210 210 { … … 215 215 * A normal frame. 216 216 */ 217 LogFlowFunc(("m=%p\n", m)); 217 218 slirp_input(pThis->pNATState->pSlirp, (uint8_t const *)pSgBuf->pvAllocator, (int)pSgBuf->cbUsed); 218 219 } … … 220 221 { 221 222 /* 222 * Large/GSO frame.223 * M_EXT buf, need to segment it. 223 224 */ 224 225 … … 249 250 } 250 251 252 LogFlowFunc(("leave\n")); 251 253 drvNATFreeSgBuf(pThis, pSgBuf); 252 254 } … … 254 256 /** 255 257 * @interface_method_impl{PDMINETWORKUP,pfnBeginXmit} 256 *257 * @param pInterface Pointer to UP network interface.258 * @param fOnWorkerThread Unused.259 *260 * @returns VBox status code.261 *262 * @thread ?263 258 */ 264 259 static DECLCALLBACK(int) drvNATNetworkUp_BeginXmit(PPDMINETWORKUP pInterface, bool fOnWorkerThread) … … 278 273 /** 279 274 * @interface_method_impl{PDMINETWORKUP,pfnAllocBuf} 280 *281 * Allocates a scatter/gather buffer for packet/frame handling.282 *283 * @param pInterface Pointer to UP network interface.284 * @param cbMin Minimum size of buffer to hold packet/frame.285 * @param pGso The GSO context.286 * @param ppSgBuf Pointer to the resulting scatter/gather buffer.287 *288 * @returns VBox status code289 *290 * @thread ?291 275 */ 292 276 static DECLCALLBACK(int) drvNATNetworkUp_AllocBuf(PPDMINETWORKUP pInterface, size_t cbMin, … … 295 279 PDRVNAT pThis = RT_FROM_MEMBER(pInterface, DRVNAT, INetworkUp); 296 280 Assert(RTCritSectIsOwner(&pThis->XmitLock)); 281 282 LogFlowFunc(("enter\n")); 297 283 298 284 /* … … 377 363 /** 378 364 * @interface_method_impl{PDMINETWORKUP,pfnFreeBuf} 379 *380 * Wrapper function for drvNATFreeSgBuff.381 *382 * @param pInterface Pointer to UP network interface.383 * @param pSgBuf Pointer to scatter/gather buffer to be freed.384 *385 * @thread ?386 365 */ 387 366 static DECLCALLBACK(int) drvNATNetworkUp_FreeBuf(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf) … … 395 374 /** 396 375 * @interface_method_impl{PDMINETWORKUP,pfnSendBuf} 397 *398 * Sends packet/frame out to network (up from guest).399 *400 * @param pInterface Pointer to UP network interface.401 * @param pSgBuf Pointer to scatter/gather packet/frame buffer.402 * @param fOnWorkerThread Unused.403 *404 * @thread ?405 376 */ 406 377 static DECLCALLBACK(int) drvNATNetworkUp_SendBuf(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf, bool fOnWorkerThread) … … 411 382 Assert(RTCritSectIsOwner(&pThis->XmitLock)); 412 383 384 LogFlowFunc(("enter\n")); 385 413 386 int rc; 414 387 if (pThis->pSlirpThread->enmState == PDMTHREADSTATE_RUNNING) … … 420 393 { 421 394 drvNATNotifyNATThread(pThis, "drvNATNetworkUp_SendBuf"); 395 LogFlowFunc(("leave success\n")); 422 396 return VINF_SUCCESS; 423 397 } … … 427 401 else 428 402 rc = VERR_NET_DOWN; 429 430 403 drvNATFreeSgBuf(pThis, pSgBuf); 404 LogFlowFunc(("leave rc=%Rrc\n", rc)); 431 405 return rc; 432 406 } … … 434 408 /** 435 409 * @interface_method_impl{PDMINETWORKUP,pfnEndXmit} 436 *437 * End transmission.438 *439 * @param pInterface Pointer to UP network interface.440 *441 * @thread ?442 410 */ 443 411 static DECLCALLBACK(void) drvNATNetworkUp_EndXmit(PPDMINETWORKUP pInterface) … … 449 417 /** 450 418 * Get the NAT thread out of poll/WSAWaitForMultipleEvents 451 *452 * @param pThis Pointer to DRVNAT state for current context.453 * @param pszWho String identifying caller.454 *455 * @thread ?456 419 */ 457 420 static void drvNATNotifyNATThread(PDRVNAT pThis, const char *pszWho) … … 463 426 size_t cbIgnored; 464 427 rc = RTPipeWrite(pThis->hPipeWrite, "", 1, &cbIgnored); 428 #else 429 /* kick WSAWaitForMultipleEvents */ 430 rc = WSASetEvent(pThis->hWakeupEvent); 465 431 #endif 466 432 AssertRC(rc); … … 480 446 * Worker function for drvNATNetworkUp_NotifyLinkChanged(). 481 447 * @thread "NAT" thread. 448 * 449 * @param pThis Pointer to DRVNAT state for current context. 450 * @param enmLinkState Enum value of link state. 451 * 452 * @thread NAT 482 453 */ 483 454 static DECLCALLBACK(void) drvNATNotifyLinkChangedWorker(PDRVNAT pThis, PDMNETWORKLINKSTATE enmLinkState) … … 488 459 case PDMNETWORKLINKSTATE_UP: 489 460 LogRel(("NAT: Link up\n")); 490 // slirp_link_up(pThis->pNATState);491 461 break; 492 462 … … 494 464 case PDMNETWORKLINKSTATE_DOWN_RESUME: 495 465 LogRel(("NAT: Link down\n")); 496 // slirp_link_down(pThis->pNATState);497 466 break; 498 467 … … 507 476 * @param pInterface Pointer to the interface structure containing the called function pointer. 508 477 * @param enmLinkState The new link state. 478 * 509 479 * @thread EMT 510 480 */ … … 537 507 } 538 508 539 /** @todo r=jack: move this to the right spot. temp for dev. */ 540 static void register_poll_fd(int fd, void *opaque) { 509 /** 510 * Registers poll. Unused function (other than logging). 511 */ 512 static void drvNAT_RegisterPoll(int fd, void *opaque) { 541 513 RT_NOREF(fd, opaque); 542 } 543 544 static void unregister_poll_fd(int fd, void *opaque) { 514 Log4(("Poll registered\n")); 515 } 516 517 /** 518 * Unregisters poll. Unused function (other than logging). 519 */ 520 static void drvNAT_UnregisterPoll(int fd, void *opaque) { 545 521 RT_NOREF(fd, opaque); 546 } 547 548 static int slirp_to_poll(int events) { 549 int ret = 0; 522 Log4(("Poll unregistered\n")); 523 } 524 525 /** 526 * Converts slirp representation of poll events to host representation. 527 * 528 * @param iEvents Integer representing slirp type poll events. 529 * 530 * @returns Integer representing host type poll events. 531 * 532 * @thread ? 533 */ 534 static int drvNAT_PollEventSlirpToHost(int iEvents) { 535 int iRet = 0; 550 536 #ifndef RT_OS_WINDOWS 551 if ( events & SLIRP_POLL_IN) ret |= POLLIN;552 if ( events & SLIRP_POLL_OUT) ret |= POLLOUT;553 if ( events & SLIRP_POLL_PRI) ret |= POLLPRI;554 if ( events & SLIRP_POLL_ERR) ret |= POLLERR;555 if ( events & SLIRP_POLL_HUP) ret |= POLLHUP;537 if (iEvents & SLIRP_POLL_IN) iRet |= POLLIN; 538 if (iEvents & SLIRP_POLL_OUT) iRet |= POLLOUT; 539 if (iEvents & SLIRP_POLL_PRI) iRet |= POLLPRI; 540 if (iEvents & SLIRP_POLL_ERR) iRet |= POLLERR; 541 if (iEvents & SLIRP_POLL_HUP) iRet |= POLLHUP; 556 542 #else 557 if ( events & SLIRP_POLL_IN) ret |= (POLLRDNORM | POLLRDBAND);558 if ( events & SLIRP_POLL_OUT) ret |= POLLWRNORM;559 if ( events & SLIRP_POLL_PRI) ret |= (POLLIN);560 if ( events & SLIRP_POLL_ERR) ret |= 0;561 if ( events & SLIRP_POLL_HUP) ret |= 0;543 if (iEvents & SLIRP_POLL_IN) iRet |= (POLLRDNORM | POLLRDBAND); 544 if (iEvents & SLIRP_POLL_OUT) iRet |= POLLWRNORM; 545 if (iEvents & SLIRP_POLL_PRI) iRet |= (POLLIN); 546 if (iEvents & SLIRP_POLL_ERR) iRet |= 0; 547 if (iEvents & SLIRP_POLL_HUP) iRet |= 0; 562 548 #endif 563 return ret; 564 } 565 566 static int poll_to_slirp(int events) { 567 int ret = 0; 549 return iRet; 550 } 551 552 /** 553 * Converts host representation of poll events to slirp representation. 554 * 555 * @param iEvents Integer representing host type poll events. 556 * 557 * @returns Integer representing slirp type poll events. 558 * 559 * @thread ? 560 */ 561 static int drvNAT_PollEventHostToSlirp(int iEvents) { 562 int iRet = 0; 568 563 #ifndef RT_OS_WINDOWS 569 if ( events & POLLIN) ret |= SLIRP_POLL_IN;570 if ( events & POLLOUT) ret |= SLIRP_POLL_OUT;571 if ( events & POLLPRI) ret |= SLIRP_POLL_PRI;572 if ( events & POLLERR) ret |= SLIRP_POLL_ERR;573 if ( events & POLLHUP) ret |= SLIRP_POLL_HUP;564 if (iEvents & POLLIN) iRet |= SLIRP_POLL_IN; 565 if (iEvents & POLLOUT) iRet |= SLIRP_POLL_OUT; 566 if (iEvents & POLLPRI) iRet |= SLIRP_POLL_PRI; 567 if (iEvents & POLLERR) iRet |= SLIRP_POLL_ERR; 568 if (iEvents & POLLHUP) iRet |= SLIRP_POLL_HUP; 574 569 #else 575 if ( events & (POLLRDNORM | POLLRDBAND)) ret |= SLIRP_POLL_IN;576 if ( events & POLLWRNORM) ret |= SLIRP_POLL_OUT;577 if ( events & (POLLPRI)) ret |= SLIRP_POLL_PRI;578 if ( events & POLLERR) ret |= SLIRP_POLL_ERR;579 if ( events & POLLHUP) ret |= SLIRP_POLL_HUP;570 if (iEvents & (POLLRDNORM | POLLRDBAND)) iRet |= SLIRP_POLL_IN; 571 if (iEvents & POLLWRNORM) iRet |= SLIRP_POLL_OUT; 572 if (iEvents & (POLLPRI)) iRet |= SLIRP_POLL_PRI; 573 if (iEvents & POLLERR) iRet |= SLIRP_POLL_ERR; 574 if (iEvents & POLLHUP) iRet |= SLIRP_POLL_HUP; 580 575 #endif 581 return ret; 582 } 583 584 static int add_poll_cb(int fd, int events, void *opaque) 585 { 586 // LogFlow(("add_poll_cb: fd=%d, events=%d\n", fd, events)); 576 return iRet; 577 } 578 579 /** 580 * Callback function to add entry to pollfd array. 581 * 582 * @param iFd Integer of system file descriptor of socket. 583 * (on windows, this is a VBox internal, not system, value). 584 * @param iEvents Integer of slirp type poll events. 585 * @param opaque Pointer to NAT State context. 586 * 587 * @returns Index of latest pollfd entry. 588 * 589 * @thread ? 590 */ 591 static int drvNAT_addPollCb(int iFd, int iEvents, void *opaque) 592 { 587 593 PDRVNAT pThis = (PDRVNAT)opaque; 588 594 … … 596 602 pThis->pNATState->uPollCap *= 2; 597 603 } 598 else { 599 LogFlow(("add_poll_cb return -1")); 604 else 600 605 return -1; 601 }602 606 } 603 607 604 608 int idx = pThis->pNATState->nsock; 605 609 #ifdef RT_OS_WINDOWS 606 pThis->pNATState->polls[idx].fd = libslirp_wrap_RTHandleTableLookup( fd);610 pThis->pNATState->polls[idx].fd = libslirp_wrap_RTHandleTableLookup(iFd); 607 611 #else 608 pThis->pNATState->polls[idx].fd = fd;612 pThis->pNATState->polls[idx].fd = iFd; 609 613 #endif 610 pThis->pNATState->polls[idx].events = slirp_to_poll(events);614 pThis->pNATState->polls[idx].events = drvNAT_PollEventSlirpToHost(iEvents); 611 615 pThis->pNATState->polls[idx].revents = 0; 612 616 pThis->pNATState->nsock += 1; … … 614 618 } 615 619 620 /** 621 * Get translated revents from a poll at a given index. 622 * 623 * @param idx Integer index of poll. 624 * @param opaque Pointer to NAT State context. 625 * 626 * @returns Integer representing transalted revents. 627 * 628 * @thread ? 629 */ 616 630 static int get_revents_cb(int idx, void *opaque) 617 631 { 618 632 PDRVNAT pThis = (PDRVNAT)opaque; 619 633 struct pollfd* polls = pThis->pNATState->polls; 620 return poll_to_slirp(polls[idx].revents);634 return drvNAT_PollEventHostToSlirp(polls[idx].revents); 621 635 } 622 636 … … 630 644 * wants to deliver packets to the guest, it enqueues a request into 631 645 * hRecvReqQueue which is later handled by the Recv thread. 646 * 647 * @param pDrvIns Pointer to PDM driver context. 648 * @param pThread Pointer to calling thread context. 649 * 650 * @returns VBox status code 651 * 652 * @thread NAT 632 653 */ 633 654 static DECLCALLBACK(int) drvNATAsyncIoThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread) … … 638 659 #else /* RT_OS_WINDOWS */ 639 660 unsigned int cPollNegRet = 0; 640 add_poll_cb(RTPipeToNative(pThis->hPipeRead), SLIRP_POLL_IN | SLIRP_POLL_HUP, pThis);661 drvNAT_addPollCb(RTPipeToNative(pThis->hPipeRead), SLIRP_POLL_IN | SLIRP_POLL_HUP, pThis); 641 662 pThis->pNATState->polls[0].fd = RTPipeToNative(pThis->hPipeRead); 642 663 pThis->pNATState->polls[0].events = POLLRDNORM | POLLPRI | POLLRDBAND; … … 664 685 pThis->pNATState->nsock = 1; 665 686 666 slirp_pollfds_fill(pThis->pNATState->pSlirp, &uTimeout, add_poll_cb /* SlirpAddPollCb */, pThis /* opaque */);687 slirp_pollfds_fill(pThis->pNATState->pSlirp, &uTimeout, drvNAT_addPollCb /* SlirpAddPollCb */, pThis /* opaque */); 667 688 slirpUpdateTimeout(&uTimeout, pThis); 668 689 … … 712 733 uint32_t uTimeout = 0; 713 734 pThis->pNATState->nsock = 0; 714 slirp_pollfds_fill(pThis->pNATState->pSlirp, &uTimeout, add_poll_cb /* SlirpAddPollCb */, pThis /* opaque */);735 slirp_pollfds_fill(pThis->pNATState->pSlirp, &uTimeout, drvNAT_addPollCb /* SlirpAddPollCb */, pThis /* opaque */); 715 736 slirpUpdateTimeout(&uTimeout, pThis); 716 737 … … 760 781 * @param pDevIns The pcnet device instance. 761 782 * @param pThread The send thread. 783 * 784 * @thread ? 762 785 */ 763 786 static DECLCALLBACK(int) drvNATAsyncIoWakeup(PPDMDRVINS pDrvIns, PPDMTHREAD pThread) … … 770 793 } 771 794 795 /** @todo r=jack: do we need? */ 772 796 static DECLCALLBACK(int) drvNATHostResThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread) 773 797 { … … 1397 1421 slirpCallbacks->timer_free = &slirpTimerFreeCb; 1398 1422 slirpCallbacks->timer_mod = &slirpTimerModCb; 1399 slirpCallbacks->register_poll_fd = & register_poll_fd;1400 slirpCallbacks->unregister_poll_fd = & unregister_poll_fd;1423 slirpCallbacks->register_poll_fd = &drvNAT_RegisterPoll; 1424 slirpCallbacks->unregister_poll_fd = &drvNAT_UnregisterPoll; 1401 1425 slirpCallbacks->notify = &slirpNotifyCb; 1402 1426 slirpCallbacks->init_completed = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.