VirtualBox

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


Ignore:
Timestamp:
Jul 5, 2024 2:26:46 PM (7 months ago)
Author:
vboxsync
Message:

Linux/Network: Do not attach netfilter to wrong names or multiple times, bugref:10713

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

Legend:

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

    r98103 r105163  
    4343# include <stdio.h>
    4444#endif /* !RT_OS_WINDOWS */
     45
     46#ifdef RT_OS_LINUX
     47# include <linux/version.h>
     48# if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0) /* proc_ns introduced */
     49#  define VBOXNETFLT_LINUX_NAMESPACE_SUPPORT
     50# endif
     51#endif
    4552
    4653#define VBOXNET_IPV4ADDR_DEFAULT      0x0138A8C0  /* 192.168.56.1 */
  • trunk/src/VBox/Main/src-client/ConsoleImplConfigCommon.cpp

    r104946 r105163  
    26602660                    }
    26612661                }
     2662#  ifdef VBOXNETFLT_LINUX_NAMESPACE_SUPPORT
     2663                RTUUID IfaceUuid;
     2664                Bstr IfId;
     2665                hrc = hostInterface->COMGETTER(Id)(IfId.asOutParam());                      H();
     2666                vrc = RTUuidFromUtf16(&IfaceUuid, IfId.raw());
     2667                AssertRCReturn(vrc, vrc);
     2668                char szTrunkNameWithNamespace[INTNET_MAX_TRUNK_NAME];
     2669                RTStrPrintf(szTrunkNameWithNamespace, sizeof(szTrunkNameWithNamespace), "%u/%s",
     2670                            IfaceUuid.au32[0], pszTrunk);
     2671                pszTrunk = szTrunkNameWithNamespace;
     2672#  endif
    26622673
    26632674# else
  • trunk/src/VBox/Main/src-server/linux/NetIf-linux.cpp

    r98288 r105163  
    4444#include <unistd.h>
    4545#include <iprt/asm.h>
     46#include <errno.h>
    4647
    4748#include "HostNetworkInterfaceImpl.h"
     
    155156        RTUUID uuid;
    156157        RTUuidClear(&uuid);
     158#ifdef VBOXNETFLT_LINUX_NAMESPACE_SUPPORT
     159        uuid.au32[0] = 0;   /* Use 0 as the indicator of missing namespace info. */
     160        /*
     161         * Namespace links use the following naming convention: "net:[1234567890]".
     162         * The maximum value of inode number is 4294967295, which gives up precisely
     163         * 16 characters without terminating zero.
     164         */
     165        char szBuf[24];
     166        ssize_t len = readlink("/proc/self/ns/net", szBuf, sizeof(szBuf) - 1);
     167        if (len == -1)
     168            Log(("NetIfList: Failed to get namespace for VBoxSVC, error %d\n", errno));
     169        else if (!RTStrStartsWith(szBuf, "net:["))
     170            Log(("NetIfList: Failed to get network namespace inode from %s\n", szBuf));
     171        else
     172            uuid.au32[0] = RTStrToUInt32(szBuf + 5);
     173        Log(("NetIfList: VBoxSVC namespace inode %u\n", uuid.au32[0]));
     174        /* Hashing the name is probably an overkill as MAC addresses should ensure uniqueness */
     175        uuid.au32[1] = RTStrHash1(pszName);
     176#else /* !VBOXNETFLT_LINUX_NAMESPACE_SUPPORT */
    157177        memcpy(&uuid, Req.ifr_name, RT_MIN(sizeof(Req.ifr_name), sizeof(uuid)));
     178#endif /* !VBOXNETFLT_LINUX_NAMESPACE_SUPPORT */
    158179        uuid.Gen.u8ClockSeqHiAndReserved = (uint8_t)((uuid.Gen.u8ClockSeqHiAndReserved & 0x3f) | 0x80);
    159180        uuid.Gen.u16TimeHiAndVersion = (uint16_t)((uuid.Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000);
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