blob: 0e026749a2ef28493be726bf897e70678ec7701b [file] [log] [blame]
Stephen Hemmingerc441bd42011-01-07 09:43:27 -08001/*
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 <syslog.h>
14#include <fcntl.h>
15#include <sys/socket.h>
16#include <netinet/in.h>
17#include <arpa/inet.h>
18#include <string.h>
19
20#include "utils.h"
21#include "tc_util.h"
22
23static void explain(void)
24{
25 fprintf(stderr, "Usage: ... qfq\n");
26}
27
28static void explain1(const char *arg)
29{
30 fprintf(stderr, "Illegal \"%s\"\n", arg);
31}
32
33static void explain_class(void)
34{
35 fprintf(stderr, "Usage: ... qfq weight NUMBER maxpkt BYTES\n");
36}
37
38static int qfq_parse_opt(struct qdisc_util *qu, int argc, char **argv,
39 struct nlmsghdr *n)
40{
Stephen Hemminger037660b2015-10-27 15:46:20 +090041 if (argc > 0) {
42 if (matches(*argv, "help") != 0)
Stephen Hemmingerc441bd42011-01-07 09:43:27 -080043 fprintf(stderr, "What is \"%s\"?\n", *argv);
Stephen Hemminger037660b2015-10-27 15:46:20 +090044 explain();
45 return -1;
Stephen Hemmingerc441bd42011-01-07 09:43:27 -080046 }
47
48 return 0;
49}
50
51static int qfq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
52 struct nlmsghdr *n)
53{
54 struct rtattr *tail;
55 __u32 tmp;
56
57 tail = NLMSG_TAIL(n);
58 addattr_l(n, 4096, TCA_OPTIONS, NULL, 0);
59
60 while (argc > 0) {
61 if (matches(*argv, "weight") == 0) {
62 NEXT_ARG();
63 if (get_u32(&tmp, *argv, 10)) {
64 explain1("weight"); return -1;
65 }
66 addattr32(n, 4096, TCA_QFQ_WEIGHT, tmp);
67 } else if (matches(*argv, "maxpkt") == 0) {
68 NEXT_ARG();
69 if (get_u32(&tmp, *argv, 10)) {
70 explain1("maxpkt"); return -1;
71 }
72 addattr32(n, 4096, TCA_QFQ_LMAX, tmp);
73 } else if (strcmp(*argv, "help") == 0) {
74 explain_class();
75 return -1;
76 } else {
77 fprintf(stderr, "What is \"%s\"?\n", *argv);
78 explain_class();
79 return -1;
80 }
81 argc--; argv++;
82 }
83
84 tail->rta_len = (void *)NLMSG_TAIL(n) - (void *)tail;
85
86 return 0;
87}
88
89static int qfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
90{
91 struct rtattr *tb[TCA_QFQ_MAX + 1];
92
93 if (opt == NULL)
94 return 0;
95
96 parse_rtattr_nested(tb, TCA_QFQ_MAX, opt);
97
98 if (tb[TCA_QFQ_WEIGHT]) {
99 fprintf(f, "weight %u ",
Stephen Hemmingerff247462012-04-10 08:47:55 -0700100 rta_getattr_u32(tb[TCA_QFQ_WEIGHT]));
Stephen Hemmingerc441bd42011-01-07 09:43:27 -0800101 }
102
103 if (tb[TCA_QFQ_LMAX]) {
104 fprintf(f, "maxpkt %u ",
Stephen Hemmingerff247462012-04-10 08:47:55 -0700105 rta_getattr_u32(tb[TCA_QFQ_LMAX]));
Stephen Hemmingerc441bd42011-01-07 09:43:27 -0800106 }
107
108 return 0;
109}
110
111struct qdisc_util qfq_qdisc_util = {
112 .id = "qfq",
113 .parse_qopt = qfq_parse_opt,
114 .print_qopt = qfq_print_opt,
115 .parse_copt = qfq_parse_class_opt,
116 .print_copt = qfq_print_opt,
117};