]> xenbits.xensource.com Git - libvirt.git/commitdiff
virnetdev: Check for root in virNetDevGetFeatures
authorJohn Ferlan <jferlan@redhat.com>
Wed, 4 Nov 2015 15:26:16 +0000 (10:26 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 6 Nov 2015 16:19:07 +0000 (11:19 -0500)
Since the SIOCETHTOOL ioctl only works for privileged daemons, if called
when not root, then virNetDevGetFeatures will VIR_DEBUG a message and
return 0 as if the functions were not available for the architecture.
This effectively returns an empty bitmap indicating no features available.

Introduced by commit id 'c9027d8f4'

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/util/virnetdev.c

index fb367e7eae72beb9633234623b13e4ea5c59e9bc..0bc1a6f603417eff28b3e077f2eb25a7ec063afb 100644 (file)
@@ -3239,7 +3239,8 @@ virNetDevGFeatureAvailable(const char *ifname, struct ethtool_gfeatures *cmd)
  * @ifname: name of the interface
  * @out: bitmap of the available virNetDevFeature feature bits
  *
- * Returns 0 on success, -1 on failure.
+ * Returns 0 on success or if called from session mode, -1 on failure.
+ * If called from session mode, an empty bitmap is returned.
  */
 int
 virNetDevGetFeatures(const char *ifname,
@@ -3271,6 +3272,12 @@ virNetDevGetFeatures(const char *ifname,
     if (!(*out = virBitmapNew(VIR_NET_DEV_FEAT_LAST)))
         return -1;
 
+    /* Only fetch features if we're privileged, but no need to fail */
+    if (geteuid() != 0) {
+        VIR_DEBUG("ETHTOOL feature bits not available in session mode");
+        return 0;
+    }
+
     for (i = 0; i < ARRAY_CARDINALITY(cmds); i++) {
         cmd.cmd = cmds[i].cmd;
         if (virNetDevFeatureAvailable(ifname, &cmd) == 1)