VirtualBox

Changeset 46573 in vbox for trunk


Ignore:
Timestamp:
Jun 15, 2013 12:19:21 PM (12 years ago)
Author:
vboxsync
Message:

LWIP/LWIP-new/NAT: adding/removing interfaces should be done on tcpip thread.

File:
1 edited

Legend:

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

    r46427 r46573  
    115115    /** Flag whether the link is up. */
    116116    bool                    fLnkUp;
     117#ifndef VBOX_WITH_NEW_LWIP
     118    /**
     119     * This hack-flag for spliting initialization logic in devINIPTcpipInitDone,
     120     * this is the only place when during initialization we can be called from TCPIP
     121     * thread.
     122     * This callback used for Initialization and Finalization with old lwip.
     123     */
     124    bool fTermination;
     125#endif
     126    /**
     127     * In callback we're getting status of interface adding operation (TCPIP thread),
     128     * but we need inform constructing routine whether it was success or not(EMT thread).
     129     */
     130    bool rcInitialization;
    117131} DEVINTNETIP, *PDEVINTNETIP;
    118132
     
    474488}
    475489
     490
     491/**
     492 * Signals the end of lwIP TCPIP initialization.
     493 *
     494 * @note: TCPIP thread, corresponding EMT waiting on semaphore.
     495 * @param   arg     opaque argument, here the pointer to the PDEVINTNETIP.
     496 */
     497static DECLCALLBACK(void) devINIPTcpipInitDone(void *arg)
     498{
     499    PDEVINTNETIP pThis = (PDEVINTNETIP)arg;
     500    AssertPtrReturnVoid(arg);
     501
     502    pThis->rcInitialization = VINF_SUCCESS;
    476503#ifndef VBOX_WITH_NEW_LWIP
    477 /**
    478  * Signals the end of lwIP TCPIP initialization.
    479  *
    480  * @param   arg     opaque argument, here the pointer to the semaphore.
    481  */
    482 static DECLCALLBACK(void) devINIPTcpipInitDone(void *arg)
    483 {
    484     sys_sem_t *sem = (sys_sem_t *)arg;
    485 
    486     lwip_sys_sem_signal(*sem);
     504    /* see PDEVINTNETIP::fTermination */
     505    if (!pThis->fTermination)
     506    {
     507#endif
     508        struct netif *ret;
     509        struct ip_addr ipaddr, netmask, gw;
     510        struct in_addr ip;
     511
     512        if (!inet_aton(pThis->pszIP, &ip))
     513        {
     514            pThis->rcInitialization = VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
     515            PDMDEV_SET_ERROR(pThis->pDevIns,
     516                             pThis->rcInitialization,
     517                             N_("Configuration error: Invalid \"IP\" value"));
     518            goto done;
     519        }
     520        memcpy(&ipaddr, &ip, sizeof(ipaddr));
     521       
     522        if (!inet_aton(pThis->pszNetmask, &ip))
     523        {
     524            pThis->rcInitialization = VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
     525            PDMDEV_SET_ERROR(pThis->pDevIns,
     526                             pThis->rcInitialization,
     527                             N_("Configuration error: Invalid \"Netmask\" value"));
     528            goto done;
     529        }
     530        memcpy(&netmask, &ip, sizeof(netmask));
     531
     532        if (pThis->pszGateway)
     533        {
     534            if (!inet_aton(pThis->pszGateway, &ip))
     535            {
     536                pThis->rcInitialization = VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
     537                PDMDEV_SET_ERROR(pThis->pDevIns,
     538                                 pThis->rcInitialization,
     539                                 N_("Configuration error: Invalid \"Gateway\" value"));
     540                goto done;
     541            }
     542
     543        }
     544        else
     545        {
     546            inet_aton(pThis->pszIP, &ip);
     547        }
     548        memcpy(&gw, &ip, sizeof(gw));
     549
     550        pThis->IntNetIF.name[0] = 'I';
     551        pThis->IntNetIF.name[1] = 'N';
     552   
     553        ret = netif_add(&pThis->IntNetIF, &ipaddr, &netmask, &gw, NULL,
     554                        devINIPInterface, lwip_tcpip_input);
     555
     556        if (!ret)
     557        {
     558           
     559            pThis->rcInitialization = VERR_NET_NO_NETWORK;
     560            PDMDEV_SET_ERROR(pThis->pDevIns,
     561                             pThis->rcInitialization,
     562                             N_("netif_add failed"));
     563            goto done;
     564        }
     565
     566        lwip_netif_set_default(&pThis->IntNetIF);
     567        lwip_netif_set_up(&pThis->IntNetIF);
     568       
     569#ifndef VBOX_WITH_NEW_LWIP
     570    }
     571    done:
     572    lwip_sys_sem_signal(pThis->LWIPTcpInitSem);
     573#else
     574    done:
     575    return;
     576#endif
     577}
     578
     579#ifdef VBOX_WITH_NEW_LWIP
     580/**
     581 * This callback is for finitializing our activity on TCPIP thread.
     582 * XXX: We do it only for new LWIP, old LWIP will stay broken for now.
     583 */
     584static DECLCALLBACK(void) devINIPTcpipFiniDone(void *arg)
     585{
     586    PDEVINTNETIP pThis = (PDEVINTNETIP)arg;
     587    AssertPtrReturnVoid(arg);
     588
     589    netif_set_link_down(&pThis->IntNetIF);
     590    netif_set_down(&pThis->IntNetIF);
     591    netif_remove(&pThis->IntNetIF);
    487592}
    488593#endif
     
    585690    if (g_pDevINIPData != NULL)
    586691    {
     692#ifndef VBOX_WITH_NEW_LWIP
    587693        netif_set_down(&pThis->IntNetIF);
    588694        netif_remove(&pThis->IntNetIF);
    589 #ifndef VBOX_WITH_NEW_LWIP
     695        pThis->fTermination = true;
    590696        tcpip_terminate();
    591697        lwip_sys_sem_wait(pThis->LWIPTcpInitSem);
    592698        lwip_sys_sem_free(pThis->LWIPTcpInitSem);
    593699#else
    594         vboxLwipCoreFinalize();
     700        vboxLwipCoreFinalize(devINIPTcpipFiniDone, pThis);
    595701#endif
    596702    }
     
    704810    AssertMsgReturn(pThis->pDrv, ("Failed to obtain the PDMINETWORKUP interface!\n"), VERR_PDM_MISSING_INTERFACE_BELOW);
    705811
    706     struct ip_addr ipaddr, netmask, gw;
    707     struct in_addr ip;
    708 
    709     if (!inet_aton(pThis->pszIP, &ip))
    710         return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
    711                                 N_("Configuration error: Invalid \"IP\" value"));
    712     memcpy(&ipaddr, &ip, sizeof(ipaddr));
    713     if (!inet_aton(pThis->pszNetmask, &ip))
    714         return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
    715                                 N_("Configuration error: Invalid \"Netmask\" value"));
    716     memcpy(&netmask, &ip, sizeof(netmask));
    717     if (pThis->pszGateway)
    718     {
    719         if (!inet_aton(pThis->pszGateway, &ip))
    720             return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
    721                                     N_("Configuration error: Invalid \"Gateway\" value"));
    722         memcpy(&gw, &ip, sizeof(gw));
    723     }
    724     else
    725     {
    726         inet_aton(pThis->pszIP, &ip);
    727         memcpy(&gw, &ip, sizeof(gw));
    728     }
     812
     813    /*
     814     * Set up global pointer to interface data.
     815     */
     816    g_pDevINIPData = pThis;
     817
     818
     819    /* link hack */
     820    pThis->pLinkHack = g_pDevINILinkHack;
    729821
    730822    /*
     
    753845
    754846    pThis->LWIPTcpInitSem = lwip_sys_sem_new(0);
    755     {
    756         lwip_tcpip_init(devINIPTcpipInitDone, &pThis->LWIPTcpInitSem);
    757         lwip_sys_sem_wait(pThis->LWIPTcpInitSem);
    758     }
     847
     848    lwip_tcpip_init(devINIPTcpipInitDone, pThis);
     849    lwip_sys_sem_wait(pThis->LWIPTcpInitSem);
     850
    759851#else /* VBOX_WITH_NEW_LWIP */
    760     vboxLwipCoreInitialize();
    761 #endif
    762 
    763     /*
    764      * Set up global pointer to interface data.
    765      */
    766     g_pDevINIPData = pThis;
    767 
    768     struct netif *ret;
    769     pThis->IntNetIF.name[0] = 'I';
    770     pThis->IntNetIF.name[1] = 'N';
    771     ret = netif_add(&pThis->IntNetIF, &ipaddr, &netmask, &gw, NULL,
    772                     devINIPInterface, lwip_tcpip_input);
    773     if (!ret)
    774         return PDMDEV_SET_ERROR(pDevIns, VERR_NET_NO_NETWORK, N_("netif_add failed"));
    775 
    776     lwip_netif_set_default(&pThis->IntNetIF);
    777     lwip_netif_set_up(&pThis->IntNetIF);
    778 
    779     /* link hack */
    780     pThis->pLinkHack = g_pDevINILinkHack;
     852    vboxLwipCoreInitialize(devINIPTcpipInitDone, pThis);
     853#endif
     854
     855    /* this rc could be updated in devINIPTcpInitDone thread */
     856    AssertRCReturn(pThis->rcInitialization, pThis->rcInitialization);
     857
    781858
    782859    LogFlow(("%s: return %Rrc\n", __FUNCTION__, 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