Changeset 28706 in vbox for trunk/src/VBox/Devices/Network
- Timestamp:
- Apr 25, 2010 3:10:30 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 60578
- Location:
- trunk/src/VBox/Devices/Network
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/SrvIntNetR0.cpp
r28701 r28706 385 385 typedef struct INTNET 386 386 { 387 /** Magic number (INTNET_MAGIC). */ 388 uint32_t volatile u32Magic; 387 389 /** Mutex protecting the creation, opening and destruction of both networks and 388 390 * interfaces. (This means all operations affecting the pNetworks list.) */ … … 393 395 RTHANDLETABLE hHtIfs; 394 396 } INTNET; 395 397 /** Pointer to an internal network ring-0 instance. */ 398 typedef struct INTNET *PINTNET; 399 400 /** Magic number for the internal network instance data (Hayao Miyazaki). */ 401 #define INTNET_MAGIC UINT32_C(0x19410105) 402 403 404 /******************************************************************************* 405 * Global Variables * 406 *******************************************************************************/ 407 /** Pointer to the internal network instance data. */ 408 static PINTNET volatile g_pIntNet = NULL; 396 409 397 410 … … 2553 2566 * Edit the source address so that it it's the same as the host. 2554 2567 */ 2555 /* ASSUME frame from I NTNETR0IfSend! */2568 /* ASSUME frame from IntNetR0IfSend! */ 2556 2569 AssertReturnVoid(pSG->cSegsUsed == 1); 2557 2570 AssertReturnVoid(pSG->cbTotal >= sizeof(RTNETETHERHDR)); … … 3227 3240 * 3228 3241 * @returns VBox status code. 3229 * @param pIntNet The instance data.3230 3242 * @param hIf The interface handle. 3231 3243 * @param pSession The caller's session. 3232 3244 */ 3233 INTNETR0DECL(int) I NTNETR0IfSend(PINTNET pIntNet,INTNETIFHANDLE hIf, PSUPDRVSESSION pSession)3234 { 3235 Log5(("I NTNETR0IfSend: pIntNet=%p hIf=%RX32\n", pIntNet, hIf));3245 INTNETR0DECL(int) IntNetR0IfSend(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession) 3246 { 3247 Log5(("IntNetR0IfSend: hIf=%RX32\n", hIf)); 3236 3248 3237 3249 /* 3238 3250 * Validate input and translate the handle. 3239 3251 */ 3240 AssertReturn(pIntNet, VERR_INVALID_PARAMETER); 3252 PINTNET pIntNet = g_pIntNet; 3253 AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER); 3254 AssertReturn(pIntNet->u32Magic, VERR_INVALID_MAGIC); 3255 3241 3256 PINTNETIF pIf = (PINTNETIF)RTHandleTableLookupWithCtx(pIntNet->hHtIfs, hIf, pSession); 3242 3257 if (!pIf) … … 3335 3350 3336 3351 /** 3337 * VMMR0 request wrapper for INTNETR0IfSend. 3338 * 3339 * @returns see INTNETR0IfSend. 3340 * @param pIntNet The internal networking instance. 3352 * VMMR0 request wrapper for IntNetR0IfSend. 3353 * 3354 * @returns see IntNetR0IfSend. 3341 3355 * @param pSession The caller's session. 3342 3356 * @param pReq The request packet. 3343 3357 */ 3344 INTNETR0DECL(int) I NTNETR0IfSendReq(PINTNET pIntNet,PSUPDRVSESSION pSession, PINTNETIFSENDREQ pReq)3358 INTNETR0DECL(int) IntNetR0IfSendReq(PSUPDRVSESSION pSession, PINTNETIFSENDREQ pReq) 3345 3359 { 3346 3360 if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq))) 3347 3361 return VERR_INVALID_PARAMETER; 3348 return I NTNETR0IfSend(pIntNet,pReq->hIf, pSession);3362 return IntNetR0IfSend(pReq->hIf, pSession); 3349 3363 } 3350 3364 … … 3354 3368 * 3355 3369 * @returns VBox status code. 3356 * @param pIntNet The instance data.3357 3370 * @param hIf The interface handle. 3358 3371 * @param pSession The caller's session. 3359 3372 * @param ppRing3Buf Where to store the address of the ring-3 mapping. 3360 3373 */ 3361 INTNETR0DECL(int) I NTNETR0IfGetRing3Buffer(PINTNET pIntNet,INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, R3PTRTYPE(PINTNETBUF) *ppRing3Buf)3362 { 3363 LogFlow(("I NTNETR0IfGetRing3Buffer: pIntNet=%p hIf=%RX32 ppRing3Buf=%p\n", pIntNet, hIf, ppRing3Buf));3374 INTNETR0DECL(int) IntNetR0IfGetRing3Buffer(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, R3PTRTYPE(PINTNETBUF) *ppRing3Buf) 3375 { 3376 LogFlow(("IntNetR0IfGetRing3Buffer: hIf=%RX32 ppRing3Buf=%p\n", hIf, ppRing3Buf)); 3364 3377 3365 3378 /* 3366 3379 * Validate input. 3367 3380 */ 3368 AssertReturn(pIntNet, VERR_INVALID_PARAMETER); 3381 PINTNET pIntNet = g_pIntNet; 3382 AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER); 3383 AssertReturn(pIntNet->u32Magic, VERR_INVALID_MAGIC); 3384 3369 3385 AssertPtrReturn(ppRing3Buf, VERR_INVALID_PARAMETER); 3370 3386 *ppRing3Buf = 0; … … 3387 3403 3388 3404 intnetR0IfRelease(pIf, pSession); 3389 LogFlow(("I NTNETR0IfGetRing3Buffer: returns %Rrc *ppRing3Buf=%p\n", rc, *ppRing3Buf));3405 LogFlow(("IntNetR0IfGetRing3Buffer: returns %Rrc *ppRing3Buf=%p\n", rc, *ppRing3Buf)); 3390 3406 return rc; 3391 3407 } … … 3393 3409 3394 3410 /** 3395 * VMMR0 request wrapper for INTNETR0IfGetRing3Buffer. 3396 * 3397 * @returns see INTNETR0IfGetRing3Buffer. 3398 * @param pIntNet The internal networking instance. 3411 * VMMR0 request wrapper for IntNetR0IfGetRing3Buffer. 3412 * 3413 * @returns see IntNetR0IfGetRing3Buffer. 3399 3414 * @param pSession The caller's session. 3400 3415 * @param pReq The request packet. 3401 3416 */ 3402 INTNETR0DECL(int) I NTNETR0IfGetRing3BufferReq(PINTNET pIntNet,PSUPDRVSESSION pSession, PINTNETIFGETRING3BUFFERREQ pReq)3417 INTNETR0DECL(int) IntNetR0IfGetRing3BufferReq(PSUPDRVSESSION pSession, PINTNETIFGETRING3BUFFERREQ pReq) 3403 3418 { 3404 3419 if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq))) 3405 3420 return VERR_INVALID_PARAMETER; 3406 return I NTNETR0IfGetRing3Buffer(pIntNet,pReq->hIf, pSession, &pReq->pRing3Buf);3421 return IntNetR0IfGetRing3Buffer(pReq->hIf, pSession, &pReq->pRing3Buf); 3407 3422 } 3408 3423 … … 3412 3427 * 3413 3428 * @returns VBox status code. 3414 * @param pIntNet The instance data.3415 3429 * @param hIf The interface handle. 3416 3430 * @param pSession The caller's session. 3417 3431 * @param ppRing0Buf Where to store the address of the ring-3 mapping. 3418 3432 */ 3419 INTNETR0DECL(int) I NTNETR0IfGetRing0Buffer(PINTNET pIntNet,INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, PINTNETBUF *ppRing0Buf)3420 { 3421 LogFlow(("I NTNETR0IfGetRing0Buffer: pIntNet=%p hIf=%RX32 ppRing0Buf=%p\n", pIntNet, hIf, ppRing0Buf));3433 INTNETR0DECL(int) IntNetR0IfGetRing0Buffer(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, PINTNETBUF *ppRing0Buf) 3434 { 3435 LogFlow(("IntNetR0IfGetRing0Buffer: hIf=%RX32 ppRing0Buf=%p\n", hIf, ppRing0Buf)); 3422 3436 3423 3437 /* 3424 3438 * Validate input. 3425 3439 */ 3440 PINTNET pIntNet = g_pIntNet; 3441 AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER); 3442 AssertReturn(pIntNet->u32Magic, VERR_INVALID_MAGIC); 3443 3426 3444 AssertPtrReturn(ppRing0Buf, VERR_INVALID_PARAMETER); 3427 3445 *ppRing0Buf = NULL; 3428 AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER);3429 3446 PINTNETIF pIf = (PINTNETIF)RTHandleTableLookupWithCtx(pIntNet->hHtIfs, hIf, pSession); 3430 3447 if (!pIf) … … 3443 3460 } 3444 3461 intnetR0IfRelease(pIf, pSession); 3445 LogFlow(("I NTNETR0IfGetRing0Buffer: returns %Rrc *ppRing0Buf=%p\n", rc, *ppRing0Buf));3462 LogFlow(("IntNetR0IfGetRing0Buffer: returns %Rrc *ppRing0Buf=%p\n", rc, *ppRing0Buf)); 3446 3463 return rc; 3447 3464 } … … 3453 3470 * 3454 3471 * @returns VBox status code. 3455 * @param pIntNet The instance data.3456 3472 * @param hIF The interface handle. 3457 3473 * @param paPages Where to store the addresses. (The reserved fields will be set to zero.) 3458 3474 * @param cPages 3459 3475 */ 3460 INTNETR0DECL(int) I NTNETR0IfGetPhysBuffer(PINTNET pIntNet,INTNETIFHANDLE hIf, PSUPPAGE paPages, unsigned cPages)3476 INTNETR0DECL(int) IntNetR0IfGetPhysBuffer(INTNETIFHANDLE hIf, PSUPPAGE paPages, unsigned cPages) 3461 3477 { 3462 3478 /* 3463 3479 * Validate input. 3464 3480 */ 3465 AssertReturn(pIntNet, VERR_INVALID_PARAMETER); 3481 PINTNET pIntNet = g_pIntNet; 3482 AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER); 3483 AssertReturn(pIntNet->u32Magic, VERR_INVALID_MAGIC); 3484 3466 3485 AssertPtrReturn(paPages, VERR_INVALID_PARAMETER); 3467 3486 AssertPtrReturn((uint8_t *)&paPages[cPages] - 1, VERR_INVALID_PARAMETER); … … 3492 3511 * 3493 3512 * @returns VBox status code. 3494 * @param pIntNet The instance handle.3495 3513 * @param hIf The interface handle. 3496 3514 * @param pSession The caller's session. 3497 3515 * @param fPromiscuous Set if the interface should be in promiscuous mode, clear if not. 3498 3516 */ 3499 INTNETR0DECL(int) I NTNETR0IfSetPromiscuousMode(PINTNET pIntNet,INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, bool fPromiscuous)3500 { 3501 LogFlow(("I NTNETR0IfSetPromiscuousMode: pIntNet=%p hIf=%RX32 fPromiscuous=%d\n", pIntNet, hIf, fPromiscuous));3517 INTNETR0DECL(int) IntNetR0IfSetPromiscuousMode(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, bool fPromiscuous) 3518 { 3519 LogFlow(("IntNetR0IfSetPromiscuousMode: hIf=%RX32 fPromiscuous=%d\n", hIf, fPromiscuous)); 3502 3520 3503 3521 /* 3504 3522 * Validate & translate input. 3505 3523 */ 3506 AssertReturn(pIntNet, VERR_INVALID_PARAMETER); 3524 PINTNET pIntNet = g_pIntNet; 3525 AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER); 3526 AssertReturn(pIntNet->u32Magic, VERR_INVALID_MAGIC); 3527 3507 3528 PINTNETIF pIf = (PINTNETIF)RTHandleTableLookupWithCtx(pIntNet->hHtIfs, hIf, pSession); 3508 3529 if (!pIf) 3509 3530 { 3510 Log(("I NTNETR0IfSetPromiscuousMode: returns VERR_INVALID_HANDLE\n"));3531 Log(("IntNetR0IfSetPromiscuousMode: returns VERR_INVALID_HANDLE\n")); 3511 3532 return VERR_INVALID_HANDLE; 3512 3533 } … … 3526 3547 if (pIf->fPromiscuous != fPromiscuous) 3527 3548 { 3528 Log(("I NTNETR0IfSetPromiscuousMode: hIf=%RX32: Changed from %d -> %d\n",3549 Log(("IntNetR0IfSetPromiscuousMode: hIf=%RX32: Changed from %d -> %d\n", 3529 3550 hIf, !fPromiscuous, !!fPromiscuous)); 3530 3551 ASMAtomicUoWriteBool(&pIf->fPromiscuous, fPromiscuous); … … 3548 3569 3549 3570 /** 3550 * VMMR0 request wrapper for INTNETR0IfSetPromiscuousMode. 3551 * 3552 * @returns see INTNETR0IfSetPromiscuousMode. 3553 * @param pIntNet The internal networking instance. 3571 * VMMR0 request wrapper for IntNetR0IfSetPromiscuousMode. 3572 * 3573 * @returns see IntNetR0IfSetPromiscuousMode. 3554 3574 * @param pSession The caller's session. 3555 3575 * @param pReq The request packet. 3556 3576 */ 3557 INTNETR0DECL(int) I NTNETR0IfSetPromiscuousModeReq(PINTNET pIntNet,PSUPDRVSESSION pSession, PINTNETIFSETPROMISCUOUSMODEREQ pReq)3577 INTNETR0DECL(int) IntNetR0IfSetPromiscuousModeReq(PSUPDRVSESSION pSession, PINTNETIFSETPROMISCUOUSMODEREQ pReq) 3558 3578 { 3559 3579 if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq))) 3560 3580 return VERR_INVALID_PARAMETER; 3561 return I NTNETR0IfSetPromiscuousMode(pIntNet,pReq->hIf, pSession, pReq->fPromiscuous);3581 return IntNetR0IfSetPromiscuousMode(pReq->hIf, pSession, pReq->fPromiscuous); 3562 3582 } 3563 3583 … … 3567 3587 * 3568 3588 * @returns VBox status code. 3569 * @param pIntNet The instance handle.3570 3589 * @param hIf The interface handle. 3571 3590 * @param pSession The caller's session. 3572 3591 * @param pMAC The new MAC address. 3573 3592 */ 3574 INTNETR0DECL(int) I NTNETR0IfSetMacAddress(PINTNET pIntNet,INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, PCRTMAC pMac)3575 { 3576 LogFlow(("I NTNETR0IfSetMacAddress: pIntNet=%p hIf=%RX32 pMac=%p:{%.6Rhxs}\n", pIntNet, hIf, pMac, pMac));3593 INTNETR0DECL(int) IntNetR0IfSetMacAddress(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, PCRTMAC pMac) 3594 { 3595 LogFlow(("IntNetR0IfSetMacAddress: hIf=%RX32 pMac=%p:{%.6Rhxs}\n", hIf, pMac, pMac)); 3577 3596 3578 3597 /* 3579 3598 * Validate & translate input. 3580 3599 */ 3600 PINTNET pIntNet = g_pIntNet; 3581 3601 AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER); 3602 AssertReturn(pIntNet->u32Magic, VERR_INVALID_MAGIC); 3603 3582 3604 AssertPtrReturn(pMac, VERR_INVALID_PARAMETER); 3583 3605 PINTNETIF pIf = (PINTNETIF)RTHandleTableLookupWithCtx(pIntNet->hHtIfs, hIf, pSession); 3584 3606 if (!pIf) 3585 3607 { 3586 Log(("I NTNETR0IfSetMacAddress: returns VERR_INVALID_HANDLE\n"));3608 Log(("IntNetR0IfSetMacAddress: returns VERR_INVALID_HANDLE\n")); 3587 3609 return VERR_INVALID_HANDLE; 3588 3610 } … … 3602 3624 if (memcmp(&pIf->MacAddr, pMac, sizeof(pIf->MacAddr))) 3603 3625 { 3604 Log(("I NTNETR0IfSetMacAddress: hIf=%RX32: Changed from %.6Rhxs -> %.6Rhxs\n",3626 Log(("IntNetR0IfSetMacAddress: hIf=%RX32: Changed from %.6Rhxs -> %.6Rhxs\n", 3605 3627 hIf, &pIf->MacAddr, pMac)); 3606 3628 … … 3624 3646 3625 3647 /** 3626 * VMMR0 request wrapper for INTNETR0IfSetMacAddress. 3627 * 3628 * @returns see INTNETR0IfSetMacAddress. 3629 * @param pIntNet The internal networking instance. 3648 * VMMR0 request wrapper for IntNetR0IfSetMacAddress. 3649 * 3650 * @returns see IntNetR0IfSetMacAddress. 3630 3651 * @param pSession The caller's session. 3631 3652 * @param pReq The request packet. 3632 3653 */ 3633 INTNETR0DECL(int) I NTNETR0IfSetMacAddressReq(PINTNET pIntNet,PSUPDRVSESSION pSession, PINTNETIFSETMACADDRESSREQ pReq)3654 INTNETR0DECL(int) IntNetR0IfSetMacAddressReq(PSUPDRVSESSION pSession, PINTNETIFSETMACADDRESSREQ pReq) 3634 3655 { 3635 3656 if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq))) 3636 3657 return VERR_INVALID_PARAMETER; 3637 return I NTNETR0IfSetMacAddress(pIntNet,pReq->hIf, pSession, &pReq->Mac);3658 return IntNetR0IfSetMacAddress(pReq->hIf, pSession, &pReq->Mac); 3638 3659 } 3639 3660 … … 3716 3737 * 3717 3738 * @returns VBox status code. 3718 * @param pIntNet The instance handle.3719 3739 * @param hIf The interface handle. 3720 3740 * @param pSession The caller's session. 3721 3741 * @param fActive The new state. 3722 3742 */ 3723 INTNETR0DECL(int) I NTNETR0IfSetActive(PINTNET pIntNet,INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, bool fActive)3724 { 3725 LogFlow(("I NTNETR0IfSetActive: pIntNet=%p hIf=%RX32 fActive=%RTbool\n", pIntNet, hIf, fActive));3743 INTNETR0DECL(int) IntNetR0IfSetActive(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, bool fActive) 3744 { 3745 LogFlow(("IntNetR0IfSetActive: hIf=%RX32 fActive=%RTbool\n", hIf, fActive)); 3726 3746 3727 3747 /* 3728 3748 * Validate & translate input. 3729 3749 */ 3750 PINTNET pIntNet = g_pIntNet; 3730 3751 AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER); 3752 AssertReturn(pIntNet->u32Magic, VERR_INVALID_MAGIC); 3753 3731 3754 PINTNETIF pIf = (PINTNETIF)RTHandleTableLookupWithCtx(pIntNet->hHtIfs, hIf, pSession); 3732 3755 if (!pIf) 3733 3756 { 3734 Log(("I NTNETR0IfSetActive: returns VERR_INVALID_HANDLE\n"));3757 Log(("IntNetR0IfSetActive: returns VERR_INVALID_HANDLE\n")); 3735 3758 return VERR_INVALID_HANDLE; 3736 3759 } … … 3759 3782 3760 3783 /** 3761 * VMMR0 request wrapper for I NTNETR0IfSetActive.3762 * 3763 * @returns see I NTNETR0IfSetActive.3784 * VMMR0 request wrapper for IntNetR0IfSetActive. 3785 * 3786 * @returns see IntNetR0IfSetActive. 3764 3787 * @param pIntNet The internal networking instance. 3765 3788 * @param pSession The caller's session. 3766 3789 * @param pReq The request packet. 3767 3790 */ 3768 INTNETR0DECL(int) I NTNETR0IfSetActiveReq(PINTNET pIntNet,PSUPDRVSESSION pSession, PINTNETIFSETACTIVEREQ pReq)3791 INTNETR0DECL(int) IntNetR0IfSetActiveReq(PSUPDRVSESSION pSession, PINTNETIFSETACTIVEREQ pReq) 3769 3792 { 3770 3793 if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq))) 3771 3794 return VERR_INVALID_PARAMETER; 3772 return I NTNETR0IfSetActive(pIntNet,pReq->hIf, pSession, pReq->fActive);3795 return IntNetR0IfSetActive(pReq->hIf, pSession, pReq->fActive); 3773 3796 } 3774 3797 … … 3779 3802 * 3780 3803 * @returns VBox status code. 3781 * @param pIntNet The instance handle.3782 3804 * @param hIf The interface handle. 3783 3805 * @param pSession The caller's session. … … 3785 3807 * used if indefinite wait is desired. 3786 3808 */ 3787 INTNETR0DECL(int) I NTNETR0IfWait(PINTNET pIntNet,INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, uint32_t cMillies)3788 { 3789 Log4(("I NTNETR0IfWait: pIntNet=%p hIf=%RX32 cMillies=%u\n", pIntNet, hIf, cMillies));3809 INTNETR0DECL(int) IntNetR0IfWait(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, uint32_t cMillies) 3810 { 3811 Log4(("IntNetR0IfWait: hIf=%RX32 cMillies=%u\n", hIf, cMillies)); 3790 3812 3791 3813 /* 3792 3814 * Get and validate essential handles. 3793 3815 */ 3816 PINTNET pIntNet = g_pIntNet; 3794 3817 AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER); 3818 AssertReturn(pIntNet->u32Magic, VERR_INVALID_MAGIC); 3819 3795 3820 PINTNETIF pIf = (PINTNETIF)RTHandleTableLookupWithCtx(pIntNet->hHtIfs, hIf, pSession); 3796 3821 if (!pIf) 3797 3822 { 3798 Log(("I NTNETR0IfWait: returns VERR_INVALID_HANDLE\n"));3823 Log(("IntNetR0IfWait: returns VERR_INVALID_HANDLE\n")); 3799 3824 return VERR_INVALID_HANDLE; 3800 3825 } … … 3804 3829 && hRecvEvent != NIL_RTSEMEVENT) 3805 3830 { 3806 Log(("I NTNETR0IfWait: returns VERR_SEM_DESTROYED\n"));3831 Log(("IntNetR0IfWait: returns VERR_SEM_DESTROYED\n")); 3807 3832 return VERR_SEM_DESTROYED; 3808 3833 } … … 3836 3861 else 3837 3862 rc = VERR_SEM_DESTROYED; 3838 Log4(("I NTNETR0IfWait: returns %Rrc\n", rc));3863 Log4(("IntNetR0IfWait: returns %Rrc\n", rc)); 3839 3864 return rc; 3840 3865 } … … 3842 3867 3843 3868 /** 3844 * VMMR0 request wrapper for INTNETR0IfWait. 3845 * 3846 * @returns see INTNETR0IfWait. 3847 * @param pIntNet The internal networking instance. 3869 * VMMR0 request wrapper for IntNetR0IfWait. 3870 * 3871 * @returns see IntNetR0IfWait. 3848 3872 * @param pSession The caller's session. 3849 3873 * @param pReq The request packet. 3850 3874 */ 3851 INTNETR0DECL(int) I NTNETR0IfWaitReq(PINTNET pIntNet,PSUPDRVSESSION pSession, PINTNETIFWAITREQ pReq)3875 INTNETR0DECL(int) IntNetR0IfWaitReq(PSUPDRVSESSION pSession, PINTNETIFWAITREQ pReq) 3852 3876 { 3853 3877 if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq))) 3854 3878 return VERR_INVALID_PARAMETER; 3855 return I NTNETR0IfWait(pIntNet,pReq->hIf, pSession, pReq->cMillies);3879 return IntNetR0IfWait(pReq->hIf, pSession, pReq->cMillies); 3856 3880 } 3857 3881 … … 3865 3889 * @param pSession The caller's session. 3866 3890 */ 3867 INTNETR0DECL(int) I NTNETR0IfClose(PINTNET pIntNet,INTNETIFHANDLE hIf, PSUPDRVSESSION pSession)3868 { 3869 LogFlow(("I NTNETR0IfClose: pIntNet=%p hIf=%RX32\n", pIntNet, hIf));3891 INTNETR0DECL(int) IntNetR0IfClose(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession) 3892 { 3893 LogFlow(("IntNetR0IfClose: hIf=%RX32\n", hIf)); 3870 3894 3871 3895 /* 3872 3896 * Validate and free the handle. 3873 3897 */ 3898 PINTNET pIntNet = g_pIntNet; 3874 3899 AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER); 3900 AssertReturn(pIntNet->u32Magic, VERR_INVALID_MAGIC); 3901 3875 3902 PINTNETIF pIf = (PINTNETIF)RTHandleTableFreeWithCtx(pIntNet->hHtIfs, hIf, pSession); 3876 3903 if (!pIf) … … 3897 3924 3898 3925 int rc = SUPR0ObjRelease(pvObj, pSession); 3899 LogFlow(("I NTNETR0IfClose: returns %Rrc\n", rc));3926 LogFlow(("IntNetR0IfClose: returns %Rrc\n", rc)); 3900 3927 return rc; 3901 3928 } … … 3903 3930 3904 3931 /** 3905 * VMMR0 request wrapper for INTNETR0IfCloseReq. 3906 * 3907 * @returns see INTNETR0IfClose. 3908 * @param pIntNet The internal networking instance. 3932 * VMMR0 request wrapper for IntNetR0IfCloseReq. 3933 * 3934 * @returns see IntNetR0IfClose. 3909 3935 * @param pSession The caller's session. 3910 3936 * @param pReq The request packet. 3911 3937 */ 3912 INTNETR0DECL(int) I NTNETR0IfCloseReq(PINTNET pIntNet,PSUPDRVSESSION pSession, PINTNETIFCLOSEREQ pReq)3938 INTNETR0DECL(int) IntNetR0IfCloseReq(PSUPDRVSESSION pSession, PINTNETIFCLOSEREQ pReq) 3913 3939 { 3914 3940 if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq))) 3915 3941 return VERR_INVALID_PARAMETER; 3916 return I NTNETR0IfClose(pIntNet,pReq->hIf, pSession);3942 return IntNetR0IfClose(pReq->hIf, pSession); 3917 3943 } 3918 3944 … … 5179 5205 * 5180 5206 * @returns VBox status code. 5181 * @param pIntNet The internal network instance.5182 5207 * @param pSession The session handle. 5183 5208 * @param pszNetwork The network name. … … 5190 5215 * @param phIf Where to store the handle to the network interface. 5191 5216 */ 5192 INTNETR0DECL(int) I NTNETR0Open(PINTNET pIntNet,PSUPDRVSESSION pSession, const char *pszNetwork,5217 INTNETR0DECL(int) IntNetR0Open(PSUPDRVSESSION pSession, const char *pszNetwork, 5193 5218 INTNETTRUNKTYPE enmTrunkType, const char *pszTrunk, uint32_t fFlags, 5194 u nsigned cbSend, unsignedcbRecv, PINTNETIFHANDLE phIf)5195 { 5196 LogFlow(("I NTNETR0Open: pIntNet=%ppSession=%p pszNetwork=%p:{%s} enmTrunkType=%d pszTrunk=%p:{%s} fFlags=%#x cbSend=%u cbRecv=%u phIf=%p\n",5197 p IntNet, pSession, pszNetwork, pszNetwork, enmTrunkType, pszTrunk, pszTrunk, fFlags, cbSend, cbRecv, phIf));5219 uint32_t cbSend, uint32_t cbRecv, PINTNETIFHANDLE phIf) 5220 { 5221 LogFlow(("IntNetR0Open: pSession=%p pszNetwork=%p:{%s} enmTrunkType=%d pszTrunk=%p:{%s} fFlags=%#x cbSend=%u cbRecv=%u phIf=%p\n", 5222 pSession, pszNetwork, pszNetwork, enmTrunkType, pszTrunk, pszTrunk, fFlags, cbSend, cbRecv, phIf)); 5198 5223 5199 5224 /* 5200 5225 * Validate input. 5201 5226 */ 5227 PINTNET pIntNet = g_pIntNet; 5202 5228 AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER); 5229 AssertReturn(pIntNet->u32Magic, VERR_INVALID_MAGIC); 5203 5230 5204 5231 AssertPtrReturn(pszNetwork, VERR_INVALID_PARAMETER); … … 5273 5300 5274 5301 RTSemMutexRelease(pIntNet->hMtxCreateOpenDestroy); 5275 LogFlow(("I NTNETR0Open: return %Rrc *phIf=%RX32\n", rc, *phIf));5302 LogFlow(("IntNetR0Open: return %Rrc *phIf=%RX32\n", rc, *phIf)); 5276 5303 return rc; 5277 5304 } … … 5282 5309 * 5283 5310 * @returns see GMMR0MapUnmapChunk. 5284 * @param pIntNet The internal networking instance.5285 5311 * @param pSession The caller's session. 5286 5312 * @param pReq The request packet. 5287 5313 */ 5288 INTNETR0DECL(int) I NTNETR0OpenReq(PINTNET pIntNet,PSUPDRVSESSION pSession, PINTNETOPENREQ pReq)5314 INTNETR0DECL(int) IntNetR0OpenReq(PSUPDRVSESSION pSession, PINTNETOPENREQ pReq) 5289 5315 { 5290 5316 if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq))) 5291 5317 return VERR_INVALID_PARAMETER; 5292 return I NTNETR0Open(pIntNet,pSession, &pReq->szNetwork[0], pReq->enmTrunkType, pReq->szTrunk,5318 return IntNetR0Open(pSession, &pReq->szNetwork[0], pReq->enmTrunkType, pReq->szTrunk, 5293 5319 pReq->fFlags, pReq->cbSend, pReq->cbRecv, &pReq->hIf); 5294 5320 } … … 5296 5322 5297 5323 /** 5324 * Count the internal networks. 5325 * 5326 * This is mainly for providing the testcase with some introspection to validate 5327 * behavior when closing interfaces. 5328 * 5329 * @returns The number of networks. 5330 */ 5331 INTNETR0DECL(uint32_t) IntNetR0GetNetworkCount(void) 5332 { 5333 /* 5334 * Grab the instance. 5335 */ 5336 PINTNET pIntNet = g_pIntNet; 5337 if (!pIntNet) 5338 return 0; 5339 AssertPtrReturn(pIntNet, 0); 5340 AssertReturn(pIntNet->u32Magic == INTNET_MAGIC, 0); 5341 5342 /* 5343 * Grab the mutex and count the networks. 5344 */ 5345 int rc = RTSemMutexRequest(pIntNet->hMtxCreateOpenDestroy, RT_INDEFINITE_WAIT); 5346 if (RT_FAILURE(rc)) 5347 return 0; 5348 5349 uint32_t cNetworks = 0; 5350 for (PINTNETNETWORK pCur = pIntNet->pNetworks; pCur; pCur = pCur->pNext) 5351 cNetworks++; 5352 5353 RTSemMutexRelease(pIntNet->hMtxCreateOpenDestroy); 5354 5355 return cNetworks; 5356 } 5357 5358 5359 5360 /** 5298 5361 * Destroys an instance of the Ring-0 internal networking service. 5299 * 5300 * @param pIntNet Pointer to the instance data. 5301 */ 5302 INTNETR0DECL(void) INTNETR0Destroy(PINTNET pIntNet) 5303 { 5304 LogFlow(("INTNETR0Destroy: pIntNet=%p\n", pIntNet));5305 5306 /*5307 * Allow NULL pointers.5308 */5362 */ 5363 INTNETR0DECL(void) IntNetR0Term(void) 5364 { 5365 LogFlow(("IntNetR0Term:\n")); 5366 5367 /* 5368 * Zap the global pointer and validate it. 5369 */ 5370 PINTNET pIntNet = g_pIntNet; 5371 g_pIntNet = NULL; 5309 5372 if (!pIntNet) 5310 5373 return; 5311 5374 AssertPtrReturnVoid(pIntNet); 5375 AssertReturnVoid(pIntNet->u32Magic == INTNET_MAGIC); 5312 5376 5313 5377 /* 5314 5378 * There is not supposed to be any networks hanging around at this time. 5315 5379 */ 5380 AssertReturnVoid(ASMAtomicCmpXchgU32(&pIntNet->u32Magic, ~INTNET_MAGIC, INTNET_MAGIC)); 5316 5381 Assert(pIntNet->pNetworks == NULL); 5317 5382 if (pIntNet->hMtxCreateOpenDestroy != NIL_RTSEMMUTEX) … … 5332 5397 5333 5398 /** 5334 * Create an instance of the Ring-0 internal networkingservice.5399 * Initalizes the internal network ring-0 service. 5335 5400 * 5336 5401 * @returns VBox status code. 5337 * @param ppIntNet Where to store the instance pointer. 5338 */ 5339 INTNETR0DECL(int) INTNETR0Create(PINTNET *ppIntNet) 5340 { 5341 LogFlow(("INTNETR0Create: ppIntNet=%p\n", ppIntNet)); 5402 */ 5403 INTNETR0DECL(int) IntNetR0Init(void) 5404 { 5405 LogFlow(("IntNetR0Init:\n")); 5342 5406 int rc = VERR_NO_MEMORY; 5343 5407 PINTNET pIntNet = (PINTNET)RTMemAllocZ(sizeof(*pIntNet)); … … 5353 5417 if (RT_SUCCESS(rc)) 5354 5418 { 5355 *ppIntNet = pIntNet; 5356 LogFlow(("INTNETR0Create: returns VINF_SUCCESS *ppIntNet=%p\n", pIntNet)); 5419 pIntNet->u32Magic = INTNET_MAGIC; 5420 g_pIntNet = pIntNet; 5421 LogFlow(("IntNetR0Init: returns VINF_SUCCESS pIntNet=%p\n", pIntNet)); 5357 5422 return VINF_SUCCESS; 5358 5423 } … … 5362 5427 RTMemFree(pIntNet); 5363 5428 } 5364 *ppIntNet = NULL; 5365 LogFlow(("INTNETR0Create: returns %Rrc\n", rc)); 5429 LogFlow(("IntNetR0Init: returns %Rrc\n", rc)); 5366 5430 return rc; 5367 5431 } -
trunk/src/VBox/Devices/Network/testcase/tstIntNetR0.cpp
r28623 r28706 190 190 * Sends the data @a pvBuf points to. 191 191 */ 192 static int tstIntNetSendBuf(PINTNET pIntNet, PINTNETRINGBUF pRingBuf, INTNETIFHANDLE hIf,192 static int tstIntNetSendBuf(PINTNETRINGBUF pRingBuf, INTNETIFHANDLE hIf, 193 193 PSUPDRVSESSION pSession, void const *pvBuf, size_t cbBuf) 194 194 { … … 197 197 int rc = intnetR0RingWriteFrame(pRingBuf, &Sg, NULL); 198 198 if (RT_SUCCESS(rc)) 199 rc = I NTNETR0IfSend(pIntNet,hIf, pSession);199 rc = IntNetR0IfSend(hIf, pSession); 200 200 return rc; 201 201 } … … 204 204 typedef struct MYARGS 205 205 { 206 PINTNET pIntNet;207 206 PINTNETBUF pBuf; 208 207 INTNETIFHANDLE hIf; … … 258 257 RTTEST_CHECK_RC_OK(g_hTest, rc = intnetR0RingWriteFrame(&pArgs->pBuf->Send, &Sg, NULL)); 259 258 if (RT_SUCCESS(rc)) 260 RTTEST_CHECK_RC_OK(g_hTest, rc = I NTNETR0IfSend(pArgs->pIntNet,pArgs->hIf, g_pSession));259 RTTEST_CHECK_RC_OK(g_hTest, rc = IntNetR0IfSend(pArgs->hIf, g_pSession)); 261 260 cbSent += cb; 262 261 } … … 271 270 for (unsigned c = 0; c < 20; c++) 272 271 { 273 RTTEST_CHECK_RC_OK(g_hTest, rc = tstIntNetSendBuf( pArgs->pIntNet,&pArgs->pBuf->Send, pArgs->hIf, g_pSession,272 RTTEST_CHECK_RC_OK(g_hTest, rc = tstIntNetSendBuf(&pArgs->pBuf->Send, pArgs->hIf, g_pSession, 274 273 abBuf, sizeof(RTMAC) * 2 + sizeof(unsigned) * 4)); 275 274 RTThreadSleep(1); … … 363 362 * Wait for data. 364 363 */ 365 int rc = I NTNETR0IfWait(pArgs->pIntNet,pArgs->hIf, g_pSession, RT_INDEFINITE_WAIT);364 int rc = IntNetR0IfWait(pArgs->hIf, g_pSession, RT_INDEFINITE_WAIT); 366 365 switch (rc) 367 366 { … … 390 389 typedef struct TSTSTATE 391 390 { 392 PINTNET pIntNet;393 394 391 PINTNETBUF pBuf0; 395 392 INTNETIFHANDLE hIf0; … … 410 407 { 411 408 pThis->hIf0 = INTNET_HANDLE_INVALID; 412 RTTESTI_CHECK_RC_OK_RET(I NTNETR0Open(pThis->pIntNet,g_pSession, pszNetwork, kIntNetTrunkType_None, "",409 RTTESTI_CHECK_RC_OK_RET(IntNetR0Open(g_pSession, pszNetwork, kIntNetTrunkType_None, "", 413 410 0/*fFlags*/, cbSend, cbRecv, &pThis->hIf0), rcCheck); 414 411 RTTESTI_CHECK_RET(pThis->hIf0 != INTNET_HANDLE_INVALID, VERR_INTERNAL_ERROR); 415 RTTESTI_CHECK_RC_RET(I NTNETR0IfGetRing0Buffer(pThis->pIntNet,pThis->hIf0, g_pSession, &pThis->pBuf0), VINF_SUCCESS, rcCheck);412 RTTESTI_CHECK_RC_RET(IntNetR0IfGetRing0Buffer(pThis->hIf0, g_pSession, &pThis->pBuf0), VINF_SUCCESS, rcCheck); 416 413 RTTESTI_CHECK_RET(pThis->pBuf0, VERR_INTERNAL_ERROR); 417 414 418 415 419 416 pThis->hIf1 = INTNET_HANDLE_INVALID; 420 RTTESTI_CHECK_RC_OK_RET(I NTNETR0Open(pThis->pIntNet,g_pSession, pszNetwork, kIntNetTrunkType_None, "",417 RTTESTI_CHECK_RC_OK_RET(IntNetR0Open(g_pSession, pszNetwork, kIntNetTrunkType_None, "", 421 418 0/*fFlags*/, cbSend, cbRecv, &pThis->hIf1), rcCheck); 422 419 RTTESTI_CHECK_RET(pThis->hIf1 != INTNET_HANDLE_INVALID, VERR_INTERNAL_ERROR); 423 RTTESTI_CHECK_RC_RET(I NTNETR0IfGetRing0Buffer(pThis->pIntNet,pThis->hIf1, g_pSession, &pThis->pBuf1), VINF_SUCCESS, rcCheck);420 RTTESTI_CHECK_RC_RET(IntNetR0IfGetRing0Buffer(pThis->hIf1, g_pSession, &pThis->pBuf1), VINF_SUCCESS, rcCheck); 424 421 RTTESTI_CHECK_RET(pThis->pBuf1, VERR_INTERNAL_ERROR); 425 422 … … 435 432 { 436 433 int rc; 437 RTTESTI_CHECK_RC_OK(rc = I NTNETR0IfClose(pThis->pIntNet,pThis->hIf0, g_pSession));434 RTTESTI_CHECK_RC_OK(rc = IntNetR0IfClose(pThis->hIf0, g_pSession)); 438 435 if (RT_SUCCESS(rc)) 439 436 { … … 442 439 } 443 440 444 RTTESTI_CHECK_RC_OK(rc = I NTNETR0IfClose(pThis->pIntNet,pThis->hIf1, g_pSession));441 RTTESTI_CHECK_RC_OK(rc = IntNetR0IfClose(pThis->hIf1, g_pSession)); 445 442 if (RT_SUCCESS(rc)) 446 443 { … … 450 447 451 448 /* The network should be dead now. */ 452 RTTESTI_CHECK( pThis->pIntNet->pNetworks == NULL);449 RTTESTI_CHECK(IntNetR0GetNetworkCount() == 0); 453 450 } 454 451 … … 462 459 Args0.hIf = pThis->hIf0; 463 460 Args0.pBuf = pThis->pBuf0; 464 Args0.pIntNet = pThis->pIntNet;465 461 Args0.Mac.au16[0] = 0x8086; 466 462 Args0.Mac.au16[1] = 0; … … 471 467 Args1.hIf = pThis->hIf1; 472 468 Args1.pBuf = pThis->pBuf1; 473 Args1.pIntNet = pThis->pIntNet;474 469 Args1.Mac.au16[0] = 0x8086; 475 470 Args1.Mac.au16[1] = 0; … … 592 587 static uint16_t const s_au16Frame[7] = { /* dst:*/ 0xffff, 0xffff, 0xffff, /*src:*/0x8086, 0, 0, 0x0800 }; 593 588 594 RTTESTI_CHECK_RC_RETV(tstIntNetSendBuf( pThis->pIntNet,&pThis->pBuf0->Send, pThis->hIf0,589 RTTESTI_CHECK_RC_RETV(tstIntNetSendBuf(&pThis->pBuf0->Send, pThis->hIf0, 595 590 g_pSession, &s_au16Frame, sizeof(s_au16Frame)), 596 591 VINF_SUCCESS); 597 592 598 593 /* No echo, please */ 599 RTTESTI_CHECK_RC_RETV(I NTNETR0IfWait(pThis->pIntNet,pThis->hIf0, g_pSession, 1), VERR_TIMEOUT);594 RTTESTI_CHECK_RC_RETV(IntNetR0IfWait(pThis->hIf0, g_pSession, 1), VERR_TIMEOUT); 600 595 601 596 /* The other interface should see it though. But Wait should only return once, thank you. */ 602 RTTESTI_CHECK_RC_RETV(I NTNETR0IfWait(pThis->pIntNet,pThis->hIf1, g_pSession, 1), VINF_SUCCESS);603 RTTESTI_CHECK_RC_RETV(I NTNETR0IfWait(pThis->pIntNet,pThis->hIf1, g_pSession, 0), VERR_TIMEOUT);597 RTTESTI_CHECK_RC_RETV(IntNetR0IfWait(pThis->hIf1, g_pSession, 1), VINF_SUCCESS); 598 RTTESTI_CHECK_RC_RETV(IntNetR0IfWait(pThis->hIf1, g_pSession, 0), VERR_TIMEOUT); 604 599 605 600 /* Receive the data. */ … … 631 626 static uint16_t const s_au16Frame[7] = { /* dst:*/ 0x8086, 0, 0, /*src:*/0x8086, 0, 1, 0x0800 }; 632 627 633 RTTESTI_CHECK_RC_RETV(tstIntNetSendBuf( pThis->pIntNet,&pThis->pBuf1->Send, pThis->hIf1,628 RTTESTI_CHECK_RC_RETV(tstIntNetSendBuf(&pThis->pBuf1->Send, pThis->hIf1, 634 629 g_pSession, s_au16Frame, sizeof(s_au16Frame)), 635 630 VINF_SUCCESS); 636 631 637 632 /* No echo, please */ 638 RTTESTI_CHECK_RC_RETV(I NTNETR0IfWait(pThis->pIntNet,pThis->hIf1, g_pSession, 1), VERR_TIMEOUT);633 RTTESTI_CHECK_RC_RETV(IntNetR0IfWait(pThis->hIf1, g_pSession, 1), VERR_TIMEOUT); 639 634 640 635 /* The other interface should see it though. But Wait should only return once, thank you. */ 641 RTTESTI_CHECK_RC_RETV(I NTNETR0IfWait(pThis->pIntNet,pThis->hIf0, g_pSession, 1), VINF_SUCCESS);642 RTTESTI_CHECK_RC_RETV(I NTNETR0IfWait(pThis->pIntNet,pThis->hIf0, g_pSession, 0), VERR_TIMEOUT);636 RTTESTI_CHECK_RC_RETV(IntNetR0IfWait(pThis->hIf0, g_pSession, 1), VINF_SUCCESS); 637 RTTESTI_CHECK_RC_RETV(IntNetR0IfWait(pThis->hIf0, g_pSession, 0), VERR_TIMEOUT); 643 638 644 639 /* Receive the data. */ … … 666 661 * Create an INTNET instance. 667 662 */ 668 RTTestISub("I NTNETR0Create");669 RTTESTI_CHECK_RC_RETV(I NTNETR0Create(&pThis->pIntNet), VINF_SUCCESS);663 RTTestISub("IntNetR0Init"); 664 RTTESTI_CHECK_RC_RETV(IntNetR0Init(), VINF_SUCCESS); 670 665 671 666 /* … … 676 671 if (RT_FAILURE(rc)) 677 672 return; 678 RTTESTI_CHECK_RC(I NTNETR0IfSetActive(pThis->pIntNet,pThis->hIf0, g_pSession, true), VINF_SUCCESS);679 RTTESTI_CHECK_RC(I NTNETR0IfSetActive(pThis->pIntNet,pThis->hIf1, g_pSession, true), VINF_SUCCESS);673 RTTESTI_CHECK_RC(IntNetR0IfSetActive(pThis->hIf0, g_pSession, true), VINF_SUCCESS); 674 RTTESTI_CHECK_RC(IntNetR0IfSetActive(pThis->hIf1, g_pSession, true), VINF_SUCCESS); 680 675 681 676 /* 682 677 * Test basic waiting. 683 678 */ 684 RTTestISub("I NTNETR0IfWait");685 RTTESTI_CHECK_RC(I NTNETR0IfWait(pThis->pIntNet,pThis->hIf0, g_pSession, 1), VERR_TIMEOUT);686 RTTESTI_CHECK_RC(I NTNETR0IfWait(pThis->pIntNet,pThis->hIf0, g_pSession, 0), VERR_TIMEOUT);687 RTTESTI_CHECK_RC(I NTNETR0IfWait(pThis->pIntNet,pThis->hIf1, g_pSession, 1), VERR_TIMEOUT);688 RTTESTI_CHECK_RC(I NTNETR0IfWait(pThis->pIntNet,pThis->hIf1, g_pSession, 0), VERR_TIMEOUT);679 RTTestISub("IntNetR0IfWait"); 680 RTTESTI_CHECK_RC(IntNetR0IfWait(pThis->hIf0, g_pSession, 1), VERR_TIMEOUT); 681 RTTESTI_CHECK_RC(IntNetR0IfWait(pThis->hIf0, g_pSession, 0), VERR_TIMEOUT); 682 RTTESTI_CHECK_RC(IntNetR0IfWait(pThis->hIf1, g_pSession, 1), VERR_TIMEOUT); 683 RTTESTI_CHECK_RC(IntNetR0IfWait(pThis->hIf1, g_pSession, 0), VERR_TIMEOUT); 689 684 690 685 /* … … 718 713 */ 719 714 tstCloseInterfaces(pThis); 720 I NTNETR0Destroy(pThis->pIntNet);715 IntNetR0Term(); 721 716 } 722 717
Note:
See TracChangeset
for help on using the changeset viewer.