VirtualBox

Changeset 43924 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Nov 21, 2012 9:05:59 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
82236
Message:

DevINIP: IPv6 and new LWIP introduction.

File:
1 edited

Legend:

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

    r43636 r43924  
    3434#include "lwip/pbuf.h"
    3535#include "lwip/netif.h"
    36 #include "ipv4/lwip/ip.h"
     36#ifndef VBOX_WITH_NEW_LWIP
     37# include "ipv4/lwip/ip.h"
     38#else
     39# include "lwip/api.h"
     40# include "lwip/tcp_impl.h"
     41# include "ipv6/lwip/ethip6.h"
     42#endif
    3743#include "lwip/udp.h"
    3844#include "lwip/tcp.h"
    39 #ifdef VBOX_WITH_NEW_LWIP
    40 # include "lwip/tcp_impl.h"
    41 #endif
    4245#include "lwip/tcpip.h"
    4346#include "lwip/sockets.h"
     
    109112    /** Flag whether the link is up. */
    110113    bool                    fLnkUp;
     114    /** Flag whether the configuration is IPv6 */
     115    bool                    fIpv6;
     116    /** Static IPv6 address of the interface. */
     117    char                   *pszIP6;
    111118} DEVINTNETIP, *PDEVINTNETIP;
    112119
     
    310317    netif->flags |= NETIF_FLAG_ETHARP;
    311318    netif->flags |= NETIF_FLAG_ETHERNET;
    312 #endif
     319    if (g_pDevINIPData->fIpv6)
     320    {
     321        /* @todo: Don't bother user with entering IPv6 address explicitly,
     322         * instead what is required here that IPv6 local-address generation ?
     323         */
     324        if (!inet6_aton(g_pDevINIPData->pszIP6, &netif->ip6_addr[0]))
     325        {
     326            PDMDEV_SET_ERROR(g_pDevINIPData->pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
     327                             N_("Configuration error: Invalid \"IPv6\" value"));
     328            return ERR_IF;
     329        }
     330        netif_ip6_addr_set_state(netif, 0, IP6_ADDR_VALID);
     331        netif->output_ip6 = ethip6_output;
     332        netif->ip6_autoconfig_enabled=1;
     333    }
     334    else
     335        netif->output = lwip_etharp_output;
     336
     337#else
    313338    netif->output = devINIPOutput;
     339#endif
    314340    netif->linkoutput = devINIPOutputRaw;
    315341
     
    318344    LogFlow(("%s: success\n", __FUNCTION__));
    319345    return ERR_OK;
     346}
     347
     348/**
     349 * Parses CFGM parameters related to network connection
     350 */
     351static DECLCALLBACK(int) devINIPNetworkConfiguration(PPDMDEVINS pDevIns, PDEVINTNETIP pThis, PCFGMNODE pCfg)
     352{
     353    int rc = VINF_SUCCESS;
     354    rc = CFGMR3QueryStringAlloc(pCfg, "IP", &pThis->pszIP);
     355    if (RT_FAILURE(rc))
     356    {
     357        PDMDEV_SET_ERROR(pDevIns, rc,
     358                         N_("Configuration error: Failed to get the \"IP\" value"));
     359        return rc;
     360    }
     361#ifdef VBOX_WITH_NEW_LWIP
     362    rc = CFGMR3QueryStringAlloc(pCfg, "IPv6", &pThis->pszIP6);
     363    if (RT_SUCCESS(rc))
     364        pThis->fIpv6 = true;
     365    else if (rc != VERR_CFGM_VALUE_NOT_FOUND)
     366    {
     367        PDMDEV_SET_ERROR(pDevIns, rc,
     368                         N_("Configuration error: Failed to get the \"IPv6\" value"));
     369        AssertReturn(rc, rc);
     370    }
     371#endif
     372    rc = CFGMR3QueryStringAlloc(pCfg, "Netmask", &pThis->pszNetmask);
     373    if (RT_FAILURE(rc))
     374    {
     375        PDMDEV_SET_ERROR(pDevIns, rc,
     376                         N_("Configuration error: Failed to get the \"Netmask\" value"));
     377        return rc;
     378    }
     379    rc = CFGMR3QueryStringAlloc(pCfg, "Gateway", &pThis->pszGateway);
     380    if (   RT_FAILURE(rc)
     381        && rc != VERR_CFGM_VALUE_NOT_FOUND)
     382    {
     383        PDMDEV_SET_ERROR(pDevIns, rc,
     384                         N_("Configuration error: Failed to get the \"Gateway\" value"));
     385        return rc;
     386    }
     387    return VINF_SUCCESS;
    320388}
    321389
     
    385453        struct netif *iface = &g_pDevINIPData->IntNetIF;
    386454        err_t lrc;
     455#ifndef VBOX_WITH_NEW_LWIP
    387456        switch (htons(ethhdr->type))
    388457        {
    389458            case ETHTYPE_IP:    /* IP packet */
    390 #ifndef VBOX_WITH_NEW_LWIP
    391459                lwip_pbuf_header(p, -(ssize_t)sizeof(struct eth_hdr));
    392 #endif
    393460                lrc = iface->input(p, iface);
    394461                if (lrc)
     
    396463                break;
    397464            case ETHTYPE_ARP:   /* ARP packet */
    398 #ifndef VBOX_WITH_NEW_LWIP
    399465                lwip_etharp_arp_input(iface, (struct eth_addr *)iface->hwaddr, p);
    400 #else
    401                 ethernet_input(p, iface);
    402 #endif
    403466                break;
    404467            default:
    405468                lwip_pbuf_free(p);
    406469        }
     470#else
     471        /* We've setup flags NETIF_FLAG_ETHARP and NETIF_FLAG_ETHERNET
     472         * so this should be thread-safe.
     473         */
     474        tcpip_input(p,iface);
     475#endif
    407476    }
    408477
     
    535604        netif_set_down(&pThis->IntNetIF);
    536605        netif_remove(&pThis->IntNetIF);
     606        tcpip_terminate();
    537607#ifndef VBOX_WITH_NEW_LWIP
    538         tcpip_terminate();
    539608        lwip_sys_sem_wait(pThis->LWIPTcpInitSem);
    540609        lwip_sys_sem_free(pThis->LWIPTcpInitSem);
    541610#else
    542         /* no termination on new lwip ??? Hmmm... */
    543611        lwip_sys_sem_wait(&pThis->LWIPTcpInitSem, 0);
    544612        lwip_sys_sem_free(&pThis->LWIPTcpInitSem);
     
    578646     * Validate the config.
    579647     */
    580     if (!CFGMR3AreValuesValid(pCfg, "MAC\0IP\0Netmask\0Gateway\0"))
     648    if (!CFGMR3AreValuesValid(pCfg, "MAC\0IP\0"
     649#ifdef VBOX_WITH_NEW_LWIP
     650                                    "IPv6\0"
     651#endif
     652                                    "Netmask\0Gateway\0"))
    581653    {
    582654        rc = PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
     
    644716        goto out;
    645717    }
    646     rc = CFGMR3QueryStringAlloc(pCfg, "IP", &pThis->pszIP);
     718    rc = devINIPNetworkConfiguration(pDevIns, pThis, pCfg);
    647719    if (RT_FAILURE(rc))
    648     {
    649         PDMDEV_SET_ERROR(pDevIns, rc,
    650                          N_("Configuration error: Failed to get the \"IP\" value"));
    651         goto out;
    652     }
    653     rc = CFGMR3QueryStringAlloc(pCfg, "Netmask", &pThis->pszNetmask);
    654     if (RT_FAILURE(rc))
    655     {
    656         PDMDEV_SET_ERROR(pDevIns, rc,
    657                          N_("Configuration error: Failed to get the \"Netmask\" value"));
    658         goto out;
    659     }
    660     rc = CFGMR3QueryStringAlloc(pCfg, "Gateway", &pThis->pszGateway);
    661     if (rc == VERR_CFGM_VALUE_NOT_FOUND)
    662         rc = VINF_SUCCESS;
    663     if (RT_FAILURE(rc))
    664     {
    665         PDMDEV_SET_ERROR(pDevIns, rc,
    666                          N_("Configuration error: Failed to get the \"Gateway\" value"));
    667         goto out;
    668     }
     720        goto out;
    669721
    670722    /*
     
    723775        memcpy(&gw, &ip, sizeof(gw));
    724776    }
    725 
    726777    /*
    727778     * Initialize lwIP.
Note: See TracChangeset for help on using the changeset viewer.

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