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