]>
Commit | Line | Data |
---|---|---|
c9681ac1 VCG |
1 | /* |
2 | * q_cbs.c CBS. | |
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: Vinicius Costa Gomes <vinicius.gomes@intel.com> | |
10 | * | |
11 | */ | |
12 | ||
13 | #include <stdio.h> | |
14 | #include <stdlib.h> | |
15 | #include <unistd.h> | |
c9681ac1 VCG |
16 | #include <fcntl.h> |
17 | #include <sys/socket.h> | |
18 | #include <netinet/in.h> | |
19 | #include <arpa/inet.h> | |
20 | #include <string.h> | |
21 | ||
22 | #include "utils.h" | |
23 | #include "tc_util.h" | |
24 | ||
25 | static void explain(void) | |
26 | { | |
27 | fprintf(stderr, "Usage: ... cbs hicredit BYTES locredit BYTES sendslope BPS idleslope BPS\n"); | |
28 | fprintf(stderr, " [offload 0|1]\n"); | |
29 | ||
30 | } | |
31 | ||
32 | static void explain1(const char *arg, const char *val) | |
33 | { | |
34 | fprintf(stderr, "cbs: illegal value for \"%s\": \"%s\"\n", arg, val); | |
35 | } | |
36 | ||
859af0a5 SH |
37 | static int cbs_parse_opt(struct qdisc_util *qu, int argc, |
38 | char **argv, struct nlmsghdr *n, const char *dev) | |
c9681ac1 VCG |
39 | { |
40 | struct tc_cbs_qopt opt = {}; | |
41 | struct rtattr *tail; | |
42 | ||
43 | while (argc > 0) { | |
44 | if (matches(*argv, "offload") == 0) { | |
45 | NEXT_ARG(); | |
46 | if (opt.offload) { | |
47 | fprintf(stderr, "cbs: duplicate \"offload\" specification\n"); | |
48 | return -1; | |
49 | } | |
50 | if (get_u8(&opt.offload, *argv, 0)) { | |
51 | explain1("offload", *argv); | |
52 | return -1; | |
53 | } | |
54 | } else if (matches(*argv, "hicredit") == 0) { | |
55 | NEXT_ARG(); | |
56 | if (opt.hicredit) { | |
57 | fprintf(stderr, "cbs: duplicate \"hicredit\" specification\n"); | |
58 | return -1; | |
59 | } | |
60 | if (get_s32(&opt.hicredit, *argv, 0)) { | |
61 | explain1("hicredit", *argv); | |
62 | return -1; | |
63 | } | |
64 | } else if (matches(*argv, "locredit") == 0) { | |
65 | NEXT_ARG(); | |
66 | if (opt.locredit) { | |
67 | fprintf(stderr, "cbs: duplicate \"locredit\" specification\n"); | |
68 | return -1; | |
69 | } | |
70 | if (get_s32(&opt.locredit, *argv, 0)) { | |
71 | explain1("locredit", *argv); | |
72 | return -1; | |
73 | } | |
74 | } else if (matches(*argv, "sendslope") == 0) { | |
75 | NEXT_ARG(); | |
76 | if (opt.sendslope) { | |
77 | fprintf(stderr, "cbs: duplicate \"sendslope\" specification\n"); | |
78 | return -1; | |
79 | } | |
80 | if (get_s32(&opt.sendslope, *argv, 0)) { | |
81 | explain1("sendslope", *argv); | |
82 | return -1; | |
83 | } | |
84 | } else if (matches(*argv, "idleslope") == 0) { | |
85 | NEXT_ARG(); | |
86 | if (opt.idleslope) { | |
87 | fprintf(stderr, "cbs: duplicate \"idleslope\" specification\n"); | |
88 | return -1; | |
89 | } | |
90 | if (get_s32(&opt.idleslope, *argv, 0)) { | |
91 | explain1("idleslope", *argv); | |
92 | return -1; | |
93 | } | |
94 | } else if (strcmp(*argv, "help") == 0) { | |
95 | explain(); | |
96 | return -1; | |
97 | } else { | |
98 | fprintf(stderr, "cbs: unknown parameter \"%s\"\n", *argv); | |
99 | explain(); | |
100 | return -1; | |
101 | } | |
102 | argc--; argv++; | |
103 | } | |
104 | ||
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; | |
109 | return 0; | |
110 | } | |
111 | ||
112 | static int cbs_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) | |
113 | { | |
114 | struct rtattr *tb[TCA_CBS_MAX+1]; | |
115 | struct tc_cbs_qopt *qopt; | |
116 | ||
117 | if (opt == NULL) | |
118 | return 0; | |
119 | ||
120 | parse_rtattr_nested(tb, TCA_CBS_MAX, opt); | |
121 | ||
122 | if (tb[TCA_CBS_PARMS] == NULL) | |
123 | return -1; | |
124 | ||
125 | qopt = RTA_DATA(tb[TCA_CBS_PARMS]); | |
126 | if (RTA_PAYLOAD(tb[TCA_CBS_PARMS]) < sizeof(*qopt)) | |
127 | return -1; | |
128 | ||
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); | |
134 | ||
135 | return 0; | |
136 | } | |
137 | ||
138 | struct qdisc_util cbs_qdisc_util = { | |
139 | .id = "cbs", | |
140 | .parse_qopt = cbs_parse_opt, | |
141 | .print_qopt = cbs_print_opt, | |
142 | }; |