VirtualBox

Changeset 44670 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Feb 13, 2013 3:16:23 PM (12 years ago)
Author:
vboxsync
Message:

DevINIP.cpp: Removed all use of the harmful statement (at least according to Dijkstra). Some minor adjustments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/DevINIP.cpp

    r44528 r44670  
    55
    66/*
    7  * Copyright (C) 2007-2012 Oracle Corporation
     7 * Copyright (C) 2007-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    8686    PPDMIBASE               pDrvBase;
    8787    /** The connector of the network driver below us. */
    88     PPDMINETWORKUP   pDrv;
     88    PPDMINETWORKUP          pDrv;
    8989    /** Pointer to the device instance. */
    9090    PPDMDEVINSR3            pDevIns;
     
    145145static DECLCALLBACK(void) devINIPTCPFastTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer);
    146146static DECLCALLBACK(void) devINIPTCPSlowTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer);
    147 static DECLCALLBACK(err_t) devINIPOutput(struct netif *netif, struct pbuf *p,
    148                                          struct ip_addr *ipaddr);
    149 static DECLCALLBACK(err_t) devINIPOutputRaw(struct netif *netif,
    150                                             struct pbuf *p);
     147static DECLCALLBACK(err_t) devINIPOutput(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr);
     148static DECLCALLBACK(err_t) devINIPOutputRaw(struct netif *netif, struct pbuf *p);
    151149static DECLCALLBACK(err_t) devINIPInterface(struct netif *netif);
     150
    152151
    153152/**
     
    205204 * @param   ipaddr  Destination IP address.
    206205 */
    207 static DECLCALLBACK(err_t) devINIPOutput(struct netif *netif, struct pbuf *p,
    208                                          struct ip_addr *ipaddr)
     206static DECLCALLBACK(err_t) devINIPOutput(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
    209207{
    210208    err_t lrc;
     
    227225 * @param   p       Frame data.
    228226 */
    229 static DECLCALLBACK(err_t) devINIPOutputRaw(struct netif *netif,
    230                                             struct pbuf *p)
     227static DECLCALLBACK(err_t) devINIPOutputRaw(struct netif *netif, struct pbuf *p)
    231228{
    232229    int rc = VINF_SUCCESS;
     
    310307    netif->flags = NETIF_FLAG_BROADCAST;
    311308#ifdef VBOX_WITH_NEW_LWIP
    312     /* @todo: why explicit ARP routing required for 1.2.0 case? */
     309    /** @todo why explicit ARP routing required for 1.2.0 case? */
    313310    netif->flags |= NETIF_FLAG_ETHARP;
    314311    netif->flags |= NETIF_FLAG_ETHERNET;
    315     /*
    316      * @note: we always assign link-local IPv6 address
    317      */
     312    /* Note! We always assign link-local IPv6 address */
    318313    netif_create_ip6_linklocal_address(netif, 0);
    319314    netif_ip6_addr_set_state(netif, 0, IP6_ADDR_VALID);
     
    390385 * @param   cb          Frame size.
    391386 */
    392 static DECLCALLBACK(int) devINIPNetworkDown_Input(PPDMINETWORKDOWN pInterface,
    393                                                   const void *pvBuf, size_t cb)
     387static DECLCALLBACK(int) devINIPNetworkDown_Input(PPDMINETWORKDOWN pInterface, const void *pvBuf, size_t cb)
    394388{
    395389    const uint8_t *pbBuf = (const uint8_t *)pvBuf;
     
    399393    int rc = VINF_SUCCESS;
    400394
    401     LogFlow(("%s: pInterface=%p pvBuf=%p cb=%lu\n", __FUNCTION__, pInterface,
    402              pvBuf, cb));
     395    LogFlow(("%s: pInterface=%p pvBuf=%p cb=%lu\n", __FUNCTION__, pInterface, pvBuf, cb));
    403396    Assert(g_pDevINIPData);
    404397    Assert(g_pDevINIPData->pDrv);
     
    406399    /* Silently ignore packets being received while lwIP isn't set up. */
    407400    if (!g_pDevINIPData)
    408         goto out;
     401    {
     402        LogFlow(("%s: return %Rrc (no global)\n", __FUNCTION__, rc));
     403        return VINF_SUCCESS;
     404    }
    409405
    410406#if ETH_PAD_SIZE
     
    449445        }
    450446#else
    451         /* We've setup flags NETIF_FLAG_ETHARP and NETIF_FLAG_ETHERNET
    452          * so this should be thread-safe.
    453          */
    454         tcpip_input(p,iface);
     447        /* We've setup flags NETIF_FLAG_ETHARP and NETIF_FLAG_ETHERNET
     448          so this should be thread-safe. */
     449        tcpip_input(p,iface);
    455450#endif
    456451    }
     
    594589    }
    595590
    596     if (pThis->pszIP)
    597         MMR3HeapFree(pThis->pszIP);
    598     if (pThis->pszNetmask)
    599         MMR3HeapFree(pThis->pszNetmask);
    600     if (pThis->pszGateway)
    601         MMR3HeapFree(pThis->pszGateway);
     591    MMR3HeapFree(pThis->pszIP);
     592    pThis->pszIP = NULL;
     593    MMR3HeapFree(pThis->pszNetmask);
     594    pThis->pszNetmask = NULL;
     595    MMR3HeapFree(pThis->pszGateway);
     596    pThis->pszGateway = NULL;
    602597
    603598    LogFlow(("%s: success\n", __FUNCTION__));
     
    609604 * @interface_method_impl{PDMDEVREG,pfnConstruct}
    610605 */
    611 static DECLCALLBACK(int) devINIPConstruct(PPDMDEVINS pDevIns, int iInstance,
    612                                           PCFGMNODE pCfg)
     606static DECLCALLBACK(int) devINIPConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
    613607{
    614608    PDEVINTNETIP pThis = PDMINS_2_DATA(pDevIns, PDEVINTNETIP);
     
    631625#endif
    632626                                    "Netmask\0Gateway\0"))
    633     {
    634         rc = PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
    635                               N_("Unknown Internal Networking IP configuration option"));
    636         goto out;
    637     }
     627        return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
     628                                N_("Unknown Internal Networking IP configuration option"));
    638629
    639630    /*
     
    672663                if (   !*macStr || !*(macStr + 1)
    673664                    || *macStr == ':' || *(macStr + 1) == ':')
    674                 {
    675                     rc = PDMDEV_SET_ERROR(pDevIns,
    676                                           VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
    677                                           N_("Configuration error: Invalid \"MAC\" value"));
    678                     goto out;
    679                 }
     665                    return PDMDEV_SET_ERROR(pDevIns,
     666                                            VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
     667                                            N_("Configuration error: Invalid \"MAC\" value"));
    680668                char c1 = *macStr++ - '0';
    681669                if (c1 > 9)
     
    691679    }
    692680    if (RT_FAILURE(rc))
    693     {
    694         PDMDEV_SET_ERROR(pDevIns, rc,
    695                          N_("Configuration error: Failed to get the \"MAC\" value"));
    696         goto out;
    697     }
     681        return PDMDEV_SET_ERROR(pDevIns, rc,
     682                                N_("Configuration error: Failed to get the \"MAC\" value"));
    698683    rc = devINIPNetworkConfiguration(pDevIns, pThis, pCfg);
    699     if (RT_FAILURE(rc))
    700         goto out;
     684    AssertLogRelRCReturn(rc, rc);
    701685
    702686    /*
    703687     * Attach driver and query the network connector interface.
    704688     */
    705     rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase,
    706                                "Network Port");
     689    rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase, "Network Port");
    707690    if (RT_FAILURE(rc))
    708691    {
    709692        pThis->pDrvBase = NULL;
    710693        pThis->pDrv = NULL;
    711         goto out;
    712     }
    713     else
    714     {
    715         pThis->pDrv = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMINETWORKUP);
    716         if (!pThis->pDrv)
    717         {
    718             AssertMsgFailed(("Failed to obtain the PDMINETWORKUP interface!\n"));
    719             rc = VERR_PDM_MISSING_INTERFACE_BELOW;
    720             goto out;
    721         }
    722     }
     694        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Error attaching device below us"));
     695    }
     696    pThis->pDrv = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMINETWORKUP);
     697    AssertMsgReturn(pThis->pDrv, ("Failed to obtain the PDMINETWORKUP interface!\n"), VERR_PDM_MISSING_INTERFACE_BELOW);
    723698
    724699    struct ip_addr ipaddr, netmask, gw;
     
    726701
    727702    if (!inet_aton(pThis->pszIP, &ip))
    728     {
    729         rc = PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
    730                               N_("Configuration error: Invalid \"IP\" value"));
    731         goto out;
    732     }
     703        return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
     704                                N_("Configuration error: Invalid \"IP\" value"));
    733705    memcpy(&ipaddr, &ip, sizeof(ipaddr));
    734706    if (!inet_aton(pThis->pszNetmask, &ip))
    735     {
    736         rc = PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
    737                               N_("Configuration error: Invalid \"Netmask\" value"));
    738         goto out;
    739     }
     707        return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
     708                                N_("Configuration error: Invalid \"Netmask\" value"));
    740709    memcpy(&netmask, &ip, sizeof(netmask));
    741710    if (pThis->pszGateway)
    742711    {
    743712        if (!inet_aton(pThis->pszGateway, &ip))
    744         {
    745             rc = PDMDEV_SET_ERROR(pDevIns,
    746                                   VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
    747                                   N_("Configuration error: Invalid \"Gateway\" value"));
    748             goto out;
    749         }
     713            return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
     714                                    N_("Configuration error: Invalid \"Gateway\" value"));
    750715        memcpy(&gw, &ip, sizeof(gw));
    751716    }
     
    755720        memcpy(&gw, &ip, sizeof(gw));
    756721    }
     722
    757723    /*
    758724     * Initialize lwIP.
     
    768734    rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, devINIPARPTimer, pThis,
    769735                                TMTIMER_FLAGS_NO_CRIT_SECT, "lwIP ARP", &pThis->ARPTimer);
    770     if (RT_FAILURE(rc))
    771         goto out;
     736    AssertRCReturn(rc, rc);
    772737    rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, devINIPTCPFastTimer, pThis,
    773738                                TMTIMER_FLAGS_NO_CRIT_SECT, "lwIP fast TCP", &pThis->TCPFastTimer);
    774     if (RT_FAILURE(rc))
    775         goto out;
     739    AssertRCReturn(rc, rc);
    776740    TMTimerSetMillies(pThis->TCPFastTimer, TCP_FAST_INTERVAL);
    777741    rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, devINIPTCPSlowTimer, pThis,
    778742                                TMTIMER_FLAGS_NO_CRIT_SECT, "lwIP slow TCP", &pThis->TCPSlowTimer);
    779     if (RT_FAILURE(rc))
    780         goto out;
     743    AssertRCReturn(rc, rc);
    781744    TMTimerSetMillies(pThis->TCPFastTimer, TCP_SLOW_INTERVAL);
    782745#ifndef VBOX_WITH_NEW_LWIP
     
    807770                    devINIPInterface, lwip_tcpip_input);
    808771    if (!ret)
    809     {
    810         rc = VERR_NET_NO_NETWORK;
    811         goto out;
    812     }
     772        return PDMDEV_SET_ERROR(pDevIns, VERR_NET_NO_NETWORK, N_("netif_add failed"));
    813773
    814774    lwip_netif_set_default(&pThis->IntNetIF);
     
    818778    pThis->pLinkHack = g_pDevINILinkHack;
    819779
    820 out:
    821780    LogFlow(("%s: return %Rrc\n", __FUNCTION__, rc));
    822781    return rc;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette