| 1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 |
/* |
| 3 |
* q_qfq.c QFQ. |
| 4 |
* |
| 5 |
* Authors: Stephen Hemminger <[email protected]> |
| 6 |
* Fabio Checconi <[email protected]> |
| 7 |
* |
| 8 |
*/ |
| 9 |
#include <fcntl.h> |
| 10 |
#include <sys/socket.h> |
| 11 |
#include <netinet/in.h> |
| 12 |
#include <arpa/inet.h> |
| 13 |
#include <string.h> |
| 14 |
|
| 15 |
#include "utils.h" |
| 16 |
#include "tc_util.h" |
| 17 |
|
| 18 |
static void explain(void) |
| 19 |
{ |
| 20 |
fprintf(stderr, "Usage: ... qfq\n"); |
| 21 |
} |
| 22 |
|
| 23 |
static void explain1(const char *arg) |
| 24 |
{ |
| 25 |
fprintf(stderr, "Illegal \"%s\"\n", arg); |
| 26 |
} |
| 27 |
|
| 28 |
static void explain_class(void) |
| 29 |
{ |
| 30 |
fprintf(stderr, "Usage: ... qfq weight NUMBER maxpkt BYTES\n"); |
| 31 |
} |
| 32 |
|
| 33 |
static int qfq_parse_opt(const struct qdisc_util *qu, int argc, char **argv, |
| 34 |
struct nlmsghdr *n, const char *dev) |
| 35 |
{ |
| 36 |
if (argc > 0) { |
| 37 |
if (matches(*argv, "help") != 0) |
| 38 |
fprintf(stderr, "What is \"%s\"?\n", *argv); |
| 39 |
explain(); |
| 40 |
return -1; |
| 41 |
} |
| 42 |
|
| 43 |
return 0; |
| 44 |
} |
| 45 |
|
| 46 |
static int qfq_parse_class_opt(const struct qdisc_util *qu, int argc, char **argv, |
| 47 |
struct nlmsghdr *n, const char *dev) |
| 48 |
{ |
| 49 |
struct rtattr *tail; |
| 50 |
__u32 tmp; |
| 51 |
|
| 52 |
tail = addattr_nest(n, 4096, TCA_OPTIONS); |
| 53 |
|
| 54 |
while (argc > 0) { |
| 55 |
if (matches(*argv, "weight") == 0) { |
| 56 |
NEXT_ARG(); |
| 57 |
if (get_u32(&tmp, *argv, 10)) { |
| 58 |
explain1("weight"); return -1; |
| 59 |
} |
| 60 |
addattr32(n, 4096, TCA_QFQ_WEIGHT, tmp); |
| 61 |
} else if (matches(*argv, "maxpkt") == 0) { |
| 62 |
NEXT_ARG(); |
| 63 |
if (get_u32(&tmp, *argv, 10)) { |
| 64 |
explain1("maxpkt"); return -1; |
| 65 |
} |
| 66 |
addattr32(n, 4096, TCA_QFQ_LMAX, tmp); |
| 67 |
} else if (strcmp(*argv, "help") == 0) { |
| 68 |
explain_class(); |
| 69 |
return -1; |
| 70 |
} else { |
| 71 |
fprintf(stderr, "What is \"%s\"?\n", *argv); |
| 72 |
explain_class(); |
| 73 |
return -1; |
| 74 |
} |
| 75 |
argc--; argv++; |
| 76 |
} |
| 77 |
|
| 78 |
addattr_nest_end(n, tail); |
| 79 |
|
| 80 |
return 0; |
| 81 |
} |
| 82 |
|
| 83 |
static int qfq_print_opt(const struct qdisc_util *qu, FILE *f, struct rtattr *opt) |
| 84 |
{ |
| 85 |
struct rtattr *tb[TCA_QFQ_MAX + 1]; |
| 86 |
|
| 87 |
if (opt == NULL) |
| 88 |
return 0; |
| 89 |
|
| 90 |
parse_rtattr_nested(tb, TCA_QFQ_MAX, opt); |
| 91 |
|
| 92 |
if (tb[TCA_QFQ_WEIGHT]) { |
| 93 |
fprintf(f, "weight %u ", |
| 94 |
rta_getattr_u32(tb[TCA_QFQ_WEIGHT])); |
| 95 |
} |
| 96 |
|
| 97 |
if (tb[TCA_QFQ_LMAX]) { |
| 98 |
fprintf(f, "maxpkt %u ", |
| 99 |
rta_getattr_u32(tb[TCA_QFQ_LMAX])); |
| 100 |
} |
| 101 |
|
| 102 |
return 0; |
| 103 |
} |
| 104 |
|
| 105 |
struct qdisc_util qfq_qdisc_util = { |
| 106 |
.id = "qfq", |
| 107 |
.parse_qopt = qfq_parse_opt, |
| 108 |
.print_qopt = qfq_print_opt, |
| 109 |
.parse_copt = qfq_parse_class_opt, |
| 110 |
.print_copt = qfq_print_opt, |
| 111 |
}; |