]> git.proxmox.com Git - mirror_iproute2.git/blob - tc/q_qfq.c
tc: B.W limits can now be specified in %.
[mirror_iproute2.git] / tc / q_qfq.c
1 /*
2 * q_qfq.c QFQ.
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: Stephen Hemminger <shemminger@vyatta.com>
10 * Fabio Checconi <fabio@gandalf.sssup.it>
11 *
12 */
13 #include <fcntl.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16 #include <arpa/inet.h>
17 #include <string.h>
18
19 #include "utils.h"
20 #include "tc_util.h"
21
22 static void explain(void)
23 {
24 fprintf(stderr, "Usage: ... qfq\n");
25 }
26
27 static void explain1(const char *arg)
28 {
29 fprintf(stderr, "Illegal \"%s\"\n", arg);
30 }
31
32 static void explain_class(void)
33 {
34 fprintf(stderr, "Usage: ... qfq weight NUMBER maxpkt BYTES\n");
35 }
36
37 static int qfq_parse_opt(struct qdisc_util *qu, int argc, char **argv,
38 struct nlmsghdr *n, const char *dev)
39 {
40 if (argc > 0) {
41 if (matches(*argv, "help") != 0)
42 fprintf(stderr, "What is \"%s\"?\n", *argv);
43 explain();
44 return -1;
45 }
46
47 return 0;
48 }
49
50 static int qfq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
51 struct nlmsghdr *n, const char *dev)
52 {
53 struct rtattr *tail;
54 __u32 tmp;
55
56 tail = NLMSG_TAIL(n);
57 addattr_l(n, 4096, TCA_OPTIONS, NULL, 0);
58
59 while (argc > 0) {
60 if (matches(*argv, "weight") == 0) {
61 NEXT_ARG();
62 if (get_u32(&tmp, *argv, 10)) {
63 explain1("weight"); return -1;
64 }
65 addattr32(n, 4096, TCA_QFQ_WEIGHT, tmp);
66 } else if (matches(*argv, "maxpkt") == 0) {
67 NEXT_ARG();
68 if (get_u32(&tmp, *argv, 10)) {
69 explain1("maxpkt"); return -1;
70 }
71 addattr32(n, 4096, TCA_QFQ_LMAX, tmp);
72 } else if (strcmp(*argv, "help") == 0) {
73 explain_class();
74 return -1;
75 } else {
76 fprintf(stderr, "What is \"%s\"?\n", *argv);
77 explain_class();
78 return -1;
79 }
80 argc--; argv++;
81 }
82
83 tail->rta_len = (void *)NLMSG_TAIL(n) - (void *)tail;
84
85 return 0;
86 }
87
88 static int qfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
89 {
90 struct rtattr *tb[TCA_QFQ_MAX + 1];
91
92 if (opt == NULL)
93 return 0;
94
95 parse_rtattr_nested(tb, TCA_QFQ_MAX, opt);
96
97 if (tb[TCA_QFQ_WEIGHT]) {
98 fprintf(f, "weight %u ",
99 rta_getattr_u32(tb[TCA_QFQ_WEIGHT]));
100 }
101
102 if (tb[TCA_QFQ_LMAX]) {
103 fprintf(f, "maxpkt %u ",
104 rta_getattr_u32(tb[TCA_QFQ_LMAX]));
105 }
106
107 return 0;
108 }
109
110 struct qdisc_util qfq_qdisc_util = {
111 .id = "qfq",
112 .parse_qopt = qfq_parse_opt,
113 .print_qopt = qfq_print_opt,
114 .parse_copt = qfq_parse_class_opt,
115 .print_copt = qfq_print_opt,
116 };