VirtualBox

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


Ignore:
Timestamp:
Jul 8, 2019 11:50:48 PM (6 years ago)
Author:
vboxsync
Message:

Dhcpd: Made the lease database filename configurable so Main can decide exactly where it is and what's it called in order to correctly implement IDCHPServer::FindLeaseByMAC. Use RTPathPurgeFilename to create the default lease filename. Added a todo regarding a bogus looking message option in an ACK. bugref:9288

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/Dhcpd/Config.cpp

    r79568 r79613  
    169169    {
    170170        m_strBaseName = m_strNetwork;
    171 
    172 /** @todo make IPRT function for this.   */
    173         char ch;
    174 #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
    175         static const char s_szIllegals[] = "/\\\"*:<>?|\t\v\n\r\f\a\b"; /** @todo all control chars... */
    176         for (char *psz = m_strBaseName.mutableRaw(); (ch = *psz) != '\0'; ++psz)
    177             if (strchr(s_szIllegals, ch))
    178                 *psz = '_';
    179 #else
    180         for (char *psz = m_strBaseName.mutableRaw(); (ch = *psz) != '\0'; ++psz)
    181             if (RTPATH_IS_SEP(ch))
    182                 *psz = '_';
    183 #endif
    184         m_strBaseName.jolt(); /* Not really necessary, but it's protocol. */
     171        RTPathPurgeFilename(m_strBaseName.mutableRaw(), RTPATH_STR_F_STYLE_HOST);
     172        m_strBaseName.jolt();
    185173    }
    186174    else
     
    260248        RTUUID Uuid;
    261249        int rc = RTUuidCreate(&Uuid);
    262         AssertReturn(rc, rc);
     250        AssertRCReturn(rc, rc);
    263251
    264252        m_MacAddress.au8[0] = 0x08;
     
    747735        m_strTrunk = "";
    748736
     737    m_strLeaseFilename = pElmServer->findAttributeValue("leaseFilename"); /* optional */
     738
    749739    i_getIPv4AddrAttribute(pElmServer, "IPAddress", &m_IPv4Address);
    750740    i_getIPv4AddrAttribute(pElmServer, "networkMask", &m_IPv4Netmask);
  • trunk/src/VBox/NetworkServices/Dhcpd/Config.h

    r79563 r79613  
    4646    RTCString       m_strNetwork;       /**< The name of the internal network the DHCP server is connected to. */
    4747    RTCString       m_strBaseName;      /**< m_strNetwork sanitized to be usable in a path component. */
     48    RTCString       m_strLeaseFilename; /**< The lease filename if one given.  Dhcpd will pick a default if empty. */
    4849
    4950    RTCString       m_strTrunk;         /**< The trunk name of the internal network. */
     
    9192
    9293    const RTCString    &getNetwork() const RT_NOEXCEPT          { return m_strNetwork; }
     94    const RTCString    &getBaseName() const RT_NOEXCEPT         { return m_strBaseName; }
     95    const RTCString    &getLeaseFilename() const RT_NOEXCEPT    { return m_strLeaseFilename; }
    9396
    94     const RTCString    &getBaseName() const RT_NOEXCEPT         { return m_strBaseName; }
    9597    const RTCString    &getTrunk() const RT_NOEXCEPT            { return m_strTrunk; }
    9698    INTNETTRUNKTYPE     getTrunkType() const RT_NOEXCEPT        { return m_enmTrunkType; }
  • trunk/src/VBox/NetworkServices/Dhcpd/DHCPD.cpp

    r79568 r79613  
    4545    AssertReturn(!m_pConfig, VERR_INVALID_STATE);
    4646
    47     /** @todo r=bird: This must be configurable so main can read the database and
    48      * fish assignments out of it.  (That's the most efficient and accurate way of
    49      * figuring  out the IP address of a VM.) */
    50 
    5147    /* leases filename */
    52     int rc = m_strLeasesFilename.assignNoThrow(pConfig->getHome());
    53     if (RT_SUCCESS(rc))
    54         rc = RTPathAppendCxx(m_strLeasesFilename, pConfig->getBaseName());
    55     if (RT_SUCCESS(rc))
    56         rc = m_strLeasesFilename.appendNoThrow("-Dhcpd.leases");
     48    int rc;
     49    if (pConfig->getLeaseFilename().isEmpty())
     50        rc = m_strLeasesFilename.assignNoThrow(pConfig->getLeaseFilename());
     51    else
     52    {
     53        rc = m_strLeasesFilename.assignNoThrow(pConfig->getHome());
     54        if (RT_SUCCESS(rc))
     55            rc = RTPathAppendCxx(m_strLeasesFilename, pConfig->getBaseName());
     56        if (RT_SUCCESS(rc))
     57            rc = m_strLeasesFilename.appendNoThrow("-Dhcpd.leases");
     58    }
    5759    if (RT_SUCCESS(rc))
    5860    {
     
    322324    if (req.ciaddr().u != 0 && reqAddr.present() && reqAddr.value().u != req.ciaddr().u)
    323325    {
    324         std::unique_ptr<DhcpServerMessage> nak (
    325             i_createMessage(RTNET_DHCP_MT_NAC, req)
    326         );
     326        std::unique_ptr<DhcpServerMessage> nak(i_createMessage(RTNET_DHCP_MT_NAC, req));
    327327        nak->addOption(OptMessage("Requested address does not match ciaddr"));
    328328        return nak.release();
     
    349349    ack->addOptions(m_pConfig->getOptions(replyOptions, optlist, req.clientId()));
    350350
     351    /** @todo r=bird: Sec 9.9 in rfc-2132 indicates the server only sends this in NACKs. Test code? */
    351352    ack->addOption(OptMessage("Ok, ok, here it is"));
    352353
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