| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
* Copyright © 2020 VMware, Inc. */ |
| 3 |
|
| 4 |
#include <linux/pkt_sched.h> |
| 5 |
|
| 6 |
#include "sd-netlink.h" |
| 7 |
|
| 8 |
#include "fq-pie.h" |
| 9 |
#include "log.h" |
| 10 |
#include "parse-util.h" |
| 11 |
#include "string-util.h" |
| 12 |
|
| 13 |
static int fq_pie_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) { |
| 14 |
FlowQueuePIE *fq_pie; |
| 15 |
int r; |
| 16 |
|
| 17 |
assert(link); |
| 18 |
assert(qdisc); |
| 19 |
assert(req); |
| 20 |
|
| 21 |
assert_se(fq_pie = FQ_PIE(qdisc)); |
| 22 |
|
| 23 |
r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "fq_pie"); |
| 24 |
if (r < 0) |
| 25 |
return r; |
| 26 |
|
| 27 |
if (fq_pie->packet_limit > 0) { |
| 28 |
r = sd_netlink_message_append_u32(req, TCA_FQ_PIE_LIMIT, fq_pie->packet_limit); |
| 29 |
if (r < 0) |
| 30 |
return r; |
| 31 |
} |
| 32 |
|
| 33 |
r = sd_netlink_message_close_container(req); |
| 34 |
if (r < 0) |
| 35 |
return r; |
| 36 |
|
| 37 |
return 0; |
| 38 |
} |
| 39 |
|
| 40 |
int config_parse_fq_pie_packet_limit( |
| 41 |
const char *unit, |
| 42 |
const char *filename, |
| 43 |
unsigned line, |
| 44 |
const char *section, |
| 45 |
unsigned section_line, |
| 46 |
const char *lvalue, |
| 47 |
int ltype, |
| 48 |
const char *rvalue, |
| 49 |
void *data, |
| 50 |
void *userdata) { |
| 51 |
|
| 52 |
_cleanup_(qdisc_unref_or_set_invalidp) QDisc *qdisc = NULL; |
| 53 |
FlowQueuePIE *fq_pie; |
| 54 |
Network *network = ASSERT_PTR(data); |
| 55 |
uint32_t val; |
| 56 |
int r; |
| 57 |
|
| 58 |
assert(filename); |
| 59 |
assert(lvalue); |
| 60 |
assert(rvalue); |
| 61 |
|
| 62 |
r = qdisc_new_static(QDISC_KIND_FQ_PIE, network, filename, section_line, &qdisc); |
| 63 |
if (r == -ENOMEM) |
| 64 |
return log_oom(); |
| 65 |
if (r < 0) |
| 66 |
return log_syntax(unit, LOG_WARNING, filename, line, r, |
| 67 |
"More than one kind of queueing discipline, ignoring assignment: %m"); |
| 68 |
|
| 69 |
fq_pie = FQ_PIE(qdisc); |
| 70 |
|
| 71 |
if (isempty(rvalue)) { |
| 72 |
fq_pie->packet_limit = 0; |
| 73 |
|
| 74 |
qdisc = NULL; |
| 75 |
return 0; |
| 76 |
} |
| 77 |
|
| 78 |
r = safe_atou32(rvalue, &val); |
| 79 |
if (r < 0) { |
| 80 |
log_syntax(unit, LOG_WARNING, filename, line, r, |
| 81 |
"Failed to parse '%s=', ignoring assignment: %s", |
| 82 |
lvalue, rvalue); |
| 83 |
return 0; |
| 84 |
} |
| 85 |
if (val == 0) { |
| 86 |
log_syntax(unit, LOG_WARNING, filename, line, 0, |
| 87 |
"Invalid '%s=', ignoring assignment: %s", |
| 88 |
lvalue, rvalue); |
| 89 |
return 0; |
| 90 |
} |
| 91 |
|
| 92 |
fq_pie->packet_limit = val; |
| 93 |
qdisc = NULL; |
| 94 |
|
| 95 |
return 0; |
| 96 |
} |
| 97 |
|
| 98 |
const QDiscVTable fq_pie_vtable = { |
| 99 |
.object_size = sizeof(FlowQueuePIE), |
| 100 |
.tca_kind = "fq_pie", |
| 101 |
.fill_message = fq_pie_fill_message, |
| 102 |
}; |