]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/q_qfq.c
Merge branch 'master' into net-next-3.11
[mirror_iproute2.git] / tc / q_qfq.c
CommitLineData
c441bd4c
SH
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 <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{
41 while (argc > 0) {
42 if (matches(*argv, "help") == 0) {
43 explain();
44 return -1;
45 } else {
46 fprintf(stderr, "What is \"%s\"?\n", *argv);
47 explain();
48 return -1;
49 }
50 argc--; argv++;
51 }
52
53 return 0;
54}
55
56static int qfq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
57 struct nlmsghdr *n)
58{
59 struct rtattr *tail;
60 __u32 tmp;
61
62 tail = NLMSG_TAIL(n);
63 addattr_l(n, 4096, TCA_OPTIONS, NULL, 0);
64
65 while (argc > 0) {
66 if (matches(*argv, "weight") == 0) {
67 NEXT_ARG();
68 if (get_u32(&tmp, *argv, 10)) {
69 explain1("weight"); return -1;
70 }
71 addattr32(n, 4096, TCA_QFQ_WEIGHT, tmp);
72 } else if (matches(*argv, "maxpkt") == 0) {
73 NEXT_ARG();
74 if (get_u32(&tmp, *argv, 10)) {
75 explain1("maxpkt"); return -1;
76 }
77 addattr32(n, 4096, TCA_QFQ_LMAX, tmp);
78 } else if (strcmp(*argv, "help") == 0) {
79 explain_class();
80 return -1;
81 } else {
82 fprintf(stderr, "What is \"%s\"?\n", *argv);
83 explain_class();
84 return -1;
85 }
86 argc--; argv++;
87 }
88
89 tail->rta_len = (void *)NLMSG_TAIL(n) - (void *)tail;
90
91 return 0;
92}
93
94static int qfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
95{
96 struct rtattr *tb[TCA_QFQ_MAX + 1];
97
98 if (opt == NULL)
99 return 0;
100
101 parse_rtattr_nested(tb, TCA_QFQ_MAX, opt);
102
103 if (tb[TCA_QFQ_WEIGHT]) {
104 fprintf(f, "weight %u ",
ff24746c 105 rta_getattr_u32(tb[TCA_QFQ_WEIGHT]));
c441bd4c
SH
106 }
107
108 if (tb[TCA_QFQ_LMAX]) {
109 fprintf(f, "maxpkt %u ",
ff24746c 110 rta_getattr_u32(tb[TCA_QFQ_LMAX]));
c441bd4c
SH
111 }
112
113 return 0;
114}
115
116struct qdisc_util qfq_qdisc_util = {
117 .id = "qfq",
118 .parse_qopt = qfq_parse_opt,
119 .print_qopt = qfq_print_opt,
120 .parse_copt = qfq_parse_class_opt,
121 .print_copt = qfq_print_opt,
122};