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