VirtualBox

Changeset 105963 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Sep 4, 2024 6:25:15 PM (3 months ago)
Author:
vboxsync
Message:

Devices/Network: fix todos incl memory leaks and buffer sizing. bugref:10268

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/DrvNATlibslirp.cpp

    r105727 r105963  
    420420                {
    421421                    void  *pvSeg;
    422 
    423                     /** @todo r=jack: is this fine leaving as a constant instead of dynamic? */
    424422                    pvSeg = RTMemAlloc(DRVNAT_MAXFRAMESIZE);
    425423
     
    523521        pSgBuf->pvAllocator = NULL;
    524522
    525         /** @todo r=jack: figure out why need *2 */
    526         pSgBuf->aSegs[0].cbSeg = RT_ALIGN_Z(cbMin*2, 128);
     523        pSgBuf->aSegs[0].cbSeg = RT_ALIGN_Z(cbMin, 128);
    527524        pSgBuf->aSegs[0].pvSeg = RTMemAlloc(pSgBuf->aSegs[0].cbSeg);
    528525        if (!pSgBuf->pvUser || !pSgBuf->aSegs[0].pvSeg)
     
    16131610             "  Netmask: %lu\n", Network, Netmask));
    16141611
    1615 #ifndef RT_OS_WINDOWS /** @todo r=bird: Why do we need special windows code here?!? */
    16161612    struct in_addr vnetwork = RTNetIPv4AddrHEToInAddr(&Network);
    16171613    struct in_addr vnetmask = RTNetIPv4AddrHEToInAddr(&Netmask);
     
    16191615    struct in_addr vdhcp_start = RTNetInAddrFromU8(10, 0, 2, 15);
    16201616    struct in_addr vnameserver = RTNetInAddrFromU8(10, 0, 2, 3);
    1621 #else
    1622     struct in_addr vnetwork;
    1623     vnetwork.S_un.S_addr = RT_BSWAP_U32(Network.u);
    1624 
    1625     struct in_addr vnetmask;
    1626     vnetmask.S_un.S_addr = RT_BSWAP_U32(Netmask.u);
    1627 
    1628     struct in_addr vhost;
    1629     vhost.S_un.S_addr = RT_BSWAP_U32(0x0a000202);
    1630 
    1631     struct in_addr vdhcp_start;
    1632     vdhcp_start.S_un.S_addr = RT_BSWAP_U32(0x0a00020f);
    1633 
    1634     struct in_addr vnameserver;
    1635     vnameserver.S_un.S_addr = RT_BSWAP_U32(0x0a000203);
    1636 #endif
    1637 
    1638     /** @todo r=bird: This is leaked.  It can be a stack structure since libslirp
    1639      *        only copies values from it and doesn't retain the pointer. */
    1640     SlirpConfig *pSlirpCfg = new SlirpConfig { 0 };
    1641 
    1642     pSlirpCfg->version = 4;
    1643     pSlirpCfg->restricted = false;
    1644     pSlirpCfg->in_enabled = true;
    1645     pSlirpCfg->vnetwork = vnetwork;
    1646     pSlirpCfg->vnetmask = vnetmask;
    1647     pSlirpCfg->vhost = vhost;
    1648     pSlirpCfg->in6_enabled = true;
    1649 
    1650     inet_pton(AF_INET6, "fd00::", &pSlirpCfg->vprefix_addr6);
    1651     pSlirpCfg->vprefix_len = 64;
    1652     inet_pton(AF_INET6, "fd00::2", &pSlirpCfg->vhost6);
    1653 
    1654     pSlirpCfg->vhostname = "vbox";
    1655     pSlirpCfg->tftp_server_name = pThis->pszNextServer;
    1656     pSlirpCfg->tftp_path = pThis->pszTFTPPrefix;
    1657     pSlirpCfg->bootfile = pThis->pszBootFile;
    1658     pSlirpCfg->vdhcp_start = vdhcp_start;
    1659     pSlirpCfg->vnameserver = vnameserver;
    1660     pSlirpCfg->if_mtu = MTU;
    1661 
    1662     inet_pton(AF_INET6, "fd00::3", &pSlirpCfg->vnameserver6);
    1663 
    1664     pSlirpCfg->vdnssearch = NULL;
    1665     pSlirpCfg->vdomainname = NULL;
    1666 
    1667     /** @todo r=bird: This is leaked.  It can be a static structure.   */
    1668     SlirpCb *slirpCallbacks = (struct SlirpCb *)RTMemAlloc(sizeof(SlirpCb));
    1669 
    1670     slirpCallbacks->send_packet = &drvNAT_SendPacketCb;
    1671     slirpCallbacks->guest_error = &drvNAT_GuestErrorCb;
    1672     slirpCallbacks->clock_get_ns = &drvNAT_ClockGetNsCb;
    1673     slirpCallbacks->timer_new = &drvNAT_TimerNewCb;
    1674     slirpCallbacks->timer_free = &drvNAT_TimerFreeCb;
    1675     slirpCallbacks->timer_mod = &drvNAT_TimerModCb;
    1676     slirpCallbacks->register_poll_fd = &drvNAT_RegisterPoll;
    1677     slirpCallbacks->unregister_poll_fd = &drvNAT_UnregisterPoll;
    1678     slirpCallbacks->notify = &drvNAT_NotifyCb;
    1679     slirpCallbacks->init_completed = NULL;
    1680     slirpCallbacks->timer_new_opaque = NULL;
    1681 
    1682     Slirp *pSlirp = slirp_new(/* cfg */ pSlirpCfg, /* callbacks */ slirpCallbacks, /* opaque */ pThis);
     1617
     1618    SlirpConfig slirpCfg = { 0 };
     1619    static SlirpCb slirpCallbacks = { 0 };
     1620
     1621    slirpCfg.version = 4;
     1622    slirpCfg.restricted = false;
     1623    slirpCfg.in_enabled = true;
     1624    slirpCfg.vnetwork = vnetwork;
     1625    slirpCfg.vnetmask = vnetmask;
     1626    slirpCfg.vhost = vhost;
     1627    slirpCfg.in6_enabled = true;
     1628
     1629    inet_pton(AF_INET6, "fd00::", &slirpCfg.vprefix_addr6);
     1630    slirpCfg.vprefix_len = 64;
     1631    inet_pton(AF_INET6, "fd00::2", &slirpCfg.vhost6);
     1632
     1633    slirpCfg.vhostname = "vbox";
     1634    slirpCfg.tftp_server_name = pThis->pszNextServer;
     1635    slirpCfg.tftp_path = pThis->pszTFTPPrefix;
     1636    slirpCfg.bootfile = pThis->pszBootFile;
     1637    slirpCfg.vdhcp_start = vdhcp_start;
     1638    slirpCfg.vnameserver = vnameserver;
     1639    slirpCfg.if_mtu = MTU;
     1640
     1641    inet_pton(AF_INET6, "fd00::3", &slirpCfg.vnameserver6);
     1642
     1643    slirpCfg.vdnssearch = NULL;
     1644    slirpCfg.vdomainname = NULL;
     1645
     1646    slirpCallbacks.send_packet = &drvNAT_SendPacketCb;
     1647    slirpCallbacks.guest_error = &drvNAT_GuestErrorCb;
     1648    slirpCallbacks.clock_get_ns = &drvNAT_ClockGetNsCb;
     1649    slirpCallbacks.timer_new = &drvNAT_TimerNewCb;
     1650    slirpCallbacks.timer_free = &drvNAT_TimerFreeCb;
     1651    slirpCallbacks.timer_mod = &drvNAT_TimerModCb;
     1652    slirpCallbacks.register_poll_fd = &drvNAT_RegisterPoll;
     1653    slirpCallbacks.unregister_poll_fd = &drvNAT_UnregisterPoll;
     1654    slirpCallbacks.notify = &drvNAT_NotifyCb;
     1655    slirpCallbacks.init_completed = NULL;
     1656    slirpCallbacks.timer_new_opaque = NULL;
     1657
     1658    Slirp *pSlirp = slirp_new(/* cfg */ &slirpCfg, /* callbacks */ &slirpCallbacks, /* opaque */ pThis);
    16831659
    16841660    if (pSlirp == NULL)
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