]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: use AF_UNIX family (not AF_PACKET) for ioctl sockets
authorLaine Stump <laine@laine.org>
Fri, 17 Mar 2017 21:33:42 +0000 (17:33 -0400)
committerLaine Stump <laine@laine.org>
Wed, 22 Mar 2017 16:07:13 +0000 (12:07 -0400)
The exact family of the socket created for the fd used by ioctl(7)
doesn't matter, it just needs to be a socket and not a file. But for
some reason when macvtap support was added, it used
AF_PACKET/SOCK_DGRAM sockets for its ioctls; we later used the same
AF_PACKET/SOCK_DGRAM socket for new ioctls we added, and eventually
modified the other pre-existing ioctl sockets (for creating/deleting
bridges) to also use AF_PACKET/SOCK_DGRAM (that code originally used
AF_UNIX/SOCK_STREAM).

The problem with using AF_PACKET (intended for sending/receiving "raw"
packets, i.e. packets that can be some protocol other than TCP or UDP)
is that it requires root privileges. This meant that none of the
ioctls in virnetdev.c or virnetdevip.c would work when running
libvirtd unprivileged.

This packet solves that problem by changing the family to AF_UNIX when
creating the socket used for any ioctl().

src/util/virnetdev.c
src/util/virnetdevip.c

index 91a5274aa58d658e7b78485a2fb494c6eb422757..acc6c2ea7e9775df112aab23d30444fd5e4fd793 100644 (file)
@@ -41,7 +41,7 @@
 #ifdef __linux__
 # include <linux/sockios.h>
 # include <linux/if_vlan.h>
-# define VIR_NETDEV_FAMILY AF_PACKET
+# define VIR_NETDEV_FAMILY AF_UNIX
 #elif defined(HAVE_STRUCT_IFREQ) && defined(AF_LOCAL)
 # define VIR_NETDEV_FAMILY AF_LOCAL
 #else
@@ -2589,9 +2589,6 @@ virNetDevGetFeatures(const char *ifname,
         return 0;
     }
 
-    /* Ultimately uses AF_PACKET for socket which requires privileged
-     * daemon support.
-     */
     if ((fd = virNetDevSetupControl(ifname, &ifr)) < 0)
         goto cleanup;
 
index a4d3824279f585a54c9b0ab1d6e54a7c63c5e88a..c9ac6baf73ea39a17bcedb2ad49e7e5dfa977492 100644 (file)
@@ -44,7 +44,7 @@
 #ifdef __linux__
 # include <linux/sockios.h>
 # include <linux/if_vlan.h>
-# define VIR_NETDEV_FAMILY AF_PACKET
+# define VIR_NETDEV_FAMILY AF_UNIX
 #elif defined(HAVE_STRUCT_IFREQ) && defined(AF_LOCAL)
 # define VIR_NETDEV_FAMILY AF_LOCAL
 #else