VBoxNetFlt-darwin.cpp revision e64031e20c39650a7bc902a3e1aba613b9415dee
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * VBoxNetFlt - Network Filter Driver (Host), Darwin Specific Code.
c58f1213e628a545081c70e26c6b67a841cff880vboxsync * Copyright (C) 2006-2008 Oracle Corporation
dba6b8a60465a62d3e1ee74942535288802e2b79vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
dba6b8a60465a62d3e1ee74942535288802e2b79vboxsync * available from http://www.virtualbox.org. This file is free software;
dba6b8a60465a62d3e1ee74942535288802e2b79vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync/*******************************************************************************
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync* Header Files *
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync*******************************************************************************/
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Deal with conflicts first.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * PVM - BSD mess, that FreeBSD has correct a long time ago.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * iprt/types.h before sys/param.h - prevents UINT32_C and friends.
#include "../VBoxNetFltInternal.h"
typedef struct VBOXNETFLTTAG
static unsigned g_offIfNetPCount = sizeof(void *) * (1 /*if_softc*/ + 1 /*if_name*/ + 2 /*if_link*/ + 2 /*if_addrhead*/ + 1 /*if_check_multi*/)
int rc;
if (!err)
return KMOD_RETURN_SUCCESS;
RTR0Term();
return KMOD_RETURN_FAILURE;
return KMOD_RETURN_FAILURE;
RTR0Term();
return KMOD_RETURN_SUCCESS;
if (pIfNet)
return pIfNet;
if (pIfNet)
if (err)
if (!pEthHdr)
if (!pEthHdr)
if (!err)
if (!err)
err = mbuf_tag_allocate(pPkt, g_idTag, 0 /* type */, sizeof(VBOXNETFLTTAG) /* tag len */, How, (void **)&pTagData);
if (!err)
return pPkt;
return NULL;
DECLINLINE(unsigned) vboxNetFltDarwinMBufCalcSGSegs(PVBOXNETFLTINS pThis, mbuf_t pMBuf, void *pvFrame)
unsigned cSegs = 0;
cSegs++;
else if ( !cSegs
&& pvFrame
cSegs++;
#ifdef PADD_RUNT_FRAMES_FROM_HOST
cSegs++;
DECLINLINE(void) vboxNetFltDarwinMBufToSG(PVBOXNETFLTINS pThis, mbuf_t pMBuf, void *pvFrame, PINTNETSG pSG, unsigned cSegs, uint32_t fSrc)
unsigned iSeg = 0;
if (cbSeg)
Assert(pvStart && pvSeg && offSeg < mbuf_maxlen(pMBuf) && offSegEnd <= mbuf_maxlen(pMBuf)); NOREF(offSegEnd);
AssertMsgFailed(("pvFrame=%p pvStart=%p pvSeg=%p offSeg=%p cbSeg=%#zx offSegEnd=%p offFrame=%p maxlen=%#zx\n",
iSeg++;
else if ( !iSeg
&& pvFrame
iSeg++;
#ifdef PADD_RUNT_FRAMES_FROM_HOST
while (iSrc > 0)
iDst--;
iSrc--;
iDst = 0;
iDst++;
bool fRc = false;
if (pIfNet)
return fRc;
if (pIfNet)
static errno_t vboxNetFltDarwinIffIoCtl(void *pvThis, ifnet_t pIfNet, protocol_family_t eProtocol, u_long uCmd, void *pvArg)
return EOPNOTSUPP;
static void vboxNetFltDarwinIffEvent(void *pvThis, ifnet_t pIfNet, protocol_family_t eProtocol, const struct kev_msg *pEvMsg)
if (!err)
Log(("vboxNetFltDarwinIffEvent: enabled promiscuous mode on %s (%d)\n", pThis->szName, VBOX_GET_PCOUNT(pIfNet)));
Log(("vboxNetFltDarwinIffEvent: ifnet_set_promiscuous failed on %s, err=%d (%d)\n", pThis->szName, err, VBOX_GET_PCOUNT(pIfNet)));
if (!err)
Log(("vboxNetFltDarwinIffEvent: fixed IFF_PROMISC on %s (%d)\n", pThis->szName, VBOX_GET_PCOUNT(pIfNet)));
Log(("vboxNetFltDarwinIffEvent: online, '%s'. flags=%#x (%d)\n", pThis->szName, ifnet_flags(pIfNet), VBOX_GET_PCOUNT(pIfNet)));
Log(("vboxNetFltDarwinIffEvent: pThis->u.s.pIfNet=%p pIfNet=%p (%d)\n", pThis->u.s.pIfNet, pIfNet, VALID_PTR(pIfNet) ? VBOX_GET_PCOUNT(pIfNet) : -1));
static errno_t vboxNetFltDarwinIffInputOutputWorker(PVBOXNETFLTINS pThis, mbuf_t pMBuf, void *pvFrame,
if (!pMBuf)
if (fActive)
if (!fActive)
bool fDropIt = false;
if (fDropIt)
static errno_t vboxNetFltDarwinIffOutput(void *pvThis, ifnet_t pIfNet, protocol_family_t eProtocol, mbuf_t *ppMBuf)
return vboxNetFltDarwinIffInputOutputWorker((PVBOXNETFLTINS)pvThis, *ppMBuf, NULL, INTNETTRUNKDIR_HOST, eProtocol);
static errno_t vboxNetFltDarwinIffInput(void *pvThis, ifnet_t pIfNet, protocol_family_t eProtocol, mbuf_t *ppMBuf, char **ppchFrame)
return vboxNetFltDarwinIffInputOutputWorker((PVBOXNETFLTINS)pvThis, *ppMBuf, *ppchFrame, INTNETTRUNKDIR_WIRE, eProtocol);
if (err)
if (!fRediscovery)
return VERR_INTNET_FLT_IF_NOT_FOUND;
if (!err)
if (!pIfNet)
pThis->pSwitchPort->pfnReportPromiscuousMode(pThis->pSwitchPort, vboxNetFltDarwinIsPromiscuous(pThis));
pThis->pSwitchPort->pfnReportGsoCapabilities(pThis->pSwitchPort, 0, INTNETTRUNKDIR_WIRE | INTNETTRUNKDIR_HOST);
if (pIfNet)
LogRel(("VBoxFltDrv: attached to '%s' / %.*Rhxs\n", pThis->szName, sizeof(pThis->u.s.MacAddr), &pThis->u.s.MacAddr));
return rc;
if (pIfNet)
if (pMBuf)
if (err)
if (pMBuf)
if (err)
return rc;
if (pIfNet)
if (fActive)
if (fActive)
if (!err)
if (!err)
if (!err)
if (!err)
Log(("vboxNetFlt: fixed IFF_PROMISC on %s (%d->%d)\n", pThis->szName, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet)));
Log(("VBoxNetFlt: ifnet_set_promiscuous -> err=%d grr! (%d->%d)\n", err, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet)));
else if (!err)
Log(("VBoxNetFlt: Waiting for the link to come up... (%d->%d)\n", cPromiscBefore, VBOX_GET_PCOUNT(pIfNet)));
if (err)
LogRel(("VBoxNetFlt: Failed to put '%s' into promiscuous mode, err=%d (%d->%d)\n", pThis->szName, err, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet)));
return VINF_SUCCESS;
return VINF_SUCCESS;
if (pIfFilter)
if (pIfFilter)
//pThis->u.s.MacAddr = {0};
return VINF_SUCCESS;