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
= NLMSG_TAIL(n
);
106 addattr_l(n
, 1024, TCA_OPTIONS
, NULL
, 0);
107 addattr_l(n
, 2024, TCA_CBS_PARMS
, &opt
, sizeof(opt
));
108 tail
->rta_len
= (void *) NLMSG_TAIL(n
) - (void *) tail
;
112 static int cbs_print_opt(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*opt
)
114 struct rtattr
*tb
[TCA_CBS_MAX
+1];
115 struct tc_cbs_qopt
*qopt
;
120 parse_rtattr_nested(tb
, TCA_CBS_MAX
, opt
);
122 if (tb
[TCA_CBS_PARMS
] == NULL
)
125 qopt
= RTA_DATA(tb
[TCA_CBS_PARMS
]);
126 if (RTA_PAYLOAD(tb
[TCA_CBS_PARMS
]) < sizeof(*qopt
))
129 fprintf(f
, "hicredit %d ", qopt
->hicredit
);
130 fprintf(f
, "locredit %d ", qopt
->locredit
);
131 fprintf(f
, "sendslope %d ", qopt
->sendslope
);
132 fprintf(f
, "idleslope %d ", qopt
->idleslope
);
133 fprintf(f
, "offload %d ", qopt
->offload
);
138 struct qdisc_util cbs_qdisc_util
= {
140 .parse_qopt
= cbs_parse_opt
,
141 .print_qopt
= cbs_print_opt
,