VirtualBox

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


Ignore:
Timestamp:
Jul 5, 2024 2:26:46 PM (9 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
163803
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette