4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
25 static void explain(void)
27 fprintf(stderr, "Usage: ... prio bands NUMBER priomap P1 P2...[multiqueue]\n");
30 static int prio_parse_opt(struct qdisc_util *qu, int argc, char **argv,
31 struct nlmsghdr *n, const char *dev)
35 struct tc_prio_qopt opt = {3, { 1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 } };
40 if (strcmp(*argv, "bands") == 0) {
44 if (get_integer(&opt.bands, *argv, 10)) {
45 fprintf(stderr, "Illegal \"bands\"\n");
48 } else if (strcmp(*argv, "priomap") == 0) {
50 fprintf(stderr, "Error: duplicate priomap\n");
54 } else if (strcmp(*argv, "multiqueue") == 0) {
56 } else if (strcmp(*argv, "help") == 0) {
63 fprintf(stderr, "What is \"%s\"?\n", *argv);
67 if (get_unsigned(&band, *argv, 10)) {
68 fprintf(stderr, "Illegal \"priomap\" element\n");
71 if (band >= opt.bands) {
72 fprintf(stderr, "\"priomap\" element is out of bands\n");
75 if (idx > TC_PRIO_MAX) {
76 fprintf(stderr, "\"priomap\" index > TC_PRIO_MAX=%u\n", TC_PRIO_MAX);
79 opt.priomap[idx++] = band;
86 for (; idx < TC_PRIO_MAX; idx++)
87 opt.priomap[idx] = opt.priomap[TC_PRIO_BESTEFFORT];
90 nest = addattr_nest_compat(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
92 addattr_l(n, 1024, TCA_PRIO_MQ, NULL, 0);
93 addattr_nest_compat_end(n, nest);
97 int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
100 struct tc_prio_qopt *qopt;
101 struct rtattr *tb[TCA_PRIO_MAX+1];
106 if (parse_rtattr_nested_compat(tb, TCA_PRIO_MAX, opt, qopt,
110 print_uint(PRINT_ANY, "bands", "bands %u ", qopt->bands);
111 open_json_array(PRINT_ANY, "priomap");
112 for (i = 0; i <= TC_PRIO_MAX; i++)
113 print_uint(PRINT_ANY, NULL, " %d", qopt->priomap[i]);
114 close_json_array(PRINT_ANY, "");
117 print_string(PRINT_FP, NULL, " multiqueue: %s ",
118 rta_getattr_u8(tb[TCA_PRIO_MQ]) ? "on" : "off");
119 print_bool(PRINT_JSON, "multiqueue", NULL,
120 tb[TCA_PRIO_MQ] && rta_getattr_u8(tb[TCA_PRIO_MQ]));
125 struct qdisc_util prio_qdisc_util = {
127 .parse_qopt = prio_parse_opt,
128 .print_qopt = prio_print_opt,