DevINIP.cpp revision a7d402dcc23137e7b9527be6de80400043a5fbf4
157093a77f2752732368338110cb50fa6cd7717fvboxsync * DevINIP - Internal Network IP stack device/service.
157093a77f2752732368338110cb50fa6cd7717fvboxsync * Copyright (C) 2007-2009 Sun Microsystems, Inc.
157093a77f2752732368338110cb50fa6cd7717fvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
157093a77f2752732368338110cb50fa6cd7717fvboxsync * available from http://www.virtualbox.org. This file is free software;
157093a77f2752732368338110cb50fa6cd7717fvboxsync * you can redistribute it and/or modify it under the terms of the GNU
157093a77f2752732368338110cb50fa6cd7717fvboxsync * General Public License (GPL) as published by the Free Software
157093a77f2752732368338110cb50fa6cd7717fvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
157093a77f2752732368338110cb50fa6cd7717fvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
157093a77f2752732368338110cb50fa6cd7717fvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
157093a77f2752732368338110cb50fa6cd7717fvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
157093a77f2752732368338110cb50fa6cd7717fvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
157093a77f2752732368338110cb50fa6cd7717fvboxsync * additional information or have any questions.
157093a77f2752732368338110cb50fa6cd7717fvboxsync/*******************************************************************************
157093a77f2752732368338110cb50fa6cd7717fvboxsync* Header Files *
2ac3892cdc8b16a0dee55e8b4510b8ecea83c95fvboxsync*******************************************************************************/
59c7f47943ae42abc3d4e1c6d87b789b668b1260vboxsync#include <iprt/cdefs.h> /* include early to allow RT_C_DECLS_BEGIN hack */
157093a77f2752732368338110cb50fa6cd7717fvboxsync#include <iprt/mem.h> /* include anything of ours that the lwip headers use. */
2ac3892cdc8b16a0dee55e8b4510b8ecea83c95fvboxsync/* All lwip header files are not C++ safe. So hack around this. */
157093a77f2752732368338110cb50fa6cd7717fvboxsync/*******************************************************************************
157093a77f2752732368338110cb50fa6cd7717fvboxsync* Macros and Defines *
157093a77f2752732368338110cb50fa6cd7717fvboxsync*******************************************************************************/
157093a77f2752732368338110cb50fa6cd7717fvboxsync/** Maximum frame size this device can handle. */
157093a77f2752732368338110cb50fa6cd7717fvboxsync/*******************************************************************************
157093a77f2752732368338110cb50fa6cd7717fvboxsync* Structures and Typedefs *
157093a77f2752732368338110cb50fa6cd7717fvboxsync*******************************************************************************/
157093a77f2752732368338110cb50fa6cd7717fvboxsync * Internal Network IP stack device instance data.
157093a77f2752732368338110cb50fa6cd7717fvboxsync * @implements PDMIBASE
157093a77f2752732368338110cb50fa6cd7717fvboxsync * @implements PDMINETWORKDOWN
157093a77f2752732368338110cb50fa6cd7717fvboxsynctypedef struct DEVINTNETIP
157093a77f2752732368338110cb50fa6cd7717fvboxsync /** The base interface for LUN\#0. */
157093a77f2752732368338110cb50fa6cd7717fvboxsync /** The network port this device provides (LUN\#0). */
157093a77f2752732368338110cb50fa6cd7717fvboxsync /** The base interface of the network driver below us. */
157093a77f2752732368338110cb50fa6cd7717fvboxsync /** The connector of the network driver below us. */
2ac3892cdc8b16a0dee55e8b4510b8ecea83c95fvboxsync /** Pointer to the device instance. */
2ac3892cdc8b16a0dee55e8b4510b8ecea83c95fvboxsync /** MAC adress. */
2ac3892cdc8b16a0dee55e8b4510b8ecea83c95fvboxsync /** Static IP address of the interface. */
2ac3892cdc8b16a0dee55e8b4510b8ecea83c95fvboxsync /** Netmask of the interface. */
2ac3892cdc8b16a0dee55e8b4510b8ecea83c95fvboxsync /** Gateway for the interface. */
2ac3892cdc8b16a0dee55e8b4510b8ecea83c95fvboxsync /** lwIP network interface description. */
2ac3892cdc8b16a0dee55e8b4510b8ecea83c95fvboxsync /** lwIP ARP timer. */
2ac3892cdc8b16a0dee55e8b4510b8ecea83c95fvboxsync /** lwIP TCP fast timer. */
2ac3892cdc8b16a0dee55e8b4510b8ecea83c95fvboxsync /** lwIP TCP slow timer. */
2ac3892cdc8b16a0dee55e8b4510b8ecea83c95fvboxsync /** lwIP semaphore to coordinate TCPIP init/terminate. */
2ac3892cdc8b16a0dee55e8b4510b8ecea83c95fvboxsync /** hack: get linking right. remove this eventually, once the device
59c7f47943ae42abc3d4e1c6d87b789b668b1260vboxsync * provides a proper interface to all IP stack functions. */
59c7f47943ae42abc3d4e1c6d87b789b668b1260vboxsync/*******************************************************************************
59c7f47943ae42abc3d4e1c6d87b789b668b1260vboxsync* Global Variables *
59c7f47943ae42abc3d4e1c6d87b789b668b1260vboxsync*******************************************************************************/
59c7f47943ae42abc3d4e1c6d87b789b668b1260vboxsync * Pointer to the (only) instance data in this device.
59c7f47943ae42abc3d4e1c6d87b789b668b1260vboxsync * really ugly hack to avoid linking problems on unix style platforms
59c7f47943ae42abc3d4e1c6d87b789b668b1260vboxsync * using .a libraries for now.
157093a77f2752732368338110cb50fa6cd7717fvboxsync/*******************************************************************************
157093a77f2752732368338110cb50fa6cd7717fvboxsync* Internal Functions *
157093a77f2752732368338110cb50fa6cd7717fvboxsync*******************************************************************************/
157093a77f2752732368338110cb50fa6cd7717fvboxsyncstatic DECLCALLBACK(void) devINIPARPTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer);
157093a77f2752732368338110cb50fa6cd7717fvboxsyncstatic DECLCALLBACK(void) devINIPTCPFastTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer);
157093a77f2752732368338110cb50fa6cd7717fvboxsyncstatic DECLCALLBACK(void) devINIPTCPSlowTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer);
157093a77f2752732368338110cb50fa6cd7717fvboxsyncstatic DECLCALLBACK(err_t) devINIPOutput(struct netif *netif, struct pbuf *p,
157093a77f2752732368338110cb50fa6cd7717fvboxsyncstatic DECLCALLBACK(err_t) devINIPOutputRaw(struct netif *netif,
157093a77f2752732368338110cb50fa6cd7717fvboxsync struct pbuf *p);
157093a77f2752732368338110cb50fa6cd7717fvboxsyncstatic DECLCALLBACK(err_t) devINIPInterface(struct netif *netif);
157093a77f2752732368338110cb50fa6cd7717fvboxsync * ARP cache timeout handling for lwIP.
157093a77f2752732368338110cb50fa6cd7717fvboxsync * @param pDevIns Device instance.
157093a77f2752732368338110cb50fa6cd7717fvboxsync * @param pTimer Pointer to timer.
157093a77f2752732368338110cb50fa6cd7717fvboxsyncstatic DECLCALLBACK(void) devINIPARPTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
157093a77f2752732368338110cb50fa6cd7717fvboxsync LogFlow(("%s: pDevIns=%p pTimer=%p\n", __FUNCTION__, pDevIns, pTimer));
157093a77f2752732368338110cb50fa6cd7717fvboxsync TMTimerSetMillies(pThis->ARPTimer, ARP_TMR_INTERVAL);
157093a77f2752732368338110cb50fa6cd7717fvboxsync * TCP fast timer handling for lwIP.
157093a77f2752732368338110cb50fa6cd7717fvboxsync * @param pDevIns Device instance.
2ac3892cdc8b16a0dee55e8b4510b8ecea83c95fvboxsync * @param pTimer Pointer to timer.
2ac3892cdc8b16a0dee55e8b4510b8ecea83c95fvboxsyncstatic DECLCALLBACK(void) devINIPTCPFastTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
157093a77f2752732368338110cb50fa6cd7717fvboxsync LogFlow(("%s: pDevIns=%p pTimer=%p\n", __FUNCTION__, pDevIns, pTimer));
return lrc;
struct pbuf *p)
if (g_pDevINIPData)
rc = g_pDevINIPData->pDrv->pfnAllocBuf(g_pDevINIPData->pDrv, DEVINIP_MAX_FRAME, NULL /*pGso*/, &pSgBuf);
#if ETH_PAD_SIZE
if (cbBuf)
#if ETH_PAD_SIZE
return lrc;
return ERR_OK;
static DECLCALLBACK(int) devINIPNetworkDown_WaitInputAvail(PPDMINETWORKDOWN pInterface, RTMSINTERVAL cMillies)
return VINF_SUCCESS;
struct pbuf *p, *q;
if (!g_pDevINIPData)
goto out;
#if ETH_PAD_SIZE
if (p != NULL)
#if ETH_PAD_SIZE
if (lrc)
lwip_pbuf_free(p);
out:
return rc;
const char *pszIID)
return NULL;
return VINF_SUCCESS;
goto out;
goto out;
macStr++;
goto out;
goto out;
goto out;
goto out;
goto out;
goto out;
goto out;
goto out;
goto out;
#if MEM_LIBC_MALLOC == 0
goto out;
goto out;
goto out;
if (!ret)
goto out;
out:
return rc;
bool DevINIPConfigured(void)
sizeof(DEVINTNETIP),
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,