[arch-commits] Commit in virtualbox/trunk (009-vbox-host-only.patch PKGBUILD)

Christian Hesse eworm at archlinux.org
Mon Jul 24 09:18:23 UTC 2017


    Date: Monday, July 24, 2017 @ 09:18:22
  Author: eworm
Revision: 246200

upgpkg: virtualbox 5.1.24-2

* fix host-only networking (FS#54889)
* drop unused optional dependency to net-tools (uses ip now)

Added:
  virtualbox/trunk/009-vbox-host-only.patch
Modified:
  virtualbox/trunk/PKGBUILD

--------------------------+
 009-vbox-host-only.patch |  155 +++++++++++++++++++++++++++++++++++++++++++++
 PKGBUILD                 |    5 -
 2 files changed, 158 insertions(+), 2 deletions(-)

Added: 009-vbox-host-only.patch
===================================================================
--- 009-vbox-host-only.patch	                        (rev 0)
+++ 009-vbox-host-only.patch	2017-07-24 09:18:22 UTC (rev 246200)
@@ -0,0 +1,155 @@
+diff --git a/src/VBox/HostDrivers/adpctl/VBoxNetAdpCtl.cpp b/src/VBox/HostDrivers/adpctl/VBoxNetAdpCtl.cpp
+index c4bd19f..84003a0 100644
+--- a/src/VBox/HostDrivers/adpctl/VBoxNetAdpCtl.cpp
++++ b/src/VBox/HostDrivers/adpctl/VBoxNetAdpCtl.cpp
+@@ -32,6 +32,7 @@
+ #include <sys/stat.h>
+ #include <fcntl.h>
+ #ifdef RT_OS_LINUX
++# include <arpa/inet.h>
+ # include <net/if.h>
+ # include <linux/types.h>
+ /* Older versions of ethtool.h rely on these: */
+@@ -253,14 +254,79 @@ protected:
+ };
+ 
+ 
++#ifdef RT_OS_LINUX
++/*
++ * Helper class to incapsulate IPv4 address conversion.
++ */
++class AddressIPv4
++{
++public:
++    AddressIPv4(const char *pcszAddress, const char *pcszNetmask = 0)
++        {
++            if (pcszNetmask)
++                m_Prefix = maskToPrefix(pcszNetmask);
++            else
++            {
++                /*
++                 * Since guessing network mask is probably futile we simply use 24,
++                 * as it matches our defaults. When non-default values are used
++                 * providing a proper netmask is up to the user.
++                 */
++                m_Prefix = 24;
++            }
++            inet_pton(AF_INET, pcszAddress, &(m_Address.sin_addr));
++            snprintf(m_szAddressAndMask, sizeof(m_szAddressAndMask), "%s/%d", pcszAddress, m_Prefix);
++            m_Broadcast.sin_addr.s_addr = computeBroadcast(m_Address.sin_addr.s_addr, m_Prefix);
++            inet_ntop(AF_INET, &(m_Broadcast.sin_addr), m_szBroadcast, sizeof(m_szBroadcast));
++        }
++    const char *getBroadcast() const { return m_szBroadcast; };
++    const char *getAddressAndMask() const { return m_szAddressAndMask; };
++private:
++    unsigned int maskToPrefix(const char *pcszNetmask);
++    unsigned long computeBroadcast(unsigned long ulAddress, unsigned int uPrefix);
++
++    unsigned int       m_Prefix;
++    struct sockaddr_in m_Address;
++    struct sockaddr_in m_Broadcast;
++    char m_szAddressAndMask[INET_ADDRSTRLEN + 3]; /* e.g. 192.168.56.101/24 */
++    char m_szBroadcast[INET_ADDRSTRLEN];
++};
++
++unsigned int AddressIPv4::maskToPrefix(const char *pcszNetmask)
++{
++    unsigned cBits = 0;
++    unsigned m[4];
++
++    if (sscanf(pcszNetmask, "%u.%u.%u.%u", &m[0], &m[1], &m[2], &m[3]) == 4)
++    {
++        for (int i = 0; i < 4 && m[i]; ++i)
++        {
++            int mask = m[i];
++            while (mask & 0x80)
++            {
++                cBits++;
++                mask <<= 1;
++            }
++        }
++    }
++    return cBits;
++}
++
++unsigned long AddressIPv4::computeBroadcast(unsigned long ulAddress, unsigned int uPrefix)
++{
++    /* Note: the address is big-endian. */
++    unsigned long ulNetworkMask = (1l << uPrefix) - 1;
++    return (ulAddress & ulNetworkMask) | ~ulNetworkMask;
++}
++
++
+ /*
+  * Linux-specific implementation of 'ip' command, as other platforms do not support it.
+  */
+ class CmdIpLinux : public AddressCommand
+ {
+ public:
+-    CmdIpLinux() { pszBuffer = 0; m_pszPath = "/sbin/ip"; };
+-    virtual ~CmdIpLinux() { delete pszBuffer; };
++    CmdIpLinux() { m_pszPath = "/sbin/ip"; };
+     /**
+      * IPv4 and IPv6 syntax is the same, so we override `remove` instead of implementing
+      * family-specific commands. It would be easier to use the same body in both
+@@ -272,11 +338,14 @@ public:
+ protected:
+     virtual int addV4(const char *pcszAdapter, const char *pcszAddress, const char *pcszNetmask = 0)
+         {
+-            return execute(CmdList("addr") << "add" << combine(pcszAddress, pcszNetmask) <<
+-                           "dev" << pcszAdapter);
++            AddressIPv4 addr(pcszAddress, pcszNetmask);
++            bringUp(pcszAdapter);
++            return execute(CmdList("addr") << "add" << addr.getAddressAndMask() <<
++                           "broadcast" << addr.getBroadcast() << "dev" << pcszAdapter);
+         };
+     virtual int addV6(const char *pcszAdapter, const char *pcszAddress, const char *pcszNetmask = 0)
+         {
++            bringUp(pcszAdapter);
+             return execute(CmdList("addr") << "add" << pcszAddress << "dev" << pcszAdapter);
+             NOREF(pcszNetmask);
+         };
+@@ -295,39 +364,11 @@ protected:
+     virtual CmdList getShowCommand(const char *pcszAdapter) const
+         { return CmdList("addr") << "show" << "dev" << pcszAdapter; };
+ private:
+-    /** Converts address and network mask into a single string in CIDR notation (like 192.168.1.1/24) */
+-    const char *combine(const char *pcszAddress, const char *pcszNetmask);
+-
+-    char *pszBuffer;
++    /** Brings up the adapter */
++    void bringUp(const char *pcszAdapter)
++        { execute(CmdList("link") << "set" << "dev" << pcszAdapter << "up"); };
+ };
+-
+-const char * CmdIpLinux::combine(const char *pcszAddress, const char *pcszNetmask)
+-{
+-    delete pszBuffer;
+-    if (pcszNetmask)
+-    {
+-        unsigned cBits = 0;
+-        unsigned m[4];
+-        if (sscanf(pcszNetmask, "%u.%u.%u.%u", &m[0], &m[1], &m[2], &m[3]) == 4)
+-        {
+-            for (int i = 0; i < 4 && m[i]; ++i)
+-            {
+-                int mask = m[i];
+-                while (mask & 0x80)
+-                {
+-                    cBits++;
+-                    mask <<= 1;
+-                }
+-            }
+-            const size_t cbBuf = strlen(pcszAddress) + 4;
+-            pszBuffer = new char[cbBuf]; // '/xx\0'
+-            snprintf(pszBuffer, cbBuf, "%s/%u", pcszAddress, cBits);
+-            return pszBuffer;
+-        }
+-    }
+-    return pcszAddress;
+-}
+-
++#endif /* RT_OS_LINUX */
+ 
+ 
+ /*********************************************************************************************************************************

Modified: PKGBUILD
===================================================================
--- PKGBUILD	2017-07-24 09:09:30 UTC (rev 246199)
+++ PKGBUILD	2017-07-24 09:18:22 UTC (rev 246200)
@@ -11,7 +11,7 @@
          'virtualbox-guest-utils-nox'
          'virtualbox-ext-vnc')
 pkgver=5.1.24
-pkgrel=1
+pkgrel=2
 arch=('i686' 'x86_64')
 url='http://virtualbox.org'
 license=('GPL' 'custom')
@@ -70,6 +70,7 @@
         '006-rdesktop-vrdp-keymap-path.patch'
         '007-python2-path.patch'
         '008-no-vboxvideo.patch'
+        '009-vbox-host-only.patch'
         )
 sha256sums=('ee2db169a322bf0db3c3b6d8b84aa39236f36cbf37d0a4c10ab65902a396bb60'
             'deb03efa7ad0376aa55a087f2e882afe00935f10b0e7aa853ba9147090d341ec'
@@ -89,6 +90,7 @@
             '5d5af2de5b1f1c61ec793503350f2440661cf8fd640f11b8a86f10bce499c0dc'
             '6bdb017459532537199c399eefd3d84d8dc7f1786e79997caebd3b6eb5c75d9f'
             '8b7f241107863f82a5b0ae336aead0b3366a40103ff72dbebf33f54b512a0cbc'
+            '4e71cfc6768ed5a36f414d6531522f4ee63ec4165e33a773a4ddacb17a44b08c'
             )
 
 prepare() {
@@ -143,7 +145,6 @@
              'libxcursor' 'libxinerama' 'libx11' 'libxext' 'libxmu' 'libxt'
              'qt5-base' 'qt5-x11extras' 'VIRTUALBOX-HOST-MODULES')
     optdepends=('vde2: Virtual Distributed Ethernet support'
-                'net-tools: Host-only or bridged networking support'
                 'virtualbox-guest-iso: Guest Additions CD image'
                 'virtualbox-ext-vnc: VNC server support'
                 'virtualbox-sdk: Developer kit')



More information about the arch-commits mailing list