VBoxNetFltBow-solaris.c revision a1fb412664878af4f651bc29cb8e324fe09be33f
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * VBoxNetFlt - Network Filter Driver (Host), Solaris Specific Code.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2008 Oracle Corporation
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * available from http://www.virtualbox.org. This file is free software;
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * you can redistribute it and/or modify it under the terms of the GNU
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * General Public License (GPL) as published by the Free Software
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync/*******************************************************************************
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync* Header Files *
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync*******************************************************************************/
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync/*******************************************************************************
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync* Defined Constants And Macros *
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync*******************************************************************************/
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync/** The module name. */
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync/** The module descriptions as seen in 'modinfo'. */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync/** The dynamically created VNIC name (hardcoded in NetIf-solaris.cpp).
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * @todo move this define into a common header. */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync/** The VirtualBox VNIC template name (hardcoded in NetIf-solaris.cpp).
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * * @todo move this define into a common header. */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync#define VBOXFLT_VNIC_TEMPLATE_NAME "vboxvnic_template"
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync/** Debugging switch for using symbols in kmdb */
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync# define LOCAL static
e7b615a442051960547fd3835527b975ab7da970vboxsync/** VBOXNETFLTVNIC::u32Magic */
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync/** VLAN tag masking, should probably be in IPRT? */
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync#define VLAN_TAG(pri,cfi,vid) (((pri) << 13) | ((cfi) << 12) | ((vid) << 0))
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsynctypedef struct VLANHEADER
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync/* Private: from sys/vlan.h */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync/* Private: from sys/param.h */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync# define MAXLINKNAMESPECIFIER 96 /* MAXLINKNAMELEN + ZONENAME_MAX */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync/* Private: from sys/mac_client_priv.h, mac client function prototypes. */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsyncextern uint16_t mac_client_vid(mac_client_handle_t hClient);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsyncextern void mac_client_get_resources(mac_client_handle_t hClient, mac_resource_props_t *pResources);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsyncextern int mac_client_set_resources(mac_client_handle_t hClient, mac_resource_props_t *pResources);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync/*******************************************************************************
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync* Kernel Entry Hooks *
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync*******************************************************************************/
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncLOCAL int VBoxNetFltSolarisAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncLOCAL int VBoxNetFltSolarisDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncLOCAL int VBoxNetFltSolarisGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pArg, void **ppResult);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync/*******************************************************************************
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync* Structures and Typedefs *
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync*******************************************************************************/
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * cb_ops: for drivers that support char/block entry points
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * dev_ops: for driver device operations
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync 0, /* ref count */
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * modldrv: export driver specifics to the kernel
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync DEVICE_DESC_DRV " " VBOX_VERSION_STRING "r" RT_XSTR(VBOX_SVN_REV),
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * modlinkage: export install/remove/info to the kernel
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncstatic struct modlinkage g_VBoxNetFltSolarisModLinkage =
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * VBOXNETFLTVNICTEMPLATE: VNIC template information.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync /** The name of link on which the VNIC template is created on. */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync /** The VLAN Id (can be VLAN_ID_NONE). */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync /** Resources (bandwidth, CPU bindings, flow priority etc.) */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsynctypedef struct VBOXNETFLTVNICTEMPLATE *PVBOXNETFLTVNICTEMPLATE;
2135a0a48189b91cd746a83b2758bc4cfe257b94vboxsync * VBOXNETFLTVNIC: Per-VNIC instance data.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync /** Magic number (VBOXNETFLTVNIC_MAGIC). */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync /** Whether we created the VNIC or not. */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync /** Pointer to the VNIC template if any. */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync /** Pointer to the VirtualBox interface instance. */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync /** The lower MAC handle. */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync /** The VNIC link ID. */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync /** The MAC client handle */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync /** The unicast address handle. */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync /** The promiscuous handle (currently unused). */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync /* The VNIC name. */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync /** Handle to the next VNIC in the list. */
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync/*******************************************************************************
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync* Global Variables *
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync*******************************************************************************/
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync/** Global Device handle we only support one instance. */
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync/** Global Mutex (actually an rw lock). */
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncstatic RTSEMFASTMUTEX g_VBoxNetFltSolarisMtx = NIL_RTSEMFASTMUTEX;
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync/** The (common) global data. */
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncstatic VBOXNETFLTGLOBALS g_VBoxNetFltSolarisGlobals;
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync/*******************************************************************************
e7b615a442051960547fd3835527b975ab7da970vboxsync* Internal Functions *
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync*******************************************************************************/
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncLOCAL mblk_t *vboxNetFltSolarisMBlkFromSG(PVBOXNETFLTINS pThis, PINTNETSG pSG, uint32_t fDst);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncLOCAL unsigned vboxNetFltSolarisMBlkCalcSGSegs(PVBOXNETFLTINS pThis, mblk_t *pMsg);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncLOCAL int vboxNetFltSolarisMBlkToSG(PVBOXNETFLTINS pThis, mblk_t *pMsg, PINTNETSG pSG, unsigned cSegs, uint32_t fSrc);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncLOCAL void vboxNetFltSolarisRecv(void *pvData, mac_resource_handle_t hResource, mblk_t *pMsg, boolean_t fLoopback);
e7b615a442051960547fd3835527b975ab7da970vboxsyncLOCAL void vboxNetFltSolarisAnalyzeMBlk(mblk_t *pMsg);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsyncLOCAL int vboxNetFltSolarisReportInfo(PVBOXNETFLTINS pThis, mac_handle_t hInterface, bool fIsVNIC);
e7b615a442051960547fd3835527b975ab7da970vboxsyncLOCAL int vboxNetFltSolarisInitVNIC(PVBOXNETFLTINS pThis, PVBOXNETFLTVNIC pVNIC);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsyncLOCAL int vboxNetFltSolarisInitVNICTemplate(PVBOXNETFLTINS pThis, PVBOXNETFLTVNIC pVNIC, PVBOXNETFLTVNICTEMPLATE pVNICTemplate);
e7b615a442051960547fd3835527b975ab7da970vboxsyncLOCAL PVBOXNETFLTVNIC vboxNetFltSolarisAllocVNIC(void);
e7b615a442051960547fd3835527b975ab7da970vboxsyncLOCAL void vboxNetFltSolarisFreeVNIC(PVBOXNETFLTVNIC pVNIC);
e7b615a442051960547fd3835527b975ab7da970vboxsyncLOCAL void vboxNetFltSolarisDestroyVNIC(PVBOXNETFLTVNIC pVNIC);
e7b615a442051960547fd3835527b975ab7da970vboxsyncLOCAL int vboxNetFltSolarisCreateVNIC(PVBOXNETFLTINS pThis, PVBOXNETFLTVNIC *ppVNIC);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsyncLOCAL inline int vboxNetFltSolarisGetLinkId(const char *pszMacName, datalink_id_t *pLinkId);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Kernel entry points
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Prevent module autounloading.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync modctl_t *pModCtl = mod_getctl(&g_VBoxNetFltSolarisModLinkage);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogRel((DEVICE_NAME ":failed to disable autounloading!\n"));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Initialize IPRT.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Initialize Solaris specific globals here.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync rc = RTSemFastMutexCreate(&g_VBoxNetFltSolarisMtx);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Initialize the globals and connect to the support driver.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * This will call back vboxNetFltOsOpenSupDrv (and maybe vboxNetFltOsCloseSupDrv)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * for establishing the connect to the support driver.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync memset(&g_VBoxNetFltSolarisGlobals, 0, sizeof(g_VBoxNetFltSolarisGlobals));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync rc = vboxNetFltInitGlobalsAndIdc(&g_VBoxNetFltSolarisGlobals);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogRel((DEVICE_NAME ":mod_install failed. rc=%d\n", rc));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync vboxNetFltTryDeleteIdcAndGlobals(&g_VBoxNetFltSolarisGlobals);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogRel((DEVICE_NAME ":failed to initialize globals.\n"));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogRel((DEVICE_NAME ":failed to initialize IPRT (rc=%d)\n", rc));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync memset(&g_VBoxNetFltSolarisGlobals, 0, sizeof(g_VBoxNetFltSolarisGlobals));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Undo the work done during start (in reverse order).
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync rc = vboxNetFltTryDeleteIdcAndGlobals(&g_VBoxNetFltSolarisGlobals);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync int rc = mod_info(&g_VBoxNetFltSolarisModLinkage, pModInfo);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Attach entry point, to attach a device to the system or resume it.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param pDip The module structure instance.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param enmCmd Operation type (attach/resume).
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @returns corresponding solaris error code.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncLOCAL int VBoxNetFltSolarisAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogFlow((DEVICE_NAME ":VBoxNetFltSolarisAttach pDip=%p enmCmd=%d\n", pDip, enmCmd));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync int rc = ddi_create_priv_minor_node(pDip, DEVICE_NAME, S_IFCHR, instance, DDI_PSEUDO, 0, "none", "none", 0666);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogRel((DEVICE_NAME ":VBoxNetFltSolarisAttach failed to create minor node. rc=%d\n", rc));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync /* Nothing to do here... */
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync /* case DDI_PM_RESUME: */
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Detach entry point, to detach a device to the system or suspend it.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param pDip The module structure instance.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param enmCmd Operation type (detach/suspend).
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @returns corresponding solaris error code.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncLOCAL int VBoxNetFltSolarisDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogFlow((DEVICE_NAME ":VBoxNetFltSolarisDetach pDip=%p enmCmd=%d\n", pDip, enmCmd));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync /* Nothing to do here... */
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync /* case DDI_PM_SUSPEND: */
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync /* case DDI_HOT_PLUG_DETACH: */
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Info entry point, called by solaris kernel for obtaining driver info.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param pDip The module structure instance (do not use).
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param enmCmd Information request type.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param pvArg Type specific argument.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param ppvResult Where to store the requested info.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @returns corresponding solaris error code.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncLOCAL int VBoxNetFltSolarisGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pvArg, void **ppResult)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogFlow((DEVICE_NAME ":VBoxNetFltSolarisGetInfo pDip=%p enmCmd=%d pArg=%p instance=%d\n", pDip, enmCmd, getminor((dev_t)pvArg)));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Create a solaris message block from the SG list.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param pThis The instance.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param pSG Pointer to the scatter-gather list.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @returns Solaris message block.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncLOCAL mblk_t *vboxNetFltSolarisMBlkFromSG(PVBOXNETFLTINS pThis, PINTNETSG pSG, uint32_t fDst)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogFlow((DEVICE_NAME ":vboxNetFltSolarisMBlkFromSG pThis=%p pSG=%p\n", pThis, pSG));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogRel((DEVICE_NAME ":vboxNetFltSolarisMBlkFromSG failed to alloc %d bytes for mblk_t.\n", pSG->cbTotal));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Single buffer copy. Maybe later explore the
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * need/possibility for using a mblk_t chain rather.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync bcopy(pSG->aSegs[i].pv, pMsg->b_wptr, pSG->aSegs[i].cb);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Calculate the number of segments required for this message block.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param pThis The instance
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param pMsg Pointer to the data message.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @returns Number of segments.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncLOCAL unsigned vboxNetFltSolarisMBlkCalcSGSegs(PVBOXNETFLTINS pThis, mblk_t *pMsg)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync unsigned cSegs = 0;
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync for (mblk_t *pCur = pMsg; pCur; pCur = pCur->b_cont)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Initializes an SG list from the given message block.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param pThis The instance.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param pMsg Pointer to the data message.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync The caller must ensure it's not a control message block.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param pSG Pointer to the SG.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param cSegs Number of segments in the SG.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * This should match the number in the message block exactly!
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param fSrc The source of the message.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @returns VBox status code.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncLOCAL int vboxNetFltSolarisMBlkToSG(PVBOXNETFLTINS pThis, mblk_t *pMsg, PINTNETSG pSG, unsigned cSegs, uint32_t fSrc)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogFlow((DEVICE_NAME ":vboxNetFltSolarisMBlkToSG pThis=%p pMsg=%p pSG=%p cSegs=%d\n", pThis, pMsg, pSG, cSegs));
6dd8f5023a9ba7588212331db90059553136fe33vboxsync * Convert the message block to segments. Works cbTotal and sets cSegsUsed.
9127c416edfd6f9266e387f7abd7aa9904eecbc9vboxsync IntNetSgInitTempSegs(pSG, 0 /*cbTotal*/, cSegs, 0 /*cSegsUsed*/);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync unsigned iSeg = 0;
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync if (pSG->cbTotal < 60 && (fSrc & INTNETTRUNKDIR_HOST))
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogFlow((DEVICE_NAME ":vboxNetFltSolarisMBlkToSG pulling up to length.\n"));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogFlow((DEVICE_NAME ":vboxNetFltSolarisMBlkToSG iSeg=%d pSG->cbTotal=%d msgdsize=%d\n", iSeg, pSG->cbTotal, msgdsize(pMsg)));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Simple packet dump, used for internal debugging.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param pMsg Pointer to the message to analyze and dump.
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsyncLOCAL void vboxNetFltSolarisAnalyzeMBlk(mblk_t *pMsg)
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync LogFlowFunc((DEVICE_NAME ":vboxNetFltSolarisAnalyzeMBlk pMsg=%p\n", pMsg));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync PCRTNETETHERHDR pEthHdr = (PCRTNETETHERHDR)pMsg->b_rptr;
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPV4))
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync LogRel((DEVICE_NAME ":ICMP D=%.6Rhxs S=%.6Rhxs T=%04x\n", pb, pb + 6, RT_BE2H_U16(*(uint16_t *)(pb + 12))));
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync LogRel((DEVICE_NAME ":TCP D=%.6Rhxs S=%.6Rhxs\n", pb, pb + 6));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync PCRTNETUDP pUdpHdr = (PCRTNETUDP)((uint32_t *)pIpHdr + pIpHdr->ip_hl);
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogRel((DEVICE_NAME ":UDP bootp ack D=%.6Rhxs S=%.6Rhxs UDP_CheckSum=%04x Computex=%04x\n", pb, pb + 6,
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync RT_BE2H_U16(pUdpHdr->uh_sum), RT_BE2H_U16(RTNetIPv4UDPChecksum(pIpHdr, pUdpHdr, pUdpHdr + 1))));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogFlow((DEVICE_NAME ":Chained IP packet. Skipping validity check.\n"));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_VLAN))
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync PVLANHEADER pVlanHdr = (PVLANHEADER)(pMsg->b_rptr + sizeof(RTNETETHERHDR) - sizeof(pEthHdr->EtherType));
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync LogRel((DEVICE_NAME ":VLAN Pcp=%u Cfi=%u Id=%u\n", VLAN_PRI(RT_BE2H_U16(pVlanHdr->Data)), VLAN_CFI(RT_BE2H_U16(pVlanHdr->Data)), VLAN_ID(RT_BE2H_U16(pVlanHdr->Data))));
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync LogRel((DEVICE_NAME "%.*Rhxd\n", sizeof(VLANHEADER), pVlanHdr));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_ARP))
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync PRTNETARPHDR pArpHdr = (PRTNETARPHDR)(pEthHdr + 1);
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync LogRel((DEVICE_NAME ":ARP Op=%d\n", pArpHdr->ar_oper));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPV6))
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync LogRel((DEVICE_NAME ":IPv6 D=%.6Rhxs S=%.6Rhxs\n", pb, pb + 6));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPX_1)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync || pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPX_2)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync || pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPX_3))
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync LogRel((DEVICE_NAME ":Unknown EtherType=%x D=%.6Rhxs S=%.6Rhxs\n", RT_H2BE_U16(pEthHdr->EtherType), &pEthHdr->DstMac,
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync /* LogFlow((DEVICE_NAME ":%.*Rhxd\n", MBLKL(pMsg), pMsg->b_rptr)); */
5f809eed9fe4d8f7f317e8102657eb877fd5fbdavboxsyncDECLINLINE(bool) vboxNetFltPortSolarisIsHostMac(PVBOXNETFLTINS pThis, PCRTMAC pMac)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Receive (rx) entry point.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param pvData Private data.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param hResource The resource handle.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param pMsg The packet.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param fLoopback Whether this is a loopback packet or not.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncLOCAL void vboxNetFltSolarisRecv(void *pvData, mac_resource_handle_t hResource, mblk_t *pMsg, boolean_t fLoopback)
e9de8285074ab7533c564399c671bfa415f24a67vboxsync LogFlow((DEVICE_NAME ":vboxNetFltSolarisRecv pvData=%p pMsg=%p fLoopback=%d cbData=%d\n", pvData, pMsg, fLoopback, pMsg ? MBLKL(pMsg) : 0));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Active? Retain the instance and increment the busy counter.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync PRTNETETHERHDR pEthHdr = (PRTNETETHERHDR)pMsg->b_rptr;
5f809eed9fe4d8f7f317e8102657eb877fd5fbdavboxsync && vboxNetFltPortSolarisIsHostMac(pThis, &pEthHdr->SrcMac))
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Route all received packets into the internal network.
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync for (mblk_t *pCurMsg = pMsg; pCurMsg != NULL; pCurMsg = pCurMsg->b_next)
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync unsigned cSegs = vboxNetFltSolarisMBlkCalcSGSegs(pThis, pCurMsg);
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync PINTNETSG pSG = (PINTNETSG)alloca(RT_OFFSETOF(INTNETSG, aSegs[cSegs]));
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync int rc = vboxNetFltSolarisMBlkToSG(pThis, pMsg, pSG, cSegs, fSrc);
586cf6585d0e6aa3bef888eeff116bf82d18cd83vboxsync pThis->pSwitchPort->pfnRecv(pThis->pSwitchPort, NULL, pSG, fSrc);
de1338ccd96eef7da920a0db96699ab9bb6829efvboxsync LogRel((DEVICE_NAME ":vboxNetFltSolarisMBlkToSG failed for %u packets.\n", cFailed));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Report capabilities and MAC address to IntNet after obtaining the MAC address
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * of the underlying interface for a VNIC or the current interface if it's a
f6443fc96d014da2dcc4b03894fd1cd3ed841843vboxsync * @param pThis The instance.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * @param hInterface The Interface handle.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * @param fIsVNIC Whether this interface handle corresponds to a VNIC
f6443fc96d014da2dcc4b03894fd1cd3ed841843vboxsync * @remarks Retains the instance while doing it's job.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * @returns VBox status code.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsyncLOCAL int vboxNetFltSolarisReportInfo(PVBOXNETFLTINS pThis, mac_handle_t hInterface, bool fIsVNIC)
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogRel((DEVICE_NAME ":vboxNetFltSolarisReportInfo failed to get lower MAC handle for '%s'\n", pThis->szName));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync mac_unicast_primary_get(hLowerMac, (uint8_t *)pThis->u.s.MacAddr.au8);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogFlow((DEVICE_NAME ":vboxNetFltSolarisReportInfo phys mac %.6Rhxs\n", &pThis->u.s.MacAddr));
e7b615a442051960547fd3835527b975ab7da970vboxsync pThis->pSwitchPort->pfnReportMacAddress(pThis->pSwitchPort, &pThis->u.s.MacAddr);
e7b615a442051960547fd3835527b975ab7da970vboxsync pThis->pSwitchPort->pfnReportPromiscuousMode(pThis->pSwitchPort, false); /** @todo Promisc */
e7b615a442051960547fd3835527b975ab7da970vboxsync pThis->pSwitchPort->pfnReportGsoCapabilities(pThis->pSwitchPort, 0, INTNETTRUNKDIR_WIRE | INTNETTRUNKDIR_HOST);
e7b615a442051960547fd3835527b975ab7da970vboxsync pThis->pSwitchPort->pfnReportNoPreemptDsts(pThis->pSwitchPort, 0 /* none */);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Initialize a VNIC, optionally from a template.
f6443fc96d014da2dcc4b03894fd1cd3ed841843vboxsync * @param pThis The instance.
f6443fc96d014da2dcc4b03894fd1cd3ed841843vboxsync * @param pVNIC Pointer to the VNIC.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * @param pVNICTemplate Pointer to the VNIC template initialize from, can be
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * @returns VBox status code.
e7b615a442051960547fd3835527b975ab7da970vboxsyncLOCAL int vboxNetFltSolarisInitVNIC(PVBOXNETFLTINS pThis, PVBOXNETFLTVNIC pVNIC)
e7b615a442051960547fd3835527b975ab7da970vboxsync * Some paranoia.
e7b615a442051960547fd3835527b975ab7da970vboxsync AssertReturn(pVNIC->hInterface, VERR_INVALID_POINTER);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync AssertReturn(pVNIC->hLinkId != DATALINK_INVALID_LINKID, VERR_INVALID_HANDLE);
e7b615a442051960547fd3835527b975ab7da970vboxsync AssertReturn(!pVNIC->hClient, VERR_INVALID_HANDLE);
e7b615a442051960547fd3835527b975ab7da970vboxsync int rc = mac_client_open(pVNIC->hInterface, &pVNIC->hClient,
e7b615a442051960547fd3835527b975ab7da970vboxsync MAC_OPEN_FLAGS_USE_DATALINK_NAME | /* client name same as underlying NIC */
e7b615a442051960547fd3835527b975ab7da970vboxsync MAC_OPEN_FLAGS_MULTI_PRIMARY /* allow multiple primary unicasts */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync rc = mac_client_set_resources(pVNIC->hClient, &pVNIC->pVNICTemplate->Resources);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync rc = vboxNetFltSolarisReportInfo(pThis, pVNIC->hInterface, true /* fIsVNIC */);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogFlow((DEVICE_NAME ":vboxNetFltSolarisInitVNIC pThis=%p szName=%s succeeded.\n", pThis, pThis->szName));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNIC failed to report info. rc=%d\n", rc));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNIC mac_client_set_resources failed. rc=%d\n", rc));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNIC failed to open mac client for '%s' rc=%d\n", pThis->szName, rc));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Initializes the VNIC template. This involves opening the template VNIC to
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * retreive info. like the VLAN Id, underlying MAC address etc.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * @param pThis The VM connection instance.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * @param pVNIC Pointer to the VNIC.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * @param pVNICTemplate Pointer to a VNIC template to initialize.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * @returns VBox status code.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsyncLOCAL int vboxNetFltSolarisInitVNICTemplate(PVBOXNETFLTINS pThis, PVBOXNETFLTVNIC pVNIC, PVBOXNETFLTVNICTEMPLATE pVNICTemplate)
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogFlow((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate pThis=%p pVNIC=%p pVNICTemplate=%p\n", pThis, pVNIC, pVNICTemplate));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync AssertReturn(pVNICTemplate, VERR_INVALID_PARAMETER);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync AssertReturn(pThis->u.s.fIsVNICTemplate == true, VERR_INVALID_STATE);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Get the VNIC template's datalink ID.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync int rc = vboxNetFltSolarisGetLinkId(pThis->szName, &VNICLinkId);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Open the VNIC to obtain a MAC handle so as to retreive the VLAN ID.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Get the underlying linkname.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync mac_handle_t hPhysLinkHandle = mac_get_lower_mac_handle(hInterface);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync const char *pszLinkName = mac_name(hPhysLinkHandle);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync rc = RTStrCopy(pVNICTemplate->szLinkName, sizeof(pVNICTemplate->szLinkName), pszLinkName);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Now open the VNIC template to retrieve the VLAN Id & resources.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync MAC_OPEN_FLAGS_USE_DATALINK_NAME | /* client name same as underlying NIC */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync MAC_OPEN_FLAGS_MULTI_PRIMARY /* allow multiple primary unicasts */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync mac_client_get_resources(hClient, &pVNICTemplate->Resources);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogFlow((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate successfully init. VNIC template. szLinkName=%s\n",
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate failed to open VNIC template. rc=%d\n", rc));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate failed to copy link name of underlying interface. rc=%d\n", rc));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate failed to get lower handle for VNIC template '%s'.\n", pThis->szName));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate failed to open by link ID. rc=%d\n", rc));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate failed to get VNIC template link Id. rc=%d\n", rc));
f6443fc96d014da2dcc4b03894fd1cd3ed841843vboxsync * Allocate a VNIC structure.
f6443fc96d014da2dcc4b03894fd1cd3ed841843vboxsync * @returns An allocated VNIC structure or NULL in case of errors.
e7b615a442051960547fd3835527b975ab7da970vboxsyncLOCAL PVBOXNETFLTVNIC vboxNetFltSolarisAllocVNIC(void)
e7b615a442051960547fd3835527b975ab7da970vboxsync PVBOXNETFLTVNIC pVNIC = RTMemAlloc(sizeof(VBOXNETFLTVNIC));
f6443fc96d014da2dcc4b03894fd1cd3ed841843vboxsync * Frees an allocated VNIC.
f6443fc96d014da2dcc4b03894fd1cd3ed841843vboxsync * @param pVNIC Pointer to the VNIC.
e7b615a442051960547fd3835527b975ab7da970vboxsyncLOCAL void vboxNetFltSolarisFreeVNIC(PVBOXNETFLTVNIC pVNIC)
f6443fc96d014da2dcc4b03894fd1cd3ed841843vboxsync * Destroy a created VNIC if it was created by us, or just
f6443fc96d014da2dcc4b03894fd1cd3ed841843vboxsync * de-initializes the VNIC freeing up resources handles.
f6443fc96d014da2dcc4b03894fd1cd3ed841843vboxsync * @param pVNIC Pointer to the VNIC.
e7b615a442051960547fd3835527b975ab7da970vboxsyncLOCAL void vboxNetFltSolarisDestroyVNIC(PVBOXNETFLTVNIC pVNIC)
e7b615a442051960547fd3835527b975ab7da970vboxsync mac_unicast_remove(pVNIC->hClient, pVNIC->hUnicast);
e7b615a442051960547fd3835527b975ab7da970vboxsync * Create a non-persistent VNIC over the given interface.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @param pThis The VM connection instance.
e7b615a442051960547fd3835527b975ab7da970vboxsync * @param ppVNIC Where to store the created VNIC.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * @returns VBox status code.
e7b615a442051960547fd3835527b975ab7da970vboxsyncLOCAL int vboxNetFltSolarisCreateVNIC(PVBOXNETFLTINS pThis, PVBOXNETFLTVNIC *ppVNIC)
e7b615a442051960547fd3835527b975ab7da970vboxsync LogFlow((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC pThis=%p\n", pThis));
e7b615a442051960547fd3835527b975ab7da970vboxsync PVBOXNETFLTVNIC pVNIC = vboxNetFltSolarisAllocVNIC();
e7b615a442051960547fd3835527b975ab7da970vboxsync RTStrPrintf(pVNIC->szName, sizeof(pVNIC->szName), "%s%RU64", VBOXFLT_VNIC_NAME, pThis->u.s.uInstance);
76a6b12b9722672f423c9c5026c4b1df6c9ef762vboxsync * Set a random MAC address for now. It will be changed to the VM interface's
76a6b12b9722672f423c9c5026c4b1df6c9ef762vboxsync * MAC address later, see vboxNetFltPortOsNotifyMacAddress().
e7b615a442051960547fd3835527b975ab7da970vboxsync vnic_mac_addr_type_t AddrType = VNIC_MAC_ADDR_TYPE_FIXED;
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync pVNIC->pVNICTemplate = RTMemAllocZ(sizeof(VBOXNETFLTVNICTEMPLATE));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Initialize the VNIC template.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync rc = vboxNetFltSolarisInitVNICTemplate(pThis, pVNIC, pVNIC->pVNICTemplate);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed to initialize VNIC from VNIC template. rc=%Rrc\n", rc));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Required only if we're creating a VLAN interface & not a VNIC with a VLAN Id.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogFlow((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC pThis=%p VLAN Id=%u\n", pThis, uVLANId));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Create the VNIC under 'pszLinkName', which can be the one from the VNIC template or can
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * be a physical interface.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync rc = vnic_create(pVNIC->szName, pszLinkName, &AddrType, &MacLen, GuestMac.au8, &MacSlot, 0 /* Mac-Prefix Length */, uVLANId,
e7b615a442051960547fd3835527b975ab7da970vboxsync fFlags, &pVNIC->hLinkId, &Diag, NULL /* Reserved */);
e7b615a442051960547fd3835527b975ab7da970vboxsync * Now try opening the created VNIC.
e7b615a442051960547fd3835527b975ab7da970vboxsync rc = mac_open_by_linkid(pVNIC->hLinkId, &pVNIC->hInterface);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Initialize the VNIC from the physical interface or the VNIC template.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogFlow((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC successfully created VNIC '%s' over '%s' with random mac %.6Rhxs\n",
e7b615a442051960547fd3835527b975ab7da970vboxsync LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC vboxNetFltSolarisInitVNIC failed. rc=%d\n", rc));
e7b615a442051960547fd3835527b975ab7da970vboxsync LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed to open VNIC '%s' over '%s'. rc=%d\n", pVNIC->szName,
e7b615a442051960547fd3835527b975ab7da970vboxsync LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed to create VNIC '%s' over '%s' rc=%d Diag=%d\n", pVNIC->szName,
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Wrapper for getting the datalink ID given the MAC name.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * @param pszMacName The MAC name.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * @param pLinkId Where to store the datalink ID.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * @returns VBox status code.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsyncLOCAL inline int vboxNetFltSolarisGetLinkId(const char *pszMacName, datalink_id_t *pLinkId)
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * dls_mgmt_get_linkid() requires to be in a state to answer upcalls. We should always use this
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * first before resorting to other means to retrieve the MAC name.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync rc = dls_devnet_macname2linkid(pszMacName, pLinkId);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogRel((DEVICE_NAME ":vboxNetFltSolarisGetLinkId failed for '%s'. rc=%d\n", pszMacName, rc));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync/* -=-=-=-=-=- Common Hooks -=-=-=-=-=- */
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncvoid vboxNetFltPortOsSetActive(PVBOXNETFLTINS pThis, bool fActive)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogFlow((DEVICE_NAME ":vboxNetFltPortOsSetActive pThis=%p fActive=%d\n", pThis, fActive));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Activate promiscuous mode.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync int rc = mac_promisc_add(pThis->u.s.hClient, MAC_CLIENT_PROMISC_ALL, vboxNetFltSolarisRecv, pThis, &pThis->u.s.hPromiscuous,
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogRel((DEVICE_NAME ":vboxNetFltPortOsSetActive cannot enable promiscuous mode for '%s' rc=%d\n", pThis->szName, rc));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Deactivate promiscuous mode.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogFlow((DEVICE_NAME ":vboxNetFltOsDisconnectIt pThis=%p\n", pThis));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogFlow((DEVICE_NAME ":vboxNetFltOsConnectIt pThis=%p\n", pThis));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncvoid vboxNetFltOsDeleteInstance(PVBOXNETFLTINS pThis)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogFlow((DEVICE_NAME ":vboxNetFltOsDeleteInstance pThis=%p\n", pThis));
e7b615a442051960547fd3835527b975ab7da970vboxsync * Destroy all managed VNICs. If a VNIC was passed to us, there
e7b615a442051960547fd3835527b975ab7da970vboxsync * will be only 1 item in the list, otherwise as many interfaces
e7b615a442051960547fd3835527b975ab7da970vboxsync * that were somehow not destroyed using DisconnectInterface() will be
e7b615a442051960547fd3835527b975ab7da970vboxsync while ((pVNIC = list_remove_head(&pThis->u.s.hVNICs)) != NULL)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncint vboxNetFltOsInitInstance(PVBOXNETFLTINS pThis, void *pvContext)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync LogFlow((DEVICE_NAME ":vboxNetFltOsInitInstance pThis=%p pvContext=%p\n", pThis, pvContext));
2135a0a48189b91cd746a83b2758bc4cfe257b94vboxsync * Figure out if the interface is a VNIC or a physical/etherstub/whatever NIC.
e7b615a442051960547fd3835527b975ab7da970vboxsync int rc = mac_open_by_linkname(pThis->szName, &hInterface);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Physical Interface: Just pretend success for now.
76a6b12b9722672f423c9c5026c4b1df6c9ef762vboxsync * We will create a VNIC per VM interface later, see vboxNetFltPortOsConnectInterface().
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync vboxNetFltSolarisReportInfo(pThis, hInterface, pThis->u.s.fIsVNIC);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync if (RTStrNCmp(pThis->szName, VBOXFLT_VNIC_TEMPLATE_NAME, sizeof(VBOXFLT_VNIC_TEMPLATE_NAME) - 1) == 0)
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * VNIC Template: Just pretend success for now.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * We will create a VNIC per VM interface later, see vboxNetFltPortOsConnectInterface().
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogFlow((DEVICE_NAME ":vboxNetFltOsInitInstance pThis=%p VNIC template '%s' detected.\n", pThis, pThis->szName));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync vboxNetFltSolarisReportInfo(pThis, hInterface, pThis->u.s.fIsVNIC);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * VNIC: Alloc & init. the VNIC structure and use the VNIC directly.
e7b615a442051960547fd3835527b975ab7da970vboxsync PVBOXNETFLTVNIC pVNIC = vboxNetFltSolarisAllocVNIC();
2135a0a48189b91cd746a83b2758bc4cfe257b94vboxsync * Obtain the data link ID for this VNIC, it's needed for modifying the MAC address among other things.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync rc = vboxNetFltSolarisGetLinkId(pThis->szName, &pVNIC->hLinkId);
e7b615a442051960547fd3835527b975ab7da970vboxsync * Initialize the VNIC and add it to the list of managed VNICs.
e7b615a442051960547fd3835527b975ab7da970vboxsync RTStrPrintf(pVNIC->szName, sizeof(pVNIC->szName), "%s", pThis->szName);
e7b615a442051960547fd3835527b975ab7da970vboxsync LogRel((DEVICE_NAME ":vboxNetFltOsInitInstance vboxNetFltSolarisInitVNIC failed. rc=%d\n", rc));
e7b615a442051960547fd3835527b975ab7da970vboxsync LogRel((DEVICE_NAME ":vboxNetFltOsInitInstance failed to get link id for '%s'. rc=%d\n", pThis->szName, rc));
e7b615a442051960547fd3835527b975ab7da970vboxsync LogRel((DEVICE_NAME ":vboxNetFltOsInitInstance failed to allocate VNIC private data.\n"));
bfde57a3a4d74895d4c5434f9bdfb2be700f9e57vboxsync LogRel((DEVICE_NAME ":vboxNetFltOsInitInstance failed to open link '%s'! rc=%d\n", pThis->szName, rc));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncint vboxNetFltOsPreInitInstance(PVBOXNETFLTINS pThis)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * Init. the solaris specific data.
e7b615a442051960547fd3835527b975ab7da970vboxsync list_create(&pThis->u.s.hVNICs, sizeof(VBOXNETFLTVNIC), offsetof(VBOXNETFLTVNIC, hNode));
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsyncbool vboxNetFltOsMaybeRediscovered(PVBOXNETFLTINS pThis)
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync * @todo Think about this.
becf3c759c574f9450ebc8b558c1cca8dc8b944bvboxsync return false;
586cf6585d0e6aa3bef888eeff116bf82d18cd83vboxsyncint vboxNetFltPortOsXmit(PVBOXNETFLTINS pThis, void *pvIfData, PINTNETSG pSG, uint32_t fDst)
e7b615a442051960547fd3835527b975ab7da970vboxsync * Validate parameters.
e7b615a442051960547fd3835527b975ab7da970vboxsync AssertMsgReturn(VALID_PTR(pVNIC) && pVNIC->u32Magic == VBOXNETFLTVNIC_MAGIC,
e7b615a442051960547fd3835527b975ab7da970vboxsync ("Invalid pvIfData=%p magic=%#x (expected %#x)\n", pvIfData, pVNIC ? pVNIC->u32Magic : 0, VBOXNETFLTVNIC_MAGIC),
e7b615a442051960547fd3835527b975ab7da970vboxsync * Xmit the packet down the appropriate VNIC interface.
e7b615a442051960547fd3835527b975ab7da970vboxsync mblk_t *pMsg = vboxNetFltSolarisMBlkFromSG(pThis, pSG, fDst);
e7b615a442051960547fd3835527b975ab7da970vboxsync LogFlow((DEVICE_NAME ":vboxNetFltPortOsXmit pThis=%p cbData=%d\n", pThis, MBLKL(pMsg)));
e7b615a442051960547fd3835527b975ab7da970vboxsync mac_tx_cookie_t pXmitCookie = mac_tx(pVNIC->hClient, pMsg, 0 /* Hint */, MAC_DROP_ON_NO_DESC, NULL /* return message */);
e7b615a442051960547fd3835527b975ab7da970vboxsync LogFlow((DEVICE_NAME ":vboxNetFltPortOsXmit Xmit failed pVNIC=%p.\n", pVNIC));
e7b615a442051960547fd3835527b975ab7da970vboxsync LogRel((DEVICE_NAME ":vboxNetFltPortOsXmit no memory for allocating Xmit packet.\n"));
586cf6585d0e6aa3bef888eeff116bf82d18cd83vboxsyncvoid vboxNetFltPortOsNotifyMacAddress(PVBOXNETFLTINS pThis, void *pvIfData, PCRTMAC pMac)
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogFlow((DEVICE_NAME ":vboxNetFltPortOSNotifyMacAddress pszIf=%s pszVNIC=%s MAC=%.6Rhxs\n", pThis->szName,
e7b615a442051960547fd3835527b975ab7da970vboxsync * Validate parameters.
e7b615a442051960547fd3835527b975ab7da970vboxsync AssertMsgReturnVoid(VALID_PTR(pVNIC) && pVNIC->u32Magic == VBOXNETFLTVNIC_MAGIC,
e7b615a442051960547fd3835527b975ab7da970vboxsync ("Invalid pvIfData=%p magic=%#x (expected %#x)\n", pvIfData, pVNIC ? pVNIC->u32Magic : 0, VBOXNETFLTVNIC_MAGIC));
e7b615a442051960547fd3835527b975ab7da970vboxsync AssertMsgReturnVoid(pVNIC->hLinkId != DATALINK_INVALID_LINKID,
e7b615a442051960547fd3835527b975ab7da970vboxsync ("Invalid hLinkId pVNIC=%p magic=%#x\n", pVNIC, pVNIC->u32Magic));
e7b615a442051960547fd3835527b975ab7da970vboxsync * Set the MAC address of the VNIC to the one used by the VM interface.
e7b615a442051960547fd3835527b975ab7da970vboxsync vnic_mac_addr_type_t AddrType = VNIC_MAC_ADDR_TYPE_FIXED;
e7b615a442051960547fd3835527b975ab7da970vboxsync int rc = vnic_modify_addr(pVNIC->hLinkId, &AddrType, &MacLen, au8GuestMac, &MacSlot, 0 /* Mac-Prefix Length */, &Diag);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Remove existing unicast address and the RX hook.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync mac_unicast_remove(pVNIC->hClient, pVNIC->hUnicast);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Add the primary unicast address and set the RX hook.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync /* uint16_t uVLANId = pVNIC->pVNICTemplate ? pVNIC->pVNICTemplate->uVLANId : 0; */
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync rc = mac_unicast_add(pVNIC->hClient, NULL, MAC_UNICAST_PRIMARY, &pVNIC->hUnicast, 0 /* VLAN Id */, &MacDiag);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Set the RX receive function.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync mac_rx_set(pVNIC->hClient, vboxNetFltSolarisRecv, pThis);
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogFlow((DEVICE_NAME ":vboxNetFltPortOsNotifyMacAddress successfully added unicast address %.6Rhxs\n", pMac));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogRel((DEVICE_NAME ":vboxNetFltPortOsNotifyMacAddress failed to add primary unicast address. rc=%d Diag=%d\n", rc, MacDiag));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * They really ought to use EEXIST, but I'm afraid this error comes from the VNIC device driver directly.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * Sequence: vnic_modify_addr()->mac_unicast_primary_set()->mac_update_macaddr() which uses a function pointer
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * to the MAC driver (calls mac_vnic_unicast_set() in our case). Documented here if the error code should change we know
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * where to look.
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogRel((DEVICE_NAME ":vboxNetFltPortOsNotifyMacAddress: failed! a VNIC with mac %.6Rhxs probably already exists.",
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogRel((DEVICE_NAME ":vboxNetFltPortOsNotifyMacAddress: This NIC cannot establish connection. szName=%s szVNIC=%s\n",
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync LogRel((DEVICE_NAME ":vboxNetFltPortOsNotifyMacAddress failed! mac %.6Rhxs rc=%d Diag=%d\n", pMac, rc, Diag));
e7b615a442051960547fd3835527b975ab7da970vboxsyncint vboxNetFltPortOsConnectInterface(PVBOXNETFLTINS pThis, void *pvIf, void **ppvIfData)
e7b615a442051960547fd3835527b975ab7da970vboxsync LogFlow((DEVICE_NAME ":vboxNetFltPortOsConnectInterface pThis=%p pvIf=%p\n", pThis, pvIf));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * If the underlying interface is a physical interface or a VNIC template, we need to create
e7b615a442051960547fd3835527b975ab7da970vboxsync * a VNIC per guest NIC.
e7b615a442051960547fd3835527b975ab7da970vboxsync * VM Interface<->VNIC association so that we can Xmit/Recv on the right ones.
e7b615a442051960547fd3835527b975ab7da970vboxsync * Add the created VNIC to the list of VNICs we manage.
f6443fc96d014da2dcc4b03894fd1cd3ed841843vboxsync LogRel((DEVICE_NAME ":vboxNetFltPortOsConnectInterface failed to create VNIC rc=%d\n", rc));
a1fb412664878af4f651bc29cb8e324fe09be33fvboxsync * This is a VNIC passed to us, use it directly.
e7b615a442051960547fd3835527b975ab7da970vboxsync PVBOXNETFLTVNIC pVNIC = list_head(&pThis->u.s.hVNICs);
e7b615a442051960547fd3835527b975ab7da970vboxsync LogFlow((DEVICE_NAME ":vboxNetFltPortOsConnectInterface set VNIC '%s' private data\n", pVNIC->szName));
e7b615a442051960547fd3835527b975ab7da970vboxsync LogRel((DEVICE_NAME ":vboxNetFltPortOsConnectInterface huh!? Missing VNIC!\n"));
e7b615a442051960547fd3835527b975ab7da970vboxsyncint vboxNetFltPortOsDisconnectInterface(PVBOXNETFLTINS pThis, void *pvIfData)
e7b615a442051960547fd3835527b975ab7da970vboxsync LogFlow((DEVICE_NAME ":vboxNetFltPortOsDisconnectInterface pThis=%p\n", pThis));
e7b615a442051960547fd3835527b975ab7da970vboxsync AssertMsgReturn(VALID_PTR(pVNIC) && pVNIC->u32Magic == VBOXNETFLTVNIC_MAGIC,
e7b615a442051960547fd3835527b975ab7da970vboxsync ("Invalid pvIfData=%p magic=%#x (expected %#x)\n", pvIfData, pVNIC ? pVNIC->u32Magic : 0, VBOXNETFLTVNIC_MAGIC),
e7b615a442051960547fd3835527b975ab7da970vboxsync * If the underlying interface is not a VNIC, we need to delete the created VNIC.
e7b615a442051960547fd3835527b975ab7da970vboxsync * Remove the VNIC from the list, destroy and free it.
b794e27fc33d6127d7157ea70b371be557625e21vboxsync LogFlow((DEVICE_NAME ":vboxNetFltPortOsDisconnectInterface destroying pVNIC=%p\n", pVNIC));