Changeset 39955 in vbox for trunk/src/VBox/Devices/Network/DrvTAP.cpp
- Timestamp:
- Feb 2, 2012 12:19:41 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DrvTAP.cpp
r37596 r39955 39 39 # include <iprt/process.h> 40 40 # include <iprt/env.h> 41 # ifdef VBOX_WITH_CROSSBOW42 # include <iprt/mem.h>43 # endif44 41 #endif 45 42 … … 61 58 # include <stdlib.h> 62 59 # include <stdio.h> 63 # ifdef VBOX_WITH_CROSSBOW64 # include "solaris/vbox-libdlpi.h"65 # endif66 60 #else 67 61 # include <sys/fcntl.h> … … 98 92 char *pszDeviceName; 99 93 #ifdef RT_OS_SOLARIS 100 # ifdef VBOX_WITH_CROSSBOW101 /** Crossbow: MAC address of the device. */102 RTMAC MacAddress;103 /** Crossbow: Handle of the NIC. */104 dlpi_handle_t pDeviceHandle;105 # else106 94 /** IP device file handle (/dev/udp). */ 107 95 int iIPFileDes; 108 # endif109 96 /** Whether device name is obtained from setup application. */ 110 97 bool fStatic; … … 157 144 *******************************************************************************/ 158 145 #ifdef RT_OS_SOLARIS 159 # ifdef VBOX_WITH_CROSSBOW160 static int SolarisOpenVNIC(PDRVTAP pThis);161 static int SolarisDLPIErr2VBoxErr(int rc);162 # else163 146 static int SolarisTAPAttach(PDRVTAP pThis); 164 # endif165 147 #endif 166 148 … … 391 373 char achBuf[16384]; 392 374 size_t cbRead = 0; 393 #ifdef VBOX_WITH_CROSSBOW394 cbRead = sizeof(achBuf);395 rc = g_pfnLibDlpiRecv(pThis->pDeviceHandle, NULL, NULL, achBuf, &cbRead, -1, NULL);396 rc = RT_LIKELY(rc == DLPI_SUCCESS) ? VINF_SUCCESS : SolarisDLPIErr2VBoxErr(rc);397 #else398 375 /** @note At least on Linux we will never receive more than one network packet 399 376 * after poll() returned successfully. I don't know why but a second 400 377 * RTFileRead() operation will return with VERR_TRY_AGAIN in any case. */ 401 378 rc = RTFileRead(pThis->hFileDevice, achBuf, sizeof(achBuf), &cbRead); 402 #endif403 379 if (RT_SUCCESS(rc)) 404 380 { … … 515 491 char szCommand[4096]; 516 492 517 #ifdef VBOX_WITH_CROSSBOW518 /* Convert MAC address bytes to string (required by Solaris' dladm). */519 char *pszHex = "0123456789abcdef";520 uint8_t *pMacAddr8 = pThis->MacAddress.au8;521 char szMacAddress[3 * sizeof(RTMAC)];522 for (unsigned int i = 0; i < sizeof(RTMAC); i++)523 {524 szMacAddress[3 * i] = pszHex[((*pMacAddr8 >> 4) & 0x0f)];525 szMacAddress[3 * i + 1] = pszHex[(*pMacAddr8 & 0x0f)];526 szMacAddress[3 * i + 2] = ':';527 *pMacAddr8++;528 }529 szMacAddress[sizeof(szMacAddress) - 1] = 0;530 531 RTStrPrintf(szCommand, sizeof(szCommand), "%s %s %s", pThis->pszSetupApplication,532 szMacAddress, pThis->fStatic ? pThis->pszDeviceName : "");533 #else534 493 RTStrPrintf(szCommand, sizeof(szCommand), "%s %s", pThis->pszSetupApplication, 535 494 pThis->fStatic ? pThis->pszDeviceName : ""); 536 #endif537 495 538 496 /* Pipe open the setup application. */ … … 623 581 624 582 #ifdef RT_OS_SOLARIS 625 # ifdef VBOX_WITH_CROSSBOW626 /**627 * Crossbow: Open & configure the virtual NIC.628 *629 * @returns VBox error code.630 * @param pThis The instance data.631 */632 static int SolarisOpenVNIC(PDRVTAP pThis)633 {634 /*635 * Open & bind the NIC using the datalink provider routine.636 */637 int rc = g_pfnLibDlpiOpen(pThis->pszDeviceName, &pThis->pDeviceHandle, DLPI_RAW);638 if (rc != DLPI_SUCCESS)639 return PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS,640 N_("Failed to open VNIC \"%s\" in raw mode"), pThis->pszDeviceName);641 642 dlpi_info_t vnicInfo;643 rc = g_pfnLibDlpiInfo(pThis->pDeviceHandle, &vnicInfo, 0);644 if (rc == DLPI_SUCCESS)645 {646 if (vnicInfo.di_mactype == DL_ETHER)647 {648 rc = g_pfnLibDlpiBind(pThis->pDeviceHandle, DLPI_ANY_SAP, NULL);649 if (rc == DLPI_SUCCESS)650 {651 rc = g_pfnLibDlpiSetPhysAddr(pThis->pDeviceHandle, DL_CURR_PHYS_ADDR, &pThis->MacAddress, ETHERADDRL);652 if (rc == DLPI_SUCCESS)653 {654 rc = g_pfnLibDlpiPromiscon(pThis->pDeviceHandle, DL_PROMISC_SAP);655 if (rc == DLPI_SUCCESS)656 {657 /* Need to use DL_PROMIS_PHYS (not multicast) as we cannot be sure what the guest needs. */658 rc = g_pfnLibDlpiPromiscon(pThis->pDeviceHandle, DL_PROMISC_PHYS);659 if (rc == DLPI_SUCCESS)660 {661 int fd = g_pfnLibDlpiFd(pThis->pDeviceHandle);662 if (pThis->FileDevice >= 0)663 {664 rc = RTFileFromNative(&pThis->hFileDevice, fd);665 if (RT_SUCCESS(rc))666 {667 Log(("SolarisOpenVNIC: %s -> %RTfile\n", pThis->pszDeviceName, pThis->hFileDevice));668 return VINF_SUCCESS;669 }670 }671 else672 rc = PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS,673 N_("Failed to obtain file descriptor for VNIC"));674 }675 else676 rc = PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS,677 N_("Failed to set appropriate promiscuous mode"));678 }679 else680 rc = PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS,681 N_("Failed to activate promiscuous mode for VNIC"));682 }683 else684 rc = PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS,685 N_("Failed to set physical address for VNIC"));686 }687 else688 rc = PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS,689 N_("Failed to bind VNIC"));690 }691 else692 rc = PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS,693 N_("VNIC type is not ethernet"));694 }695 else696 rc = PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS,697 N_("Failed to obtain VNIC info"));698 g_pfnLibDlpiClose(pThis->pDeviceHandle);699 return rc;700 }701 702 703 /**704 * Crossbow: Converts a Solaris DLPI error code to a VBox error code.705 *706 * @returns corresponding VBox error code.707 * @param rc DLPI error code (DLPI_* defines).708 */709 static int SolarisDLPIErr2VBoxErr(int rc)710 {711 switch (rc)712 {713 case DLPI_SUCCESS: return VINF_SUCCESS;714 case DLPI_EINVAL: return VERR_INVALID_PARAMETER;715 case DLPI_ELINKNAMEINVAL: return VERR_INVALID_NAME;716 case DLPI_EINHANDLE: return VERR_INVALID_HANDLE;717 case DLPI_ETIMEDOUT: return VERR_TIMEOUT;718 case DLPI_FAILURE: return VERR_GENERAL_FAILURE;719 720 case DLPI_EVERNOTSUP:721 case DLPI_EMODENOTSUP:722 case DLPI_ERAWNOTSUP:723 /* case DLPI_ENOTENOTSUP: */724 case DLPI_EUNAVAILSAP: return VERR_NOT_SUPPORTED;725 726 /* Define VBox error codes for these, if really needed. */727 case DLPI_ENOLINK:728 case DLPI_EBADLINK:729 /* case DLPI_ENOTEIDINVAL: */730 case DLPI_EBADMSG:731 case DLPI_ENOTSTYLE2: return VERR_GENERAL_FAILURE;732 }733 734 AssertMsgFailed(("SolarisDLPIErr2VBoxErr: Unhandled error %d\n", rc));735 return VERR_UNRESOLVED_ERROR;736 }737 738 # else /* VBOX_WITH_CROSSBOW */739 740 583 /** From net/if_tun.h, installed by Universal TUN/TAP driver */ 741 584 # define TUNNEWPPA (('T'<<16) | 0x0001) … … 897 740 } 898 741 899 # endif /* VBOX_WITH_CROSSBOW */900 742 #endif /* RT_OS_SOLARIS */ 901 743 … … 948 790 pThis->hFileDevice = NIL_RTFILE; 949 791 } 950 951 # ifndef VBOX_WITH_CROSSBOW952 if (pThis->iIPFileDes != -1)953 {954 close(pThis->iIPFileDes);955 pThis->iIPFileDes = -1;956 }957 # endif958 792 959 793 /* … … 1014 848 pThis->pszDeviceName = NULL; 1015 849 #ifdef RT_OS_SOLARIS 1016 # ifdef VBOX_WITH_CROSSBOW1017 pThis->pDeviceHandle = NULL;1018 # else1019 850 pThis->iIPFileDes = -1; 1020 # endif1021 851 pThis->fStatic = true; 1022 852 #endif … … 1093 923 return PDMDRV_SET_ERROR(pDrvIns, rc, N_("Configuration error: failed to query \"TAPTerminateApplication\"")); 1094 924 1095 # ifdef VBOX_WITH_CROSSBOW1096 rc = CFGMR3QueryBytes(pCfg, "MAC", &pThis->MacAddress, sizeof(pThis->MacAddress));1097 if (RT_FAILURE(rc))1098 return PDMDRV_SET_ERROR(pDrvIns, rc, N_("Configuration error: Failed to query \"MAC\""));1099 # endif1100 1101 925 rc = CFGMR3QueryStringAlloc(pCfg, "Device", &pThis->pszDeviceName); 1102 926 if (RT_FAILURE(rc)) … … 1115 939 * Do the setup. 1116 940 */ 1117 # ifdef VBOX_WITH_CROSSBOW1118 if (!VBoxLibDlpiFound())1119 {1120 return PDMDrvHlpVMSetError(pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS,1121 N_("Failed to load library %s required for host interface networking."), LIB_DLPI);1122 }1123 rc = SolarisOpenVNIC(pThis);1124 # else1125 941 rc = SolarisTAPAttach(pThis); 1126 # endif1127 942 if (RT_FAILURE(rc)) 1128 943 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.