VirtualBox

Changeset 87707 in vbox for trunk


Ignore:
Timestamp:
Feb 11, 2021 12:04:31 AM (4 years ago)
Author:
vboxsync
Message:

NAT/Net: Move the code to init the loopback map into a method of its
own (to be rewritten in the follow up commits). bugref:9929.

File:
1 edited

Legend:

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

    r87688 r87707  
    178178    int logInit();
    179179    int ipv4Init();
     180    int ipv4LoopbackMapInit();
    180181    int ipv6Init();
    181182    int eventsInit();
     
    377378        fetchNatPortForwardRules(m_vecPortForwardRule6, /* :fIsIPv6 */ true);
    378379
    379     AddressToOffsetMapping tmp;
    380     rc = localMappings(m_net, tmp);
    381     if (RT_SUCCESS(rc) && !tmp.empty())
    382     {
    383         unsigned long i = 0;
    384         for (AddressToOffsetMapping::iterator it = tmp.begin();
    385              it != tmp.end() && i < RT_ELEMENTS(m_lo2off);
    386              ++it, ++i)
    387         {
    388             ip4_addr_set_u32(&m_lo2off[i].loaddr, it->first.u);
    389             m_lo2off[i].off = it->second;
    390         }
    391 
    392         m_loOptDescriptor.lomap = m_lo2off;
    393         m_loOptDescriptor.num_lomap = i;
    394         m_ProxyOptions.lomap_desc = &m_loOptDescriptor;
    395     }
    396 
    397380
    398381    if (m_strHome.isNotEmpty())
     
    609592                    strSourceIp4.c_str()));
    610593        }
     594    }
     595
     596
     597    return VINF_SUCCESS;
     598}
     599
     600
     601/**
     602 * Init mapping from the natnet's IPv4 addresses to host's IPv4
     603 * loopbacks.  Plural "loopbacks" because it's now quite common to run
     604 * services on loopback addresses other than 127.0.0.1.  E.g. a
     605 * caching dns proxy on 127.0.1.1 or 127.0.0.53.
     606 */
     607int VBoxNetLwipNAT::ipv4LoopbackMapInit()
     608{
     609    int rc;
     610
     611    AddressToOffsetMapping tmp;
     612    rc = localMappings(m_net, tmp);
     613    if (RT_SUCCESS(rc) && !tmp.empty())
     614    {
     615        unsigned long i = 0;
     616        for (AddressToOffsetMapping::iterator it = tmp.begin();
     617             it != tmp.end() && i < RT_ELEMENTS(m_lo2off);
     618             ++it, ++i)
     619        {
     620            ip4_addr_set_u32(&m_lo2off[i].loaddr, it->first.u);
     621            m_lo2off[i].off = it->second;
     622        }
     623
     624        m_loOptDescriptor.lomap = m_lo2off;
     625        m_loOptDescriptor.num_lomap = i;
     626        m_ProxyOptions.lomap_desc = &m_loOptDescriptor;
    611627    }
    612628
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