diff --git a/man/systemd.network.xml b/man/systemd.network.xml
index 556deea881..516744c5f7 100644
--- a/man/systemd.network.xml
+++ b/man/systemd.network.xml
@@ -2765,6 +2765,42 @@
+
+ [DeficitRoundRobinSchedulerClass] Section Options
+ The [DeficitRoundRobinSchedulerClass] section manages the traffic control class of
+ Deficit Round Robin Scheduler (DRR).
+
+
+
+ Parent=
+
+ Specifies the parent Queueing Discipline (qdisc). Takes one of root,
+ clsact, ingress or a class id. The class id takes the
+ major and minor number in hexadecimal ranges 1 to ffff separated with a colon
+ (major:minor). Defaults to root.
+
+
+
+
+ ClassId=
+
+ Specifies the major and minur number of unique identifier of the class, known as the
+ class ID. Each number is in hexadecimal ranges 1 to ffff. Defaults to unset.
+
+
+
+
+ Quantum=
+
+ Specifies the amount of bytes a flow is allowed to dequeue before the
+ scheduler moves to the next class. An unsigned integer ranges 1 to 4294967294.
+ Defaults to the MTU of the interface.
+
+
+
+
+
+
[GenericRandomEarlyDetection] Section Options
The [GenericRandomEarlyDetection] section manages the queueing discipline
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index 17e4256b54..5d7150c58a 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -271,6 +271,9 @@ ControlledDelay.CEThresholdSec, config_parse_controlled_delay_usec,
ControlledDelay.ECN, config_parse_controlled_delay_bool, QDISC_KIND_CODEL, 0
DeficitRoundRobinScheduler.Parent, config_parse_qdisc_parent, QDISC_KIND_DRR, 0
DeficitRoundRobinScheduler.Handle, config_parse_qdisc_handle, QDISC_KIND_DRR, 0
+DeficitRoundRobinSchedulerClass.Parent, config_parse_tclass_parent, TCLASS_KIND_DRR, 0
+DeficitRoundRobinSchedulerClass.ClassId, config_parse_tclass_classid, TCLASS_KIND_DRR, 0
+DeficitRoundRobinSchedulerClass.Quantum, config_parse_drr_size, TCLASS_KIND_DRR, 0
PFIFO.Parent, config_parse_qdisc_parent, QDISC_KIND_PFIFO, 0
PFIFO.Handle, config_parse_qdisc_handle, QDISC_KIND_PFIFO, 0
PFIFO.PacketLimit, config_parse_fifo_size, QDISC_KIND_PFIFO, 0
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 896e5b9de6..cf423e274a 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -489,6 +489,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
"CAKE\0"
"ControlledDelay\0"
"DeficitRoundRobinScheduler\0"
+ "DeficitRoundRobinSchedulerClass\0"
"PFIFO\0"
"FairQueueing\0"
"FairQueueingControlledDelay\0"
diff --git a/src/network/tc/drr.c b/src/network/tc/drr.c
index 086d775ed4..ac64eb8b03 100644
--- a/src/network/tc/drr.c
+++ b/src/network/tc/drr.c
@@ -1,9 +1,105 @@
/* SPDX-License-Identifier: LGPL-2.1+
* Copyright © 2020 VMware, Inc. */
+#include
+
+#include "alloc-util.h"
+#include "conf-parser.h"
#include "drr.h"
+#include "netlink-util.h"
+#include "parse-util.h"
+#include "string-util.h"
const QDiscVTable drr_vtable = {
.object_size = sizeof(DeficitRoundRobinScheduler),
.tca_kind = "drr",
};
+
+static int drr_class_fill_message(Link *link, TClass *tclass, sd_netlink_message *req) {
+ DeficitRoundRobinSchedulerClass *drr;
+ int r;
+
+ assert(link);
+ assert(tclass);
+ assert(req);
+
+ drr = TCLASS_TO_DRR(tclass);
+
+ r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "drr");
+ if (r < 0)
+ return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m");
+
+ if (drr->quantum > 0) {
+ r = sd_netlink_message_append_u32(req, TCA_DRR_QUANTUM, drr->quantum);
+ if (r < 0)
+ return log_link_error_errno(link, r, "Could not append TCA_DRR_QUANTUM, attribute: %m");
+ }
+
+ r = sd_netlink_message_close_container(req);
+ if (r < 0)
+ return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m");
+
+ return 0;
+}
+
+int config_parse_drr_size(
+ const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ unsigned section_line,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ _cleanup_(tclass_free_or_set_invalidp) TClass *tclass = NULL;
+ DeficitRoundRobinSchedulerClass *drr;
+ Network *network = data;
+ uint64_t u;
+ int r;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+ assert(data);
+
+ r = tclass_new_static(TCLASS_KIND_DRR, network, filename, section_line, &tclass);
+ if (r < 0)
+ return log_syntax(unit, LOG_ERR, filename, line, r,
+ "Failed to create traffic control class, ignoring assignment: %m");
+
+ drr = TCLASS_TO_DRR(tclass);
+
+ if (isempty(rvalue)) {
+ drr->quantum = 0;
+
+ tclass = NULL;
+ return 0;
+ }
+
+ r = parse_size(rvalue, 1000, &u);
+ if (r < 0) {
+ log_syntax(unit, LOG_ERR, filename, line, r,
+ "Failed to parse '%s=', ignoring assignment: %s",
+ lvalue, rvalue);
+ return 0;
+ }
+ if (u > UINT32_MAX) {
+ log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid '%s=', ignoring assignment: %s",
+ lvalue, rvalue);
+ return 0;
+ }
+
+ drr->quantum = (uint32_t) u;
+
+ tclass = NULL;
+ return 0;
+}
+
+const TClassVTable drr_tclass_vtable = {
+ .object_size = sizeof(DeficitRoundRobinSchedulerClass),
+ .tca_kind = "drr",
+ .fill_message = drr_class_fill_message,
+};
diff --git a/src/network/tc/drr.h b/src/network/tc/drr.h
index 4e20c4f7d1..ff2b658acc 100644
--- a/src/network/tc/drr.h
+++ b/src/network/tc/drr.h
@@ -10,3 +10,14 @@ typedef struct DeficitRoundRobinScheduler {
DEFINE_QDISC_CAST(DRR, DeficitRoundRobinScheduler);
extern const QDiscVTable drr_vtable;
+
+typedef struct DeficitRoundRobinSchedulerClass {
+ TClass meta;
+
+ uint32_t quantum;
+} DeficitRoundRobinSchedulerClass;
+
+DEFINE_TCLASS_CAST(DRR, DeficitRoundRobinSchedulerClass);
+extern const TClassVTable drr_tclass_vtable;
+
+CONFIG_PARSER_PROTOTYPE(config_parse_drr_size);
diff --git a/src/network/tc/tclass.c b/src/network/tc/tclass.c
index 87f5bcf704..219ffa2ea6 100644
--- a/src/network/tc/tclass.c
+++ b/src/network/tc/tclass.c
@@ -16,6 +16,7 @@
#include "tclass.h"
const TClassVTable * const tclass_vtable[_TCLASS_KIND_MAX] = {
+ [TCLASS_KIND_DRR] = &drr_tclass_vtable,
[TCLASS_KIND_HTB] = &htb_tclass_vtable,
};
diff --git a/src/network/tc/tclass.h b/src/network/tc/tclass.h
index 9698e582fa..217dbfe001 100644
--- a/src/network/tc/tclass.h
+++ b/src/network/tc/tclass.h
@@ -9,6 +9,7 @@
#include "tc.h"
typedef enum TClassKind {
+ TCLASS_KIND_DRR,
TCLASS_KIND_HTB,
_TCLASS_KIND_MAX,
_TCLASS_KIND_INVALID = -1,
@@ -64,4 +65,5 @@ DEFINE_TC_CAST(TCLASS, TClass);
CONFIG_PARSER_PROTOTYPE(config_parse_tclass_parent);
CONFIG_PARSER_PROTOTYPE(config_parse_tclass_classid);
+#include "drr.h"
#include "htb.h"
diff --git a/test/fuzz/fuzz-network-parser/directives.network b/test/fuzz/fuzz-network-parser/directives.network
index 151b1c2c39..6ea18d7dc9 100644
--- a/test/fuzz/fuzz-network-parser/directives.network
+++ b/test/fuzz/fuzz-network-parser/directives.network
@@ -377,3 +377,7 @@ PacketLimit=
[DeficitRoundRobinScheduler]
Parent=
Handle=
+[DeficitRoundRobinSchedulerClass]
+Parent=
+ClassId=
+Quantum=