Changeset 25367 in vbox
- Timestamp:
- Dec 14, 2009 4:29:10 PM (15 years ago)
- Location:
- trunk/src/VBox/HostDrivers/VBoxNetFlt
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/Makefile.kmk
r25336 r25367 337 337 vboxnetbow_DEPS += $(VBOX_SVN_REV_KMK) 338 338 vboxnetbow_INCS := $(PATH_SUB_CURRENT) 339 vboxnetbow_LDFLAGS += -N drv/vboxdrv -N misc/mac339 vboxnetbow_LDFLAGS += -N drv/vboxdrv -N drv/vnic -N misc/mac -N misc/dls 340 340 vboxnetbow_LIBS = \ 341 341 $(PATH_LIB)/SUPR0IdcClient$(VBOX_SUFF_LIB) -
trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h
r25302 r25367 176 176 * @{ */ 177 177 # ifdef VBOX_WITH_NETFLT_CROSSBOW 178 /** The link Id of the VNIC */ 179 datalink_id_t VNICLinkId; 180 /** Instance number of VNIC */ 181 uint16_t uInstance; 182 /** Whether we created the VNIC or not */ 183 bool fCreatedVNIC; 178 184 /** The lower MAC handle */ 179 185 mac_handle_t hInterface; -
trunk/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFltBow-solaris.c
r25327 r25367 25 25 #define LOG_GROUP LOG_GROUP_NET_FLT_DRV 26 26 #include <VBox/log.h> 27 #include <VBox/err.h> 27 28 #include <VBox/cdefs.h> 28 29 #include <VBox/version.h> … … 31 32 #include <iprt/assert.h> 32 33 #include <iprt/err.h> 34 #include <iprt/string.h> 33 35 #include <iprt/net.h> 34 36 #include <iprt/spinlock.h> 35 37 38 #include <sys/types.h> 36 39 #include <sys/modctl.h> 37 40 #include <sys/conf.h> … … 42 45 #include <sys/strsubr.h> 43 46 #include <sys/dlpi.h> 47 #include <sys/dls_mgmt.h> 44 48 #include <sys/mac.h> 45 49 #include <sys/strsun.h> 46 47 #include "include/mac_provider.h" 48 #include "include/mac_client.h" 49 #include "include/mac_client_priv.h" 50 #include <sys/sunddi.h> 51 52 #include "include/mac_provider.h" /* dependency for other headers */ 53 #include "include/mac_client.h" /* for mac_* */ 54 #include "include/mac_client_priv.h" /* for mac_info, mac_capab_get etc. */ 55 #if 0 56 #include "include/dls.h" /* for dls_mgmt_* */ 57 #include "include/dld_ioc.h" /* required by vnic.h */ 58 #include "include/vnic.h" /* for vnic_ioc_diag_t */ 59 #include "include/vnic_impl.h" /* for vnic_dev_create */ 60 #endif 50 61 51 62 #define VBOXNETFLT_OS_SPECFIC 1 … … 59 70 /** The module descriptions as seen in 'modinfo'. */ 60 71 #define DEVICE_DESC_DRV "VirtualBox NetBow" 72 /** The dynamically created VNIC name */ 73 #define VBOXFLT_VNIC_NAME "vboxvnic" 61 74 /** Debugging switch for using symbols in kmdb */ 62 75 # define LOCAL static … … 143 156 { 144 157 MODREV_1, 145 &g_VBoxNetFltSolarisModule, 146 NULL, 158 { 159 &g_VBoxNetFltSolarisModule, 160 NULL, 161 } 147 162 }; 148 163 … … 592 607 * @param fLoopback Whether this is a loopback packet or not. 593 608 */ 594 595 609 LOCAL void vboxNetFltSolarisRecv(void *pvData, mac_resource_handle_t hResource, mblk_t *pMsg, boolean_t fLoopback) 596 610 { … … 638 652 639 653 /** 654 * Create a VNIC dynamically over the given interface. 655 * 656 * @param pThis The VM connection instance. 657 * 658 * @returns corresponding VBox error code. 659 */ 660 LOCAL int vboxNetFltSolarisCreateVNIC(PVBOXNETFLTINS pThis) 661 { 662 #if 0 663 LogFlow((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC pThis=%p\n", pThis)); 664 665 datalink_id_t InterfaceLinkId; 666 int rc = dls_mgmt_get_linkid(pThis->szName, &InterfaceLinkId); 667 if (!rc) 668 { 669 dev_t DeviceNum = makedevice(ddi_driver_major(g_pVBoxNetFltSolarisDip), pThis->u.s.uInstance); 670 char szVNICName[sizeof(VBOXFLT_VNIC_NAME) + 16]; 671 RTStrPrintf(szVNICName, sizeof(szVNICName), "%s%d", VBOXFLT_VNIC_NAME, pThis->u.s.uInstance); 672 LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC Creating VNIC '%s' over '%s'\n", szVNICName, pThis->szName)); 673 rc = dls_mgmt_create(szVNICName, DeviceNum, DATALINK_CLASS_VNIC, DL_ETHER, B_FALSE /* Persist */, &pThis->u.s.VNICLinkId); 674 if (!rc) 675 { 676 /* -XXX- @todo remove hardcoded Guest MAC address, should be sent from guest later. */ 677 RTMAC GuestMac; 678 GuestMac.au8[0] = 0x08; 679 GuestMac.au8[1] = 0x00; 680 GuestMac.au8[2] = 0x27; 681 GuestMac.au8[3] = 0xFE; 682 GuestMac.au8[4] = 0x21; 683 GuestMac.au8[5] = 0x03; 684 685 AssertCompile(sizeof(RTMAC) <= MAXMACADDRLEN); 686 uchar_t MacAddr[MAXMACADDRLEN]; 687 bzero(MacAddr, sizeof(MacAddr)); 688 bcopy(GuestMac.au8, MacAddr, RT_MIN(sizeof(GuestMac), sizeof(MacAddr))); 689 690 int MacSlot = 0; 691 vnic_ioc_diag_t Diag = VNIC_IOC_DIAG_NONE; 692 vnic_mac_addr_type_t MacAddrType = VNIC_MAC_ADDR_TYPE_FIXED; 693 int cbMac = sizeof(RTMAC); 694 int fFlags = VNIC_IOC_CREATE_NODUPCHECK | VNIC_IOC_CREATE_REQ_HWRINGS; 695 rc = vnic_dev_create(pThis->u.s.VNICLinkId, InterfaceLinkId, &MacAddrType, &cbMac, MacAddr, 696 &MacSlot, 0 /* Mac Prefix */, 0 /* VLAN Id */, NULL /* Resources Caps */, 697 fFlags, &Diag, kcred); 698 if (rc) 699 { 700 if (Diag == VNIC_IOC_DIAG_NO_HWRINGS) 701 { 702 /* 703 * No hardware rings available, retry without requesting hardware ring. 704 */ 705 LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC No hardware rings available for VNIC over '%s'. Recreating VNIC '%s'\n", pThis->szName, 706 szVNICName)); 707 708 fFlags = VNIC_IOC_CREATE_NODUPCHECK; 709 rc = vnic_dev_create(pThis->u.s.VNICLinkId, InterfaceLinkId, &MacAddrType, &cbMac, MacAddr, 710 &MacSlot, 0 /* Mac Prefix */, 0 /* VLAN Id */, NULL /* Resources Caps */, 711 fFlags, &Diag, kcred); 712 } 713 } 714 715 if (!rc) 716 { 717 pThis->u.s.fCreatedVNIC = true; 718 pThis->u.s.uInstance++; 719 LogFlow((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC successfully created VNIC '%s' over '%s'\n", "vboxvnic", pThis->szName)); 720 return VINF_SUCCESS; 721 } 722 else 723 { 724 LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed to create VNIC over '%s'. rc=%d Diagnosis=%d\n", pThis->szName, 725 rc, Diag)); 726 rc = VERR_INTNET_FLT_VNIC_CREATE_FAILED; 727 } 728 729 dls_mgmt_destroy(pThis->u.s.VNICLinkId, B_FALSE /* Persist */); 730 } 731 else 732 { 733 LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed to create a link id for a VNIC over '%s' rc=%d\n", pThis->szName, rc)); 734 rc = VERR_INTNET_FLT_VNIC_CREATE_FAILED; 735 } 736 } 737 else 738 { 739 LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed to find interface '%s' rc=%d\n", pThis->szName, rc)); 740 rc = VERR_INTNET_FLT_IF_NOT_FOUND; 741 } 742 743 return rc; 744 #endif 745 } 746 747 748 /** 640 749 * Attach to the network interface. 641 750 * … … 647 756 LOCAL int vboxNetFltSolarisAttachToInterface(PVBOXNETFLTINS pThis, bool fRediscovery) 648 757 { 758 LogFlow((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface pThis=%p fRediscovery=%d\n", pThis, fRediscovery)); 759 649 760 AssertPtrReturn(pThis, VERR_INVALID_POINTER); 650 761 … … 655 766 if (RT_LIKELY(!rc)) 656 767 { 657 const mac_info_t *pMacInfo = mac_info(pThis->u.s.hInterface); 658 if (RT_LIKELY(pMacInfo)) 659 { 660 if ( pMacInfo->mi_media == DL_ETHER 661 && pMacInfo->mi_nativemedia == DL_ETHER) 768 /* 769 * If this is not a VNIC, create a VNIC and open it instead. 770 */ 771 rc = mac_is_vnic(pThis->u.s.hInterface); 772 if (!rc) 773 { 774 LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface '%s' is not a VNIC. Creating one.\n", pThis->szName)); 775 776 mac_close(pThis->u.s.hInterface); 777 pThis->u.s.hInterface = NULL; 778 rc = vboxNetFltSolarisCreateVNIC(pThis); 779 if (RT_SUCCESS(rc)) 780 rc = mac_open_by_linkid(pThis->u.s.VNICLinkId, &pThis->u.s.hInterface); 781 else 662 782 { 663 /* 664 * Obtain the MAC address of the interface. 665 */ 666 AssertCompile(sizeof(RTMAC) == ETHERADDRL); 667 mac_unicast_primary_get(pThis->u.s.hInterface, (uint8_t *)&pThis->u.s.Mac.au8); 668 669 LogFlow((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface MAC address of %s is %.*Rhxs\n", pThis->szName, 670 sizeof(pThis->u.s.Mac), &pThis->u.s.Mac)); 671 672 /** @todo Obtain the MTU size using mac_sdu_get() */ 673 /** @todo Obtain capabilities (hardware checksum etc.) using mac_capab_get() */ 674 675 /* 676 * Open a client connection to the lower MAC interface. 677 */ 678 rc = mac_client_open(pThis->u.s.hInterface, &pThis->u.s.hClient, 679 NULL /* name of this client */, 680 MAC_OPEN_FLAGS_USE_DATALINK_NAME | /* client name same as underlying NIC */ 681 MAC_OPEN_FLAGS_MULTI_PRIMARY /* allow multiple primary unicasts */ 682 ); 683 if (RT_LIKELY(!rc)) 783 pThis->u.s.hInterface = NULL; 784 LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to create VNIC. rc=%Rrc\n", rc)); 785 } 786 } 787 else 788 rc = VINF_SUCCESS; 789 790 /* 791 * At this point "hInterface" should be a handle to a VNIC, we no longer would deal with physical interface 792 * if it has been passed by the user. 793 */ 794 if (RT_SUCCESS(rc)) 795 { 796 const mac_info_t *pMacInfo = mac_info(pThis->u.s.hInterface); 797 if (RT_LIKELY(pMacInfo)) 798 { 799 if ( pMacInfo->mi_media == DL_ETHER 800 && pMacInfo->mi_nativemedia == DL_ETHER) 684 801 { 685 802 /* 686 * Set a unicast address for this client and the packet receive callback. 687 * We want to use the primary unicast address of the underlying interface hence we pass NULL. 688 * Also we don't really set the RX function here, this is done when we activate promiscuous mode. 803 * Obtain the MAC address of the interface. 689 804 */ 690 mac_diag_t MacDiag; 691 rc = mac_unicast_add_set_rx(pThis->u.s.hClient, NULL /* MAC Address */, 692 MAC_UNICAST_PRIMARY | MAC_UNICAST_STRIP_DISABLE | 693 MAC_UNICAST_DISABLE_TX_VID_CHECK | MAC_UNICAST_NODUPCHECK, 694 &pThis->u.s.hUnicast, 0 /* VLAN id */, &MacDiag, NULL /* pfnRecv */, pThis); 695 if (!rc) 805 AssertCompile(sizeof(RTMAC) == ETHERADDRL); 806 mac_unicast_primary_get(pThis->u.s.hInterface, (uint8_t *)&pThis->u.s.Mac.au8); 807 808 LogFlow((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface MAC address of %s is %.*Rhxs\n", pThis->szName, 809 sizeof(pThis->u.s.Mac), &pThis->u.s.Mac)); 810 811 /** @todo Obtain the MTU size using mac_sdu_get() */ 812 /** @todo Obtain capabilities (hardware checksum etc.) using mac_capab_get() */ 813 814 /* 815 * Open a client connection to the lower MAC interface. 816 */ 817 rc = mac_client_open(pThis->u.s.hInterface, &pThis->u.s.hClient, 818 NULL /* name of this client */, 819 MAC_OPEN_FLAGS_USE_DATALINK_NAME | /* client name same as underlying NIC */ 820 MAC_OPEN_FLAGS_MULTI_PRIMARY /* allow multiple primary unicasts */ 821 ); 822 if (RT_LIKELY(!rc)) 696 823 { 697 LogFlow((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface successfully attached over '%s'\n", pThis->szName)); 698 return VINF_SUCCESS; 824 /** @todo -XXX- if possible we must move unicast_add and rx_set to when the Guest advertises it's MAC to us. */ 825 826 /* 827 * Set a unicast address for this client and the packet receive callback. 828 * We want to use the primary unicast address of the underlying interface (VNIC) hence we pass NULL. 829 * Also we don't really set the RX function here, this is done when we activate promiscuous mode. 830 */ 831 mac_diag_t MacDiag; 832 rc = mac_unicast_add(pThis->u.s.hClient, NULL /* MAC Address */, 833 MAC_UNICAST_PRIMARY | MAC_UNICAST_STRIP_DISABLE | 834 MAC_UNICAST_DISABLE_TX_VID_CHECK | MAC_UNICAST_NODUPCHECK | MAC_UNICAST_HW, 835 &pThis->u.s.hUnicast, 0 /* VLAN id */, &MacDiag); 836 if (!rc) 837 { 838 LogFlow((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface successfully attached over '%s'\n", pThis->szName)); 839 return VINF_SUCCESS; 840 } 841 else 842 LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to set client MAC address over link '%s' rc=%d\n", 843 pThis->szName, rc)); 844 845 mac_client_close(pThis->u.s.hClient, 0 /* fFlags */); 846 pThis->u.s.hClient = NULL; 699 847 } 700 848 else 701 LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to set client MAC address over link '%s' rc=%d\n", 849 { 850 LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to create client over link '%s' rc=%d\n", 702 851 pThis->szName, rc)); 703 704 mac_client_close(pThis->u.s.hClient, 0 /* fFlags */); 705 pThis->u.s.hClient = NULL; 852 } 706 853 } 707 854 else 708 855 { 709 LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to create client over link '%s' rc=%d\n", 710 pThis->szName, rc)); 856 LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface media type incompatible: %d %d\n", pMacInfo->mi_media, 857 pMacInfo->mi_nativemedia)); 858 rc = EPROTO; 711 859 } 712 860 } 713 861 else 714 862 { 715 LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface media type incompatible: %d %d\n", pMacInfo->mi_media, 716 pMacInfo->mi_nativemedia)); 717 rc = EPROTO; 863 LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to obtain info for link '%s'\n", pThis->szName)); 864 rc = ENXIO; 718 865 } 719 866 } 720 867 else 721 868 { 722 Log Rel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to obtain info for link'%s'\n", pThis->szName));869 LogFlow((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface VNIC creation failed over '%s'\n", pThis->szName)); 723 870 rc = ENXIO; 724 871 } 725 872 726 mac_close(pThis->u.s.hInterface); 873 if (pThis->u.s.hInterface) 874 { 875 mac_close(pThis->u.s.hInterface); 876 pThis->u.s.hInterface = NULL; 877 } 727 878 } 728 879 else … … 768 919 mac_close(pThis->u.s.hInterface); 769 920 pThis->u.s.hInterface = NULL; 921 } 922 923 if (pThis->u.s.fCreatedVNIC) 924 { 925 #if 0 926 vnic_dev_delete(pThis->u.s.VNICLinkId, 0 /* Flags -- ununsed in snv_127 */, kcred); 927 dls_mgmt_destroy(pThis->u.s.VNICLinkId, B_FALSE /* Persist */); 928 pThis->u.s.VNICLinkId = DATALINK_INVALID_LINKID; 929 pThis->u.s.fCreatedVNIC = false; 930 #endif 770 931 } 771 932 } … … 861 1022 * Init. the solaris specific data. 862 1023 */ 1024 pThis->u.s.VNICLinkId = DATALINK_INVALID_LINKID; 1025 pThis->u.s.uInstance = 0; 1026 pThis->u.s.fCreatedVNIC = false; 863 1027 pThis->u.s.hInterface = NULL; 864 1028 pThis->u.s.hClient = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.