]> git.proxmox.com Git - mirror_iproute2.git/blob - tc/tc_stab.c
add generic size table for qdiscs
[mirror_iproute2.git] / tc / tc_stab.c
1 /*
2 * tc_stab.c "tc qdisc ... stab *".
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: Jussi Kivilinna, <jussi.kivilinna@mbnet.fi>
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 <math.h>
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
22 #include <string.h>
23 #include <malloc.h>
24
25 #include "utils.h"
26 #include "tc_util.h"
27 #include "tc_core.h"
28 #include "tc_common.h"
29
30 static void stab_help(void)
31 {
32 fprintf(stderr,
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");
41
42 return;
43 }
44
45 int check_size_table_opts(struct tc_sizespec *s)
46 {
47 return s->linklayer >= LINKLAYER_ETHERNET || s->mpu != 0 ||
48 s->overhead != 0;
49 }
50
51 int parse_size_table(int *argcp, char ***argvp, struct tc_sizespec *sp)
52 {
53 char **argv = *argvp;
54 int argc = *argcp;
55 struct tc_sizespec s;
56
57 memset(&s, 0, sizeof(s));
58
59 NEXT_ARG();
60 if (matches(*argv, "help") == 0) {
61 stab_help();
62 return -1;
63 }
64 while (argc > 0) {
65 if (matches(*argv, "mtu") == 0) {
66 NEXT_ARG();
67 if (s.mtu)
68 duparg("mtu", *argv);
69 if (get_u32(&s.mtu, *argv, 10)) {
70 invarg("mtu", "invalid mtu");
71 return -1;
72 }
73 } else if (matches(*argv, "mpu") == 0) {
74 NEXT_ARG();
75 if (s.mpu)
76 duparg("mpu", *argv);
77 if (get_u32(&s.mpu, *argv, 10)) {
78 invarg("mpu", "invalid mpu");
79 return -1;
80 }
81 } else if (matches(*argv, "overhead") == 0) {
82 NEXT_ARG();
83 if (s.overhead)
84 duparg("overhead", *argv);
85 if (get_integer(&s.overhead, *argv, 10)) {
86 invarg("overhead", "invalid overhead");
87 return -1;
88 }
89 } else if (matches(*argv, "tsize") == 0) {
90 NEXT_ARG();
91 if (s.tsize)
92 duparg("tsize", *argv);
93 if (get_u32(&s.tsize, *argv, 10)) {
94 invarg("tsize", "invalid table size");
95 return -1;
96 }
97 } else if (matches(*argv, "linklayer") == 0) {
98 NEXT_ARG();
99 if (s.linklayer != LINKLAYER_UNSPEC)
100 duparg("linklayer", *argv);
101 if (get_linklayer(&s.linklayer, *argv)) {
102 invarg("linklayer", "invalid linklayer");
103 return -1;
104 }
105 } else
106 break;
107 argc--; argv++;
108 }
109
110 if (!check_size_table_opts(&s))
111 return -1;
112
113 *sp = s;
114 *argvp = argv;
115 *argcp = argc;
116 return 0;
117 }
118
119 void print_size_table(FILE *fp, const char *prefix, struct rtattr *rta)
120 {
121 struct rtattr *tb[TCA_STAB_MAX + 1];
122 SPRINT_BUF(b1);
123
124 parse_rtattr_nested(tb, TCA_STAB_MAX, rta);
125
126 if (tb[TCA_STAB_BASE]) {
127 struct tc_sizespec s = {0};
128 memcpy(&s, RTA_DATA(tb[TCA_STAB_BASE]),
129 MIN(RTA_PAYLOAD(tb[TCA_STAB_BASE]), sizeof(s)));
130
131 fprintf(fp, "%s", prefix);
132 if (s.linklayer)
133 fprintf(fp, "linklayer %s ",
134 sprint_linklayer(s.linklayer, b1));
135 if (s.overhead)
136 fprintf(fp, "overhead %d ", s.overhead);
137 if (s.mpu)
138 fprintf(fp, "mpu %u ", s.mpu);
139 if (s.mtu)
140 fprintf(fp, "mtu %u ", s.mtu);
141 if (s.tsize)
142 fprintf(fp, "tsize %u ", s.tsize);
143 }
144
145 #if 0
146 if (tb[TCA_STAB_DATA]) {
147 unsigned i, j, dlen;
148 __u16 *data = RTA_DATA(tb[TCA_STAB_DATA]);
149 dlen = RTA_PAYLOAD(tb[TCA_STAB_DATA]) / sizeof(__u16);
150
151 fprintf(fp, "\n%sstab data:", prefix);
152 for (i = 0; i < dlen/12; i++) {
153 fprintf(fp, "\n%s %3u:", prefix, i * 12);
154 for (j = 0; i * 12 + j < dlen; j++)
155 fprintf(fp, " %05x", data[i * 12 + j]);
156 }
157 }
158 #endif
159 }
160