blob: cdbae4217092f0c2e948ef08e2611b2800647ca9 [file] [log] [blame]
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +00001/*
2 * tc_util.c Misc TC utility functions.
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: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10 *
11 */
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <unistd.h>
16#include <syslog.h>
17#include <fcntl.h>
18#include <sys/socket.h>
19#include <netinet/in.h>
20#include <arpa/inet.h>
21#include <string.h>
22#include <math.h>
23
24#include "utils.h"
25#include "tc_util.h"
26
Stephen Hemmingeraa27f882007-06-20 15:27:22 -070027const char *get_tc_lib(void)
28{
29 const char *lib_dir;
30
31 lib_dir = getenv("TC_LIB_DIR");
32 if (!lib_dir)
33 lib_dir = "/usr/lib/tc";
34
35 return lib_dir;
36}
37
osdl.org!shemmingerdbd90dc2004-06-02 20:22:08 +000038int get_qdisc_handle(__u32 *h, const char *str)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000039{
40 __u32 maj;
41 char *p;
42
43 maj = TC_H_UNSPEC;
44 if (strcmp(str, "none") == 0)
45 goto ok;
46 maj = strtoul(str, &p, 16);
47 if (p == str)
48 return -1;
49 maj <<= 16;
50 if (*p != ':' && *p!=0)
51 return -1;
52ok:
53 *h = maj;
54 return 0;
55}
56
osdl.org!shemmingerdbd90dc2004-06-02 20:22:08 +000057int get_tc_classid(__u32 *h, const char *str)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000058{
59 __u32 maj, min;
60 char *p;
61
62 maj = TC_H_ROOT;
63 if (strcmp(str, "root") == 0)
64 goto ok;
65 maj = TC_H_UNSPEC;
66 if (strcmp(str, "none") == 0)
67 goto ok;
68 maj = strtoul(str, &p, 16);
69 if (p == str) {
70 maj = 0;
71 if (*p != ':')
72 return -1;
73 }
74 if (*p == ':') {
osdl.net!shemmingera8b303c2005-02-07 18:16:29 +000075 if (maj >= (1<<16))
76 return -1;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000077 maj <<= 16;
78 str = p+1;
79 min = strtoul(str, &p, 16);
80 if (*p != 0)
81 return -1;
osdl.net!shemmingera8b303c2005-02-07 18:16:29 +000082 if (min >= (1<<16))
83 return -1;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000084 maj |= min;
85 } else if (*p != 0)
86 return -1;
87
88ok:
89 *h = maj;
90 return 0;
91}
92
93int print_tc_classid(char *buf, int len, __u32 h)
94{
95 if (h == TC_H_ROOT)
96 sprintf(buf, "root");
97 else if (h == TC_H_UNSPEC)
98 snprintf(buf, len, "none");
99 else if (TC_H_MAJ(h) == 0)
100 snprintf(buf, len, ":%x", TC_H_MIN(h));
101 else if (TC_H_MIN(h) == 0)
102 snprintf(buf, len, "%x:", TC_H_MAJ(h)>>16);
103 else
104 snprintf(buf, len, "%x:%x", TC_H_MAJ(h)>>16, TC_H_MIN(h));
105 return 0;
106}
107
108char * sprint_tc_classid(__u32 h, char *buf)
109{
110 if (print_tc_classid(buf, SPRINT_BSIZE-1, h))
111 strcpy(buf, "???");
112 return buf;
113}
114
osdl.net!shemminger26ab0b12004-08-13 23:23:46 +0000115/* See http://physics.nist.gov/cuu/Units/binary.html */
116static const struct rate_suffix {
117 const char *name;
118 double scale;
119} suffixes[] = {
120 { "bit", 1. },
121 { "Kibit", 1024. },
122 { "kbit", 1000. },
123 { "mibit", 1024.*1024. },
124 { "mbit", 1000000. },
125 { "gibit", 1024.*1024.*1024. },
126 { "gbit", 1000000000. },
127 { "tibit", 1024.*1024.*1024.*1024. },
128 { "tbit", 1000000000000. },
129 { "Bps", 8. },
130 { "KiBps", 8.*1024. },
131 { "KBps", 8000. },
132 { "MiBps", 8.*1024*1024. },
133 { "MBps", 8000000. },
134 { "GiBps", 8.*1024.*1024.*1024. },
135 { "GBps", 8000000000. },
136 { "TiBps", 8.*1024.*1024.*1024.*1024. },
137 { "TBps", 8000000000000. },
138 { NULL }
139};
140
141
osdl.org!shemmingerdbd90dc2004-06-02 20:22:08 +0000142int get_rate(unsigned *rate, const char *str)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000143{
144 char *p;
145 double bps = strtod(str, &p);
osdl.net!shemminger26ab0b12004-08-13 23:23:46 +0000146 const struct rate_suffix *s;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000147
148 if (p == str)
149 return -1;
150
osdl.net!shemminger26ab0b12004-08-13 23:23:46 +0000151 if (*p == '\0') {
152 *rate = bps / 8.; /* assume bytes/sec */
153 return 0;
154 }
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000155
osdl.net!shemminger26ab0b12004-08-13 23:23:46 +0000156 for (s = suffixes; s->name; ++s) {
157 if (strcasecmp(s->name, p) == 0) {
158 *rate = (bps * s->scale) / 8.;
159 return 0;
160 }
161 }
162
163 return -1;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000164}
165
166int get_rate_and_cell(unsigned *rate, int *cell_log, char *str)
167{
168 char * slash = strchr(str, '/');
169
170 if (slash)
171 *slash = 0;
172
173 if (get_rate(rate, str))
174 return -1;
175
176 if (slash) {
177 int cell;
178 int i;
179
180 if (get_integer(&cell, slash+1, 0))
181 return -1;
182 *slash = '/';
183
184 for (i=0; i<32; i++) {
185 if ((1<<i) == cell) {
186 *cell_log = i;
187 return 0;
188 }
189 }
190 return -1;
191 }
192 return 0;
193}
194
osdl.net!shemmingerd40b38b2004-06-28 20:42:59 +0000195void print_rate(char *buf, int len, __u32 rate)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000196{
197 double tmp = (double)rate*8;
osdl.net!shemmingerd40b38b2004-06-28 20:42:59 +0000198 extern int use_iec;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000199
osdl.net!shemmingerd40b38b2004-06-28 20:42:59 +0000200 if (use_iec) {
osdl.net!shemmingerabf1d0b2004-10-19 19:51:41 +0000201 if (tmp >= 1000.0*1024.0*1024.0)
202 snprintf(buf, len, "%.0fMibit", tmp/1024.0*1024.0);
203 else if (tmp >= 1000.0*1024)
204 snprintf(buf, len, "%.0fKibit", tmp/1024);
osdl.net!shemmingerd40b38b2004-06-28 20:42:59 +0000205 else
osdl.net!shemmingerabf1d0b2004-10-19 19:51:41 +0000206 snprintf(buf, len, "%.0fbit", tmp);
207 } else {
208 if (tmp >= 1000.0*1000000.0)
209 snprintf(buf, len, "%.0fMbit", tmp/1000000.0);
210 else if (tmp >= 1000.0 * 1000.0)
211 snprintf(buf, len, "%.0fKbit", tmp/1000.0);
osdl.net!shemmingerd40b38b2004-06-28 20:42:59 +0000212 else
osdl.net!shemmingerabf1d0b2004-10-19 19:51:41 +0000213 snprintf(buf, len, "%.0fbit", tmp);
osdl.net!shemmingerd40b38b2004-06-28 20:42:59 +0000214 }
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000215}
216
217char * sprint_rate(__u32 rate, char *buf)
218{
osdl.net!shemmingerd40b38b2004-06-28 20:42:59 +0000219 print_rate(buf, SPRINT_BSIZE-1, rate);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000220 return buf;
221}
222
Patrick McHardy8f34caa2007-03-04 20:15:00 +0100223int get_time(unsigned *time, const char *str)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000224{
225 double t;
226 char *p;
227
228 t = strtod(str, &p);
229 if (p == str)
230 return -1;
231
232 if (*p) {
233 if (strcasecmp(p, "s") == 0 || strcasecmp(p, "sec")==0 ||
234 strcasecmp(p, "secs")==0)
Patrick McHardyf0bda7e2007-03-04 20:14:59 +0100235 t *= TIME_UNITS_PER_SEC;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000236 else if (strcasecmp(p, "ms") == 0 || strcasecmp(p, "msec")==0 ||
237 strcasecmp(p, "msecs") == 0)
Patrick McHardyf0bda7e2007-03-04 20:14:59 +0100238 t *= TIME_UNITS_PER_SEC/1000;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000239 else if (strcasecmp(p, "us") == 0 || strcasecmp(p, "usec")==0 ||
240 strcasecmp(p, "usecs") == 0)
Patrick McHardyf0bda7e2007-03-04 20:14:59 +0100241 t *= TIME_UNITS_PER_SEC/1000000;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000242 else
243 return -1;
244 }
245
Patrick McHardy8f34caa2007-03-04 20:15:00 +0100246 *time = t;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000247 return 0;
248}
249
250
Patrick McHardy8f34caa2007-03-04 20:15:00 +0100251void print_time(char *buf, int len, __u32 time)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000252{
Patrick McHardy8f34caa2007-03-04 20:15:00 +0100253 double tmp = time;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000254
Patrick McHardyf0bda7e2007-03-04 20:14:59 +0100255 if (tmp >= TIME_UNITS_PER_SEC)
256 snprintf(buf, len, "%.1fs", tmp/TIME_UNITS_PER_SEC);
257 else if (tmp >= TIME_UNITS_PER_SEC/1000)
258 snprintf(buf, len, "%.1fms", tmp/(TIME_UNITS_PER_SEC/1000));
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000259 else
Stephen Hemminger89151442007-03-14 10:14:07 -0700260 snprintf(buf, len, "%uus", time);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000261}
262
Patrick McHardy8f34caa2007-03-04 20:15:00 +0100263char * sprint_time(__u32 time, char *buf)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000264{
Patrick McHardy8f34caa2007-03-04 20:15:00 +0100265 print_time(buf, SPRINT_BSIZE-1, time);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000266 return buf;
267}
268
Patrick McHardybd29e352007-03-04 20:15:01 +0100269char * sprint_ticks(__u32 ticks, char *buf)
270{
271 return sprint_time(tc_core_tick2time(ticks), buf);
272}
273
osdl.org!shemmingerdbd90dc2004-06-02 20:22:08 +0000274int get_size(unsigned *size, const char *str)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000275{
276 double sz;
277 char *p;
278
279 sz = strtod(str, &p);
280 if (p == str)
281 return -1;
282
283 if (*p) {
284 if (strcasecmp(p, "kb") == 0 || strcasecmp(p, "k")==0)
285 sz *= 1024;
osdl.org!shemmingerdbd90dc2004-06-02 20:22:08 +0000286 else if (strcasecmp(p, "gb") == 0 || strcasecmp(p, "g")==0)
287 sz *= 1024*1024*1024;
288 else if (strcasecmp(p, "gbit") == 0)
289 sz *= 1024*1024*1024/8;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000290 else if (strcasecmp(p, "mb") == 0 || strcasecmp(p, "m")==0)
291 sz *= 1024*1024;
292 else if (strcasecmp(p, "mbit") == 0)
293 sz *= 1024*1024/8;
294 else if (strcasecmp(p, "kbit") == 0)
295 sz *= 1024/8;
296 else if (strcasecmp(p, "b") != 0)
297 return -1;
298 }
299
300 *size = sz;
301 return 0;
302}
303
304int get_size_and_cell(unsigned *size, int *cell_log, char *str)
305{
306 char * slash = strchr(str, '/');
307
308 if (slash)
309 *slash = 0;
310
311 if (get_size(size, str))
312 return -1;
313
314 if (slash) {
315 int cell;
316 int i;
317
318 if (get_integer(&cell, slash+1, 0))
319 return -1;
320 *slash = '/';
321
322 for (i=0; i<32; i++) {
323 if ((1<<i) == cell) {
324 *cell_log = i;
325 return 0;
326 }
327 }
328 return -1;
329 }
330 return 0;
331}
332
osdl.net!shemmingerd40b38b2004-06-28 20:42:59 +0000333void print_size(char *buf, int len, __u32 sz)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000334{
335 double tmp = sz;
336
337 if (sz >= 1024*1024 && fabs(1024*1024*rint(tmp/(1024*1024)) - sz) < 1024)
338 snprintf(buf, len, "%gMb", rint(tmp/(1024*1024)));
339 else if (sz >= 1024 && fabs(1024*rint(tmp/1024) - sz) < 16)
340 snprintf(buf, len, "%gKb", rint(tmp/1024));
341 else
342 snprintf(buf, len, "%ub", sz);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000343}
344
345char * sprint_size(__u32 size, char *buf)
346{
osdl.net!shemmingerd40b38b2004-06-28 20:42:59 +0000347 print_size(buf, SPRINT_BSIZE-1, size);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000348 return buf;
349}
350
osdl.net!shemminger25f86902004-08-24 18:54:49 +0000351static const double max_percent_value = 0xffffffff;
osdl.net!shemminger63e989f2004-06-25 20:59:28 +0000352
353int get_percent(__u32 *percent, const char *str)
354{
355 char *p;
osdl.net!shemminger25f86902004-08-24 18:54:49 +0000356 double per = strtod(str, &p) / 100.;
osdl.net!shemminger63e989f2004-06-25 20:59:28 +0000357
osdl.net!shemminger25f86902004-08-24 18:54:49 +0000358 if (per > 1. || per < 0)
osdl.net!shemminger63e989f2004-06-25 20:59:28 +0000359 return -1;
360 if (*p && strcmp(p, "%"))
361 return -1;
362
osdl.net!shemminger25f86902004-08-24 18:54:49 +0000363 *percent = (unsigned) rint(per * max_percent_value);
osdl.net!shemminger63e989f2004-06-25 20:59:28 +0000364 return 0;
365}
366
osdl.net!shemmingerd40b38b2004-06-28 20:42:59 +0000367void print_percent(char *buf, int len, __u32 per)
osdl.net!shemminger63e989f2004-06-25 20:59:28 +0000368{
osdl.net!shemminger25f86902004-08-24 18:54:49 +0000369 snprintf(buf, len, "%g%%", 100. * (double) per / max_percent_value);
osdl.net!shemminger63e989f2004-06-25 20:59:28 +0000370}
371
372char * sprint_percent(__u32 per, char *buf)
373{
osdl.net!shemmingerd40b38b2004-06-28 20:42:59 +0000374 print_percent(buf, SPRINT_BSIZE-1, per);
osdl.net!shemminger63e989f2004-06-25 20:59:28 +0000375 return buf;
376}
377
osdl.net!shemmingerd40b38b2004-06-28 20:42:59 +0000378void print_qdisc_handle(char *buf, int len, __u32 h)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000379{
380 snprintf(buf, len, "%x:", TC_H_MAJ(h)>>16);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000381}
382
383char * sprint_qdisc_handle(__u32 h, char *buf)
384{
osdl.net!shemmingerd40b38b2004-06-28 20:42:59 +0000385 print_qdisc_handle(buf, SPRINT_BSIZE-1, h);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000386 return buf;
387}
388
osdl.net!shemminger2373fde2004-08-13 23:54:55 +0000389char * action_n2a(int action, char *buf, int len)
390{
391 switch (action) {
392 case -1:
393 return "continue";
394 break;
395 case TC_ACT_OK:
396 return "pass";
397 break;
398 case TC_ACT_SHOT:
399 return "drop";
400 break;
401 case TC_ACT_RECLASSIFY:
402 return "reclassify";
403 case TC_ACT_PIPE:
404 return "pipe";
405 case TC_ACT_STOLEN:
406 return "stolen";
407 default:
408 snprintf(buf, len, "%d", action);
409 return buf;
410 }
411}
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000412
osdl.net!shemminger2373fde2004-08-13 23:54:55 +0000413int action_a2n(char *arg, int *result)
414{
415 int res;
416
417 if (matches(arg, "continue") == 0)
418 res = -1;
419 else if (matches(arg, "drop") == 0)
420 res = TC_ACT_SHOT;
421 else if (matches(arg, "shot") == 0)
422 res = TC_ACT_SHOT;
423 else if (matches(arg, "pass") == 0)
424 res = TC_ACT_OK;
425 else if (strcmp(arg, "ok") == 0)
426 res = TC_ACT_OK;
427 else if (matches(arg, "reclassify") == 0)
428 res = TC_ACT_RECLASSIFY;
429 else {
430 char dummy;
431 if (sscanf(arg, "%d%c", &res, &dummy) != 1)
432 return -1;
433 }
434 *result = res;
435 return 0;
436}
437
osdl.net!shemminger6dc9f012004-08-31 17:45:21 +0000438void print_tm(FILE * f, const struct tcf_t *tm)
osdl.net!shemminger2373fde2004-08-13 23:54:55 +0000439{
net[shemminger]!shemminger5e8bc632005-03-14 18:44:54 +0000440 int hz = get_user_hz();
osdl.net!shemminger2373fde2004-08-13 23:54:55 +0000441 if (tm->install != 0)
osdl.net!shemminger63ae25d2005-03-10 19:04:17 +0000442 fprintf(f, " installed %u sec", (unsigned)(tm->install/hz));
osdl.net!shemminger2373fde2004-08-13 23:54:55 +0000443 if (tm->lastuse != 0)
osdl.net!shemminger63ae25d2005-03-10 19:04:17 +0000444 fprintf(f, " used %u sec", (unsigned)(tm->lastuse/hz));
osdl.net!shemminger2373fde2004-08-13 23:54:55 +0000445 if (tm->expires != 0)
osdl.net!shemminger63ae25d2005-03-10 19:04:17 +0000446 fprintf(f, " expires %u sec", (unsigned)(tm->expires/hz));
osdl.net!shemminger2373fde2004-08-13 23:54:55 +0000447}
ch[shemminger]!tgrafe5879dc2004-12-07 23:52:52 +0000448
449void print_tcstats2_attr(FILE *fp, struct rtattr *rta, char *prefix, struct rtattr **xstats)
450{
451 SPRINT_BUF(b1);
14!tgraf7d69fd92005-01-18 22:11:58 +0000452 struct rtattr *tbs[TCA_STATS_MAX + 1];
ch[shemminger]!tgrafe5879dc2004-12-07 23:52:52 +0000453
14!tgraf7d69fd92005-01-18 22:11:58 +0000454 parse_rtattr_nested(tbs, TCA_STATS_MAX, rta);
ch[shemminger]!tgrafe5879dc2004-12-07 23:52:52 +0000455
456 if (tbs[TCA_STATS_BASIC]) {
457 struct gnet_stats_basic bs = {0};
458 memcpy(&bs, RTA_DATA(tbs[TCA_STATS_BASIC]), MIN(RTA_PAYLOAD(tbs[TCA_STATS_BASIC]), sizeof(bs)));
459 fprintf(fp, "%sSent %llu bytes %u pkt",
net[shemminger]!shemmingerb9062432005-01-17 23:28:16 +0000460 prefix, (unsigned long long) bs.bytes, bs.packets);
ch[shemminger]!tgrafe5879dc2004-12-07 23:52:52 +0000461 }
462
463 if (tbs[TCA_STATS_QUEUE]) {
464 struct gnet_stats_queue q = {0};
465 memcpy(&q, RTA_DATA(tbs[TCA_STATS_QUEUE]), MIN(RTA_PAYLOAD(tbs[TCA_STATS_QUEUE]), sizeof(q)));
466 fprintf(fp, " (dropped %u, overlimits %u requeues %u) ",
467 q.drops, q.overlimits, q.requeues);
468 }
Stephen Hemmingerae665a52006-12-05 10:10:22 -0800469
ch[shemminger]!tgrafe5879dc2004-12-07 23:52:52 +0000470 if (tbs[TCA_STATS_RATE_EST]) {
471 struct gnet_stats_rate_est re = {0};
472 memcpy(&re, RTA_DATA(tbs[TCA_STATS_RATE_EST]), MIN(RTA_PAYLOAD(tbs[TCA_STATS_RATE_EST]), sizeof(re)));
473 fprintf(fp, "\n%srate %s %upps ",
474 prefix, sprint_rate(re.bps, b1), re.pps);
475 }
476
477 if (tbs[TCA_STATS_QUEUE]) {
478 struct gnet_stats_queue q = {0};
479 memcpy(&q, RTA_DATA(tbs[TCA_STATS_QUEUE]), MIN(RTA_PAYLOAD(tbs[TCA_STATS_QUEUE]), sizeof(q)));
480 if (!tbs[TCA_STATS_RATE_EST])
481 fprintf(fp, "\n%s", prefix);
482 fprintf(fp, "backlog %s %up requeues %u ",
483 sprint_size(q.backlog, b1), q.qlen, q.requeues);
484 }
485
486 if (xstats)
487 *xstats = tbs[TCA_STATS_APP] ? : NULL;
488}
489
490void print_tcstats_attr(FILE *fp, struct rtattr *tb[], char *prefix, struct rtattr **xstats)
491{
492 SPRINT_BUF(b1);
493
494 if (tb[TCA_STATS2]) {
495 print_tcstats2_attr(fp, tb[TCA_STATS2], prefix, xstats);
496 if (xstats && NULL == *xstats)
497 goto compat_xstats;
498 return;
499 }
500 /* backward compatibility */
501 if (tb[TCA_STATS]) {
502 struct tc_stats st;
503
504 /* handle case where kernel returns more/less than we know about */
505 memset(&st, 0, sizeof(st));
506 memcpy(&st, RTA_DATA(tb[TCA_STATS]), MIN(RTA_PAYLOAD(tb[TCA_STATS]), sizeof(st)));
507
508 fprintf(fp, "%sSent %llu bytes %u pkts (dropped %u, overlimits %u) ",
Stephen Hemmingerae665a52006-12-05 10:10:22 -0800509 prefix, (unsigned long long)st.bytes, st.packets, st.drops,
ch[shemminger]!tgrafe5879dc2004-12-07 23:52:52 +0000510 st.overlimits);
511
512 if (st.bps || st.pps || st.qlen || st.backlog) {
513 fprintf(fp, "\n%s", prefix);
514 if (st.bps || st.pps) {
515 fprintf(fp, "rate ");
516 if (st.bps)
517 fprintf(fp, "%s ", sprint_rate(st.bps, b1));
518 if (st.pps)
519 fprintf(fp, "%upps ", st.pps);
520 }
521 if (st.qlen || st.backlog) {
522 fprintf(fp, "backlog ");
523 if (st.backlog)
524 fprintf(fp, "%s ", sprint_size(st.backlog, b1));
525 if (st.qlen)
526 fprintf(fp, "%up ", st.qlen);
527 }
528 }
529 }
530
531compat_xstats:
532 if (tb[TCA_XSTATS] && xstats)
533 *xstats = tb[TCA_XSTATS];
534}
535