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: Vinicius Costa Gomes <vinicius.gomes@intel.com>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
25 static void explain(void)
27 fprintf(stderr
, "Usage: ... cbs hicredit BYTES locredit BYTES sendslope BPS idleslope BPS\n");
28 fprintf(stderr
, " [offload 0|1]\n");
32 static void explain1(const char *arg
, const char *val
)
34 fprintf(stderr
, "cbs: illegal value for \"%s\": \"%s\"\n", arg
, val
);
37 static int cbs_parse_opt(struct qdisc_util
*qu
, int argc
,
38 char **argv
, struct nlmsghdr
*n
, const char *dev
)
40 struct tc_cbs_qopt opt
= {};
44 if (matches(*argv
, "offload") == 0) {
47 fprintf(stderr
, "cbs: duplicate \"offload\" specification\n");
50 if (get_u8(&opt
.offload
, *argv
, 0)) {
51 explain1("offload", *argv
);
54 } else if (matches(*argv
, "hicredit") == 0) {
57 fprintf(stderr
, "cbs: duplicate \"hicredit\" specification\n");
60 if (get_s32(&opt
.hicredit
, *argv
, 0)) {
61 explain1("hicredit", *argv
);
64 } else if (matches(*argv
, "locredit") == 0) {
67 fprintf(stderr
, "cbs: duplicate \"locredit\" specification\n");
70 if (get_s32(&opt
.locredit
, *argv
, 0)) {
71 explain1("locredit", *argv
);
74 } else if (matches(*argv
, "sendslope") == 0) {
77 fprintf(stderr
, "cbs: duplicate \"sendslope\" specification\n");
80 if (get_s32(&opt
.sendslope
, *argv
, 0)) {
81 explain1("sendslope", *argv
);
84 } else if (matches(*argv
, "idleslope") == 0) {
87 fprintf(stderr
, "cbs: duplicate \"idleslope\" specification\n");
90 if (get_s32(&opt
.idleslope
, *argv
, 0)) {
91 explain1("idleslope", *argv
);
94 } else if (strcmp(*argv
, "help") == 0) {
98 fprintf(stderr
, "cbs: unknown parameter \"%s\"\n", *argv
);
105 tail
= addattr_nest(n
, 1024, TCA_OPTIONS
);
106 addattr_l(n
, 2024, TCA_CBS_PARMS
, &opt
, sizeof(opt
));
107 addattr_nest_end(n
, tail
);
111 static int cbs_print_opt(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*opt
)
113 struct rtattr
*tb
[TCA_CBS_MAX
+1];
114 struct tc_cbs_qopt
*qopt
;
119 parse_rtattr_nested(tb
, TCA_CBS_MAX
, opt
);
121 if (tb
[TCA_CBS_PARMS
] == NULL
)
124 qopt
= RTA_DATA(tb
[TCA_CBS_PARMS
]);
125 if (RTA_PAYLOAD(tb
[TCA_CBS_PARMS
]) < sizeof(*qopt
))
128 fprintf(f
, "hicredit %d ", qopt
->hicredit
);
129 fprintf(f
, "locredit %d ", qopt
->locredit
);
130 fprintf(f
, "sendslope %d ", qopt
->sendslope
);
131 fprintf(f
, "idleslope %d ", qopt
->idleslope
);
132 fprintf(f
, "offload %d ", qopt
->offload
);
137 struct qdisc_util cbs_qdisc_util
= {
139 .parse_qopt
= cbs_parse_opt
,
140 .print_qopt
= cbs_print_opt
,