VirtualBox

Changeset 68444 in vbox for trunk/src/VBox/Devices/Network


Ignore:
Timestamp:
Aug 17, 2017 1:05:10 PM (7 years ago)
Author:
vboxsync
Message:

NAT: Bind TCP sockets to specific address if requested. Why and how
this has been overlooked is a mistery. Report the address we will
bind to in the release log. While here, actually verify --natbindip
argument at the API call time.

Location:
trunk/src/VBox/Devices/Network
Files:
3 edited

Legend:

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

    r65710 r68444  
    16561656        slirp_set_mtu(pThis->pNATState, MTU);
    16571657        slirp_set_somaxconn(pThis->pNATState, i32SoMaxConn);
     1658
    16581659        char *pszBindIP = NULL;
    16591660        GET_STRING_ALLOC(rc, pThis, pCfg, "BindIP", pszBindIP);
    1660         rc = slirp_set_binding_address(pThis->pNATState, pszBindIP);
    1661         if (rc != 0 && pszBindIP && *pszBindIP)
    1662             LogRel(("NAT: Value of BindIP has been ignored\n"));
    1663 
    1664         if(pszBindIP != NULL)
     1661        slirp_set_binding_address(pThis->pNATState, pszBindIP);
     1662        if (pszBindIP != NULL)
    16651663            MMR3HeapFree(pszBindIP);
     1664
    16661665#define SLIRP_SET_TUNING_VALUE(name, setter)                    \
    16671666            do                                                  \
  • trunk/src/VBox/Devices/Network/slirp/slirp.c

    r65810 r68444  
    16941694int slirp_set_binding_address(PNATState pData, char *addr)
    16951695{
    1696     if (addr == NULL || (inet_aton(addr, &pData->bindIP) == 0))
    1697     {
     1696    int ok;
     1697
     1698    pData->bindIP.s_addr = INADDR_ANY;
     1699
     1700    if (addr == NULL || *addr == '\0')
     1701        return VINF_SUCCESS;
     1702
     1703    ok = inet_aton(addr, &pData->bindIP);
     1704    if (!ok)
     1705    {
     1706        LogRel(("NAT: Unable to parse binding address: %s\n", addr));
     1707        return VERR_INVALID_PARAMETER;
     1708    }
     1709
     1710    if (pData->bindIP.s_addr == INADDR_ANY)
     1711        return VINF_SUCCESS;
     1712
     1713    if ((pData->bindIP.s_addr & RT_N2H_U32_C(0xe0000000)) == RT_N2H_U32_C(0xe0000000))
     1714    {
     1715        LogRel(("NAT: Ignoring multicast binding address %RTnaipv4\n", pData->bindIP.s_addr));
    16981716        pData->bindIP.s_addr = INADDR_ANY;
    1699         return 1;
    1700     }
    1701     return 0;
     1717        return VERR_INVALID_PARAMETER;
     1718    }
     1719
     1720    LogRel(("NAT: Binding address %RTnaipv4\n", pData->bindIP.s_addr));
     1721    return VINF_SUCCESS;
    17021722}
    17031723
  • trunk/src/VBox/Devices/Network/slirp/tcp_subr.c

    r63668 r68444  
    417417        opt = 1;
    418418        setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char *)&opt, sizeof(opt));
     419
     420        if (pData->bindIP.s_addr != INADDR_ANY)
     421        {
     422            struct sockaddr_in self;
     423            self.sin_family = AF_INET;
     424            self.sin_addr = pData->bindIP;
     425            self.sin_port = 0;
     426
     427            ret = bind(s, (struct sockaddr *)&self, sizeof(self));
     428            if (ret != 0)
     429            {
     430                Log2(("NAT: bind(%RTnaipv4): %s\n", pData->bindIP.s_addr, strerror(errno)));
     431                return ret;
     432            }
     433        }
    419434
    420435        addr.sin_family = AF_INET;
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