VirtualBox

Changeset 67431 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Jun 15, 2017 9:41:18 PM (8 years ago)
Author:
vboxsync
Message:

Main: ASMBitSetRange and ASMBitFirstClear don't do the right thing for
network masks because of the wrong bit-order. Use new
RTNetMaskToPrefixIPv6 and RTNetPrefixToMaskIPv6 instead.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/netif.h

    r65428 r67431  
    117117}
    118118
    119 DECLINLINE(ULONG) composeIPv6PrefixLenghFromAddress(PRTNETADDRIPV6 aAddrPtr)
    120 {
    121     int res = ASMBitFirstClear(aAddrPtr, sizeof(RTNETADDRIPV6)*8);
    122     return res != -1 ? res : 128;
    123 }
    124 
    125 DECLINLINE(int) prefixLength2IPv6Address(ULONG cPrefix, PRTNETADDRIPV6 aAddrPtr)
    126 {
    127     if (cPrefix > 128)
    128         return VERR_INVALID_PARAMETER;
    129     if (!aAddrPtr)
    130         return VERR_INVALID_PARAMETER;
    131 
    132     RT_ZERO(*aAddrPtr);
    133 
    134     ASMBitSetRange(aAddrPtr, 0, cPrefix);
    135 
    136     return VINF_SUCCESS;
    137 }
    138 
    139119DECLINLINE(Bstr) composeHardwareAddress(PRTMAC aMacPtr)
    140120{
  • trunk/src/VBox/Main/src-server/HostNetworkInterfaceImpl.cpp

    r65120 r67431  
    163163    if (RT_SUCCESS(rc))
    164164    {
     165        int iPrefixIPv6;
     166
    165167        m.realIPAddress = m.IPAddress = info.IPAddress.u;
    166168        m.realNetworkMask = m.networkMask = info.IPNetMask.u;
    167169        m.dhcpEnabled = info.bDhcpEnabled;
    168170        m.realIPV6Address = m.IPV6Address = composeIPv6Address(&info.IPv6Address);
    169         m.realIPV6PrefixLength = m.IPV6NetworkMaskPrefixLength = composeIPv6PrefixLenghFromAddress(&info.IPv6NetMask);
     171        RTNetMaskToPrefixIPv6(&info.IPv6NetMask, &iPrefixIPv6);
     172        m.realIPV6PrefixLength = m.IPV6NetworkMaskPrefixLength = iPrefixIPv6;
    170173        m.hardwareAddress = composeHardwareAddress(&info.MACAddress);
    171174#ifdef RT_OS_WINDOWS
     
    220223    mIfType = ifType;
    221224
     225    int iPrefixIPv6;
     226
    222227    m.realIPAddress = m.IPAddress = pIf->IPAddress.u;
    223228    m.realNetworkMask = m.networkMask = pIf->IPNetMask.u;
    224229    m.realIPV6Address = m.IPV6Address = composeIPv6Address(&pIf->IPv6Address);
    225     m.realIPV6PrefixLength = m.IPV6NetworkMaskPrefixLength = composeIPv6PrefixLenghFromAddress(&pIf->IPv6NetMask);
     230    RTNetMaskToPrefixIPv6(&pIf->IPv6NetMask, &iPrefixIPv6);
     231    m.realIPV6PrefixLength = m.IPV6NetworkMaskPrefixLength = iPrefixIPv6;
    226232    m.dhcpEnabled = pIf->bDhcpEnabled;
    227233    m.hardwareAddress = composeHardwareAddress(&pIf->MACAddress);
  • trunk/src/VBox/Main/src-server/win/NetIf-win.cpp

    r67390 r67431  
    2525#define NETIF_WITHOUT_NETCFG
    2626
    27 #include <iprt/asm.h>
    2827#include <iprt/err.h>
    2928#include <list>
     
    181180                                    {
    182181                                        fIPv6Found = true;
    183                                         ASMBitSetRange(&pInfo->IPv6NetMask, 0, pPrefix->PrefixLength);
     182                                        RTNetPrefixToMaskIPv6(pPrefix->PrefixLength, &pInfo->IPv6NetMask);
    184183                                    }
    185184                                    else
     
    17151714                    {
    17161715                        uPrefixLenV6 = pPrefix->PrefixLength;
    1717                         ASMBitSetRange(&pInfo->IPv6NetMask, 0, pPrefix->PrefixLength);
     1716                        RTNetPrefixToMaskIPv6(pPrefix->PrefixLength, &pInfo->IPv6NetMask);
    17181717                    }
    17191718                    else
     
    17751774                        netIfLog(("netIfFillInfoWithAddresses: Invalid IPv6 prefix length of %d\n", pAddrLh->OnLinkPrefixLength));
    17761775                    else
    1777                         ASMBitSetRange(&pInfo->IPv6NetMask, 0, pAddrLh->OnLinkPrefixLength);
     1776                        RTNetPrefixToMaskIPv6(pAddrLh->OnLinkPrefixLength, &pInfo->IPv6NetMask);
    17781777                }
    17791778                break;
    17801779        }
    17811780    }
    1782     netIfLog(("netIfFillInfoWithAddresses: %RTnaipv4/%u\n",
    1783               pInfo->IPAddress, ASMBitFirstClear(&pInfo->IPNetMask, sizeof(RTNETADDRIPV4)*8)));
    1784     netIfLog(("netIfFillInfoWithAddresses: %RTnaipv6/%u\n",
    1785               &pInfo->IPv6Address, composeIPv6PrefixLenghFromAddress(&pInfo->IPv6NetMask)));
     1781
     1782    if (fIPFound)
     1783    {
     1784        int iPrefixIPv4 = -1;
     1785        RTNetMaskToPrefixIPv4(&pInfo->IPNetMask, &iPrefixIPv4);
     1786        netIfLog(("netIfFillInfoWithAddresses: %RTnaipv4/%u\n", pInfo->IPAddress, iPrefixIPv4));
     1787    }
     1788    if (fIPv6Found)
     1789    {
     1790        int iPrefixIPv6 = -1;
     1791        RTNetMaskToPrefixIPv6(&pInfo->IPv6NetMask, &iPrefixIPv6);
     1792        netIfLog(("netIfFillInfoWithAddresses: %RTnaipv6/%u\n", &pInfo->IPv6Address, iPrefixIPv6));
     1793    }
    17861794}
    17871795
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