VirtualBox

Changeset 48289 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Sep 5, 2013 3:23:26 AM (11 years ago)
Author:
vboxsync
Message:

Move code to set up IPv6 addresses to VBoxNetLwipNAT::netifInit.
While there, clean up netifInit a bit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp

    r48288 r48289  
    363363    AssertPtrReturnVoid(pNetif);
    364364
    365     /* IPv6 link-local address in slot 0 */
    366     netif_create_ip6_linklocal_address(pNetif, /* :from_mac_48bit */ 1);
    367 
    368     /*
    369      * RFC 4193 Locally Assigned Global ID (ULA) in slot 1
    370      * [fd17:625c:f037:XXXX::1] where XXXX, 16 bit Subnet ID, are two
    371      * bytes from the middle of the IPv4 address, e.g. :dead: for
    372      * 10.222.173.1
    373      */
    374     {
    375         uint8_t nethi = g_pLwipNat->m_Ipv4Address.au8[1];
    376         uint8_t netlo = g_pLwipNat->m_Ipv4Address.au8[2];
    377 
    378         ip6_addr_t *paddr = netif_ip6_addr(pNetif, 1);
    379         IP6_ADDR(paddr, 0,   0xFD, 0x17,   0x62, 0x5C);
    380         IP6_ADDR(paddr, 1,   0xF0, 0x37,  nethi, netlo);
    381         IP6_ADDR(paddr, 2,   0x00, 0x00,   0x00, 0x00);
    382         IP6_ADDR(paddr, 3,   0x00, 0x00,   0x00, 0x01);
    383         netif_ip6_addr_set_state(pNetif, 1, IP6_ADDR_PREFERRED);
    384     }
    385 
    386 #if LWIP_IPV6_SEND_ROUTER_SOLICIT
    387     pNetif->rs_count = 0;
    388 #endif
    389 
    390365    netif_set_up(pNetif);
    391366    netif_set_link_up(pNetif);
     
    443418
    444419/*
    445  * This function finalize the interface initialization
    446  * (tcpip thread?)
     420 * Callback for netif_add() to initialize the interface.
    447421 */
    448422err_t VBoxNetLwipNAT::netifInit(netif *pNetif)
    449423{
     424    err_t rcLwip = ERR_OK;
     425
    450426    AssertPtrReturn(pNetif, ERR_ARG);
    451    
     427
     428    VBoxNetLwipNAT *pNat = static_cast<VBoxNetLwipNAT *>(pNetif->state);
     429    AssertPtrReturn(pNat, ERR_ARG);
     430
    452431    LogFlowFunc(("ENTER: pNetif[%c%c%d]\n", pNetif->name[0], pNetif->name[1], pNetif->num));
    453432    /* validity */
    454433    AssertReturn(   pNetif->name[0] == 'N'
    455434                 && pNetif->name[1] == 'T', ERR_ARG);
    456    
     435
    457436
    458437    pNetif->hwaddr_len = sizeof(RTMAC);
    459     memcpy(pNetif->hwaddr, &g_pLwipNat->m_MacAddress, sizeof(RTMAC));
    460     g_pLwipNat->m_u16Mtu = 1500; // XXX: FIXME
    461     pNetif->mtu = g_pLwipNat->m_u16Mtu;
     438    memcpy(pNetif->hwaddr, &pNat->m_MacAddress, sizeof(RTMAC));
     439
     440    pNat->m_u16Mtu = 1500; // XXX: FIXME
     441    pNetif->mtu = pNat->m_u16Mtu;
     442
    462443    pNetif->flags = NETIF_FLAG_BROADCAST
    463444      | NETIF_FLAG_ETHARP                /* Don't bother driver with ARP and let Lwip resolve ARP handling */
    464445      | NETIF_FLAG_ETHERNET;             /* Lwip works with ethernet too */
    465446
     447    pNetif->linkoutput = netifLinkoutput; /* ether-level-pipe */
     448    pNetif->output = lwip_etharp_output; /* ip-pipe */
     449    pNetif->output_ip6 = ethip6_output;
     450
     451    /* IPv6 link-local address in slot 0 */
    466452    netif_create_ip6_linklocal_address(pNetif, /* :from_mac_48bit */ 1);
    467     netif_ip6_addr_set_state(pNetif, 0, IP6_ADDR_VALID);
    468     pNetif->output_ip6 = ethip6_output;
    469     LogFunc(("netif[%c%c%d] ipv6 addr:%RTnaipv6\n",
    470              pNetif->name[0],
    471              pNetif->name[1],
    472              pNetif->num,
    473              &pNetif->ip6_addr[0].addr[0]));
    474 
    475     pNetif->output = lwip_etharp_output; /* ip-pipe */
    476     pNetif->linkoutput = netifLinkoutput; /* ether-level-pipe */
    477 
    478     err_t rcLwip = ERR_OK;
    479  
     453    netif_ip6_addr_set_state(pNetif, 0, IP6_ADDR_PREFERRED); // skip DAD
     454
     455    /*
     456     * RFC 4193 Locally Assigned Global ID (ULA) in slot 1
     457     * [fd17:625c:f037:XXXX::1] where XXXX, 16 bit Subnet ID, are two
     458     * bytes from the middle of the IPv4 address, e.g. :dead: for
     459     * 10.222.173.1
     460     */
     461    u8_t nethi = ip4_addr2(&pNetif->ip_addr);
     462    u8_t netlo = ip4_addr3(&pNetif->ip_addr);
     463
     464    ip6_addr_t *paddr = netif_ip6_addr(pNetif, 1);
     465    IP6_ADDR(paddr, 0,   0xFD, 0x17,   0x62, 0x5C);
     466    IP6_ADDR(paddr, 1,   0xF0, 0x37,  nethi, netlo);
     467    IP6_ADDR(paddr, 2,   0x00, 0x00,   0x00, 0x00);
     468    IP6_ADDR(paddr, 3,   0x00, 0x00,   0x00, 0x01);
     469    netif_ip6_addr_set_state(pNetif, 1, IP6_ADDR_PREFERRED);
     470
     471#if LWIP_IPV6_SEND_ROUTER_SOLICIT
     472    pNetif->rs_count = 0;
     473#endif
    480474
    481475    LogFlowFunc(("LEAVE: %d\n", rcLwip));
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