|
1 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ |
2 | 2 | * Copyright © 2020 VMware, Inc. */ |
3 | 3 |
|
| 4 | +#include <linux/pkt_sched.h> |
| 5 | + |
| 6 | +#include "parse-util.h" |
4 | 7 | #include "qdisc.h" |
5 | 8 | #include "qfq.h" |
| 9 | +#include "string-util.h" |
| 10 | + |
| 11 | +#define QFQ_MAX_WEIGHT (1 << 10) |
| 12 | +#define QFQ_MIN_MAX_PACKET 512 |
| 13 | +#define QFQ_MAX_MAX_PACKET (1 << 16) |
6 | 14 |
|
7 | 15 | const QDiscVTable qfq_vtable = { |
8 | 16 | .object_size = sizeof(QuickFairQueueing), |
9 | 17 | .tca_kind = "qfq", |
10 | 18 | }; |
| 19 | + |
| 20 | +static int quick_fair_queueing_class_fill_message(Link *link, TClass *tclass, sd_netlink_message *req) { |
| 21 | + QuickFairQueueingClass *qfq; |
| 22 | + int r; |
| 23 | + |
| 24 | + assert(link); |
| 25 | + assert(tclass); |
| 26 | + assert(req); |
| 27 | + |
| 28 | + qfq = TCLASS_TO_QFQ(tclass); |
| 29 | + |
| 30 | + r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "qfq"); |
| 31 | + if (r < 0) |
| 32 | + return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m"); |
| 33 | + |
| 34 | + if (qfq->weight > 0) { |
| 35 | + r = sd_netlink_message_append_u32(req, TCA_QFQ_WEIGHT, qfq->weight); |
| 36 | + if (r < 0) |
| 37 | + return log_link_error_errno(link, r, "Could not append TCA_QFQ_WEIGHT attribute: %m"); |
| 38 | + } |
| 39 | + |
| 40 | + if (qfq->max_packet > 0) { |
| 41 | + r = sd_netlink_message_append_u32(req, TCA_QFQ_LMAX, qfq->max_packet); |
| 42 | + if (r < 0) |
| 43 | + return log_link_error_errno(link, r, "Could not append TCA_QFQ_LMAX attribute: %m"); |
| 44 | + } |
| 45 | + |
| 46 | + r = sd_netlink_message_close_container(req); |
| 47 | + if (r < 0) |
| 48 | + return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m"); |
| 49 | + return 0; |
| 50 | +} |
| 51 | + |
| 52 | +int config_parse_quick_fair_queueing_weight( |
| 53 | + const char *unit, |
| 54 | + const char *filename, |
| 55 | + unsigned line, |
| 56 | + const char *section, |
| 57 | + unsigned section_line, |
| 58 | + const char *lvalue, |
| 59 | + int ltype, |
| 60 | + const char *rvalue, |
| 61 | + void *data, |
| 62 | + void *userdata) { |
| 63 | + |
| 64 | + _cleanup_(tclass_free_or_set_invalidp) TClass *tclass = NULL; |
| 65 | + QuickFairQueueingClass *qfq; |
| 66 | + Network *network = data; |
| 67 | + uint32_t v; |
| 68 | + int r; |
| 69 | + |
| 70 | + assert(filename); |
| 71 | + assert(lvalue); |
| 72 | + assert(rvalue); |
| 73 | + assert(data); |
| 74 | + |
| 75 | + r = tclass_new_static(TCLASS_KIND_QFQ, network, filename, section_line, &tclass); |
| 76 | + if (r < 0) |
| 77 | + return log_syntax(unit, LOG_ERR, filename, line, r, |
| 78 | + "Failed to create traffic control class, ignoring assignment: %m"); |
| 79 | + |
| 80 | + qfq = TCLASS_TO_QFQ(tclass); |
| 81 | + |
| 82 | + if (isempty(rvalue)) { |
| 83 | + qfq->weight = 0; |
| 84 | + tclass = NULL; |
| 85 | + return 0; |
| 86 | + } |
| 87 | + |
| 88 | + r = safe_atou32(rvalue, &v); |
| 89 | + if (r < 0) { |
| 90 | + log_syntax(unit, LOG_ERR, filename, line, r, |
| 91 | + "Failed to parse '%s=', ignoring assignment: %s", |
| 92 | + lvalue, rvalue); |
| 93 | + return 0; |
| 94 | + } |
| 95 | + |
| 96 | + if (v == 0 || v > QFQ_MAX_WEIGHT) { |
| 97 | + log_syntax(unit, LOG_ERR, filename, line, 0, |
| 98 | + "Invalid '%s=', ignoring assignment: %s", |
| 99 | + lvalue, rvalue); |
| 100 | + return 0; |
| 101 | + } |
| 102 | + |
| 103 | + qfq->weight = v; |
| 104 | + tclass = NULL; |
| 105 | + |
| 106 | + return 0; |
| 107 | +} |
| 108 | + |
| 109 | +int config_parse_quick_fair_queueing_max_packet( |
| 110 | + const char *unit, |
| 111 | + const char *filename, |
| 112 | + unsigned line, |
| 113 | + const char *section, |
| 114 | + unsigned section_line, |
| 115 | + const char *lvalue, |
| 116 | + int ltype, |
| 117 | + const char *rvalue, |
| 118 | + void *data, |
| 119 | + void *userdata) { |
| 120 | + |
| 121 | + _cleanup_(tclass_free_or_set_invalidp) TClass *tclass = NULL; |
| 122 | + QuickFairQueueingClass *qfq; |
| 123 | + Network *network = data; |
| 124 | + uint64_t v; |
| 125 | + int r; |
| 126 | + |
| 127 | + assert(filename); |
| 128 | + assert(lvalue); |
| 129 | + assert(rvalue); |
| 130 | + assert(data); |
| 131 | + |
| 132 | + r = tclass_new_static(TCLASS_KIND_QFQ, network, filename, section_line, &tclass); |
| 133 | + if (r < 0) |
| 134 | + return log_syntax(unit, LOG_ERR, filename, line, r, |
| 135 | + "Failed to create traffic control class, ignoring assignment: %m"); |
| 136 | + |
| 137 | + qfq = TCLASS_TO_QFQ(tclass); |
| 138 | + |
| 139 | + if (isempty(rvalue)) { |
| 140 | + qfq->max_packet = 0; |
| 141 | + tclass = NULL; |
| 142 | + return 0; |
| 143 | + } |
| 144 | + |
| 145 | + r = parse_size(rvalue, 1000, &v); |
| 146 | + if (r < 0) { |
| 147 | + log_syntax(unit, LOG_ERR, filename, line, r, |
| 148 | + "Failed to parse '%s=', ignoring assignment: %s", |
| 149 | + lvalue, rvalue); |
| 150 | + return 0; |
| 151 | + } |
| 152 | + |
| 153 | + if (v < QFQ_MIN_MAX_PACKET || v > QFQ_MAX_MAX_PACKET) { |
| 154 | + log_syntax(unit, LOG_ERR, filename, line, 0, |
| 155 | + "Invalid '%s=', ignoring assignment: %s", |
| 156 | + lvalue, rvalue); |
| 157 | + return 0; |
| 158 | + } |
| 159 | + |
| 160 | + qfq->max_packet = (uint32_t) v; |
| 161 | + tclass = NULL; |
| 162 | + |
| 163 | + return 0; |
| 164 | +} |
| 165 | + |
| 166 | +const TClassVTable qfq_tclass_vtable = { |
| 167 | + .object_size = sizeof(QuickFairQueueingClass), |
| 168 | + .tca_kind = "qfq", |
| 169 | + .fill_message = quick_fair_queueing_class_fill_message, |
| 170 | +}; |
0 commit comments