blob: b8e6ab792f9f736c191f835d405e150546dc5634 [file] [log] [blame]
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +00001/*
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 *
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000011 */
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <unistd.h>
16#include <syslog.h>
17#include <fcntl.h>
18#include <sys/socket.h>
19#include <netinet/in.h>
20#include <arpa/inet.h>
21#include <string.h>
22
23#include "utils.h"
24#include "tc_util.h"
25
26static void explain(void)
27{
Subash Abhinov Kasiviswanathan0b5eaaa2014-07-17 17:21:44 -060028 fprintf(stderr, "Usage: ... prio bands NUMBER priomap P1 P2...[multiqueue] [flow (enable|disable)]\n");
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000029}
30
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000031static int prio_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
32{
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000033 int pmap_mode = 0;
34 int idx = 0;
Subash Abhinov Kasiviswanathan0b5eaaa2014-07-17 17:21:44 -060035 struct tc_prio_qopt opt={3,{ 1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 },1};
PJ Waskiewicz292ce962007-08-14 11:21:24 -070036 struct rtattr *nest;
37 unsigned char mq = 0;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000038
39 while (argc > 0) {
40 if (strcmp(*argv, "bands") == 0) {
41 if (pmap_mode)
42 explain();
43 NEXT_ARG();
44 if (get_integer(&opt.bands, *argv, 10)) {
45 fprintf(stderr, "Illegal \"bands\"\n");
46 return -1;
47 }
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000048 } else if (strcmp(*argv, "priomap") == 0) {
49 if (pmap_mode) {
50 fprintf(stderr, "Error: duplicate priomap\n");
51 return -1;
52 }
53 pmap_mode = 1;
PJ Waskiewicz292ce962007-08-14 11:21:24 -070054 } else if (strcmp(*argv, "multiqueue") == 0) {
55 mq = 1;
Subash Abhinov Kasiviswanathan0b5eaaa2014-07-17 17:21:44 -060056 } else if (strcmp(*argv, "flow") == 0) {
57 NEXT_ARG();
58 if (strcmp(*argv, "enable") == 0)
59 {
60 opt.enable_flow = 1;
61 }
62 else if (strcmp(*argv, "disable") == 0)
63 {
64 opt.enable_flow = 0;
65 }
66 else
67 {
68 explain();
69 return -1;
70 }
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000071 } else if (strcmp(*argv, "help") == 0) {
72 explain();
73 return -1;
74 } else {
75 unsigned band;
76 if (!pmap_mode) {
77 fprintf(stderr, "What is \"%s\"?\n", *argv);
78 explain();
79 return -1;
80 }
81 if (get_unsigned(&band, *argv, 10)) {
82 fprintf(stderr, "Illegal \"priomap\" element\n");
83 return -1;
84 }
85 if (band > opt.bands) {
86 fprintf(stderr, "\"priomap\" element is out of bands\n");
87 return -1;
88 }
89 if (idx > TC_PRIO_MAX) {
90 fprintf(stderr, "\"priomap\" index > TC_PRIO_MAX=%u\n", TC_PRIO_MAX);
91 return -1;
92 }
93 opt.priomap[idx++] = band;
94 }
95 argc--; argv++;
96 }
97
98/*
99 if (pmap_mode) {
100 for (; idx < TC_PRIO_MAX; idx++)
101 opt.priomap[idx] = opt.priomap[TC_PRIO_BESTEFFORT];
102 }
103*/
PJ Waskiewicz292ce962007-08-14 11:21:24 -0700104 nest = addattr_nest_compat(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
105 if (mq)
106 addattr_l(n, 1024, TCA_PRIO_MQ, NULL, 0);
107 addattr_nest_compat_end(n, nest);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000108 return 0;
109}
110
osdl.org!shemminger78d55b62004-06-02 20:22:08 +0000111int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000112{
113 int i;
114 struct tc_prio_qopt *qopt;
PJ Waskiewicz292ce962007-08-14 11:21:24 -0700115 struct rtattr *tb[TCA_PRIO_MAX+1];
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000116
117 if (opt == NULL)
118 return 0;
119
PJ Waskiewicz292ce962007-08-14 11:21:24 -0700120 if (parse_rtattr_nested_compat(tb, TCA_PRIO_MAX, opt, qopt,
121 sizeof(*qopt)))
122 return -1;
123
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000124 fprintf(f, "bands %u priomap ", qopt->bands);
125 for (i=0; i<=TC_PRIO_MAX; i++)
126 fprintf(f, " %d", qopt->priomap[i]);
PJ Waskiewicz292ce962007-08-14 11:21:24 -0700127
128 if (tb[TCA_PRIO_MQ])
129 fprintf(f, " multiqueue: %s ",
Stephen Hemmingerff247462012-04-10 08:47:55 -0700130 rta_getattr_u8(tb[TCA_PRIO_MQ]) ? "on" : "off");
PJ Waskiewicz292ce962007-08-14 11:21:24 -0700131
Subash Abhinov Kasiviswanathan0b5eaaa2014-07-17 17:21:44 -0600132 if (qu && !strcmp(qu->id, "prio"))
133 fprintf(f, " flow %s", qopt->enable_flow ? "enabled" : "disabled");
134
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000135 return 0;
136}
137
net[shemminger]!kaber95812b52004-09-28 18:35:49 +0000138struct qdisc_util prio_qdisc_util = {
osdl.net!shemmingerf2f99e22004-08-31 17:45:21 +0000139 .id = "prio",
140 .parse_qopt = prio_parse_opt,
141 .print_qopt = prio_print_opt,
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000142};
143