2 * tc_stab.c "tc qdisc ... stab *".
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: Jussi Kivilinna, <jussi.kivilinna@mbnet.fi>
18 #include <sys/socket.h>
19 #include <sys/param.h>
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
28 #include "tc_common.h"
30 static void stab_help(void)
33 "Usage: ... stab [ mtu BYTES ] [ tsize SLOTS ] [ mpu BYTES ]\n"
34 " [ overhead BYTES ] [ linklayer TYPE ] ...\n"
35 " mtu : max packet size we create rate map for {2047}\n"
36 " tsize : how many slots should size table have {512}\n"
37 " mpu : minimum packet size used in rate computations\n"
38 " overhead : per-packet size overhead used in rate computations\n"
39 " linklayer : adapting to a linklayer e.g. atm\n"
40 "Example: ... stab overhead 20 linklayer atm\n");
44 int check_size_table_opts(struct tc_sizespec *s)
46 return s->linklayer >= LINKLAYER_ETHERNET || s->mpu != 0 ||
50 int parse_size_table(int *argcp, char ***argvp, struct tc_sizespec *sp)
54 struct tc_sizespec s = {};
57 if (matches(*argv, "help") == 0) {
62 if (matches(*argv, "mtu") == 0) {
66 if (get_u32(&s.mtu, *argv, 10))
67 invarg("mtu", "invalid mtu");
68 } else if (matches(*argv, "mpu") == 0) {
72 if (get_u32(&s.mpu, *argv, 10))
73 invarg("mpu", "invalid mpu");
74 } else if (matches(*argv, "overhead") == 0) {
77 duparg("overhead", *argv);
78 if (get_integer(&s.overhead, *argv, 10))
79 invarg("overhead", "invalid overhead");
80 } else if (matches(*argv, "tsize") == 0) {
83 duparg("tsize", *argv);
84 if (get_u32(&s.tsize, *argv, 10))
85 invarg("tsize", "invalid table size");
86 } else if (matches(*argv, "linklayer") == 0) {
88 if (s.linklayer != LINKLAYER_UNSPEC)
89 duparg("linklayer", *argv);
90 if (get_linklayer(&s.linklayer, *argv))
91 invarg("linklayer", "invalid linklayer");
97 if (!check_size_table_opts(&s))
106 void print_size_table(FILE *fp, const char *prefix, struct rtattr *rta)
108 struct rtattr *tb[TCA_STAB_MAX + 1];
112 parse_rtattr_nested(tb, TCA_STAB_MAX, rta);
114 if (tb[TCA_STAB_BASE]) {
115 struct tc_sizespec s = {0};
117 memcpy(&s, RTA_DATA(tb[TCA_STAB_BASE]),
118 MIN(RTA_PAYLOAD(tb[TCA_STAB_BASE]), sizeof(s)));
120 fprintf(fp, "%s", prefix);
122 fprintf(fp, "linklayer %s ",
123 sprint_linklayer(s.linklayer, b1));
125 fprintf(fp, "overhead %d ", s.overhead);
127 fprintf(fp, "mpu %u ", s.mpu);
129 fprintf(fp, "mtu %u ", s.mtu);
131 fprintf(fp, "tsize %u ", s.tsize);
135 if (tb[TCA_STAB_DATA]) {
136 unsigned int i, j, dlen;
137 __u16 *data = RTA_DATA(tb[TCA_STAB_DATA]);
139 dlen = RTA_PAYLOAD(tb[TCA_STAB_DATA]) / sizeof(__u16);
141 fprintf(fp, "\n%sstab data:", prefix);
142 for (i = 0; i < dlen/12; i++) {
143 fprintf(fp, "\n%s %3u:", prefix, i * 12);
144 for (j = 0; i * 12 + j < dlen; j++)
145 fprintf(fp, " %05x", data[i * 12 + j]);