VirtualBox

Changeset 87450 in vbox for trunk/src/VBox/NetworkServices


Ignore:
Timestamp:
Jan 27, 2021 2:00:34 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
142468
Message:

NAT/Net: Get rid of obsolete options -p/-P to pass port-forwarding
rules on the command line. It's a left-over from some very early test
code that just adds clutter. Leave the placeholders to add custom
options in place. Since there are no options, and arrays can't be
empty, use an array with a sentinel entry instead (and only the
sentinel for now).

While here fix VBoxNetBaseService::addCommandLineOption() - const and
pointer typedefs don't mean what they might seem to mean.

Location:
trunk/src/VBox/NetworkServices
Files:
3 edited

Legend:

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

    r87449 r87450  
    113113
    114114
    115 static RTGETOPTDEF g_aGetOptDef[] =
    116 {
    117     { "--port-forward4",           'p',   RTGETOPT_REQ_STRING },
    118     { "--port-forward6",           'P',   RTGETOPT_REQ_STRING }
    119 };
    120115
    121116typedef struct NATSERVICEPORTFORWARDRULE
     
    156151    ComNatListenerPtr m_VBoxClientListener;
    157152
    158     /* Only for debug needs, by default NAT service should load rules from SVC
    159      * on startup, and then on sync them on events.
    160      */
    161     bool fDontLoadRulesOnStartup;
    162 
    163153    VECNATSERVICEPF m_vecPortForwardRule4;
    164154    VECNATSERVICEPF m_vecPortForwardRule6;
     
    166156    static INTNETSEG aXmitSeg[64];
    167157
     158    static RTGETOPTDEF s_aGetOptDef[];
    168159
    169160public:
     
    174165
    175166    virtual void usage() { /** @todo should be implemented */ };
    176     virtual int parseOpt(int rc, const RTGETOPTUNION& getOptVal);
     167    virtual int parseOpt(int c, const RTGETOPTUNION &Value);
    177168
    178169    virtual bool isMainNeeded() const { return true; }
     
    207198
    208199INTNETSEG VBoxNetLwipNAT::aXmitSeg[64];
     200
     201/**
     202 * Additional command line options.
     203 *
     204 * Our parseOpt() will be called by the base class if any of these are
     205 * supplied.
     206 */
     207RTGETOPTDEF VBoxNetLwipNAT::s_aGetOptDef[] =
     208{
     209    /*
     210     * Currently there are no extra options and since arrays can't be
     211     * empty use a sentinel entry instead, so that the placeholder
     212     * code to process the options can be supplied nonetheless.
     213     */
     214    {}                          /* sentinel */
     215};
    209216
    210217
     
    251258    setIpv4Netmask(address);
    252259
    253     fDontLoadRulesOnStartup = false;
    254 
    255     for (size_t i = 0; i < RT_ELEMENTS(g_aGetOptDef); ++i)
    256         addCommandLineOption(&g_aGetOptDef[i]);
     260    /* tell the base class about our command line options */
     261    for (PCRTGETOPTDEF pcOpt = &s_aGetOptDef[0]; pcOpt->iShort != 0; ++pcOpt)
     262        addCommandLineOption(pcOpt);
    257263
    258264    LogFlowFuncLeave();
     
    285291 *
    286292 * Called by VBoxNetBaseService::parseArgs() for options that are not
    287  * recognized by the base class.
    288  */
    289 int VBoxNetLwipNAT::parseOpt(int rc, const RTGETOPTUNION& Val)
    290 {
    291     switch (rc)
    292     {
    293         case 'p':
    294         case 'P':
    295         {
    296             NATSERVICEPORTFORWARDRULE Rule;
    297             VECNATSERVICEPF& rules = (rc == 'P'?
    298                                         m_vecPortForwardRule6
    299                                       : m_vecPortForwardRule4);
    300 
    301             fDontLoadRulesOnStartup = true;
    302 
    303             RT_ZERO(Rule);
    304 
    305             int rc2 = netPfStrToPf(Val.psz, (rc == 'P'), &Rule.Pfr);
    306             RT_NOREF_PV(rc2);
    307             rules.push_back(Rule);
    308             return VINF_SUCCESS;
    309         }
    310         default:;
    311     }
    312     return VERR_NOT_FOUND;
     293 * recognized by the base class.  See s_aGetOptDef[].
     294 */
     295int VBoxNetLwipNAT::parseOpt(int c, const RTGETOPTUNION &Value)
     296{
     297    RT_NOREF(c, Value);
     298    return VERR_NOT_FOUND;      /* not recognized */
    313299}
    314300
     
    436422
    437423
    438     if (!fDontLoadRulesOnStartup)
    439     {
    440         fetchNatPortForwardRules(m_vecPortForwardRule4, /* :fIsIPv6 */ false);
     424    fetchNatPortForwardRules(m_vecPortForwardRule4, /* :fIsIPv6 */ false);
     425    if (fIPv6Enabled)
    441426        fetchNatPortForwardRules(m_vecPortForwardRule6, /* :fIsIPv6 */ true);
    442     }
    443427
    444428    AddressToOffsetMapping tmp;
  • trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp

    r85506 r87450  
    108108    PINTNETBUF          m_pIfBuf;       /**< Interface buffer. */
    109109
    110     std::vector<PRTGETOPTDEF> m_vecOptionDefs;
     110    std::vector<PCRTGETOPTDEF> m_vecOptionDefs;
    111111
    112112    int32_t             m_cVerbosity;
     
    682682
    683683
    684 void VBoxNetBaseService::addCommandLineOption(const PRTGETOPTDEF optDef)
     684void VBoxNetBaseService::addCommandLineOption(PCRTGETOPTDEF optDef)
    685685{
    686686    m->m_vecOptionDefs.push_back(optDef);
     
    843843    for (unsigned int i = 0; i < m->m_vecOptionDefs.size(); ++i)
    844844    {
    845         PRTGETOPTDEF pOpt = m->m_vecOptionDefs[i];
     845        PCRTGETOPTDEF pOpt = m->m_vecOptionDefs[i];
    846846        memcpy(&pOptArray[i], pOpt, sizeof(*pOpt));
    847847    }
  • trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.h

    r84364 r87450  
    115115    void setVerbosityLevel(int32_t);
    116116
    117     void addCommandLineOption(const PRTGETOPTDEF);
     117    void addCommandLineOption(PCRTGETOPTDEF);
    118118
    119119    /**
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