1 /* SPDX-License-Identifier: LGPL-2.1+
2 * Copyright © 2020 VMware, Inc. */
4 #include <linux/pkt_sched.h>
6 #include "alloc-util.h"
7 #include "conf-parser.h"
9 #include "netlink-util.h"
10 #include "parse-util.h"
11 #include "string-util.h"
13 static int fifo_fill_message(Link
*link
, QDisc
*qdisc
, sd_netlink_message
*req
) {
14 struct tc_fifo_qopt opt
= {};
15 FirstInFirstOut
*fifo
;
23 case QDISC_KIND_PFIFO
:
26 case QDISC_KIND_BFIFO
:
29 case QDISC_KIND_PFIFO_HEAD_DROP
:
30 fifo
= PFIFO_HEAD_DROP(qdisc
);
33 assert_not_reached("Invalid QDisc kind.");
36 opt
.limit
= fifo
->limit
;
38 r
= sd_netlink_message_append_data(req
, TCA_OPTIONS
, &opt
, sizeof(struct tc_fifo_qopt
));
40 return log_link_error_errno(link
, r
, "Could not append TCA_OPTIONS attribute: %m");
45 int config_parse_pfifo_size(
50 unsigned section_line
,
57 _cleanup_(qdisc_free_or_set_invalidp
) QDisc
*qdisc
= NULL
;
58 Network
*network
= data
;
59 FirstInFirstOut
*fifo
;
67 r
= qdisc_new_static(ltype
, network
, filename
, section_line
, &qdisc
);
71 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
72 "More than one kind of queueing discipline, ignoring assignment: %m");
75 case QDISC_KIND_PFIFO
:
78 case QDISC_KIND_PFIFO_HEAD_DROP
:
79 fifo
= PFIFO_HEAD_DROP(qdisc
);
82 assert_not_reached("Invalid QDisc kind.");
85 if (isempty(rvalue
)) {
92 r
= safe_atou32(rvalue
, &fifo
->limit
);
94 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
95 "Failed to parse '%s=', ignoring assignment: %s",
104 int config_parse_bfifo_size(
106 const char *filename
,
109 unsigned section_line
,
116 _cleanup_(qdisc_free_or_set_invalidp
) QDisc
*qdisc
= NULL
;
117 Network
*network
= data
;
118 FirstInFirstOut
*fifo
;
127 r
= qdisc_new_static(QDISC_KIND_BFIFO
, network
, filename
, section_line
, &qdisc
);
131 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
132 "More than one kind of queueing discipline, ignoring assignment: %m");
136 if (isempty(rvalue
)) {
143 r
= parse_size(rvalue
, 1024, &u
);
145 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
146 "Failed to parse '%s=', ignoring assignment: %s",
150 if (u
> UINT32_MAX
) {
151 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid '%s=', ignoring assignment: %s",
156 fifo
->limit
= (uint32_t) u
;
162 const QDiscVTable pfifo_vtable
= {
163 .object_size
= sizeof(FirstInFirstOut
),
165 .fill_message
= fifo_fill_message
,
168 const QDiscVTable bfifo_vtable
= {
169 .object_size
= sizeof(FirstInFirstOut
),
171 .fill_message
= fifo_fill_message
,
174 const QDiscVTable pfifo_head_drop_vtable
= {
175 .object_size
= sizeof(FirstInFirstOut
),
176 .tca_kind
= "pfifo_head_drop",
177 .fill_message
= fifo_fill_message
,
180 const QDiscVTable pfifo_fast_vtable
= {
181 .object_size
= sizeof(FirstInFirstOut
),
182 .tca_kind
= "pfifo_fast",