]>
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 | ||
927e3cfb | 37 | static int cbs_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n, const char *dev) |
c9681ac1 VCG |
38 | { |
39 | struct tc_cbs_qopt opt = {}; | |
40 | struct rtattr *tail; | |
41 | ||
42 | while (argc > 0) { | |
43 | if (matches(*argv, "offload") == 0) { | |
44 | NEXT_ARG(); | |
45 | if (opt.offload) { | |
46 | fprintf(stderr, "cbs: duplicate \"offload\" specification\n"); | |
47 | return -1; | |
48 | } | |
49 | if (get_u8(&opt.offload, *argv, 0)) { | |
50 | explain1("offload", *argv); | |
51 | return -1; | |
52 | } | |
53 | } else if (matches(*argv, "hicredit") == 0) { | |
54 | NEXT_ARG(); | |
55 | if (opt.hicredit) { | |
56 | fprintf(stderr, "cbs: duplicate \"hicredit\" specification\n"); | |
57 | return -1; | |
58 | } | |
59 | if (get_s32(&opt.hicredit, *argv, 0)) { | |
60 | explain1("hicredit", *argv); | |
61 | return -1; | |
62 | } | |
63 | } else if (matches(*argv, "locredit") == 0) { | |
64 | NEXT_ARG(); | |
65 | if (opt.locredit) { | |
66 | fprintf(stderr, "cbs: duplicate \"locredit\" specification\n"); | |
67 | return -1; | |
68 | } | |
69 | if (get_s32(&opt.locredit, *argv, 0)) { | |
70 | explain1("locredit", *argv); | |
71 | return -1; | |
72 | } | |
73 | } else if (matches(*argv, "sendslope") == 0) { | |
74 | NEXT_ARG(); | |
75 | if (opt.sendslope) { | |
76 | fprintf(stderr, "cbs: duplicate \"sendslope\" specification\n"); | |
77 | return -1; | |
78 | } | |
79 | if (get_s32(&opt.sendslope, *argv, 0)) { | |
80 | explain1("sendslope", *argv); | |
81 | return -1; | |
82 | } | |
83 | } else if (matches(*argv, "idleslope") == 0) { | |
84 | NEXT_ARG(); | |
85 | if (opt.idleslope) { | |
86 | fprintf(stderr, "cbs: duplicate \"idleslope\" specification\n"); | |
87 | return -1; | |
88 | } | |
89 | if (get_s32(&opt.idleslope, *argv, 0)) { | |
90 | explain1("idleslope", *argv); | |
91 | return -1; | |
92 | } | |
93 | } else if (strcmp(*argv, "help") == 0) { | |
94 | explain(); | |
95 | return -1; | |
96 | } else { | |
97 | fprintf(stderr, "cbs: unknown parameter \"%s\"\n", *argv); | |
98 | explain(); | |
99 | return -1; | |
100 | } | |
101 | argc--; argv++; | |
102 | } | |
103 | ||
104 | tail = NLMSG_TAIL(n); | |
105 | addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); | |
106 | addattr_l(n, 2024, TCA_CBS_PARMS, &opt, sizeof(opt)); | |
107 | tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; | |
108 | return 0; | |
109 | } | |
110 | ||
111 | static int cbs_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) | |
112 | { | |
113 | struct rtattr *tb[TCA_CBS_MAX+1]; | |
114 | struct tc_cbs_qopt *qopt; | |
115 | ||
116 | if (opt == NULL) | |
117 | return 0; | |
118 | ||
119 | parse_rtattr_nested(tb, TCA_CBS_MAX, opt); | |
120 | ||
121 | if (tb[TCA_CBS_PARMS] == NULL) | |
122 | return -1; | |
123 | ||
124 | qopt = RTA_DATA(tb[TCA_CBS_PARMS]); | |
125 | if (RTA_PAYLOAD(tb[TCA_CBS_PARMS]) < sizeof(*qopt)) | |
126 | return -1; | |
127 | ||
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); | |
133 | ||
134 | return 0; | |
135 | } | |
136 | ||
137 | struct qdisc_util cbs_qdisc_util = { | |
138 | .id = "cbs", | |
139 | .parse_qopt = cbs_parse_opt, | |
140 | .print_qopt = cbs_print_opt, | |
141 | }; |