VirtualBox

Changeset 87381 in vbox


Ignore:
Timestamp:
Jan 22, 2021 10:27:07 PM (4 years ago)
Author:
vboxsync
Message:

NAT/Net: Hiding the ctor/dtor of the main class right in the middle of
the file is not the best idea. Move it where it can be more easily
found when skimming through the file. A few more minor cosmetic
tweaks while here. No actual code changes.

File:
1 edited

Legend:

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

    r87380 r87381  
    133133
    134134
    135 class VBoxNetLwipNAT: public VBoxNetBaseService, public NATNetworkEventAdapter
     135class VBoxNetLwipNAT
     136  : public VBoxNetBaseService,
     137    public NATNetworkEventAdapter
    136138{
    137139    friend class NATNetworkListener;
     
    196198};
    197199
     200INTNETSEG VBoxNetLwipNAT::aXmitSeg[64];
    198201
    199202static VBoxNetLwipNAT *g_pLwipNat;
    200 INTNETSEG VBoxNetLwipNAT::aXmitSeg[64];
     203
     204
     205
     206VBoxNetLwipNAT::VBoxNetLwipNAT(SOCKET icmpsock4, SOCKET icmpsock6)
     207  : VBoxNetBaseService("VBoxNetNAT", "nat-network")
     208{
     209    LogFlowFuncEnter();
     210
     211    m_ProxyOptions.ipv6_enabled = 0;
     212    m_ProxyOptions.ipv6_defroute = 0;
     213    m_ProxyOptions.icmpsock4 = icmpsock4;
     214    m_ProxyOptions.icmpsock6 = icmpsock6;
     215    m_ProxyOptions.tftp_root = NULL;
     216    m_ProxyOptions.src4 = NULL;
     217    m_ProxyOptions.src6 = NULL;
     218    RT_ZERO(m_src4);
     219    RT_ZERO(m_src6);
     220    m_src4.sin_family = AF_INET;
     221    m_src6.sin6_family = AF_INET6;
     222#if HAVE_SA_LEN
     223    m_src4.sin_len = sizeof(m_src4);
     224    m_src6.sin6_len = sizeof(m_src6);
     225#endif
     226    m_ProxyOptions.nameservers = NULL;
     227
     228    m_LwipNetIf.name[0] = 'N';
     229    m_LwipNetIf.name[1] = 'T';
     230
     231    RTMAC mac;
     232    mac.au8[0] = 0x52;
     233    mac.au8[1] = 0x54;
     234    mac.au8[2] = 0;
     235    mac.au8[3] = 0x12;
     236    mac.au8[4] = 0x35;
     237    mac.au8[5] = 0;
     238    setMacAddress(mac);
     239
     240    RTNETADDRIPV4 address;
     241    address.u     = RT_MAKE_U32_FROM_U8( 10,  0,  2,  2); // NB: big-endian
     242    setIpv4Address(address);
     243
     244    address.u     = RT_H2N_U32_C(0xffffff00);
     245    setIpv4Netmask(address);
     246
     247    fDontLoadRulesOnStartup = false;
     248
     249    for (size_t i = 0; i < RT_ELEMENTS(g_aGetOptDef); ++i)
     250        addCommandLineOption(&g_aGetOptDef[i]);
     251
     252    LogFlowFuncLeave();
     253}
     254
     255
     256VBoxNetLwipNAT::~VBoxNetLwipNAT()
     257{
     258    if (m_ProxyOptions.tftp_root)
     259    {
     260        RTStrFree((char *)m_ProxyOptions.tftp_root);
     261        m_ProxyOptions.tftp_root = NULL;
     262    }
     263    if (m_ProxyOptions.nameservers)
     264    {
     265        const char **pv = m_ProxyOptions.nameservers;
     266        while (*pv)
     267        {
     268            RTStrFree((char*)*pv);
     269            pv++;
     270        }
     271        RTMemFree(m_ProxyOptions.nameservers);
     272        m_ProxyOptions.nameservers = NULL;
     273    }
     274}
     275
    201276
    202277/**
     
    641716
    642717
    643 VBoxNetLwipNAT::VBoxNetLwipNAT(SOCKET icmpsock4, SOCKET icmpsock6) : VBoxNetBaseService("VBoxNetNAT", "nat-network")
    644 {
    645     LogFlowFuncEnter();
    646 
    647     m_ProxyOptions.ipv6_enabled = 0;
    648     m_ProxyOptions.ipv6_defroute = 0;
    649     m_ProxyOptions.icmpsock4 = icmpsock4;
    650     m_ProxyOptions.icmpsock6 = icmpsock6;
    651     m_ProxyOptions.tftp_root = NULL;
    652     m_ProxyOptions.src4 = NULL;
    653     m_ProxyOptions.src6 = NULL;
    654     RT_ZERO(m_src4);
    655     RT_ZERO(m_src6);
    656     m_src4.sin_family = AF_INET;
    657     m_src6.sin6_family = AF_INET6;
    658 #if HAVE_SA_LEN
    659     m_src4.sin_len = sizeof(m_src4);
    660     m_src6.sin6_len = sizeof(m_src6);
    661 #endif
    662     m_ProxyOptions.nameservers = NULL;
    663 
    664     m_LwipNetIf.name[0] = 'N';
    665     m_LwipNetIf.name[1] = 'T';
    666 
    667     RTMAC mac;
    668     mac.au8[0] = 0x52;
    669     mac.au8[1] = 0x54;
    670     mac.au8[2] = 0;
    671     mac.au8[3] = 0x12;
    672     mac.au8[4] = 0x35;
    673     mac.au8[5] = 0;
    674     setMacAddress(mac);
    675 
    676     RTNETADDRIPV4 address;
    677     address.u     = RT_MAKE_U32_FROM_U8( 10,  0,  2,  2); // NB: big-endian
    678     setIpv4Address(address);
    679 
    680     address.u     = RT_H2N_U32_C(0xffffff00);
    681     setIpv4Netmask(address);
    682 
    683     fDontLoadRulesOnStartup = false;
    684 
    685     for(unsigned int i = 0; i < RT_ELEMENTS(g_aGetOptDef); ++i)
    686         addCommandLineOption(&g_aGetOptDef[i]);
    687 
    688     LogFlowFuncLeave();
    689 }
    690 
    691 
    692 VBoxNetLwipNAT::~VBoxNetLwipNAT()
    693 {
    694     if (m_ProxyOptions.tftp_root)
    695     {
    696         RTStrFree((char *)m_ProxyOptions.tftp_root);
    697         m_ProxyOptions.tftp_root = NULL;
    698     }
    699     if (m_ProxyOptions.nameservers)
    700     {
    701         const char **pv = m_ProxyOptions.nameservers;
    702         while (*pv)
    703         {
    704             RTStrFree((char*)*pv);
    705             pv++;
    706         }
    707         RTMemFree(m_ProxyOptions.nameservers);
    708         m_ProxyOptions.nameservers = NULL;
    709     }
    710 }
    711 
    712 
    713718/*static*/ int VBoxNetLwipNAT::natServicePfRegister(NATSEVICEPORTFORWARDRULE& natPf)
    714719{
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