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.
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
11 * Changes: Alexander Atanasov, <alex@ssi.bg>
12 * Alexander Clouter, <alex@digriz.org.uk>
13 * Corey Hickey, <bugfood-c@fatooh.org>
23 #include <sys/socket.h>
24 #include <netinet/in.h>
25 #include <arpa/inet.h>
31 static void explain(void)
33 fprintf(stderr
, "Usage: ... esfq [ perturb SECS ] [ quantum BYTES ] [ depth FLOWS ]\n\t[ divisor HASHBITS ] [ limit PKTS ] [ hash HASHTYPE]\n");
34 fprintf(stderr
,"Where: \n");
35 fprintf(stderr
,"HASHTYPE := { classic | src | dst | fwmark | ctorigdst | ctorigsrc | ctrepldst | ctreplsrc | ctnatchg }\n");
38 static void explain1(char *arg
)
40 fprintf(stderr
, "Illegal \"%s\"\n", arg
);
44 #define usage() return(-1)
46 static int esfq_parse_opt(struct qdisc_util
*qu
, int argc
, char **argv
, struct nlmsghdr
*n
)
49 struct tc_esfq_qopt opt
;
51 memset(&opt
, 0, sizeof(opt
));
53 opt
.hash_kind
= TCA_SFQ_HASH_CLASSIC
;
56 if (strcmp(*argv
, "quantum") == 0) {
58 if (get_size(&opt
.quantum
, *argv
)) {
59 explain1("quantum"); return -1;
62 } else if (strcmp(*argv
, "perturb") == 0) {
64 if (get_integer(&opt
.perturb_period
, *argv
, 0)) {
65 explain1("perturb"); return -1;
68 } else if (strcmp(*argv
, "depth") == 0) {
70 if (get_integer((int *) &opt
.flows
, *argv
, 0)) {
71 explain1("depth"); return -1;
74 } else if (strcmp(*argv
, "divisor") == 0) {
76 if (get_integer((int *) &opt
.divisor
, *argv
, 0)) {
77 explain1("divisor"); return -1;
79 if(opt
.divisor
>= 14) {
80 fprintf(stderr
, "Illegal \"divisor\": must be < 14\n");
83 opt
.divisor
=pow(2,opt
.divisor
);
85 } else if (strcmp(*argv
, "limit") == 0) {
87 if (get_integer((int *) &opt
.limit
, *argv
, 0)) {
88 explain1("limit"); return -1;
91 } else if (strcmp(*argv
, "hash") == 0) {
93 if(strcmp(*argv
, "classic") == 0) {
94 opt
.hash_kind
= TCA_SFQ_HASH_CLASSIC
;
96 if(strcmp(*argv
, "dst") == 0) {
97 opt
.hash_kind
= TCA_SFQ_HASH_DST
;
99 if(strcmp(*argv
, "src") == 0) {
100 opt
.hash_kind
= TCA_SFQ_HASH_SRC
;
102 if(strcmp(*argv
, "fwmark") == 0) {
103 opt
.hash_kind
= TCA_SFQ_HASH_FWMARK
;
105 if(strcmp(*argv
, "ctorigsrc") == 0) {
106 opt
.hash_kind
= TCA_SFQ_HASH_CTORIGSRC
;
108 if(strcmp(*argv
, "ctorigdst") == 0) {
109 opt
.hash_kind
= TCA_SFQ_HASH_CTORIGDST
;
111 if(strcmp(*argv
, "ctreplsrc") == 0) {
112 opt
.hash_kind
= TCA_SFQ_HASH_CTREPLSRC
;
114 if(strcmp(*argv
, "ctrepldst") == 0) {
115 opt
.hash_kind
= TCA_SFQ_HASH_CTREPLDST
;
117 if(strcmp(*argv
, "ctnatchg") == 0) {
118 opt
.hash_kind
= TCA_SFQ_HASH_CTNATCHG
;
120 explain1("hash"); return -1;
123 } else if (strcmp(*argv
, "help") == 0) {
127 fprintf(stderr
, "What is \"%s\"?\n", *argv
);
135 addattr_l(n
, 1024, TCA_OPTIONS
, &opt
, sizeof(opt
));
139 static int esfq_print_opt(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*opt
)
141 struct tc_esfq_qopt
*qopt
;
147 if (RTA_PAYLOAD(opt
) < sizeof(*qopt
))
149 qopt
= RTA_DATA(opt
);
150 fprintf(f
, "quantum %s ", sprint_size(qopt
->quantum
, b1
));
152 fprintf(f
, "limit %up flows %u/%u ",
153 qopt
->limit
, qopt
->flows
, qopt
->divisor
);
155 if (qopt
->perturb_period
)
156 fprintf(f
, "perturb %dsec ", qopt
->perturb_period
);
159 switch(qopt
->hash_kind
)
161 case TCA_SFQ_HASH_CLASSIC
:
162 fprintf(f
,"classic");
164 case TCA_SFQ_HASH_DST
:
167 case TCA_SFQ_HASH_SRC
:
170 case TCA_SFQ_HASH_FWMARK
:
173 case TCA_SFQ_HASH_CTORIGSRC
:
174 fprintf(f
,"ctorigsrc");
176 case TCA_SFQ_HASH_CTORIGDST
:
177 fprintf(f
,"ctorigdst");
179 case TCA_SFQ_HASH_CTREPLSRC
:
180 fprintf(f
,"ctreplsrc");
182 case TCA_SFQ_HASH_CTREPLDST
:
183 fprintf(f
,"ctrepldst");
185 case TCA_SFQ_HASH_CTNATCHG
:
186 fprintf(f
,"ctnatchg");
189 fprintf(f
,"Unknown");
194 static int esfq_print_xstats(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*xstats
)
200 struct qdisc_util esfq_util
= {