1 /* SPDX-License-Identifier: LGPL-2.1+
2 * Copyright © 2020 VMware, Inc. */
4 #include <linux/pkt_sched.h>
6 #include "alloc-util.h"
8 #include "conf-parser.h"
9 #include "netlink-util.h"
10 #include "parse-util.h"
12 #include "string-util.h"
14 static int cake_fill_message(Link
*link
, QDisc
*qdisc
, sd_netlink_message
*req
) {
15 CommonApplicationsKeptEnhanced
*c
;
24 r
= sd_netlink_message_open_container_union(req
, TCA_OPTIONS
, "cake");
26 return log_link_error_errno(link
, r
, "Could not open container TCA_OPTIONS: %m");
28 if (c
->bandwidth
> 0) {
29 r
= sd_netlink_message_append_u64(req
, TCA_CAKE_BASE_RATE64
, c
->bandwidth
);
31 return log_link_error_errno(link
, r
, "Could not append TCA_CAKE_BASE_RATE64 attribute: %m");
34 r
= sd_netlink_message_append_s32(req
, TCA_CAKE_OVERHEAD
, c
->overhead
);
36 return log_link_error_errno(link
, r
, "Could not append TCA_CAKE_OVERHEAD attribute: %m");
38 r
= sd_netlink_message_close_container(req
);
40 return log_link_error_errno(link
, r
, "Could not close container TCA_OPTIONS: %m");
45 int config_parse_cake_bandwidth(
50 unsigned section_line
,
57 _cleanup_(qdisc_free_or_set_invalidp
) QDisc
*qdisc
= NULL
;
58 CommonApplicationsKeptEnhanced
*c
;
59 Network
*network
= data
;
68 r
= qdisc_new_static(QDISC_KIND_CAKE
, network
, filename
, section_line
, &qdisc
);
72 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
73 "More than one kind of queueing discipline, ignoring assignment: %m");
77 if (isempty(rvalue
)) {
84 r
= parse_size(rvalue
, 1000, &k
);
86 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
87 "Failed to parse '%s=', ignoring assignment: %s",
98 int config_parse_cake_overhead(
100 const char *filename
,
103 unsigned section_line
,
110 _cleanup_(qdisc_free_or_set_invalidp
) QDisc
*qdisc
= NULL
;
111 CommonApplicationsKeptEnhanced
*c
;
112 Network
*network
= data
;
121 r
= qdisc_new_static(QDISC_KIND_CAKE
, network
, filename
, section_line
, &qdisc
);
125 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
126 "More than one kind of queueing discipline, ignoring assignment: %m");
130 if (isempty(rvalue
)) {
136 r
= safe_atoi32(rvalue
, &v
);
138 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
139 "Failed to parse 'Overhead=', ignoring assignment: %s",
143 if (v
< -64 || v
> 256) {
144 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
145 "Invalid 'Overhead=', ignoring assignment: %s",
155 const QDiscVTable cake_vtable
= {
156 .object_size
= sizeof(CommonApplicationsKeptEnhanced
),
158 .fill_message
= cake_fill_message
,