- Timestamp:
- May 26, 2012 3:40:24 AM (13 years ago)
- Location:
- trunk/src/VBox/Devices/Network
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DrvNAT.cpp
r40282 r41453 160 160 PDMNETWORKLINKSTATE enmLinkStateWant; 161 161 162 #ifdef VBOX_WITH_SLIRP_MT163 PPDMTHREAD pGuestThread;164 #endif165 162 #ifndef RT_OS_WINDOWS 166 163 /** The write end of the control pipe. */ … … 534 531 PDMDrvHlpFTSetCheckpoint(pThis->pDrvIns, FTMCHECKPOINTTYPE_NETWORK); 535 532 536 #ifdef VBOX_WITH_SLIRP_MT 537 RTREQQUEUE hQueue = (RTREQQUEUE)slirp_get_queue(pThis->pNATState); 538 #else 533 539 534 RTREQQUEUE hQueue = pThis->hSlirpReqQueue; 540 #endif 535 541 536 rc = RTReqQueueCallEx(hQueue, NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT, 542 537 (PFNRT)drvNATSendWorker, 2, pThis, pSgBuf); … … 849 844 } 850 845 851 #ifdef VBOX_WITH_SLIRP_MT852 853 static DECLCALLBACK(int) drvNATAsyncIoGuest(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)854 {855 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);856 857 if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)858 return VINF_SUCCESS;859 860 while (pThread->enmState == PDMTHREADSTATE_RUNNING)861 slirp_process_queue(pThis->pNATState);862 863 return VINF_SUCCESS;864 }865 866 867 static DECLCALLBACK(int) drvNATAsyncIoGuestWakeup(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)868 {869 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);870 871 return VINF_SUCCESS;872 }873 874 #endif /* VBOX_WITH_SLIRP_MT */875 876 846 /** 877 847 * Function called by slirp to check if it's possible to feed incoming data to the network port. … … 916 886 PDRVNAT pThis = (PDRVNAT)pvUser; 917 887 Assert(pThis); 888 LogFlowFuncEnter(); 918 889 pThis->pIAboveNet->pfnXmitPending(pThis->pIAboveNet); 890 LogFlowFuncLeave(); 919 891 } 920 892 … … 942 914 drvNATRecvWakeup(pThis->pDrvIns, pThis->pRecvThread); 943 915 STAM_COUNTER_INC(&pThis->StatQueuePktSent); 916 LogFlowFuncLeave(); 944 917 } 945 918 … … 1415 1388 drvNATAsyncIoWakeup, 128 * _1K, RTTHREADTYPE_IO, "NAT"); 1416 1389 AssertRCReturn(rc, rc); 1417 1418 #ifdef VBOX_WITH_SLIRP_MT1419 rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pGuestThread, pThis, drvNATAsyncIoGuest,1420 drvNATAsyncIoGuestWakeup, 128 * _1K, RTTHREADTYPE_IO, "NATGUEST");1421 AssertRCReturn(rc, rc);1422 #endif1423 1390 1424 1391 pThis->enmLinkState = pThis->enmLinkStateWant = PDMNETWORKLINKSTATE_UP; -
trunk/src/VBox/Devices/Network/slirp/libslirp.h
r39775 r41453 128 128 #endif /* RT_OS_WINDOWS */ 129 129 130 #ifdef VBOX_WITH_SLIRP_MT131 void slirp_process_queue(PNATState pData);132 void *slirp_get_queue(PNATState pData);133 #endif134 135 130 struct mbuf *slirp_ext_m_get(PNATState pData, size_t cbMin, void **ppvBuf, size_t *pcbBuf); 136 131 void slirp_ext_m_free(PNATState pData, struct mbuf *, uint8_t *pu8Buf); -
trunk/src/VBox/Devices/Network/slirp/slirp.c
r41341 r41453 635 635 pData->phEvents[VBOX_SOCKET_EVENT_INDEX] = CreateEvent(NULL, FALSE, FALSE, NULL); 636 636 #endif 637 #ifdef VBOX_WITH_SLIRP_MT638 QSOCKET_LOCK_CREATE(tcb);639 QSOCKET_LOCK_CREATE(udb);640 rc = RTReqQueueCreate(&pData->pReqQueue);641 AssertReleaseRC(rc);642 #endif643 637 644 638 link_up = 1; … … 1052 1046 so->so_timeout(pData, so, so->so_timeout_arg); 1053 1047 } 1054 #ifdef VBOX_WITH_SLIRP_MT1055 /* we need so_next for continue our cycle*/1056 so_next = so->so_next;1057 #endif1058 1048 UDP_DETACH(pData, so, so_next); 1059 1049 CONTINUE_NO_UNLOCK(udp); … … 1217 1207 QSOCKET_FOREACH(so, so_next, tcp) 1218 1208 /* { */ 1219 1220 #ifdef VBOX_WITH_SLIRP_MT1221 if ( so->so_state & SS_NOFDREF1222 && so->so_deleted == 1)1223 {1224 struct socket *son, *sop = NULL;1225 QSOCKET_LOCK(tcb);1226 if (so->so_next != NULL)1227 {1228 if (so->so_next != &tcb)1229 SOCKET_LOCK(so->so_next);1230 son = so->so_next;1231 }1232 if ( so->so_prev != &tcb1233 && so->so_prev != NULL)1234 {1235 SOCKET_LOCK(so->so_prev);1236 sop = so->so_prev;1237 }1238 QSOCKET_UNLOCK(tcb);1239 remque(pData, so);1240 NSOCK_DEC();1241 SOCKET_UNLOCK(so);1242 SOCKET_LOCK_DESTROY(so);1243 RTMemFree(so);1244 so_next = son;1245 if (sop != NULL)1246 SOCKET_UNLOCK(sop);1247 CONTINUE_NO_UNLOCK(tcp);1248 }1249 #endif1250 1209 /* TCP socket can't be cloned */ 1251 1210 #ifdef VBOX_WITH_NAT_UDP_SOCKET_CLONE … … 1462 1421 QSOCKET_FOREACH(so, so_next, udp) 1463 1422 /* { */ 1464 #ifdef VBOX_WITH_SLIRP_MT1465 if ( so->so_state & SS_NOFDREF1466 && so->so_deleted == 1)1467 {1468 struct socket *son, *sop = NULL;1469 QSOCKET_LOCK(udb);1470 if (so->so_next != NULL)1471 {1472 if (so->so_next != &udb)1473 SOCKET_LOCK(so->so_next);1474 son = so->so_next;1475 }1476 if ( so->so_prev != &udb1477 && so->so_prev != NULL)1478 {1479 SOCKET_LOCK(so->so_prev);1480 sop = so->so_prev;1481 }1482 QSOCKET_UNLOCK(udb);1483 remque(pData, so);1484 NSOCK_DEC();1485 SOCKET_UNLOCK(so);1486 SOCKET_LOCK_DESTROY(so);1487 RTMemFree(so);1488 so_next = son;1489 if (sop != NULL)1490 SOCKET_UNLOCK(sop);1491 CONTINUE_NO_UNLOCK(udp);1492 }1493 #endif1494 1423 #ifdef VBOX_WITH_NAT_UDP_SOCKET_CLONE 1495 1424 if (so->so_cloneOf) … … 2020 1949 m_freem(pData, m); 2021 1950 } 2022 #ifdef VBOX_WITH_SLIRP_MT2023 void slirp_process_queue(PNATState pData)2024 {2025 RTReqQueueProcess(pData->pReqQueue, RT_INDEFINITE_WAIT);2026 }2027 void *slirp_get_queue(PNATState pData)2028 {2029 return pData->pReqQueue;2030 }2031 #endif2032 1951 2033 1952 void slirp_set_dhcp_TFTP_prefix(PNATState pData, const char *tftpPrefix) -
trunk/src/VBox/Devices/Network/slirp/slirp_state.h
r39783 r41453 57 57 58 58 int timestamp; 59 uint64_t u64Offset; 59 60 }; 60 61 … … 153 154 int socket_snd; 154 155 int soMaxConn; 155 #ifdef VBOX_WITH_SLIRP_MT156 RTREQQUEUE hReqQueue;157 #endif158 156 #ifdef RT_OS_WINDOWS 159 157 ULONG (WINAPI * pfGetAdaptersAddresses)(ULONG, ULONG, PVOID, PIP_ADAPTER_ADDRESSES, PULONG); … … 174 172 /* Stuff from tcp_input.c */ 175 173 struct socket tcb; 176 #ifdef VBOX_WITH_SLIRP_MT 177 RTCRITSECT tcb_mutex; 178 #endif 174 179 175 struct socket *tcp_last_so; 180 176 tcp_seq tcp_iss; … … 192 188 struct udpstat_t udpstat; 193 189 struct socket udb; 194 #ifdef VBOX_WITH_SLIRP_MT195 RTCRITSECT udb_mutex;196 #endif197 190 struct socket *udp_last_so; 198 191 struct socket icmp_socket; … … 427 420 #define VBOX_X(x) VBOX_X2(x) 428 421 429 #ifdef VBOX_WITH_SLIRP_MT 430 431 # define QSOCKET_LOCK(queue) \ 432 do { \ 433 int rc; \ 434 /* Assert(strcmp(RTThreadSelfName(), "EMT") != 0); */ \ 435 rc = RTCritSectEnter(&VBOX_X(queue) ## _mutex); \ 436 AssertRC(rc); \ 437 } while (0) 438 # define QSOCKET_UNLOCK(queue) \ 439 do { \ 440 int rc; \ 441 rc = RTCritSectLeave(&VBOX_X(queue) ## _mutex); \ 442 AssertRC(rc); \ 443 } while (0) 444 # define QSOCKET_LOCK_CREATE(queue) \ 445 do { \ 446 int rc; \ 447 rc = RTCritSectInit(&pData->queue ## _mutex); \ 448 AssertRC(rc); \ 449 } while (0) 450 # define QSOCKET_LOCK_DESTROY(queue) \ 451 do { \ 452 int rc = RTCritSectDelete(&pData->queue ## _mutex); \ 453 AssertRC(rc); \ 454 } while (0) 455 456 # define QSOCKET_FOREACH(so, sonext, label) \ 457 QSOCKET_LOCK(VBOX_X2(queue_## label ## _label)); \ 458 (so) = (VBOX_X(queue_ ## label ## _label)).so_next; \ 459 QSOCKET_UNLOCK(VBOX_X2(queue_## label ##_label)); \ 460 if ((so) != &(VBOX_X(queue_## label ## _label))) SOCKET_LOCK((so));\ 461 for (;;) \ 462 { \ 463 if ((so) == &(VBOX_X(queue_## label ## _label))) \ 464 { \ 465 break; \ 466 } \ 467 Log2(("%s:%d Processing so:%R[natsock]\n", __FUNCTION__, __LINE__, (so))); 468 469 # define CONTINUE_NO_UNLOCK(label) goto loop_end_ ## label ## _mt_nounlock 470 # define CONTINUE(label) goto loop_end_ ## label ## _mt 471 /* @todo replace queue parameter with macrodinition */ 472 /* _mt_nounlock - user should lock so_next before calling CONTINUE_NO_UNLOCK */ 473 # define LOOP_LABEL(label, so, sonext) loop_end_ ## label ## _mt: \ 474 (sonext) = (so)->so_next; \ 475 SOCKET_UNLOCK(so); \ 476 QSOCKET_LOCK(VBOX_X(queue_ ## label ## _label)); \ 477 if ((sonext) != &(VBOX_X(queue_## label ## _label))) \ 478 { \ 479 SOCKET_LOCK((sonext)); \ 480 QSOCKET_UNLOCK(VBOX_X(queue_ ## label ## _label)); \ 481 } \ 482 else \ 483 { \ 484 so = &VBOX_X(queue_ ## label ## _label); \ 485 QSOCKET_UNLOCK(VBOX_X(queue_ ## label ## _label)); \ 486 break; \ 487 } \ 488 (so) = (sonext); \ 489 continue; \ 490 loop_end_ ## label ## _mt_nounlock: \ 491 (so) = (sonext) 492 493 # define DO_TCP_OUTPUT(data, sotcb) \ 494 do { \ 495 PRTREQ pReq; \ 496 int rc; \ 497 rc = RTReqQueueCallVoid((data)->hReqQueue, &pReq, 0 /*cMillies*/, \ 498 (PFNRT)tcp_output 2, data, sotcb); \ 499 if (RT_LIKELY(rc == VERR_TIMEOUT)) \ 500 { \ 501 SOCKET_UNLOCK(so); \ 502 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \ 503 AssertReleaseRC(rc); \ 504 SOCKET_LOCK(so); \ 505 RTReqRelease(pReq); \ 506 } \ 507 else \ 508 AssertReleaseRC(rc); \ 509 } while(0) 510 511 # define DO_TCP_INPUT(data, mbuf, size, so) \ 512 do { \ 513 int rc; \ 514 rc = RTReqQueueCallEx((data)->hReqQueue, NULL, 0 /*cMillies*/, \ 515 RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT, \ 516 (PFNRT)tcp_input, 4, data, mbuf, size, so); \ 517 AssertReleaseRC(rc); \ 518 } while(0) 519 520 # define DO_TCP_CONNECT(data, so) \ 521 do { \ 522 PRTREQ pReq; \ 523 int rc; \ 524 rc = RTReqQueueCallVoid((data)->hReqQueue, &pReq, 0 /*cMillies*/, \ 525 (PFNRT)tcp_connect, 2, data, so); \ 526 if (RT_LIKELY(rc == VERR_TIMEOUT)) \ 527 { \ 528 SOCKET_UNLOCK(so); \ 529 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \ 530 AssertReleaseRC(rc); \ 531 SOCKET_LOCK(so); \ 532 RTReqRelease(pReq); \ 533 } \ 534 else \ 535 AssertReleaseRC(rc); \ 536 } while(0) 537 538 # define DO_SOREAD(ret, data, so, ifclose) \ 539 do { \ 540 PRTREQ pReq; \ 541 int rc; \ 542 rc = RTReqQueueCallVoid((data)->hReqQueue, &pReq, 0 /*cMillies*/, \ 543 (PFNRT)soread_queue, 4, \ 544 data, so, ifclose, &(ret)); \ 545 if (RT_LIKELY(rc == VERR_TIMEOUT)) \ 546 { \ 547 SOCKET_UNLOCK(so); \ 548 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \ 549 AssertReleaseRC(rc); \ 550 SOCKET_LOCK(so); \ 551 RTReqRelease(pReq); \ 552 } \ 553 else \ 554 AssertReleaseRC(rc); \ 555 } while(0) 556 557 # define DO_SOWRITE(ret, data, so) \ 558 do { \ 559 PRTREQ pReq; \ 560 int rc; \ 561 rc = RTReqQueueCall((data)->hReqQueue, &pReq, 0 /*cMillies*/, \ 562 (PFNRT)sowrite, 2, data, so); \ 563 if (RT_LIKELY(rc == VERR_TIMEOUT)) \ 564 { \ 565 SOCKET_UNLOCK(so); \ 566 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \ 567 SOCKET_LOCK(so); \ 568 ret = pReq->iStatus; \ 569 RTReqRelease(pReq); \ 570 } \ 571 else \ 572 AssertReleaseRC(rc); \ 573 } while(0) 574 575 # define DO_SORECFROM(data, so) \ 576 do { \ 577 PRTREQ pReq; \ 578 int rc; \ 579 rc = RTReqQueueCallVoid((data)->hReqQueue, &pReq, 0 /*cMillies */, \ 580 (PFNRT)sorecvfrom, 2, data, so); \ 581 if (RT_LIKELY(rc == VERR_TIMEOUT)) \ 582 { \ 583 SOCKET_UNLOCK(so); \ 584 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \ 585 AssertReleaseRC(rc); \ 586 SOCKET_LOCK(so); \ 587 RTReqRelease(pReq); \ 588 } \ 589 else \ 590 AssertReleaseRC(rc); \ 591 } while(0) 592 593 # define DO_UDP_DETACH(data, so, so_next) \ 594 do { \ 595 PRTREQ pReq; \ 596 int rc; \ 597 rc = RTReqQueueCallVoid((data)->hReqQueue, &pReq, 0 /* cMillies*/, \ 598 (PFNRT)udp_detach, 2, data, so); \ 599 if (RT_LIKELY(rc == VERR_TIMEOUT)) \ 600 { \ 601 SOCKET_UNLOCK(so); \ 602 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \ 603 AssertReleaseRC(rc); \ 604 if ((so_next) != &udb) SOCKET_LOCK((so_next)); \ 605 RTReqRelease(pReq); \ 606 } \ 607 else \ 608 AssertReleaseRC(rc); \ 609 } while(0) 610 611 # define SOLOOKUP(so, label, src, sport, dst, dport) \ 612 do { \ 613 struct socket *sonxt; \ 614 (so) = NULL; \ 615 QSOCKET_FOREACH(so, sonxt, label) \ 616 /* { */ \ 617 if ( so->so_lport == (sport) \ 618 && so->so_laddr.s_addr == (src).s_addr \ 619 && so->so_faddr.s_addr == (dst).s_addr \ 620 && so->so_fport == (dport)) \ 621 { \ 622 if (sonxt != &VBOX_X2(queue_ ## label ## _label)) \ 623 SOCKET_UNLOCK(sonxt); \ 624 break; /*so is locked*/ \ 625 } \ 626 LOOP_LABEL(so, sonxt, label); \ 627 } \ 628 } \ 629 } while (0) 630 631 #else /* !VBOX_WITH_SLIRP_MT */ 422 #if 1 632 423 633 424 # define QSOCKET_LOCK(queue) do {} while (0) … … 663 454 # define DO_UDP_DETACH(data, so, ignored) udp_detach((data), (so)) 664 455 665 #endif /* !VBOX_WITH_SLIRP_MT */456 #endif 666 457 667 458 #define TCP_OUTPUT(data, sotcb) DO_TCP_OUTPUT((data), (sotcb)) -
trunk/src/VBox/Devices/Network/slirp/socket.c
r41227 r41453 177 177 /* 178 178 * remque and free a socket, clobber cache 179 * VBOX_WITH_SLIRP_MT: before sofree queue should be locked, because180 * in sofree we don't know from which queue item beeing removed.181 179 */ 182 180 void … … 199 197 udp_last_so = &udb; 200 198 201 #ifndef VBOX_WITH_SLIRP_MT202 203 199 /* libalias notification */ 204 200 if (so->so_pvLnk) … … 218 214 219 215 RTMemFree(so); 220 #else221 so->so_deleted = 1;222 #endif223 216 LogFlowFuncLeave(); 224 217 } 225 226 #ifdef VBOX_WITH_SLIRP_MT227 void228 soread_queue(PNATState pData, struct socket *so, int *ret)229 {230 *ret = soread(pData, so);231 }232 #endif233 218 234 219 /* -
trunk/src/VBox/Devices/Network/slirp/socket.h
r41178 r41453 29 29 #ifndef _SLIRP_SOCKET_H_ 30 30 #define _SLIRP_SOCKET_H_ 31 #ifdef VBOX_WITH_SLIRP_MT32 #include <iprt/critsect.h>33 #endif34 31 35 32 #define SO_EXPIRE 240000 … … 85 82 struct sbuf so_rcv; /* Receive buffer */ 86 83 struct sbuf so_snd; /* Send buffer */ 87 #ifdef VBOX_WITH_SLIRP_MT88 RTCRITSECT so_mutex;89 int so_deleted;90 #endif91 84 #ifndef RT_OS_WINDOWS 92 85 int so_poll_index; … … 139 132 void slirpDeleteLinkSocket(void *pvLnk); 140 133 141 #ifdef VBOX_WITH_SLIRP_MT 142 # define SOCKET_LOCK(so) \ 143 do { \ 144 int rc; \ 145 /* Assert(strcmp(RTThreadSelfName(), "EMT") != 0); */ \ 146 Log2(("lock:%s:%d L on %R[natsock]\n", __FUNCTION__, __LINE__, (so))); \ 147 Assert(!RTCritSectIsOwner(&(so)->so_mutex)); \ 148 rc = RTCritSectEnter(&(so)->so_mutex); \ 149 AssertRC(rc); \ 150 } while (0) 151 # define SOCKET_UNLOCK(so) \ 152 do { \ 153 int rc; \ 154 if ((so) != NULL) Log2(("lock:%s:%d U on %R[natsock]\n", __FUNCTION__, __LINE__, (so))); \ 155 rc = RTCritSectLeave(&(so)->so_mutex); \ 156 Assert(rc); \ 157 } while (0) 158 # define SOCKET_LOCK_CREATE(so) \ 159 do { \ 160 int rc; \ 161 rc = RTCritSectInit(&(so)->so_mutex); \ 162 AssertRC(rc); \ 163 } while (0) 164 # define SOCKET_LOCK_DESTROY(so) \ 165 do { \ 166 int rc = RTCritSectDelete(&(so)->so_mutex); \ 167 AssertRC(rc); \ 168 } while (0) 169 #else 134 170 135 # define SOCKET_LOCK(so) do {} while (0) 171 136 # define SOCKET_UNLOCK(so) do {} while (0) 172 137 # define SOCKET_LOCK_CREATE(so) do {} while (0) 173 138 # define SOCKET_LOCK_DESTROY(so) do {} while (0) 174 #endif 139 175 140 /* 176 141 * Socket state bits. (peer means the host on the Internet, … … 204 169 struct socket * socreate (void); 205 170 void sofree (PNATState, struct socket *); 206 #ifdef VBOX_WITH_SLIRP_MT207 void soread_queue (PNATState, struct socket *, int *);208 #endif209 171 int soread (PNATState, struct socket *); 210 172 void sorecvoob (PNATState, struct socket *); -
trunk/src/VBox/Devices/Network/slirp/tcp_input.c
r40423 r41453 460 460 || so->so_faddr.s_addr != ti->ti_dst.s_addr) 461 461 { 462 #ifdef VBOX_WITH_SLIRP_MT463 struct socket *sonxt;464 #endif465 462 QSOCKET_UNLOCK(tcb); 466 463 /* @todo fix SOLOOKUP macrodefinition to be usable here */ 467 #ifndef VBOX_WITH_SLIRP_MT468 464 so = solookup(&tcb, ti->ti_src, ti->ti_sport, 469 465 ti->ti_dst, ti->ti_dport); 470 #else471 so = NULL;472 QSOCKET_FOREACH(so, sonxt, tcp)473 /* { */474 if ( so->so_lport == ti->ti_sport475 && so->so_laddr.s_addr == ti->ti_src.s_addr476 && so->so_faddr.s_addr == ti->ti_dst.s_addr477 && so->so_fport == ti->ti_dport478 && so->so_deleted != 1)479 {480 break; /* so is locked here */481 }482 LOOP_LABEL(tcp, so, sonxt);483 }484 if (so == &tcb) {485 so = NULL;486 }487 #endif488 466 if (so) 489 467 {
Note:
See TracChangeset
for help on using the changeset viewer.