- Timestamp:
- Feb 25, 2009 10:46:39 AM (16 years ago)
- Location:
- trunk/src/VBox/HostDrivers/VBoxNetAdp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdp.c
r17095 r17118 331 331 } 332 332 RTSpinlockRelease(pThis->hSpinlock, &Tmp); 333 Log(("vboxNetAdpPrepareToReceive: fCanReceive=%d.\n", fCanReceive)); 333 334 334 335 return fCanReceive; … … 350 351 AssertPtr(pThis->pSwitchPort); 351 352 Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION); 353 Log(("vboxNetAdpReceive: forwarding packet to internal net...\n")); 352 354 pThis->pSwitchPort->pfnRecv(pThis->pSwitchPort, pSG, INTNETTRUNKDIR_HOST); 353 355 vboxNetAdpIdle(pThis); … … 362 364 DECLHIDDEN(void) vboxNetAdpCancelReceive(PVBOXNETADP pThis) 363 365 { 366 Log(("vboxNetAdpCancelReceive: cancelled.\n")); 364 367 vboxNetAdpIdle(pThis); 365 368 vboxNetAdpRelease(pThis); … … 405 408 Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION); 406 409 410 Log(("vboxNetAdpPortXmit: outgoing packet (len=%d)\n", pSG->cbTotal)); 411 407 412 /* 408 413 * Do a retain/busy, invoke the OS specific code. … … 439 444 AssertPtr(pThis); 440 445 Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION); 441 Assert(vboxNetAdpGetStateWithLock(pThis) == kVBoxNetAdpState_ Connected);446 Assert(vboxNetAdpGetStateWithLock(pThis) == kVBoxNetAdpState_Active); 442 447 443 448 /* … … 460 465 AssertPtr(pThis); 461 466 Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION); 462 Assert(vboxNetAdpGetStateWithLock(pThis) == kVBoxNetAdpState_ Connected);467 Assert(vboxNetAdpGetStateWithLock(pThis) == kVBoxNetAdpState_Active); 463 468 464 469 /* … … 548 553 case kVBoxNetAdpState_Active: 549 554 vboxNetAdpSetState(pThis, kVBoxNetAdpState_Connected); 555 break; 556 default: 550 557 break; 551 558 } -
trunk/src/VBox/HostDrivers/VBoxNetAdp/darwin/VBoxNetAdp-darwin.cpp
r17095 r17118 42 42 #include <iprt/string.h> 43 43 #include <iprt/uuid.h> 44 #include <iprt/alloca.h> 44 45 45 46 #include <sys/systm.h> … … 63 64 * Defined Constants And Macros * 64 65 *******************************************************************************/ 65 #define VBOXNETADP_MAX_FAMILIES 4 66 #define VBOXNETADP_NAME "vboxnet" 67 #define VBOXNETADP_MTU 1500 68 #define VBOXNETADP_DETACH_TIMEOUT 500 66 /** The maximum number of SG segments. 67 * Used to prevent stack overflow and similar bad stuff. */ 68 #define VBOXNETADP_DARWIN_MAX_SEGS 32 69 #define VBOXNETADP_DARWIN_MAX_FAMILIES 4 70 #define VBOXNETADP_DARWIN_NAME "vboxnet" 71 #define VBOXNETADP_DARWIN_MTU 1500 72 #define VBOXNETADP_DARWIN_DETACH_TIMEOUT 500 69 73 70 74 #define VBOXNETADP_FROM_IFACE(iface) ((PVBOXNETADP) ifnet_softc(iface)) … … 121 125 DECLINLINE(ifnet_t) vboxNetAdpDarwinRetainIfNet(PVBOXNETADP pThis) 122 126 { 123 ifnet_t pIfNet = NULL; 124 125 ifnet_reference(pThis->u.s.pIface); 126 127 return pIfNet; 127 if (pThis->u.s.pIface) 128 ifnet_reference(pThis->u.s.pIface); 129 130 return pThis->u.s.pIface; 128 131 } 129 132 … … 141 144 if (pIfNet) 142 145 ifnet_release(pIfNet); 143 }144 145 146 147 static errno_t vboxNetAdpDarwinOutput(ifnet_t pIface, mbuf_t pMBuf)148 {149 PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface);150 Assert(pThis);151 if (vboxNetAdpPrepareToReceive(pThis))152 {153 if (/* converted to SG */0)154 vboxNetAdpReceive(pThis, NULL);155 else156 vboxNetAdpCancelReceive(pThis);157 }158 mbuf_freem_list(pMBuf);159 return 0;160 }161 162 static void vboxNetAdpDarwinAttachFamily(PVBOXNETADP pThis, protocol_family_t Family)163 {164 u_int32_t i;165 for (i = 0; i < VBOXNETADP_MAX_FAMILIES; i++)166 if (pThis->u.s.aAttachedFamilies[i] == 0)167 {168 pThis->u.s.aAttachedFamilies[i] = Family;169 break;170 }171 }172 173 static void vboxNetAdpDarwinDetachFamily(PVBOXNETADP pThis, protocol_family_t Family)174 {175 u_int32_t i;176 for (i = 0; i < VBOXNETADP_MAX_FAMILIES; i++)177 if (pThis->u.s.aAttachedFamilies[i] == Family)178 pThis->u.s.aAttachedFamilies[i] = 0;179 }180 181 static errno_t vboxNetAdpDarwinAddProto(ifnet_t pIface, protocol_family_t Family, const struct ifnet_demux_desc *pDemuxDesc, u_int32_t nDesc)182 {183 PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface);184 Assert(pThis);185 vboxNetAdpDarwinAttachFamily(pThis, Family);186 LogFlow(("vboxNetAdpAddProto: Family=%d.\n", Family));187 return ether_add_proto(pIface, Family, pDemuxDesc, nDesc);188 }189 190 static errno_t vboxNetAdpDarwinDelProto(ifnet_t pIface, protocol_family_t Family)191 {192 PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface);193 Assert(pThis);194 LogFlow(("vboxNetAdpDelProto: Family=%d.\n", Family));195 vboxNetAdpDarwinDetachFamily(pThis, Family);196 return ether_del_proto(pIface, Family);197 }198 199 static void vboxNetAdpDarwinDetach(ifnet_t pIface)200 {201 PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface);202 Assert(pThis);203 Log2(("vboxNetAdpDarwinDetach: Signaling detach to vboxNetAdpUnregisterDevice.\n"));204 /* Let vboxNetAdpDarwinUnregisterDevice know that the interface has been detached. */205 RTSemEventSignal(pThis->u.s.hEvtDetached);206 146 } 207 147 … … 500 440 } 501 441 442 443 static errno_t vboxNetAdpDarwinOutput(ifnet_t pIface, mbuf_t pMBuf) 444 { 445 PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface); 446 Assert(pThis); 447 if (vboxNetAdpPrepareToReceive(pThis)) 448 { 449 unsigned cSegs = vboxNetAdpDarwinMBufCalcSGSegs(pThis, pMBuf, NULL); 450 if (cSegs < VBOXNETADP_DARWIN_MAX_SEGS) 451 { 452 PINTNETSG pSG = (PINTNETSG)alloca(RT_OFFSETOF(INTNETSG, aSegs[cSegs])); 453 vboxNetAdpDarwinMBufToSG(pThis, pMBuf, NULL, pSG, cSegs, INTNETTRUNKDIR_HOST); 454 vboxNetAdpReceive(pThis, pSG); 455 } 456 else 457 vboxNetAdpCancelReceive(pThis); 458 } 459 mbuf_freem_list(pMBuf); 460 return 0; 461 } 462 463 static void vboxNetAdpDarwinAttachFamily(PVBOXNETADP pThis, protocol_family_t Family) 464 { 465 u_int32_t i; 466 for (i = 0; i < VBOXNETADP_MAX_FAMILIES; i++) 467 if (pThis->u.s.aAttachedFamilies[i] == 0) 468 { 469 pThis->u.s.aAttachedFamilies[i] = Family; 470 break; 471 } 472 } 473 474 static void vboxNetAdpDarwinDetachFamily(PVBOXNETADP pThis, protocol_family_t Family) 475 { 476 u_int32_t i; 477 for (i = 0; i < VBOXNETADP_MAX_FAMILIES; i++) 478 if (pThis->u.s.aAttachedFamilies[i] == Family) 479 pThis->u.s.aAttachedFamilies[i] = 0; 480 } 481 482 static errno_t vboxNetAdpDarwinAddProto(ifnet_t pIface, protocol_family_t Family, const struct ifnet_demux_desc *pDemuxDesc, u_int32_t nDesc) 483 { 484 PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface); 485 Assert(pThis); 486 vboxNetAdpDarwinAttachFamily(pThis, Family); 487 LogFlow(("vboxNetAdpAddProto: Family=%d.\n", Family)); 488 return ether_add_proto(pIface, Family, pDemuxDesc, nDesc); 489 } 490 491 static errno_t vboxNetAdpDarwinDelProto(ifnet_t pIface, protocol_family_t Family) 492 { 493 PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface); 494 Assert(pThis); 495 LogFlow(("vboxNetAdpDelProto: Family=%d.\n", Family)); 496 vboxNetAdpDarwinDetachFamily(pThis, Family); 497 return ether_del_proto(pIface, Family); 498 } 499 500 static void vboxNetAdpDarwinDetach(ifnet_t pIface) 501 { 502 PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface); 503 Assert(pThis); 504 Log2(("vboxNetAdpDarwinDetach: Signaling detach to vboxNetAdpUnregisterDevice.\n")); 505 /* Let vboxNetAdpDarwinUnregisterDevice know that the interface has been detached. */ 506 RTSemEventSignal(pThis->u.s.hEvtDetached); 507 } 508 509 510 502 511 int vboxNetAdpPortOsXmit(PVBOXNETADP pThis, PINTNETSG pSG, uint32_t fDst) 503 512 { … … 509 518 * Create a mbuf for the gather list and push it onto the host stack. 510 519 */ 511 if (fDst & INTNETTRUNKDIR_HOST) 512 { 513 mbuf_t pMBuf = vboxNetAdpDarwinMBufFromSG(pThis, pSG); 514 if (pMBuf) 515 { 516 /* This is what IONetworkInterface::inputPacket does. */ 517 unsigned const cbEthHdr = 14; 518 mbuf_pkthdr_setheader(pMBuf, mbuf_data(pMBuf)); 519 mbuf_pkthdr_setlen(pMBuf, mbuf_pkthdr_len(pMBuf) - cbEthHdr); 520 mbuf_setdata(pMBuf, (uint8_t *)mbuf_data(pMBuf) + cbEthHdr, mbuf_len(pMBuf) - cbEthHdr); 521 mbuf_pkthdr_setrcvif(pMBuf, pIfNet); /* will crash without this. */ 522 523 errno_t err = ifnet_input(pIfNet, pMBuf, NULL); 524 if (err) 525 rc = RTErrConvertFromErrno(err); 526 } 527 else 528 rc = VERR_NO_MEMORY; 520 mbuf_t pMBuf = vboxNetAdpDarwinMBufFromSG(pThis, pSG); 521 if (pMBuf) 522 { 523 /* This is what IONetworkInterface::inputPacket does. */ 524 unsigned const cbEthHdr = 14; 525 mbuf_pkthdr_setheader(pMBuf, mbuf_data(pMBuf)); 526 mbuf_pkthdr_setlen(pMBuf, mbuf_pkthdr_len(pMBuf) - cbEthHdr); 527 mbuf_setdata(pMBuf, (uint8_t *)mbuf_data(pMBuf) + cbEthHdr, mbuf_len(pMBuf) - cbEthHdr); 528 mbuf_pkthdr_setrcvif(pMBuf, pIfNet); /* will crash without this. */ 529 530 Log(("vboxNetAdpPortOsXmit: calling ifnet_input()\n")); 531 errno_t err = ifnet_input(pIfNet, pMBuf, NULL); 532 if (err) 533 rc = RTErrConvertFromErrno(err); 534 } 535 else 536 { 537 Log(("vboxNetAdpPortOsXmit: failed to convert SG to mbuf.\n")); 538 rc = VERR_NO_MEMORY; 529 539 } 530 540 531 541 vboxNetAdpDarwinReleaseIfNet(pThis, pIfNet); 532 542 } 543 else 544 Log(("vboxNetAdpPortOsXmit: failed to retain the interface.\n")); 533 545 534 546 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.