Changeset 5719 in vbox
- Timestamp:
- Nov 13, 2007 11:05:17 AM (17 years ago)
- Location:
- trunk/src/VBox/Devices
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Makefile.kmk
r5718 r5719 138 138 VBoxDD_LIBS += adm 139 139 ifdef VBOX_WITH_CROSSBOW 140 VBoxDD_LIBS += dl adm # or maybe try libdladm.so.1 ?140 VBoxDD_LIBS += dlpi 141 141 endif 142 142 ifdef VBOX_WITH_SUID_WRAPPER … … 530 530 ifdef VBOX_WITH_CROSSBOW 531 531 Drivers_DEFS += VBOX_WITH_CROSSBOW 532 Drivers_INCS += \533 Network/solaris534 532 endif 535 533 ifdef VBOX_WITH_SUID_WRAPPER -
trunk/src/VBox/Devices/Network/DrvTAP.cpp
r5701 r5719 59 59 # include <ctype.h> 60 60 # include <stdlib.h> 61 # include <stdio.h> 61 62 # ifdef VBOX_WITH_CROSSBOW 62 # include <limits.h>63 63 # include <libdlpi.h> 64 # include <libdlvnic.h>65 64 # endif 66 65 #else … … 105 104 char *pszDeviceName; 106 105 #ifdef RT_OS_SOLARIS 107 /** The actual TAP/VNIC device name. */108 char *pszDeviceNameActual;109 106 # ifdef VBOX_WITH_CROSSBOW 110 107 /** Crossbow: MAC address of the device. */ … … 112 109 /** Crossbow: Handle of the NIC. */ 113 110 dlpi_handle_t pDeviceHandle; 114 /** Crossbow: ID of the virtual NIC. */115 uint_t uDeviceID;116 111 # else 117 112 /** IP device file handle (/dev/udp). */ 118 113 RTFILE IPFileDevice; 119 114 # endif 115 /** Whether device name is obtained from setup application. */ 116 bool fStatic; 120 117 #endif 121 118 /** TAP setup application. */ … … 174 171 #ifdef RT_OS_SOLARIS 175 172 # ifdef VBOX_WITH_CROSSBOW 176 static int SolarisCreateVNIC(PDRVTAP pData); 177 static int SolarisGetNIC(char *pszNICName, size_t cbSize); 178 static int SolarisOpenNIC(PDRVTAP pData, const char *pszNICName); 173 static int SolarisOpenVNIC(PDRVTAP pData); 179 174 static int SolarisDLPIErr2VBoxErr(int rc); 180 175 # else 181 static int SolarisTAPAttach(P PDMDRVINS pDrvIns);176 static int SolarisTAPAttach(PDRVTAP pData); 182 177 # endif 183 178 #endif … … 509 504 static int drvTAPSetupApplication(PDRVTAP pData) 510 505 { 506 char szCommand[4096]; 507 508 #ifdef VBOX_WITH_CROSSBOW 509 /* Convert MAC address bytes to string (required by Solaris' dladm). */ 510 char *pszHex = "0123456789abcdef"; 511 uint8_t *pMacAddr8 = pData->MacAddress.au8; 512 char szMacAddress[3 * sizeof(PDMMAC)]; 513 for (unsigned int i = 0; i < sizeof(PDMMAC); i++) 514 { 515 szMacAddress[3 * i] = pszHex[((*pMacAddr8 >> 4) & 0x0f)]; 516 szMacAddress[3 * i + 1] = pszHex[(*pMacAddr8 & 0x0f)]; 517 szMacAddress[3 * i + 2] = ':'; 518 *pMacAddr8++; 519 } 520 szMacAddress[sizeof(szMacAddress) - 1] = 0; 521 522 RTStrPrintf(szCommand, sizeof(szCommand), "%s %s %s", pData->pszSetupApplication, 523 szMacAddress, pData->fStatic ? pData->pszDeviceName : ""); 524 #else 525 RTStrPrintf(szCommand, sizeof(szCommand), "%s %s", pData->pszSetupApplication, 526 pData->fStatic ? pData->pszDeviceName : ""); 527 #endif 528 529 /* Pipe open the setup application. */ 530 Log2(("Starting TAP setup application: %s\n", szCommand)); 531 FILE* pfSetupHandle = popen(szCommand, "r"); 532 if (pfSetupHandle == 0) 533 { 534 LogRel(("TAP#%d: Failed to run TAP setup application: %s\n", pData->pDrvIns->iInstance, 535 pData->pszSetupApplication, strerror(errno))); 536 return VERR_HOSTIF_INIT_FAILED; 537 } 538 if (!pData->fStatic) 539 { 540 /* Obtain device name from setup application. */ 541 char acBuffer[64]; 542 size_t cBufSize; 543 fgets(acBuffer, sizeof(acBuffer), pfSetupHandle); 544 cBufSize = strlen(acBuffer); 545 /* The script must return the name of the interface followed by a carriage return as the 546 first line of its output. We need a null-terminated string. */ 547 if ((cBufSize < 2) || (acBuffer[cBufSize - 1] != '\n')) 548 { 549 pclose(pfSetupHandle); 550 LogRel(("The TAP interface setup script did not return the name of a TAP device.\n")); 551 return VERR_HOSTIF_INIT_FAILED; 552 } 553 /* Overwrite the terminating newline character. */ 554 acBuffer[cBufSize - 1] = 0; 555 RTStrAPrintf(&pData->pszDeviceName, "%s", acBuffer); 556 } 557 int rc = pclose(pfSetupHandle); 558 if (!WIFEXITED(rc)) 559 { 560 LogRel(("The TAP interface setup script terminated abnormally.\n")); 561 return VERR_HOSTIF_INIT_FAILED; 562 } 563 if (WEXITSTATUS(rc) != 0) 564 { 565 LogRel(("The TAP interface setup script returned a non-zero exit code.\n")); 566 return VERR_HOSTIF_INIT_FAILED; 567 } 568 return VINF_SUCCESS; 569 } 570 571 572 /** 573 * Calls OS-specific TAP terminate application/script. 574 * 575 * @returns VBox error code. 576 * @param pData The instance data. 577 */ 578 static int drvTAPTerminateApplication(PDRVTAP pData) 579 { 511 580 char *pszArgs[3]; 512 pszArgs[0] = pData->psz SetupApplication;513 pszArgs[1] = pData->pszDeviceName Actual;581 pszArgs[0] = pData->pszTerminateApplication; 582 pszArgs[1] = pData->pszDeviceName; 514 583 pszArgs[2] = NULL; 515 584 516 Log2(("Starting TAP setup application: %s %s\n", pData->pszSetupApplication, pData->pszDeviceNameActual));585 Log2(("Starting TAP terminate application: %s %s\n", pData->pszTerminateApplication, pData->pszDeviceName)); 517 586 RTPROCESS pid = NIL_RTPROCESS; 518 587 int rc = RTProcCreate(pszArgs[0], pszArgs, RTENV_DEFAULT, 0, &pid); … … 527 596 return VINF_SUCCESS; 528 597 529 LogRel(("TAP#%d: Error running TAP setup application: %s\n", pData->pDrvIns->iInstance, pData->pszSetupApplication));530 }531 else532 LogRel(("TAP#%d: RTProcWait failed for: %s\n", pData->pDrvIns->iInstance, pData->pszSetupApplication));533 }534 else535 {536 /* Bad. RTProcCreate() failed! */537 LogRel(("TAP#%d: Failed to fork() process for running TAP setup application: %s\n", pData->pDrvIns->iInstance,538 pData->pszSetupApplication, strerror(errno)));539 }540 541 return VERR_HOSTIF_INIT_FAILED;542 }543 544 545 /**546 * Calls OS-specific TAP terminate application/script.547 *548 * @returns VBox error code.549 * @param pData The instance data.550 */551 static int drvTAPTerminateApplication(PDRVTAP pData)552 {553 char *pszArgs[3];554 pszArgs[0] = pData->pszTerminateApplication;555 pszArgs[1] = pData->pszDeviceNameActual;556 pszArgs[2] = NULL;557 558 Log2(("Starting TAP terminate application: %s %s\n", pData->pszTerminateApplication, pData->pszDeviceNameActual));559 RTPROCESS pid = NIL_RTPROCESS;560 int rc = RTProcCreate(pszArgs[0], pszArgs, RTENV_DEFAULT, 0, &pid);561 if (RT_SUCCESS(rc))562 {563 RTPROCSTATUS Status;564 rc = RTProcWait(pid, 0, &Status);565 if (RT_SUCCESS(rc))566 {567 if ( Status.iStatus == 0568 && Status.enmReason == RTPROCEXITREASON_NORMAL)569 return VINF_SUCCESS;570 571 598 LogRel(("TAP#%d: Error running TAP terminate application: %s\n", pData->pDrvIns->iInstance, pData->pszTerminateApplication)); 572 599 } … … 589 616 # ifdef VBOX_WITH_CROSSBOW 590 617 /** 591 * Crossbow: create avirtual NIC.618 * Crossbow: Open & configure the virtual NIC. 592 619 * 593 620 * @returns VBox error code. 594 621 * @param pData The instance data. 595 622 */ 596 static int SolarisCreateVNIC(PDRVTAP pData) 597 { 598 /* 599 * Get a physical NIC. 600 */ 601 /** @todo r=bird: I'm I right in thinking that this just gets the name of the 602 * last ethernet NIC and binds us to that? If so, this really needs to be 603 * a user option. On OS/2 this is passed in as 'ConnectTo', using the same name 604 * is possibly a good idea even if the type is different (we need string not integer). */ 605 char szNICName[_LIFNAMSIZ]; 606 int ret = SolarisGetNIC(szNICName, sizeof(szNICName)); 607 if (VBOX_FAILURE(ret)) 608 return VERR_HOSTIF_INIT_FAILED; 609 610 /* 611 * Setup VNIC parameters. 612 */ 613 dladm_vnic_attr_sys_t VNICAttr; 614 memset(&VNICAttr, 0, sizeof(VNICAttr)); 615 size_t cbDestSize = sizeof(VNICAttr.va_dev_name); 616 if (strlcpy(VNICAttr.va_dev_name, szNICName, cbDestSize) >= cbDestSize) 617 return VERR_BUFFER_OVERFLOW; 618 Assert(sizeof(struct ether_addr) == sizeof(pData->MacAddress)); 619 memcpy(VNICAttr.va_mac_addr, &pData->MacAddress, ETHERADDRL); 620 VNICAttr.va_mac_len = ETHERADDRL; 621 622 uint_t VnicID; 623 bool fAutoID = true; 624 #if 0 625 /* Disabled for now, since Crossbow does not entirely respect our own VNIC ID.*/ 626 if (pData->pszDeviceName) 627 { 628 size_t cch = strlen(pData->pszDeviceName); 629 if (cch > 1 && isdigit(pData->pszDeviceName[cch - 1]) != 0) 630 { 631 VnicID = pData->pszDeviceName[cch - 1] - '0'; 632 fAutoID = false; 633 } 634 } 635 #endif 636 637 /* 638 * Create the VNIC. 639 */ 640 /** r=bird: The users should be able to create the vnic himself and pass it down. This would be the 641 * same as the tapN interface name. */ 642 uint32_t flags = DLADM_VNIC_OPT_TEMP; 643 if (fAutoID) 644 flags |= DLADM_VNIC_OPT_AUTOID; 645 646 dladm_status_t rc = dladm_vnic_create(fAutoID ? 0 : VnicID, szNICName, VNIC_MAC_ADDR_TYPE_FIXED, 647 (uchar_t *)&pData->MacAddress, ETHERADDRL, &VnicID, flags); 648 if (rc != DLADM_STATUS_OK) 649 return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, 650 N_("dladm_vnic_create() failed. NIC %s probably incorrect."), szNICName); 651 652 pData->pszDeviceNameActual = NULL; 653 RTStrAPrintf(&pData->pszDeviceNameActual, "vnic%u", VnicID); 654 pData->uDeviceID = VnicID; 655 656 ret = SolarisOpenNIC(pData, szNICName); 657 if (VBOX_FAILURE(ret)) 658 return ret; 659 return VINF_SUCCESS; 660 } 661 662 663 /** 664 * Crossbow: Obtain a physical NIC for binding the virtual NIC. 665 * 666 * @returns VBox error code. 667 * @param pszNICName Where to store the NIC name. 668 * @param cchNICName The size of the buffer buffer pszNICName points to. 669 */ 670 static int SolarisGetNIC(char *pszNICName, size_t cchNICName) 671 { 672 /* 673 * Try and obtain the a physical NIC to bind the VNIC to. 674 */ 675 int InetSocket = socket(AF_INET, SOCK_DGRAM, 0); 676 if (RT_UNLIKELY(InetSocket == -1)) 677 { 678 LogRel(("SolarisGetNIC: Socket creation for AF_INET family failed.\n")); 679 return VERR_HOSTIF_INIT_FAILED; 680 } 681 682 int rc; 683 struct lifnum IfNum; 684 IfNum.lifn_family = AF_UNSPEC; 685 if (ioctl(InetSocket, SIOCGLIFNUM, &IfNum) >= 0) 686 { 687 caddr_t pBuf = (caddr_t)RTMemAlloc(IfNum.lifn_count * sizeof(struct lifreq)); 688 if (pBuf) 689 { 690 struct lifconf IfCfg; 691 memset(&IfCfg, 0, sizeof(IfCfg)); 692 IfCfg.lifc_family = AF_UNSPEC; 693 IfCfg.lifc_buf = pBuf; 694 IfCfg.lifc_len = IfNum.lifn_count * sizeof(struct lifreq); 695 if (ioctl(InetSocket, SIOCGLIFCONF, &IfCfg) >= 0) 696 { 697 /* 698 * Loop through all NICs on the machine. We'll use the first ethernet NIC 699 * that is not a loopback interface for binding the VNIC. 700 */ 701 rc = VERR_GENERAL_FAILURE; /** @todo find a better return code. */ 702 struct lifreq *paIf = IfCfg.lifc_req; 703 int iIf = IfCfg.lifc_len / sizeof(struct lifreq); 704 while (iIf-- > 0) 705 if (strncmp(paIf[iIf].lifr_name, "lo", 2) != 0) 706 { 707 dlpi_handle_t hNIC = NULL; 708 if (dlpi_open(paIf[iIf].lifr_name, &hNIC, DLPI_RAW) == DLPI_SUCCESS) 709 { 710 dlpi_info_t NICInfo; 711 int rc2 = dlpi_info(hNIC, &NICInfo, 0); 712 dlpi_close(hNIC); 713 if ( rc2 == DLPI_SUCCESS 714 && NICInfo.di_mactype == DL_ETHER) 715 { 716 size_t cch = strlen(paIf[iIf].lifr_name); 717 if (cch < cchNICName) 718 { 719 memcpy(pszNICName, paIf[iIf].lifr_name, cch + 1); 720 rc = VINF_SUCCESS; 721 } 722 else 723 rc = VERR_BUFFER_OVERFLOW; 724 break; 725 } 726 } 727 } 728 } 729 else 730 { 731 LogRel(("SolarisGetNIC: SIOCGLIFCONF failed\n")); 732 rc = VERR_HOSTIF_INIT_FAILED; 733 } 734 RTMemFree(pBuf); 735 } 736 else 737 rc = VERR_NO_MEMORY; 738 } 739 else 740 { 741 LogRel(("SolarisGetNIC: SIOCGLIFNUM failed\n")); 742 rc = VERR_HOSTIF_INIT_FAILED; 743 } 744 close(InetSocket); 745 return rc; 746 } 747 748 749 /** 750 * Crossbow: Open & configure the physical NIC. 751 * 752 * @returns VBox error code. 753 * @param pData The instance data. 754 * @param pszNICName Name of the physical NIC. 755 * @param pEtherAddr Ethernet address to use for the VNIC. 756 */ 757 static int SolarisOpenNIC(PDRVTAP pData, const char *pszNICName) 623 static int SolarisOpenVNIC(PDRVTAP pData) 758 624 { 759 625 /* 760 626 * Open & bind the NIC using the datalink provider routine. 761 627 */ 762 int rc = dlpi_open(p szNICName, &pData->pDeviceHandle, DLPI_RAW);628 int rc = dlpi_open(pData->pszDeviceName, &pData->pDeviceHandle, DLPI_RAW); 763 629 if (rc != DLPI_SUCCESS) 764 630 return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, 765 N_("Failed to open VNIC in raw mode.")); 766 767 /* 768 * If we decide to get NIC name directly from user/env var., we will 769 * need to checks here to make sure the NIC has a ethernet address. 770 */ 771 rc = dlpi_bind(pData->pDeviceHandle, DLPI_ANY_SAP, NULL); 631 N_("Failed to open VNIC \"%s\" in raw mode."), pData->pszDeviceName); 632 633 dlpi_info_t vnicInfo; 634 rc = dlpi_info(pData->pDeviceHandle, &vnicInfo, 0); 772 635 if (rc == DLPI_SUCCESS) 773 636 { 774 rc = dlpi_set_physaddr(pData->pDeviceHandle, DL_CURR_PHYS_ADDR, &pData->MacAddress, ETHERADDRL); 775 if (rc == DLPI_SUCCESS) 637 if (vnicInfo.di_mactype == DL_ETHER) 776 638 { 777 rc = dlpi_ promiscon(pData->pDeviceHandle, DL_PROMISC_SAP);639 rc = dlpi_bind(pData->pDeviceHandle, DLPI_ANY_SAP, NULL); 778 640 if (rc == DLPI_SUCCESS) 779 641 { 780 /* Need to use DL_PROMIS_PHYS (not multicast) as we cannot be sure what the guest needs. */ 781 rc = dlpi_promiscon(pData->pDeviceHandle, DL_PROMISC_PHYS); 642 rc = dlpi_set_physaddr(pData->pDeviceHandle, DL_CURR_PHYS_ADDR, &pData->MacAddress, ETHERADDRL); 782 643 if (rc == DLPI_SUCCESS) 783 644 { 784 pData->FileDevice = dlpi_fd(pData->pDeviceHandle);785 if ( pData->FileDevice >= 0)645 rc = dlpi_promiscon(pData->pDeviceHandle, DL_PROMISC_SAP); 646 if (rc == DLPI_SUCCESS) 786 647 { 787 Log(("SolarisOpenNIC: %s -> %d\n", pszNICName, pData->FileDevice)); 788 return VINF_SUCCESS; 648 /* Need to use DL_PROMIS_PHYS (not multicast) as we cannot be sure what the guest needs. */ 649 rc = dlpi_promiscon(pData->pDeviceHandle, DL_PROMISC_PHYS); 650 if (rc == DLPI_SUCCESS) 651 { 652 pData->FileDevice = dlpi_fd(pData->pDeviceHandle); 653 if (pData->FileDevice >= 0) 654 { 655 Log(("SolarisOpenVNIC: %s -> %d\n", pData->pszDeviceName, pData->FileDevice)); 656 return VINF_SUCCESS; 657 } 658 659 rc = PDMDrvHlpVMSetError(pData->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, 660 N_("Failed to obtain file descriptor for VNIC.")); 661 } 662 else 663 rc = PDMDrvHlpVMSetError(pData->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, 664 N_("Failed to set appropriate promiscous mode.")); 789 665 } 790 791 rc = PDMDrvHlpVMSetError(pData->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS,792 N_("Failed to obtain file descriptorfor VNIC."));666 else 667 rc = PDMDrvHlpVMSetError(pData->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, 668 N_("Failed to activate promiscous mode for VNIC.")); 793 669 } 794 670 else 795 671 rc = PDMDrvHlpVMSetError(pData->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, 796 N_("Failed to set appropriate promiscous mode."));672 N_("Failed to set physical address for VNIC.")); 797 673 } 798 674 else 799 675 rc = PDMDrvHlpVMSetError(pData->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, 800 N_("Failed to activate promiscous mode forVNIC."));676 N_("Failed to bind VNIC.")); 801 677 } 802 678 else 803 679 rc = PDMDrvHlpVMSetError(pData->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, 804 N_("Failed to set physical address for VNIC."));680 N_("VNIC type is not ethernet.")); 805 681 } 806 682 else 807 683 rc = PDMDrvHlpVMSetError(pData->pDrvIns, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, 808 N_("Failed to bind VNIC."));684 N_("Failed to obtain VNIC info.")); 809 685 dlpi_close(pData->pDeviceHandle); 810 686 return rc; 811 }812 813 814 /**815 * Crossbow: Delete the virtual NIC.816 *817 * @returns VBox error code.818 * @param pData The instance data.819 */820 static int SolarisDeleteVNIC(PDRVTAP pData)821 {822 if (pData->pszDeviceNameActual)823 {824 dladm_status_t rc = dladm_vnic_delete(pData->uDeviceID, DLADM_VNIC_OPT_TEMP);825 if (rc == DLADM_STATUS_OK)826 return VINF_SUCCESS;827 }828 return VERR_HOSTIF_TERM_FAILED;829 687 } 830 688 … … 876 734 * 877 735 * @returns VBox error code. 878 * @param pDrvIns The driver instance data. 879 * @param pszDevName Pointer to device name. 880 */ 881 static DECLCALLBACK(int) SolarisTAPAttach(PPDMDRVINS pDrvIns) 882 { 883 PDRVTAP pData = PDMINS2DATA(pDrvIns, PDRVTAP); 736 * @param pData The instance data. 737 */ 738 static DECLCALLBACK(int) SolarisTAPAttach(PDRVTAP pData) 739 { 884 740 LogFlow(("SolarisTapAttach: pData=%p\n", pData)); 885 741 … … 887 743 int IPFileDes = open("/dev/udp", O_RDWR, 0); 888 744 if (IPFileDes < 0) 889 return PDMDrvHlpVMSetError(pD rvIns, VERR_PDM_HIF_OPEN_FAILED, RT_SRC_POS,745 return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_PDM_HIF_OPEN_FAILED, RT_SRC_POS, 890 746 N_("Failed to open /dev/udp. errno=%d"), errno); 891 747 892 748 int TapFileDes = open("/dev/tap", O_RDWR, 0); 893 749 if (TapFileDes < 0) 894 return PDMDrvHlpVMSetError(pD rvIns, VERR_PDM_HIF_OPEN_FAILED, RT_SRC_POS,750 return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_PDM_HIF_OPEN_FAILED, RT_SRC_POS, 895 751 N_("Failed to open /dev/tap for TAP. errno=%d"), errno); 896 752 … … 913 769 { 914 770 close(TapFileDes); 915 return PDMDrvHlpVMSetError(pD rvIns, VERR_HOSTIF_IOCTL, RT_SRC_POS,771 return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_HOSTIF_IOCTL, RT_SRC_POS, 916 772 N_("Failed to get new interface. errno=%d"), errno); 917 773 } … … 919 775 int InterfaceFD = open("/dev/tap", O_RDWR, 0); 920 776 if (!InterfaceFD) 921 return PDMDrvHlpVMSetError(pD rvIns, VERR_PDM_HIF_OPEN_FAILED, RT_SRC_POS,777 return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_PDM_HIF_OPEN_FAILED, RT_SRC_POS, 922 778 N_("Failed to open interface /dev/tap. errno=%d"), errno); 923 779 … … 925 781 { 926 782 close(InterfaceFD); 927 return PDMDrvHlpVMSetError(pD rvIns, VERR_HOSTIF_IOCTL, RT_SRC_POS,783 return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_HOSTIF_IOCTL, RT_SRC_POS, 928 784 N_("Failed to push IP. errno=%d"), errno); 929 785 } … … 932 788 memset(&ifReq, 0, sizeof(ifReq)); 933 789 if (ioctl(InterfaceFD, SIOCGLIFFLAGS, &ifReq) == -1) 934 LogRel(("TAP#%d: Failed to get interface flags.\n", pDrvIns->iInstance)); 935 936 char szTmp[16]; 937 char *pszDevName = pData->pszDeviceName; 938 if (!pData->pszDeviceName || !*pData->pszDeviceName) 939 { 940 RTStrPrintf(szTmp, sizeof(szTmp), "tap%d", iPPA); 941 pszDevName = szTmp; 942 } 790 LogRel(("TAP#%d: Failed to get interface flags.\n", pData->pDrvIns->iInstance)); 943 791 944 792 ifReq.lifr_ppa = iPPA; 945 RTStrPrintf (ifReq.lifr_name, sizeof(ifReq.lifr_name), p szDevName);793 RTStrPrintf (ifReq.lifr_name, sizeof(ifReq.lifr_name), pData->pszDeviceName); 946 794 947 795 if (ioctl(InterfaceFD, SIOCSLIFNAME, &ifReq) == -1) 948 LogRel(("TAP#%d: Failed to set PPA. errno=%d\n", pD rvIns->iInstance, errno));796 LogRel(("TAP#%d: Failed to set PPA. errno=%d\n", pData->pDrvIns->iInstance, errno)); 949 797 950 798 if (ioctl(InterfaceFD, SIOCGLIFFLAGS, &ifReq) == -1) 951 LogRel(("TAP#%d: Failed to get interface flags after setting PPA. errno=%d\n", pD rvIns->iInstance, errno));799 LogRel(("TAP#%d: Failed to get interface flags after setting PPA. errno=%d\n", pData->pDrvIns->iInstance, errno)); 952 800 953 801 #ifdef VBOX_SOLARIS_TAP_ARP 954 802 /* Interface */ 955 803 if (ioctl(InterfaceFD, I_PUSH, "arp") == -1) 956 LogRel(("TAP#%d: Failed to push ARP to Interface FD. errno=%d\n", pD rvIns->iInstance, errno));804 LogRel(("TAP#%d: Failed to push ARP to Interface FD. errno=%d\n", pData->pDrvIns->iInstance, errno)); 957 805 958 806 /* IP */ 959 807 if (ioctl(IPFileDes, I_POP, NULL) == -1) 960 LogRel(("TAP#%d: Failed I_POP from IP FD. errno=%d\n", pD rvIns->iInstance, errno));808 LogRel(("TAP#%d: Failed I_POP from IP FD. errno=%d\n", pData->pDrvIns->iInstance, errno)); 961 809 962 810 if (ioctl(IPFileDes, I_PUSH, "arp") == -1) 963 LogRel(("TAP#%d: Failed to push ARP to IP FD. errno=%d\n", pD rvIns->iInstance, errno));811 LogRel(("TAP#%d: Failed to push ARP to IP FD. errno=%d\n", pData->pDrvIns->iInstance, errno)); 964 812 965 813 /* ARP */ 966 814 int ARPFileDes = open("/dev/tap", O_RDWR, 0); 967 815 if (ARPFileDes < 0) 968 LogRel(("TAP#%d: Failed to open for /dev/tap for ARP. errno=%d", pD rvIns->iInstance, errno));816 LogRel(("TAP#%d: Failed to open for /dev/tap for ARP. errno=%d", pData->pDrvIns->iInstance, errno)); 969 817 970 818 if (ioctl(ARPFileDes, I_PUSH, "arp") == -1) 971 LogRel(("TAP#%d: Failed to push ARP to ARP FD. errno=%d\n", pD rvIns->iInstance, errno));819 LogRel(("TAP#%d: Failed to push ARP to ARP FD. errno=%d\n", pData->pDrvIns->iInstance, errno)); 972 820 973 821 ioIF.ic_cmd = SIOCSLIFNAME; … … 976 824 ioIF.ic_dp = (char *)&ifReq; 977 825 if (ioctl(ARPFileDes, I_STR, &ioIF) == -1) 978 LogRel(("TAP#%d: Failed to set interface name to ARP.\n", pD rvIns->iInstance));826 LogRel(("TAP#%d: Failed to set interface name to ARP.\n", pData->pDrvIns->iInstance)); 979 827 #endif 980 828 … … 990 838 close(ARPFileDes); 991 839 #endif 992 LogRel(("TAP#%d: Cannot link TAP device to IP.\n", pD rvIns->iInstance));993 return PDMDrvHlpVMSetError(pD rvIns, VERR_HOSTIF_IOCTL, RT_SRC_POS,840 LogRel(("TAP#%d: Cannot link TAP device to IP.\n", pData->pDrvIns->iInstance)); 841 return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_HOSTIF_IOCTL, RT_SRC_POS, 994 842 N_("Failed to link TAP device to IP. Check TAP interface name. errno=%d"), errno); 995 843 } … … 998 846 int ARPMuxID = ioctl(IPFileDes, I_LINK, ARPFileDes); 999 847 if (ARPMuxID == -1) 1000 LogRel(("TAP#%d: Failed to link TAP device to ARP\n", pD rvIns->iInstance));848 LogRel(("TAP#%d: Failed to link TAP device to ARP\n", pData->pDrvIns->iInstance)); 1001 849 1002 850 close(ARPFileDes); … … 1006 854 /* Reuse ifReq */ 1007 855 memset(&ifReq, 0, sizeof(ifReq)); 1008 RTStrPrintf (ifReq.lifr_name, sizeof(ifReq.lifr_name), p szDevName);856 RTStrPrintf (ifReq.lifr_name, sizeof(ifReq.lifr_name), pData->pszDeviceName); 1009 857 ifReq.lifr_ip_muxid = IPMuxID; 1010 858 #ifdef VBOX_SOLARIS_TAP_ARP … … 1019 867 ioctl(IPFileDes, I_PUNLINK, IPMuxID); 1020 868 close(IPFileDes); 1021 LogRel(("TAP#%d: Failed to set Mux ID.\n", pD rvIns->iInstance));1022 return PDMDrvHlpVMSetError(pD rvIns, VERR_HOSTIF_IOCTL, RT_SRC_POS,869 LogRel(("TAP#%d: Failed to set Mux ID.\n", pData->pDrvIns->iInstance)); 870 return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_HOSTIF_IOCTL, RT_SRC_POS, 1023 871 N_("Failed to set Mux ID. Check TAP interface name. errno=%d"), errno); 1024 872 } … … 1026 874 pData->FileDevice = (RTFILE)TapFileDes; 1027 875 pData->IPFileDevice = (RTFILE)IPFileDes; 1028 pData->pszDeviceNameActual = RTStrDup(pszDevName);1029 876 1030 877 return VINF_SUCCESS; … … 1133 980 drvTAPTerminateApplication(pData); 1134 981 1135 # ifdef VBOX_WITH_CROSSBOW1136 /* Finally unregister the VNIC */1137 dlpi_close(pData->pDeviceHandle);1138 SolarisDeleteVNIC(pData);1139 # endif1140 1141 RTStrFree(pData->pszDeviceNameActual);1142 982 #endif /* RT_OS_SOLARIS */ 1143 983 984 #ifdef RT_OS_SOLARIS 985 if (!pData->fStatic) 986 RTStrFree(pData->pszDeviceName); /* allocated by drvTAPSetupApplication */ 987 else 988 MMR3HeapFree(pData->pszDeviceName); 989 #else 1144 990 MMR3HeapFree(pData->pszDeviceName); 991 #endif 1145 992 MMR3HeapFree(pData->pszSetupApplication); 1146 993 MMR3HeapFree(pData->pszTerminateApplication); … … 1169 1016 pData->pszDeviceName = NULL; 1170 1017 #ifdef RT_OS_SOLARIS 1171 pData->pszDeviceNameActual = NULL;1172 1018 # ifdef VBOX_WITH_CROSSBOW 1173 1019 pData->pDeviceHandle = NULL; 1174 pData->uDeviceID = 0;1175 1020 # else 1176 1021 pData->IPFileDevice = NIL_RTFILE; 1177 1022 # endif 1023 pData->fStatic = true; 1178 1024 #endif 1179 1025 pData->pszSetupApplication = NULL; … … 1245 1091 rc = CFGMR3QueryStringAlloc(pCfgHandle, "Device", &pData->pszDeviceName); 1246 1092 if (VBOX_FAILURE(rc)) 1247 return PDMDRV_SET_ERROR(pDrvIns, rc, 1248 N_("Configuration error: Query for \"Device\" string failed!")); 1249 1250 /* 1251 * Do the setup. 1252 */ 1253 # ifdef VBOX_WITH_CROSSBOW 1254 rc = SolarisCreateVNIC(pData); 1255 # else 1256 rc = SolarisTAPAttach(pDrvIns); 1257 # endif 1258 if (VBOX_FAILURE(rc)) 1259 return rc; 1260 1093 pData->fStatic = false; 1094 1095 /* Obtain the device name from the setup application (if none was specified). */ 1261 1096 if (pData->pszSetupApplication) 1262 1097 { … … 1266 1101 N_("Error running TAP setup application. rc=%d"), rc); 1267 1102 } 1103 1104 /* 1105 * Do the setup. 1106 */ 1107 # ifdef VBOX_WITH_CROSSBOW 1108 rc = SolarisOpenVNIC(pData); 1109 # else 1110 rc = SolarisTAPAttach(pData); 1111 # endif 1112 if (VBOX_FAILURE(rc)) 1113 return rc; 1268 1114 1269 1115 #else /* !RT_OS_SOLARIS */ -
trunk/src/VBox/Devices/Network/solaris/vnicinit_solaris.sh
r5587 r5719 2 2 3 3 # VirtualBox VNIC setup script for Solaris hosts with Crossbow. 4 # usage: ./vnicinit.sh vnicname5 #6 # format of VNIC interface names MUST be like [name][number]7 # example: vnic1, vnic2, vnic900 etc.8 4 9 5 if [ -z "$1" ]; then 10 echo "Missing VNIC interface name."6 echo "Missing MAC address." 11 7 echo 12 echo "Usage: $0 vnicname" 8 echo "Usage: $0 macaddress [vnicname]" 9 echo " A new VNIC is created if no vnicname is provided." 13 10 exit 1 14 11 fi 15 12 16 vnic_name=`echo $1 | /usr/xpg4/bin/tr -s [:upper:] [:lower:]` 17 vnic_id=${vnic_name##*[a-z]} 18 vnic_name=$1 13 vnic_id=0 14 vnic_name="" 15 mac=$1 16 17 # Create the VNIC if required 18 if [ -z "$2" ]; then 19 vnic_id=`/usr/lib/vna iprb0 $mac` 20 if [ $? != 0 ]; then 21 exit 1 22 fi 23 vnic_name=vnic${vnic_id} 24 else 25 vnic_name=$2 26 vnic_id=${vnic_name##*[a-z]} 27 fi 28 19 29 if [ ${vnic_id} -lt 10 ]; then 20 30 host_ip="192.168.1.10${vnic_id}" … … 35 45 netmask="255.255.255.0" 36 46 37 /sbin/ifconfig $vnic_name plumb 38 /sbin/ifconfig $vnic_name $host_ip destination $guest_ip netmask $netmask up 47 if [ -z "$2" ]; then 48 /sbin/ifconfig $vnic_name plumb 49 /sbin/ifconfig $vnic_name $host_ip destination $guest_ip netmask $netmask up 50 #else 51 # Do existing VNIC configuration here if needed... 52 fi 39 53 40 # Output the VNIC name though not used by VirtualBox41 54 echo "$vnic_name" 42 55 exit $? -
trunk/src/VBox/Devices/Network/solaris/vnicterm_solaris.sh
r5587 r5719 15 15 16 16 /sbin/ifconfig $1 unplumb 17 vnic_id=${1##*[a-z]} 18 /usr/lib/vna ${vnic_id} 17 19 exit $? 18 20
Note:
See TracChangeset
for help on using the changeset viewer.