]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: put the command that adds a tx filter qdisc into a separate function
authorLaine Stump <laine@redhat.com>
Tue, 26 Nov 2024 03:24:46 +0000 (22:24 -0500)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 26 Nov 2024 13:36:14 +0000 (14:36 +0100)
virNetDevBandwidthSet() adds a queue discipline (qdisc) for each
interface that it will need to add tc transmit filters to, and the
filters are then attached to the qdisc.

There are other circumstances where some other function will need to
add tc transmit filters to an interface (in particular an upcoming
patch to the network driver nftables backend that will use a tc tx
filter to fix the checksum of dhcp packets), so that function will
also need a qdisc for the tx filter. To assure both always use exactly
the same qdisc, this patch puts the command that adds the tx filter
qdisc into a separate helper function that can (and will) be called
from either place

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/libvirt_private.syms
src/util/virnetdevbandwidth.c
src/util/virnetdevbandwidth.h

index 2a9d3230e10fa14ecaa9f4154c17d0b61238d83e..c931003fadd2763b02e058ae13e767e36994f79b 100644 (file)
@@ -2875,6 +2875,7 @@ virNetDevVFInterfaceStats;
 
 
 # util/virnetdevbandwidth.h
+virNetDevBandWidthAddTxFilterParentQdisc;
 virNetDevBandwidthClear;
 virNetDevBandwidthCopy;
 virNetDevBandwidthEqual;
index 9c48844c5dd1d297bd9ec99d603ca3b8ce9307ba..90eebe65761366a1ee5d46c7247a41b52c17d297 100644 (file)
@@ -266,11 +266,7 @@ virNetDevBandwidthSet(const char *ifname,
         if (tx->burst)
             burst = g_strdup_printf("%llukb", tx->burst);
 
-        cmd = virCommandNew(TC);
-        virCommandAddArgList(cmd, "qdisc", "add", "dev", ifname, "root",
-                             "handle", "1:", "htb", "default",
-                             hierarchical_class ? "2" : "1", NULL);
-        if (virCommandRun(cmd, NULL) < 0)
+        if (virNetDevBandWidthAddTxFilterParentQdisc(ifname, hierarchical_class) < 0)
             goto cleanup;
 
         /* If we are creating a hierarchical class, all non guaranteed traffic
@@ -794,3 +790,27 @@ virNetDevBandwidthSetRootQDisc(const char *ifname,
 
     return 0;
 }
+
+/**
+ * virNetDevBandwidthAddTxFilterParentQdisc:
+ * @ifname: name of interface that needs a qdisc to attach tx filters to
+ * @hierarchical_class: true if hierarchical classes will be used on this interface
+ *
+ * Add a root Qdisc (Queueing Discipline) for attaching Tx filters to
+ * @ifname.
+ *
+ * returns 0 on success, -1 on failure
+ */
+int
+virNetDevBandWidthAddTxFilterParentQdisc(const char *ifname,
+                                         bool hierarchical_class)
+{
+    g_autoptr(virCommand) cmd = NULL;
+
+    cmd = virCommandNew(TC);
+    virCommandAddArgList(cmd, "qdisc", "add", "dev", ifname, "root",
+                         "handle", "1:", "htb", "default",
+                         hierarchical_class ? "2" : "1", NULL);
+
+    return virCommandRun(cmd, NULL);
+}
index 744aa4c826593fc796f4c540fbf3fadb47827a8f..65c1500637b86f21e9a54ec17e0d1f5bc65b0cf4 100644 (file)
@@ -84,3 +84,6 @@ int virNetDevBandwidthUpdateFilter(const char *ifname,
 int virNetDevBandwidthSetRootQDisc(const char *ifname,
                                    const char *qdisc)
     G_NO_INLINE;
+
+int virNetDevBandWidthAddTxFilterParentQdisc(const char *ifname,
+                                             bool hierarchical_class);