DevINIP.cpp revision 01644b3fb3841a1b087fb2a5b8c2870d9876541b
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * DevINIP - Internal Network IP stack device/service.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2007-2009 Oracle Corporation
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * available from http://www.virtualbox.org. This file is free software;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * you can redistribute it and/or modify it under the terms of the GNU
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * General Public License (GPL) as published by the Free Software
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync/*******************************************************************************
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync* Header Files *
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync*******************************************************************************/
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsync#include <iprt/cdefs.h> /* include early to allow RT_C_DECLS_BEGIN hack */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync#include <iprt/mem.h> /* include anything of ours that the lwip headers use. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync/* All lwip header files are not C++ safe. So hack around this. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync/*******************************************************************************
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync* Macros and Defines *
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync*******************************************************************************/
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync/** Maximum frame size this device can handle. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync/*******************************************************************************
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync* Structures and Typedefs *
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync*******************************************************************************/
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Internal Network IP stack device instance data.
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements PDMIBASE
787c7e6ef15f993c455c374f5158e7bb753b1c33vboxsync * @implements PDMINETWORKDOWN
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsynctypedef struct DEVINTNETIP
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync /** The base interface for LUN\#0. */
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync /** The network port this device provides (LUN\#0). */
114aab25ffaeef9fba3a27b58ac0c07296bb5814vboxsync /** The network configuration port this device provides (LUN\#0). */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /** The base interface of the network driver below us. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /** The connector of the network driver below us. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /** Pointer to the device instance. */
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync /** MAC address. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /** Static IP address of the interface. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /** Netmask of the interface. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /** Gateway for the interface. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /** lwIP network interface description. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /** lwIP ARP timer. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /** lwIP TCP fast timer. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /** lwIP TCP slow timer. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /** lwIP semaphore to coordinate TCPIP init/terminate. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /** hack: get linking right. remove this eventually, once the device
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * provides a proper interface to all IP stack functions. */
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync /** Flag whether the link is up. */
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync /** Flag whether the configuration is IPv6 */
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync /** Static IPv6 address of the interface. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync/*******************************************************************************
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync* Global Variables *
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync*******************************************************************************/
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Pointer to the (only) instance data in this device.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * really ugly hack to avoid linking problems on unix style platforms
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * using .a libraries for now.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync/*******************************************************************************
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync* Internal Functions *
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync*******************************************************************************/
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncstatic DECLCALLBACK(void) devINIPARPTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncstatic DECLCALLBACK(void) devINIPTCPFastTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncstatic DECLCALLBACK(void) devINIPTCPSlowTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncstatic DECLCALLBACK(err_t) devINIPOutput(struct netif *netif, struct pbuf *p,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncstatic DECLCALLBACK(err_t) devINIPOutputRaw(struct netif *netif,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync struct pbuf *p);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncstatic DECLCALLBACK(err_t) devINIPInterface(struct netif *netif);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * ARP cache timeout handling for lwIP.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param pDevIns Device instance.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param pTimer Pointer to timer.
25747178cb66800d8386c20b8ffd87f78f24f4e5vboxsyncstatic DECLCALLBACK(void) devINIPARPTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlow(("%s: pDevIns=%p pTimer=%p\n", __FUNCTION__, pDevIns, pTimer));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync TMTimerSetMillies(pThis->ARPTimer, ARP_TMR_INTERVAL);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * TCP fast timer handling for lwIP.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param pDevIns Device instance.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param pTimer Pointer to timer.
25747178cb66800d8386c20b8ffd87f78f24f4e5vboxsyncstatic DECLCALLBACK(void) devINIPTCPFastTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlow(("%s: pDevIns=%p pTimer=%p\n", __FUNCTION__, pDevIns, pTimer));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync TMTimerSetMillies(pThis->TCPFastTimer, TCP_FAST_INTERVAL);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * TCP slow timer handling for lwIP.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param pDevIns Device instance.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param pTimer Pointer to timer.
25747178cb66800d8386c20b8ffd87f78f24f4e5vboxsyncstatic DECLCALLBACK(void) devINIPTCPSlowTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlow(("%s: pDevIns=%p pTimer=%p\n", __FUNCTION__, pDevIns, pTimer));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync TMTimerSetMillies(pThis->TCPSlowTimer, TCP_SLOW_INTERVAL);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Output a TCP/IP packet on the interface. Uses the generic lwIP ARP
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * code to resolve the address and call the link-level packet function.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @returns lwIP error code
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param netif Interface on which to send IP packet.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param p Packet data.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param ipaddr Destination IP address.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncstatic DECLCALLBACK(err_t) devINIPOutput(struct netif *netif, struct pbuf *p,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlow(("%s: netif=%p p=%p ipaddr=%#04x\n", __FUNCTION__, netif, p,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Output a raw packet on the interface.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @returns lwIP error code
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param netif Interface on which to send frame.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param p Frame data.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncstatic DECLCALLBACK(err_t) devINIPOutputRaw(struct netif *netif,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlow(("%s: netif=%p p=%p\n", __FUNCTION__, netif, p));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* Silently ignore packets being sent while lwIP isn't set up. */
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync rc = g_pDevINIPData->pDrv->pfnBeginXmit(g_pDevINIPData->pDrv, true /* fOnWorkerThread */);
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync rc = g_pDevINIPData->pDrv->pfnAllocBuf(g_pDevINIPData->pDrv, DEVINIP_MAX_FRAME, NULL /*pGso*/, &pSgBuf);
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync lwip_pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync uint8_t *pbBuf = pSgBuf ? (uint8_t *)pSgBuf->aSegs[0].pvSeg : NULL;
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync rc = g_pDevINIPData->pDrv->pfnSendBuf(g_pDevINIPData->pDrv, pSgBuf, true /* fOnWorkerThread */);
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync rc = g_pDevINIPData->pDrv->pfnFreeBuf(g_pDevINIPData->pDrv, pSgBuf);
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync lwip_pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync g_pDevINIPData->pDrv->pfnEndXmit(g_pDevINIPData->pDrv);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlow(("%s: return %d (vbox: %Rrc)\n", __FUNCTION__, rc, lrc));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Implements the ethernet interface backend initialization for lwIP.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @returns lwIP error code
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param netif Interface to configure.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncstatic DECLCALLBACK(err_t) devINIPInterface(struct netif *netif)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync memcpy(netif->hwaddr, &g_pDevINIPData->MAC, sizeof(g_pDevINIPData->MAC));
1e61c2f4dd6e398ffa2028c55f1e0170b53fa7a3vboxsync /* @todo: why explicit ARP routing required for 1.2.0 case? */
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync /* @todo: Don't bother user with entering IPv6 address explicitly,
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync * instead what is required here that IPv6 local-address generation ?
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync if (!inet6_aton(g_pDevINIPData->pszIP6, &netif->ip6_addr[0]))
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync PDMDEV_SET_ERROR(g_pDevINIPData->pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync N_("Configuration error: Invalid \"IPv6\" value"));
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync netif_ip6_addr_set_state(netif, 0, IP6_ADDR_VALID);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync TMTimerSetMillies(g_pDevINIPData->ARPTimer, ARP_TMR_INTERVAL);
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync * Parses CFGM parameters related to network connection
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsyncstatic DECLCALLBACK(int) devINIPNetworkConfiguration(PPDMDEVINS pDevIns, PDEVINTNETIP pThis, PCFGMNODE pCfg)
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync rc = CFGMR3QueryStringAlloc(pCfg, "IP", &pThis->pszIP);
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync N_("Configuration error: Failed to get the \"IP\" value"));
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync rc = CFGMR3QueryStringAlloc(pCfg, "IPv6", &pThis->pszIP6);
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync N_("Configuration error: Failed to get the \"IPv6\" value"));
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync rc = CFGMR3QueryStringAlloc(pCfg, "Netmask", &pThis->pszNetmask);
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync N_("Configuration error: Failed to get the \"Netmask\" value"));
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync rc = CFGMR3QueryStringAlloc(pCfg, "Gateway", &pThis->pszGateway);
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync N_("Configuration error: Failed to get the \"Gateway\" value"));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Wait until data can be received.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @returns VBox status code. VINF_SUCCESS means there is at least one receive descriptor available.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param pInterface PDM network port interface pointer.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param cMillies Number of milliseconds to wait. 0 means return immediately.
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsyncstatic DECLCALLBACK(int) devINIPNetworkDown_WaitInputAvail(PPDMINETWORKDOWN pInterface, RTMSINTERVAL cMillies)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlow(("%s: pInterface=%p\n", __FUNCTION__, pInterface));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlow(("%s: return VINF_SUCCESS\n", __FUNCTION__));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Receive data and pass it to lwIP for processing.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @returns VBox status code
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param pInterface PDM network port interface pointer.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param pvBuf Pointer to frame data.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param cb Frame size.
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsyncstatic DECLCALLBACK(int) devINIPNetworkDown_Input(PPDMINETWORKDOWN pInterface,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync struct pbuf *p, *q;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlow(("%s: pInterface=%p pvBuf=%p cb=%lu\n", __FUNCTION__, pInterface,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* Silently ignore packets being received while lwIP isn't set up. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* We allocate a pbuf chain of pbufs from the pool. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync lwip_pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* Fill the buffers, and clean out unused buffer space. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync memset(((uint8_t *)q->payload) + cb, '\0', q->len - cb);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync lwip_pbuf_header(p, -(ssize_t)sizeof(struct eth_hdr));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync lwip_etharp_arp_input(iface, (struct eth_addr *)iface->hwaddr, p);
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync /* We've setup flags NETIF_FLAG_ETHARP and NETIF_FLAG_ETHERNET
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync * so this should be thread-safe.
a7d402dcc23137e7b9527be6de80400043a5fbf4vboxsync * @interface_method_impl{PDMINETWORKDOWN,pfnXmitPending}
a7d402dcc23137e7b9527be6de80400043a5fbf4vboxsyncstatic DECLCALLBACK(void) devINIPNetworkDown_XmitPending(PPDMINETWORKDOWN pInterface)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Signals the end of lwIP TCPIP initialization.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @param arg opaque argument, here the pointer to the semaphore.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncstatic DECLCALLBACK(void) devINIPTcpipInitDone(void *arg)
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync * Gets the current Media Access Control (MAC) address.
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync * @returns VBox status code.
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync * @param pInterface Pointer to the interface structure containing the called function pointer.
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync * @param pMac Where to store the MAC address.
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync * @thread EMT
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsyncstatic DECLCALLBACK(int) devINIPGetMac(PPDMINETWORKCONFIG pInterface, PRTMAC pMac)
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync PDEVINTNETIP pThis = RT_FROM_MEMBER(pInterface, DEVINTNETIP, INetworkConfig);
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync * Gets the new link state.
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync * @returns The current link state.
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync * @param pInterface Pointer to the interface structure containing the called function pointer.
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync * @thread EMT
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsyncstatic DECLCALLBACK(PDMNETWORKLINKSTATE) devINIPGetLinkState(PPDMINETWORKCONFIG pInterface)
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync PDEVINTNETIP pThis = RT_FROM_MEMBER(pInterface, DEVINTNETIP, INetworkConfig);
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync * Sets the new link state.
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync * @returns VBox status code.
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync * @param pInterface Pointer to the interface structure containing the called function pointer.
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync * @param enmState The new link state
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsyncstatic DECLCALLBACK(int) devINIPSetLinkState(PPDMINETWORKCONFIG pInterface, PDMNETWORKLINKSTATE enmState)
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync PDEVINTNETIP pThis = RT_FROM_MEMBER(pInterface, DEVINTNETIP, INetworkConfig);
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync pThis->pDrv->pfnNotifyLinkChanged(pThis->pDrv, enmState);
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync/* -=-=-=-=- PDMIBASE -=-=-=-=- */
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @interface_method_impl{PDMIBASE,pfnQueryInterface}
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncstatic DECLCALLBACK(void *) devINIPQueryInterface(PPDMIBASE pInterface,
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync const char *pszIID)
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync PDEVINTNETIP pThis = RT_FROM_MEMBER(pInterface, DEVINTNETIP, IBase);
a39ea3668b7019c23a68936259545f9b71bce1aavboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->IBase);
787c7e6ef15f993c455c374f5158e7bb753b1c33vboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMINETWORKDOWN, &pThis->INetworkDown);
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMINETWORKCONFIG, &pThis->INetworkConfig);
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync/* -=-=-=-=- PDMDEVREG -=-=-=-=- */
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync * Destruct a device instance.
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync * Most VM resources are freed by the VM. This callback is provided so that any non-VM
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync * resources can be freed correctly.
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync * @returns VBox status.
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync * @param pDevIns The device instance data.
e74eef731a813e4e06680c587a6759b9974b29c9vboxsyncstatic DECLCALLBACK(int) devINIPDestruct(PPDMDEVINS pDevIns)
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync PDEVINTNETIP pThis = PDMINS_2_DATA(pDevIns, PDEVINTNETIP);
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync LogFlow(("%s: pDevIns=%p\n", __FUNCTION__, pDevIns));
cad8876b46f9e366c4a1007a40c27ca1df078950vboxsync * @interface_method_impl{PDMDEVREG,pfnConstruct}
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncstatic DECLCALLBACK(int) devINIPConstruct(PPDMDEVINS pDevIns, int iInstance,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync PDEVINTNETIP pThis = PDMINS_2_DATA(pDevIns, PDEVINTNETIP);
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync LogFlow(("%s: pDevIns=%p iInstance=%d pCfg=%p\n", __FUNCTION__,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Validate the config.
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync "Netmask\0Gateway\0"))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync rc = PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync N_("Unknown Internal Networking IP configuration option"));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Init the static parts.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* Pointer to device instance */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* IBase */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync pThis->IBase.pfnQueryInterface = devINIPQueryInterface;
787c7e6ef15f993c455c374f5158e7bb753b1c33vboxsync /* INetworkDown */
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync pThis->INetworkDown.pfnWaitReceiveAvail = devINIPNetworkDown_WaitInputAvail;
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync pThis->INetworkDown.pfnReceive = devINIPNetworkDown_Input;
a7d402dcc23137e7b9527be6de80400043a5fbf4vboxsync pThis->INetworkDown.pfnXmitPending = devINIPNetworkDown_XmitPending;
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync /* INetworkConfig */
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync pThis->INetworkConfig.pfnGetLinkState = devINIPGetLinkState;
72730eaca1e865cb4503d6f8f00bc00bc5e1c038vboxsync pThis->INetworkConfig.pfnSetLinkState = devINIPSetLinkState;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Get the configuration settings.
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync rc = CFGMR3QueryBytes(pCfg, "MAC", &pThis->MAC, sizeof(pThis->MAC));
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync rc = CFGMR3QueryString(pCfg, "MAC", &szMAC[0], sizeof(szMAC));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync N_("Configuration error: Failed to get the \"MAC\" value"));
01644b3fb3841a1b087fb2a5b8c2870d9876541bvboxsync rc = devINIPNetworkConfiguration(pDevIns, pThis, pCfg);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Attach driver and query the network connector interface.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync "Network Port");
787c7e6ef15f993c455c374f5158e7bb753b1c33vboxsync pThis->pDrv = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMINETWORKUP);
787c7e6ef15f993c455c374f5158e7bb753b1c33vboxsync AssertMsgFailed(("Failed to obtain the PDMINETWORKUP interface!\n"));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync rc = PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync rc = PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync N_("Configuration error: Invalid \"Netmask\" value"));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync N_("Configuration error: Invalid \"Gateway\" value"));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Initialize lwIP.
25747178cb66800d8386c20b8ffd87f78f24f4e5vboxsync rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, devINIPARPTimer, pThis,
25747178cb66800d8386c20b8ffd87f78f24f4e5vboxsync TMTIMER_FLAGS_NO_CRIT_SECT, "lwIP ARP", &pThis->ARPTimer);
25747178cb66800d8386c20b8ffd87f78f24f4e5vboxsync rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, devINIPTCPFastTimer, pThis,
25747178cb66800d8386c20b8ffd87f78f24f4e5vboxsync TMTIMER_FLAGS_NO_CRIT_SECT, "lwIP fast TCP", &pThis->TCPFastTimer);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync TMTimerSetMillies(pThis->TCPFastTimer, TCP_FAST_INTERVAL);
25747178cb66800d8386c20b8ffd87f78f24f4e5vboxsync rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, devINIPTCPSlowTimer, pThis,
25747178cb66800d8386c20b8ffd87f78f24f4e5vboxsync TMTIMER_FLAGS_NO_CRIT_SECT, "lwIP slow TCP", &pThis->TCPSlowTimer);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync TMTimerSetMillies(pThis->TCPFastTimer, TCP_SLOW_INTERVAL);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync lwip_tcpip_init(devINIPTcpipInitDone, &pThis->LWIPTcpInitSem);
1e61c2f4dd6e398ffa2028c55f1e0170b53fa7a3vboxsync errRc = lwip_sys_sem_new(&pThis->LWIPTcpInitSem, 0);
1e61c2f4dd6e398ffa2028c55f1e0170b53fa7a3vboxsync /* VERR_INTERNAL_ERROR perhaps should be replaced with right error code */
1e61c2f4dd6e398ffa2028c55f1e0170b53fa7a3vboxsync AssertReturn(errRc == ERR_OK, VERR_INTERNAL_ERROR);
1e61c2f4dd6e398ffa2028c55f1e0170b53fa7a3vboxsync lwip_tcpip_init(devINIPTcpipInitDone, &pThis->LWIPTcpInitSem);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Set up global pointer to interface data.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync ret = netif_add(&pThis->IntNetIF, &ipaddr, &netmask, &gw, NULL,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* link hack */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Query whether lwIP is initialized or not. Since there is only a single
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * instance of this device ever for a VM, it can be a global function.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * @returns True if lwIP is initialized.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Internal network IP stack device registration record.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* u32Version */
2c8ee291fb75c4a6f05df160f5d67f4e9ef1cabcvboxsync /* szName */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync "IntNetIP",
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* pszDescription */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync "Internal Network IP stack device",
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* fFlags */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* fClass. As this is used by the storage devices, it must come earlier. */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* cMaxInstances */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* cbInstance */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* pfnConstruct */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* pfnDestruct */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* pfnRelocate */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* pfnIOCtl */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* pfnPowerOn */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* pfnReset */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* pfnSuspend */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* pfnResume */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* pfnAttach */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* pfnDetach */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* pfnQueryInterface */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* pfnInitComplete */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* pfnPowerOff */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* pfnSoftReset */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* u32VersionEnd */