]> git.proxmox.com Git - mirror_iproute2.git/blob - tc/q_prio.c
tc: B.W limits can now be specified in %.
[mirror_iproute2.git] / tc / q_prio.c
1 /*
2 * q_prio.c PRIO.
3 *
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.
8 *
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10 *
11 */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include <fcntl.h>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
20 #include <string.h>
21
22 #include "utils.h"
23 #include "tc_util.h"
24
25 static void explain(void)
26 {
27 fprintf(stderr, "Usage: ... prio bands NUMBER priomap P1 P2...[multiqueue]\n");
28 }
29
30 static int prio_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n, const char *dev)
31 {
32 int pmap_mode = 0;
33 int idx = 0;
34 struct tc_prio_qopt opt = {3, { 1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 } };
35 struct rtattr *nest;
36 unsigned char mq = 0;
37
38 while (argc > 0) {
39 if (strcmp(*argv, "bands") == 0) {
40 if (pmap_mode)
41 explain();
42 NEXT_ARG();
43 if (get_integer(&opt.bands, *argv, 10)) {
44 fprintf(stderr, "Illegal \"bands\"\n");
45 return -1;
46 }
47 } else if (strcmp(*argv, "priomap") == 0) {
48 if (pmap_mode) {
49 fprintf(stderr, "Error: duplicate priomap\n");
50 return -1;
51 }
52 pmap_mode = 1;
53 } else if (strcmp(*argv, "multiqueue") == 0) {
54 mq = 1;
55 } else if (strcmp(*argv, "help") == 0) {
56 explain();
57 return -1;
58 } else {
59 unsigned int band;
60
61 if (!pmap_mode) {
62 fprintf(stderr, "What is \"%s\"?\n", *argv);
63 explain();
64 return -1;
65 }
66 if (get_unsigned(&band, *argv, 10)) {
67 fprintf(stderr, "Illegal \"priomap\" element\n");
68 return -1;
69 }
70 if (band >= opt.bands) {
71 fprintf(stderr, "\"priomap\" element is out of bands\n");
72 return -1;
73 }
74 if (idx > TC_PRIO_MAX) {
75 fprintf(stderr, "\"priomap\" index > TC_PRIO_MAX=%u\n", TC_PRIO_MAX);
76 return -1;
77 }
78 opt.priomap[idx++] = band;
79 }
80 argc--; argv++;
81 }
82
83 /*
84 if (pmap_mode) {
85 for (; idx < TC_PRIO_MAX; idx++)
86 opt.priomap[idx] = opt.priomap[TC_PRIO_BESTEFFORT];
87 }
88 */
89 nest = addattr_nest_compat(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
90 if (mq)
91 addattr_l(n, 1024, TCA_PRIO_MQ, NULL, 0);
92 addattr_nest_compat_end(n, nest);
93 return 0;
94 }
95
96 int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
97 {
98 int i;
99 struct tc_prio_qopt *qopt;
100 struct rtattr *tb[TCA_PRIO_MAX+1];
101
102 if (opt == NULL)
103 return 0;
104
105 if (parse_rtattr_nested_compat(tb, TCA_PRIO_MAX, opt, qopt,
106 sizeof(*qopt)))
107 return -1;
108
109 fprintf(f, "bands %u priomap ", qopt->bands);
110 for (i = 0; i <= TC_PRIO_MAX; i++)
111 fprintf(f, " %d", qopt->priomap[i]);
112
113 if (tb[TCA_PRIO_MQ])
114 fprintf(f, " multiqueue: %s ",
115 rta_getattr_u8(tb[TCA_PRIO_MQ]) ? "on" : "off");
116
117 return 0;
118 }
119
120 struct qdisc_util prio_qdisc_util = {
121 .id = "prio",
122 .parse_qopt = prio_parse_opt,
123 .print_qopt = prio_print_opt,
124 };