From: Laine Stump Date: Tue, 26 Nov 2024 03:24:46 +0000 (-0500) Subject: util: put the command that adds a tx filter qdisc into a separate function X-Git-Tag: v10.10.0-rc1~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35a5bf25d125074356ee40881b5592e3b793f6b4;p=thirdparty%2Flibvirt.git util: put the command that adds a tx filter qdisc into a separate function 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 Reviewed-by: Michal Privoznik --- diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2a9d3230e1..c931003fad 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2875,6 +2875,7 @@ virNetDevVFInterfaceStats; # util/virnetdevbandwidth.h +virNetDevBandWidthAddTxFilterParentQdisc; virNetDevBandwidthClear; virNetDevBandwidthCopy; virNetDevBandwidthEqual; diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c index 9c48844c5d..90eebe6576 100644 --- a/src/util/virnetdevbandwidth.c +++ b/src/util/virnetdevbandwidth.c @@ -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); +} diff --git a/src/util/virnetdevbandwidth.h b/src/util/virnetdevbandwidth.h index 744aa4c826..65c1500637 100644 --- a/src/util/virnetdevbandwidth.h +++ b/src/util/virnetdevbandwidth.h @@ -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);