]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virnetdev: Introduce virNetDevSetRootQDisc()
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 8 Oct 2020 12:37:54 +0000 (14:37 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 13 Oct 2020 14:31:29 +0000 (16:31 +0200)
This helper changes the root qdisc on given interface.
Ideally, it would be written using netlink but my attempts to
write the code were not successful and thus I've fallen back to
virCommand() + tc.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/libvirt_private.syms
src/util/virnetdev.c
src/util/virnetdev.h

index d773aee5713e6e99482c8d324ae7ba348841fd01..52e9c6313fb6f036ab07f664b8a1102382cb010a 100644 (file)
@@ -2580,6 +2580,7 @@ virNetDevSetOnline;
 virNetDevSetPromiscuous;
 virNetDevSetRcvAllMulti;
 virNetDevSetRcvMulti;
+virNetDevSetRootQDisc;
 virNetDevSetupControl;
 virNetDevSysfsFile;
 virNetDevValidateConfig;
index e711a6dc8a7463ab5b66ae73f17f62050059f69e..5c7660dab4f96326b05bbf4740c9f976a928e48b 100644 (file)
@@ -3394,3 +3394,49 @@ virNetDevRunEthernetScript(const char *ifname, const char *script)
 
     return virCommandRun(cmd, NULL);
 }
+
+
+/**
+ * virNetDevSetRootQDisc:
+ * @ifname: the interface name
+ * @qdisc: queueing discipline to set
+ *
+ * For given interface @ifname set its root queueing discipline
+ * to @qdisc. This can be used to replace the default qdisc
+ * (usually pfifo_fast or whatever is set in
+ * /proc/sys/net/core/default_qdisc) with different qdisc.
+ *
+ * Returns: 0 on success,
+ *         -1 if failed to exec tc (with error reported)
+ *         -2 if tc failed (with no error reported)
+ */
+int
+virNetDevSetRootQDisc(const char *ifname,
+                      const char *qdisc)
+{
+    g_autoptr(virCommand) cmd = NULL;
+    g_autofree char *outbuf = NULL;
+    g_autofree char *errbuf = NULL;
+    int status;
+
+    /* Ideally, we would have a netlink implementation and just
+     * call it here.  But honestly, I tried and failed miserably.
+     * Fallback to spawning tc. */
+    cmd = virCommandNewArgList(TC, "qdisc", "add", "dev", ifname,
+                               "root", "handle", "0:", qdisc,
+                               NULL);
+
+    virCommandAddEnvString(cmd, "LC_ALL=C");
+    virCommandSetOutputBuffer(cmd, &outbuf);
+    virCommandSetErrorBuffer(cmd, &errbuf);
+
+    if (virCommandRun(cmd, &status) < 0)
+        return -1;
+
+    if (status != 0) {
+        VIR_DEBUG("Setting qdisc failed: output='%s' err='%s'", outbuf, errbuf);
+        return -2;
+    }
+
+    return 0;
+}
index 5f581323ed9f21b4b48d6e2737b768e71d2c6535..82943b8e08ff608055c655ac66baf00a1a1fc147 100644 (file)
@@ -312,4 +312,7 @@ int virNetDevSysfsFile(char **pf_sysfs_device_link,
 int virNetDevRunEthernetScript(const char *ifname, const char *script)
     G_GNUC_NO_INLINE;
 
+int virNetDevSetRootQDisc(const char *ifname,
+                          const char *qdisc);
+
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetDevRxFilter, virNetDevRxFilterFree);